changeset 9620:c001be3c330e

[gaim-migrate @ 10464] Changes to those get_alias functions in blist.c from Christopher (siege) O'Brien: Renames gaim_get_buddy_alias to gaim_buddy_get_alias Renames gaim_get_buddy_alias_only to _gaim_buddy_get_alias_only Adds function gaim_buddy_get_contact_alias, which looks up a buddy's appropriate display name by order of: buddy alias; contact alias; server alias; buddy name. Note that the buddy alias is still the top-priority. Changed conversation.c to use _get_contact_alias rather than _get_alias The end result of this is that aliasing the contact will result in conversations with any of that contact's buddies using the contact alias. This allows people like myself to no longer have to alias each buddy to the same alias in order to achieve the same effect. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 31 Jul 2004 21:29:40 +0000
parents da88e2cd5c53
children de9c4dc072b5
files plugins/ChangeLog.API plugins/statenotify.c plugins/tcl/tcl_cmds.c plugins/ticker/ticker.c src/blist.c src/blist.h src/conversation.c src/gtkblist.c src/gtkpounce.c src/protocols/msn/switchboard.c src/protocols/novell/novell.c src/protocols/oscar/oscar.c src/server.c
diffstat 13 files changed, 98 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Sat Jul 31 20:48:03 2004 +0000
+++ b/plugins/ChangeLog.API	Sat Jul 31 21:29:40 2004 +0000
@@ -3,6 +3,11 @@
 version 0.81cvs
 	Commands API:
 	* Most functions now have a void *data argument.
+
+	Blist API:
+	* Added gaim_buddy_get_contact_alias
+	* Renamed gaim_get_buddy_alias to gaim_buddy_get_alias
+	* Renamed gaim_get_buddy_alias_only to gaim_buddy_get_alias_only
 	
 	Conversation API:
 	* Changed: gaim_conv_chat_add_user() (added flags parameter)
--- a/plugins/statenotify.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/plugins/statenotify.c	Sat Jul 31 21:29:40 2004 +0000
@@ -23,7 +23,7 @@
 	if (conv == NULL)
 		return;
 
-	who = gaim_get_buddy_alias(buddy);
+	who = gaim_buddy_get_alias(buddy);
 
 	g_snprintf(buf, sizeof(buf), message, who);
 
--- a/plugins/tcl/tcl_cmds.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/plugins/tcl/tcl_cmds.c	Sat Jul 31 21:29:40 2004 +0000
@@ -275,7 +275,7 @@
 		if (node->type == GAIM_BLIST_CHAT_NODE)
 			Tcl_SetStringObj(result, ((GaimChat *)node)->alias, -1);
 		else if (node->type == GAIM_BLIST_BUDDY_NODE)
-			Tcl_SetStringObj(result, (char *)gaim_get_buddy_alias((GaimBuddy *)node), -1);
+			Tcl_SetStringObj(result, (char *)gaim_buddy_get_alias((GaimBuddy *)node), -1);
 		return TCL_OK;
 		break;
 	case CMD_BUDDY_HANDLE:
--- a/plugins/ticker/ticker.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/plugins/ticker/ticker.c	Sat Jul 31 21:29:40 2004 +0000
@@ -154,7 +154,7 @@
 	g_signal_connect(G_OBJECT(td->ebox), "button-press-event",
 		G_CALLBACK(buddy_click_cb), b);
 
-	td->label = gtk_label_new(gaim_get_buddy_alias(b));
+	td->label = gtk_label_new(gaim_buddy_get_alias(b));
 	gtk_box_pack_start(GTK_BOX(hbox), td->label, FALSE, FALSE, 5);
 
 	gtk_widget_show_all(td->ebox);
--- a/src/blist.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/src/blist.c	Sat Jul 31 21:29:40 2004 +0000
@@ -916,7 +916,7 @@
 	if (contact->alias)
 		return contact->alias;
 
-	return gaim_get_buddy_alias(contact->priority);
+	return gaim_buddy_get_alias(contact->priority);
 }
 
 GaimGroup *gaim_group_new(const char *name)
