[gnome-settings-daemon] updates: Do not show multiple notifications when updates are available



commit a6a5d13daf711a3bb017061a0311d91c1a8eb283
Author: Richard Hughes <richard hughsie com>
Date:   Mon Sep 30 15:43:00 2013 +0100

    updates: Do not show multiple notifications when updates are available
    
    We were showing a notification after we have finished preparing the update from
    two different code paths. Merge them, so we only do one notification and do the
    correct thing for gnome-software or gnome-software-less installs.

 plugins/updates/gsd-updates-manager.c |  179 ++++++++------------------------
 1 files changed, 45 insertions(+), 134 deletions(-)
---
diff --git a/plugins/updates/gsd-updates-manager.c b/plugins/updates/gsd-updates-manager.c
index 3a3d181..901840e 100644
--- a/plugins/updates/gsd-updates-manager.c
+++ b/plugins/updates/gsd-updates-manager.c
@@ -66,13 +66,11 @@ struct GsdUpdatesManagerPrivate
         GVolumeMonitor          *volume_monitor;
         guint                    failed_get_updates_count;
         GPtrArray               *update_packages;
-        GFile                   *offline_update_file;
-        GFileMonitor            *offline_update_monitor;
-        gboolean                 offline_update_notified;
 };
 
 static void gsd_updates_manager_class_init (GsdUpdatesManagerClass *klass);
 static void gsd_updates_manager_init (GsdUpdatesManager *updates_manager);
+static void restart_and_install_updates (void);
 
 G_DEFINE_TYPE (GsdUpdatesManager, gsd_updates_manager, G_TYPE_OBJECT)
 
@@ -283,6 +281,10 @@ libnotify_action_cb (NotifyNotification *notification,
                 show_offline_updates_error (manager);
                 goto out;
         }
+        if (g_strcmp0 (action, "install") == 0) {
+                restart_and_install_updates ();
+                goto out;
+        }
         if (g_strcmp0 (action, "cancel") == 0) {
                 /* try to cancel */
                 g_cancellable_cancel (manager->priv->cancellable);
@@ -521,9 +523,26 @@ notify_critical_updates (GsdUpdatesManager *manager, GPtrArray *array)
         notify_notification_set_app_name (notification, _("Software Updates"));
         notify_notification_set_timeout (notification, 15000);
         notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
-        notify_notification_add_action (notification, "show-update-viewer",
-                                        /* TRANSLATORS: button: open the update viewer to install updates*/
-                                        _("Install updates"), libnotify_action_cb, manager, NULL);
+        notify_notification_add_action (notification, "ignore",
+                                        /* TRANSLATORS: don't install updates now */
+                                        _("Not Now"),
+                                        libnotify_action_cb,
+                                        manager, NULL);
+        if (g_find_program_in_path ("gnome-software")) {
+                notify_notification_add_action (notification, "show-update-viewer",
+                                                /* TRANSLATORS: view available updates */
+                                                _("View"),
+                                                libnotify_action_cb, manager, NULL);
+                notify_notification_add_action (notification, "install",
+                                                /* TRANSLATORS: install available updates */
+                                                _("Restart & Install"),
+                                                libnotify_action_cb,
+                                                manager, NULL);
+        } else {
+                notify_notification_add_action (notification, "show-update-viewer",
+                                                /* TRANSLATORS: button: open the update viewer to install 
updates*/
+                                                _("Install updates"), libnotify_action_cb, manager, NULL);
+        }
         g_signal_connect (notification, "closed",
                           G_CALLBACK (on_notification_closed), NULL);
         ret = notify_notification_show (notification, &error);
@@ -585,9 +604,26 @@ notify_normal_updates_maybe (GsdUpdatesManager *manager, GPtrArray *array)
         notify_notification_set_app_name (notification, _("Software Updates"));
         notify_notification_set_timeout (notification, 15000);
         notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);
-        notify_notification_add_action (notification, "show-update-viewer",
-                                        /* TRANSLATORS: button: open the update viewer to install updates*/
-                                        _("Install updates"), libnotify_action_cb, manager, NULL);
+        notify_notification_add_action (notification, "ignore",
+                                        /* TRANSLATORS: don't install updates now */
+                                        _("Not Now"),
+                                        libnotify_action_cb,
+                                        manager, NULL);
+        if (g_find_program_in_path ("gnome-software")) {
+                notify_notification_add_action (notification, "show-update-viewer",
+                                                /* TRANSLATORS: view available updates */
+                                                _("View"),
+                                                libnotify_action_cb, manager, NULL);
+                notify_notification_add_action (notification, "install",
+                                                /* TRANSLATORS: install available updates */
+                                                _("Restart & Install"),
+                                                libnotify_action_cb,
+                                                manager, NULL);
+        } else {
+                notify_notification_add_action (notification, "show-update-viewer",
+                                                /* TRANSLATORS: button: open the update viewer to install 
updates*/
+                                                _("Install updates"), libnotify_action_cb, manager, NULL);
+        }
         g_signal_connect (notification, "closed",
                           G_CALLBACK (on_notification_closed), NULL);
         ret = notify_notification_show (notification, &error);
