[gnome-software] Do not use PackageKit for network type detection
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Do not use PackageKit for network type detection
- Date: Wed, 27 Jan 2016 10:11:41 +0000 (UTC)
commit 6c2df35817c08884a717f5d46d24d15bc01ec8b2
Author: Richard Hughes <richard hughsie com>
Date: Wed Jan 27 08:28:30 2016 +0000
Do not use PackageKit for network type detection
Now we can get the 'GNetworkMonitor:metered' property from GIO instead.
configure.ac | 2 +-
src/gs-shell-updates.c | 127 +++++++++++++++--------------------------------
src/gs-update-monitor.c | 24 +++++-----
3 files changed, 54 insertions(+), 99 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index e502d2a..49b79a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,7 +52,7 @@ GETTEXT_PACKAGE=AC_PACKAGE_NAME
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE(GETTEXT_PACKAGE, "AC_PACKAGE_NAME", [gnome-software])
-AM_PATH_GLIB_2_0(2.45.8, :, AC_MSG_ERROR([GLib is required]), gobject gmodule gio)
+AM_PATH_GLIB_2_0(2.46.0, :, AC_MSG_ERROR([GLib is required]), gobject gmodule gio)
AM_GLIB_GNU_GETTEXT
GLIB_GSETTINGS
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 82b7aed..127f8e5 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -22,6 +22,7 @@
#include "config.h"
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <packagekit-glib2/packagekit.h>
#include "gs-shell.h"
@@ -63,7 +64,7 @@ struct _GsShellUpdates
gboolean cache_valid;
gboolean in_progress;
GsShell *shell;
- PkControl *control;
+ GNetworkMonitor *network_monitor;
GsPluginStatus last_status;
GsShellUpdatesState state;
gboolean has_agreed_to_mobile_data;
@@ -203,27 +204,12 @@ static void
gs_shell_updates_update_ui_state (GsShellUpdates *self)
{
GtkWidget *widget;
- PkNetworkEnum network_state;
- gboolean is_free_connection;
g_autofree gchar *checked_str = NULL;
g_autofree gchar *spinner_str = NULL;
if (gs_shell_get_mode (self->shell) != GS_SHELL_MODE_UPDATES)
return;
- /* get the current network state */
- g_object_get (self->control, "network-state", &network_state, NULL);
- switch (network_state) {
- case PK_NETWORK_ENUM_ONLINE:
- case PK_NETWORK_ENUM_WIFI:
- case PK_NETWORK_ENUM_WIRED:
- is_free_connection = TRUE;
- break;
- default:
- is_free_connection = FALSE;
- break;
- }
-
/* main spinner */
switch (self->state) {
case GS_SHELL_UPDATES_STATE_STARTUP:
@@ -321,7 +307,8 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
"view-refresh-symbolic", GTK_ICON_SIZE_MENU);
widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "button_refresh"));
gtk_widget_set_visible (widget,
- is_free_connection || self->has_agreed_to_mobile_data);
+ !g_network_monitor_get_network_metered (self->network_monitor) ||
+ self->has_agreed_to_mobile_data);
break;
default:
g_assert_not_reached ();
@@ -356,26 +343,25 @@ gs_shell_updates_update_ui_state (GsShellUpdates *self)
gtk_stack_set_visible_child_name (GTK_STACK (self->stack_updates), "spinner");
break;
case GS_SHELL_UPDATES_STATE_NO_UPDATES:
+
/* check we have a "free" network connection */
- switch (network_state) {
- case PK_NETWORK_ENUM_ONLINE:
- case PK_NETWORK_ENUM_WIFI:
- case PK_NETWORK_ENUM_WIRED:
+ if (g_network_monitor_get_network_available (self->network_monitor) &&
+ !g_network_monitor_get_network_metered (self->network_monitor)) {
gtk_stack_set_visible_child_name (GTK_STACK (self->stack_updates), "uptodate");
- break;
- case PK_NETWORK_ENUM_OFFLINE:
- gtk_stack_set_visible_child_name (GTK_STACK (self->stack_updates), "offline");
- break;
- case PK_NETWORK_ENUM_MOBILE:
+
+ /* expensive network connection */
+ } else if (g_network_monitor_get_network_metered (self->network_monitor)) {
if (self->has_agreed_to_mobile_data) {
gtk_stack_set_visible_child_name (GTK_STACK (self->stack_updates),
"uptodate");
} else {
gtk_stack_set_visible_child_name (GTK_STACK (self->stack_updates), "mobile");
}
- break;
- default:
- break;
+
+ /* no network connection */
+ } else {
+ gtk_stack_set_visible_child_name (GTK_STACK (self->stack_updates), "offline");
}
+
break;
case GS_SHELL_UPDATES_STATE_HAS_UPDATES:
case GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES:
@@ -424,8 +410,8 @@ gs_shell_updates_set_state (GsShellUpdates *self,
* gs_shell_updates_notify_network_state_cb:
**/
static void
-gs_shell_updates_notify_network_state_cb (PkControl *control,
- GParamSpec *pspec,
+gs_shell_updates_notify_network_state_cb (GNetworkMonitor *network_monitor,
+ gboolean available,
GsShellUpdates *self)
{
gs_shell_updates_update_ui_state (self);
@@ -750,7 +736,6 @@ gs_shell_updates_button_refresh_cb (GtkWidget *widget,
GsShellUpdates *self)
{
GtkWidget *dialog;
- PkNetworkEnum network_state;
/* cancel existing action? */
if (self->state == GS_SHELL_UPDATES_STATE_ACTION_REFRESH_HAS_UPDATES ||
@@ -761,67 +746,61 @@ gs_shell_updates_button_refresh_cb (GtkWidget *widget,
}
/* check we have a "free" network connection */
- g_object_get (self->control,
- "network-state", &network_state,
- NULL);
- switch (network_state) {
- case PK_NETWORK_ENUM_ONLINE:
- case PK_NETWORK_ENUM_WIFI:
- case PK_NETWORK_ENUM_WIRED:
+ if (g_network_monitor_get_network_available (self->network_monitor) &&
+ !g_network_monitor_get_network_metered (self->network_monitor)) {
gs_shell_updates_get_new_updates (self);
- break;
- case PK_NETWORK_ENUM_OFFLINE:
+
+ /* expensive network connection */
+ } else if (g_network_monitor_get_network_metered (self->network_monitor)) {
+ if (self->has_agreed_to_mobile_data) {
+ gs_shell_updates_get_new_updates (self);
+ return;
+ }
dialog = gtk_message_dialog_new (gs_shell_get_window (self->shell),
GTK_DIALOG_MODAL |
GTK_DIALOG_USE_HEADER_BAR |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CANCEL,
- /* TRANSLATORS: can't do updates check */
- _("No Network"));
+ /* TRANSLATORS: this is to explain that downloading updates
may cost money */
+ _("Charges may apply"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
/* TRANSLATORS: we need network
* to do the updates check */
- _("Internet access is required to check for
updates."));
+ _("Checking for updates while using mobile
broadband could cause you to incur charges."));
gtk_dialog_add_button (GTK_DIALOG (dialog),
/* TRANSLATORS: this is a link to the
* control-center network panel */
- _("Network Settings"),
- GTK_RESPONSE_REJECT);
+ _("Check Anyway"),
+ GTK_RESPONSE_ACCEPT);
g_signal_connect (dialog, "response",
G_CALLBACK (gs_shell_updates_refresh_confirm_cb),
self);
gtk_window_present (GTK_WINDOW (dialog));
- break;
- case PK_NETWORK_ENUM_MOBILE:
- if (self->has_agreed_to_mobile_data) {
- gs_shell_updates_get_new_updates (self);
- break;
- }
+
+ /* no network connection */
+ } else {
dialog = gtk_message_dialog_new (gs_shell_get_window (self->shell),
GTK_DIALOG_MODAL |
GTK_DIALOG_USE_HEADER_BAR |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CANCEL,
- /* TRANSLATORS: this is to explain that downloading updates
may cost money */
- _("Charges may apply"));
+ /* TRANSLATORS: can't do updates check */
+ _("No Network"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
/* TRANSLATORS: we need network
* to do the updates check */
- _("Checking for updates while using mobile
broadband could cause you to incur charges."));
+ _("Internet access is required to check for
updates."));
gtk_dialog_add_button (GTK_DIALOG (dialog),
/* TRANSLATORS: this is a link to the
* control-center network panel */
- _("Check Anyway"),
- GTK_RESPONSE_ACCEPT);
+ _("Network Settings"),
+ GTK_RESPONSE_REJECT);
g_signal_connect (dialog, "response",
G_CALLBACK (gs_shell_updates_refresh_confirm_cb),
self);
gtk_window_present (GTK_WINDOW (dialog));
- break;
- default:
- g_assert_not_reached ();
}
}
@@ -878,24 +857,6 @@ gs_shell_updates_button_update_all_cb (GtkButton *button,
}
/**
- * gs_shell_updates_get_properties_cb:
- **/
-static void
-gs_shell_updates_get_properties_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- GsShellUpdates *self = GS_SHELL_UPDATES (user_data);
- PkControl *control = PK_CONTROL (source);
- g_autoptr(GError) error = NULL;
-
- /* get result */
- if (!pk_control_get_properties_finish (control, res, &error))
- g_warning ("failed to get properties: %s", error->message);
- gs_shell_updates_update_ui_state (self);
-}
-
-/**
* gs_shell_updates_status_changed_cb:
**/
static void
@@ -979,15 +940,10 @@ gs_shell_updates_setup (GsShellUpdates *self,
gs_shell_updates_monitor_permission (self);
- g_signal_connect (self->control, "notify::network-state",
+ g_signal_connect (self->network_monitor, "network-changed",
G_CALLBACK (gs_shell_updates_notify_network_state_cb),
self);
- /* get the initial network state */
- pk_control_get_properties_async (self->control, cancellable,
- gs_shell_updates_get_properties_cb,
- self);
-
/* chain up */
gs_page_setup (GS_PAGE (self),
shell,
@@ -1011,7 +967,6 @@ gs_shell_updates_dispose (GObject *object)
g_clear_object (&self->builder);
g_clear_object (&self->plugin_loader);
g_clear_object (&self->cancellable);
- g_clear_object (&self->control);
g_clear_object (&self->settings);
g_clear_object (&self->desktop_settings);
@@ -1052,7 +1007,7 @@ gs_shell_updates_init (GsShellUpdates *self)
gtk_widget_init_template (GTK_WIDGET (self));
- self->control = pk_control_new ();
+ self->network_monitor = g_network_monitor_get_default ();
self->state = GS_SHELL_UPDATES_STATE_STARTUP;
self->settings = g_settings_new ("org.gnome.software");
self->desktop_settings = g_settings_new ("org.gnome.desktop.interface");
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index 46782e9..1946317 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -44,7 +44,7 @@ struct _GsUpdateMonitor {
guint check_startup_id; /* 60s after startup */
guint check_hourly_id; /* and then every hour */
guint check_daily_id; /* every 3rd day */
- PkControl *control; /* network type detection */
+ GNetworkMonitor *network_monitor; /* network type detection */
guint notification_blocked_id; /* rate limit notifications */
};
@@ -281,15 +281,13 @@ refresh_cache_finished_cb (GObject *object,
static void
check_updates (GsUpdateMonitor *monitor)
{
- PkNetworkEnum network_state;
gint64 tmp;
g_autoptr(GDateTime) last_refreshed = NULL;
g_autoptr(GDateTime) now_refreshed = NULL;
/* never refresh when offline or on mobile connections */
- g_object_get (monitor->control, "network-state", &network_state, NULL);
- if (network_state == PK_NETWORK_ENUM_OFFLINE ||
- network_state == PK_NETWORK_ENUM_MOBILE)
+ if (!g_network_monitor_get_network_available (monitor->network_monitor) ||
+ g_network_monitor_get_network_metered (monitor->network_monitor))
return;
g_settings_get (monitor->settings, "check-timestamp", "x", &tmp);
@@ -375,8 +373,8 @@ check_updates_on_startup_cb (gpointer data)
}
static void
-notify_network_state_cb (PkControl *control,
- GParamSpec *pspec,
+notify_network_state_cb (GNetworkMonitor *network_monitor,
+ gboolean active,
GsUpdateMonitor *monitor)
{
check_updates (monitor);
@@ -485,8 +483,8 @@ gs_update_monitor_init (GsUpdateMonitor *monitor)
g_timeout_add_seconds (60, check_updates_on_startup_cb, monitor);
monitor->cancellable = g_cancellable_new ();
- monitor->control = pk_control_new ();
- g_signal_connect (monitor->control, "notify::network-state",
+ monitor->network_monitor = g_network_monitor_get_default ();
+ g_signal_connect (monitor->network_monitor, "network-changed",
G_CALLBACK (notify_network_state_cb), monitor);
}
@@ -519,9 +517,11 @@ gs_update_monitor_dispose (GObject *object)
g_source_remove (monitor->cleanup_notifications_id);
monitor->cleanup_notifications_id = 0;
}
- if (monitor->control != NULL) {
- g_signal_handlers_disconnect_by_func (monitor->control, notify_network_state_cb, monitor);
- g_clear_object (&monitor->control);
+ if (monitor->network_monitor != NULL) {
+ g_signal_handlers_disconnect_by_func (monitor->network_monitor,
+ notify_network_state_cb,
+ monitor);
+ monitor->network_monitor = NULL;
}
g_clear_object (&monitor->settings);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]