diff finch/gntrequest.c @ 16310:8c89913276b3

Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 22 Apr 2007 23:55:24 +0000
parents 0f0832c13fcb
children 08db93bbd798
line wrap: on
line diff
--- a/finch/gntrequest.c	Sun Apr 22 18:20:05 2007 +0000
+++ b/finch/gntrequest.c	Sun Apr 22 23:55:24 2007 +0000
@@ -139,6 +139,11 @@
 finch_close_request(PurpleRequestType type, gpointer ui_handle)
 {
 	GntWidget *widget = GNT_WIDGET(ui_handle);
+	if (type == PURPLE_REQUEST_FIELDS) {
+		PurpleRequestFields *fields = g_object_get_data(G_OBJECT(widget), "fields");
+		purple_request_fields_destroy(fields);
+	}
+
 	while (widget->parent)
 		widget = widget->parent;
 	gnt_widget_destroy(widget);
@@ -243,7 +248,7 @@
 	gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata");
 	GList *list;
 
-	/* Update the data of the fields. GtkPurple does this differently. Instead of
+	/* Update the data of the fields. Pidgin does this differently. Instead of
 	 * updating the fields at the end like here, it updates the appropriate field
 	 * instantly whenever a change is made. That allows it to make sure the
 	 * 'required' fields are entered before the user can hit OK. It's not the case
@@ -532,6 +537,8 @@
 	gnt_box_add_widget(GNT_BOX(window), box);
 
 	gnt_widget_show(window);
+
+	g_object_set_data(G_OBJECT(window), "fields", allfields);
 	
 	return window;
 }
@@ -620,3 +627,54 @@
 {
 }
 
+void finch_request_save_in_prefs(gpointer null, PurpleRequestFields *allfields)
+{
+	GList *list;
+	for (list = purple_request_fields_get_groups(allfields); list; list = list->next) {
+		PurpleRequestFieldGroup *group = list->data;
+		GList *fields = purple_request_field_group_get_fields(group);
+		
+		for (; fields ; fields = fields->next) {
+			PurpleRequestField *field = fields->data;
+			PurpleRequestFieldType type = purple_request_field_get_type(field);
+			PurplePrefType pt;
+			gpointer val = NULL;
+			const char *id = purple_request_field_get_id(field);
+
+			switch (type) {
+				case PURPLE_REQUEST_FIELD_LIST:
+					val = purple_request_field_list_get_selected(field)->data;
+					break;
+				case PURPLE_REQUEST_FIELD_BOOLEAN:
+					val = GINT_TO_POINTER(purple_request_field_bool_get_value(field));
+					break;
+				case PURPLE_REQUEST_FIELD_INTEGER:
+					val = GINT_TO_POINTER(purple_request_field_int_get_value(field));
+					break;
+				case PURPLE_REQUEST_FIELD_STRING:
+					val = (gpointer)purple_request_field_string_get_value(field);
+					break;
+				default:
+					break;
+			}
+
+			pt = purple_prefs_get_type(id);
+			switch (pt) {
+				case PURPLE_PREF_INT:
+					if (type == PURPLE_REQUEST_FIELD_LIST) /* Lists always return string */
+						sscanf(val, "%ld", (long int *)&val);
+					purple_prefs_set_int(id, GPOINTER_TO_INT(val));
+					break;
+				case PURPLE_PREF_BOOLEAN:
+					purple_prefs_set_bool(id, GPOINTER_TO_INT(val));
+					break;
+				case PURPLE_PREF_STRING:
+					purple_prefs_set_string(id, val);
+					break;
+				default:
+					break;
+			}
+		}
+	}
+}
+