[network-manager-netbook] Add a new signal "delete" to list items to differentiate between deletion and



commit d9743bbc1b00c6dcc5b3ad3d4acd0c52804e191e
Author: Tambet Ingo <tambet gmail com>
Date:   Tue May 26 15:07:09 2009 +0300

    Add a new signal "delete" to list items to differentiate between deletion and
    removing from UI.
---
 src/nmn-item.c           |   28 ++++++++++++++++++++++++++--
 src/nmn-item.h           |    5 ++++-
 src/nmn-network-item.c   |   14 +++++++++++---
 src/nmn-networks.c       |   10 ----------
 src/nmn-serial-handler.c |    4 +++-
 src/nmn-serial-item.c    |    2 +-
 src/nmn-wifi-handler.c   |    2 +-
 src/nmn-wifi-item.c      |   42 +-----------------------------------------
 8 files changed, 47 insertions(+), 60 deletions(-)

diff --git a/src/nmn-item.c b/src/nmn-item.c
index 9a69697..52306fe 100644
--- a/src/nmn-item.c
+++ b/src/nmn-item.c
@@ -9,6 +9,7 @@ enum {
     CONNECT_REQUESTED,
     DISCONNECT_REQUESTED,
     REMOVE_REQUESTED,
+    DELETE,
     LAST_SIGNAL
 };
 
@@ -98,6 +99,14 @@ nmn_item_set_status (NmnItem *item,
     }
 }
 
+NmnItemStatus
+nmn_item_get_status (NmnItem *item)
+{
+    g_return_val_if_fail (NMN_IS_ITEM (item), NMN_ITEM_STATUS_DISCONNECTED);
+
+    return NMN_ITEM_GET_PRIVATE (item)->status;
+}
+
 void
 nmn_item_set_icon (NmnItem *item,
                    const char *icon_name)
@@ -130,8 +139,14 @@ nmn_item_set_security (NmnItem *item,
                         security_string ? security_string : "");
 }
 
+static void
+nmn_item_delete (NmnItem *self)
+{
+    g_signal_emit (self, signals[DELETE], 0);
+}
+
 void
