[gnome-control-center] network: Only show the flight mode toggle when there are wireless devices
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Only show the flight mode toggle when there are wireless devices
- Date: Tue, 24 Jan 2012 15:50:00 +0000 (UTC)
commit d1a5af0818e3bff3180875ef6f0aebb70d7f891d
Author: Richard Hughes <richard hughsie com>
Date: Tue Jan 24 15:49:06 2012 +0000
network: Only show the flight mode toggle when there are wireless devices
panels/network/cc-network-panel.c | 55 ++++++++++++++++++++++++++++++++++++-
1 files changed, 54 insertions(+), 1 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 25a8521..63cced9 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -630,6 +630,54 @@ register_object_interest (CcNetworkPanel *panel, NetObject *object)
panel);
}
+static void
+panel_refresh_killswitch_visibility (CcNetworkPanel *panel)
+{
+ gboolean ret;
+ gboolean show_flight_toggle = FALSE;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ NetObject *object_tmp;
+ NMDeviceModemCapabilities caps;
+ NMDevice *nm_device;
+
+ /* find any wireless devices in model */
+ model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
+ "liststore_devices"));
+ ret = gtk_tree_model_get_iter_first (model, &iter);
+ if (!ret)
+ return;
+ do {
+ gtk_tree_model_get (model, &iter,
+ PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
+ -1);
+ if (NET_IS_DEVICE (object_tmp)) {
+ nm_device = net_device_get_nm_device (NET_DEVICE (object_tmp));
+ switch (nm_device_get_device_type (nm_device)) {
+ case NM_DEVICE_TYPE_WIFI:
+ case NM_DEVICE_TYPE_WIMAX:
+ show_flight_toggle = TRUE;
+ break;
+ case NM_DEVICE_TYPE_MODEM:
+ {
+ caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
+ if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
+ (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO))
+ show_flight_toggle = TRUE;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ g_object_unref (object_tmp);
+ } while (!show_flight_toggle && gtk_tree_model_iter_next (model, &iter));
+
+ /* only show toggle if there are wireless devices */
+ gtk_widget_set_visible (panel->priv->kill_switch_header,
+ show_flight_toggle);
+}
+
static gboolean
panel_add_device (CcNetworkPanel *panel, NMDevice *device)
{
@@ -2266,6 +2314,7 @@ device_added_cb (NMClient *client, NMDevice *device, CcNetworkPanel *panel)
{
g_debug ("New device added");
panel_add_device (panel, device);
+ panel_refresh_killswitch_visibility (panel);
}
static void
@@ -2273,6 +2322,7 @@ device_removed_cb (NMClient *client, NMDevice *device, CcNetworkPanel *panel)
{
g_debug ("Device removed");
panel_remove_device (panel, device);
+ panel_refresh_killswitch_visibility (panel);
}
static void
@@ -3195,16 +3245,19 @@ network_add_shell_header_widgets_cb (gpointer user_data)
* network panel */
widget = gtk_label_new (_("Airplane Mode"));
gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
+ gtk_widget_set_visible (widget, TRUE);
widget = gtk_switch_new ();
gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
+ gtk_widget_set_visible (widget, TRUE);
cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (panel)), box);
- gtk_widget_show_all (box);
+ panel->priv->kill_switch_header = g_object_ref (box);
ret = nm_client_wireless_get_enabled (panel->priv->client);
gtk_switch_set_active (GTK_SWITCH (widget), !ret);
g_signal_connect (GTK_SWITCH (widget), "notify::active",
G_CALLBACK (cc_network_panel_notify_enable_active_cb),
panel);
+ panel_refresh_killswitch_visibility (panel);
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]