comparison libpurple/protocols/bonjour/buddy.c @ 24120:16734635febf

Start hiding blist.h internals in prpls.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 27 Sep 2008 06:33:42 +0000
parents ef0bcbe33689
children 5ace6c024230
comparison
equal deleted inserted replaced
24119:d1cfa8c11902 24120:16734635febf
126 bonjour_buddy_add_to_purple(BonjourBuddy *bonjour_buddy, PurpleBuddy *buddy) 126 bonjour_buddy_add_to_purple(BonjourBuddy *bonjour_buddy, PurpleBuddy *buddy)
127 { 127 {
128 PurpleGroup *group; 128 PurpleGroup *group;
129 PurpleAccount *account = bonjour_buddy->account; 129 PurpleAccount *account = bonjour_buddy->account;
130 const char *status_id, *old_hash, *new_hash; 130 const char *status_id, *old_hash, *new_hash;
131 const char *name;
131 132
132 /* Translate between the Bonjour status and the Purple status */ 133 /* Translate between the Bonjour status and the Purple status */
133 if (bonjour_buddy->status != NULL && g_ascii_strcasecmp("dnd", bonjour_buddy->status) == 0) 134 if (bonjour_buddy->status != NULL && g_ascii_strcasecmp("dnd", bonjour_buddy->status) == 0)
134 status_id = BONJOUR_STATUS_ID_AWAY; 135 status_id = BONJOUR_STATUS_ID_AWAY;
135 else 136 else
155 buddy = purple_buddy_new(account, bonjour_buddy->name, NULL); 156 buddy = purple_buddy_new(account, bonjour_buddy->name, NULL);
156 purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE); 157 purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE);
157 purple_blist_add_buddy(buddy, NULL, group, NULL); 158 purple_blist_add_buddy(buddy, NULL, group, NULL);
158 } 159 }
159 160
161 name = purple_buddy_get_name(buddy);
160 buddy->proto_data = bonjour_buddy; 162 buddy->proto_data = bonjour_buddy;
161 163
162 /* Create the alias for the buddy using the first and the last name */ 164 /* Create the alias for the buddy using the first and the last name */
163 if (bonjour_buddy->nick) 165 if (bonjour_buddy->nick)
164 serv_got_alias(purple_account_get_connection(account), buddy->name, bonjour_buddy->nick); 166 serv_got_alias(purple_account_get_connection(account), name, bonjour_buddy->nick);
165 else { 167 else {
166 gchar *alias = NULL; 168 gchar *alias = NULL;
167 const char *first, *last; 169 const char *first, *last;
168 first = bonjour_buddy->first; 170 first = bonjour_buddy->first;
169 last = bonjour_buddy->last; 171 last = bonjour_buddy->last;
170 if ((first && *first) || (last && *last)) 172 if ((first && *first) || (last && *last))
171 alias = g_strdup_printf("%s%s%s", 173 alias = g_strdup_printf("%s%s%s",
172 (first && *first ? first : ""), 174 (first && *first ? first : ""),
173 (first && *first && last && *last ? " " : ""), 175 (first && *first && last && *last ? " " : ""),
174 (last && *last ? last : "")); 176 (last && *last ? last : ""));
175 serv_got_alias(purple_account_get_connection(account), buddy->name, alias); 177 serv_got_alias(purple_account_get_connection(account), name, alias);
176 g_free(alias); 178 g_free(alias);
177 } 179 }
178 180
179 /* Set the user's status */ 181 /* Set the user's status */
180 if (bonjour_buddy->msg != NULL) 182 if (bonjour_buddy->msg != NULL)
181 purple_prpl_got_user_status(account, buddy->name, status_id, 183 purple_prpl_got_user_status(account, name, status_id,
182 "message", bonjour_buddy->msg, NULL); 184 "message", bonjour_buddy->msg, NULL);
183 else 185 else
184 purple_prpl_got_user_status(account, buddy->name, status_id, NULL); 186 purple_prpl_got_user_status(account, name, status_id, NULL);
185 187
186 purple_prpl_got_user_idle(account, buddy->name, FALSE, 0); 188 purple_prpl_got_user_idle(account, name, FALSE, 0);
187 189
188 /* TODO: Because we don't save Bonjour buddies in blist.xml, 190 /* TODO: Because we don't save Bonjour buddies in blist.xml,
189 * we will always have to look up the buddy icon at login time. 191 * we will always have to look up the buddy icon at login time.
190 * I think we should figure out a way to do something about this. */ 192 * I think we should figure out a way to do something about this. */
191 193
196 /* Look up the new icon data */ 198 /* Look up the new icon data */
197 /* TODO: Make sure the hash assigned to the retrieved buddy icon is the same 199 /* TODO: Make sure the hash assigned to the retrieved buddy icon is the same
198 * as what we looked up. */ 200 * as what we looked up. */
199 bonjour_dns_sd_retrieve_buddy_icon(bonjour_buddy); 201 bonjour_dns_sd_retrieve_buddy_icon(bonjour_buddy);
200 } else if (!new_hash) 202 } else if (!new_hash)
201 purple_buddy_icons_set_for_user(account, buddy->name, NULL, 0, NULL); 203 purple_buddy_icons_set_for_user(account, name, NULL, 0, NULL);
202 } 204 }
203 205
204 /** 206 /**
205 * The buddy has signed off Bonjour. 207 * The buddy has signed off Bonjour.
206 * If the buddy is being saved, mark as offline, otherwise delete 208 * If the buddy is being saved, mark as offline, otherwise delete