@@ -1100,9 +1100,6 @@
 	g_return_if_fail(group != NULL);
 	g_return_if_fail(GAIM_BLIST_NODE_IS_GROUP((GaimBlistNode *)group));
 
-	/* XXX - Wha?  Why does this exist here? */
-	//if (!gaimbuddylist)
-		//gaimbuddylist = gaim_blist_new();
 	ops = gaimbuddylist->ui_ops;
 
 	if (!gaimbuddylist->root) {
@@ -1367,7 +1364,7 @@
 	return contact->priority;
 }
 
-const char *gaim_get_buddy_alias_only(GaimBuddy *buddy)
+const char *gaim_buddy_get_alias_only(GaimBuddy *buddy)
 {
 	g_return_val_if_fail(buddy != NULL, NULL);
 
@@ -1383,20 +1380,52 @@
 	return NULL;
 }
 
-const char *gaim_get_buddy_alias(GaimBuddy *buddy)
+
+const char *gaim_buddy_get_contact_alias(GaimBuddy *buddy)
 {
-	const char *ret;
-
-	/* Are there ever times when we WANT to return "Unknown"? */
-	/* g_return_val_if_fail(buddy != NULL, NULL); */
-	if (!buddy)
-		return _("Unknown");
-
-	ret = gaim_get_buddy_alias_only(buddy);
-
-	return ret ? ret : buddy->name;
+	GaimContact *c;
+
+	g_return_val_if_fail(buddy != NULL, NULL);
+
+	/* Search for an alias for the buddy. In order of precedence: */
+	/* The buddy alias */
+	if (buddy->alias != NULL)
+		return buddy->alias;
+
+	/* The contact alias */
+	c = gaim_buddy_get_contact(buddy);
+	if ((c != NULL) && (c->alias != NULL))
+		return c->alias;
+
+	/* The server alias, if preferences say so */
+	if ((buddy->server_alias) && (*buddy->server_alias) &&
+			(gaim_prefs_get_bool("/core/buddies/use_server_alias")))
+		return buddy->server_alias;
+
+	/* The buddy's user name (i.e. no alias) */
+	return buddy->name;
 }
 
