comparison src/gtkaccount.c @ 11303:10066662176a

[gaim-migrate @ 13503] For accounts, store only the basename of a buddy icon cache file. Everyone please make sure buddy icons still work for you. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 18 Aug 2005 20:49:58 +0000
parents ee1b890760be
children 74e30ef571ce
comparison
equal deleted inserted replaced
11302:fc17554c32c5 11303:10066662176a
194 194
195 return hbox; 195 return hbox;
196 } 196 }
197 197
198 static void 198 static void
199 delete_buddy_icon(const char *filename) 199 set_dialog_icon(AccountPrefsDialog *dialog)
200 { 200 {
201 const char *dirname; 201 char *filename = gaim_buddy_icons_get_full_path(dialog>icon_path);
202 202 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry), filename);
203 if (filename == NULL) 203 g_free(filename);
204 return;
205
206 /* XXX: This is a hack so we only delete the file if it's
207 * in the cache dir. Otherwise, people who upgrade (who
208 * may have buddy icon filenames set outside of the cache
209 * dir) could lose files. */
210 dirname = gaim_buddy_icons_get_cache_dir();
211 if (!strncmp(dirname, filename, strlen(dirname)))
212 g_unlink(filename);
213 } 204 }
214 205
215 static void 206 static void
216 set_account_protocol_cb(GtkWidget *item, const char *id, 207 set_account_protocol_cb(GtkWidget *item, const char *id,
217 AccountPrefsDialog *dialog) 208 AccountPrefsDialog *dialog)
306 #endif /* FILECHOOSER */ 297 #endif /* FILECHOOSER */
307 298
308 if (dialog->icon_path) 299 if (dialog->icon_path)
309 g_free(dialog->icon_path); 300 g_free(dialog->icon_path);
310 dialog->icon_path = convert_buddy_icon(dialog->plugin, filename); 301 dialog->icon_path = convert_buddy_icon(dialog->plugin, filename);
311 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry), dialog->icon_path); 302 set_dialog_icon(dialog);
312 gtk_widget_show(dialog->icon_entry); 303 gtk_widget_show(dialog->icon_entry);
313 304
314 gtk_widget_destroy(dialog->icon_filesel); 305 gtk_widget_destroy(dialog->icon_filesel);
315 dialog->icon_filesel = NULL; 306 dialog->icon_filesel = NULL;
316 g_free(filename); 307 g_free(filename);
501 if ((rtmp = strchr(tmp, '\r')) || (rtmp = strchr(tmp, '\n'))) 492 if ((rtmp = strchr(tmp, '\r')) || (rtmp = strchr(tmp, '\n')))
502 *rtmp = '\0'; 493 *rtmp = '\0';
503 if (dialog->icon_path) 494 if (dialog->icon_path)
504 g_free(dialog->icon_path); 495 g_free(dialog->icon_path);
505 dialog->icon_path = convert_buddy_icon(dialog->plugin, tmp); 496 dialog->icon_path = convert_buddy_icon(dialog->plugin, tmp);
506 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry), dialog->icon_path); 497 set_dialog_icon(dialog);
507 gtk_widget_show(dialog->icon_entry); 498 gtk_widget_show(dialog->icon_entry);
508 g_free(tmp); 499 g_free(tmp);
509 } 500 }
510 gtk_drag_finish(dc, TRUE, FALSE, t); 501 gtk_drag_finish(dc, TRUE, FALSE, t);
511 } 502 }
547 #endif 538 #endif
548 #endif 539 #endif
549 const char *dirname = gaim_buddy_icons_get_cache_dir(); 540 const char *dirname = gaim_buddy_icons_get_cache_dir();
550 char *random = g_strdup_printf("%x", g_random_int()); 541 char *random = g_strdup_printf("%x", g_random_int());
551 char *filename = g_build_filename(dirname, random, NULL); 542 char *filename = g_build_filename(dirname, random, NULL);
552 g_free(random);
553 543
554 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { 544 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
555 gaim_debug_info("buddyicon", "Creating icon cache directory.\n"); 545 gaim_debug_info("buddyicon", "Creating icon cache directory.\n");
556 546
557 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) { 547 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) {
559 "Unable to create directory %s: %s\n", 549 "Unable to create directory %s: %s\n",
560 dirname, strerror(errno)); 550 dirname, strerror(errno));
561 #if GTK_CHECK_VERSION(2,2,0) 551 #if GTK_CHECK_VERSION(2,2,0)
562 g_strfreev(prpl_formats); 552 g_strfreev(prpl_formats);
563 #endif 553 #endif
554 g_free(random);
564 g_free(filename); 555 g_free(filename);
565 return NULL; 556 return NULL;
566 } 557 }
567 } 558 }
568 559
607 /* Copy the image to the cache folder as "filename". */ 598 /* Copy the image to the cache folder as "filename". */
608 599
609 if (!g_file_get_contents(path, &contents, &length, NULL) || 600 if (!g_file_get_contents(path, &contents, &length, NULL) ||
610 (image = g_fopen(filename, "wb")) == NULL) 601 (image = g_fopen(filename, "wb")) == NULL)
611 { 602 {
603 g_free(random);
612 g_free(filename); 604 g_free(filename);
613 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0) 605 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0)
614 g_object_unref(G_OBJECT(pixbuf)); 606 g_object_unref(G_OBJECT(pixbuf));
615 #endif 607 #endif
616 return NULL; 608 return NULL;
619 if (fwrite(contents, 1, length, image) != length) 611 if (fwrite(contents, 1, length, image) != length)
620 { 612 {
621 fclose(image); 613 fclose(image);
622 g_unlink(filename); 614 g_unlink(filename);
623 615
616 g_free(random);
624 g_free(filename); 617 g_free(filename);
625 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0) 618 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0)
626 g_object_unref(G_OBJECT(pixbuf)); 619 g_object_unref(G_OBJECT(pixbuf));
627 #endif 620 #endif
628 return NULL; 621 return NULL;
631 624
632 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0) 625 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0)
633 g_object_unref(G_OBJECT(pixbuf)); 626 g_object_unref(G_OBJECT(pixbuf));
634 #endif 627 #endif
635 628
636 return filename; 629 g_free(filename);
630 return random;
637 } 631 }
638 #if GTK_CHECK_VERSION(2,2,0) 632 #if GTK_CHECK_VERSION(2,2,0)
639 else 633 else
640 { 634 {
641 int i; 635 int i;
673 GDK_INTERP_HYPER); 667 GDK_INTERP_HYPER);
674 g_object_unref(G_OBJECT(pixbuf)); 668 g_object_unref(G_OBJECT(pixbuf));
675 pixbuf = scale; 669 pixbuf = scale;
676 } 670 }
677 if (error) { 671 if (error) {
672 g_free(random);
678 g_free(filename); 673 g_free(filename);
679 gaim_debug_error("buddyicon", "Could not open icon for conversion: %s\n", error->message); 674 gaim_debug_error("buddyicon", "Could not open icon for conversion: %s\n", error->message);
680 g_error_free(error); 675 g_error_free(error);
681 g_strfreev(prpl_formats); 676 g_strfreev(prpl_formats);
682 return NULL; 677 return NULL;
693 error = NULL; 688 error = NULL;
694 } 689 }
695 g_strfreev(prpl_formats); 690 g_strfreev(prpl_formats);
696 if (!error) { 691 if (!error) {
697 g_object_unref(G_OBJECT(pixbuf)); 692 g_object_unref(G_OBJECT(pixbuf));
698 return filename; 693 g_free(filename);
694 return random;
699 } else { 695 } else {
700 gaim_debug_error("buddyicon", "Could not convert icon to usable format: %s\n", error->message); 696 gaim_debug_error("buddyicon", "Could not convert icon to usable format: %s\n", error->message);
701 g_error_free(error); 697 g_error_free(error);
702 } 698 }
699 g_free(random);
703 g_free(filename); 700 g_free(filename);
704 g_object_unref(G_OBJECT(pixbuf)); 701 g_object_unref(G_OBJECT(pixbuf));
705 } 702 }
706 return NULL; 703 return NULL;
707 #endif 704 #endif
936 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->new_mail_check), 933 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->new_mail_check),
937 gaim_account_get_check_mail(dialog->account)); 934 gaim_account_get_check_mail(dialog->account));
938 935
939 if (gaim_account_get_buddy_icon(dialog->account) != NULL) { 936 if (gaim_account_get_buddy_icon(dialog->account) != NULL) {
940 dialog->icon_path = g_strdup(gaim_account_get_buddy_icon(dialog->account)); 937 dialog->icon_path = g_strdup(gaim_account_get_buddy_icon(dialog->account));
941 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry),dialog->icon_path); 938 set_dialog_icon(dialog);
942 } 939 }
943 } 940 }
944 941
945 if (!dialog->prpl_info || 942 if (!dialog->prpl_info ||
946 (!(dialog->prpl_info->options & OPT_PROTO_MAIL_CHECK) && 943 (!(dialog->prpl_info->options & OPT_PROTO_MAIL_CHECK) &&
1382 1379
1383 if (dialog->protocol_id != NULL) 1380 if (dialog->protocol_id != NULL)
1384 g_free(dialog->protocol_id); 1381 g_free(dialog->protocol_id);
1385 1382
1386 if (dialog->icon_path != NULL) 1383 if (dialog->icon_path != NULL)
1384 {
1385 const char *icon = gaim_account_get_buddy_icon(dialog->account);
1386 if (dialog->icon_path != NULL && (icon == NULL || strcmp(dialog->icon_path, icon)))
1387 {
1388 /* The user set an icon, which would've been cached by convert_buddy_icon,
1389 * but didn't save the changes. Delete the cache file. */
1390 char *filename = g_build_filename(gaim_buddy_icons_get_cache_dir(), dialog->icon_path, NULL);
1391 g_unlink(filename);
1392 g_free(filename);
1393 }
1394
1387 g_free(dialog->icon_path); 1395 g_free(dialog->icon_path);
1396 }
1388 1397
1389 if (dialog->icon_filesel) 1398 if (dialog->icon_filesel)
1390 gtk_widget_destroy(dialog->icon_filesel); 1399 gtk_widget_destroy(dialog->icon_filesel);
1391 1400
1392 g_free(dialog); 1401 g_free(dialog);
1434 gaim_account_set_alias(dialog->account, value); 1443 gaim_account_set_alias(dialog->account, value);
1435 else 1444 else
1436 gaim_account_set_alias(dialog->account, NULL); 1445 gaim_account_set_alias(dialog->account, NULL);
1437 1446
1438 /* Buddy Icon */ 1447 /* Buddy Icon */
1439 value = gaim_account_get_buddy_icon(dialog->account); 1448 gaim_account_set_buddy_icon(dialog->account, dialog->icon_path);
1440 if (value == NULL || dialog->icon_path == NULL || strcmp(value, dialog->icon_path)) {
1441 delete_buddy_icon(value);
1442 gaim_account_set_buddy_icon(dialog->account, dialog->icon_path);
1443 }
1444 1449
1445 /* Remember Password */ 1450 /* Remember Password */
1446 gaim_account_set_remember_password(dialog->account, 1451 gaim_account_set_remember_password(dialog->account,
1447 gtk_toggle_button_get_active( 1452 gtk_toggle_button_get_active(
1448 GTK_TOGGLE_BUTTON(dialog->remember_pass_check))); 1453 GTK_TOGGLE_BUTTON(dialog->remember_pass_check)));