Merged soc.2013.gobjectification branch soc.2013.gobjectification.plugins

Tue, 17 Sep 2013 22:22:40 +0530

author
Ankit Vani <a@nevitus.org>
date
Tue, 17 Sep 2013 22:22:40 +0530
branch
soc.2013.gobjectification.plugins
changeset 36761
a84a6709c72a
parent 36760
88a9488af4e8 (current diff)
parent 34948
e31ee6f00ff8 (diff)
child 36762
e83ad7c340e7

Merged soc.2013.gobjectification branch

libpurple/protocols/gg/gg.c file | annotate | diff | comparison | revisions
libpurple/request.h file | annotate | diff | comparison | revisions
pidgin/gtkrequest.c file | annotate | diff | comparison | revisions
--- a/finch/gntrequest.c	Tue Sep 17 22:18:39 2013 +0530
+++ b/finch/gntrequest.c	Tue Sep 17 22:22:40 2013 +0530
@@ -814,10 +814,11 @@
 	finch_request_input,
 	finch_request_choice,
 	finch_request_action,
+	NULL,
 	finch_request_fields,
 	finch_request_file,
+	finch_request_folder,
 	finch_close_request,
-	finch_request_folder,
 	NULL,
 	NULL,
 	NULL,
--- a/libpurple/protocols/gg/gg.c	Tue Sep 17 22:18:39 2013 +0530
+++ b/libpurple/protocols/gg/gg.c	Tue Sep 17 22:22:40 2013 +0530
@@ -418,6 +418,9 @@
 			info->session->check, info->session->state);
 
 	switch (info->session->state) {
+		case GG_STATE_ERROR:
+			purple_debug_info("gg", "GG_STATE_ERROR\n");
+			break;
 		case GG_STATE_RESOLVING:
 			purple_debug_info("gg", "GG_STATE_RESOLVING\n");
 			break;
@@ -554,6 +557,11 @@
 						_("Error connecting to master "
 						"server"));
 					break;
+				case GG_FAILURE_INTERNAL:
+					purple_connection_error(gc,
+						PURPLE_CONNECTION_ERROR_OTHER_ERROR,
+						_("Internal error"));
+					break;
 				default:
 					purple_connection_error(gc,
 						PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
--- a/libpurple/protocols/gg/tcpsocket.c	Tue Sep 17 22:18:39 2013 +0530
+++ b/libpurple/protocols/gg/tcpsocket.c	Tue Sep 17 22:22:40 2013 +0530
@@ -20,13 +20,15 @@
 	if (!gg_socket_manager_connected(ps, priv_gg, fd)) {
 		purple_debug_error("gg", "socket not handled");
 		purple_socket_destroy(ps);
-		return;
 	}
 
 	if (info->inpa > 0)
 		purple_input_remove(info->inpa);
-	info->inpa = purple_input_add(fd, ggp_tcpsocket_inputcond_gg_to_purple(
-		info->session->check), ggp_async_login_handler, gc);
+	if (info->session->fd < 0)
+		return;
+	info->inpa = purple_input_add(info->session->fd,
+		ggp_tcpsocket_inputcond_gg_to_purple(info->session->check),
+		ggp_async_login_handler, gc);
 }
 
 static void*
--- a/libpurple/request.c	Tue Sep 17 22:18:39 2013 +0530
+++ b/libpurple/request.c	Tue Sep 17 22:22:40 2013 +0530
@@ -173,6 +173,8 @@
 
 	PurpleRequestHelpCb help_cb;
 	gpointer help_data;
+
+	GSList *extra_actions;
 };
 
 PurpleRequestCommonParameters *
@@ -236,6 +238,7 @@
 	if (--cpar->ref_count > 0)
 		return cpar;
 
+	purple_request_cpar_set_extra_actions(cpar, NULL);
 	g_free(cpar);
 	return NULL;
 }
@@ -289,7 +292,7 @@
 purple_request_cpar_get_icon(PurpleRequestCommonParameters *cpar)
 {
 	if (cpar == NULL)
-		return PURPLE_REQUEST_ICON_REQUEST;
+		return PURPLE_REQUEST_ICON_DEFAULT;
 
 	return cpar->icon_type;
 }
@@ -378,6 +381,49 @@
 	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)
 {
@@ -2011,6 +2057,74 @@
 }
 
 void *
