network-manager-applet r773 - in trunk: . src



Author: dcbw
Date: Tue Jul  1 20:51:58 2008
New Revision: 773
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=773&view=rev

Log:
2008-07-01  Dan Williams <dcbw redhat com>

	* src/applet.c
	  src/applet.h
		- (applet_settings_new_secrets_requested_cb): pass hints to device
			subclass

	* src/applet-device-wifi.c
	  src/applet-device-wired.c
		- (wireless_get_secrets, wired_get_secrets): update for 'hints' argument

	* src/applet-device-gsm.c
		- (gsm_get_secrets): use hints to determine which secret (PIN, PUK, or
			PPP password) NM is requesting
		- (ask_for_password): ask for PPP password when required
		- (ask_for_pin_puk): handle PUK too
		- (get_gsm_secrets_cb): handle all of PIN, PUK, and PPP password

	* src/applet-device-cdma.c
		- (cdma_get_secrets, ask_for_password, get_cdma_secrets_cb): handle PPP
			passwords



Modified:
   trunk/ChangeLog
   trunk/src/applet-device-cdma.c
   trunk/src/applet-device-gsm.c
   trunk/src/applet-device-wifi.c
   trunk/src/applet-device-wired.c
   trunk/src/applet.c
   trunk/src/applet.h

Modified: trunk/src/applet-device-cdma.c
==============================================================================
--- trunk/src/applet-device-cdma.c	(original)
+++ trunk/src/applet-device-cdma.c	Tue Jul  1 20:51:58 2008
@@ -315,6 +315,174 @@
 	return pixbuf;
 }
 