+
+const char *gaim_buddy_get_alias(GaimBuddy *buddy)
+{
+	g_return_val_if_fail(buddy != NULL, NULL);
+
+	/* Search for an alias for the buddy. In order of precedence: */
+	/* The buddy alias */
+	if (buddy->alias != NULL)
+		return buddy->alias;
+
+	/* The server alias, if preferences say so */
+	if ((buddy->server_alias) && (*buddy->server_alias) &&
+			(gaim_prefs_get_bool("/core/buddies/use_server_alias")))
+		return buddy->server_alias;
+
+	/* The buddy's user name (i.e. no alias) */
+	return buddy->name;
+}
+
+
 const char *gaim_chat_get_name(GaimChat *chat)
 {
 	struct proto_chat_entry *pce;
--- a/src/blist.h	Sat Jul 31 20:48:03 2004 +0000
+++ b/src/blist.h	Sat Jul 31 21:29:40 2004 +0000
@@ -529,16 +529,30 @@
  * @param buddy   The buddy whose name will be returned.
  * @return        The alias (if set), server alias (if option is set), or NULL.
  */
-const char *gaim_get_buddy_alias_only(GaimBuddy *buddy);
+const char *gaim_buddy_get_alias_only(GaimBuddy *buddy);
 
 
 /**
- * Returns the correct name to display for a buddy.
+ * Returns the correct name to display for a buddy, taking the contact alias
+ * into account. In order of precedence: the buddy's alias; the buddy's
+ * contact alias; the buddy's server alias; the buddy's user name.
+ *
+ * @param buddy  The buddy whose name will be returned
+ * @return       The appropriate name or alias, or "Unknown"
+ *
+ */
+const char *gaim_buddy_get_contact_alias(GaimBuddy *buddy);
+
+
+/**
+ * Returns the correct name to display for a buddy. In order of precedence:
+ * the buddy's alias; the buddy's server alias; the buddy's contact alias;
+ * the buddy's user name.
  *
  * @param buddy   The buddy whose name will be returned.
- * @return        The alias (if set), server alias (if option is set), screenname, or "Unknown"
+ * @return        The appropriate name or alias, or "Unknown"
  */
-const char *gaim_get_buddy_alias(GaimBuddy *buddy);
+const char *gaim_buddy_get_alias(GaimBuddy *buddy);
 
 /**
  * Returns the correct name to display for a blist chat.
--- a/src/conversation.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/src/conversation.c	Sat Jul 31 21:29:40 2004 +0000
@@ -1100,7 +1100,7 @@
 	if (gaim_prefs_get_bool("/core/conversations/use_alias_for_title")) {
 		if(gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
 			if(account && ((b = gaim_find_buddy(account, name)) != NULL))
-				text = gaim_get_buddy_alias(b);
+				text = gaim_buddy_get_contact_alias(b);
 		} else if(gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
 			if(account && ((chat = gaim_blist_find_chat(account, name)) != NULL))
 				text = chat->alias;
@@ -1389,8 +1389,8 @@
 
 					if (gaim_account_get_alias(account) != NULL)
 						who = account->alias;
-					else if (b != NULL && strcmp(b->name, gaim_get_buddy_alias(b)))
-						who = gaim_get_buddy_alias(b);
+					else if (b != NULL && strcmp(b->name, gaim_buddy_get_contact_alias(b)))
+						who = gaim_buddy_get_contact_alias(b);
 					else if (gaim_connection_get_display_name(gc) != NULL)
 						who = gaim_connection_get_display_name(gc);
 					else
@@ -1401,7 +1401,7 @@
 							    gaim_conversation_get_name(conv));
 
 					if (b != NULL)
-						who = gaim_get_buddy_alias(b);
+						who = gaim_buddy_get_contact_alias(b);
 					else
 						who = gaim_conversation_get_name(conv);
 				}
@@ -1410,7 +1410,7 @@
 				b = gaim_find_buddy(account, who);
 
 				if (b != NULL)
-					who = gaim_get_buddy_alias(b);
+					who = gaim_buddy_get_contact_alias(b);
 			}
 		}
 	}
--- a/src/gtkblist.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/src/gtkblist.c	Sat Jul 31 21:29:40 2004 +0000
@@ -2727,7 +2727,7 @@
 	if(gtkcontactnode && !gtkcontactnode->contact_expanded && contact->alias)
 		name = contact->alias;
 	else
-		name = gaim_get_buddy_alias(b);
+		name = gaim_buddy_get_alias(b);
 	esc = g_markup_escape_text(name, strlen(name));
 
 	prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account));
--- a/src/gtkpounce.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/src/gtkpounce.c	Sat Jul 31 21:29:40 2004 +0000
@@ -932,7 +932,7 @@
 
 	buddy = gaim_find_buddy(account, pouncee);
 
-	alias = gaim_get_buddy_alias(buddy);
+	alias = gaim_buddy_get_alias(buddy);
 
 	/* Find the protocol id for the window title and/or message */
 	proto = gaim_find_prpl(gaim_account_get_protocol_id(account));
--- a/src/protocols/msn/switchboard.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/src/protocols/msn/switchboard.c	Sat Jul 31 21:29:40 2004 +0000
@@ -180,7 +180,7 @@
 		char *str = NULL;
 
 		if ((b = gaim_find_buddy(account, user)) != NULL)
-			username = gaim_escape_html(gaim_get_buddy_alias(b));
+			username = gaim_escape_html(gaim_buddy_get_alias(b));
 		else
 			username = gaim_escape_html(user);
 
--- a/src/protocols/novell/novell.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/src/protocols/novell/novell.c	Sat Jul 31 21:29:40 2004 +0000
@@ -266,7 +266,7 @@
 		gaim_blist_rename_buddy(buddy,
 								nm_user_record_get_display_id(user_record));
 
-		alias = gaim_get_buddy_alias(buddy);
+		alias = gaim_buddy_get_alias(buddy);
 		if (alias == NULL || (strcmp(alias, buddy->name) == 0)) {
 			gaim_blist_alias_buddy(buddy,
 								   nm_user_record_get_full_name(user_record));
@@ -2456,7 +2456,7 @@
 	/* Remove the GaimBuddy (we will add it back after adding it
 	 * to the server side list). Save the alias if there is one.
 	 */
-	alias = gaim_get_buddy_alias(buddy);
+	alias = gaim_buddy_get_alias(buddy);
 	if (alias && strcmp(alias, buddy->name))
 		nm_contact_set_display_name(contact, alias);
 
--- a/src/protocols/oscar/oscar.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/src/protocols/oscar/oscar.c	Sat Jul 31 21:29:40 2004 +0000
@@ -3341,7 +3341,7 @@
 					   buddy->name, group->name);
 			aim_ssi_sendauthrequest(od->sess, data->name, msg ? msg : _("Please authorize me so I can add you to my buddy list."));
 			if (!aim_ssi_itemlist_finditem(od->sess->ssi.local, group->name, buddy->name, AIM_SSI_TYPE_BUDDY))
-				aim_ssi_addbuddy(od->sess, buddy->name, group->name, gaim_get_buddy_alias_only(buddy), NULL, NULL, 1);
+				aim_ssi_addbuddy(od->sess, buddy->name, group->name, gaim_buddy_get_alias_only(buddy), NULL, NULL, 1);
 		}
 	}
 }
