changeset 28248:e07209e4bd9e

merge of '9577fe0ea00b1f8e69abaf756e5e1ed31b0c76cf' and 'b9bd0e2e1abbd4a3fedf2ce2fddf4efc6e3b2a5c'
author Etan Reisner <pidgin@unreliablesource.net>
date Tue, 08 Sep 2009 12:47:40 +0000
parents bfe511f69e93 (current diff) bc87a89e4401 (diff)
children 915ff09c2b91
files
diffstat 5 files changed, 73 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Tue Sep 08 01:51:16 2009 +0000
+++ b/ChangeLog.API	Tue Sep 08 12:47:40 2009 +0000
@@ -34,6 +34,7 @@
 		  and fwrite for saving a file locally. These allow a UI to stream a
 		  file through a socket without buffering the file on the local disk.
 		* Jabber plugin signals (see jabber-signals.dox)
+		* purple_account_get_name_for_display
 		* purple_account_remove_setting
 		* purple_buddy_destroy
 		* purple_buddy_get_protocol_data
--- a/libpurple/account.c	Tue Sep 08 01:51:16 2009 +0000
+++ b/libpurple/account.c	Tue Sep 08 12:47:40 2009 +0000
@@ -2019,6 +2019,42 @@
 	return account->gc;
 }
 
+const gchar *
+purple_account_get_name_for_display(const PurpleAccount *account)
+{
+	PurpleBuddy *self = NULL;
+	PurpleConnection *gc = NULL;
+	const gchar *name = NULL, *username = NULL, *displayname = NULL;
+
+	name = purple_account_get_alias(account);
+
+	if (name) {
+		return name;
+	}
+
+	username = purple_account_get_username(account);
+	self = purple_find_buddy((PurpleAccount *)account, username);
+
+	if (self) {
+		const gchar *calias= purple_buddy_get_contact_alias(self);
+
+		/* We don't want to return the buddy name if the buddy/contact
+		 * doesn't have an alias set. */
+		if (!purple_strequal(username, calias)) {
+			return calias;
+		}
+	}
+
+	gc = purple_account_get_connection(account);
+	displayname = purple_connection_get_display_name(gc);
+
+	if (displayname) {
+		return displayname;
+	}
+
+	return username;
+}
+
 gboolean
 purple_account_get_remember_password(const PurpleAccount *account)
 {
--- a/libpurple/account.h	Tue Sep 08 01:51:16 2009 +0000
+++ b/libpurple/account.h	Tue Sep 08 12:47:40 2009 +0000
@@ -630,6 +630,20 @@
 PurpleConnection *purple_account_get_connection(const PurpleAccount *account);
 
 /**
+ * Returns a name for this account appropriate for display to the user. In
+ * order of preference: the account's alias; the contact or buddy alias (if
+ * the account exists on its own buddy list); the connection's display name;
+ * the account's username.
+ *
+ * @param account The account.
+ *
+ * @return The name to display.
+ *
+ * @since 2.6.0
+ */
+const gchar *purple_account_get_name_for_display(const PurpleAccount *account);
+
+/**
  * Returns whether or not this account should save its password.
  *
  * @param account The account.
--- a/pidgin/gtkconv.c	Tue Sep 08 01:51:16 2009 +0000
+++ b/pidgin/gtkconv.c	Tue Sep 08 12:47:40 2009 +0000
@@ -3867,7 +3867,7 @@
 	gtk_size_group_add_widget(sg, image);
 
 	/* Make our menu item */
-	text = g_strdup_printf("%s (%s)", name, purple_account_get_username(account));
+	text = g_strdup_printf("%s (%s)", name, purple_account_get_name_for_display(account));
 	menuitem = gtk_radio_menu_item_new_with_label(*group, text);
 	g_free(text);
 	*group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem));
--- a/pidgin/gtkimhtmltoolbar.c	Tue Sep 08 01:51:16 2009 +0000
+++ b/pidgin/gtkimhtmltoolbar.c	Tue Sep 08 12:47:40 2009 +0000
@@ -133,22 +133,30 @@
 	destroy_toolbar_font(widget, NULL, toolbar);
 }
 
-static void apply_font(GtkWidget *widget, GtkFontSelection *fontsel)
+static void
+apply_font(GtkWidget *widget, GtkFontSelectionDialog *fontsel)
 {
 	/* this could be expanded to include font size, weight, etc.
 	   but for now only works with font face */
-	char *fontname;
-	char *space;
-	GtkIMHtmlToolbar *toolbar =  g_object_get_data(G_OBJECT(fontsel), "purple_toolbar");
+	gchar *fontname = gtk_font_selection_dialog_get_font_name(fontsel);
+	GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(fontsel),
+	                                              "purple_toolbar");
 
-	fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel));
+	if (fontname) {
+		const gchar *family_name = NULL;
+		PangoFontDescription *desc = NULL;
 
-	space = strrchr(fontname, ' ');
-	if(space && isdigit(*(space+1)))
-		*space = '\0';
+		desc = pango_font_description_from_string(fontname);
+		family_name = pango_font_description_get_family(desc);
 
-	gtk_imhtml_toggle_fontface(GTK_IMHTML(toolbar->imhtml), fontname);
-	g_free(fontname);
+		if (family_name) {
+			gtk_imhtml_toggle_fontface(GTK_IMHTML(toolbar->imhtml),
+			                           family_name);
+		}
+
+		pango_font_description_free(desc);
+		g_free(fontname);
+	}
 
 	cancel_toolbar_font(NULL, toolbar);
 }
@@ -1224,13 +1232,14 @@
 		{PIDGIN_STOCK_TOOLBAR_TEXT_SMALLER, do_small, &toolbar->smaller_size, _("Decrease Font Size")},
 		{"", NULL, NULL, NULL},
 		{PIDGIN_STOCK_TOOLBAR_FONT_FACE, toggle_font, &toolbar->font, _("Font Face")},
+		{PIDGIN_STOCK_TOOLBAR_FGCOLOR, toggle_fg_color, &toolbar->fgcolor, _("Foreground Color")},
 		{PIDGIN_STOCK_TOOLBAR_BGCOLOR, toggle_bg_color, &toolbar->bgcolor, _("Background Color")},
-		{PIDGIN_STOCK_TOOLBAR_FGCOLOR, toggle_fg_color, &toolbar->fgcolor, _("Foreground Color")},
 		{"", NULL, NULL, NULL},
 		{PIDGIN_STOCK_CLEAR, clear_formatting_cb, &toolbar->clear, _("Reset Formatting")},
 		{"", NULL, NULL, NULL},
+		{PIDGIN_STOCK_TOOLBAR_INSERT_IMAGE, insert_image_cb, &toolbar->image, _("Insert IM Image")},
 		{PIDGIN_STOCK_TOOLBAR_INSERT_LINK, insert_link_cb, &toolbar->link, _("Insert Link")},
-		{PIDGIN_STOCK_TOOLBAR_INSERT_IMAGE, insert_image_cb, &toolbar->image, _("Insert IM Image")},
+		{"", NULL, NULL, NULL},
 		{PIDGIN_STOCK_TOOLBAR_SMILEY, insert_smiley_cb, &toolbar->smiley, _("Insert Smiley")},
 		{NULL, NULL, NULL, NULL}
 	};