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 a80e7db1a8
and re-applying the correct patch over the top.

https://bugzilla.gnome.org/show_bug.cgi?id=750282
This commit is contained in:
Philip Withnall 2015-07-29 11:56:41 +01:00
parent 7f195ac956
commit 6b652b1a2e
4 changed files with 35 additions and 10 deletions

View File

@ -118,9 +118,7 @@ g_network_monitor_get_network_available (GNetworkMonitor *monitor)
* g_network_monitor_get_network_metered: * g_network_monitor_get_network_metered:
* @monitor: the #GNetworkMonitor * @monitor: the #GNetworkMonitor
* *
* Checks if the network is metered. "Metered" here means that the * Checks if the network is metered.
* traffic flowing through the connection is subject to limitations,
* for example set by service providers.
* See #GNetworkMonitor:network-metered for more details. * See #GNetworkMonitor:network-metered for more details.
* *
* Returns: whether the connection is metered * 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 * Whether the network is considered metered. That is, whether the
* system has traffic flowing through the default connection that is * 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 * 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. * marked as metered.
* *
* See also #GNetworkMonitor::network-available. * See also #GNetworkMonitor:network-available.
* *
* Since: 2.46 * Since: 2.46
*/ */

View File

@ -39,6 +39,7 @@ enum
PROP_0, PROP_0,
PROP_NETWORK_AVAILABLE, PROP_NETWORK_AVAILABLE,
PROP_NETWORK_METERED,
PROP_CONNECTIVITY PROP_CONNECTIVITY
}; };
@ -119,6 +120,11 @@ g_network_monitor_base_get_property (GObject *object,
g_value_set_boolean (value, monitor->priv->is_available); g_value_set_boolean (value, monitor->priv->is_available);
break; break;
case PROP_NETWORK_METERED:
/* Default to FALSE in the unknown case. */
g_value_set_boolean (value, FALSE);
break;
case PROP_CONNECTIVITY: case PROP_CONNECTIVITY:
g_value_set_enum (value, g_value_set_enum (value,
monitor->priv->is_available ? 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; 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_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"); g_object_class_override_property (gobject_class, PROP_CONNECTIVITY, "connectivity");
} }

View File

@ -134,10 +134,13 @@ nm_metered_to_bool (guint nm_metered)
{ {
switch (nm_metered) switch (nm_metered)
{ {
case 0: /* unknown */
case 1: /* yes */ case 1: /* yes */
case 3: /* guess-yes */ case 3: /* guess-yes */
return TRUE; 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 2: /* no */
case 4: /* guess-no */ case 4: /* guess-no */
return FALSE; return FALSE;
@ -170,7 +173,7 @@ sync_properties (GNetworkMonitorNM *nm,
else 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"); v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "Metered");
if (v == NULL) if (v == NULL)
{ {
@ -202,7 +205,7 @@ sync_properties (GNetworkMonitorNM *nm,
if (new_network_metered != nm->priv->network_metered) if (new_network_metered != nm->priv->network_metered)
{ {
nm->priv->network_metered = new_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) if (new_connectivity != nm->priv->connectivity)
{ {

View File

@ -499,6 +499,14 @@ watch_connectivity_changed (GNetworkMonitor *monitor,
g_print ("Connectivity is %d\n", g_network_monitor_get_connectivity (monitor)); g_print ("Connectivity is %d\n", g_network_monitor_get_connectivity (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 static void
do_watch_network (void) do_watch_network (void)
{ {
@ -511,8 +519,11 @@ do_watch_network (void)
G_CALLBACK (watch_network_changed), NULL); G_CALLBACK (watch_network_changed), NULL);
g_signal_connect (monitor, "notify::connectivity", g_signal_connect (monitor, "notify::connectivity",
G_CALLBACK (watch_connectivity_changed), NULL); 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_network_changed (monitor, g_network_monitor_get_network_available (monitor), NULL);
watch_connectivity_changed (monitor, NULL, NULL); watch_connectivity_changed (monitor, NULL, NULL);
watch_metered_changed (monitor, NULL, NULL);
loop = g_main_loop_new (NULL, FALSE); loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop); g_main_loop_run (loop);