[gnome-software] Port GsUpdateMonitor to use the plugin loader



commit 149a03ea1c3851b250923a6c187c60bbea77079a
Author: Richard Hughes <richard hughsie com>
Date:   Mon Sep 28 10:09:46 2015 +0100

    Port GsUpdateMonitor to use the plugin loader
    
    This ensures we 'prime' both PackageKit and the AppStream plugin caches and
    means we can return results to the updates panel much faster.
    This also makes the code much simpler as we now only have one place files are
    downloaded, and only one place where the offline update is prepared.
    
    As a bonus, it also makes the notification work for firmware updates provided
    by fwupd and any future plugin like ostree.

 src/gs-update-monitor.c |  520 ++++++++++++++++-------------------------------
 1 files changed, 177 insertions(+), 343 deletions(-)
---
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index 78a51fb..765a61f 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2013-2015 Richard Hughes <richard hughsie com>
  * Copyright (C) 2013 Matthias Clasen <mclasen redhat com>
  *
  * Licensed under the GNU General Public License Version 2
@@ -28,6 +28,7 @@
 #include <gsettings-desktop-schemas/gdesktop-enums.h>
 
 #include "gs-update-monitor.h"
+#include "gs-plugin-loader.h"
 #include "gs-utils.h"
 #include "gs-offline-updates.h"
 
@@ -36,24 +37,14 @@ struct _GsUpdateMonitor {
 
        GApplication    *application;
        GCancellable    *cancellable;
-
-       guint            check_hourly_id;
-       guint            start_hourly_checks_id;
-       GDateTime       *check_timestamp;
-       GDateTime       *install_timestamp;
-       gboolean         refresh_cache_due;
-       gboolean         get_updates_due;
-       gboolean         network_available;
-       gchar           **pending_downloads;
-       PkTask          *task;
-       PkControl       *control;
        GSettings       *settings;
+       GsPluginLoader  *plugin_loader;
 
-       GFile           *offline_update_file;
-       GFileMonitor    *offline_update_monitor;
-       gboolean         offline_update_notified;
-       guint            reenable_offline_update_id;
-       guint            check_offline_update_id;
+       guint            cleanup_notifications_id;      /* at startup */
+       guint            check_startup_id;              /* 60s after startup */
+       guint            check_hourly_id;               /* and then every hour */
+       PkControl       *control;                       /* network type detection */
+       guint            notification_blocked_id;       /* rate limit notifications */
 };
 
 G_DEFINE_TYPE (GsUpdateMonitor, gs_update_monitor, G_TYPE_OBJECT)
@@ -62,11 +53,7 @@ static gboolean
 reenable_offline_update_notification (gpointer data)
 {
        GsUpdateMonitor *monitor = data;
-
-       monitor->offline_update_notified = FALSE;
-
-       monitor->reenable_offline_update_id = 0;
-
+       monitor->notification_blocked_id = 0;
        return G_SOURCE_REMOVE;
 }
 
@@ -79,19 +66,13 @@ notify_offline_update_available (GsUpdateMonitor *monitor)
        guint64 security_timestamp = 0;
        g_autoptr(GNotification) n = NULL;
 
-       if (!g_file_query_exists (monitor->offline_update_file, NULL))
-               return;
-
-       if (monitor->offline_update_notified)
-               return;
-
        if (gs_application_has_active_window (GS_APPLICATION (monitor->application)))
                return;
-
-       monitor->offline_update_notified = TRUE;
+       if (monitor->notification_blocked_id > 0)
+               return;
 
        /* rate limit update notifications to once per hour */
-       monitor->reenable_offline_update_id = g_timeout_add_seconds (3600, 
reenable_offline_update_notification, monitor);
+       monitor->notification_blocked_id = g_timeout_add_seconds (3600, reenable_offline_update_notification, 
monitor);
 
        /* get time in days since we saw the first unapplied security update */
        g_settings_get (monitor->settings,
@@ -124,111 +105,17 @@ notify_offline_update_available (GsUpdateMonitor *monitor)
        }
 }
 
