[gnome-software] gs-plugin-loader: Listen for network-metered changes and signal them



commit 4b78593f83c6ab3e2d35716d1af23c8fba252bc6
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Jan 7 13:46:11 2020 +0000

    gs-plugin-loader: Listen for network-metered changes and signal them
    
    The plugin loader previously provided a way to query the current
    network-metered state of the network, but no way to get notifications if
    that changed.
    
    Add that as a `notify` signal on a new `GObject` property.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 lib/gs-plugin-loader.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index b57c205b..f0e124cb 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -60,6 +60,7 @@ typedef struct
        GNetworkMonitor         *network_monitor;
        gulong                   network_changed_handler;
        gulong                   network_available_notify_handler;
+       gulong                   network_metered_notify_handler;
 } GsPluginLoaderPrivate;
 
 static void gs_plugin_loader_monitor_network (GsPluginLoader *plugin_loader);
@@ -81,6 +82,7 @@ enum {
        PROP_EVENTS,
        PROP_ALLOW_UPDATES,
        PROP_NETWORK_AVAILABLE,
+       PROP_NETWORK_METERED,
        PROP_LAST
 };
 
@@ -2567,6 +2569,9 @@ gs_plugin_loader_get_property (GObject *object, guint prop_id,
        case PROP_NETWORK_AVAILABLE:
                g_value_set_boolean (value, gs_plugin_loader_get_network_available (plugin_loader));
                break;
+       case PROP_NETWORK_METERED:
+               g_value_set_boolean (value, gs_plugin_loader_get_network_metered (plugin_loader));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -2612,6 +2617,11 @@ gs_plugin_loader_dispose (GObject *object)
                                             priv->network_available_notify_handler);
                priv->network_available_notify_handler = 0;
        }
+       if (priv->network_metered_notify_handler != 0) {
+               g_signal_handler_disconnect (priv->network_monitor,
+                                            priv->network_metered_notify_handler);
+               priv->network_metered_notify_handler = 0;
+       }
        if (priv->queued_ops_pool != NULL) {
                /* stop accepting more requests and wait until any currently
                 * running ones are finished */
@@ -2672,6 +2682,11 @@ gs_plugin_loader_class_init (GsPluginLoaderClass *klass)
                                      G_PARAM_READABLE);
        g_object_class_install_property (object_class, PROP_NETWORK_AVAILABLE, pspec);
 
+       pspec = g_param_spec_boolean ("network-metered", NULL, NULL,
+                                     FALSE,
+                                     G_PARAM_READABLE);
+       g_object_class_install_property (object_class, PROP_NETWORK_METERED, pspec);
+
        signals [SIGNAL_STATUS_CHANGED] =
                g_signal_new ("status-changed",
                              G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
@@ -2868,6 +2883,7 @@ gs_plugin_loader_network_changed_cb (GNetworkMonitor *monitor,
                 metered ? "metered" : "unmetered");
 
        g_object_notify (G_OBJECT (plugin_loader), "network-available");
+       g_object_notify (G_OBJECT (plugin_loader), "network-metered");
 
        if (available && !metered) {
                g_autoptr(GsAppList) queue = NULL;
@@ -2904,6 +2920,17 @@ gs_plugin_loader_network_available_notify_cb (GObject    *obj,
        gs_plugin_loader_network_changed_cb (monitor, g_network_monitor_get_network_available (monitor), 
plugin_loader);
 }
 
+static void
+gs_plugin_loader_network_metered_notify_cb (GObject    *obj,
+                                           GParamSpec *pspec,
+                                           gpointer    user_data)
+{
+       GNetworkMonitor *monitor = G_NETWORK_MONITOR (obj);
+       GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (user_data);
+
+       gs_plugin_loader_network_changed_cb (monitor, g_network_monitor_get_network_available (monitor), 
plugin_loader);
+}
+
 static void
 gs_plugin_loader_monitor_network (GsPluginLoader *plugin_loader)
 {
@@ -2921,6 +2948,9 @@ gs_plugin_loader_monitor_network (GsPluginLoader *plugin_loader)
        priv->network_available_notify_handler =
                g_signal_connect (priv->network_monitor, "notify::network-available",
                                  G_CALLBACK (gs_plugin_loader_network_available_notify_cb), plugin_loader);
+       priv->network_metered_notify_handler =
+               g_signal_connect (priv->network_monitor, "notify::network-metered",
+                                 G_CALLBACK (gs_plugin_loader_network_metered_notify_cb), plugin_loader);
 
        gs_plugin_loader_network_changed_cb (priv->network_monitor,
                            g_network_monitor_get_network_available (priv->network_monitor),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]