# HG changeset patch # User Mark Huetsch # Date 1164881949 0 # Node ID 97ae8709d6dc3c022c752d59fd88637dbc0af428 # Parent 3d6f2568457cb0a68019f2eb1813f70060d744cd [gaim-migrate @ 17854] Added ability to keep track of non-cached buddy icons committer: Tailor Script diff -r 3d6f2568457c -r 97ae8709d6dc gtk/gtkaccount.c --- a/gtk/gtkaccount.c Thu Nov 30 05:56:29 2006 +0000 +++ b/gtk/gtkaccount.c Thu Nov 30 10:19:09 2006 +0000 @@ -118,6 +118,7 @@ GtkWidget *icon_hbox; GtkWidget *icon_check; GtkWidget *icon_entry; + char *cached_icon_path; char *icon_path; GtkWidget *icon_filesel; GtkWidget *icon_preview; @@ -190,15 +191,17 @@ } static void -set_dialog_icon(AccountPrefsDialog *dialog, gchar *new_icon_path) +set_dialog_icon(AccountPrefsDialog *dialog, gchar *new_cached_icon_path, gchar *new_icon_path) { char *filename; GdkPixbuf *pixbuf = NULL; + g_free(dialog->cached_icon_path); g_free(dialog->icon_path); + dialog->cached_icon_path = new_cached_icon_path; dialog->icon_path = new_icon_path; - filename = gaim_buddy_icons_get_full_path(dialog->icon_path); + filename = gaim_buddy_icons_get_full_path(dialog->cached_icon_path); if (filename != NULL) { pixbuf = gdk_pixbuf_new_from_file(filename, NULL); g_free(filename); @@ -298,7 +301,7 @@ dialog = data; if (filename != NULL) - set_dialog_icon(dialog, gaim_gtk_convert_buddy_icon(dialog->plugin, filename)); + set_dialog_icon(dialog, gaim_gtk_convert_buddy_icon(dialog->plugin, filename), g_strdup(filename)); dialog->icon_filesel = NULL; } @@ -313,7 +316,7 @@ static void icon_reset_cb(GtkWidget *button, AccountPrefsDialog *dialog) { - set_dialog_icon(dialog, NULL); + set_dialog_icon(dialog, NULL, NULL); } static void @@ -338,7 +341,7 @@ } if ((rtmp = strchr(tmp, '\r')) || (rtmp = strchr(tmp, '\n'))) *rtmp = '\0'; - set_dialog_icon(dialog, gaim_gtk_convert_buddy_icon(dialog->plugin, tmp)); + set_dialog_icon(dialog, gaim_gtk_convert_buddy_icon(dialog->plugin, tmp), g_strdup(tmp)); g_free(tmp); } gtk_drag_finish(dc, TRUE, FALSE, t); @@ -586,6 +589,7 @@ gtk_widget_show(dialog->icon_entry); /* TODO: Uh, isn't this next line pretty useless? */ gaim_set_accessible_label (dialog->icon_entry, label); + dialog->cached_icon_path = NULL; dialog->icon_path = NULL; vbox2 = gtk_vbox_new(FALSE, 0); @@ -617,12 +621,15 @@ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->icon_check), !gaim_account_get_ui_bool(dialog->account, GAIM_GTK_UI, "use-global-buddyicon", TRUE)); + set_dialog_icon(dialog, + g_strdup(gaim_account_get_ui_string(dialog->account, + GAIM_GTK_UI, "non-global-buddyicon-cached-path", NULL)), + g_strdup(gaim_account_get_ui_string(dialog->account, + GAIM_GTK_UI, "non-global-buddyicon-path", NULL))); + } else { + set_dialog_icon(dialog, NULL, NULL); } - set_dialog_icon(dialog, dialog->account ? - g_strdup(gaim_account_get_ui_string(dialog->account, - GAIM_GTK_UI, "non-global-buddyicon", NULL)) : NULL); - if (!dialog->prpl_info || (!(dialog->prpl_info->options & OPT_PROTO_MAIL_CHECK) && (dialog->prpl_info->icon_spec.format == NULL))) { @@ -1061,20 +1068,23 @@ g_list_free(dialog->protocol_opt_entries); g_free(dialog->protocol_id); - if (dialog->icon_path != NULL) + if (dialog->cached_icon_path != NULL) { - const char *icon = gaim_account_get_ui_string(dialog->account, GAIM_GTK_UI, "non-global-buddyicon", NULL); - if (dialog->icon_path != NULL && (icon == NULL || strcmp(dialog->icon_path, icon))) + const char *icon = gaim_account_get_ui_string(dialog->account, GAIM_GTK_UI, "non-global-buddyicon-cached-path", NULL); + if (dialog->cached_icon_path != NULL && (icon == NULL || strcmp(dialog->cached_icon_path, icon))) { /* The user set an icon, which would've been cached by convert_buddy_icon, * but didn't save the changes. Delete the cache file. */ - char *filename = g_build_filename(gaim_buddy_icons_get_cache_dir(), dialog->icon_path, NULL); + char *filename = g_build_filename(gaim_buddy_icons_get_cache_dir(), dialog->cached_icon_path, NULL); g_unlink(filename); g_free(filename); } + g_free(dialog->cached_icon_path); + } + + if (dialog->cached_icon_path != NULL) g_free(dialog->icon_path); - } if (dialog->icon_filesel) gtk_widget_destroy(dialog->icon_filesel); @@ -1136,14 +1146,18 @@ icon_change = TRUE; } gaim_account_set_ui_bool(account, GAIM_GTK_UI, "use-global-buddyicon", !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->icon_check))); - gaim_account_set_ui_string(account, GAIM_GTK_UI, "non-global-buddyicon", dialog->icon_path); + gaim_account_set_ui_string(account, GAIM_GTK_UI, "non-global-buddyicon-cached-path", dialog->cached_icon_path); + gaim_account_set_ui_string(account, GAIM_GTK_UI, "non-global-buddyicon-path", dialog->icon_path); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->icon_check))) { - gaim_account_set_buddy_icon(account, dialog->icon_path); + gaim_account_set_buddy_icon_path(account, dialog->icon_path); + gaim_account_set_buddy_icon(account, dialog->cached_icon_path); } else if (gaim_prefs_get_string("/gaim/gtk/accounts/buddyicon") && icon_change) { - char *icon = gaim_gtk_convert_buddy_icon(dialog->plugin, gaim_prefs_get_string("/gaim/gtk/accounts/buddyicon")); + const char *filename = gaim_prefs_get_string("/gaim/gtk/accounts/buddyicon"); + char *icon = gaim_gtk_convert_buddy_icon(dialog->plugin, gaim_prefs_get_string(filename)); + gaim_account_set_buddy_icon_path(account, filename); gaim_account_set_buddy_icon(account, icon); g_free(icon); } diff -r 3d6f2568457c -r 97ae8709d6dc gtk/gtkstatusbox.c --- a/gtk/gtkstatusbox.c Thu Nov 30 05:56:29 2006 +0000 +++ b/gtk/gtkstatusbox.c Thu Nov 30 10:19:09 2006 +0000 @@ -1228,7 +1228,8 @@ if (filename) icon = gaim_gtk_convert_buddy_icon(plug, filename); gaim_account_set_ui_bool(box->account, GAIM_GTK_UI, "use-global-buddyicon", (filename != NULL)); - gaim_account_set_ui_string(box->account, GAIM_GTK_UI, "non-global-buddyicon", icon); + gaim_account_set_ui_string(box->account, GAIM_GTK_UI, "non-global-buddyicon-cached-path", icon); + gaim_account_set_buddy_icon_path(box->account, filename); gaim_account_set_buddy_icon(box->account, icon); g_free(icon); } @@ -1246,6 +1247,7 @@ char *icon = NULL; if (filename) icon = gaim_gtk_convert_buddy_icon(plug, filename); + gaim_account_set_buddy_icon_path(account, filename); gaim_account_set_buddy_icon(account, icon); g_free(icon); } diff -r 3d6f2568457c -r 97ae8709d6dc libgaim/account.c --- a/libgaim/account.c Thu Nov 30 05:56:29 2006 +0000 +++ b/libgaim/account.c Thu Nov 30 10:19:09 2006 +0000 @@ -872,6 +872,8 @@ g_free(account->alias); g_free(account->password); g_free(account->user_info); + g_free(account->buddy_icon); + g_free(account->buddy_icon_path); g_free(account->protocol_id); g_hash_table_destroy(account->settings); @@ -1281,15 +1283,25 @@ if (prpl_info && prpl_info->set_buddy_icon) { - char *filename = gaim_buddy_icons_get_full_path(icon); - prpl_info->set_buddy_icon(gc, filename); - g_free(filename); + char *cached_path = gaim_buddy_icons_get_full_path(icon); + prpl_info->set_buddy_icon(gc, cached_path); + g_free(cached_path); } } schedule_accounts_save(); } +void gaim_account_set_buddy_icon_path(GaimAccount *account, const char *path) +{ + g_return_if_fail(account != NULL); + + g_free(account->buddy_icon_path); + account->buddy_icon_path = g_strdup(path); + + schedule_accounts_save(); +} + void gaim_account_set_protocol_id(GaimAccount *account, const char *protocol_id) { @@ -1663,6 +1675,14 @@ } const char * +gaim_account_get_buddy_icon_path(const GaimAccount *account) +{ + g_return_val_if_fail(account != NULL, NULL); + + return account->buddy_icon_path; +} + +const char * gaim_account_get_protocol_id(const GaimAccount *account) { g_return_val_if_fail(account != NULL, NULL); diff -r 3d6f2568457c -r 97ae8709d6dc libgaim/account.h --- a/libgaim/account.h Thu Nov 30 05:56:29 2006 +0000 +++ b/libgaim/account.h Thu Nov 30 10:19:09 2006 +0000 @@ -64,7 +64,8 @@ char *password; /**< The account password. */ char *user_info; /**< User information. */ - char *buddy_icon; /**< The buddy icon. */ + char *buddy_icon; /**< The buddy icon's cached path. */ + char *buddy_icon_path; /**< The buddy icon's non-cached path. */ gboolean remember_pass; /**< Remember the password. */ @@ -251,6 +252,14 @@ void gaim_account_set_buddy_icon(GaimAccount *account, const char *icon); /** + * Sets the account's buddy icon path. + * + * @param account The account. + * @param info The buddy icon non-cached path. + */ +void gaim_account_set_buddy_icon_path(GaimAccount *account, const char *path); + +/** * Sets the account's protocol ID. * * @param account The account. @@ -485,6 +494,15 @@ const char *gaim_account_get_buddy_icon(const GaimAccount *account); /** + * Gets the account's buddy icon path. + * + * @param account The account. + * + * @return The buddy icon's non-cached path. + */ +const char *gaim_account_get_buddy_icon_path(const GaimAccount *account); + +/** * Returns the account's protocol ID. * * @param account The account. diff -r 3d6f2568457c -r 97ae8709d6dc libgaim/buddyicon.c --- a/libgaim/buddyicon.c Thu Nov 30 05:56:29 2006 +0000 +++ b/libgaim/buddyicon.c Thu Nov 30 10:19:09 2006 +0000 @@ -77,6 +77,7 @@ gaim_buddy_icon_ref(icon); gaim_buddy_icon_set_data(icon, icon_data, icon_len); + gaim_buddy_icon_set_path(icon, NULL); /* gaim_buddy_icon_set_data() makes blist.c or * conversation.c, or both, take a reference. @@ -134,6 +135,7 @@ g_free(icon->username); g_free(icon->data); + g_free(icon->path); GAIM_DBUS_UNREGISTER_POINTER(icon); g_free(icon); } @@ -339,6 +341,15 @@ gaim_buddy_icon_update(icon); } +void +gaim_buddy_icon_set_path(GaimBuddyIcon *icon, const gchar *path) +{ + g_return_if_fail(icon != NULL); + + g_free(icon->path); + icon->path = (path != NULL ? g_strdup(path) : NULL); +} + GaimAccount * gaim_buddy_icon_get_account(const GaimBuddyIcon *icon) { @@ -367,6 +378,14 @@ } const char * +gaim_buddy_icon_get_path(GaimBuddyIcon *icon) +{ + g_return_val_if_fail(icon != NULL, NULL); + + return icon->path; +} + +const char * gaim_buddy_icon_get_type(const GaimBuddyIcon *icon) { const void *data; @@ -394,7 +413,7 @@ void gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username, - void *icon_data, size_t icon_len) + void *icon_data, size_t icon_len) { g_return_if_fail(account != NULL); g_return_if_fail(username != NULL); diff -r 3d6f2568457c -r 97ae8709d6dc libgaim/buddyicon.h --- a/libgaim/buddyicon.h Thu Nov 30 05:56:29 2006 +0000 +++ b/libgaim/buddyicon.h Thu Nov 30 10:19:09 2006 +0000 @@ -38,6 +38,7 @@ void *data; /**< The buddy icon data. */ size_t len; /**< The length of the buddy icon data. */ + char *path; /**< The buddy icon's non-cached path. */ int ref_count; /**< The buddy icon reference count. */ }; @@ -62,7 +63,7 @@ * @return The buddy icon structure. */ GaimBuddyIcon *gaim_buddy_icon_new(GaimAccount *account, const char *username, - void *icon_data, size_t icon_len); + void *icon_data, size_t icon_len); /** * Destroys a buddy icon structure. @@ -142,6 +143,14 @@ void gaim_buddy_icon_set_data(GaimBuddyIcon *icon, void *data, size_t len); /** + * Sets the buddy icon's path. + * + * @param icon The buddy icon. + * @param path The buddy icon's non-cached path. + */ +void gaim_buddy_icon_set_path(GaimBuddyIcon *icon, const gchar *path); + +/** * Returns the buddy icon's account. * * @param icon The buddy icon. @@ -170,6 +179,15 @@ const guchar *gaim_buddy_icon_get_data(const GaimBuddyIcon *icon, size_t *len); /** + * Returns the buddy icon's path. + * + * @param icon The buddy icon. + * + * @preturn The buddy icon's non-cached path. + */ +const gchar *gaim_buddy_icon_get_path(GaimBuddyIcon *icon); + +/** * Returns an extension corresponding to the buddy icon's file type. * * @param icon The buddy icon. @@ -192,9 +210,11 @@ * @param username The username of the user. * @param icon_data The icon data. * @param icon_len The length of the icon data. + * + * @return The buddy icon set, or NULL if no icon was set. */ void gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username, - void *icon_data, size_t icon_len); + void *icon_data, size_t icon_len); /** * Returns the buddy icon information for a user. diff -r 3d6f2568457c -r 97ae8709d6dc libgaim/prpl.h --- a/libgaim/prpl.h Thu Nov 30 05:56:29 2006 +0000 +++ b/libgaim/prpl.h Thu Nov 30 10:19:09 2006 +0000 @@ -276,7 +276,7 @@ const char *(*normalize)(const GaimAccount *, const char *); - void (*set_buddy_icon)(GaimConnection *, const char *filename); + void (*set_buddy_icon)(GaimConnection *, const char *cached_path); void (*remove_group)(GaimConnection *gc, GaimGroup *group);