+purple_request_wait(void *handle, const char *title, const char *primary,
+	const char *secondary, GCallback cancel_cb,
+	PurpleRequestCommonParameters *cpar, void *user_data)
+{
+	PurpleRequestUiOps *ops;
+
+	if (title == NULL)
+		title = _("Please wait");
+	if (primary == NULL)
+		primary = _("Please wait...");
+
+	ops = purple_request_get_ui_ops();
+
+	if (ops != NULL && ops->request_wait != NULL) {
+		PurpleRequestInfo *info;
+		gchar **tmp;
+
+		tmp = purple_request_strip_html(cpar, &primary, &secondary);
+
+		info            = g_new0(PurpleRequestInfo, 1);
+		info->type      = PURPLE_REQUEST_WAIT;
+		info->handle    = handle;
+		info->ui_handle = ops->request_wait(title, primary, secondary,
+			cancel_cb, cpar, user_data);
+
+		handles = g_list_append(handles, info);
+
+		g_strfreev(tmp);
+		purple_request_cpar_unref(cpar);
+		return info->ui_handle;
+	}
+
+	if (cpar == NULL)
+		cpar = purple_request_cpar_new();
+	if (purple_request_cpar_get_icon(cpar) == PURPLE_REQUEST_ICON_DEFAULT)
+		purple_request_cpar_set_icon(cpar, PURPLE_REQUEST_ICON_WAIT);
+
+	return purple_request_action(handle, title, primary, secondary,
+		PURPLE_DEFAULT_ACTION_NONE, cpar, user_data,
+		cancel_cb ? 1 : 0, _("Cancel"), cancel_cb);
+}
+
+static void
+purple_request_fields_strip_html(PurpleRequestFields *fields)
+{
+	GList *itg;
+
+	for (itg = fields->groups; itg != NULL; itg = g_list_next(itg)) {
+		PurpleRequestFieldGroup *group = itg->data;
+		GList *itf;
+
+		for (itf = group->fields; itf != NULL; itf = g_list_next(itf)) {
+			PurpleRequestField *field = itf->data;
+			gchar *new_label;
+
+			new_label = purple_request_strip_html_custom(
+				field->label);
+			if (g_strcmp0(new_label, field->label) == 0) {
+				g_free(new_label);
+				continue;
+			}
+			g_free(field->label);
+			field->label = new_label;
+		}
+	}
+}
+
+void *
 purple_request_fields(void *handle, const char *title, const char *primary,
 	const char *secondary, PurpleRequestFields *fields, const char *ok_text,
 	GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
@@ -2031,6 +2145,12 @@
 
 	ops = purple_request_get_ui_ops();
 
+	if (purple_request_cpar_is_html(cpar) &&
+		!((ops->features & PURPLE_REQUEST_FEATURE_HTML)))
+	{
+		purple_request_fields_strip_html(fields);
+	}
+
 	if (ops != NULL && ops->request_fields != NULL) {
 		PurpleRequestInfo *info;
 		gchar **tmp;
--- a/libpurple/request.h	Tue Sep 17 22:18:39 2013 +0530
+++ b/libpurple/request.h	Tue Sep 17 22:22:40 2013 +0530
@@ -64,6 +64,7 @@
 	PURPLE_REQUEST_INPUT = 0,  /**< Text input request.        */
 	PURPLE_REQUEST_CHOICE,     /**< Multiple-choice request.   */
 	PURPLE_REQUEST_ACTION,     /**< Action request.            */
+	PURPLE_REQUEST_WAIT,       /**< Please wait dialog.        */
 	PURPLE_REQUEST_FIELDS,     /**< Multiple fields request.   */
 	PURPLE_REQUEST_FILE,       /**< File open or save request. */
 	PURPLE_REQUEST_FOLDER      /**< Folder selection request.  */
@@ -95,8 +96,10 @@
 
 typedef enum
 {
-	PURPLE_REQUEST_ICON_REQUEST = 0,
+	PURPLE_REQUEST_ICON_DEFAULT = 0,
+	PURPLE_REQUEST_ICON_REQUEST,
 	PURPLE_REQUEST_ICON_DIALOG,
+	PURPLE_REQUEST_ICON_WAIT,
 	PURPLE_REQUEST_ICON_INFO,
 	PURPLE_REQUEST_ICON_WARNING,
 	PURPLE_REQUEST_ICON_ERROR
@@ -130,6 +133,11 @@
 		PurpleRequestCommonParameters *cpar, void *user_data,
 		size_t action_count, va_list actions);
 
+	/** @see purple_request_wait(). */
+	void *(*request_wait)(const char *title, const char *primary,
+		const char *secondary, GCallback cancel_cb,
+		PurpleRequestCommonParameters *cpar, void *user_data);
+
 	/** @see purple_request_fields(). */
 	void *(*request_fields)(const char *title, const char *primary,
 		const char *secondary, PurpleRequestFields *fields,
@@ -142,13 +150,13 @@
 		gboolean savedialog, GCallback ok_cb, GCallback cancel_cb,
 		PurpleRequestCommonParameters *cpar, void *user_data);
 
-	void (*close_request)(PurpleRequestType type, void *ui_handle);
-
 	/** @see purple_request_folder(). */
 	void *(*request_folder)(const char *title, const char *dirname,
 		GCallback ok_cb, GCallback cancel_cb,
 		PurpleRequestCommonParameters *cpar, void *user_data);
 
+	void (*close_request)(PurpleRequestType type, void *ui_handle);
+
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);
 	void (*_purple_reserved3)(void);
@@ -374,11 +382,37 @@
  * @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);
