summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2018-08-23 23:25:48 -0400
committerMatthias Clasen <mclasen@redhat.com>2018-08-27 10:55:30 -0400
commit5c5881b2ed0069a2cd4adf856b608743ebd1be97 (patch)
tree5f8749d0a2991b77a6051831658a426579f3cb31
parenta090d8605bc5e393c603f5ec0cfcf31259e82e3e (diff)
downloadglib-5c5881b2ed0069a2cd4adf856b608743ebd1be97.tar.gz
portal network monitor: use GetStatus when available
Version 3 of the portal interface adds a GetStatus method that gets all data in a single roundtrip. Use it when available.
-rw-r--r--gio/gnetworkmonitorportal.c75
1 files changed, 71 insertions, 4 deletions
diff --git a/gio/gnetworkmonitorportal.c b/gio/gnetworkmonitorportal.c
index ebf210e5b..9ec5e37fb 100644
--- a/gio/gnetworkmonitorportal.c
+++ b/gio/gnetworkmonitorportal.c
@@ -184,12 +184,79 @@ got_connectivity (GObject *source,
}
static void
+got_status (GObject *source,
+ GAsyncResult *res,
+ gpointer data)
+{
+ GDBusProxy *proxy = G_DBUS_PROXY (source);
+ GNetworkMonitorPortal *nm = G_NETWORK_MONITOR_PORTAL (data);
+ GError *error = NULL;
+ GVariant *ret;
+ gboolean should_emit_changed = FALSE;
+ GVariant *status;
+ gboolean available;
+ gboolean metered;
+ GNetworkConnectivity connectivity;
+
+ ret = g_dbus_proxy_call_finish (proxy, res, &error);
+ if (ret == NULL)
+ {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ g_variant_get (ret, "(@a{sv})", &status);
+ g_variant_unref (ret);
+
+ g_variant_lookup (status, "available", "b", &available);
+ g_variant_lookup (status, "metered", "b", &metered);
+ g_variant_lookup (status, "connectivity", "u", &connectivity);
+ g_variant_unref (status);
+
+ g_object_freeze_notify (G_OBJECT (nm));
+
+ if (nm->priv->available != available)
+ {
+ nm->priv->available = available;
+ g_object_notify (G_OBJECT (nm), "network-available");
+ should_emit_changed = TRUE;
+ }
+
+ if (nm->priv->metered != metered)
+ {
+ nm->priv->metered = metered;
+ g_object_notify (G_OBJECT (nm), "network-metered");
+ should_emit_changed = TRUE;
+ }
+
+ if (nm->priv->connectivity != connectivity)
+ {
+ nm->priv->connectivity = connectivity;
+ g_object_notify (G_OBJECT (nm), "connectivity");
+ should_emit_changed = TRUE;
+ }
+
+ g_object_thaw_notify (G_OBJECT (nm));
+
+ if (should_emit_changed)
+ g_signal_emit_by_name (nm, "network-changed", available);
+}
+
+static void
update_properties (GDBusProxy *proxy,
GNetworkMonitorPortal *nm)
{
- g_dbus_proxy_call (proxy, "GetConnectivity", NULL, 0, -1, NULL, got_connectivity, nm);
- g_dbus_proxy_call (proxy, "GetMetered", NULL, 0, -1, NULL, got_metered, nm);
- g_dbus_proxy_call (proxy, "GetAvailable", NULL, 0, -1, NULL, got_available, nm);
+ if (nm->priv->version == 3)
+ {
+ g_dbus_proxy_call (proxy, "GetStatus", NULL, 0, -1, NULL, got_status, nm);
+ }
+ else
+ {
+ g_dbus_proxy_call (proxy, "GetConnectivity", NULL, 0, -1, NULL, got_connectivity, nm);
+ g_dbus_proxy_call (proxy, "GetMetered", NULL, 0, -1, NULL, got_metered, nm);
+ g_dbus_proxy_call (proxy, "GetAvailable", NULL, 0, -1, NULL, got_available, nm);
+ }
}
static void
@@ -209,7 +276,7 @@ proxy_signal (GDBusProxy *proxy,
g_variant_get (parameters, "(b)", &available);
g_signal_emit_by_name (nm, "network-changed", available);
}
- else if (nm->priv->version == 2)
+ else if (nm->priv->version == 2 || nm->priv->version == 3)
{
update_properties (proxy, nm);
}