add minimal query error handling

Wed, 23 Oct 2024 18:25:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 23 Oct 2024 18:25:43 +0200
changeset 58
0d25f15e2625
parent 57
d5a7dbc945ef
child 59
6bd37fe6d905

add minimal query error handling

application/davcontroller.c file | annotate | diff | comparison | revisions
ui/gtk/button.c file | annotate | diff | comparison | revisions
ui/gtk/button.h file | annotate | diff | comparison | revisions
ui/gtk/headerbar.c file | annotate | diff | comparison | revisions
ui/gtk/window.c file | annotate | diff | comparison | revisions
--- a/application/davcontroller.c	Wed Oct 23 18:25:28 2024 +0200
+++ b/application/davcontroller.c	Wed Oct 23 18:25:43 2024 +0200
@@ -163,7 +163,8 @@
         if (query->result) {
             davbrowser_set_collection(event->obj, browser, query->result);
         } else {
-            // TODO: error
+            cxmutstr error = cx_asprintf("Error %d", query->browser->sn->error);
+            ui_dialog(event->obj, .title = "Error", .content = error.ptr, .closebutton_label = "OK");
         }
 
         window_progress(event->window, 0);
--- a/ui/gtk/button.c	Wed Oct 23 18:25:28 2024 +0200
+++ b/ui/gtk/button.c	Wed Oct 23 18:25:43 2024 +0200
@@ -60,7 +60,8 @@
         const char *icon,
         ui_callback onclick,
         void *userdata,
-        int event_value)
+        int event_value,
+        bool activate_event)
 {
     GtkWidget *button = gtk_button_new_with_label(label);
     ui_button_set_icon_name(button, icon);
@@ -83,6 +84,13 @@
                 "destroy",
                 G_CALLBACK(ui_destroy_userdata),
                 event);
+        if(activate_event) {
+            g_signal_connect(
+                button,
+                "activate",
+                G_CALLBACK(ui_button_clicked),
+                event);
+        }
     }
     
     return button;
@@ -90,7 +98,7 @@
 
 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) {
     UiObject* current = uic_current_obj(obj);
-    GtkWidget *button = ui_create_button(obj, args.label, args.icon, args.onclick, args.onclickdata, 0);
+    GtkWidget *button = ui_create_button(obj, args.label, args.icon, args.onclick, args.onclickdata, 0, FALSE);
     ui_set_name_and_style(button, args.name, args.style_class);
     ui_set_widget_groups(obj->ctx, button, args.groups);
     UI_APPLY_LAYOUT1(current, args);
--- a/ui/gtk/button.h	Wed Oct 23 18:25:28 2024 +0200
+++ b/ui/gtk/button.h	Wed Oct 23 18:25:43 2024 +0200
@@ -47,7 +47,8 @@
         const char *icon,
         ui_callback onclick,
         void *userdata,
-        int event_value);
+        int event_value,
+        bool activate_event);
 
 void ui_setup_togglebutton(
         UiObject *obj,
--- a/ui/gtk/headerbar.c	Wed Oct 23 18:25:28 2024 +0200
+++ b/ui/gtk/headerbar.c	Wed Oct 23 18:25:43 2024 +0200
@@ -114,7 +114,7 @@
         UiObject *obj,
         enum UiToolbarPos pos)
 {
-    GtkWidget *button = ui_create_button(obj, item->args.label, item->args.icon, item->args.onclick, item->args.onclickdata, 0);
+    GtkWidget *button = ui_create_button(obj, item->args.label, item->args.icon, item->args.onclick, item->args.onclickdata, 0, FALSE);
     WIDGET_ADD_CSS_CLASS(button, "flat");
     headerbar_add(headerbar, box, button, pos);
 }
--- a/ui/gtk/window.c	Wed Oct 23 18:25:28 2024 +0200
+++ b/ui/gtk/window.c	Wed Oct 23 18:25:43 2024 +0200
@@ -610,8 +610,10 @@
 
 #if GTK_CHECK_VERSION(4, 0, 0)
 #define HEADERBAR_SHOW_CLOSEBUTTON(headerbar, set) gtk_header_bar_set_show_title_buttons(GTK_HEADER_BAR(headerbar), set)
+#define DEFAULT_BUTTON(window, button) gtk_window_set_default_widget(GTK_WINDOW(window), button)
 #else
 #define HEADERBAR_SHOW_CLOSEBUTTON(headerbar, set) gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(headerbar), set)
+#define DEFAULT_BUTTON(window, button) gtk_window_set_default(GTK_WINDOW(window), button)
 #endif
 
 
@@ -672,32 +674,36 @@
             }
             
             if(args.lbutton1) {
-                GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1);
+                GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1, args.default_button == 1);
                 gtk_header_bar_pack_start(GTK_HEADER_BAR(headerbar), button);
                 if(args.default_button == 1) {
                     WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                    DEFAULT_BUTTON(dialog, button);
                 }
             }
             if(args.lbutton2) {
-                GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2);
+                GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2, args.default_button == 2);
                 gtk_header_bar_pack_start(GTK_HEADER_BAR(headerbar), button);
                 if(args.default_button == 2) {
                     WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                    DEFAULT_BUTTON(dialog, button);
                 }
             }
             
             if(args.rbutton4) {
-                GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4);
+                GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4, args.default_button == 4);
                 gtk_header_bar_pack_end(GTK_HEADER_BAR(headerbar), button);
                 if(args.default_button == 4) {
                     WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                    DEFAULT_BUTTON(dialog, button);
                 }
             }
             if(args.rbutton3) {
-                GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3);
+                GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3, args.default_button == 3);
                 gtk_header_bar_pack_end(GTK_HEADER_BAR(headerbar), button);
                 if(args.default_button == 3) {
                     WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                    DEFAULT_BUTTON(dialog, button);
                 }
             }
             WINDOW_SET_CONTENT(obj->widget, content_vbox);
@@ -714,23 +720,39 @@
         gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE); 
         
         if(args.lbutton1) {
-            GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1);
+            GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1, args.default_button == 1);
             gtk_grid_attach(GTK_GRID(grid), button, 0, 0, 1, 1);
+            if(args.default_button == 1) {
+                WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                DEFAULT_BUTTON(dialog, button);
+            }
         }
         if(args.lbutton2) {
-            GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2);
+            GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2, args.default_button == 2);
             gtk_grid_attach(GTK_GRID(grid), button, 1, 0, 1, 1);
+            if(args.default_button == 2) {
+                WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                DEFAULT_BUTTON(dialog, button);
+            }
         }
         GtkWidget *space = gtk_label_new(NULL);
         gtk_widget_set_hexpand(space, TRUE);
         gtk_grid_attach(GTK_GRID(grid), space, 2, 0, 1, 1);
         if(args.rbutton3) {
-            GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3);
+            GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3, args.default_button == 3);
             gtk_grid_attach(GTK_GRID(grid), button, 3, 0, 1, 1);
+            if(args.default_button == 3) {
+                WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                DEFAULT_BUTTON(dialog, button);
+            }
         }
-        if(args.rbutton3) {
-            GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4);
+        if(args.rbutton4) {
+            GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4, args.default_button == 4);
             gtk_grid_attach(GTK_GRID(grid), button, 4, 0, 1, 1);
+            if(args.default_button == 4) {
+                WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                DEFAULT_BUTTON(dialog, button);
+            }
         }
         
         BOX_ADD_EXPAND(vbox, content_vbox);   

mercurial