]> spindle.queued.net Git - midori/commitdiff
Implement transfer completion notification via libnotify
authorChristian Dywan <christian@twotoasts.de>
Sun, 26 Apr 2009 22:22:16 +0000 (00:22 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sun, 26 Apr 2009 22:22:16 +0000 (00:22 +0200)
midori/midori-browser.c
midori/midori-view.c
midori/midori-websettings.c
midori/sokoke.c
midori/sokoke.h

index f4dfae808c4f372698b51264a4782dd2227c1774..bee9839769f4c9608b375f8f62e77c3ac4049f05 100644 (file)
@@ -900,6 +900,9 @@ midori_browser_download_notify_status_cb (WebKitDownload* download,
     switch (webkit_download_get_status (download))
     {
         case WEBKIT_DOWNLOAD_STATUS_FINISHED:
+        {
+            MidoriBrowser* browser = midori_browser_get_for_widget (button);
+
             icon = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
             gtk_button_set_image (GTK_BUTTON (button), icon);
             if (g_object_get_data (G_OBJECT (download), "open-download"))
@@ -907,6 +910,28 @@ midori_browser_download_notify_status_cb (WebKitDownload* download,
             else
                 g_object_set_data (G_OBJECT (gtk_widget_get_parent (button)),
                                    "done", (void*)1);
+
+            if (browser->settings && katze_object_get_boolean (
+                browser->settings, "notify-transfer-completed"))
+            {
+                gchar* program = g_find_program_in_path ("notify-send");
+                if (program != NULL)
+                {
+                    gchar* msg = g_strdup_printf (
+                        _("The file <b>%s</b> has been downloaded."),
+                        webkit_download_get_suggested_filename (download));
+                    gchar* msgq = g_shell_quote (msg);
+                    gchar* titleq = g_shell_quote (_("Transfer completed"));
+                    gchar* command = g_strconcat (titleq, " ", msgq, NULL);
+                    g_free (msg);
+                    g_free (titleq);
+                    g_free (msgq);
+                    sokoke_spawn_program ("notify-send -i midori %s", command, FALSE);
+                    g_free (command);
+                    g_free (program);
+                }
+            }
+        }
             break;
         case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
         case WEBKIT_DOWNLOAD_STATUS_ERROR:
@@ -2428,7 +2453,7 @@ midori_browser_source_transfer_cb (KatzeNetRequest* request,
                 g_object_get (browser->settings,
                     "text-editor", &text_editor, NULL);
                 if (text_editor && *text_editor)
-                    sokoke_spawn_program (text_editor, unique_filename);
+                    sokoke_spawn_program (text_editor, unique_filename, TRUE);
                 else
                     sokoke_show_uri (NULL, unique_filename,
                                      gtk_get_current_event_time (), NULL);
@@ -2621,7 +2646,7 @@ _action_location_secondary_icon_released (GtkAction*     action,
     {
         const gchar* uri = midori_view_get_display_uri (MIDORI_VIEW (view));
         if (browser->news_aggregator && *browser->news_aggregator)
-            sokoke_spawn_program (browser->news_aggregator, uri);
+            sokoke_spawn_program (browser->news_aggregator, uri, TRUE);
     }
 }
 
index f5d9cebe1124fb66f4fb308ca109cf6e6a64ba16..426271e5b5f5ee9c943bf83016101072064d76af 100644 (file)
@@ -926,7 +926,7 @@ static void
 midori_web_view_menu_download_activate_cb (GtkWidget*  widget,
                                            MidoriView* view)
 {
-    sokoke_spawn_program (view->download_manager, view->link_uri);
+    sokoke_spawn_program (view->download_manager, view->link_uri, TRUE);
 }
 
 static void
index e9a4609c7c083641e8cc9c9cc7637bb29ad99a3f..fb903b86f631ea12cef33a7d01eab24db5706848 100644 (file)
@@ -50,6 +50,7 @@ struct _MidoriWebSettings
     gchar* homepage;
     gboolean show_crash_dialog;
     gchar* download_folder;
+    gboolean notify_transfer_completed;
     gchar* download_manager;
     gchar* text_editor;
     gchar* news_aggregator;
@@ -120,6 +121,7 @@ enum
     PROP_HOMEPAGE,
     PROP_SHOW_CRASH_DIALOG,
     PROP_DOWNLOAD_FOLDER,
+    PROP_NOTIFY_TRANSFER_COMPLETED,
     PROP_DOWNLOAD_MANAGER,
     PROP_TEXT_EDITOR,
     PROP_NEWS_AGGREGATOR,
@@ -580,6 +582,26 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
                                      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
     #endif
 
+    /**
+     * MidoriWebSettings:notify-transfer-completed:
+     *
+     * Whether to show a notification when a transfer has been completed.
+     *
+     * Since: 0.1.7
+     */
+    g_object_class_install_property (gobject_class,
+                                     PROP_NOTIFY_TRANSFER_COMPLETED,
+                                     g_param_spec_boolean (
+                                     "notify-transfer-completed",
+                                     _("Notify when a transfer has been completed"),
+                                     _("Whether to show a notification when a transfer has been completed"),
+                                     TRUE,
+    #if WEBKIT_CHECK_VERSION (1, 1, 3)
+                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+    #else
+                                     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+    #endif
+
     g_object_class_install_property (gobject_class,
                                      PROP_DOWNLOAD_MANAGER,
                                      g_param_spec_string (
@@ -912,6 +934,7 @@ notify_default_encoding_cb (GObject*    object,
 static void
 midori_web_settings_init (MidoriWebSettings* web_settings)
 {
+    web_settings->notify_transfer_completed = TRUE;
     web_settings->download_folder = g_strdup (midori_get_download_dir ());
     web_settings->http_proxy = NULL;
     web_settings->open_popups_in_tabs = TRUE;
@@ -1077,6 +1100,9 @@ midori_web_settings_set_property (GObject*      object,
     case PROP_DOWNLOAD_FOLDER:
         katze_assign (web_settings->download_folder, g_value_dup_string (value));
         break;
+    case PROP_NOTIFY_TRANSFER_COMPLETED:
+        web_settings->notify_transfer_completed = g_value_get_boolean (value);
+        break;
     case PROP_DOWNLOAD_MANAGER:
         katze_assign (web_settings->download_manager, g_value_dup_string (value));
         break;
@@ -1276,6 +1302,9 @@ midori_web_settings_get_property (GObject*    object,
     case PROP_DOWNLOAD_FOLDER:
         g_value_set_string (value, web_settings->download_folder);
         break;
+    case PROP_NOTIFY_TRANSFER_COMPLETED:
+        g_value_set_boolean (value, web_settings->notify_transfer_completed);
+        break;
     case PROP_DOWNLOAD_MANAGER:
         g_value_set_string (value, web_settings->download_manager);
         break;
index 1330378f55523d6e3b00378b25c921720fe3ce64..4802abecef756884bc85522b0cc909caeca9d68e 100644 (file)
@@ -139,7 +139,8 @@ sokoke_show_uri (GdkScreen*   screen,
 
 gboolean
 sokoke_spawn_program (const gchar* command,
-                      const gchar* argument)
+                      const gchar* argument,
+                      gboolean     quote)
 {
     gchar* argument_escaped;
     gchar* command_ready;
@@ -149,7 +150,7 @@ sokoke_spawn_program (const gchar* command,
     g_return_val_if_fail (command != NULL, FALSE);
     g_return_val_if_fail (argument != NULL, FALSE);
 
-    argument_escaped = g_shell_quote (argument);
+    argument_escaped = quote ? g_shell_quote (argument) : g_strdup (argument);
     if (strstr (command, "%s"))
         command_ready = g_strdup_printf (command, argument_escaped);
     else
index 61d80c3cec45d50d1518c6671a0ba1b6862f7768..d750f2f3fc7fa32d53be9e7ae434f5037924d08a 100644 (file)
@@ -35,7 +35,8 @@ sokoke_show_uri                         (GdkScreen*      screen,
 
 gboolean
 sokoke_spawn_program                    (const gchar*    command,
-                                         const gchar*    argument);
+                                         const gchar*    argument,
+                                         gboolean        quote);
 
 gchar* sokoke_search_uri                (const gchar*    uri,
                                          const gchar*    keywords);