/pidgin/main: 4fe0e2422d82: Request API: extra actions for field...

Tomasz Wasilczyk twasilczyk at pidgin.im
Tue Sep 17 08:06:53 EDT 2013


Changeset: 4fe0e2422d8281a18686173b9050b000851ca617
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-09-17 14:06 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/4fe0e2422d82

Description:

Request API: extra actions for fields request

diffstat:

 libpurple/request.c |  46 ++++++++++++++++++++++++++++++++++++++++++++++
 libpurple/request.h |  26 ++++++++++++++++++++++++++
 pidgin/gtkrequest.c |  31 +++++++++++++++++++++++++++++++
 3 files changed, 103 insertions(+), 0 deletions(-)

diffs (173 lines):

diff --git a/libpurple/request.c b/libpurple/request.c
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -173,6 +173,8 @@ struct _PurpleRequestCommonParameters
 
 	PurpleRequestHelpCb help_cb;
 	gpointer help_data;
+
+	GSList *extra_actions;
 };
 
 PurpleRequestCommonParameters *
@@ -236,6 +238,7 @@ purple_request_cpar_unref(PurpleRequestC
 	if (--cpar->ref_count > 0)
 		return cpar;
 
+	purple_request_cpar_set_extra_actions(cpar, NULL);
 	g_free(cpar);
 	return NULL;
 }
@@ -378,6 +381,49 @@ purple_request_cpar_get_help_cb(PurpleRe
 	return cpar->help_cb;
 }
 
+void
+purple_request_cpar_set_extra_actions(PurpleRequestCommonParameters *cpar, ...)
+{
+	va_list args;
+	GSList *extra = NULL, *it;
+
+	it = cpar->extra_actions;
+	while (it != NULL) {
+		gchar *label = it->data;
+
+		g_free(label);
+		it = g_slist_next(it);
+		if (it == NULL)
+			break;
+		it = g_slist_next(it);
+	}
+
+	va_start(args, cpar);
+
+	while (TRUE) {
+		const gchar *label;
+		PurpleRequestFieldsCb cb;
+
+		label = va_arg(args, const gchar*);
+		if (label == NULL)
+			break;
+		cb = va_arg(args, PurpleRequestFieldsCb);
+
+		extra = g_slist_append(extra, g_strdup(label));
+		extra = g_slist_append(extra, cb);
+	}
+
+	va_end(args);
+
+	cpar->extra_actions = extra;
+}
+
+GSList *
+purple_request_cpar_get_extra_actions(PurpleRequestCommonParameters *cpar)
+{
+	return cpar->extra_actions;
+}
+
 PurpleRequestFields *
 purple_request_fields_new(void)
 {
diff --git a/libpurple/request.h b/libpurple/request.h
--- a/libpurple/request.h
+++ b/libpurple/request.h
@@ -382,11 +382,37 @@ purple_request_cpar_set_help_cb(PurpleRe
  * @param cpar      The parameters set (may be @c NULL).
  * @param user_data The pointer to the variable, where user data (to be passed
  *                  to callback function) should be stored.
+ *
+ * @return The callback.
  */
 PurpleRequestHelpCb
 purple_request_cpar_get_help_cb(PurpleRequestCommonParameters *cpar,
 	gpointer *user_data);
 
+/**
+ * Sets extra actions for the PurpleRequestFields dialog.
+ *
+ * @param cpar The parameters set.
+ * @param ...  A list of actions. These are pairs of arguments. The first of
+ *             each pair is the <tt>char *</tt> label that appears on the
+ *             button. It should have an underscore before the letter you want
+ *             to use as the accelerator key for the button. The second of each
+ *             pair is the #PurpleRequestFieldsCb function to use when the
+ *             button is clicked. Should be terminated with the NULL label.
+ */
+void
+purple_request_cpar_set_extra_actions(PurpleRequestCommonParameters *cpar, ...);
+
+/**
+ * Gets extra actions for the PurpleRequestFields dialog.
+ *
+ * @param cpar The parameters set (may be @c NULL).
+ *
+ * @return A list of actions (pairs of arguments, as in setter).
+ */
+GSList *
+purple_request_cpar_get_extra_actions(PurpleRequestCommonParameters *cpar);
+
 /*@}*/
 
 /**************************************************************************/
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -296,6 +296,21 @@ multifield_cancel_cb(GtkWidget *button, 
 	purple_request_close(PURPLE_REQUEST_FIELDS, data);
 }
 
+static void
+multifield_extra_cb(GtkWidget *button, PidginRequestData *data)
+{
+	PurpleRequestFieldsCb cb;
+
+	generic_response_start(data);
+
+	cb = g_object_get_data(G_OBJECT(button), "extra-cb");
+
+	if (cb != NULL)
+		cb(data->user_data, data->u.multifield.fields);
+
+	purple_request_close(PURPLE_REQUEST_FIELDS, data);
+}
+
 static gboolean
 destroy_multifield_cb(GtkWidget *dialog, GdkEvent *event,
 					  PidginRequestData *data)
@@ -1401,6 +1416,8 @@ pidgin_request_fields(const char *title,
 	char *primary_esc, *secondary_esc;
 	int total_fields = 0;
 	const gboolean compact = purple_request_cpar_is_compact(cpar);
+	GSList *extra_actions, *it;
+	size_t extra_actions_count, i;
 
 	data            = g_new0(PidginRequestData, 1);
 	data->type      = PURPLE_REQUEST_FIELDS;
@@ -1409,6 +1426,9 @@ pidgin_request_fields(const char *title,
 
 	purple_request_fields_set_ui_data(fields, data);
 
+	extra_actions = purple_request_cpar_get_extra_actions(cpar);
+	extra_actions_count = g_slist_length(extra_actions) / 2;
+
 	data->cb_count = 2;
 	data->cbs = g_new0(GCallback, 2);
 
@@ -1438,6 +1458,17 @@ pidgin_request_fields(const char *title,
 
 	pidgin_request_add_help(GTK_DIALOG(win), cpar);
 
+	it = extra_actions;
+	for (i = 0; i < extra_actions_count; i++, it = it->next->next) {
+		const gchar *label = it->data;
+		PurpleRequestFieldsCb *cb = it->next->data;
+
+		button = pidgin_dialog_add_button(GTK_DIALOG(win),
+			text_to_stock(label), G_CALLBACK(multifield_extra_cb),
+			data);
+		g_object_set_data(G_OBJECT(button), "extra-cb", cb);
+	}
+
 	/* Cancel button */
 	button = pidgin_dialog_add_button(GTK_DIALOG(win), text_to_stock(cancel_text), G_CALLBACK(multifield_cancel_cb), data);
 	gtk_widget_set_can_default(button, TRUE);



More information about the Commits mailing list