+typedef struct {
+	DBusGMethodInvocation *context;
+	NMApplet *applet;
+	NMConnection *connection;
+	GtkWidget *ok_button;
+	GtkEntry *secret_entry;
+	char *secret_name;
+} NMCdmaInfo;
+
+static void
+get_cdma_secrets_cb (GtkDialog *dialog,
+                     gint response,
+                     gpointer user_data)
+{
+	NMCdmaInfo *info = (NMCdmaInfo *) user_data;
+	NMAGConfConnection *gconf_connection;
+	NMSettingCdma *setting;
+	GHashTable *settings_hash;
+	GHashTable *secrets;
+	GError *err = NULL;
+
+	if (response != GTK_RESPONSE_OK) {
+		g_set_error (&err, NM_SETTINGS_ERROR, 1,
+		             "%s.%d (%s): canceled",
+		             __FILE__, __LINE__, __func__);
+		goto done;
+	}
+
+	setting = NM_SETTING_CDMA (nm_connection_get_setting (info->connection, NM_TYPE_SETTING_CDMA));
+
+	if (!strcmp (info->secret_name, NM_SETTING_CDMA_PASSWORD)) {
+		g_free (setting->password);
+		setting->password = g_strdup (gtk_entry_get_text (info->secret_entry));
+	}
+
+	secrets = nm_setting_to_hash (NM_SETTING (setting));
+	if (!secrets) {
+		g_set_error (&err, NM_SETTINGS_ERROR, 1,
+				   "%s.%d (%s): failed to hash setting '%s'.",
+				   __FILE__, __LINE__, __func__, NM_SETTING (setting)->name);
+		goto done;
+	}
+
+	/* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
+	 * will contain all the individual settings hashes.
+	 */
+	settings_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+								    g_free, (GDestroyNotify) g_hash_table_destroy);
+
+	g_hash_table_insert (settings_hash, g_strdup (NM_SETTING (setting)->name), secrets);
+	dbus_g_method_return (info->context, settings_hash);
+	g_hash_table_destroy (settings_hash);
+
+	/* Save the connection back to GConf _after_ hashing it, because
+	 * saving to GConf might trigger the GConf change notifiers, resulting
+	 * in the connection being read back in from GConf which clears secrets.
+	 */
+	gconf_connection = nma_gconf_settings_get_by_connection (info->applet->gconf_settings, info->connection);
+	if (gconf_connection)
+		nma_gconf_connection_save (gconf_connection);
+
+ done:
+	if (err) {
+		g_warning (err->message);
+		dbus_g_method_return_error (info->context, err);
+		g_error_free (err);
+	}
+
+	gtk_widget_hide (GTK_WIDGET (dialog));
+	gtk_widget_destroy (GTK_WIDGET (dialog));
+
+	nm_connection_clear_secrets (info->connection);
+	g_object_unref (info->connection);
+	g_free (info->secret_name);
+	g_free (info);
+}
+
+
+static void
+ask_for_password (NMDevice *device,
+                  NMConnection *connection,
+                  DBusGMethodInvocation *context,
+                  NMApplet *applet)
+{
+	GtkDialog *dialog;
+	GtkWidget *w;
+	GtkBox *box;
+	char *dev_str;
+	NMCdmaInfo *info;
+
+	info = g_new (NMCdmaInfo, 1);
+	info->context = context;
+	info->applet = applet;
+	info->connection = g_object_ref (connection);
+	info->secret_name = g_strdup (NM_SETTING_CDMA_PASSWORD);
+
+	dialog = GTK_DIALOG (gtk_dialog_new ());
+	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+	gtk_window_set_title (GTK_WINDOW (dialog), _("CDMA Network Password"));
+
+	w = gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
+	w = gtk_dialog_add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK);
+	info->ok_button = w;
+	gtk_window_set_default (GTK_WINDOW (dialog), info->ok_button);
+
+	w = gtk_label_new (_("A password is required to connect to the CDMA network."));
+	gtk_box_pack_start_defaults (GTK_BOX (dialog->vbox), w);
+
+	dev_str = g_strdup_printf ("<b>%s</b>", utils_get_device_description (device));
+	w = gtk_label_new (NULL);
+	gtk_label_set_markup (GTK_LABEL (w), dev_str);
+	g_free (dev_str);
+	gtk_box_pack_start_defaults (GTK_BOX (dialog->vbox), w);
+
+	w = gtk_alignment_new (0.5, 0.5, 0, 1.0);
+	gtk_box_pack_start_defaults (GTK_BOX (dialog->vbox), w);
+
+	box = GTK_BOX (gtk_hbox_new (FALSE, 6));
+	gtk_container_set_border_width (GTK_CONTAINER (box), 6);
+	gtk_container_add (GTK_CONTAINER (w), GTK_WIDGET (box));
+
+	gtk_box_pack_start (box, gtk_label_new (_("Password:")), FALSE, FALSE, 0);
+
+	w = gtk_entry_new ();
+	info->secret_entry = GTK_ENTRY (w);
+	gtk_entry_set_activates_default (GTK_ENTRY (w), TRUE);
+	gtk_box_pack_start (box, w, FALSE, FALSE, 0);
+
+	gtk_widget_show_all (dialog->vbox);
+
+	g_signal_connect (dialog, "response",
+				   G_CALLBACK (get_cdma_secrets_cb),
+				   info);
+
+	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
+	gtk_widget_realize (GTK_WIDGET (dialog));
+	gtk_window_present (GTK_WINDOW (dialog));
+}
+
+static gboolean
+cdma_get_secrets (NMDevice *device,
+                 NMConnection *connection,
+                 const char *specific_object,
+                 const char *setting_name,
+                 const char **hints,
+                 DBusGMethodInvocation *context,
+                 NMApplet *applet,
+                 GError **error)
+{
+	if (!hints || !g_strv_length ((char **) hints)) {
+		g_set_error (error, NM_SETTINGS_ERROR, 1,
+		             "%s.%d (%s): missing secrets hints.",
+		             __FILE__, __LINE__, __func__);
+		return FALSE;
+	}
+
+	if (!strcmp (hints[0], NM_SETTING_CDMA_PASSWORD))
+		ask_for_password (device, connection, context, applet);
+	else {
+		g_set_error (error, NM_SETTINGS_ERROR, 1,
+		             "%s.%d (%s): unknown secrets hint '%s'.",
+		             __FILE__, __LINE__, __func__, hints[0]);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
 NMADeviceClass *
 applet_device_cdma_get_class (NMApplet *applet)
 {
@@ -328,6 +496,7 @@
 	dclass->add_menu_item = cdma_add_menu_item;
 	dclass->device_state_changed = cdma_device_state_changed;
 	dclass->get_icon = cdma_get_icon;
+	dclass->get_secrets = cdma_get_secrets;
 
 	return dclass;
 }

Modified: trunk/src/applet-device-gsm.c
==============================================================================
--- trunk/src/applet-device-gsm.c	(original)
+++ trunk/src/applet-device-gsm.c	Tue Jul  1 20:51:58 2008
@@ -321,7 +321,8 @@
 	NMApplet *applet;
 	NMConnection *connection;
 	GtkWidget *ok_button;
-	GtkEntry *pin_entry;
+	GtkEntry *secret_entry;
+	char *secret_name;
 } NMGsmInfo;
 
 static void
@@ -332,7 +333,7 @@
 	int i;
 	gboolean valid = FALSE;
 
-	s = gtk_entry_get_text (info->pin_entry);
+	s = gtk_entry_get_text (GTK_ENTRY (editable));
 	if (s && strlen (s) == 4) {
 		valid = TRUE;
 		for (i = 0; i < 4; i++) {
@@ -366,8 +367,17 @@
 	}
 
 	setting = NM_SETTING_GSM (nm_connection_get_setting (info->connection, NM_TYPE_SETTING_GSM));
-	g_free (setting->pin);
-	setting->pin = g_strdup (gtk_entry_get_text (info->pin_entry));
+
+	if (!strcmp (info->secret_name, NM_SETTING_GSM_PIN)) {
+		g_free (setting->pin);
+		setting->pin = g_strdup (gtk_entry_get_text (info->secret_entry));
+	} else if (!strcmp (info->secret_name, NM_SETTING_GSM_PUK)) {
+		g_free (setting->puk);
+		setting->puk = g_strdup (gtk_entry_get_text (info->secret_entry));
+	} else if (!strcmp (info->secret_name, NM_SETTING_GSM_PASSWORD)) {
+		g_free (setting->password);
+		setting->password = g_strdup (gtk_entry_get_text (info->secret_entry));
+	}
 
 	secrets = nm_setting_to_hash (NM_SETTING (setting));
 	if (!secrets) {
@@ -407,17 +417,16 @@
 
 	nm_connection_clear_secrets (info->connection);
 	g_object_unref (info->connection);
+	g_free (info->secret_name);
 	g_free (info);
 }
 
-static gboolean
-gsm_get_secrets (NMDevice *device,
-			  NMConnection *connection,
-			  const char *specific_object,
-			  const char *setting_name,
-			  DBusGMethodInvocation *context,
-			  NMApplet *applet,
-			  GError **error)
+static void
+ask_for_pin_puk (NMDevice *device,
+                 NMConnection *connection,
+                 const char *secret_name,
+                 DBusGMethodInvocation *context,
+                 NMApplet *applet)
 {
 	GtkDialog *dialog;
 	GtkWidget *w;
@@ -429,17 +438,27 @@
 	info->context = context;
 	info->applet = applet;
 	info->connection = g_object_ref (connection);
+	info->secret_name = g_strdup (secret_name);
 
 	dialog = GTK_DIALOG (gtk_dialog_new ());
-	gtk_window_set_title (GTK_WINDOW (dialog), _("PIN code"));
 	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
 
+	if (!strcmp (secret_name, NM_SETTING_GSM_PIN))
+		gtk_window_set_title (GTK_WINDOW (dialog), _("PIN code required"));
+	else if (!strcmp (secret_name, NM_SETTING_GSM_PUK))
+		gtk_window_set_title (GTK_WINDOW (dialog), _("PUK code required"));
+	else
+		g_assert_not_reached ();
+
 	w = gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
 	w = gtk_dialog_add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK);
 	info->ok_button = w;
 	gtk_window_set_default (GTK_WINDOW (dialog), info->ok_button);
 
-	w = gtk_label_new ("PIN code is needed for device");
+	if (!strcmp (secret_name, NM_SETTING_GSM_PIN))
+		w = gtk_label_new (_("PIN code is needed for the GSM device"));
+	else if (!strcmp (secret_name, NM_SETTING_GSM_PUK))
+		w = gtk_label_new (_("PUK code is needed for the GSM device"));
 	gtk_box_pack_start_defaults (GTK_BOX (dialog->vbox), w);
 
 	dev_str = g_strdup_printf ("<b>%s</b>", utils_get_device_description (device));
@@ -458,10 +477,10 @@
 	gtk_box_pack_start (box, gtk_label_new ("PIN:"), FALSE, FALSE, 0);
 
 	w = gtk_entry_new ();
-	info->pin_entry = GTK_ENTRY (w);
-	gtk_entry_set_max_length (info->pin_entry, 4);
-	gtk_entry_set_width_chars (info->pin_entry, 4);
-	gtk_entry_set_activates_default (info->pin_entry, TRUE);
+	info->secret_entry = GTK_ENTRY (w);
+	gtk_entry_set_max_length (GTK_ENTRY (w), 4);
+	gtk_entry_set_width_chars (GTK_ENTRY (w), 4);
+	gtk_entry_set_activates_default (GTK_ENTRY (w), TRUE);
 	gtk_box_pack_start (box, w, FALSE, FALSE, 0);
 	g_signal_connect (w, "changed", G_CALLBACK (pin_entry_changed), info);
 	pin_entry_changed (GTK_EDITABLE (w), info);
@@ -475,6 +494,97 @@
 	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
 	gtk_widget_realize (GTK_WIDGET (dialog));
 	gtk_window_present (GTK_WINDOW (dialog));
+}
+
+static void
+ask_for_password (NMDevice *device,
+                  NMConnection *connection,
+                  DBusGMethodInvocation *context,
+                  NMApplet *applet)
+{
+	GtkDialog *dialog;
+	GtkWidget *w;
+	GtkBox *box;
+	char *dev_str;
+	NMGsmInfo *info;
+
+	info = g_new (NMGsmInfo, 1);
+	info->context = context;
+	info->applet = applet;
+	info->connection = g_object_ref (connection);
+	info->secret_name = g_strdup (NM_SETTING_GSM_PASSWORD);
+
+	dialog = GTK_DIALOG (gtk_dialog_new ());
+	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+	gtk_window_set_title (GTK_WINDOW (dialog), _("GSM Network Password"));
+
+	w = gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
+	w = gtk_dialog_add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK);
+	info->ok_button = w;
+	gtk_window_set_default (GTK_WINDOW (dialog), info->ok_button);
+
+	w = gtk_label_new (_("A password is required to connect to the GSM network."));
+	gtk_box_pack_start_defaults (GTK_BOX (dialog->vbox), w);
+
+	dev_str = g_strdup_printf ("<b>%s</b>", utils_get_device_description (device));
+	w = gtk_label_new (NULL);
+	gtk_label_set_markup (GTK_LABEL (w), dev_str);
+	g_free (dev_str);
+	gtk_box_pack_start_defaults (GTK_BOX (dialog->vbox), w);
+
+	w = gtk_alignment_new (0.5, 0.5, 0, 1.0);
+	gtk_box_pack_start_defaults (GTK_BOX (dialog->vbox), w);
+
+	box = GTK_BOX (gtk_hbox_new (FALSE, 6));
+	gtk_container_set_border_width (GTK_CONTAINER (box), 6);
+	gtk_container_add (GTK_CONTAINER (w), GTK_WIDGET (box));
+
+	gtk_box_pack_start (box, gtk_label_new (_("Password:")), FALSE, FALSE, 0);
+
+	w = gtk_entry_new ();
+	info->secret_entry = GTK_ENTRY (w);
+	gtk_entry_set_activates_default (GTK_ENTRY (w), TRUE);
+	gtk_box_pack_start (box, w, FALSE, FALSE, 0);
+
+	gtk_widget_show_all (dialog->vbox);
+
+	g_signal_connect (dialog, "response",
+				   G_CALLBACK (get_gsm_secrets_cb),
+				   info);
+
+	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
+	gtk_widget_realize (GTK_WIDGET (dialog));
+	gtk_window_present (GTK_WINDOW (dialog));
+}
+
+static gboolean
+gsm_get_secrets (NMDevice *device,
+                 NMConnection *connection,
+                 const char *specific_object,
+                 const char *setting_name,
+                 const char **hints,
+                 DBusGMethodInvocation *context,
+                 NMApplet *applet,
+                 GError **error)
+{
+	if (!hints || !g_strv_length ((char **) hints)) {
+		g_set_error (error, NM_SETTINGS_ERROR, 1,
+		             "%s.%d (%s): missing secrets hints.",
+		             __FILE__, __LINE__, __func__);
+		return FALSE;
+	}
+
+	if (   !strcmp (hints[0], NM_SETTING_GSM_PIN)
+	    || !strcmp (hints[0], NM_SETTING_GSM_PUK))
+		ask_for_pin_puk (device, connection, hints[0], context, applet);
+	else if (!strcmp (hints[0], NM_SETTING_GSM_PASSWORD))
+		ask_for_password (device, connection, context, applet);
+	else {
+		g_set_error (error, NM_SETTINGS_ERROR, 1,
+		             "%s.%d (%s): unknown secrets hint '%s'.",
+		             __FILE__, __LINE__, __func__, hints[0]);
+		return FALSE;
+	}
 
 	return TRUE;
 }

