[gnome-settings-daemon] updates: show security update notifications by default once per day, but restrict non-critical notif
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] updates: show security update notifications by default once per day, but restrict non-critical notif
- Date: Fri, 18 Feb 2011 12:23:37 +0000 (UTC)
commit aad2895ca7b3bde73146a0fa854def296859a4aa
Author: Richard Hughes <richard hughsie com>
Date: Fri Feb 18 12:22:35 2011 +0000
updates: show security update notifications by default once per day, but restrict non-critical notificatons to once per week by default
...ttings-daemon.plugins.updates.gschema.xml.in.in | 19 +++--
plugins/updates/gsd-updates-common.h | 5 +-
plugins/updates/gsd-updates-manager.c | 98 ++++++++++++++++----
3 files changed, 93 insertions(+), 29 deletions(-)
---
diff --git a/data/org.gnome.settings-daemon.plugins.updates.gschema.xml.in.in b/data/org.gnome.settings-daemon.plugins.updates.gschema.xml.in.in
index 8a678b7..0cea787 100644
--- a/data/org.gnome.settings-daemon.plugins.updates.gschema.xml.in.in
+++ b/data/org.gnome.settings-daemon.plugins.updates.gschema.xml.in.in
@@ -33,12 +33,22 @@
<key name="force-get-updates-login" type="b">
<default>false</default>
<_summary>Get the update list when the session starts</_summary>
- <_description>Get the update list when the session starts, even if not scheduled to. This ensures the user has up to date and valid data in the tray at startup.</_description>
+ <_description>Get the update list when the session starts, even if not scheduled to.</_description>
</key>
<key name="frequency-get-updates" type="i">
<default>86400</default>
<_summary>How often to check for updates</_summary>
- <_description>How often to check for updates. Value is in seconds.</_description>
+ <_description>How often to check for updates. Value is in seconds. This is a maximum amount of time that can pass between a security update being published, and the update being automatically installed or the user notified.</_description>
+ </key>
+ <key name="frequency-updates-notification" type="i">
+ <default>604800</default>
+ <_summary>How often to notify the user that non-critical updates are available</_summary>
+ <_description>How often to tell the user there are non-critical updates. Value is in seconds. Security update notifications are always shown after the check for updates, but non-critical notifications should be shown a lot less frequently.</_description>
+ </key>
+ <key name="last-updates-notification" type="t">
+ <default>0</default>
+ <_summary>The last time we told the user about non-critical notifications</_summary>
+ <_description>The last time we notified the user about non-critical updates. Value is in seconds since the epoch, or zero for never.</_description>
</key>
<key name="frequency-get-upgrades" type="i">
<default>604800</default>
@@ -85,11 +95,6 @@
<_summary>Notify the user when the update was started</_summary>
<_description>Notify the user when the update was started.</_description>
</key>
- <key name="notify-update-type" enum="org.gnome.settings-daemon.GsdUpdateType">
- <default>'security'</default>
- <_summary>Notify the user when the update type is available</_summary>
- <_description>Notify the user when updates are available of a certain type and not auto-installed.</_description>
- </key>
<key name="enable-check-firmware" type="b">
<default>true</default>
<_summary>Ask the user if additional firmware should be installed</_summary>
diff --git a/plugins/updates/gsd-updates-common.h b/plugins/updates/gsd-updates-common.h
index 6016646..001a4ab 100644
--- a/plugins/updates/gsd-updates-common.h
+++ b/plugins/updates/gsd-updates-common.h
@@ -33,16 +33,17 @@ G_BEGIN_DECLS
#define GSD_SETTINGS_FREQUENCY_GET_UPDATES "frequency-get-updates"
#define GSD_SETTINGS_FREQUENCY_GET_UPGRADES "frequency-get-upgrades"
#define GSD_SETTINGS_FREQUENCY_REFRESH_CACHE "frequency-refresh-cache"
+#define GSD_SETTINGS_FREQUENCY_UPDATES_NOTIFICATION "frequency-updates-notification"
#define GSD_SETTINGS_IGNORED_DEVICES "ignored-devices"
+#define GSD_SETTINGS_LAST_UPDATES_NOTIFICATION "last-updates-notification"
+#define GSD_SETTINGS_MEDIA_REPO_FILENAMES "media-repo-filenames"
#define GSD_SETTINGS_NOTIFY_DISTRO_UPGRADES "notify-distro-upgrades"
#define GSD_SETTINGS_NOTIFY_UPDATE_COMPLETE "notify-update-complete"
#define GSD_SETTINGS_NOTIFY_UPDATE_COMPLETE_RESTART "notify-update-complete-restart"
#define GSD_SETTINGS_NOTIFY_UPDATE_NOT_BATTERY "notify-update-not-battery"
-#define GSD_SETTINGS_NOTIFY_UPDATE_TYPE "notify-update-type"
#define GSD_SETTINGS_SCHEMA "org.gnome.settings-daemon.plugins.updates"
#define GSD_SETTINGS_SESSION_STARTUP_TIMEOUT "session-startup-timeout"
#define GSD_SETTINGS_UPDATE_BATTERY "update-battery"
-#define GSD_SETTINGS_MEDIA_REPO_FILENAMES "media-repo-filenames"
G_END_DECLS
diff --git a/plugins/updates/gsd-updates-manager.c b/plugins/updates/gsd-updates-manager.c
index 324a7d2..96ae67b 100644
--- a/plugins/updates/gsd-updates-manager.c
+++ b/plugins/updates/gsd-updates-manager.c
@@ -49,7 +49,7 @@ struct GsdUpdatesManagerPrivate
GSettings *settings_http;
guint number_updates_critical_last_shown;
guint timeout;
- NotifyNotification *notification_updates_available;
+ NotifyNotification *notification_updates;
PkControl *control;
PkTask *task;
guint inhibit_cookie;
@@ -286,17 +286,8 @@ notify_critical_updates (GsdUpdatesManager *manager, GPtrArray *array)
const gchar *title;
gboolean ret;
GError *error = NULL;
- GsdUpdateType update_type;
NotifyNotification *notification;
- /* do we do the notification? */
- update_type = g_settings_get_enum (manager->priv->settings_gsd,
- GSD_SETTINGS_NOTIFY_UPDATE_TYPE);
- if (update_type == GSD_UPDATE_TYPE_NONE) {
- g_debug ("ignoring due to GSettings");
- return;
- }
-
/* if the number of critical updates is the same as the last notification,
* then skip the notifcation as we don't want to bombard the user every hour */
if (array->len == manager->priv->number_updates_critical_last_shown) {
@@ -308,16 +299,16 @@ notify_critical_updates (GsdUpdatesManager *manager, GPtrArray *array)
manager->priv->number_updates_critical_last_shown = array->len;
/* TRANSLATORS: title in the libnotify popup */
- title = ngettext ("Security update available", "Security updates available", array->len);
+ title = ngettext ("Update", "Updates", array->len);
/* TRANSLATORS: message when there are security updates */
- message = ngettext ("An important update is available for your computer:",
- "Important updates are available for your computer:", array->len);
+ message = ngettext ("An important software update is available",
+ "Important software updates are available", array->len);
/* close any existing notification */
- if (manager->priv->notification_updates_available != NULL) {
- notify_notification_close (manager->priv->notification_updates_available, NULL);
- manager->priv->notification_updates_available = NULL;
+ if (manager->priv->notification_updates != NULL) {
+ notify_notification_close (manager->priv->notification_updates, NULL);
+ manager->priv->notification_updates = NULL;
}
/* do the bubble */
@@ -338,7 +329,72 @@ notify_critical_updates (GsdUpdatesManager *manager, GPtrArray *array)
g_error_free (error);
}
/* track so we can prevent doubled notifications */
- manager->priv->notification_updates_available = notification;
+ manager->priv->notification_updates = notification;
+}
+
+static void
+notify_normal_updates_maybe (GsdUpdatesManager *manager, GPtrArray *array)
+{
+ const gchar *message;
+ const gchar *title;
+ gboolean ret;
+ GError *error = NULL;
+ guint64 time_last_notify;
+ guint64 time_now;
+ guint freq_updates_notify;
+ NotifyNotification *notification;
+
+ /* find out if enough time has passed since the last notification */
+ time_now = g_get_real_time ();
+ freq_updates_notify = g_settings_get_int (manager->priv->settings_gsd,
+ GSD_SETTINGS_FREQUENCY_UPDATES_NOTIFICATION);
+ g_settings_get (manager->priv->settings_gsd,
+ GSD_SETTINGS_LAST_UPDATES_NOTIFICATION,
+ "t", &time_last_notify);
+ if ((guint64) freq_updates_notify < time_now - time_last_notify) {
+ g_debug ("not showing non-critical notification as already shown %i days ago",
+ (guint) (time_now - time_last_notify) / (24 * 60 * 60));
+ return;
+ }
+
+ /* TRANSLATORS: title in the libnotify popup */
+ title = ngettext ("Update", "Updates", array->len);
+
+ /* TRANSLATORS: message when there are non-security updates */
+ message = ngettext ("A software update is available.",
+ "Software updates are available.", array->len);
+
+ /* close any existing notification */
+ if (manager->priv->notification_updates != NULL) {
+ notify_notification_close (manager->priv->notification_updates, NULL);
+ manager->priv->notification_updates = NULL;
+ }
+
+ /* do the bubble */
+ g_debug ("title=%s, message=%s", title, message);
+ notification = notify_notification_new (title, message, NULL);
+ if (notification == NULL) {
+ g_warning ("failed to get bubble");
+ return;
+ }
+ 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);
+ ret = notify_notification_show (notification, &error);
+ if (!ret) {
+ g_warning ("error: %s", error->message);
+ g_error_free (error);
+ }
+
+ /* reset notification time */
+ g_settings_set (manager->priv->settings_gsd,
+ GSD_SETTINGS_LAST_UPDATES_NOTIFICATION,
+ "t", time_now);
+
+ /* track so we can prevent doubled notifications */
+ manager->priv->notification_updates = notification;
}
static gboolean
@@ -682,6 +738,8 @@ get_updates_finished_cb (GObject *object,
/* do we warn the user? */
if (security_array->len > 0)
notify_critical_updates (manager, security_array);
+ else
+ notify_normal_updates_maybe (manager, array);
goto out;
}
@@ -1029,10 +1087,10 @@ update_viewer_appeared_cb (GDBusConnection *connection,
GsdUpdatesManager *manager = GSD_UPDATES_MANAGER (user_data);
/* close any existing notification */
- if (manager->priv->notification_updates_available != NULL) {
+ if (manager->priv->notification_updates != NULL) {
g_debug ("update viewer on the bus, clearing bubble");
- notify_notification_close (manager->priv->notification_updates_available, NULL);
- manager->priv->notification_updates_available = NULL;
+ notify_notification_close (manager->priv->notification_updates, NULL);
+ manager->priv->notification_updates = NULL;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]