From d328d2afabd0f86153b4027e8f87c0f4fd0e3fa5 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Mon, 27 Apr 2009 00:22:16 +0200 Subject: [PATCH] Implement transfer completion notification via libnotify --- midori/midori-browser.c | 29 +++++++++++++++++++++++++++-- midori/midori-view.c | 2 +- midori/midori-websettings.c | 29 +++++++++++++++++++++++++++++ midori/sokoke.c | 5 +++-- midori/sokoke.h | 3 ++- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index f4dfae80..bee98397 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -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 %s 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); } } diff --git a/midori/midori-view.c b/midori/midori-view.c index f5d9cebe..426271e5 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -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 diff --git a/midori/midori-websettings.c b/midori/midori-websettings.c index e9a4609c..fb903b86 100644 --- a/midori/midori-websettings.c +++ b/midori/midori-websettings.c @@ -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; diff --git a/midori/sokoke.c b/midori/sokoke.c index 1330378f..4802abec 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -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 diff --git a/midori/sokoke.h b/midori/sokoke.h index 61d80c3c..d750f2f3 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -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); -- 2.39.5