[gnome-software/wip/william/update-all: 73/75] Update offline only if an update requires it
- From: William Hua <williamhua src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/william/update-all: 73/75] Update offline only if an update requires it
- Date: Wed, 6 Apr 2016 17:33:54 +0000 (UTC)
commit 396cb74cf4b8cfca04b64fa8583166b7cd2698c2
Author: William Hua <william hua canonical com>
Date: Tue Apr 5 17:02:34 2016 +0100
Update offline only if an update requires it
src/gs-shell-updates.c | 103 ++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 87 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 0e908d6..21889bb 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -43,10 +43,12 @@ typedef enum {
GS_SHELL_UPDATES_STATE_STARTUP,
GS_SHELL_UPDATES_STATE_ACTION_REFRESH_NO_UPDATES,
GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES,
+ GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES,
GS_SHELL_UPDATES_STATE_ACTION_GET_UPDATES,
GS_SHELL_UPDATES_STATE_NO_UPDATES,
GS_SHELL_UPDATES_STATE_MANAGED,
GS_SHELL_UPDATES_STATE_HAS_UPDATES,
+ GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES,
GS_SHELL_UPDATES_STATE_FAILED,
GS_SHELL_UPDATES_STATE_LAST,
} GsShellUpdatesState;
@@ -227,9 +229,11 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
gs_start_spinner (GTK_SPINNER (self->spinner_updates));
break;
case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES:
case GS_SHELL_UPDATES_STATE_NO_UPDATES:
case GS_SHELL_UPDATES_STATE_MANAGED:
case GS_SHELL_UPDATES_STATE_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES:
case GS_SHELL_UPDATES_STATE_FAILED:
gs_stop_spinner (GTK_SPINNER (self->spinner_updates));
break;
@@ -256,9 +260,11 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
break;
case GS_SHELL_UPDATES_STATE_ACTION_GET_UPDATES:
case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES:
case GS_SHELL_UPDATES_STATE_NO_UPDATES:
case GS_SHELL_UPDATES_STATE_MANAGED:
case GS_SHELL_UPDATES_STATE_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES:
case GS_SHELL_UPDATES_STATE_FAILED:
break;
default:
@@ -269,6 +275,7 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
/* headerbar spinner */
switch (self->state) {
case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES:
gtk_widget_show (self->header_spinner_start);
gtk_spinner_start (GTK_SPINNER (self->header_spinner_start));
break;
@@ -277,6 +284,7 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
case GS_SHELL_UPDATES_STATE_NO_UPDATES:
case GS_SHELL_UPDATES_STATE_MANAGED:
case GS_SHELL_UPDATES_STATE_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES:
case GS_SHELL_UPDATES_STATE_STARTUP:
case GS_SHELL_UPDATES_STATE_FAILED:
gtk_spinner_stop (GTK_SPINNER (self->header_spinner_start));
@@ -289,6 +297,7 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
/* headerbar refresh icon */
switch (self->state) {
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES:
case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_NO_UPDATES:
gtk_image_set_from_icon_name (GTK_IMAGE (gtk_button_get_image (GTK_BUTTON
(self->button_refresh))),
@@ -302,6 +311,7 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
break;
case GS_SHELL_UPDATES_STATE_FAILED:
case GS_SHELL_UPDATES_STATE_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES:
gtk_image_set_from_icon_name (GTK_IMAGE (gtk_button_get_image (GTK_BUTTON
(self->button_refresh))),
"view-refresh-symbolic", GTK_ICON_SIZE_MENU);
gtk_widget_show (self->button_refresh);
@@ -322,8 +332,14 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
/* headerbar update button */
switch (self->state) {
- case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
case GS_SHELL_UPDATES_STATE_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
+ gtk_button_set_label (GTK_BUTTON (self->button_update_all), _("_Install All"));
+ gtk_widget_show (self->button_update_all);
+ break;
+ case GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES:
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES:
+ gtk_button_set_label (GTK_BUTTON (self->button_update_all), _("Restart & _Install"));
gtk_widget_show (self->button_update_all);
break;
case GS_SHELL_UPDATES_STATE_STARTUP:
@@ -372,7 +388,9 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
break;
case GS_SHELL_UPDATES_STATE_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES:
case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES:
gtk_stack_set_visible_child_name (GTK_STACK (self->stack_updates), "view");
break;
case GS_SHELL_UPDATES_STATE_MANAGED:
@@ -459,17 +477,23 @@ gs_shell_updates_get_updates_cb (GsPluginLoader *plugin_loader,
GsShellUpdates *self)
{
GList *l;
+ GsApp *app;
GtkWidget *widget;
g_autoptr(GError) error = NULL;
g_autoptr(GsAppList) list = NULL;
+ gboolean has_non_live_updates = FALSE;
self->cache_valid = TRUE;
/* get the results */
list = gs_plugin_loader_get_updates_finish (plugin_loader, res, &error);
for (l = list; l != NULL; l = l->next) {
- gs_update_list_add_app (GS_UPDATE_LIST (self->list_box_updates),
- GS_APP (l->data));
+ app = l->data;
+
+ if (gs_app_get_state (app) == AS_APP_STATE_UPDATABLE)
+ has_non_live_updates = TRUE;
+
+ gs_update_list_add_app (GS_UPDATE_LIST (self->list_box_updates), app);
}
widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "button_updates_counter"));
@@ -504,8 +528,12 @@ gs_shell_updates_get_updates_cb (GsPluginLoader *plugin_loader,
GS_SHELL_UPDATES_STATE_FAILED);
}
} else {
- gs_shell_updates_set_state (self,
- GS_SHELL_UPDATES_STATE_HAS_UPDATES);
+ if (has_non_live_updates)
+ gs_shell_updates_set_state (self,
+ GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES);
+ else
+ gs_shell_updates_set_state (self,
+ GS_SHELL_UPDATES_STATE_HAS_UPDATES);
}
self->in_progress = FALSE;
@@ -665,6 +693,10 @@ gs_shell_updates_refresh_cb (GsPluginLoader *plugin_loader,
G_IO_ERROR,
G_IO_ERROR_CANCELLED)) {
switch (self->state) {
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES:
+ gs_shell_updates_set_state (self,
+ GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES);
+ break;
case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
gs_shell_updates_set_state (self,
GS_SHELL_UPDATES_STATE_HAS_UPDATES);
@@ -704,10 +736,17 @@ static void
gs_shell_updates_get_new_updates (GsShellUpdates *self)
{
/* force a check for updates and download */
- gs_shell_updates_set_state (self,
- self->state == GS_SHELL_UPDATES_STATE_HAS_UPDATES ?
- GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES :
- GS_SHELL_UPDATES_STATE_ACTION_REFRESH_NO_UPDATES);
+ switch (self->state) {
+ case GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES:
+ gs_shell_updates_set_state (self, GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES);
+ break;
+ case GS_SHELL_UPDATES_STATE_HAS_UPDATES:
+ gs_shell_updates_set_state (self, GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES);
+ break;
+ default:
+ gs_shell_updates_set_state (self, GS_SHELL_UPDATES_STATE_ACTION_REFRESH_NO_UPDATES);
+ break;
+ }
if (self->cancellable_refresh != NULL) {
g_cancellable_cancel (self->cancellable_refresh);
@@ -791,7 +830,8 @@ gs_shell_updates_button_refresh_cb (GtkWidget *widget,
GtkWidget *dialog;
/* cancel existing action? */
- if (self->state == GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES ||
+ if (self->state == GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES ||
+ self->state == GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES ||
self->state == GS_SHELL_UPDATES_STATE_ACTION_REFRESH_NO_UPDATES) {
g_cancellable_cancel (self->cancellable_refresh);
g_clear_object (&self->cancellable_refresh);
@@ -919,6 +959,21 @@ gs_shell_updates_reboot_failed_cb (GObject *source, GAsyncResult *res, gpointer
}
/**
+ * gs_shell_updates_update_all_cb:
+ **/
+static void
+gs_shell_updates_update_all_cb (GsPluginLoader *plugin_loader,
+ GAsyncResult *res,
+ GsShellUpdates *self)
+{
+ g_autoptr(GError) error = NULL;
+
+ /* get the results */
+ if (!gs_plugin_loader_update_all_finish (plugin_loader, res, &error))
+ g_warning ("Failed to update all: %s", error->message);
+}
+
+/**
* gs_shell_updates_offline_update_cb:
**/
static void
@@ -955,13 +1010,29 @@ gs_shell_updates_button_update_all_cb (GtkButton *button,
g_autoptr(GError) error = NULL;
g_autoptr(GList) apps = NULL;
- /* do the offline update */
+ /* do the update (offline if there are non-live updates) */
apps = gs_update_list_get_apps (GS_UPDATE_LIST (self->list_box_updates));
- gs_plugin_loader_offline_update_async (self->plugin_loader,
- apps,
- self->cancellable,
- (GAsyncReadyCallback) gs_shell_updates_offline_update_cb,
- self);
+
+ switch (self->state) {
+ case GS_SHELL_UPDATES_STATE_HAS_UPDATES:
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
+ gs_plugin_loader_update_all_async (self->plugin_loader,
+ apps,
+ self->cancellable,
+ (GAsyncReadyCallback) gs_shell_updates_update_all_cb,
+ self);
+ break;
+ case GS_SHELL_UPDATES_STATE_HAS_NON_LIVE_UPDATES:
+ case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_NON_LIVE_UPDATES:
+ gs_plugin_loader_offline_update_async (self->plugin_loader,
+ apps,
+ self->cancellable,
+ (GAsyncReadyCallback)
gs_shell_updates_offline_update_cb,
+ self);
+ break;
+ default:
+ break;
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]