[network-manager-applet] gsm: auto-unlock only when user wants it to happen



commit 29d2d075ddcdb813dc4b7746ac65135987fecee6
Author: Dan Williams <dcbw redhat com>
Date:   Fri Oct 14 12:28:08 2011 -0500

    gsm: auto-unlock only when user wants it to happen
    
    Provide a checkbox so the user can decide whether or not to
    automatically unlock the modem.  Some people don't want to.

 src/applet-device-gsm.c |   46 +++++++++++++++++++++++++++++++++++++++++++---
 src/applet-dialogs.c    |   25 ++++++++++++++++++++++++-
 src/applet-dialogs.h    |    5 ++++-
 src/gsm-unlock.ui       |   46 +++++++++++++++++++++++++++++++++-------------
 4 files changed, 104 insertions(+), 18 deletions(-)
---
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index e492cdb..e411aee 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -814,6 +814,39 @@ set_pin_in_keyring (const char *devid,
 }
 
 static void
+delete_pin_cb (GnomeKeyringResult result, gpointer user_data)
+{
+	/* nothing to do */
+}
+
+static void
+delete_pins_find_cb (GnomeKeyringResult result, GList *list, gpointer user_data)
+{
+	GList *iter;
+
+	if (result == GNOME_KEYRING_RESULT_OK) {
+		for (iter = list; iter; iter = g_list_next (iter)) {
+			GnomeKeyringFound *found = iter->data;
+
+			gnome_keyring_item_delete (found->keyring, found->item_id, delete_pin_cb, NULL, NULL);
+		}
+	}
+}
+
+static void
+delete_pins_in_keyring (const char *devid)
+{
+	gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+	                           delete_pins_find_cb,
+	                           NULL,
+	                           NULL,
+	                           "devid",
+	                           GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+	                           devid,
+	                           NULL);
+}
+
+static void
 unlock_dialog_destroy (GsmDeviceInfo *info)
 {
 	applet_mobile_pin_dialog_destroy (info->dialog);
@@ -828,8 +861,11 @@ unlock_pin_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
 	const char *dbus_error, *msg = NULL, *code1;
 
 	if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) {
-		code1 = applet_mobile_pin_dialog_get_entry1 (info->dialog);
-		set_pin_in_keyring (info->devid, info->simid, code1);
+		if (applet_mobile_pin_dialog_get_auto_unlock (info->dialog)) {
+			code1 = applet_mobile_pin_dialog_get_entry1 (info->dialog);
+			set_pin_in_keyring (info->devid, info->simid, code1);
+		} else
+			delete_pins_in_keyring (info->devid);
 		unlock_dialog_destroy (info);
 		return;
 	}
@@ -984,7 +1020,11 @@ unlock_dialog_new (NMDevice *device, GsmDeviceInfo *info)
 	}
 
 	/* Construct and run the dialog */
-	info->dialog = applet_mobile_pin_dialog_new (title, header, desc, show_pass_label);
+	info->dialog = applet_mobile_pin_dialog_new (title,
+	                                             header,
+	                                             desc,
+	                                             show_pass_label,
+	                                             (unlock_code == UNLOCK_CODE_PIN) ? TRUE : FALSE);
 	g_free (desc);
 	g_return_if_fail (info->dialog != NULL);
 
diff --git a/src/applet-dialogs.c b/src/applet-dialogs.c
index 48639da..ba085e5 100644
--- a/src/applet-dialogs.c
+++ b/src/applet-dialogs.c
@@ -1124,7 +1124,8 @@ GtkWidget *
 applet_mobile_pin_dialog_new (const char *title,
                               const char *header,
                               const char *desc,
-                              const char *show_password_label)
+                              const char *show_password_label,
+                              gboolean show_auto_unlock_checkbox)
 {
 	char *str;
 	GtkWidget *dialog;
@@ -1173,6 +1174,10 @@ applet_mobile_pin_dialog_new (const char *title,
 
 	g_signal_connect (dialog, "delete-event", G_CALLBACK (mpd_cancel_dialog), NULL);
 
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "save_checkbutton"));
+	if (show_auto_unlock_checkbox)
+		g_object_set_data (G_OBJECT (widget), "active", GUINT_TO_POINTER (TRUE));
+
 	mpd_entry_changed (NULL, dialog);
 
 	return dialog;
