/pidgin/main: e15d91a77cb3: Request API: PURPLE_REQUEST_WAIT wit...

Tomasz Wasilczyk twasilczyk at pidgin.im
Wed Sep 18 12:24:38 EDT 2013


Changeset: e15d91a77cb3e0803ebc6dcf08a2de296119db61
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-09-18 18:24 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/e15d91a77cb3

Description:

Request API: PURPLE_REQUEST_WAIT with progress bar

diffstat:

 finch/gntrequest.c          |    1 +
 libpurple/protocols/gg/gg.c |    2 +-
 libpurple/request.c         |   44 ++++++++++-
 libpurple/request.h         |   64 ++++++++++++----
 pidgin/gtkrequest.c         |  170 ++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 253 insertions(+), 28 deletions(-)

diffs (truncated from 432 to 300 lines):

diff --git a/finch/gntrequest.c b/finch/gntrequest.c
--- a/finch/gntrequest.c
+++ b/finch/gntrequest.c
@@ -815,6 +815,7 @@ static PurpleRequestUiOps uiops =
 	finch_request_choice,
 	finch_request_action,
 	NULL,
+	NULL,
 	finch_request_fields,
 	finch_request_file,
 	finch_request_folder,
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -954,7 +954,7 @@ static gssize
 ggp_get_max_message_size(PurpleConversation *conv)
 {
 	/* TODO: it may depend on protocol version or other factors */
-	return 1232;
+	return 1200; /* no more than 1232 */
 }
 
 static PurplePluginProtocolInfo prpl_info =
diff --git a/libpurple/request.c b/libpurple/request.c
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -2058,13 +2058,12 @@ purple_request_action_varg(void *handle,
 
 void *
 purple_request_wait(void *handle, const char *title, const char *primary,
-	const char *secondary, GCallback cancel_cb,
-	PurpleRequestCommonParameters *cpar, void *user_data)
+	const char *secondary, gboolean with_progress,
+	PurpleRequestCancelCb cancel_cb, PurpleRequestCommonParameters *cpar,
+	void *user_data)
 {
 	PurpleRequestUiOps *ops;
 
-	if (title == NULL)
-		title = _("Please wait");
 	if (primary == NULL)
 		primary = _("Please wait...");
 
@@ -2080,7 +2079,7 @@ purple_request_wait(void *handle, const 
 		info->type      = PURPLE_REQUEST_WAIT;
 		info->handle    = handle;
 		info->ui_handle = ops->request_wait(title, primary, secondary,
-			cancel_cb, cpar, user_data);
+			with_progress, cancel_cb, cpar, user_data);
 
 		handles = g_list_append(handles, info);
 
@@ -2099,6 +2098,41 @@ purple_request_wait(void *handle, const 
 		cancel_cb ? 1 : 0, _("Cancel"), cancel_cb);
 }
 
+void
+purple_request_wait_pulse(void *ui_handle)
+{
+	PurpleRequestUiOps *ops;
+
+	ops = purple_request_get_ui_ops();
+
+	if (ops == NULL || ops->request_wait_update == NULL)
+		return;
+
+	ops->request_wait_update(ui_handle, TRUE, 0.0);
+}
+
+void
+purple_request_wait_progress(void *ui_handle, gfloat fraction)
+{
+	PurpleRequestUiOps *ops;
+
+	ops = purple_request_get_ui_ops();
+
+	if (ops == NULL || ops->request_wait_update == NULL)
+		return;
+
+	if (fraction < 0.0 || fraction > 1.0) {
+		purple_debug_warning("request", "Fraction parameter out of "
+			"range: %f", fraction);
+		if (fraction < 0.0)
+			fraction = 0.0;
+		else /* if (fraction > 1.0) */
+			fraction = 1.0;
+	}
+
+	ops->request_wait_update(ui_handle, FALSE, fraction);
+}
+
 static void
 purple_request_fields_strip_html(PurpleRequestFields *fields)
 {
diff --git a/libpurple/request.h b/libpurple/request.h
--- a/libpurple/request.h
+++ b/libpurple/request.h
@@ -105,6 +105,8 @@ typedef enum
 	PURPLE_REQUEST_ICON_ERROR
 } PurpleRequestIconType;
 
