[gnome-settings-daemon] updates: if we failed to get the updates 10 times in a row, then show the user a notification
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] updates: if we failed to get the updates 10 times in a row, then show the user a notification
- Date: Thu, 17 Feb 2011 11:18:10 +0000 (UTC)
commit 31c8f2112a6665e3bb5410215392fa05ab68f395
Author: Richard Hughes <richard hughsie com>
Date: Thu Feb 17 11:17:27 2011 +0000
updates: if we failed to get the updates 10 times in a row, then show the user a notification
This is a compomise we've come up with in #gnome-design where we need to
keep the user informed if they are not getting updates done, but also
we don't want to bombard the user with notifications like we have done
in the past.
By default, we only do the updates check once per day, so this shouldn't
lead to lots of extra messages.
plugins/updates/gsd-updates-manager.c | 64 +++++++++++++++++++++++++++++++-
1 files changed, 62 insertions(+), 2 deletions(-)
---
diff --git a/plugins/updates/gsd-updates-manager.c b/plugins/updates/gsd-updates-manager.c
index e0bdb7f..ea96316 100644
--- a/plugins/updates/gsd-updates-manager.c
+++ b/plugins/updates/gsd-updates-manager.c
@@ -37,6 +37,8 @@
#define GSD_UPDATES_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_UPDATES_MANAGER, GsdUpdatesManagerPrivate))
+#define MAX_FAILED_GET_UPDATES 10 /* the maximum number of tries */
+
struct GsdUpdatesManagerPrivate
{
GCancellable *cancellable;
@@ -54,6 +56,7 @@ struct GsdUpdatesManagerPrivate
GDBusProxy *proxy_session;
guint update_viewer_watcher_id;
GVolumeMonitor *volume_monitor;
+ guint failed_get_updates_count;
};
static void gsd_updates_manager_class_init (GsdUpdatesManagerClass *klass);
@@ -599,7 +602,58 @@ out:
}
static void
-get_updates_finished_cb (GObject *object, GAsyncResult *res, GsdUpdatesManager *manager)
+notify_failed_get_updates_maybe (GsdUpdatesManager *manager)
+{
+ const gchar *button;
+ const gchar *message;
+ const gchar *title;
+ gboolean ret;
+ GError *error = NULL;
+ NotifyNotification *notification;
+
+ /* give the user a break */
+ if (manager->priv->failed_get_updates_count++ < MAX_FAILED_GET_UPDATES) {
+ g_debug ("failed GetUpdates, but will retry %i more times before notification",
+ MAX_FAILED_GET_UPDATES - manager->priv->failed_get_updates_count);
+ goto out;
+ }
+
+ /* TRANSLATORS: the updates mechanism */
+ title = _("Updates");
+
+ /* TRANSLATORS: we failed to get the updates multiple times,
+ * and now we need to inform the user that something might be wrong */
+ message = _("Unable to access software updates");
+
+ /* TRANSLATORS: try again, this time launching the update viewer */
+ button = _("Try again");
+
+ notification = notify_notification_new (title, message, NULL);
+ if (notification == NULL) {
+ g_warning ("failed to create notification");
+ goto out;
+ }
+ notify_notification_set_timeout (notification, 120*1000);
+ notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);
+ notify_notification_add_action (notification, "show-update-viewer",
+ button,
+ libnotify_action_cb,
+ manager, NULL);
+ ret = notify_notification_show (notification, &error);
+ if (!ret) {
+ g_warning ("failed to show notification: %s",
+ error->message);
+ g_error_free (error);
+ }
+out:
+ /* reset, even if the message failed */
+ manager->priv->failed_get_updates_count = 0;
+}
+
+static void
+get_updates_finished_cb (GObject *object,
+ GAsyncResult *res,
+ GsdUpdatesManager *manager)
{
PkClient *client = PK_CLIENT(object);
PkResults *results;
@@ -616,8 +670,10 @@ get_updates_finished_cb (GObject *object, GAsyncResult *res, GsdUpdatesManager *
/* get the results */
results = pk_client_generic_finish (PK_CLIENT(client), res, &error);
if (results == NULL) {
- g_warning ("failed to get updates: %s", error->message);
+ g_warning ("failed to get updates: %s",
+ error->message);
g_error_free (error);
+ notify_failed_get_updates_maybe (manager);
goto out;
}
@@ -627,9 +683,13 @@ get_updates_finished_cb (GObject *object, GAsyncResult *res, GsdUpdatesManager *
g_warning ("failed to get updates: %s, %s",
pk_error_enum_to_text (pk_error_get_code (error_code)),
pk_error_get_details (error_code));
+ notify_failed_get_updates_maybe (manager);
goto out;
}
+ /* we succeeded, so clear the count */
+ manager->priv->failed_get_updates_count = 0;
+
/* get data */
array = pk_results_get_package_array (results);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]