-static void
-offline_update_monitor_cb (GFileMonitor      *file_monitor,
-                          GFile             *file,
-                          GFile             *other_file,
-                          GFileMonitorEvent  event_type,
-                          GsUpdateMonitor   *monitor)
-{
-       if (!g_file_query_exists (monitor->offline_update_file, NULL)) {
-               g_debug ("prepared update removed; withdrawing updates-available notification");
-               g_application_withdraw_notification (monitor->application,
-                                                    "updates-available");
-               return;
-       }
-
-       notify_offline_update_available (monitor);
-}
-
-static void
-start_monitoring_offline_updates (GsUpdateMonitor *monitor)
-{
-       monitor->offline_update_monitor = g_file_monitor_file (monitor->offline_update_file, 0, NULL, NULL);
-
-       g_signal_connect (monitor->offline_update_monitor, "changed",
-                         G_CALLBACK (offline_update_monitor_cb), monitor);
-}
-
-static void
-show_installed_updates_notification (GsUpdateMonitor *monitor)
-{
-       const gchar *message;
-       const gchar *title;
-       g_autoptr(GNotification) notification = NULL;
-       g_autoptr(PkResults) results = NULL;
-
-       results = pk_offline_get_results (NULL);
-       if (results == NULL)
-               return;
-       if (pk_results_get_exit_code (results) == PK_EXIT_ENUM_SUCCESS) {
-               GPtrArray *packages;
-               packages = pk_results_get_package_array (results);
-               title = ngettext ("Software Update Installed",
-                                 "Software Updates Installed",
-                                 packages->len);
-               /* TRANSLATORS: message when we've done offline updates */
-               message = ngettext ("An important OS update has been installed.",
-                                   "Important OS updates have been installed.",
-                                   packages->len);
-               g_ptr_array_unref (packages);
-       } else {
-
-               title = _("Software Updates Failed");
-               /* TRANSLATORS: message when we offline updates have failed */
-               message = _("An important OS update failed to be installed.");
-       }
-
-       notification = g_notification_new (title);
-       g_notification_set_body (notification, message);
-       if (pk_results_get_exit_code (results) == PK_EXIT_ENUM_SUCCESS) {
-               g_notification_add_button_with_target (notification, _("Review"), "app.set-mode", "s", 
"updated");
-               g_notification_set_default_action_and_target (notification, "app.set-mode", "s", "updated");
-       } else {
-               g_notification_add_button (notification, _("Show Details"), "app.show-offline-update-error");
-               g_notification_set_default_action (notification, "app.show-offline-update-error");
-       }
-
-       g_application_send_notification (monitor->application, "offline-updates", notification);
-}
-
-static gboolean
-check_offline_update_cb (gpointer user_data)
-{
-       GsUpdateMonitor *monitor = user_data;
-       guint64 time_last_notified;
-       guint64 time_update_completed;
-
-       g_settings_get (monitor->settings,
-                       "install-timestamp", "x", &time_last_notified);
-
-       time_update_completed = pk_offline_get_results_mtime (NULL);
-       if (time_update_completed > 0) {
-               if (time_last_notified < time_update_completed)
-                       show_installed_updates_notification (monitor);
-
-               g_settings_set (monitor->settings,
-                               "install-timestamp", "x", time_update_completed);
-       }
-
-       start_monitoring_offline_updates (monitor);
-
-       monitor->check_offline_update_id = 0;
-
-       return G_SOURCE_REMOVE;
-}
-
 static gboolean
