[gnome-software/wip/jrocha/add-manage-updates-setting] WIP
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/jrocha/add-manage-updates-setting] WIP
- Date: Fri, 28 Oct 2016 14:02:12 +0000 (UTC)
commit 771ee8d9663154e193bd5be41ec8e0615825a961
Author: Joaquim Rocha <jrocha endlessm com>
Date: Fri Oct 28 15:59:53 2016 +0200
WIP
data/org.gnome.software.gschema.xml | 5 +++
src/gs-shell.c | 16 +++++++-
src/gs-update-monitor.c | 67 +++++++++++++++++++++++++++++------
3 files changed, 75 insertions(+), 13 deletions(-)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index 2f9f0f5..5a02236 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -15,6 +15,11 @@
<summary>Whether to automatically refresh when on a metered connection</summary>
<description>If enabled, GNOME Software automatically refreshes in the background even when using a
metered connection (eventually downloading some metadata, checking for updates, etc., which may incur in
costs for the user).</description>
</key>
+ <key name="manage-updates" type="b">
+ <default>true</default>
+ <summary>Whether to manage updates</summary>
+ <description>If enabled, GNOME Software automatically checks for updates in the background and allows
the user to update the apps. If disabled, the mentioned actions will not happen and the updates tab will be
disabled.</description>
+ </key>
<key name="first-run" type="b">
<default>true</default>
<summary>Whether it's the very first run of GNOME Software</summary>
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 6c044b5..b33d4cb 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -42,6 +42,8 @@
#include "gs-update-dialog.h"
#include "gs-update-monitor.h"
+#define MANAGE_UPDATES_CONF_KEY "manage-updates"
+
static const gchar *page_name[] = {
"unknown",
"overview",
@@ -67,6 +69,7 @@ typedef struct
{
gboolean ignore_primary_buttons;
GCancellable *cancellable;
+ GSettings *settings;
GsPluginLoader *plugin_loader;
GsShellMode mode;
GsShellOverview *shell_overview;
@@ -261,6 +264,7 @@ gs_shell_change_mode (GsShell *shell,
GsPage *new_page;
GtkWidget *widget;
GtkStyleContext *context;
+ gboolean manage_updates = FALSE;
if (priv->ignore_primary_buttons)
return;
@@ -289,6 +293,9 @@ gs_shell_change_mode (GsShell *shell,
/* TRANSLATORS: this is the main window title */
gtk_window_set_title (priv->main_window, _("Software"));
+ manage_updates = g_settings_get_boolean (priv->settings,
+ MANAGE_UPDATES_CONF_KEY);
+
/* update main buttons according to mode */
priv->ignore_primary_buttons = TRUE;
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_all"));
@@ -299,7 +306,7 @@ gs_shell_change_mode (GsShell *shell,
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_updates"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), mode == GS_SHELL_MODE_UPDATES);
- gtk_widget_set_visible (widget, !gs_update_monitor_is_managed() || mode == GS_SHELL_MODE_UPDATES);
+ gtk_widget_set_visible (widget, manage_updates || mode == GS_SHELL_MODE_UPDATES);
priv->ignore_primary_buttons = FALSE;
@@ -675,9 +682,12 @@ on_permission_changed (GPermission *permission,
GsShell *shell = data;
GsShellPrivate *priv = gs_shell_get_instance_private (shell);
GtkWidget *widget;
+ gboolean manage_updates = g_settings_get_boolean (priv->settings,
+ MANAGE_UPDATES_CONF_KEY);
+
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_updates"));
- gtk_widget_set_visible (widget, !gs_update_monitor_is_managed() || priv->mode ==
GS_SHELL_MODE_UPDATES);
+ gtk_widget_set_visible (widget, manage_updates || priv->mode == GS_SHELL_MODE_UPDATES);
}
static void
@@ -1710,6 +1720,7 @@ gs_shell_dispose (GObject *object)
g_queue_free_full (priv->back_entry_stack, (GDestroyNotify) free_back_entry);
priv->back_entry_stack = NULL;
}
+ g_clear_object (&priv->settings);
g_clear_object (&priv->builder);
g_clear_object (&priv->cancellable);
g_clear_object (&priv->plugin_loader);
@@ -1743,6 +1754,7 @@ gs_shell_init (GsShell *shell)
priv->back_entry_stack = g_queue_new ();
priv->ignore_primary_buttons = FALSE;
priv->modal_dialogs = g_ptr_array_new_with_free_func ((GDestroyNotify) gtk_widget_destroy);
+ priv->settings = g_settings_new ("org.gnome.software");
}
GsShell *
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index e47cb1e..7452137 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -51,6 +51,15 @@ struct _GsUpdateMonitor {
G_DEFINE_TYPE (GsUpdateMonitor, gs_update_monitor, G_TYPE_OBJECT)
+#define MANAGE_UPDATES_CONF_KEY "manage-updates"
+
+static gboolean
+should_manage_updates (GsUpdateMonitor *monitor)
+{
+ return g_settings_get_boolean (monitor->settings,
+ MANAGE_UPDATES_CONF_KEY);
+}
+
static gboolean
reenable_offline_update_notification (gpointer data)
{
@@ -320,7 +329,8 @@ refresh_cache_finished_cb (GObject *object,
g_warning ("failed to refresh the cache: %s", error->message);
return;
}
- get_updates (monitor);
+ if (should_manage_updates (monitor))
+ get_updates (monitor);
}
typedef enum {
@@ -403,7 +413,8 @@ check_updates (GsUpdateMonitor *monitor)
g_settings_set (monitor->settings, "check-timestamp", "x",
g_date_time_to_unix (now_refreshed));
- if (g_settings_get_boolean (monitor->settings, "download-updates")) {
+ if (should_manage_updates (monitor) &&
+ g_settings_get_boolean (monitor->settings, "download-updates")) {
g_debug ("Refreshing for metadata and payload");
refresh_flags |= GS_PLUGIN_REFRESH_FLAGS_PAYLOAD;
} else {
@@ -440,6 +451,27 @@ check_thrice_daily_cb (gpointer data)
return G_SOURCE_CONTINUE;
}
+static void
+stop_upgrades_check (GsUpdateMonitor *monitor)
+{
+ if (monitor->check_daily_id == 0)
+ return;
+
+ g_source_remove (monitor->check_hourly_id);
+ monitor->check_hourly_id = 0;
+}
+
+static void
+start_upgrades_check (GsUpdateMonitor *monitor)
+{
+ stop_upgrades_check (monitor);
+ get_upgrades (monitor);
+
+ monitor->check_daily_id = g_timeout_add_seconds (3 * 86400,
+ check_thrice_daily_cb,
+ monitor);
+}
+
static gboolean
check_updates_on_startup_cb (gpointer data)
{
@@ -447,12 +479,12 @@ check_updates_on_startup_cb (gpointer data)
g_debug ("First hourly updates check");
check_updates (monitor);
- get_upgrades (monitor);
- monitor->check_hourly_id =
- g_timeout_add_seconds (3600, check_hourly_cb, monitor);
- monitor->check_daily_id =
- g_timeout_add_seconds (3 * 86400, check_thrice_daily_cb, monitor);
+ monitor->check_hourly_id = g_timeout_add_seconds (3600, check_hourly_cb,
+ monitor);
+
+ if (should_manage_updates (monitor))
+ start_upgrades_check (monitor);
monitor->check_startup_id = 0;
return G_SOURCE_REMOVE;
@@ -637,6 +669,19 @@ gs_update_monitor_show_error (GsUpdateMonitor *monitor, GsShell *shell)
}
static void
+settings_changed_cb (GsUpdateMonitor *self,
+ const gchar *key,
+ gpointer data)
+{
+ if (g_strcmp0 (key, MANAGE_UPDATES_CONF_KEY) == 0) {
+ if (should_manage_updates)
+ start_upgrades_check (self);
+ else
+ stop_upgrades_check (self);
+ }
+}
+
+static void
gs_update_monitor_init (GsUpdateMonitor *monitor)
{
g_autoptr(GError) error = NULL;
@@ -673,6 +718,9 @@ gs_update_monitor_init (GsUpdateMonitor *monitor)
} else {
g_warning ("failed to connect to upower: %s", error->message);
}
+
+ g_signal_connect_swapped (monitor->settings, "changed",
+ G_CALLBACK (settings_changed_cb), monitor);
}
static void
@@ -688,10 +736,6 @@ gs_update_monitor_dispose (GObject *object)
g_source_remove (monitor->check_hourly_id);
monitor->check_hourly_id = 0;
}
- if (monitor->check_daily_id != 0) {
- g_source_remove (monitor->check_daily_id);
- monitor->check_daily_id = 0;
- }
if (monitor->check_startup_id != 0) {
g_source_remove (monitor->check_startup_id);
monitor->check_startup_id = 0;
@@ -716,6 +760,7 @@ gs_update_monitor_dispose (GObject *object)
monitor);
monitor->plugin_loader = NULL;
}
+ stop_upgrades_check (monitor);
g_clear_object (&monitor->settings);
g_clear_object (&monitor->proxy_upower);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]