/cpw/tomkiewicz/masterpassword: 1d9ea89d4934: Group and string s...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sat May 11 10:26:47 EDT 2013


Changeset: 1d9ea89d4934fe13d0ba5a49b6715d57605c2e5d
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-05-11 16:26 +0200
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/1d9ea89d4934

Description:

Group and string support for keyring settings

diffstat:

 libpurple/plugins/keyrings/internalkeyring.c |  11 +++++-
 pidgin/gtkprefs.c                            |  48 +++++++++++++++++++++++----
 pidgin/gtkutils.c                            |  14 ++++---
 3 files changed, 59 insertions(+), 14 deletions(-)

diffs (142 lines):

diff --git a/libpurple/plugins/keyrings/internalkeyring.c b/libpurple/plugins/keyrings/internalkeyring.c
--- a/libpurple/plugins/keyrings/internalkeyring.c
+++ b/libpurple/plugins/keyrings/internalkeyring.c
@@ -195,7 +195,16 @@ internal_keyring_read_settings(void)
 	field = purple_request_field_bool_new("encrypt", "Use encryption", FALSE);
 	purple_request_field_group_add_field(group, field);
 
-	/* TODO: master password setting */
+	group = purple_request_field_group_new("Master password");
+	purple_request_fields_add_group(fields, group);
+
+	field = purple_request_field_string_new("passphrase1", "New passphrase:", "", FALSE);
+	purple_request_field_string_set_masked(field, TRUE);
+	purple_request_field_group_add_field(group, field);
+
+	field = purple_request_field_string_new("passphrase2", "Re-enter passphrase:", "", FALSE);
+	purple_request_field_string_set_masked(field, TRUE);
+	purple_request_field_group_add_field(group, field);
 
 	return fields;
 }
diff --git a/pidgin/gtkprefs.c b/pidgin/gtkprefs.c
--- a/pidgin/gtkprefs.c
+++ b/pidgin/gtkprefs.c
@@ -2655,8 +2655,20 @@ keyring_page_settings_toggled(GtkToggleB
 		gtk_toggle_button_get_active(togglebutton));
 }
 
+static void
+keyring_page_settings_string_changed(GtkWidget *widget, gpointer _unused)
+{
+	PurpleRequestField *setting;
+
+	gtk_widget_set_sensitive(keyring_apply, TRUE);
+
+	setting = g_object_get_data(G_OBJECT(widget), "setting");
+	purple_request_field_string_set_value(setting,
+		gtk_entry_get_text(GTK_ENTRY(widget)));
+}
+
 static GtkWidget *
-keyring_page_add_settings_field(PurpleRequestField *setting)
+keyring_page_add_settings_field(GtkBox *vbox, PurpleRequestField *setting)
 {
 	GtkWidget *widget, *hbox;
 	PurpleRequestFieldType field_type;
@@ -2672,15 +2684,23 @@ keyring_page_add_settings_field(PurpleRe
 			purple_request_field_bool_get_default_value(setting));
 		g_signal_connect(G_OBJECT(widget), "toggled",
 			G_CALLBACK(keyring_page_settings_toggled), NULL);
+	} else if (field_type == PURPLE_REQUEST_FIELD_STRING) {
+		widget = gtk_entry_new();
+		gtk_entry_set_text(GTK_ENTRY(widget),
+			purple_request_field_string_get_default_value(setting));
+		if (purple_request_field_string_is_masked(setting))
+			gtk_entry_set_visibility(GTK_ENTRY(widget), FALSE);
+		g_signal_connect(G_OBJECT(widget), "changed",
+			G_CALLBACK(keyring_page_settings_string_changed), NULL);
 	} else {
 		purple_debug_error("gtkprefs", "Unsupported field type\n");
 		return NULL;
 	}
 
 	g_object_set_data(G_OBJECT(widget), "setting", setting);
-	hbox = pidgin_add_widget_to_vbox(keyring_vbox, label, NULL, widget,
+	hbox = pidgin_add_widget_to_vbox(vbox, label, NULL, widget,
 		FALSE, NULL);
-	return ((void*)hbox == (void*)keyring_vbox) ? widget : hbox;
+	return ((void*)hbox == (void*)vbox) ? widget : hbox;
 }
 
 /* XXX: it could be available for all plugins, not keyrings only */
@@ -2694,13 +2714,26 @@ keyring_page_add_settings(PurpleRequestF
 	groups = purple_request_fields_get_groups(settings);
 	for (it = g_list_first(groups); it != NULL; it = g_list_next(it)) {
 		GList *it2, *fields;
-
-		fields = purple_request_field_group_get_fields(it->data);
+		GtkBox *vbox;
+		PurpleRequestFieldGroup *group;
+		const gchar *group_title;
+
+		group = it->data;
+		group_title = purple_request_field_group_get_title(group);
+		if (group_title) {
+			vbox = GTK_BOX(pidgin_make_frame(
+				GTK_WIDGET(keyring_vbox), group_title));
+			added_fields = g_list_prepend(added_fields,
+				g_object_get_data(G_OBJECT(vbox), "main-vbox"));
+		} else
+			vbox = keyring_vbox;
+
+		fields = purple_request_field_group_get_fields(group);
 		for (it2 = g_list_first(fields); it2 != NULL;
 			it2 = g_list_next(it2)) {
-			GtkWidget *added = keyring_page_add_settings_field(
+			GtkWidget *added = keyring_page_add_settings_field(vbox,
 				it2->data);
-			if (added == NULL)
+			if (added == NULL || vbox != keyring_vbox)
 				continue;
 			added_fields = g_list_prepend(added_fields, added);
 		}
@@ -2793,6 +2826,7 @@ keyring_page_pref_changed(GtkComboBox *c
 		gtk_container_remove(
 			GTK_CONTAINER(gtk_widget_get_parent(widget)), widget);
 	}
+	gtk_widget_show_all(keyring_page_instance);
 	g_list_free(keyring_settings_fields);
 	keyring_settings_fields = NULL;
 	if (keyring_settings)
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -483,7 +483,7 @@ GtkWidget *pidgin_new_item_from_stock(Gt
 GtkWidget *
 pidgin_make_frame(GtkWidget *parent, const char *title)
 {
-	GtkWidget *vbox, *label, *hbox;
+	GtkWidget *vbox, *vbox2, *label, *hbox;
 	char *labeltitle;
 
 	vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
@@ -509,11 +509,13 @@ pidgin_make_frame(GtkWidget *parent, con
 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
 	gtk_widget_show(label);
 
-	vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
-	gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
-	gtk_widget_show(vbox);
-
-	return vbox;
+	vbox2 = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
+	gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 0);
+	gtk_widget_show(vbox2);
+
+	g_object_set_data(G_OBJECT(vbox2), "main-vbox", vbox);
+
+	return vbox2;
 }
 
 static gpointer



More information about the Commits mailing list