]> spindle.queued.net Git - midori/commitdiff
Refactor compact add and error message dialogues
authorChristian Dywan <christian@twotoasts.de>
Sun, 29 Nov 2009 13:08:52 +0000 (14:08 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sun, 29 Nov 2009 13:09:29 +0000 (14:09 +0100)
midori/midori-browser.c
midori/sokoke.c
midori/sokoke.h

index c2e3fdbd662a517bf8a393a1381a5c8f91cdaed2..8afd16a8b731a580969602d85855c320a41b5be5 100644 (file)
@@ -2258,16 +2258,7 @@ midori_browser_subscribe_to_news_feed (MidoriBrowser* browser,
     if (browser->news_aggregator && *browser->news_aggregator)
         sokoke_spawn_program (browser->news_aggregator, uri, FALSE);
     else
-    {
-        GtkWidget* dialog = gtk_message_dialog_new (
-            GTK_WINDOW (browser), 0, GTK_MESSAGE_INFO,
-            GTK_BUTTONS_OK, "%s", _("New feed"));
-        gtk_message_dialog_format_secondary_text (
-            GTK_MESSAGE_DIALOG (dialog), "%s", uri);
-        gtk_widget_show (dialog);
-        g_signal_connect_swapped (dialog, "response",
-            G_CALLBACK (gtk_widget_destroy), dialog);
-    }
+        sokoke_message_dialog (GTK_MESSAGE_INFO, _("New feed"), uri);
 }
 
 static void
@@ -2291,8 +2282,9 @@ _action_compact_add_activate (GtkAction*     action,
 {
     GtkWidget* dialog;
     GtkBox* box;
-    gchar* label = NULL;
-    GtkWidget* button;
+    const gchar* actions[] = { "BookmarkAdd", "AddSpeedDial",
+                               "AddDesktopShortcut", "AddNewsFeed" };
+    guint i;
 
     if (!GTK_WIDGET_VISIBLE (browser))
         return;
@@ -2302,30 +2294,25 @@ _action_compact_add_activate (GtkAction*     action,
         "title", _("Add a new bookmark"), NULL);
     box = GTK_BOX (GTK_DIALOG (dialog)->vbox);
 
-    action = _action_by_name (browser, "BookmarkAdd");
-    katze_assign (label, katze_object_get_string (action, "label"));
-    button = gtk_button_new_with_mnemonic (label);
-    gtk_box_pack_start (box, button, TRUE, TRUE, 4);
-    gtk_action_connect_proxy (action, button);
-    action = _action_by_name (browser, "AddSpeedDial");
-    katze_assign (label, katze_object_get_string (action, "label"));
-    button = gtk_button_new_with_mnemonic (label);
-    gtk_box_pack_start (box, button, TRUE, TRUE, 4);
-    gtk_action_connect_proxy (action, button);
-    action = _action_by_name (browser, "AddDesktopShortcut");
-    katze_assign (label, katze_object_get_string (action, "label"));
-    button = gtk_button_new_with_mnemonic (label);
-    gtk_box_pack_start (box, button, TRUE, TRUE, 4);
-    gtk_action_connect_proxy (action, button);
-    action = _action_by_name (browser, "AddNewsFeed");
-    katze_assign (label, katze_object_get_string (action, "label"));
-    button = gtk_button_new_with_mnemonic (label);
-    gtk_box_pack_start (box, button, TRUE, TRUE, 4);
-    gtk_action_connect_proxy (action, button);
-
-    g_free (label);
-
-    gtk_dialog_run (GTK_DIALOG (dialog));
+    for (i = 0; i < G_N_ELEMENTS (actions); i++)
+    {
+        gchar* label;
+        GtkWidget* button;
+
+        action = _action_by_name (browser, actions[i]);
+        label = katze_object_get_string (action, "label");
+        button = gtk_button_new_with_mnemonic (label);
+        g_free (label);
+        gtk_widget_set_name (button, "GtkButton-thumb");
+        gtk_box_pack_start (box, button, TRUE, TRUE, 4);
+        gtk_action_connect_proxy (action, button);
+        g_signal_connect_swapped (button, "clicked",
+                                  G_CALLBACK (gtk_widget_destroy), dialog);
+    }
+
+    gtk_widget_show (dialog);
+    g_signal_connect_swapped (dialog, "response",
+                              G_CALLBACK (gtk_widget_destroy), dialog);
 }
 
 static void
@@ -3455,8 +3442,8 @@ _action_source_view_activate (GtkAction*     action,
         {
             if (!sokoke_show_uri_with_mime_type (gtk_widget_get_screen (view),
                 uri, "text/plain", gtk_get_current_event_time (), &error))
-                sokoke_error_dialog (_("Could not run external program."),
-                    error ? error->message : "");
+                sokoke_message_dialog (GTK_MESSAGE_ERROR,
+                    _("Could not run external program."), error ? error->message : "");
             if (error)
                 g_error_free (error);
             g_free (text_editor);
index 373c52fe3abe22ab0821f95ed8101fd6f697cdf4..823662adfec1e4002307cbbee488f295288acac3 100644 (file)
@@ -46,6 +46,7 @@
 
 #if HAVE_HILDON
     #include <libosso.h>
+    #include <hildon/hildon.h>
     #include <hildon-mime.h>
     #include <hildon-uri.h>
 #endif
@@ -97,16 +98,23 @@ sokoke_js_script_eval (JSContextRef js_context,
 }
 
 void
-sokoke_error_dialog (const gchar* short_message,
-                     const gchar* detailed_message)
+sokoke_message_dialog (GtkMessageType message_type,
+                       const gchar*   short_message,
+                       const gchar*   detailed_message)
 {
     GtkWidget* dialog = gtk_message_dialog_new (
-        NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", short_message);
+        NULL, 0, message_type,
+        #if HAVE_HILDON
+        GTK_BUTTONS_NONE,
+        #else
+        GTK_BUTTONS_OK,
+        #endif
+        "%s", short_message);
     gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                               "%s", detailed_message);
-    gtk_widget_show (dialog);
     g_signal_connect_swapped (dialog, "response",
                               G_CALLBACK (gtk_widget_destroy), dialog);
+    gtk_widget_show (dialog);
 }
 
 /**
@@ -263,8 +271,9 @@ sokoke_spawn_program (const gchar* command,
         osso = osso_initialize (PACKAGE_NAME, PACKAGE_VERSION, FALSE, NULL);
         if (!osso)
         {
-            sokoke_error_dialog (_("Could not run external program."),
-                                 "Failed to initialize libosso");
+            sokoke_message_dialog (GTK_MESSAGE_ERROR,
+                                   _("Could not run external program."),
+                                   "Failed to initialize libosso");
             return FALSE;
         }
 
@@ -272,8 +281,9 @@ sokoke_spawn_program (const gchar* command,
         if (!dbus)
         {
             osso_deinitialize (osso);
-            sokoke_error_dialog (_("Could not run external program."),
-                                 "Failed to get dbus connection from osso context");
+            sokoke_message_dialog (GTK_MESSAGE_ERROR,
+                                   _("Could not run external program."),
+                                   "Failed to get dbus connection from osso context");
             return FALSE;
         }
 
@@ -299,7 +309,8 @@ sokoke_spawn_program (const gchar* command,
 
         if (!success)
         {
-            sokoke_error_dialog (_("Could not run external program."),
+            sokoke_message_dialog (GTK_MESSAGE_ERROR,
+                _("Could not run external program."),
                 error ? error->message : "");
             if (error)
                 g_error_free (error);
@@ -320,8 +331,9 @@ sokoke_spawn_program (const gchar* command,
         error = NULL;
         if (!g_shell_parse_argv (command_ready, NULL, &argv, &error))
         {
-            sokoke_error_dialog (_("Could not run external program."),
-                                 error->message);
+            sokoke_message_dialog (GTK_MESSAGE_ERROR,
+                                   _("Could not run external program."),
+                                   error->message);
             g_error_free (error);
             g_free (command_ready);
             return FALSE;
@@ -333,8 +345,9 @@ sokoke_spawn_program (const gchar* command,
             (GSpawnFlags)G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
             NULL, NULL, NULL, &error))
         {
-            sokoke_error_dialog (_("Could not run external program."),
-                                 error->message);
+            sokoke_message_dialog (GTK_MESSAGE_ERROR,
+                                   _("Could not run external program."),
+                                   error->message);
             g_error_free (error);
         }
 
index c16e284c3ee7358e6d7d7e989868f1d4a6b99b18..5f805a335b6f4c087ffbebb487409f5ade1e781d 100644 (file)
@@ -27,7 +27,8 @@ sokoke_js_script_eval                   (JSContextRef    js_context,
 #define GTK_ICON_SIZE_SMALL_TOOLBAR GTK_ICON_SIZE_BUTTON
 
 void
-sokoke_error_dialog                     (const gchar*    short_message,
+sokoke_message_dialog                   (GtkMessageType  message_type,
+                                         const gchar*    short_message,
                                          const gchar*    detailed_message);
 
 gboolean