[gnome-software] GsUpdateMonitor: don't notify every hour for available updates



commit abb661f60b2f2977a10ff68572fbe6f680189388
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sat Jan 4 18:40:33 2014 +0100

    GsUpdateMonitor: don't notify every hour for available updates
    
    If the user has taken time to click "Not now" (and thus has
    definitely seen the notification), don't bother him for at
    least 6 hours.
    The timeout is chosen in a way that the user is notified around
    twice per day, so at the next daily shutdown he will remember to
    run the updates.
    If the user does nothing or closes the notification, a new
    one is still sent an hour later.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721467

 src/gs-update-monitor.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index 9f7b57d..8a7018f 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -95,7 +95,7 @@ notify_offline_update_available (GsUpdateMonitor *monitor)
 
        monitor->offline_update_notified = TRUE;
 
-       /* don't notify more often than once every hour */
+       /* Notify in another hour, if the user does nothing (closes the notification) */
        monitor->reenable_offline_update_id = g_timeout_add_seconds (3600, 
reenable_offline_update_notification, monitor);
        g_source_set_name_by_id (monitor->reenable_offline_update_id, "[gnome-software] 
reenable_offline_update_notification");
 
@@ -104,7 +104,7 @@ notify_offline_update_available (GsUpdateMonitor *monitor)
        n = g_notification_new (title);
        g_notification_set_body (n, body);
        g_notification_add_button_with_target (n, _("View"), "app.set-mode", "s", "updates");
-       g_notification_add_button (n, _("Not Now"), "app.nop");
+       g_notification_add_button (n, _("Not Now"), "app.reschedule-updates");
        g_notification_set_default_action_and_target (n, "app.set-mode", "s", "updates");
        g_application_send_notification (monitor->application, "updates-available", n);
        g_object_unref (n);
@@ -560,15 +560,37 @@ gs_update_monitor_class_init (GsUpdateMonitorClass *klass)
        object_class->finalize = gs_update_monitor_finalize;
 }
 
+static void
+do_reschedule_updates (GSimpleAction   *action,
+                      GVariant        *parameter,
+                      GsUpdateMonitor *monitor)
+{
+       if (monitor->reenable_offline_update_id)
+               g_source_remove (monitor->reenable_offline_update_id);
+
+       /* The user explicitly clicked "Not now". Don't bother him
+          for another 6 hours */
+
+       monitor->offline_update_notified = TRUE;
+       monitor->reenable_offline_update_id = g_timeout_add_seconds (6 * 3600, 
reenable_offline_update_notification, monitor);
+       g_source_set_name_by_id (monitor->reenable_offline_update_id, "[gnome-software] 
reenable_offline_update_notification (longer)");
+}
+
 GsUpdateMonitor *
 gs_update_monitor_new (GsApplication *application)
 {
        GsUpdateMonitor *monitor;
+       GSimpleAction *reschedule_updates;
 
        monitor = GS_UPDATE_MONITOR (g_object_new (GS_TYPE_UPDATE_MONITOR, NULL));
        monitor->application = G_APPLICATION (application);
        g_application_hold (monitor->application);
 
+       reschedule_updates = g_simple_action_new ("reschedule-updates", NULL);
+       g_signal_connect_object (reschedule_updates, "activate",
+                                G_CALLBACK (do_reschedule_updates), monitor, 0);
+       g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (reschedule_updates));
+
        return monitor;
 }
 


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