pidgin: 312b5a74: Finally merged the code that fixes #5038...

ivan.komarov at pidgin.im ivan.komarov at pidgin.im
Wed Mar 30 18:40:52 EDT 2011


----------------------------------------------------------------------
Revision: 312b5a74ad324337a47554ec05943a58f68c2ae1
Parent:   7386f651da12e8eaa3a280ff11f2d7c163136d94
Author:   ivan.komarov at pidgin.im
Date:     03/30/11 18:36:30
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/312b5a74ad324337a47554ec05943a58f68c2ae1

Changelog: 

Finally merged the code that fixes #5038 to i.p.p.

applied changes from 563c6a79e1266b750fe4bd608890195cfbcd8a2c
             through d00e5622c7b15359775cf6892019db8af29ed8fe

Changes against parent 7386f651da12e8eaa3a280ff11f2d7c163136d94

  patched  pidgin/gtkaccount.c
  patched  pidgin/gtkblist.c
  patched  pidgin/minidialog.c
  patched  pidgin/minidialog.h

-------------- next part --------------
============================================================
--- pidgin/gtkblist.c	3f42109863afcbb33bbf73825ca3b6ab933f6eeb
+++ pidgin/gtkblist.c	1801513e52b71a71fc44a78f78581f06b30e43b5
@@ -5134,7 +5134,7 @@ add_generic_error_dialog(PurpleAccount *
 		account);
 
 	 if(err->type == PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT)