@@ -1371,120 +1407,6 @@ restart_and_install_updates (void)
         g_object_unref (bus);
 }
 
-static void
-view_updates (void)
-{
-        gboolean ret;
-        GError *error = NULL;
-
-        ret = g_spawn_command_line_async (BINDIR "/gnome-software --mode updates", &error);
-        if (!ret) {
-                g_warning ("Failure launching gnome-software: %s",
-                           error->message);
-                g_error_free (error);
-        }
-}
-
-static void
-offline_update_action_cb (NotifyNotification *notification,
-                          gchar              *action,
-                          gpointer            user_data)
-{
-
-        notify_notification_close (notification, NULL);
-
-        if (g_strcmp0 (action, "view") == 0) {
-                view_updates ();
-        }
-        else if (g_strcmp0 (action, "install") == 0) {
-                restart_and_install_updates ();
-        }
-}
-
-static gboolean
-reenable_offline_update (gpointer data)
-{
-        GsdUpdatesManager *manager = data;
-
-        manager->priv->offline_update_notified = FALSE;
-
-        return G_SOURCE_REMOVE;
-}
-
-static void
-notify_offline_update_available (GsdUpdatesManager *manager)
-{
-        NotifyNotification *notification;
-        const gchar *title;
-        const gchar *body;
-        gboolean ret;
-        GError *error = NULL;
-
-        if (!g_file_query_exists (manager->priv->offline_update_file, NULL))
-                return;
-
-        if (manager->priv->offline_update_notified)
-                return;
-
-        manager->priv->offline_update_notified = TRUE;
-
-        /* don't notify more often than every 5 minutes */
-        g_timeout_add_seconds (300, reenable_offline_update, manager);
-
-        title = _("Software Updates available");
-        body = _("Important OS and application updates are ready to be installed");
-        notification = notify_notification_new (title, body,
-                                                GSD_UPDATES_ICON_NORMAL);
-        notify_notification_set_hint_string (notification, "desktop-entry", "gnome-software");
-        notify_notification_set_app_name (notification, _("GNOME Software"));
-        notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
-        notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);
-        notify_notification_add_action (notification, "ignore",
-                                        /* TRANSLATORS: don't install updates now */
-                                        _("Not Now"),
-                                        offline_update_action_cb,
-                                        manager, NULL);
-        if (g_find_program_in_path ("gnome-software"))
-                notify_notification_add_action (notification, "view",
-                                                /* TRANSLATORS: view available updates */
-                                                _("View"),
-                                                offline_update_action_cb,
-                                                manager, NULL);
-        else
-                notify_notification_add_action (notification, "install",
-                                                /* TRANSLATORS: install available updates */
-                                                _("Restart & Install"),
-                                                offline_update_action_cb,
-                                                manager, NULL);
-        g_signal_connect (notification, "closed",
-                          G_CALLBACK (on_notification_closed), NULL);
-        ret = notify_notification_show (notification, &error);
-        if (!ret) {
-                g_warning ("error: %s", error->message);
-                g_error_free (error);
-        }
-}
-
-static void
-offline_update_cb (GFileMonitor      *monitor,
-                   GFile             *file,
-                   GFile             *other_file,
-                   GFileMonitorEvent  event_type,
-                   GsdUpdatesManager *manager)
-{
-        notify_offline_update_available (manager);
-}
-
-static gboolean
-initial_offline_update_check (gpointer data)
-{
-        GsdUpdatesManager *manager = data;
-
-        notify_offline_update_available (manager);
-
-        return G_SOURCE_REMOVE;
-}
-
 gboolean
 gsd_updates_manager_start (GsdUpdatesManager *manager,
                            GError **error)
@@ -1568,15 +1490,6 @@ gsd_updates_manager_start (GsdUpdatesManager *manager,
                                        check_offline_update_cb,
                                        manager);
 
-        manager->priv->offline_update_file = g_file_new_for_path ("/var/lib/PackageKit/prepared-update");
-        manager->priv->offline_update_monitor = g_file_monitor_file (manager->priv->offline_update_file, 0, 
NULL, NULL);
-        g_signal_connect (manager->priv->offline_update_monitor, "changed",
-                          G_CALLBACK (offline_update_cb), manager);
-
-        g_timeout_add_seconds (300,
-                               initial_offline_update_check,
-                               manager);
-
         /* success */
         ret = TRUE;
         g_debug ("Started updates manager");
@@ -1599,8 +1512,6 @@ gsd_updates_manager_stop (GsdUpdatesManager *manager)
         g_clear_object (&manager->priv->firmware);
         g_clear_object (&manager->priv->proxy_session);
         g_clear_object (&manager->priv->volume_monitor);
-        g_clear_object (&manager->priv->offline_update_file);
-        g_clear_object (&manager->priv->offline_update_monitor);
         if (manager->priv->cancellable) {
                 g_cancellable_cancel (manager->priv->cancellable);
                 g_clear_object (&manager->priv->cancellable);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]