# HG changeset patch # User Etan Reisner # Date 1250313007 0 # Node ID e8eaf57f42da167318d8e1bdbb160f5b72fc83c7 # Parent 90075d91f4e82107bc225ca49fb05c5cba2f9220 Add a purple_account_get_name_for_display function (I'm not a huge fan of that name but didn't want to use get_display_name as that means something else for connections). This wants to be used in places where we need to display an identifier for the account to the user and honor the appropriate aliases/etc. Refs #8391 diff -r 90075d91f4e8 -r e8eaf57f42da ChangeLog.API --- a/ChangeLog.API Fri Aug 14 18:05:25 2009 +0000 +++ b/ChangeLog.API Sat Aug 15 05:10:07 2009 +0000 @@ -22,6 +22,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 diff -r 90075d91f4e8 -r e8eaf57f42da libpurple/account.c --- a/libpurple/account.c Fri Aug 14 18:05:25 2009 +0000 +++ b/libpurple/account.c Sat Aug 15 05:10:07 2009 +0000 @@ -2016,6 +2016,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) { diff -r 90075d91f4e8 -r e8eaf57f42da libpurple/account.h --- a/libpurple/account.h Fri Aug 14 18:05:25 2009 +0000 +++ b/libpurple/account.h Sat Aug 15 05:10:07 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.