[network-manager-netbook] Handle unmanaged and disabled (due to rfkill for example) devices.
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Subject: [network-manager-netbook] Handle unmanaged and disabled (due to rfkill for example) devices.
- Date: Tue, 16 Jun 2009 08:01:40 -0400 (EDT)
commit 535cc631c094397e7987430725810d3c110f3cde
Author: Tambet Ingo <tambet gmail com>
Date: Tue Jun 16 13:57:21 2009 +0300
Handle unmanaged and disabled (due to rfkill for example) devices.
Reorganize the code a bit to get rid of some stupid duplication.
src/nmn-device-handler.c | 71 ++++++++++++++++++++++++++++++++++++-------
src/nmn-device-handler.h | 3 +-
src/nmn-ethernet-handler.c | 24 ++------------
src/nmn-serial-handler.c | 25 +++------------
src/nmn-wifi-handler.c | 23 ++------------
5 files changed, 74 insertions(+), 72 deletions(-)
---
diff --git a/src/nmn-device-handler.c b/src/nmn-device-handler.c
index ebf153a..14c1cf0 100644
--- a/src/nmn-device-handler.c
+++ b/src/nmn-device-handler.c
@@ -27,6 +27,7 @@ typedef struct {
NMDevice *device;
GSList *items;
gboolean started;
+ gulong device_state_changed_id;
gulong user_connection_added_id;
gulong system_connection_added_id;
@@ -51,11 +52,41 @@ add_one_connection (gpointer data, gpointer user_data)
}
void
+nmn_device_handler_add_items (NmnDeviceHandler *self)
+{
+ GSList *list;
+
+ g_return_if_fail (NMN_IS_DEVICE_HANDLER (self));
+ g_return_if_fail (GET_PRIVATE (self)->started);
+
+ if (nm_device_get_state (nmn_device_handler_get_device (self)) < NM_DEVICE_STATE_DISCONNECTED)
+ return;
+
+ list = nmn_device_handler_get_connections (self);
+ g_slist_foreach (list, add_one_connection, self);
+ g_slist_free (list);
+}
+
+static void
+device_state_changed (NMDevice *device,
+ NMDeviceState new_state,
+ NMDeviceState old_state,
+ NMDeviceStateReason reason,
+ gboolean user_data)
+{
+ NmnDeviceHandler *handler = NMN_DEVICE_HANDLER (user_data);
+
+ if (new_state < NM_DEVICE_STATE_DISCONNECTED)
+ nmn_device_handler_remove_items (handler);
+ else if (old_state < NM_DEVICE_STATE_DISCONNECTED && new_state >= NM_DEVICE_STATE_DISCONNECTED)
+ nmn_device_handler_add_items (handler);
+}
+
+void
nmn_device_handler_start (NmnDeviceHandler *self)
{
NMSettings *settings;
NmnDeviceHandlerPrivate *priv;
- GSList *list;
g_return_if_fail (NMN_IS_DEVICE_HANDLER (self));
@@ -65,25 +96,20 @@ nmn_device_handler_start (NmnDeviceHandler *self)
priv->started = TRUE;
+ priv->device_state_changed_id = g_signal_connect (priv->device, "state-changed",
+ G_CALLBACK (device_state_changed), self);
+
settings = nmn_nm_data_get_user_settings (priv->nm_data);
- if (settings) {
+ if (settings)
priv->user_connection_added_id = g_signal_connect (settings, "new-connection",
G_CALLBACK (connection_added), self);
- list = nm_settings_list_connections (settings);
- g_slist_foreach (list, add_one_connection, self);
- g_slist_free (list);
- }
-
settings = nmn_nm_data_get_system_settings (priv->nm_data);
- if (settings) {
+ if (settings)
priv->system_connection_added_id = g_signal_connect (settings, "new-connection",
G_CALLBACK (connection_added), self);
- list = nm_settings_list_connections (settings);
- g_slist_foreach (list, add_one_connection, self);
- g_slist_free (list);
- }
+ nmn_device_handler_add_items (self);
}
NmnNMData *
@@ -175,6 +201,25 @@ nmn_device_handler_get_item_for_connection (NmnDeviceHandler *self,
return NULL;
}
+void
+nmn_device_handler_remove_items (NmnDeviceHandler *self)
+{
+ GSList *list;
+ GSList *iter;
+
+ g_return_if_fail (NMN_IS_DEVICE_HANDLER (self));
+
+ list = nmn_device_handler_get_items (self);
+ 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 void
nmn_device_handler_init (NmnDeviceHandler *handler)
{
@@ -254,6 +299,8 @@ dispose (GObject *object)
if (priv->disposed)
return;
+ g_signal_handler_disconnect (settings, priv->device_state_changed_id);
+
settings = nmn_nm_data_get_user_settings (priv->nm_data);
g_signal_handler_disconnect (settings, priv->user_connection_added_id);
diff --git a/src/nmn-device-handler.h b/src/nmn-device-handler.h
index 46ce72c..3450bc1 100644
--- a/src/nmn-device-handler.h
+++ b/src/nmn-device-handler.h
@@ -38,7 +38,7 @@ typedef struct {
GType nmn_device_handler_get_type (void);
void nmn_device_handler_start (NmnDeviceHandler *self);
-
+void nmn_device_handler_add_items (NmnDeviceHandler *self);
NmnNMData *nmn_device_handler_get_nm_data (NmnDeviceHandler *self);
NMDevice *nmn_device_handler_get_device (NmnDeviceHandler *self);
@@ -51,5 +51,6 @@ GSList *nmn_device_handler_get_connections (NmnDeviceHandler *self);
NmnItem *nmn_device_handler_get_item_for_connection (NmnDeviceHandler *self,
NMExportedConnection *connection);
+void nmn_device_handler_remove_items (NmnDeviceHandler *self);
#endif /* NMN_DEVICE_HANDLER_H */
diff --git a/src/nmn-ethernet-handler.c b/src/nmn-ethernet-handler.c
index 57bcf88..3e35b49 100644
--- a/src/nmn-ethernet-handler.c
+++ b/src/nmn-ethernet-handler.c
@@ -53,26 +53,10 @@ connection_added (NmnDeviceHandler *handler,
static void
state_changed (NmnDeviceHandler *handler, gboolean active)
{
- 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);
- }
- }
+ if (active)
+ nmn_device_handler_add_items (handler);
+ else
+ nmn_device_handler_remove_items (handler);
}
static void
diff --git a/src/nmn-serial-handler.c b/src/nmn-serial-handler.c
index 5783e53..b550dea 100644
--- a/src/nmn-serial-handler.c
+++ b/src/nmn-serial-handler.c
@@ -53,26 +53,11 @@ modems_toggled (NmnNMData *nm_data,
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);
- }
- }
+
+ if (active)
+ nmn_device_handler_add_items (handler);
+ else
+ nmn_device_handler_remove_items (handler);
}
static void
diff --git a/src/nmn-wifi-handler.c b/src/nmn-wifi-handler.c
index 886755c..818a335 100644
--- a/src/nmn-wifi-handler.c
+++ b/src/nmn-wifi-handler.c
@@ -176,26 +176,11 @@ wifi_toggled (NmnNMData *nm_data,
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);
- }
- }
+ if (active)
+ nmn_device_handler_add_items (handler);
+ else
+ nmn_device_handler_remove_items (handler);
}
static GObject*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]