@@ -3373,8 +3373,8 @@
 	gchar *dialog_msg, *nombre;
 
 	buddy = gaim_find_buddy(gc->account, name);
-	if (buddy && (gaim_get_buddy_alias_only(buddy)))
-		nombre = g_strdup_printf("%s (%s)", name, gaim_get_buddy_alias_only(buddy));
+	if (buddy && (gaim_buddy_get_alias_only(buddy)))
+		nombre = g_strdup_printf("%s (%s)", name, gaim_buddy_get_alias_only(buddy));
 	else
 		nombre = NULL;
 
@@ -3417,7 +3417,7 @@
 		message = 0;
 		buddy = gaim_find_buddy(gc->account, data->name);
 		aim_im_sendch4(od->sess, data->name, AIM_ICQMSG_AUTHGRANTED, &message);
-		gaim_account_notify_added(gc->account, NULL, data->name, (buddy ? gaim_get_buddy_alias_only(buddy) : NULL), NULL);
+		gaim_account_notify_added(gc->account, NULL, data->name, (buddy ? gaim_buddy_get_alias_only(buddy) : NULL), NULL);
 #else
 		aim_ssi_sendauthreply(od->sess, data->name, 0x01, NULL);
 #endif
@@ -4906,7 +4906,7 @@
 		g_string_append_printf(str, "\n<hr>\n");
 	}
 
-	primary = g_strdup_printf(_("ICQ Info for %s"), gaim_get_buddy_alias(buddy));
+	primary = g_strdup_printf(_("ICQ Info for %s"), gaim_buddy_get_alias(buddy));
 	gaim_notify_formatted(gc, NULL, primary, NULL, str->str, NULL, NULL);
 	g_free(primary);
 	g_string_free(str, TRUE);
@@ -5532,7 +5532,7 @@
 		if (buddy && group) {
 			gaim_debug_info("oscar",
 					   "ssi: adding buddy %s to group %s\n", buddy->name, group->name);
-			aim_ssi_addbuddy(od->sess, buddy->name, group->name, gaim_get_buddy_alias_only(buddy), NULL, NULL, 0);
+			aim_ssi_addbuddy(od->sess, buddy->name, group->name, gaim_buddy_get_alias_only(buddy), NULL, NULL, 0);
 		}
 	}
 #endif
