comparison libpurple/account.c @ 16483:5e47b3427b28

propagate from branch 'im.pidgin.rlaager.gaim_migration' (head dcc40d46afbe3f87cc674e4fb1526ac722bc35cb) to branch 'im.pidgin.pidgin' (head 0ef5b6c44115778e329fd628324124f872f5253b)
author Sean Egan <seanegan@gmail.com>
date Fri, 27 Apr 2007 02:14:44 +0000
parents 08db93bbd798 3be560001d26
children 1d1ddf972ac8
comparison
equal deleted inserted replaced
16467:b2044e10915a 16483:5e47b3427b28
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 const char *dirname = purple_buddy_icons_get_cache_dir();
744 char *filename = g_build_filename(dirname, data, NULL);
745 gchar *contents;
746 gsize len;
747
748 if (g_file_get_contents(filename, &contents, &len, NULL))
749 {
750 purple_buddy_icons_set_account_icon(ret, (guchar *)contents, len);
751 }
752
753 g_free(filename);
750 g_free(data); 754 g_free(data);
751 } 755 }
752 756
753 /* Read settings (both core and UI) */ 757 /* Read settings (both core and UI) */
754 for (child = xmlnode_get_child(node, "settings"); child != NULL; 758 for (child = xmlnode_get_child(node, "settings"); child != NULL;
878 882
879 g_free(account->username); 883 g_free(account->username);
880 g_free(account->alias); 884 g_free(account->alias);
881 g_free(account->password); 885 g_free(account->password);
882 g_free(account->user_info); 886 g_free(account->user_info);
883 g_free(account->buddy_icon);
884 g_free(account->buddy_icon_path); 887 g_free(account->buddy_icon_path);
885 g_free(account->protocol_id); 888 g_free(account->protocol_id);
886 889
887 g_hash_table_destroy(account->settings); 890 g_hash_table_destroy(account->settings);
888 g_hash_table_destroy(account->ui_settings); 891 g_hash_table_destroy(account->ui_settings);
1318 account->user_info = g_strdup(user_info); 1321 account->user_info = g_strdup(user_info);
1319 1322
1320 schedule_accounts_save(); 1323 schedule_accounts_save();
1321 } 1324 }
1322 1325
1323 void
1324 purple_account_set_buddy_icon(PurpleAccount *account, const char *icon)
1325 {
1326 g_return_if_fail(account != NULL);
1327
1328 /* Delete an existing icon from the cache. */
1329 if (account->buddy_icon != NULL && (icon == NULL || strcmp(account->buddy_icon, icon)))
1330 {
1331 const char *dirname = purple_buddy_icons_get_cache_dir();
1332
1333 if (g_file_test(account->buddy_icon, G_FILE_TEST_IS_REGULAR))
1334 {
1335 /* The file exists. This is a full path. */
1336
1337 /* XXX: This is a hack so we only delete the file if it's
1338 * in the cache dir. Otherwise, people who upgrade (who
1339 * may have buddy icon filenames set outside of the cache
1340 * dir) could lose files. */
1341 if (!strncmp(dirname, account->buddy_icon, strlen(dirname)))
1342 g_unlink(account->buddy_icon);
1343 }
1344 else
1345 {
1346 char *filename = g_build_filename(dirname, account->buddy_icon, NULL);
1347 g_unlink(filename);
1348 g_free(filename);
1349 }
1350 }
1351
1352 g_free(account->buddy_icon);
1353 account->buddy_icon = g_strdup(icon);
1354 if (purple_account_is_connected(account))
1355 {
1356 PurpleConnection *gc;
1357 PurplePluginProtocolInfo *prpl_info;
1358
1359 gc = purple_account_get_connection(account);
1360 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
1361
1362 if (prpl_info && prpl_info->set_buddy_icon)
1363 {
1364 char *cached_path = purple_buddy_icons_get_full_path(icon);
1365 prpl_info->set_buddy_icon(gc, cached_path);
1366 g_free(cached_path);
1367 }
1368 }
1369
1370 schedule_accounts_save();
1371 }
1372
1373 void purple_account_set_buddy_icon_path(PurpleAccount *account, const char *path) 1326 void purple_account_set_buddy_icon_path(PurpleAccount *account, const char *path)
1374 { 1327 {
1375 g_return_if_fail(account != NULL); 1328 g_return_if_fail(account != NULL);
1376 1329
1377 g_free(account->buddy_icon_path); 1330 g_free(account->buddy_icon_path);
1740 purple_account_get_user_info(const PurpleAccount *account) 1693 purple_account_get_user_info(const PurpleAccount *account)
1741 { 1694 {
1742 g_return_val_if_fail(account != NULL, NULL); 1695 g_return_val_if_fail(account != NULL, NULL);
1743 1696
1744 return account->user_info; 1697 return account->user_info;
1745 }
1746
1747 const char *
1748 purple_account_get_buddy_icon(const PurpleAccount *account)
1749 {
1750 g_return_val_if_fail(account != NULL, NULL);
1751
1752 return account->buddy_icon;
1753 } 1698 }
1754 1699
1755 const char * 1700 const char *
1756 purple_account_get_buddy_icon_path(const PurpleAccount *account) 1701 purple_account_get_buddy_icon_path(const PurpleAccount *account)
1757 { 1702 {
2277 2222
2278 /* Remove this account's pounces */ 2223 /* Remove this account's pounces */
2279 purple_pounce_destroy_all_by_account(account); 2224 purple_pounce_destroy_all_by_account(account);
2280 2225
2281 /* This will cause the deletion of an old buddy icon. */ 2226 /* This will cause the deletion of an old buddy icon. */
2282 purple_account_set_buddy_icon(account, NULL); 2227 purple_buddy_icons_set_account_icon(account, NULL, 0);
2283 2228
2284 purple_account_destroy(account); 2229 purple_account_destroy(account);
2285 } 2230 }
2286 2231
2287 void 2232 void