+
 /*@}*/
 
 /**************************************************************************/
@@ -1722,6 +1756,30 @@
 	size_t action_count, va_list actions);
 
 /**
+ * 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.
+ *
+ * @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);
+
+/**
  * Displays groups of fields for the user to fill in.
  *
  * @param handle      The plugin or connection handle.  For some things this
--- a/pidgin/gtkrequest.c	Tue Sep 17 22:18:39 2013 +0530
+++ b/pidgin/gtkrequest.c	Tue Sep 17 22:22:40 2013 +0530
@@ -296,6 +296,21 @@
 	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)
@@ -410,11 +425,13 @@
 	icon_type = purple_request_cpar_get_icon(cpar);
 	switch (icon_type)
 	{
+		case PURPLE_REQUEST_ICON_DEFAULT:
 		case PURPLE_REQUEST_ICON_REQUEST:
 			icon_stock = PIDGIN_STOCK_DIALOG_QUESTION;
 			break;
 		case PURPLE_REQUEST_ICON_DIALOG:
 		case PURPLE_REQUEST_ICON_INFO:
+		case PURPLE_REQUEST_ICON_WAIT: /* TODO: we need another icon */
 			icon_stock = PIDGIN_STOCK_DIALOG_INFO;
 			break;
 		case PURPLE_REQUEST_ICON_WARNING:
@@ -1051,12 +1068,16 @@
 }
 
 static GtkWidget *
-create_bool_field(PurpleRequestField *field)
+create_bool_field(PurpleRequestField *field,
+	PurpleRequestCommonParameters *cpar)
 {
 	GtkWidget *widget;
+	gchar *label;
 
-	widget = gtk_check_button_new_with_label(
+	label = pidgin_request_escape(cpar,
 		purple_request_field_get_label(field));
+	widget = gtk_check_button_new_with_label(label);
+	g_free(label);
 
 	gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
 
@@ -1399,6 +1420,8 @@
 	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;
@@ -1407,6 +1430,9 @@
 
 	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);
 
@@ -1436,6 +1462,17 @@
 
 	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);
@@ -1597,7 +1634,7 @@
 				size_t col_offset = col_num * 2;
 				PurpleRequestFieldType type;
 				GtkWidget *widget = NULL;
-				const char *field_label;
+				gchar *field_label;
 
 				label = NULL;
 				field = fl->data;
@@ -1608,14 +1645,16 @@
 				}
 
 				type = purple_request_field_get_type(field);
-				field_label = purple_request_field_get_label(field);
+				field_label = pidgin_request_escape(cpar,
+					purple_request_field_get_label(field));
 
 				if (type != PURPLE_REQUEST_FIELD_BOOLEAN && field_label)
 				{
 					char *text = NULL;
 
 					if (field_label[strlen(field_label) - 1] != ':' &&
-						field_label[strlen(field_label) - 1] != '?')
+						field_label[strlen(field_label) - 1] != '?' &&
+						type != PURPLE_REQUEST_FIELD_LABEL)
 					{
 						text = g_strdup_printf("%s:", field_label);
 					}
@@ -1651,6 +1690,7 @@
 					}
 
 					gtk_widget_show(label);
+					g_free(field_label);
 				}
 
 				widget = GTK_WIDGET(purple_request_field_get_ui_data(field));
@@ -1661,7 +1701,7 @@
 					else if (type == PURPLE_REQUEST_FIELD_INTEGER)
 						widget = create_int_field(field);
 					else if (type == PURPLE_REQUEST_FIELD_BOOLEAN)
-						widget = create_bool_field(field);
+						widget = create_bool_field(field, cpar);
 					else if (type == PURPLE_REQUEST_FIELD_CHOICE)
 						widget = create_choice_field(field, cpar);
 					else if (type == PURPLE_REQUEST_FIELD_LIST)
@@ -1971,10 +2011,11 @@
 	pidgin_request_input,
 	pidgin_request_choice,
 	pidgin_request_action,
+	NULL,
 	pidgin_request_fields,
 	pidgin_request_file,
+	pidgin_request_folder,
 	pidgin_close_request,
-	pidgin_request_folder,
 	NULL,
 	NULL,
 	NULL,

mercurial