comparison src/gtkaccount.c @ 9555:a79e03ef63f6

[gaim-migrate @ 10391] Buddy icon scaling changes. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sun, 18 Jul 2004 14:57:55 +0000
parents 8cd47267c5bd
children bc910eb2679f
comparison
equal deleted inserted replaced
9554:8b2451878e26 9555:a79e03ef63f6
156 static AccountsWindow *accounts_window = NULL; 156 static AccountsWindow *accounts_window = NULL;
157 157
158 static void add_account(AccountsWindow *dialog, GaimAccount *account); 158 static void add_account(AccountsWindow *dialog, GaimAccount *account);
159 static void set_account(GtkListStore *store, GtkTreeIter *iter, 159 static void set_account(GtkListStore *store, GtkTreeIter *iter,
160 GaimAccount *account); 160 GaimAccount *account);
161 static char*
162 convert_buddy_icon(GaimAccount *account, const char *path);
161 163
162 static char * 164 static char *
163 proto_name(const char *id) 165 proto_name(const char *id)
164 { 166 {
165 GaimPlugin *p = gaim_find_prpl(id); 167 GaimPlugin *p = gaim_find_prpl(id);
279 } 281 }
280 #endif /* FILECHOOSER */ 282 #endif /* FILECHOOSER */
281 283
282 if (dialog->icon_path) 284 if (dialog->icon_path)
283 g_free(dialog->icon_path); 285 g_free(dialog->icon_path);
284 dialog->icon_path = g_strdup(filename); 286 dialog->icon_path = convert_buddy_icon(dialog->account, filename);
285 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry), filename); 287 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry), dialog->icon_path);
286 gtk_widget_show(dialog->icon_entry); 288 gtk_widget_show(dialog->icon_entry);
287 289
288 gtk_widget_destroy(dialog->icon_filesel); 290 gtk_widget_destroy(dialog->icon_filesel);
289 dialog->icon_filesel = NULL; 291 dialog->icon_filesel = NULL;
290 } 292 }
291 293
292 static void 294 static void
293 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ 295 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
294 icon_preview_change_cb(GtkFileChooser *widget, AccountPrefsDialog *dialog) 296 icon_preview_change_cb(GtkFileChooser *widget, AccountPrefsDialog *dialog)
295 #else /* FILECHOOSER */ 297 #else /* FILECHOOSER */
471 } 473 }
472 if ((rtmp = strchr(tmp, '\r')) || (rtmp = strchr(tmp, '\n'))) 474 if ((rtmp = strchr(tmp, '\r')) || (rtmp = strchr(tmp, '\n')))
473 *rtmp = '\0'; 475 *rtmp = '\0';
474 if (dialog->icon_path) 476 if (dialog->icon_path)
475 g_free(dialog->icon_path); 477 g_free(dialog->icon_path);
476 dialog->icon_path = g_strdup(tmp); 478 dialog->icon_path = convert_buddy_icon(dialog->account, tmp);
477 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry), tmp); 479 gtk_image_set_from_file(GTK_IMAGE(dialog->icon_entry), dialog->icon_path);
478 gtk_widget_show(dialog->icon_entry); 480 gtk_widget_show(dialog->icon_entry);
479 g_free(tmp); 481 g_free(tmp);
480 } 482 }
481 gtk_drag_finish(dc, TRUE, FALSE, t); 483 gtk_drag_finish(dc, TRUE, FALSE, t);
482 } 484 }
498 return TRUE; 500 return TRUE;
499 return FALSE; 501 return FALSE;
500 } 502 }
501 #endif 503 #endif
502 504
503 static void 505 static char*
504 convert_and_set_buddy_icon(GaimAccount *account, const char *path) 506 convert_buddy_icon(GaimAccount *account, const char *path)
505 { 507 {
506 #if GTK_CHECK_VERSION(2,2,0) 508 #if GTK_CHECK_VERSION(2,2,0)
507 int width, height; 509 int width, height;
508 char **pixbuf_formats = NULL; 510 char **pixbuf_formats = NULL;
509 GdkPixbufFormat *format; 511 GdkPixbufFormat *format;
542 (prpl_info->icon_spec.min_width <= width && 544 (prpl_info->icon_spec.min_width <= width &&
543 prpl_info->icon_spec.max_width >= width && 545 prpl_info->icon_spec.max_width >= width &&
544 prpl_info->icon_spec.min_height <= height && 546 prpl_info->icon_spec.min_height <= height &&
545 prpl_info->icon_spec.max_height >= height))) { /* The icon is the correct size */ 547 prpl_info->icon_spec.max_height >= height))) { /* The icon is the correct size */
546 #endif 548 #endif
547 gaim_account_set_buddy_icon(account, path); 549 return g_strdup(path);
548 #if GTK_CHECK_VERSION(2,2,0) 550 #if GTK_CHECK_VERSION(2,2,0)
549 } else { 551 } else {
550 int i; 552 int i;
551 GError *error = NULL; 553 GError *error = NULL;
552 GdkPixbuf *scale; 554 GdkPixbuf *scale;
575 if (error) { 577 if (error) {
576 g_free(filename); 578 g_free(filename);
577 g_free(random); 579 g_free(random);
578 gaim_debug_error("buddyicon", "Could not open icon for conversion: %s\n", error->message); 580 gaim_debug_error("buddyicon", "Could not open icon for conversion: %s\n", error->message);
579 g_error_free(error); 581 g_error_free(error);
580 return; 582 return NULL;
581 } 583 }
582 for (i = 0; prpl_formats[i]; i++) { 584 for (i = 0; prpl_formats[i]; i++) {
583 gaim_debug_info("buddyicon", "Converting buddy icon to %s as %s\n", prpl_formats[i], filename); 585 gaim_debug_info("buddyicon", "Converting buddy icon to %s as %s\n", prpl_formats[i], filename);
584 if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == FALSE) 586 if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == FALSE)
585 break; 587 break;
586 } 588 }
587 if (!error) { 589 if (!error) {
588 gaim_account_set_buddy_icon(account, filename); 590 g_free(random);
591 g_object_unref(G_OBJECT(pixbuf));
592 return filename;
589 } else { 593 } else {
590 gaim_debug_error("buddyicon", "Could not convert icon to usable format: %s\n", error->message); 594 gaim_debug_error("buddyicon", "Could not convert icon to usable format: %s\n", error->message);
591 g_error_free(error); 595 g_error_free(error);
592 } 596 }
593 g_free(filename); 597 g_free(filename);
594 g_free(random); 598 g_free(random);
595 g_object_unref(G_OBJECT(pixbuf)); 599 g_object_unref(G_OBJECT(pixbuf));
596 } 600 }
601 return NULL;
597 #endif 602 #endif
598 } 603 }
599 604
600 static void 605 static void
601 add_login_options(AccountPrefsDialog *dialog, GtkWidget *parent) 606 add_login_options(AccountPrefsDialog *dialog, GtkWidget *parent)
1328 else 1333 else
1329 gaim_account_set_alias(dialog->account, NULL); 1334 gaim_account_set_alias(dialog->account, NULL);
1330 1335
1331 /* Buddy Icon */ 1336 /* Buddy Icon */
1332 value = dialog->icon_path; 1337 value = dialog->icon_path;
1338 gaim_account_set_buddy_icon(dialog->account, value);
1333 1339
1334 if (dialog->prpl_info &&
1335 (dialog->prpl_info->icon_spec.format) &&
1336 value != NULL) {
1337 convert_and_set_buddy_icon(dialog->account, value);
1338 } else {
1339 gaim_account_set_buddy_icon(dialog->account, NULL);
1340 }
1341 /* Remember Password */ 1340 /* Remember Password */
1342 gaim_account_set_remember_password(dialog->account, 1341 gaim_account_set_remember_password(dialog->account,
1343 gtk_toggle_button_get_active( 1342 gtk_toggle_button_get_active(
1344 GTK_TOGGLE_BUTTON(dialog->remember_pass_check))); 1343 GTK_TOGGLE_BUTTON(dialog->remember_pass_check)));
1345 1344