[glib] gio: Fix application of GNetworkMonitor:network-metered patch
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gio: Fix application of GNetworkMonitor:network-metered patch
- Date: Wed, 29 Jul 2015 10:59:44 +0000 (UTC)
commit 6b652b1a2e7c6f67e9576e4331da76971d54cc68
Author: Philip Withnall <philip withnall collabora co uk>
Date: Wed Jul 29 11:56:41 2015 +0100
gio: Fix application of GNetworkMonitor:network-metered patch
The wrong patch from https://bugzilla.gnome.org/show_bug.cgi?id=750282
was applied, causing test failures due to not implementing the property
on GNetworkMonitorBase (plus some other omissions).
Fix that by reverting commit a80e7db1a8f26dc558085844dcb8003edb6eca74
and re-applying the correct patch over the top.
https://bugzilla.gnome.org/show_bug.cgi?id=750282
gio/gnetworkmonitor.c | 18 +++++++++++-------
gio/gnetworkmonitorbase.c | 7 +++++++
gio/gnetworkmonitornm.c | 9 ++++++---
gio/tests/network-monitor.c | 11 +++++++++++
4 files changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/gio/gnetworkmonitor.c b/gio/gnetworkmonitor.c
index 60c5987..42cfedc 100644
--- a/gio/gnetworkmonitor.c
+++ b/gio/gnetworkmonitor.c
@@ -118,9 +118,7 @@ g_network_monitor_get_network_available (GNetworkMonitor *monitor)
* g_network_monitor_get_network_metered:
* @monitor: the #GNetworkMonitor
*
- * Checks if the network is metered. "Metered" here means that the
- * traffic flowing through the connection is subject to limitations,
- * for example set by service providers.
+ * Checks if the network is metered.
* See #GNetworkMonitor:network-metered for more details.
*
* Returns: whether the connection is metered
@@ -362,15 +360,21 @@ g_network_monitor_default_init (GNetworkMonitorInterface *iface)
*
* Whether the network is considered metered. That is, whether the
* system has traffic flowing through the default connection that is
- * subject to limitations for example set by service providers.
+ * subject to limitations set by service providers. For example, traffic
+ * might be billed by the amount of data transmitted, or there might be a
+ * quota on the amount of traffic per month. This is typical with tethered
+ * connections (3G and 4G) and in such situations, bandwidth intensive
+ * applications may wish to avoid network activity where possible if it will
+ * cost the user money or use up their limited quota.
*
* If more information is required about specific devices then the
- * system network management API should be used instead.
+ * system network management API should be used instead (for example,
+ * NetworkManager or ConnMan).
*
- * If this information is not available then no networks willl be
+ * If this information is not available then no networks will be
* marked as metered.
*
- * See also #GNetworkMonitor::network-available.
+ * See also #GNetworkMonitor:network-available.
*
* Since: 2.46
*/
diff --git a/gio/gnetworkmonitorbase.c b/gio/gnetworkmonitorbase.c
index f0af804..7d34712 100644
--- a/gio/gnetworkmonitorbase.c
+++ b/gio/gnetworkmonitorbase.c
@@ -39,6 +39,7 @@ enum
PROP_0,
PROP_NETWORK_AVAILABLE,
+ PROP_NETWORK_METERED,
PROP_CONNECTIVITY
};
@@ -119,6 +120,11 @@ g_network_monitor_base_get_property (GObject *object,
g_value_set_boolean (value, monitor->priv->is_available);
break;
+ case PROP_NETWORK_METERED:
+ /* Default to FALSE in the unknown case. */
+ g_value_set_boolean (value, FALSE);
+ break;
+
case PROP_CONNECTIVITY:
g_value_set_enum (value,
monitor->priv->is_available ?
@@ -160,6 +166,7 @@ g_network_monitor_base_class_init (GNetworkMonitorBaseClass *monitor_class)
gobject_class->finalize = g_network_monitor_base_finalize;
g_object_class_override_property (gobject_class, PROP_NETWORK_AVAILABLE, "network-available");
+ g_object_class_override_property (gobject_class, PROP_NETWORK_METERED, "network-metered");
g_object_class_override_property (gobject_class, PROP_CONNECTIVITY, "connectivity");
}
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
index c2f861a..afa23f7 100644
--- a/gio/gnetworkmonitornm.c
+++ b/gio/gnetworkmonitornm.c
@@ -134,10 +134,13 @@ nm_metered_to_bool (guint nm_metered)
{
switch (nm_metered)
{
- case 0: /* unknown */
case 1: /* yes */
case 3: /* guess-yes */
return TRUE;
+ case 0: /* unknown */
+ /* We default to FALSE in the unknown-because-you're-not-running-NM
+ * case, so we should return FALSE in the
+ * unknown-when-you-are-running-NM case too. */
case 2: /* no */
case 4: /* guess-no */
return FALSE;
@@ -170,7 +173,7 @@ sync_properties (GNetworkMonitorNM *nm,
else
{
- /* this is only available post 1.0 */
+ /* this is only available post NM 1.0 */
v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "Metered");
if (v == NULL)
{
@@ -202,7 +205,7 @@ sync_properties (GNetworkMonitorNM *nm,
if (new_network_metered != nm->priv->network_metered)
{
nm->priv->network_metered = new_network_metered;
- g_object_notify (G_OBJECT (nm), "network-available");
+ g_object_notify (G_OBJECT (nm), "network-metered");
}
if (new_connectivity != nm->priv->connectivity)
{
diff --git a/gio/tests/network-monitor.c b/gio/tests/network-monitor.c
index 04f75f1..2e38e39 100644
--- a/gio/tests/network-monitor.c
+++ b/gio/tests/network-monitor.c
@@ -500,6 +500,14 @@ watch_connectivity_changed (GNetworkMonitor *monitor,
}
static void
+watch_metered_changed (GNetworkMonitor *monitor,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ g_print ("Metered is %d\n", g_network_monitor_get_network_metered (monitor));
+}
+
+static void
do_watch_network (void)
{
GNetworkMonitor *monitor = g_network_monitor_get_default ();
@@ -511,8 +519,11 @@ do_watch_network (void)
G_CALLBACK (watch_network_changed), NULL);
g_signal_connect (monitor, "notify::connectivity",
G_CALLBACK (watch_connectivity_changed), NULL);
+ g_signal_connect (monitor, "notify::network-metered",
+ G_CALLBACK (watch_metered_changed), NULL);
watch_network_changed (monitor, g_network_monitor_get_network_available (monitor), NULL);
watch_connectivity_changed (monitor, NULL, NULL);
+ watch_metered_changed (monitor, NULL, NULL);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]