[network-manager-netbook] Keep the "add new Mobile connection" page up to date with PIN requests



commit 5975f786c164382e61fab132322e8587a7822fcd
Author: Tambet Ingo <tambet gmail com>
Date:   Wed Mar 3 11:28:55 2010 -0400

    Keep the "add new Mobile connection" page up to date with PIN requests
    
    Don't allow addition of new connections if the modem is locked.

 src/nmn-applet.c         |    3 ++
 src/nmn-list.c           |    1 -
 src/nmn-new-connection.c |   60 ++++++++++++++++++++++++++++++++++++---------
 src/nmn-new-connection.h |    1 +
 4 files changed, 52 insertions(+), 13 deletions(-)
---
diff --git a/src/nmn-applet.c b/src/nmn-applet.c
index 999de58..644538d 100644
--- a/src/nmn-applet.c
+++ b/src/nmn-applet.c
@@ -365,6 +365,9 @@ static void
 add_new_connection_show (GtkButton *button,
                          gpointer user_data)
 {
+    NmnAppletPrivate *priv = GET_PRIVATE (user_data);
+
+    nmn_new_connection_update (NMN_NEW_CONNECTION (priv->new_dialog));
     gtk_notebook_set_current_page (GTK_NOTEBOOK (user_data), PAGE_ADD_CONNECTION);
 }
 
diff --git a/src/nmn-list.c b/src/nmn-list.c
index 8340c33..b188ec7 100644
--- a/src/nmn-list.c
+++ b/src/nmn-list.c
@@ -273,7 +273,6 @@ model_row_inserted (GtkTreeModel *model,
     index = gtk_tree_path_get_indices (path)[0];
 
     gtk_tree_model_get (model, iter, NM_LIST_MODEL_COL_ITEM, &item, -1);
-    g_debug ("Inserted row, has item %p (%s)", item, G_OBJECT_TYPE_NAME (item));
 
     if (item && NM_IS_GSM_PIN_REQUEST_ITEM (item))
         renderer = (NmnItemRenderer *) nmn_gsm_pin_request_renderer_new ();
diff --git a/src/nmn-new-connection.c b/src/nmn-new-connection.c
index 95d75e5..a8350a2 100644
--- a/src/nmn-new-connection.c
+++ b/src/nmn-new-connection.c
@@ -35,6 +35,7 @@
 #include "nmn-new-connection.h"
 #include "nm-list-model.h"
 #include "nm-wifi-item.h"
+#include "nm-gsm-pin-request-item.h"
 #include "nm-gconf-settings.h"
 #include "nmn-list.h"
 #include "wireless-dialog.h"
@@ -243,27 +244,57 @@ mobile_have_device (NmnNewConnection *connection, NMMobileProviderType *type)
     return found;
 }
 
+static gboolean
+gsm_is_locked (NmnModel *nmn_model)
+{
+    GtkTreeModel *model = GTK_TREE_MODEL (nmn_model);
+    GtkTreeIter iter;
+    gboolean valid;
+    gboolean found = FALSE;
+
+    valid = gtk_tree_model_get_iter_first (model, &iter);
+    while (valid && !found) {
+        NMListItem *item = NULL;
+
+        gtk_tree_model_get (model, &iter, NM_LIST_MODEL_COL_ITEM, &item, -1);
+        if (item) {
+            if (NM_IS_GSM_PIN_REQUEST_ITEM (item))
+                found = TRUE;
+
+            g_object_unref (item);
+        }
+
+        valid = gtk_tree_model_iter_next (model, &iter);
+    }
+
+    return found;
+}
+
 static void
 mobile_status_update (NmnNewConnection *connection)
 {
     NmnNewConnectionPrivate *priv = GET_PRIVATE (connection);
     NMMobileProviderType type;
-    gboolean found;
+    gboolean active;
 
     if (!nmn_model_modems_get_active (priv->model)) {
-        found = FALSE;
+        active = FALSE;
         gtk_label_set_text (GTK_LABEL (priv->mobile_label), _("3G disabled"));
     } else {
-        found = mobile_have_device (connection, &type);
-
-        if (found)
-            gtk_label_set_text (GTK_LABEL (priv->mobile_label), _("Internal 3G modem and SIM card detected"));
-        else
+        active = mobile_have_device (connection, &type);
+
+        if (active) {
+            if (type == NM_MOBILE_ACCESS_METHOD_TYPE_GSM && gsm_is_locked (priv->model)) {
+                gtk_label_set_text (GTK_LABEL (priv->mobile_label), _("3G modem is locked"));
+                active = FALSE;
+            } else
+                gtk_label_set_text (GTK_LABEL (priv->mobile_label), _("Internal 3G modem and SIM card detected"));
+        } else
             gtk_label_set_text (GTK_LABEL (priv->mobile_label), _("No modems detected"));
     }
 
-    gtk_widget_set_sensitive (priv->mobile_list, found);
-    gtk_widget_set_sensitive (priv->mobile_save, found);
+    gtk_widget_set_sensitive (priv->mobile_list, active);
+    gtk_widget_set_sensitive (priv->mobile_save, active);
 }
 
 static gboolean
@@ -580,7 +611,6 @@ mobile_device_added (NMClient *client,
         NmnNewConnection *connection = NMN_NEW_CONNECTION (user_data);
 
         mobile_list_populate (connection);
-        mobile_status_update (connection);
     }
 }
 
@@ -590,15 +620,21 @@ mobile_page_init (NmnNewConnection *connection)
     NmnNewConnectionPrivate *priv = GET_PRIVATE (connection);
     NMClient *client = nmn_model_get_client (priv->model);
 
-    g_signal_connect (connection, "realize", G_CALLBACK (mobile_list_populate), NULL);
     g_signal_connect (client, "device-added", G_CALLBACK (mobile_device_added), connection);
     g_signal_connect_swapped (client, "device-removed", G_CALLBACK (mobile_status_update), connection);
     
     priv->mobile_toggled_id = g_signal_connect_swapped (priv->model, "modems-toggled",
                                                         G_CALLBACK (mobile_status_update),
                                                         connection);
+}
+
+void
+nmn_new_connection_update (NmnNewConnection *self)
+{
+    g_return_if_fail (NMN_IS_NEW_CONNECTION (self));
 
-    mobile_status_update (connection);
+    mobile_list_populate (self);
+    mobile_status_update (self);
 }
 
 static void
diff --git a/src/nmn-new-connection.h b/src/nmn-new-connection.h
index 476bbb8..0969f06 100644
--- a/src/nmn-new-connection.h
+++ b/src/nmn-new-connection.h
@@ -46,5 +46,6 @@ typedef struct {
 GType nmn_new_connection_get_type (void);
 
 GtkWidget *nmn_new_connection_create (NmnModel *model);
+void       nmn_new_connection_update (NmnNewConnection *self);
 
 #endif /* NMN_NEW_CONNECTION_H */



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