cpw.ivan: d00e5622: Add a "Send Instant Message" button and ...

ivan.komarov at soc.pidgin.im ivan.komarov at soc.pidgin.im
Sun Oct 10 11:12:40 EDT 2010


----------------------------------------------------------------------
Revision: d00e5622c7b15359775cf6892019db8af29ed8fe
Parent:   563c6a79e1266b750fe4bd608890195cfbcd8a2c
Author:   ivan.komarov at soc.pidgin.im
Date:     10/10/10 11:04:20
Branch:   im.pidgin.cpw.ivan
URL: http://d.pidgin.im/viewmtn/revision/info/d00e5622c7b15359775cf6892019db8af29ed8fe

Changelog: 

Add a "Send Instant Message" button and a hyperlink to the user's profile
(works only for GTK+ >= 2.18) to the authorization request dialog.
Refs #5038

Changes against parent 563c6a79e1266b750fe4bd608890195cfbcd8a2c

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

-------------- next part --------------
============================================================
--- pidgin/gtkblist.c	849ad4c8761af32a534733bd3124544c69978fd6
+++ pidgin/gtkblist.c	7b36e5c1d026ad581b7a5a75636ae86797cbfe7d
@@ -5188,7 +5188,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	67355ddf08aa04ea8bc82450a9b0276a03937981
+++ pidgin/gtkaccount.c	364cae38569bb61b628b61f63267f325310f0c3a
@@ -46,6 +46,7 @@
 #include "gtkutils.h"
 #include "gtkstatusbox.h"
 #include "pidginstock.h"
+#include "minidialog.h"
 
 enum
 {
@@ -2452,6 +2453,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,
@@ -2466,29 +2489,49 @@ pidgin_accounts_request_authorization(Pu
 	char *buffer;
 	PurpleConnection *gc;
 	GtkWidget *alert;
+	PidginMiniDialog *dialog;
 	GdkPixbuf *prpl_icon;
 	struct auth_request *aa;
+	const char *our_name;
 
 	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,
-				(alias != NULL ? " ("  : ""),
-				(alias != NULL ? alias : ""),
-				(alias != NULL ? ")"   : ""),
-				(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,
+					(alias != NULL ? " ("  : ""),
+					escaped_alias,
+					(alias != NULL ? ")"   : ""),
+					escaped_our_name,
+					(message != NULL ? ": " : "."),
+					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,
+					(alias != NULL ? " ("  : ""),
+					(alias != NULL ? alias : ""),
+					(alias != NULL ? ")"   : ""),
+					our_name,
+					(message != NULL ? ": " : "."),
+					(message != NULL ? message  : ""));
+	}
 
 	prpl_icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL);
-	
+
 	aa = g_new0(struct auth_request, 1);
 	aa->auth_cb = auth_cb;
 	aa->deny_cb = deny_cb;
@@ -2497,14 +2540,22 @@ pidgin_accounts_request_authorization(Pu
 	aa->alias = g_strdup(alias);
 	aa->account = account;
 	aa->add_buddy_after_auth = !on_list;
-	
+
 	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	0ff3f39351172aebcd5504f3915242777b6d05cd
+++ 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);
 
@@ -332,6 +381,10 @@ pidgin_mini_dialog_set_property(GObject 
 			break;
 		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);
 	}
@@ -382,13 +435,19 @@ 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_ICON_NAME, param_spec);
-	
+
 	param_spec = g_param_spec_object("custom-icon", "custom-icon",
 		"Pixbuf to use as the dialog's icon",
 		GDK_TYPE_PIXBUF,
 		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	0a32b4e69f9f0210bdfd6849a2cc8c2c8b17329a
+++ pidgin/minidialog.h	3947a588578644903c1ac79ad815316f1179d73f
@@ -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