-		pidgin_mini_dialog_add_button(PIDGIN_MINI_DIALOG(mini_dialog),
+		pidgin_mini_dialog_add_non_closing_button(PIDGIN_MINI_DIALOG(mini_dialog),
 				_("SSL FAQs"), ssl_faq_clicked_cb, NULL);
 
 	g_signal_connect_after(mini_dialog, "destroy",
============================================================
--- pidgin/gtkaccount.c	a24f7229dfb323cb38b19ffeafbdde7b052728a9
+++ pidgin/gtkaccount.c	20f43b6c2ebe78b0d0847448fc4d8c7271377b03
@@ -46,6 +46,7 @@
 #include "gtkutils.h"
 #include "gtkstatusbox.h"
 #include "pidginstock.h"
+#include "minidialog.h"
 
 enum
 {
@@ -2501,6 +2502,28 @@ deny_no_add_cb(struct auth_request *ar)
 	ar->deny_cb(ar->data);
 }
 
+static gboolean
+get_user_info_cb(GtkWidget   *label,
+                 const gchar *uri,
+                 gpointer     data)
+{
+	struct auth_request *ar = data;
+	if (!strcmp(uri, "viewinfo")) {
+		pidgin_retrieve_user_info(purple_account_get_connection(ar->account), ar->username);
+		return TRUE;
+	}
+	return FALSE;
+}
+
+static void
+send_im_cb(PidginMiniDialog *mini_dialog,
+           GtkButton *button,
+           gpointer data)
+{
+	struct auth_request *ar = data;
+	pidgin_dialogs_im_with_user(ar->account, ar->username);
+}
+
 static void *
 pidgin_accounts_request_authorization(PurpleAccount *account,
                                       const char *remote_user,
@@ -2515,27 +2538,47 @@ pidgin_accounts_request_authorization(Pu
 	char *buffer;
 	PurpleConnection *gc;
 	GtkWidget *alert;
+	PidginMiniDialog *dialog;
 	GdkPixbuf *prpl_icon;
 	struct auth_request *aa;
+	const char *our_name;
 	gboolean have_valid_alias = alias && *alias;
 
 	gc = purple_account_get_connection(account);
 	if (message != NULL && *message == '\0')
 		message = NULL;
 
-	buffer = g_strdup_printf(_("%s%s%s%s wants to add you (%s) to his or her buddy list%s%s"),
-				remote_user,
-				(have_valid_alias ? " ("  : ""),
-				(have_valid_alias ? alias : ""),
-				(have_valid_alias ? ")"   : ""),
-				(id != NULL
-				? id
-				: (purple_connection_get_display_name(gc) != NULL
-				? purple_connection_get_display_name(gc)
-				: purple_account_get_username(account))),
-				(message != NULL ? ": " : "."),
-				(message != NULL ? message  : ""));
+	our_name = (id != NULL) ? id :
+			(purple_connection_get_display_name(gc) != NULL) ? purple_connection_get_display_name(gc) :
+			purple_account_get_username(account);
 
+	if (pidgin_mini_dialog_links_supported()) {
+		char *escaped_remote_user = g_markup_escape_text(remote_user, -1);
+		char *escaped_alias = alias != NULL ? g_markup_escape_text(alias, -1) : g_strdup("");
+		char *escaped_our_name = g_markup_escape_text(our_name, -1);
+		char *escaped_message = message != NULL ? g_markup_escape_text(message, -1) : g_strdup("");
+		buffer = g_strdup_printf(_("<a href=\"viewinfo\">%s</a>%s%s%s wants to add you (%s) to his or her buddy list%s%s"),
+					escaped_remote_user,
+					(have_valid_alias ? " ("  : ""),
+					escaped_alias,
+					(have_valid_alias ? ")"   : ""),
+					escaped_our_name,
+					(have_valid_alias ? ": " : "."),
+					escaped_message);
+		g_free(escaped_remote_user);
+		g_free(escaped_alias);
+		g_free(escaped_our_name);
+		g_free(escaped_message);
+	} else {
+		buffer = g_strdup_printf(_("%s%s%s%s wants to add you (%s) to his or her buddy list%s%s"),
+					remote_user,
+					(have_valid_alias ? " ("  : ""),
+					(have_valid_alias ? alias : ""),
+					(have_valid_alias ? ")"   : ""),
+					our_name,
+					(message != NULL ? ": " : "."),
+					(message != NULL ? message  : ""));
+	}
 
 	prpl_icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL);
 
@@ -2550,11 +2593,19 @@ pidgin_accounts_request_authorization(Pu
 
 	alert = pidgin_make_mini_dialog_with_custom_icon(
 		gc, prpl_icon,
-		_("Authorize buddy?"), buffer, aa,
+		_("Authorize buddy?"), NULL, aa,
 		_("Authorize"), authorize_and_add_cb,
 		_("Deny"), deny_no_add_cb,
 		NULL);
 
+	dialog = PIDGIN_MINI_DIALOG(alert);
+	if (pidgin_mini_dialog_links_supported()) {
+		pidgin_mini_dialog_enable_description_markup(dialog);
+		pidgin_mini_dialog_set_link_callback(dialog, G_CALLBACK(get_user_info_cb), aa);
+	}
+	pidgin_mini_dialog_set_description(dialog, buffer);
+	pidgin_mini_dialog_add_non_closing_button(dialog, _("Send Instant Message"), send_im_cb, aa);
+
 	g_signal_connect_swapped(G_OBJECT(alert), "destroy", G_CALLBACK(free_auth_request), aa);
 	g_signal_connect(G_OBJECT(alert), "destroy", G_CALLBACK(purple_account_request_close), NULL);
 	pidgin_blist_add_alert(alert);
============================================================
--- pidgin/minidialog.c	d14d7458239921be4fa9baf33df2af4adcab0a79
+++ pidgin/minidialog.c	25df03b2f3f0c96122312096e55480391960a750
@@ -76,6 +76,7 @@ enum
 	PROP_DESCRIPTION,
 	PROP_ICON_NAME,
 	PROP_CUSTOM_ICON,
+	PROP_ENABLE_DESCRIPTION_MARKUP,
 
 	LAST_PROPERTY
 } HazeConnectionProperties;
@@ -87,6 +88,7 @@ typedef struct _PidginMiniDialogPrivate
 	GtkLabel *title;
 	GtkLabel *desc;
 	GtkBox *buttons;
+	gboolean enable_description_markup;
 
 	guint idle_destroy_cb_id;
 } PidginMiniDialogPrivate;
@@ -138,6 +140,27 @@ void
 }
 
 void
+pidgin_mini_dialog_enable_description_markup(PidginMiniDialog *mini_dialog)
+{
+	g_object_set(G_OBJECT(mini_dialog), "enable-description-markup", TRUE, NULL);
+}
+
+gboolean
+pidgin_mini_dialog_links_supported()
+{
+#if GTK_CHECK_VERSION(2,18,0)
+	return TRUE;
+#else
+	return FALSE;
+#endif
+}
+
+void pidgin_mini_dialog_set_link_callback(PidginMiniDialog *mini_dialog, GCallback cb, gpointer user_data)
+{
+	g_signal_connect(PIDGIN_MINI_DIALOG_GET_PRIVATE(mini_dialog)->desc, "activate-link", cb, user_data);
+}
+
+void
 pidgin_mini_dialog_set_icon_name(PidginMiniDialog *mini_dialog,
                                  const char *icon_name)
 {
@@ -155,6 +178,7 @@ struct _mini_dialog_button_clicked_cb_da
 	PidginMiniDialog *mini_dialog;
 	PidginMiniDialogCallback callback;
 	gpointer user_data;
+	gboolean close_dialog_after_click;
 };
 
 guint
@@ -178,12 +202,14 @@ mini_dialog_button_clicked_cb(GtkButton 
 	PidginMiniDialogPrivate *priv =
 		PIDGIN_MINI_DIALOG_GET_PRIVATE(data->mini_dialog);
 
-	/* Set up the destruction callback before calling the clicked callback,
-	 * so that if the mini-dialog gets destroyed during the clicked callback
-	 * the idle_destroy_cb is correctly removed by _finalize.
-	 */
-	priv->idle_destroy_cb_id =
-		g_idle_add((GSourceFunc) idle_destroy_cb, data->mini_dialog);
+	if (data->close_dialog_after_click) {
+		/* Set up the destruction callback before calling the clicked callback,
+		 * so that if the mini-dialog gets destroyed during the clicked callback
+		 * the idle_destroy_cb is correctly removed by _finalize.
+		 */
+		priv->idle_destroy_cb_id =
+			g_idle_add((GSourceFunc) idle_destroy_cb, data->mini_dialog);
+	}
 
 	if (data->callback != NULL)
 		data->callback(data->mini_dialog, button, data->user_data);
@@ -198,11 +224,12 @@ mini_dialog_button_destroy_cb(GtkButton 
 	g_free(data);
 }
 
-void
-pidgin_mini_dialog_add_button(PidginMiniDialog *self,
-                              const char *text,
-                              PidginMiniDialogCallback clicked_cb,
-                              gpointer user_data)
+static void
+mini_dialog_add_button(PidginMiniDialog *self,
+                       const char *text,
+                       PidginMiniDialogCallback clicked_cb,
+                       gpointer user_data,
+                       gboolean close_dialog_after_click)
 {
 	PidginMiniDialogPrivate *priv = PIDGIN_MINI_DIALOG_GET_PRIVATE(self);
 	struct _mini_dialog_button_clicked_cb_data *callback_data
@@ -218,6 +245,7 @@ pidgin_mini_dialog_add_button(PidginMini
 	callback_data->mini_dialog = self;
 	callback_data->callback = clicked_cb;
 	callback_data->user_data = user_data;
+	callback_data->close_dialog_after_click = close_dialog_after_click;
 	g_signal_connect(G_OBJECT(button), "clicked",
 		(GCallback) mini_dialog_button_clicked_cb, callback_data);
 	g_signal_connect(G_OBJECT(button), "destroy",
@@ -231,6 +259,24 @@ pidgin_mini_dialog_add_button(PidginMini
 	gtk_widget_show_all(GTK_WIDGET(button));
 }
 
+void
+pidgin_mini_dialog_add_button(PidginMiniDialog *self,
+                              const char *text,
+                              PidginMiniDialogCallback clicked_cb,
+                              gpointer user_data)
+{
+	mini_dialog_add_button(self, text, clicked_cb, user_data, TRUE);
+}
+
+void
+pidgin_mini_dialog_add_non_closing_button(PidginMiniDialog *self,
+                                          const char *text,
+                                          PidginMiniDialogCallback clicked_cb,
+                                          gpointer user_data)
+{
+	mini_dialog_add_button(self, text, clicked_cb, user_data, FALSE);
+}
+
 static void
 pidgin_mini_dialog_get_property(GObject *object,
                                 guint property_id,
@@ -258,6 +304,9 @@ pidgin_mini_dialog_get_property(GObject 
 		case PROP_CUSTOM_ICON:
 			g_value_set_object(value, gtk_image_get_pixbuf(priv->icon));
 			break;
+		case PROP_ENABLE_DESCRIPTION_MARKUP:
+			g_value_set_boolean(value, priv->enable_description_markup);
+			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 	}
@@ -287,7 +336,7 @@ mini_dialog_set_description(PidginMiniDi
 	PidginMiniDialogPrivate *priv = PIDGIN_MINI_DIALOG_GET_PRIVATE(self);
 	if(description)
 	{
-		char *desc_esc = g_markup_escape_text(description, -1);
+		char *desc_esc = priv->enable_description_markup ? g_strdup(description) : g_markup_escape_text(description, -1);
 		char *desc_markup = g_strdup_printf(
 			"<span size=\"smaller\">%s</span>", desc_esc);
 
@@ -333,6 +382,9 @@ pidgin_mini_dialog_set_property(GObject 
 		case PROP_CUSTOM_ICON:
 			gtk_image_set_from_pixbuf(priv->icon, g_value_get_object(value));
 			break;
+		case PROP_ENABLE_DESCRIPTION_MARKUP:
+			priv->enable_description_markup = g_value_get_boolean(value);
+			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 	}
@@ -390,6 +442,12 @@ pidgin_mini_dialog_class_init(PidginMini
 		G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB |
 		G_PARAM_READWRITE);
 	g_object_class_install_property (object_class, PROP_CUSTOM_ICON, param_spec);
+
+	param_spec = g_param_spec_boolean("enable-description-markup", "enable-description-markup",
+		"Use GMarkup in the description text", FALSE,
+		G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB |
+		G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_ENABLE_DESCRIPTION_MARKUP, param_spec);
 }
 
 /* 16 is the width of the icon, due to PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL */
============================================================
--- pidgin/minidialog.h	6e76b825e7b0f92a3c28b5d76c8eec8fbe7e57ef
+++ pidgin/minidialog.h	e862993faec728088db1817b2a3c72af40c7d093
@@ -139,6 +139,23 @@ void pidgin_mini_dialog_set_description(
 void pidgin_mini_dialog_set_description(PidginMiniDialog *mini_dialog,
 	const char *description);
 
+/** Enable GMarkup elements in the mini-dialog's description.
+ *  @param mini_dialog a mini-dialog
+ */
+void pidgin_mini_dialog_enable_description_markup(PidginMiniDialog *mini_dialog);
+
+/** Mini-dialogs support hyperlinks in their description
+ *  (you should first call pidgin_mini_dialog_enable_description_markup() on a given
+ *  dialog to enable them). */
+gboolean pidgin_mini_dialog_links_supported(void);
+
+/** Sets a callback which gets invoked when a hyperlink in the dialog's description is clicked on.
+ *  @param mini_dialog a mini-dialog
+ *  @param cb the callback to invoke
+ *  @param user_data the user data to pass to the callback
+ */
+void pidgin_mini_dialog_set_link_callback(PidginMiniDialog *mini_dialog, GCallback cb, gpointer user_data);
+
 /** Shortcut for setting a mini-dialog's icon via GObject properties.
  *  @param mini_dialog a mini-dialog
  *  @param icon_name   the Gtk stock ID of an icon, or @c NULL for no icon.
@@ -166,6 +183,13 @@ void pidgin_mini_dialog_add_button(Pidgi
 	const char *text, PidginMiniDialogCallback clicked_cb,
 	gpointer user_data);
 
+/** Equivalent to pidgin_mini_dialog_add_button(), the only difference
+ *  is that the mini-dialog won't be closed after the button is clicked.
+ */
+void pidgin_mini_dialog_add_non_closing_button(PidginMiniDialog *mini_dialog,
+	const char *text, PidginMiniDialogCallback clicked_cb,
+	gpointer user_data);
+
 /** Gets the number of widgets packed into PidginMiniDialog.contents.
  *  @param mini_dialog a mini-dialog
  *  @return the number of widgets in @a mini_dialog->contents.


More information about the Commits mailing list