-has_important_updates (GPtrArray *packages)
+has_important_updates (GsAppList *apps)
 {
-       guint i;
-       PkPackage *pkg;
-
-       for (i = 0; i < packages->len; i++) {
-               pkg = g_ptr_array_index (packages, i);
-               if (pk_package_get_info (pkg) == PK_INFO_ENUM_SECURITY ||
-                   pk_package_get_info (pkg) == PK_INFO_ENUM_IMPORTANT)
-                       return TRUE;    
+       GList *l;
+       GsApp *app;
+
+       for (l = apps; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (gs_app_get_update_severity (app) == GS_APP_UPDATE_SEVERITY_SECURITY ||
+                   gs_app_get_update_severity (app) == GS_APP_UPDATE_SEVERITY_IMPORTANT)
+                       return TRUE;
        }
 
        return FALSE;
@@ -254,7 +141,6 @@ no_updates_for_a_week (GsUpdateMonitor *monitor)
 
        now = g_date_time_new_now_local ();
        d = g_date_time_difference (now, last_update);
-
        if (d >= 7 * G_TIME_SPAN_DAY)
                return TRUE;
 
@@ -262,93 +148,36 @@ no_updates_for_a_week (GsUpdateMonitor *monitor)
 }
 
 static void
-package_download_finished_cb (GObject *object,
-                             GAsyncResult *res,
-                             gpointer data)
-{
-       GsUpdateMonitor *monitor = data;
-       g_autoptr(GError) error = NULL;
-       g_autoptr(PkError) error_code = NULL;
-       g_autoptr(PkResults) results = NULL;
-
-       results = pk_client_generic_finish (PK_CLIENT (object), res, &error);
-       if (results == NULL) {
-               if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
-                       g_warning ("failed to download: %s", error->message);
-               return;
-       }
-
-       error_code = pk_results_get_error_code (results);
-       if (error_code != NULL) {
-               g_warning ("failed to download: %s, %s",
-                          pk_error_enum_to_string (pk_error_get_code (error_code)),
-                          pk_error_get_details (error_code));
-               return;
-       }
-
-       g_debug ("Downloaded updates");
-       g_clear_pointer (&monitor->pending_downloads, g_strfreev);
-}
-
-static void
-download_updates (GsUpdateMonitor *monitor)
-{
-       if (monitor->pending_downloads == NULL)
-               return;
-
-       if (!monitor->network_available)
-               return;
-
-       g_debug ("Downloading updates");
-
-       pk_task_update_packages_async (monitor->task,
-                                      monitor->pending_downloads,
-                                      monitor->cancellable,
-                                      NULL, NULL,
-                                      package_download_finished_cb,
-                                      monitor);
-}
-
-static void
 get_updates_finished_cb (GObject *object,
                         GAsyncResult *res,
                         gpointer data)
 {
        GsUpdateMonitor *monitor = data;
+       GList *l;
+       GsApp *app;
        guint64 security_timestamp = 0;
        guint64 security_timestamp_old = 0;
-       guint i;
-       PkPackage *pkg;
        g_autoptr(GError) error = NULL;
        g_autoptr(PkError) error_code = NULL;
-       g_autoptr(PkResults) results = NULL;
-       g_autoptr(GPtrArray) packages = NULL;
+       g_autoptr(GsAppList) apps = NULL;
 
-       results = pk_client_generic_finish (PK_CLIENT (object), res, &error);
-       if (results == NULL) {
+       /* get result */
+       apps = gs_plugin_loader_get_updates_finish (GS_PLUGIN_LOADER (object), res, &error);
+       if (apps == NULL) {
+               g_debug ("no updates; withdrawing updates-available notification");
+               g_application_withdraw_notification (monitor->application,
+                                                    "updates-available");
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
                        g_warning ("failed to get updates: %s", error->message);
                return;
        }
 
-       error_code = pk_results_get_error_code (results);
-       if (error_code != NULL) {
-               g_warning ("failed to get updates: %s, %s",
-                          pk_error_enum_to_string (pk_error_get_code (error_code)),
-                          pk_error_get_details (error_code));
-               return;
-       }
-
-       /* we succeeded */
-       monitor->get_updates_due = FALSE;
-
        /* find security updates, or clear timestamp if there are now none */
-       packages = pk_results_get_package_array (results);
        g_settings_get (monitor->settings,
                        "security-timestamp", "x", &security_timestamp_old);
-       for (i = 0; i < packages->len; i++) {
-               pkg = (PkPackage *)g_ptr_array_index (packages, i);
-               if (pk_package_get_info (pkg) == PK_INFO_ENUM_SECURITY) {
+       for (l = apps; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (gs_app_get_metadata_item (app, "is-security") != NULL) {
                        security_timestamp = g_get_monotonic_time ();
                        break;
                }
@@ -358,39 +187,26 @@ get_updates_finished_cb (GObject *object,
                                "security-timestamp", "x", security_timestamp);
        }
 
-       g_debug ("Got %d updates", packages->len);
+       g_debug ("Got %d updates", g_list_length (apps));
 
-       if (has_important_updates (packages) ||
+       if (has_important_updates (apps) ||
            no_updates_for_a_week (monitor)) {
-
-               monitor->pending_downloads = g_new0 (gchar *, packages->len + 1);
-               for (i = 0; i < packages->len; i++) {
-                       pkg = (PkPackage *)g_ptr_array_index (packages, i);
-                       monitor->pending_downloads[i] = g_strdup (pk_package_get_id (pkg));
-               }
-               monitor->pending_downloads[packages->len] = NULL;
-
-               download_updates (monitor);
+               notify_offline_update_available (monitor);
        }
 }
 
 static void
 get_updates (GsUpdateMonitor *monitor)
 {
-       if (monitor->refresh_cache_due)
-               return;
-
-       if (!monitor->get_updates_due)
-               return;
-
+       /* NOTE: this doesn't actually do any network access, instead it just
+        * returns already downloaded-and-depsolved packages */
        g_debug ("Getting updates");
-
-       pk_client_get_updates_async (PK_CLIENT (monitor->task),
-                                    pk_bitfield_value (PK_FILTER_ENUM_NONE),
-                                    monitor->cancellable,
-                                    NULL, NULL,
-                                    get_updates_finished_cb,
-                                    monitor);
+       gs_plugin_loader_get_updates_async (monitor->plugin_loader,
+                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS |
+                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_SEVERITY,
+                                           monitor->cancellable,
+                                           get_updates_finished_cb,
+                                           monitor);
 }
 
 static void
@@ -400,55 +216,32 @@ refresh_cache_finished_cb (GObject *object,
 {
        GsUpdateMonitor *monitor = data;
        g_autoptr(GError) error = NULL;
-       g_autoptr(PkError) error_code = NULL;
-       g_autoptr(PkResults) results = NULL;
 
-       results = pk_client_generic_finish (PK_CLIENT (object), res, &error);
-       if (results == NULL) {
+       if (!gs_plugin_loader_refresh_finish (GS_PLUGIN_LOADER (object), res, &error)) {
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
                        g_warning ("failed to refresh the cache: %s", error->message);
                return;
        }
-
-       error_code = pk_results_get_error_code (results);
-       if (error_code != NULL) {
-               g_warning ("failed to refresh the cache: %s, %s",
-                          pk_error_enum_to_string (pk_error_get_code (error_code)),
-                          pk_error_get_details (error_code));
-               return;
-       }
-
-       monitor->refresh_cache_due = FALSE;
-
        get_updates (monitor);
 }
 
 static void
-refresh_cache (GsUpdateMonitor *monitor)
-{
-       if (!monitor->refresh_cache_due)
-               return;
-
-       if (!monitor->network_available)
-               return;
-
-       g_debug ("Refreshing cache");
-       pk_client_refresh_cache_async (PK_CLIENT (monitor->task),
-                                      TRUE,
-                                      monitor->cancellable,
-                                      NULL, NULL,
-                                      refresh_cache_finished_cb,
-                                      monitor);
-}
-
-static void
 check_updates (GsUpdateMonitor *monitor)
 {
-       /* no need to check again */    
-       if (monitor->refresh_cache_due)
+       PkNetworkEnum network_state;
+       gint64 tmp;
+       g_autoptr(GDateTime) last_refreshed = NULL;
+       g_autoptr(GDateTime) now_refreshed = NULL;
+
+       /* never refresh when offline or on mobile connections */
+       g_object_get (monitor->control, "network-state", &network_state, NULL);
+       if (network_state == PK_NETWORK_ENUM_OFFLINE ||
+           network_state == PK_NETWORK_ENUM_MOBILE)
                return;
 
-       if (monitor->check_timestamp != NULL) {
+       g_settings_get (monitor->settings, "check-timestamp", "x", &tmp);
+       last_refreshed = g_date_time_new_from_unix_local (tmp);
+       if (last_refreshed != NULL) {
                gint now_year, now_month, now_day, now_hour;
                gint year, month, day;
                g_autoptr(GDateTime) now = NULL;
@@ -458,7 +251,7 @@ check_updates (GsUpdateMonitor *monitor)
                g_date_time_get_ymd (now, &now_year, &now_month, &now_day);
                now_hour = g_date_time_get_hour (now);
 
-               g_date_time_get_ymd (monitor->check_timestamp, &year, &month, &day);
+               g_date_time_get_ymd (last_refreshed, &year, &month, &day);
 
                /* check that it is the next day */
                if (!((now_year > year) ||
@@ -469,20 +262,23 @@ check_updates (GsUpdateMonitor *monitor)
                /* ...and past 6am */
                if (!(now_hour >= 6))
                        return;
-
-               g_clear_pointer (&monitor->check_timestamp, g_date_time_unref);
        }
 
        g_debug ("Daily update check due");
-
-       monitor->check_timestamp = g_date_time_new_now_local ();
+       now_refreshed = g_date_time_new_now_local ();
        g_settings_set (monitor->settings, "check-timestamp", "x",
-                       g_date_time_to_unix (monitor->check_timestamp));
+                       g_date_time_to_unix (now_refreshed));
 
-       monitor->refresh_cache_due = TRUE;
-       monitor->get_updates_due = TRUE;
-
-       refresh_cache (monitor);
+       /* NOTE: this doesn't actually refresh the cache, it actually just checks
+        * for updates (which might happen to also refresh the cache as a side
+        * effect) and then downloads new packages */
+       g_debug ("Refreshing cache");
+       gs_plugin_loader_refresh_async (monitor->plugin_loader,
+                                       60 * 60 * 24,
+                                       GS_PLUGIN_REFRESH_FLAGS_UPDATES,
+                                       monitor->cancellable,
+                                       refresh_cache_finished_cb,
+                                       monitor);
 }
 
 static gboolean
@@ -497,7 +293,7 @@ check_hourly_cb (gpointer data)
 }
 
 static gboolean
-start_hourly_checks_cb (gpointer data)
+check_updates_on_startup_cb (gpointer data)
 {
        GsUpdateMonitor *monitor = data;
 
@@ -507,7 +303,7 @@ start_hourly_checks_cb (gpointer data)
        monitor->check_hourly_id =
                g_timeout_add_seconds (3600, check_hourly_cb, monitor);
 
-       monitor->start_hourly_checks_id = 0;
+       monitor->check_startup_id = 0;
        return G_SOURCE_REMOVE;
 }
 
@@ -516,52 +312,112 @@ notify_network_state_cb (PkControl *control,
                         GParamSpec *pspec,
                         GsUpdateMonitor *monitor)
 {
-       PkNetworkEnum network_state;
-       gboolean available;
+       check_updates (monitor);
+}
 
-       g_object_get (control, "network-state", &network_state, NULL);
-       
-       if (network_state == PK_NETWORK_ENUM_OFFLINE ||
-           network_state == PK_NETWORK_ENUM_MOBILE)
-               available = FALSE;
-       else
-               available = TRUE;
+static void
+updates_changed_cb (GsPluginLoader *plugin_loader, GsUpdateMonitor *monitor)
+{
+       /* when the list of downloaded-and-ready-to-go updates changes get the
+        * new list and perhaps show/hide the notification */
+       get_updates (monitor);
+}
+
+static void
+show_installed_updates_notification (GsUpdateMonitor *monitor, PkResults *results)
+{
+       const gchar *message;
+       const gchar *title;
+       guint64 time_last_notified;
+       guint64 time_update_completed;
+       g_autoptr(GNotification) notification = NULL;
+
+       g_settings_get (monitor->settings,
+                       "install-timestamp", "x", &time_last_notified);
+
+       /* have we notified about this before */
+       time_update_completed = pk_offline_get_results_mtime (NULL);
+       if (time_update_completed == 0) {
+               /* FIXME: is this ever going to be true? */
+               g_application_withdraw_notification (monitor->application,
+                                                    "offline-updates");
+               return;
+       }
+       if (time_last_notified >= time_update_completed)
+               return;
 
-       if (monitor->network_available != available) {
-               monitor->network_available = available;
+       if (pk_results_get_exit_code (results) == PK_EXIT_ENUM_SUCCESS) {
+               GPtrArray *packages;
+               packages = pk_results_get_package_array (results);
+               title = ngettext ("Software Update Installed",
+                                 "Software Updates Installed",
+                                 packages->len);
+               /* TRANSLATORS: message when we've done offline updates */
+               message = ngettext ("An important OS update has been installed.",
+                                   "Important OS updates have been installed.",
+                                   packages->len);
+               g_ptr_array_unref (packages);
+       } else {
+
+               title = _("Software Updates Failed");
+               /* TRANSLATORS: message when we offline updates have failed */
+               message = _("An important OS update failed to be installed.");
+       }
 
-               /* resume any pending operations */
-               refresh_cache (monitor);
-               get_updates (monitor);
-               download_updates (monitor);
+       notification = g_notification_new (title);
+       g_notification_set_body (notification, message);
+       if (pk_results_get_exit_code (results) == PK_EXIT_ENUM_SUCCESS) {
+               g_notification_add_button_with_target (notification, _("Review"), "app.set-mode", "s", 
"updated");
+               g_notification_set_default_action_and_target (notification, "app.set-mode", "s", "updated");
+       } else {
+               g_notification_add_button (notification, _("Show Details"), "app.show-offline-update-error");
+               g_notification_set_default_action (notification, "app.show-offline-update-error");
        }
+
+       g_application_send_notification (monitor->application, "offline-updates", notification);
+
+       /* update the timestamp so we don't show again */
+       g_settings_set (monitor->settings,
+                       "install-timestamp", "x", time_update_completed);
 }
 
-static void
-gs_update_monitor_init (GsUpdateMonitor *monitor)
+static gboolean
+cleanup_notifications_cb (gpointer user_data)
 {
-       gint64 tmp;
+       GsUpdateMonitor *monitor = user_data;
+       g_autoptr(PkResults) results = NULL;
 
-       monitor->offline_update_file = g_file_new_for_path ("/var/lib/PackageKit/prepared-update");
-       monitor->check_offline_update_id = 
-               g_timeout_add_seconds (5, check_offline_update_cb, monitor);
+       /* only show this at first-boot */
+       results = pk_offline_get_results (NULL);
+       if (results != NULL) {
+               show_installed_updates_notification (monitor, results);
+       } else {
+               g_application_withdraw_notification (monitor->application,
+                                                    "offline-update");
+       }
 
+       /* wait until first check to show */
+       g_application_withdraw_notification (monitor->application,
+                                            "updates-available");
+
+       monitor->cleanup_notifications_id = 0;
+       return G_SOURCE_REMOVE;
+}
+
+static void
+gs_update_monitor_init (GsUpdateMonitor *monitor)
+{
        monitor->settings = g_settings_new ("org.gnome.software");
-       g_settings_get (monitor->settings, "check-timestamp", "x", &tmp);
-       monitor->check_timestamp = g_date_time_new_from_unix_local (tmp);
 
-       monitor->start_hourly_checks_id =
-               g_timeout_add_seconds (60, start_hourly_checks_cb, monitor);
+       /* cleanup at startup */
+       monitor->cleanup_notifications_id =
+               g_idle_add (cleanup_notifications_cb, monitor);
+
+       /* do a first check 60 seconds after login, and then every hour */
+       monitor->check_startup_id =
+               g_timeout_add_seconds (60, check_updates_on_startup_cb, monitor);
 
        monitor->cancellable = g_cancellable_new ();
-       monitor->task = pk_task_new ();
-       g_object_set (monitor->task,
-                     "background", TRUE,
-                     "interactive", FALSE,
-                     "only-download", TRUE,
-                     NULL);
-
-       monitor->network_available = FALSE;
        monitor->control = pk_control_new ();
        g_signal_connect (monitor->control, "notify::network-state",
                          G_CALLBACK (notify_network_state_cb), monitor);
@@ -580,30 +436,22 @@ gs_update_monitor_dispose (GObject *object)
                g_source_remove (monitor->check_hourly_id);
                monitor->check_hourly_id = 0;
        }
-       if (monitor->start_hourly_checks_id != 0) {
-               g_source_remove (monitor->start_hourly_checks_id);
-               monitor->start_hourly_checks_id = 0;
+       if (monitor->check_startup_id != 0) {
+               g_source_remove (monitor->check_startup_id);
+               monitor->check_startup_id = 0;
        }
-       if (monitor->check_offline_update_id != 0) {
-               g_source_remove (monitor->check_offline_update_id);
-               monitor->check_offline_update_id = 0;
+       if (monitor->notification_blocked_id != 0) {
+               g_source_remove (monitor->notification_blocked_id);
+               monitor->notification_blocked_id = 0;
        }
-       if (monitor->reenable_offline_update_id != 0) {
-               g_source_remove (monitor->reenable_offline_update_id);
-               monitor->reenable_offline_update_id = 0;
+       if (monitor->cleanup_notifications_id != 0) {
+               g_source_remove (monitor->cleanup_notifications_id);
+               monitor->cleanup_notifications_id = 0;
        }
        if (monitor->control != NULL) {
                g_signal_handlers_disconnect_by_func (monitor->control, notify_network_state_cb, monitor);
                g_clear_object (&monitor->control);
        }
-       if (monitor->offline_update_monitor != NULL) {
-               g_signal_handlers_disconnect_by_func (monitor->offline_update_monitor, 
offline_update_monitor_cb, monitor);
-               g_clear_object (&monitor->offline_update_monitor);
-       }
-       g_clear_pointer (&monitor->pending_downloads, g_strfreev);
-       g_clear_pointer (&monitor->check_timestamp, g_date_time_unref);
-       g_clear_object (&monitor->task);
-       g_clear_object (&monitor->offline_update_file);
        g_clear_object (&monitor->settings);
 
        G_OBJECT_CLASS (gs_update_monitor_parent_class)->dispose (object);
@@ -627,22 +475,6 @@ gs_update_monitor_class_init (GsUpdateMonitorClass *klass)
        object_class->finalize = gs_update_monitor_finalize;
 }
 
-static void
-remove_stale_notifications (GsUpdateMonitor *monitor)
-{
-       if (!g_file_query_exists (monitor->offline_update_file, NULL)) {
-               g_debug ("Withdrawing stale updates-available notification");
-               g_application_withdraw_notification (monitor->application,
-                                                    "updates-available");
-       }
-
-       if (pk_offline_get_results_mtime (NULL) == 0) {
-               g_debug ("Withdrawing stale offline-updates notification");
-               g_application_withdraw_notification (monitor->application,
-                                                    "offline-updates");
-       }
-}
-
 GsUpdateMonitor *
 gs_update_monitor_new (GsApplication *application)
 {
@@ -652,7 +484,9 @@ gs_update_monitor_new (GsApplication *application)
        monitor->application = G_APPLICATION (application);
        g_application_hold (monitor->application);
 
-       remove_stale_notifications (monitor);
+       monitor->plugin_loader = gs_application_get_plugin_loader (application);
+       g_signal_connect (monitor->plugin_loader, "updates-changed",
+                         G_CALLBACK (updates_changed_cb), monitor);
 
        return monitor;
 }


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