+typedef void (*PurpleRequestCancelCb)(gpointer);
+
 /**
  * Request UI operations.
  */
@@ -135,9 +137,17 @@ typedef struct
 
 	/** @see purple_request_wait(). */
 	void *(*request_wait)(const char *title, const char *primary,
-		const char *secondary, GCallback cancel_cb,
+		const char *secondary, gboolean with_progress,
+		PurpleRequestCancelCb cancel_cb,
 		PurpleRequestCommonParameters *cpar, void *user_data);
 
+	/**
+	 * @see purple_request_wait_pulse().
+	 * @see purple_request_wait_progress().
+	 */
+	void (*request_wait_update)(void *ui_handle, gboolean pulse,
+		gfloat fraction);
+
 	/** @see purple_request_fields(). */
 	void *(*request_fields)(const char *title, const char *primary,
 		const char *secondary, PurpleRequestFields *fields,
@@ -1758,26 +1768,48 @@ purple_request_action_varg(void *handle,
 /**
  * Displays a "please wait" dialog.
  *
- * @param handle      The plugin or connection handle.  For some things this
- *                    is <em>extremely</em> important.  See the comments on
- *                    purple_request_input().
- * @param title       The title of the message, or @c NULL if it should have
- *                    default title.
- * @param primary     The main point of the message, or @c NULL if you're
- *                    feeling enigmatic.
- * @param secondary   Secondary information, or @c NULL if there is none.
- * @param cancel_cb   The callback for the @c Cancel button, which may be
- *                    @c NULL.
- * @param cpar        The #PurpleRequestCommonParameters object, which gets
- *                    unref'ed after this call.
- * @param user_data   The data to pass to the callback.
+ * @param handle        The plugin or connection handle.  For some things this
+ *                      is <em>extremely</em> important.  See the comments on
+ *                      purple_request_input().
+ * @param title         The title of the message, or @c NULL if it should have
+ *                      default title.
+ * @param primary       The main point of the message, or @c NULL if you're
+ *                      feeling enigmatic.
+ * @param secondary     Secondary information, or @c NULL if there is none.
+ * @param with_progress @c TRUE, if we want to display progress bar, @c FALSE
+ *                      otherwise
+ * @param cancel_cb     The callback for the @c Cancel button, which may be
+ *                      @c NULL.
+ * @param cpar          The #PurpleRequestCommonParameters object, which gets
+ *                      unref'ed after this call.
+ * @param user_data     The data to pass to the callback.
  *
  * @return A UI-specific handle.
  */
 void *
 purple_request_wait(void *handle, const char *title, const char *primary,
-	const char *secondary, GCallback cancel_cb,
-	PurpleRequestCommonParameters *cpar, void *user_data);
+	const char *secondary, gboolean with_progress,
+	PurpleRequestCancelCb cancel_cb, PurpleRequestCommonParameters *cpar,
+	void *user_data);
+
+/**
+ * Notifies the "please wait" dialog that some progress has been made, but you
+ * don't know how much.
+ *
+ * @param ui_handle The request UI handle.
+ */
+void
+purple_request_wait_pulse(void *ui_handle);
+
+/**
+ * Notifies the "please wait" dialog about progress has been made.
+ *
+ * @param ui_handle The request UI handle.
+ * @param fraction  The part of task that is done (between 0.0 and 1.0,
+ *                  inclusive).
+ */
+void
+purple_request_wait_progress(void *ui_handle, gfloat fraction);
 
 /**
  * Displays groups of fields for the user to fill in.
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -66,6 +66,11 @@ typedef struct
 	{
 		struct
 		{
+			GtkProgressBar *progress_bar;
+		} wait;
+
+		struct
+		{
 			GtkWidget *entry;
 
 			gboolean multiline;
@@ -376,7 +381,8 @@ pidgin_request_escape(PurpleRequestCommo
 }
 
 static GtkWidget *
-pidgin_request_dialog_icon(PurpleRequestCommonParameters *cpar)
+pidgin_request_dialog_icon(PurpleRequestType dialog_type,
+	PurpleRequestCommonParameters *cpar)
 {
 	GtkWidget *img = NULL;
 	PurpleRequestIconType icon_type;
@@ -427,6 +433,8 @@ pidgin_request_dialog_icon(PurpleRequest
 	switch (icon_type)
 	{
 		case PURPLE_REQUEST_ICON_DEFAULT:
+			icon_stock = NULL;
+			break;
 		case PURPLE_REQUEST_ICON_REQUEST:
 			icon_stock = PIDGIN_STOCK_DIALOG_QUESTION;
 			break;
@@ -444,6 +452,23 @@ pidgin_request_dialog_icon(PurpleRequest
 		/* intentionally no default value */
 	}
 