@@ -6053,8 +6053,8 @@
 			   "ssi: %s has given you permission to add him to your buddy list\n", sn);
 
 	buddy = gaim_find_buddy(gc->account, sn);
-	if (buddy && (gaim_get_buddy_alias_only(buddy)))
-		nombre = g_strdup_printf("%s (%s)", sn, gaim_get_buddy_alias_only(buddy));
+	if (buddy && (gaim_buddy_get_alias_only(buddy)))
+		nombre = g_strdup_printf("%s (%s)", sn, gaim_buddy_get_alias_only(buddy));
 	else
 		nombre = g_strdup(sn);
 
@@ -6092,8 +6092,8 @@
 			   "ssi: received authorization request from %s\n", sn);
 
 	buddy = gaim_find_buddy(gc->account, sn);
-	if (buddy && (gaim_get_buddy_alias_only(buddy)))
-		nombre = g_strdup_printf("%s (%s)", sn, gaim_get_buddy_alias_only(buddy));
+	if (buddy && (gaim_buddy_get_alias_only(buddy)))
+		nombre = g_strdup_printf("%s (%s)", sn, gaim_buddy_get_alias_only(buddy));
 	else
 		nombre = g_strdup(sn);
 
@@ -6132,8 +6132,8 @@
 			   "ssi: received authorization reply from %s.  Reply is 0x%04hhx\n", sn, reply);
 
 	buddy = gaim_find_buddy(gc->account, sn);
-	if (buddy && (gaim_get_buddy_alias_only(buddy)))
-		nombre = g_strdup_printf("%s (%s)", sn, gaim_get_buddy_alias_only(buddy));
+	if (buddy && (gaim_buddy_get_alias_only(buddy)))
+		nombre = g_strdup_printf("%s (%s)", sn, gaim_buddy_get_alias_only(buddy));
 	else
 		nombre = g_strdup(sn);
 
@@ -6165,7 +6165,7 @@
 	buddy = gaim_find_buddy(gc->account, sn);
 	gaim_debug_info("oscar",
 			   "ssi: %s added you to their buddy list\n", sn);
-	gaim_account_notify_added(gc->account, NULL, sn, (buddy ? gaim_get_buddy_alias_only(buddy) : NULL), NULL);
+	gaim_account_notify_added(gc->account, NULL, sn, (buddy ? gaim_buddy_get_alias_only(buddy) : NULL), NULL);
 
 	return 1;
 }
@@ -6912,8 +6912,8 @@
 				if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
 					continue;
 				if (buddy->account == gc->account && aim_ssi_waitingforauth(od->sess->ssi.local, group->name, buddy->name)) {
-					if (gaim_get_buddy_alias_only(buddy))
-						nombre = g_strdup_printf(" %s (%s)", buddy->name, gaim_get_buddy_alias_only(buddy));
+					if (gaim_buddy_get_alias_only(buddy))
+						nombre = g_strdup_printf(" %s (%s)", buddy->name, gaim_buddy_get_alias_only(buddy));
 					else
 						nombre = g_strdup_printf(" %s", buddy->name);
 					tmp = g_strdup_printf("%s%s<br>", text, nombre);
--- a/src/server.c	Sat Jul 31 20:48:03 2004 +0000
+++ b/src/server.c	Sat Jul 31 21:29:40 2004 +0000
@@ -900,7 +900,7 @@
 		time_t t = time(NULL);
 		char *tmpmsg;
 		GaimBuddy *b = gaim_find_buddy(gc->account, name);
-		const char *alias = b ? gaim_get_buddy_alias(b) : name;
+		const char *alias = b ? gaim_buddy_get_alias(b) : name;
 		int row;
 		struct last_auto_response *lar;
 		const gchar *auto_reply_pref;
@@ -1170,7 +1170,7 @@
 		gaim_blist_rename_buddy(b, name);
 	}
 
-	alias = gaim_escape_html(gaim_get_buddy_alias(b));
+	alias = gaim_escape_html(gaim_buddy_get_alias(b));
 
 	old_idle = b->idle;