[network-manager-netbook] Fix device type and flight mode switches.
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Subject: [network-manager-netbook] Fix device type and flight mode switches.
- Date: Tue, 16 Jun 2009 08:01:35 -0400 (EDT)
commit 38e3cf777ddc89cd99dd9dc8d26ef96690954632
Author: Tambet Ingo <tambet gmail com>
Date: Mon Jun 15 13:04:01 2009 +0300
Fix device type and flight mode switches.
src/nmn-applet.c | 50 +++++++++++++---------
src/nmn-nm-data.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++
src/nmn-nm-data.h | 30 ++++++++++---
src/nmn-wifi-handler.c | 38 +++++++++++++++++
4 files changed, 199 insertions(+), 28 deletions(-)
---
diff --git a/src/nmn-applet.c b/src/nmn-applet.c
index 9fa910a..3085dae 100644
--- a/src/nmn-applet.c
+++ b/src/nmn-applet.c
@@ -67,21 +67,19 @@ enable_wifi_toggled (NbtkGtkLightSwitch *w,
{
NmnAppletPrivate *priv = GET_PRIVATE (user_data);
- nm_client_wireless_set_enabled (NM_CLIENT (priv->nm_data), active);
+ nmn_nm_data_wifi_toggled (priv->nm_data, active);
}
static void
-wireless_state_changed (NMClient *client,
- GParamSpec *pspec,
- gpointer user_data)
+wifi_toggled (NmnNMData *nm_data,
+ gboolean active,
+ gpointer user_data)
{
NmnAppletPrivate *priv = GET_PRIVATE (user_data);
- g_signal_handlers_block_by_func (priv->enable_wifi, enable_wifi_toggled, user_data);
- nbtk_gtk_light_switch_set_active (NBTK_GTK_LIGHT_SWITCH (priv->enable_wifi),
- nm_client_wireless_get_enabled (client));
-
- g_signal_handlers_unblock_by_func (priv->enable_wifi, enable_wifi_toggled, user_data);
+ g_signal_handlers_block_by_func (priv->nm_data, enable_wifi_toggled, user_data);
+ nbtk_gtk_light_switch_set_active (NBTK_GTK_LIGHT_SWITCH (priv->enable_wifi), active);
+ g_signal_handlers_unblock_by_func (priv->nm_data, enable_wifi_toggled, user_data);
}
static void
@@ -99,17 +97,8 @@ enable_wifi_setup (NmnApplet *applet)
g_signal_connect (priv->enable_wifi, "switch-flipped", G_CALLBACK (enable_wifi_toggled), applet);
gtk_widget_show (priv->enable_wifi);
- g_signal_connect (priv->nm_data,
- "notify::" NM_CLIENT_WIRELESS_ENABLED,
- G_CALLBACK (wireless_state_changed),
- applet);
-
- g_signal_connect (priv->nm_data,
- "notify::" NM_CLIENT_WIRELESS_HARDWARE_ENABLED,
- G_CALLBACK (wireless_state_changed),
- applet);
-
- wireless_state_changed (NM_CLIENT (priv->nm_data), NULL, applet);
+ g_signal_connect (priv->nm_data, "wifi-toggled", G_CALLBACK (wifi_toggled), applet);
+ wifi_toggled (priv->nm_data, nmn_nm_data_wifi_get_active (priv->nm_data), applet);
}
/* enable/disable ethernet button */
@@ -209,7 +198,23 @@ enable_flightmode_toggled (NbtkGtkLightSwitch *w,
gtk_widget_set_sensitive (priv->enable_wifi, !active);
gtk_widget_set_sensitive (priv->enable_3g, !active);
- nm_client_wireless_set_enabled (NM_CLIENT (priv->nm_data), !active);
+ nmn_nm_data_flight_mode_toggled (priv->nm_data, active);
+}
+
+static void
+flightmode_toggled (NmnNMData *nm_data,
+ gboolean active,
+ gpointer user_data)
+{
+ NmnAppletPrivate *priv = GET_PRIVATE (user_data);
+
+ g_signal_handlers_block_by_func (priv->nm_data, enable_flightmode_toggled, user_data);
+ nbtk_gtk_light_switch_set_active (NBTK_GTK_LIGHT_SWITCH (priv->enable_flightmode), active);
+ g_signal_handlers_unblock_by_func (priv->nm_data, enable_flightmode_toggled, user_data);
+
+ gtk_widget_set_sensitive (priv->enable_flightmode, nmn_nm_data_flight_mode_can_change (priv->nm_data));
+ gtk_widget_set_sensitive (priv->enable_3g, !active);
+ gtk_widget_set_sensitive (priv->enable_wifi, !active);
}
static void
@@ -226,6 +231,9 @@ enable_flightmode_setup (NmnApplet *applet)
g_signal_connect (priv->enable_flightmode, "switch-flipped", G_CALLBACK (enable_flightmode_toggled), applet);
gtk_widget_show (priv->enable_flightmode);
+
+ g_signal_connect (priv->nm_data, "flight-mode-toggled", G_CALLBACK (flightmode_toggled), applet);
+ flightmode_toggled (priv->nm_data, nmn_nm_data_flight_mode_get_active (priv->nm_data), applet);
}
/* add new connection button */
diff --git a/src/nmn-nm-data.c b/src/nmn-nm-data.c
index 51e5649..d1053f4 100644
--- a/src/nmn-nm-data.c
+++ b/src/nmn-nm-data.c
@@ -8,7 +8,9 @@ G_DEFINE_TYPE (NmnNMData, nmn_nm_data, NM_TYPE_CLIENT)
enum {
ETHERNET_TOGGLED,
+ WIFI_TOGGLED,
MODEMS_TOGGLED,
+ FLIGHT_MODE_TOGGLED,
LAST_SIGNAL
};
@@ -22,7 +24,9 @@ typedef struct {
NMSettings *system_settings;
gboolean ethernet_active;
+ gboolean wifi_active;
gboolean modems_active;
+ gboolean flight_mode_active;
gboolean disposed;
} NmnNMDataPrivate;
@@ -77,6 +81,30 @@ nmn_nm_data_ethernet_toggled (NmnNMData *self,
}
gboolean
+nmn_nm_data_wifi_get_active (NmnNMData *self)
+{
+ g_return_val_if_fail (NMN_IS_NM_DATA (self), FALSE);
+
+ return GET_PRIVATE (self)->wifi_active;
+}
+
+void
+nmn_nm_data_wifi_toggled (NmnNMData *self,
+ gboolean active)
+{
+ NmnNMDataPrivate *priv;
+
+ g_return_if_fail (NMN_IS_NM_DATA (self));
+
+ priv = GET_PRIVATE (self);
+ if (priv->wifi_active != active) {
+ /* FIXME: Save in gconf? */
+ priv->wifi_active = active;
+ g_signal_emit (self, signals[WIFI_TOGGLED], 0, active);
+ }
+}
+
+gboolean
nmn_nm_data_modems_get_active (NmnNMData *self)
{
g_return_val_if_fail (NMN_IS_NM_DATA (self), FALSE);
@@ -100,6 +128,53 @@ nmn_nm_data_modems_toggled (NmnNMData *self,
}
}
+gboolean
+nmn_nm_data_flight_mode_can_change (NmnNMData *self)
+{
+ g_return_val_if_fail (NMN_IS_NM_DATA (self), FALSE);
+
+ return nm_client_wireless_hardware_get_enabled (NM_CLIENT (self));
+}
+
+gboolean
+nmn_nm_data_flight_mode_get_active (NmnNMData *self)
+{
+ g_return_val_if_fail (NMN_IS_NM_DATA (self), FALSE);
+
+ return GET_PRIVATE (self)->flight_mode_active;
+}
+
+static void
+flight_mode_toggled_internal (NmnNMData *self, gboolean active)
+{
+ NmnNMDataPrivate *priv = GET_PRIVATE (self);
+
+ if (priv->flight_mode_active != active) {
+ /* FIXME: Save in gconf? */
+ priv->flight_mode_active = active;
+ g_signal_emit (self, signals[FLIGHT_MODE_TOGGLED], 0, active);
+ }
+}
+
+void
+nmn_nm_data_flight_mode_toggled (NmnNMData *self,
+ gboolean active)
+{
+ g_return_if_fail (NMN_IS_NM_DATA (self));
+
+ flight_mode_toggled_internal (self, active);
+ nm_client_wireless_set_enabled (NM_CLIENT (self), !active);
+}
+
+static void
+nm_wireless_state_changed (NMClient *client,
+ GParamSpec *gobject,
+ gpointer user_data)
+{
+ flight_mode_toggled_internal (NMN_NM_DATA (client),
+ !nm_client_wireless_get_enabled (client));
+}
+
static void
nmn_nm_data_init (NmnNMData *self)
{
@@ -107,7 +182,9 @@ nmn_nm_data_init (NmnNMData *self)
/* FIXME: Load from gconf? */
priv->ethernet_active = TRUE;
+ priv->wifi_active = TRUE;
priv->modems_active = TRUE;
+ priv->flight_mode_active = FALSE;
}
static GObject*
@@ -131,6 +208,18 @@ constructor (GType type,
priv->user_settings = NM_SETTINGS (nma_gconf_settings_new ());
priv->system_settings = NM_SETTINGS (nm_dbus_settings_system_new (bus));
+ g_signal_connect (object,
+ "notify::" NM_CLIENT_WIRELESS_ENABLED,
+ G_CALLBACK (nm_wireless_state_changed),
+ NULL);
+
+ g_signal_connect (object,
+ "notify::" NM_CLIENT_WIRELESS_HARDWARE_ENABLED,
+ G_CALLBACK (nm_wireless_state_changed),
+ NULL);
+
+ nm_wireless_state_changed (NM_CLIENT (object), NULL, NULL);
+
return object;
}
@@ -170,6 +259,16 @@ nmn_nm_data_class_init (NmnNMDataClass *class)
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
+ signals[WIFI_TOGGLED] = g_signal_new
+ ("wifi-toggled",
+ G_OBJECT_CLASS_TYPE (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NmnNMDataClass, wifi_toggled),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1,
+ G_TYPE_BOOLEAN);
+
signals[MODEMS_TOGGLED] = g_signal_new
("modems-toggled",
G_OBJECT_CLASS_TYPE (class),
@@ -179,4 +278,14 @@ nmn_nm_data_class_init (NmnNMDataClass *class)
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
+
+ signals[FLIGHT_MODE_TOGGLED] = g_signal_new
+ ("flight-mode-toggled",
+ G_OBJECT_CLASS_TYPE (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NmnNMDataClass, flight_mode_toggled),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1,
+ G_TYPE_BOOLEAN);
}
diff --git a/src/nmn-nm-data.h b/src/nmn-nm-data.h
index 8886f45..f9ccbe4 100644
--- a/src/nmn-nm-data.h
+++ b/src/nmn-nm-data.h
@@ -25,22 +25,38 @@ typedef struct {
void (*ethernet_toggled) (NmnNMData *self,
gboolean active);
+ void (*wifi_toggled) (NmnNMData *self,
+ gboolean active);
+
void (*modems_toggled) (NmnNMData *self,
gboolean active);
+
+ void (*flight_mode_toggled) (NmnNMData *self,
+ gboolean active);
+
} NmnNMDataClass;
GType nmn_nm_data_get_type (void);
-NmnNMData *nmn_nm_data_new (DBusGConnection *bus);
-NMSettings *nmn_nm_data_get_user_settings (NmnNMData *data);
-NMSettings *nmn_nm_data_get_system_settings (NmnNMData *data);
+NmnNMData *nmn_nm_data_new (DBusGConnection *bus);
+NMSettings *nmn_nm_data_get_user_settings (NmnNMData *data);
+NMSettings *nmn_nm_data_get_system_settings (NmnNMData *data);
+
+gboolean nmn_nm_data_ethernet_get_active (NmnNMData *self);
+void nmn_nm_data_ethernet_toggled (NmnNMData *self,
+ gboolean active);
+
+gboolean nmn_nm_data_wifi_get_active (NmnNMData *self);
+void nmn_nm_data_wifi_toggled (NmnNMData *self,
+ gboolean active);
-gboolean nmn_nm_data_ethernet_get_active (NmnNMData *self);
-void nmn_nm_data_ethernet_toggled (NmnNMData *self,
+gboolean nmn_nm_data_modems_get_active (NmnNMData *self);
+void nmn_nm_data_modems_toggled (NmnNMData *self,
gboolean active);
-gboolean nmn_nm_data_modems_get_active (NmnNMData *self);
-void nmn_nm_data_modems_toggled (NmnNMData *self,
+gboolean nmn_nm_data_flight_mode_can_change (NmnNMData *self);
+gboolean nmn_nm_data_flight_mode_get_active (NmnNMData *self);
+void nmn_nm_data_flight_mode_toggled (NmnNMData *self,
gboolean active);
#endif /* NMN_NM_DATA_H */
diff --git a/src/nmn-wifi-handler.c b/src/nmn-wifi-handler.c
index dadae80..886755c 100644
--- a/src/nmn-wifi-handler.c
+++ b/src/nmn-wifi-handler.c
@@ -13,6 +13,7 @@ G_DEFINE_TYPE (NmnWifiHandler, nmn_wifi_handler, NMN_TYPE_DEVICE_HANDLER)
#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NMN_TYPE_WIFI_HANDLER, NmnWifiHandlerPrivate))
typedef struct {
+ gulong wifi_toggled_id;
gulong ap_added_id;
gulong ap_removed_id;
gulong ap_changed_id;
@@ -169,12 +170,41 @@ active_ap_changed (NMDeviceWifi *device,
update_items (NMN_WIFI_HANDLER (user_data));
}
+static void
+wifi_toggled (NmnNMData *nm_data,
+ gboolean active,
+ gpointer user_data)
+{
+ NmnDeviceHandler *handler = NMN_DEVICE_HANDLER (user_data);
+ GSList *list;
+ GSList *iter;
+
+ if (active) {
+ list = nmn_device_handler_get_connections (handler);
+ for (iter = list; iter; iter = iter->next)
+ connection_added (handler, NM_EXPORTED_CONNECTION (iter->data));
+
+ g_slist_free (list);
+ } else {
+ list = nmn_device_handler_get_items (handler);
+ for (iter = list; iter; iter = iter->next) {
+ NmnItem *item = NMN_ITEM (iter->data);
+
+ if (nmn_item_get_status (item) != NMN_ITEM_STATUS_DISCONNECTED)
+ nmn_item_disconnect_request (item);
+
+ nmn_item_remove_request (item);
+ }
+ }
+}
+
static GObject*
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
GObject *object;
+ NmnNMData *nm_data;
NmnWifiHandlerPrivate *priv;
NMDeviceWifi *device;
const GPtrArray *aps;
@@ -187,6 +217,10 @@ constructor (GType type,
return NULL;
priv = GET_PRIVATE (object);
+
+ nm_data = nmn_device_handler_get_nm_data (NMN_DEVICE_HANDLER (object));
+ priv->wifi_toggled_id = g_signal_connect (nm_data, "wifi-toggled", G_CALLBACK (wifi_toggled), object);
+
device = NM_DEVICE_WIFI (nmn_device_handler_get_device (NMN_DEVICE_HANDLER (object)));
priv->ap_added_id = g_signal_connect (device, "access-point-added", G_CALLBACK (ap_added), object);
@@ -213,6 +247,7 @@ static void
dispose (GObject *object)
{
NmnWifiHandlerPrivate *priv = GET_PRIVATE (object);
+ NmnNMData *nm_data;
NMDeviceWifi *device;
const GPtrArray *aps;
int i;
@@ -220,6 +255,9 @@ dispose (GObject *object)
if (priv->disposed)
return;
+ nm_data = nmn_device_handler_get_nm_data (NMN_DEVICE_HANDLER (object));
+ g_signal_handler_disconnect (nm_data, priv->wifi_toggled_id);
+
device = NM_DEVICE_WIFI (nmn_device_handler_get_device (NMN_DEVICE_HANDLER (object)));
aps = nm_device_wifi_get_access_points (device);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]