+	if (icon_stock == NULL) {
+		switch (dialog_type) {
+			case PURPLE_REQUEST_INPUT:
+			case PURPLE_REQUEST_CHOICE:
+			case PURPLE_REQUEST_ACTION:
+			case PURPLE_REQUEST_FIELDS:
+			case PURPLE_REQUEST_FILE:
+			case PURPLE_REQUEST_FOLDER:
+				icon_stock = PIDGIN_STOCK_DIALOG_QUESTION;
+				break;
+			case PURPLE_REQUEST_WAIT:
+				icon_stock = PIDGIN_STOCK_DIALOG_INFO;
+				break;
+			/* intentionally no default value */
+		}
+	}
+
 	img = gtk_image_new_from_stock(icon_stock,
 		gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
 
@@ -544,7 +569,7 @@ pidgin_request_input(const char *title, 
 	                  hbox);
 
 	/* Dialog icon. */
-	img = pidgin_request_dialog_icon(cpar);
+	img = pidgin_request_dialog_icon(PURPLE_REQUEST_INPUT, cpar);
 	gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
 	gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
 
@@ -704,7 +729,7 @@ pidgin_request_choice(const char *title,
 	                  hbox);
 
 	/* Dialog icon. */
-	img = pidgin_request_dialog_icon(cpar);
+	img = pidgin_request_dialog_icon(PURPLE_REQUEST_CHOICE, cpar);
 	gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
 	gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
 
@@ -826,7 +851,7 @@ pidgin_request_action(const char *title,
 	gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
 	                  hbox);
 
-	img = pidgin_request_dialog_icon(cpar);
+	img = pidgin_request_dialog_icon(PURPLE_REQUEST_ACTION, cpar);
 	gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
 	gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
 
@@ -882,6 +907,138 @@ pidgin_request_action(const char *title,
 }
 
 static void
+wait_cancel_cb(GtkWidget *button, PidginRequestData *data)
+{
+	generic_response_start(data);
+
+	if (data->cbs[0] != NULL)
+		((PurpleRequestCancelCb)data->cbs[0])(data->user_data);
+
+	purple_request_close(PURPLE_REQUEST_FIELDS, data);
+}
+
+static void *
+pidgin_request_wait(const char *title, const char *primary,
+	const char *secondary, gboolean with_progress,
+	PurpleRequestCancelCb cancel_cb, PurpleRequestCommonParameters *cpar,
+	void *user_data)
+{
+	PidginRequestData *data;
+	GtkWidget *dialog;
+	GtkWidget *hbox, *vbox, *img, *label, *button;
+	gchar *primary_esc, *secondary_esc, *label_text;
+
+	data            = g_new0(PidginRequestData, 1);



More information about the Commits mailing list