Modified: trunk/src/applet-device-wifi.c
==============================================================================
--- trunk/src/applet-device-wifi.c	(original)
+++ trunk/src/applet-device-wifi.c	Tue Jul  1 20:51:58 2008
@@ -1546,6 +1546,7 @@
                       NMConnection *connection,
                       const char *specific_object,
                       const char *setting_name,
+                      const char **hints,
                       DBusGMethodInvocation *context,
                       NMApplet *applet,
                       GError **error)

Modified: trunk/src/applet-device-wired.c
==============================================================================
--- trunk/src/applet-device-wired.c	(original)
+++ trunk/src/applet-device-wired.c	Tue Jul  1 20:51:58 2008
@@ -625,6 +625,7 @@
 				   NMConnection *connection,
 				   const char *specific_object,
 				   const char *setting_name,
+				   const char **hints,
 				   DBusGMethodInvocation *context,
 				   NMApplet *applet,
 				   GError **error)

Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c	(original)
+++ trunk/src/applet.c	Tue Jul  1 20:51:58 2008
@@ -1879,7 +1879,7 @@
 
 	/* Let the device class handle secrets */
 	if (!dclass->get_secrets (device, connection, specific_object, setting_name,
-	                          context, applet, &error))
+	                          hints, context, applet, &error))
 		goto error;
 
 	return;

Modified: trunk/src/applet.h
==============================================================================
--- trunk/src/applet.h	(original)
+++ trunk/src/applet.h	Tue Jul  1 20:51:58 2008
@@ -153,6 +153,7 @@
 	                               NMConnection *connection,
 	                               const char *specific_object,
 	                               const char *setting_name,
+	                               const char **hints,
 	                               DBusGMethodInvocation *context,
 	                               NMApplet *applet,
 	                               GError **error);



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