-nmn_item_set_remove_visible (NmnItem *item,
+nmn_item_set_delete_visible (NmnItem *item,
                              gboolean visible)
 {
     NmnItemPrivate *priv = NMN_ITEM_GET_PRIVATE (item);
@@ -145,7 +160,7 @@ nmn_item_set_remove_visible (NmnItem *item,
 
         gtk_box_pack_end (GTK_BOX (item), priv->remove, FALSE, FALSE, 0);
         g_signal_connect_swapped (priv->remove, "clicked",
-                                  G_CALLBACK (nmn_item_remove_request),
+                                  G_CALLBACK (nmn_item_delete),
                                   item);
     } else if (!visible && priv->remove) {
         gtk_container_remove (GTK_CONTAINER (item), priv->remove);
@@ -294,4 +309,13 @@ nmn_item_class_init (NmnItemClass *class)
          NULL, NULL,
          g_cclosure_marshal_VOID__VOID,
          G_TYPE_NONE, 0);
+
+    signals[DELETE] = g_signal_new 
+        ("delete",
+         G_OBJECT_CLASS_TYPE (class),
+         G_SIGNAL_RUN_LAST,
+         G_STRUCT_OFFSET (NmnItemClass, delete),
+         NULL, NULL,
+         g_cclosure_marshal_VOID__VOID,
+         G_TYPE_NONE, 0);
 }
diff --git a/src/nmn-item.h b/src/nmn-item.h
index 16954eb..f8bde34 100644
--- a/src/nmn-item.h
+++ b/src/nmn-item.h
@@ -27,6 +27,7 @@ typedef struct {
     void (*connect_requested) (NmnItem *self);
     void (*disconnect_requested) (NmnItem *self);
     void (*remove_requested) (NmnItem *self);
+    void (*delete) (NmnItem *self);
 } NmnItemClass;
 
 typedef enum {
@@ -48,13 +49,15 @@ void       nmn_item_set_status_visible (NmnItem *item,
 void       nmn_item_set_status (NmnItem *item,
                                 NmnItemStatus status);
 
+NmnItemStatus nmn_item_get_status (NmnItem *item);
+
 void       nmn_item_set_icon (NmnItem *item,
                               const char *icon_name);
 
 void       nmn_item_set_security (NmnItem *item,
                                   const char *security_string);
 
-void       nmn_item_set_remove_visible (NmnItem *item,
+void       nmn_item_set_delete_visible (NmnItem *item,
                                         gboolean visible);
 
 void       nmn_item_connect_request (NmnItem *self);
diff --git a/src/nmn-network-item.c b/src/nmn-network-item.c
index 4779fab..3377de2 100644
--- a/src/nmn-network-item.c
+++ b/src/nmn-network-item.c
@@ -31,6 +31,7 @@ typedef struct {
     NMActiveConnection *ac;
 
     gulong connection_updated_id;
+    gulong connection_removed_id;
     gulong secrets_requested_id;
     gulong ac_state_changed_id;
 
@@ -138,6 +139,12 @@ updated (NMExportedConnection *connection,
 }
 
 static void
+removed (NMExportedConnection *connection, gpointer user_data)
+{
+    nmn_item_remove_request (NMN_ITEM (user_data));
+}
+
+static void
 connection_secrets_requested_cb (NMExportedConnection *connection,
                                  const char *setting_name,
                                  const char **hints,
@@ -238,6 +245,7 @@ nmn_network_item_set_connection (NmnNetworkItem *self,
 
     if (priv->connection) {
         g_signal_handler_disconnect (priv->connection, priv->connection_updated_id);
+        g_signal_handler_disconnect (priv->connection, priv->connection_removed_id);
 
         if (priv->secrets_requested_id)
             g_signal_handler_disconnect (priv->connection, priv->secrets_requested_id);
@@ -248,6 +256,7 @@ nmn_network_item_set_connection (NmnNetworkItem *self,
     if (connection) {
         priv->connection = g_object_ref (connection);
         priv->connection_updated_id = g_signal_connect (connection, "updated", G_CALLBACK (updated), self);
+        priv->connection_removed_id = g_signal_connect (connection, "removed", G_CALLBACK (removed), self);
 
         if (NMA_IS_GCONF_CONNECTION (connection))
             priv->secrets_requested_id = g_signal_connect (connection, "new-secrets-requested",
@@ -263,7 +272,7 @@ nmn_network_item_set_connection (NmnNetworkItem *self,
 }
 
 static void
-remove_requested (NmnItem *item)
+item_delete (NmnItem *item)
 {
     NMExportedConnection *exported = nmn_network_item_get_connection (NMN_NETWORK_ITEM (item));
 
@@ -275,8 +284,6 @@ remove_requested (NmnItem *item)
 static void
 nmn_network_item_init (NmnNetworkItem *item)
 {
-    /* Connect the signal here to be sure we're the first one called */
-    g_signal_connect (item, "remove-requested", G_CALLBACK (remove_requested), NULL);
 }
 
 static GObject*
@@ -397,6 +404,7 @@ nmn_network_item_class_init (NmnNetworkItemClass *class)
 
     item_class->connect = connect;
     item_class->disconnect = disconnect;
+    item_class->delete = item_delete;
 
     /* properties */
     g_object_class_install_property
diff --git a/src/nmn-networks.c b/src/nmn-networks.c
index 1ecdc93..85d37e1 100644
--- a/src/nmn-networks.c
+++ b/src/nmn-networks.c
@@ -129,15 +129,6 @@ item_remove_requested (NmnItem *item,
     remove_connections (NMN_NETWORKS (user_data), item, NULL, NULL);
 }
 
-#if 0
-static void
-connection_removed (NMExportedConnection *connection,
-                    gpointer user_data)
-{
-    remove_connections (NMN_NETWORKS (user_data), NULL, connection, NULL);
-}
-#endif
-
 static void
 item_added (NmnDeviceHandler *handler,
             NmnItem *item,
@@ -153,7 +144,6 @@ item_added (NmnDeviceHandler *handler,
     g_signal_connect (item, "remove-requested", G_CALLBACK (item_remove_requested), self);
 
     find_ac_for_item (self, NMN_NETWORK_ITEM (item));
-    //g_signal_connect (exported, "removed", G_CALLBACK (connection_removed), self);
 }
 
 static void
diff --git a/src/nmn-serial-handler.c b/src/nmn-serial-handler.c
index 59202d8..5783e53 100644
--- a/src/nmn-serial-handler.c
+++ b/src/nmn-serial-handler.c
@@ -67,7 +67,9 @@ modems_toggled (NmnNMData *nm_data,
         for (iter = list; iter; iter = iter->next) {
             NmnItem *item = NMN_ITEM (iter->data);
 
-            nmn_item_disconnect_request (item);
+            if (nmn_item_get_status (item) != NMN_ITEM_STATUS_DISCONNECTED)
+                nmn_item_disconnect_request (item);
+
             nmn_item_remove_request (item);
         }
     }
diff --git a/src/nmn-serial-item.c b/src/nmn-serial-item.c
index 680b0b7..cf5d1ab 100644
--- a/src/nmn-serial-item.c
+++ b/src/nmn-serial-item.c
@@ -55,7 +55,7 @@ nmn_serial_item_new (NmnNMData *nm_data,
 static void
 nmn_serial_item_init (NmnSerialItem *item)
 {
-    nmn_item_set_remove_visible (NMN_ITEM (item), TRUE);
+    nmn_item_set_delete_visible (NMN_ITEM (item), TRUE);
 }
 
 static GObject*
diff --git a/src/nmn-wifi-handler.c b/src/nmn-wifi-handler.c
index 2c7a5b9..dadae80 100644
--- a/src/nmn-wifi-handler.c
+++ b/src/nmn-wifi-handler.c
@@ -133,7 +133,7 @@ connection_added (NmnDeviceHandler *handler,
     if (ap) {
         item = nmn_wifi_item_new (nmn_device_handler_get_nm_data (handler), device, ap);
         g_object_set (item, NMN_NETWORK_ITEM_CONNECTION, exported, NULL);
-        nmn_item_set_remove_visible (NMN_ITEM (item), TRUE);
+        nmn_item_set_delete_visible (NMN_ITEM (item), TRUE);
         nmn_device_handler_add_item (handler, NMN_ITEM (item));
     }
 }
diff --git a/src/nmn-wifi-item.c b/src/nmn-wifi-item.c
index 027295e..0a90a22 100644
--- a/src/nmn-wifi-item.c
+++ b/src/nmn-wifi-item.c
@@ -112,45 +112,6 @@ updated (NMAccessPoint *ap,
     update_item (NMN_WIFI_ITEM (user_data));
 }
 
-GtkWidget *
-nmn_wifi_item_create_for_connection (NmnNMData *nm_data,
-                                     NMDeviceWifi *device,
-                                     NMExportedConnection *exported)
-{
-    NMConnection *wrapped;
-    NMSettingConnection *s_con;
-    const char *connection_type;
-    const GPtrArray *aps;
-    GtkWidget *item;
-    int i;
-
-    g_return_val_if_fail (NMN_IS_NM_DATA (nm_data), NULL);
-    g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
-    g_return_val_if_fail (NM_IS_EXPORTED_CONNECTION (exported), NULL);
-
-    wrapped = nm_exported_connection_get_connection (exported);
-    s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (wrapped, NM_TYPE_SETTING_CONNECTION));
-    connection_type = nm_setting_connection_get_connection_type (s_con);
-
-    if (!connection_type && strcmp (connection_type, NM_SETTING_WIRELESS_SETTING_NAME))
-        /* Not a wifi connection */
-        return NULL;
-
-    item = NULL;
-    aps = nm_device_wifi_get_access_points (device);
-    for (i = 0; !item && aps && i < aps->len; i++) {
-        NMAccessPoint *ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
-
-        if (utils_connection_valid_for_device (wrapped, NM_DEVICE (device), ap)) {
-            item = nmn_wifi_item_new (nm_data, device, ap);
-            g_object_set (item, NMN_NETWORK_ITEM_CONNECTION, exported, NULL);
-            nmn_item_set_remove_visible (NMN_ITEM (item), TRUE);
-        }
-    }
-
-    return item;
-}
-
 void
 nmn_wifi_item_set_ap (NmnWifiItem *self,
                       NMAccessPoint *ap)
@@ -169,10 +130,9 @@ nmn_wifi_item_set_ap (NmnWifiItem *self,
     if (ap) {
         priv->ap = g_object_ref (ap);
         priv->notify_id = g_signal_connect (ap, "notify", G_CALLBACK (updated), self);
+        update_item (self);
     } else
         priv->ap = NULL;
-
-    update_item (self);
 }
 
 NMAccessPoint *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]