@@ -1209,6 +1214,10 @@ applet_mobile_pin_dialog_present (GtkWidget *dialog, gboolean now)
 		gtk_widget_hide (widget);
 	}
 
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "save_checkbutton"));
+	if (!g_object_get_data (G_OBJECT (widget), "active"))
+		gtk_widget_hide (widget);
+
 	/* Need to resize the dialog after hiding widgets */
 	gtk_window_resize (GTK_WINDOW (dialog), 400, 100);
 
@@ -1363,6 +1372,20 @@ applet_mobile_pin_dialog_get_entry3 (GtkWidget *dialog)
 	return mpd_get_entry (dialog, "code3_entry");
 }
 
+gboolean
+applet_mobile_pin_dialog_get_auto_unlock (GtkWidget *dialog)
+{
+	GtkBuilder *builder;
+	GtkWidget *widget;
+
+	g_return_val_if_fail (dialog != NULL, FALSE);
+	builder = g_object_get_data (G_OBJECT (dialog), "builder");
+	g_return_val_if_fail (builder != NULL, FALSE);
+
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "save_checkbutton"));
+	return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+}
+
 void
 applet_mobile_pin_dialog_start_spinner (GtkWidget *dialog, const char *text)
 {
diff --git a/src/applet-dialogs.h b/src/applet-dialogs.h
index c3dbcca..f01d6a8 100644
--- a/src/applet-dialogs.h
+++ b/src/applet-dialogs.h
@@ -41,7 +41,8 @@ GtkWidget *applet_mobile_password_dialog_new (NMConnection *connection,
 GtkWidget *applet_mobile_pin_dialog_new (const char *title,
                                          const char *header,
                                          const char *desc,
-                                         const char *show_password_label);
+                                         const char *show_password_label,
+                                         gboolean show_auto_unlock_checkbox);
 
 void applet_mobile_pin_dialog_present (GtkWidget *dialog, gboolean now);
 
@@ -67,6 +68,8 @@ const char *applet_mobile_pin_dialog_get_entry3 (GtkWidget *dialog);
 
 void applet_mobile_pin_dialog_match_23 (GtkWidget *dialog, gboolean match);
 
+gboolean applet_mobile_pin_dialog_get_auto_unlock (GtkWidget *dialog);
+
 void applet_mobile_pin_dialog_start_spinner (GtkWidget *dialog, const char *text);
 void applet_mobile_pin_dialog_stop_spinner (GtkWidget *dialog, const char *text);
 
diff --git a/src/gsm-unlock.ui b/src/gsm-unlock.ui
index 22ece11..34333a1 100644
--- a/src/gsm-unlock.ui
+++ b/src/gsm-unlock.ui
@@ -76,7 +76,7 @@
                     <child>
                       <object class="GtkTable" id="table14">
                         <property name="visible">True</property>
-                        <property name="n_rows">5</property>
+                        <property name="n_rows">6</property>
                         <property name="n_columns">2</property>
                         <property name="column_spacing">6</property>
                         <property name="row_spacing">6</property>
@@ -153,6 +153,32 @@
                           </packing>
                         </child>
                         <child>
+                          <object class="GtkCheckButton" id="show_password_checkbutton">
+                            <property name="label">Show it</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_action_appearance">False</property>
+                            <property name="xalign">0</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">3</property>
+                            <property name="bottom_attach">4</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
                           <object class="GtkHBox" id="progress_hbox">
                             <property name="visible">True</property>
                             <property name="spacing">6</property>
@@ -184,16 +210,16 @@
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="right_attach">2</property>
-                            <property name="top_attach">4</property>
-                            <property name="bottom_attach">5</property>
+                            <property name="top_attach">5</property>
+                            <property name="bottom_attach">6</property>
                             <property name="x_options">GTK_FILL</property>
                             <property name="y_options">GTK_FILL</property>
                             <property name="y_padding">6</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkCheckButton" id="show_password_checkbutton">
-                            <property name="label" translatable="no">Show it</property>
+                          <object class="GtkCheckButton" id="save_checkbutton">
+                            <property name="label" translatable="yes">Automatically unlock this device</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
@@ -202,16 +228,10 @@
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="right_attach">2</property>
-                            <property name="top_attach">3</property>
-                            <property name="bottom_attach">4</property>
+                            <property name="top_attach">4</property>
+                            <property name="bottom_attach">5</property>
                           </packing>
                         </child>
-                        <child>
-                          <placeholder/>
-                        </child>
-                        <child>
-                          <placeholder/>
-                        </child>
                       </object>
                     </child>
                   </object>



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