Mercurial > pidgin.yaz
comparison libpurple/account.c @ 16390:4fc51a87ce42
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 25 Apr 2007 21:48:56 +0000 |
parents | ac1a32ebd62c |
children | 3be560001d26 |
comparison
equal
deleted
inserted
replaced
16389:493ca924c199 | 16390:4fc51a87ce42 |
---|---|
345 /* TODO: Do we need to call purple_str_strip_char(tmp, '\r') here? */ | 345 /* TODO: Do we need to call purple_str_strip_char(tmp, '\r') here? */ |
346 child = xmlnode_new_child(node, "userinfo"); | 346 child = xmlnode_new_child(node, "userinfo"); |
347 xmlnode_insert_data(child, tmp, -1); | 347 xmlnode_insert_data(child, tmp, -1); |
348 } | 348 } |
349 | 349 |
350 if ((tmp = purple_account_get_buddy_icon(account)) != NULL) | |
351 { | |
352 child = xmlnode_new_child(node, "buddyicon"); | |
353 xmlnode_insert_data(child, tmp, -1); | |
354 } | |
355 | |
356 if (g_hash_table_size(account->settings) > 0) | 350 if (g_hash_table_size(account->settings) > 0) |
357 { | 351 { |
358 child = xmlnode_new_child(node, "settings"); | 352 child = xmlnode_new_child(node, "settings"); |
359 g_hash_table_foreach(account->settings, setting_to_xmlnode, child); | 353 g_hash_table_foreach(account->settings, setting_to_xmlnode, child); |
360 } | 354 } |
740 { | 734 { |
741 purple_account_set_user_info(ret, data); | 735 purple_account_set_user_info(ret, data); |
742 g_free(data); | 736 g_free(data); |
743 } | 737 } |
744 | 738 |
745 /* Read the buddyicon */ | 739 /* Read an old buddyicon */ |
746 child = xmlnode_get_child(node, "buddyicon"); | 740 child = xmlnode_get_child(node, "buddyicon"); |
747 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | 741 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) |
748 { | 742 { |
749 purple_account_set_buddy_icon(ret, data); | 743 // TODO: Read the file and cache it using the new system |
750 g_free(data); | 744 g_free(data); |
751 } | 745 } |
752 | 746 |
753 /* Read settings (both core and UI) */ | 747 /* Read settings (both core and UI) */ |
754 for (child = xmlnode_get_child(node, "settings"); child != NULL; | 748 for (child = xmlnode_get_child(node, "settings"); child != NULL; |
878 | 872 |
879 g_free(account->username); | 873 g_free(account->username); |
880 g_free(account->alias); | 874 g_free(account->alias); |
881 g_free(account->password); | 875 g_free(account->password); |
882 g_free(account->user_info); | 876 g_free(account->user_info); |
883 g_free(account->buddy_icon); | |
884 g_free(account->buddy_icon_path); | 877 g_free(account->buddy_icon_path); |
885 g_free(account->protocol_id); | 878 g_free(account->protocol_id); |
886 | 879 |
887 g_hash_table_destroy(account->settings); | 880 g_hash_table_destroy(account->settings); |
888 g_hash_table_destroy(account->ui_settings); | 881 g_hash_table_destroy(account->ui_settings); |
1314 account->user_info = g_strdup(user_info); | 1307 account->user_info = g_strdup(user_info); |
1315 | 1308 |
1316 schedule_accounts_save(); | 1309 schedule_accounts_save(); |
1317 } | 1310 } |
1318 | 1311 |
1319 void | |
1320 purple_account_set_buddy_icon(PurpleAccount *account, const char *icon) | |
1321 { | |
1322 g_return_if_fail(account != NULL); | |
1323 | |
1324 /* Delete an existing icon from the cache. */ | |
1325 if (account->buddy_icon != NULL && (icon == NULL || strcmp(account->buddy_icon, icon))) | |
1326 { | |
1327 const char *dirname = purple_buddy_icons_get_cache_dir(); | |
1328 | |
1329 if (g_file_test(account->buddy_icon, G_FILE_TEST_IS_REGULAR)) | |
1330 { | |
1331 /* The file exists. This is a full path. */ | |
1332 | |
1333 /* XXX: This is a hack so we only delete the file if it's | |
1334 * in the cache dir. Otherwise, people who upgrade (who | |
1335 * may have buddy icon filenames set outside of the cache | |
1336 * dir) could lose files. */ | |
1337 if (!strncmp(dirname, account->buddy_icon, strlen(dirname))) | |
1338 g_unlink(account->buddy_icon); | |
1339 } | |
1340 else | |
1341 { | |
1342 char *filename = g_build_filename(dirname, account->buddy_icon, NULL); | |
1343 g_unlink(filename); | |
1344 g_free(filename); | |
1345 } | |
1346 } | |
1347 | |
1348 g_free(account->buddy_icon); | |
1349 account->buddy_icon = g_strdup(icon); | |
1350 if (purple_account_is_connected(account)) | |
1351 { | |
1352 PurpleConnection *gc; | |
1353 PurplePluginProtocolInfo *prpl_info; | |
1354 | |
1355 gc = purple_account_get_connection(account); | |
1356 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
1357 | |
1358 if (prpl_info && prpl_info->set_buddy_icon) | |
1359 { | |
1360 char *cached_path = purple_buddy_icons_get_full_path(icon); | |
1361 prpl_info->set_buddy_icon(gc, cached_path); | |
1362 g_free(cached_path); | |
1363 } | |
1364 } | |
1365 | |
1366 schedule_accounts_save(); | |
1367 } | |
1368 | |
1369 void purple_account_set_buddy_icon_path(PurpleAccount *account, const char *path) | 1312 void purple_account_set_buddy_icon_path(PurpleAccount *account, const char *path) |
1370 { | 1313 { |
1371 g_return_if_fail(account != NULL); | 1314 g_return_if_fail(account != NULL); |
1372 | 1315 |
1373 g_free(account->buddy_icon_path); | 1316 g_free(account->buddy_icon_path); |
1736 purple_account_get_user_info(const PurpleAccount *account) | 1679 purple_account_get_user_info(const PurpleAccount *account) |
1737 { | 1680 { |
1738 g_return_val_if_fail(account != NULL, NULL); | 1681 g_return_val_if_fail(account != NULL, NULL); |
1739 | 1682 |
1740 return account->user_info; | 1683 return account->user_info; |
1741 } | |
1742 | |
1743 const char * | |
1744 purple_account_get_buddy_icon(const PurpleAccount *account) | |
1745 { | |
1746 g_return_val_if_fail(account != NULL, NULL); | |
1747 | |
1748 return account->buddy_icon; | |
1749 } | 1684 } |
1750 | 1685 |
1751 const char * | 1686 const char * |
1752 purple_account_get_buddy_icon_path(const PurpleAccount *account) | 1687 purple_account_get_buddy_icon_path(const PurpleAccount *account) |
1753 { | 1688 { |
2273 | 2208 |
2274 /* Remove this account's pounces */ | 2209 /* Remove this account's pounces */ |
2275 purple_pounce_destroy_all_by_account(account); | 2210 purple_pounce_destroy_all_by_account(account); |
2276 | 2211 |
2277 /* This will cause the deletion of an old buddy icon. */ | 2212 /* This will cause the deletion of an old buddy icon. */ |
2278 purple_account_set_buddy_icon(account, NULL); | 2213 purple_buddy_icons_set_account_icon(account, NULL, 0); |
2279 | 2214 |
2280 purple_account_destroy(account); | 2215 purple_account_destroy(account); |
2281 } | 2216 } |
2282 | 2217 |
2283 void | 2218 void |