# HG changeset patch # User Sean Egan # Date 1055207366 0 # Node ID bd0d0e89cac37777cf702ddfc480863e44012f5e # Parent 729e688fd2e7432012737ad865590a420305fb6c [gaim-migrate @ 6256] You can once again set your buddy icon. Of course, you* haven't been using CVS, so you've always been able to set your buddy icon. * Gaim developers not applicable committer: Tailor Script diff -r 729e688fd2e7 -r bd0d0e89cac3 src/gtkaccount.c --- a/src/gtkaccount.c Mon Jun 09 20:34:58 2003 +0000 +++ b/src/gtkaccount.c Tue Jun 10 01:09:26 2003 +0000 @@ -21,6 +21,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include +#include +#include + #include #include "gtkaccount.h" @@ -113,7 +117,10 @@ GtkWidget *new_mail_check; GtkWidget *buddy_icon_hbox; GtkWidget *buddy_icon_entry; - + GtkWidget *buddy_icon_filesel; + GtkWidget *buddy_icon_preview; + GtkWidget *buddy_icon_text; + /* Protocol Options */ GtkWidget *protocol_frame; GtkWidget *register_check; @@ -198,7 +205,103 @@ return; gtk_widget_set_sensitive(dialog->ok_button, - *gtk_entry_get_text(entry) != '\0'); + *gtk_entry_get_text(entry) != '\0'); +} + +static void buddy_icon_filesel_delete_cb (GtkWidget *w, AccountPrefsDialog *dialog) +{ + gtk_widget_destroy(dialog->buddy_icon_filesel); + dialog->buddy_icon_filesel = NULL; +} + +static void buddy_icon_filesel_choose (GtkWidget *w, AccountPrefsDialog *dialog) +{ + const char *filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)); + if (dialog->account) + gaim_account_set_buddy_icon(dialog->account, filename); + gtk_entry_set_text(GTK_ENTRY(dialog->buddy_icon_entry), filename); + gtk_widget_destroy(dialog->buddy_icon_filesel); +} + +static void buddy_icon_preview_change_cb(GtkTreeSelection *sel, AccountPrefsDialog *dialog) +{ + GdkPixbuf *pixbuf, *scale; + int height, width; + char *basename, *markup, *size; + struct stat st; + + const char *filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)); + if (!filename || stat(filename, &st)) + return; + + pixbuf = gdk_pixbuf_new_from_file(filename, NULL); + if (!pixbuf) { + gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->buddy_icon_preview), NULL); + gtk_label_set_markup(GTK_LABEL(dialog->buddy_icon_text), ""); + return; + } + + width = gdk_pixbuf_get_width(pixbuf); + height = gdk_pixbuf_get_height(pixbuf); + basename = g_path_get_basename(filename); + size = gaim_get_size_string(st.st_size); + markup = g_strdup_printf(_("File: %s\nFile size: %s\nImage size: %dx%d"), + basename, size, width, height); + scale = gdk_pixbuf_scale_simple(pixbuf, width * 50 / height, 50, GDK_INTERP_BILINEAR); + gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->buddy_icon_preview), scale); + gtk_label_set_markup(GTK_LABEL(dialog->buddy_icon_text), markup); + + g_object_unref(G_OBJECT(pixbuf)); + g_object_unref(G_OBJECT(scale)); + g_free(basename); + g_free(size); +} + +static void buddy_icon_select_cb(GtkWidget *button, AccountPrefsDialog *dialog) +{ + GtkWidget *hbox; + GtkWidget *tv; + GtkTreeSelection *sel; + + if (dialog->buddy_icon_filesel) { + gdk_window_show(GDK_WINDOW(dialog->buddy_icon_filesel)); + return; + } + + dialog->buddy_icon_filesel = gtk_file_selection_new(_("Buddy Icon")); + dialog->buddy_icon_preview = gtk_image_new(); + dialog->buddy_icon_text = gtk_label_new(NULL); + gtk_widget_set_size_request(GTK_WIDGET(dialog->buddy_icon_preview), -1, 50); + hbox = gtk_hbox_new(FALSE, 6); + gtk_box_pack_start(GTK_BOX(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->main_vbox), hbox, + FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(hbox), dialog->buddy_icon_preview, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(hbox), dialog->buddy_icon_text, FALSE, FALSE, 0); + + tv = GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->file_list; + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); + g_signal_connect(G_OBJECT(sel), "changed", G_CALLBACK(buddy_icon_preview_change_cb), dialog); + + g_signal_connect(G_OBJECT(dialog->buddy_icon_filesel), "delete-event", G_CALLBACK(buddy_icon_filesel_delete_cb), dialog); + g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->cancel_button), "clicked", + G_CALLBACK(buddy_icon_filesel_delete_cb), dialog); + g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->ok_button), "clicked", G_CALLBACK(buddy_icon_filesel_choose), + dialog); + + gtk_widget_show_all(dialog->buddy_icon_filesel); + if (dialog->account) { + gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog->buddy_icon_filesel), + gaim_account_get_buddy_icon(dialog->account)); + buddy_icon_preview_change_cb(NULL, dialog); + } + +} + +static void buddy_icon_reset_cb(GtkWidget *button, AccountPrefsDialog *dialog) +{ + gtk_entry_set_text(GTK_ENTRY(dialog->buddy_icon_entry), ""); + if (dialog->account) + gaim_account_set_buddy_icon(dialog->account, NULL); } static void @@ -236,11 +339,11 @@ /* Screen Name */ dialog->screenname_entry = gtk_entry_new(); - + add_pref_box(dialog, vbox, _("Screenname:"), dialog->screenname_entry); - + g_signal_connect(G_OBJECT(dialog->screenname_entry), "changed", - G_CALLBACK(screenname_changed_cb), dialog); + G_CALLBACK(screenname_changed_cb), dialog); /* Do the user split thang */ if (dialog->plugin == NULL) /* Yeah right. */ @@ -400,14 +503,19 @@ gtk_widget_show(label); dialog->buddy_icon_entry = gtk_entry_new(); + gtk_entry_set_editable(GTK_ENTRY(dialog->buddy_icon_entry), FALSE); gtk_box_pack_start(GTK_BOX(hbox), dialog->buddy_icon_entry, TRUE, TRUE, 0); gtk_widget_show(dialog->buddy_icon_entry); - button = gtk_button_new_with_label(_("Browse")); + button = gtk_button_new_with_mnemonic(_("_Browse")); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(buddy_icon_select_cb), dialog); gtk_widget_show(button); - button = gtk_button_new_with_label(_("Reset")); + button = gtk_button_new_with_mnemonic(_("_Reset")); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(buddy_icon_reset_cb), dialog); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); gtk_widget_show(button); @@ -773,6 +881,9 @@ if (dialog->protocol_opt_entries != NULL) g_list_free(dialog->protocol_opt_entries); + if (dialog->buddy_icon_filesel) + gtk_widget_destroy(dialog->buddy_icon_filesel); + g_free(dialog); } diff -r 729e688fd2e7 -r bd0d0e89cac3 src/gtkft.c --- a/src/gtkft.c Mon Jun 09 20:34:58 2003 +0000 +++ b/src/gtkft.c Tue Jun 10 01:09:26 2003 +0000 @@ -95,31 +95,6 @@ /************************************************************************** * Utility Functions **************************************************************************/ -static char * -get_size_string(size_t size) -{ - static const char *size_str[4] = { "bytes", "KB", "MB", "GB" }; - float size_mag; - int size_index = 0; - - if (size == -1) { - return g_strdup(_("Calculating...")); - } - else if (size == 0) { - return g_strdup(_("Unknown.")); - } - else { - size_mag = (float)size; - - while ((size_index < 4) && (size_mag > 1024)) { - size_mag /= 1024; - size_index++; - } - - return g_strdup_printf("%.2f %s", size_mag, size_str[size_index]); - } -} - static void get_xfer_info_strings(struct gaim_xfer *xfer, char **kbsec, char **time_elapsed, @@ -778,8 +753,8 @@ type = gaim_xfer_get_type(xfer); - size_str = get_size_string(gaim_xfer_get_size(xfer)); - remaining_str = get_size_string(gaim_xfer_get_bytes_remaining(xfer)); + size_str = gaim_get_size_string(gaim_xfer_get_size(xfer)); + remaining_str = gaim_get_size_string(gaim_xfer_get_bytes_remaining(xfer)); pixbuf = gtk_widget_render_icon(dialog->window, (type == GAIM_XFER_RECEIVE @@ -896,8 +871,8 @@ if (!(data = GAIM_GTKXFER(xfer))) return; - size_str = get_size_string(gaim_xfer_get_size(xfer)); - remaining_str = get_size_string(gaim_xfer_get_bytes_remaining(xfer)); + size_str = gaim_get_size_string(gaim_xfer_get_size(xfer)); + remaining_str = gaim_get_size_string(gaim_xfer_get_bytes_remaining(xfer)); gtk_list_store_set(xfer_dialog->model, &data->iter, COLUMN_PROGRESS, gaim_xfer_get_progress(xfer), @@ -1117,7 +1092,7 @@ size = gaim_xfer_get_size(xfer); - size_buf = get_size_string(size); + size_buf = gaim_get_size_string(size); buf = g_strdup_printf(_("%s wants to send you %s (%s)"), xfer->who, gaim_xfer_get_filename(xfer), size_buf); diff -r 729e688fd2e7 -r bd0d0e89cac3 src/main.c --- a/src/main.c Mon Jun 09 20:34:58 2003 +0000 +++ b/src/main.c Tue Jun 10 01:09:26 2003 +0000 @@ -656,7 +656,6 @@ #ifdef DEBUG opt_debug = 1; #endif -abort(); #ifdef ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, "UTF-8"); diff -r 729e688fd2e7 -r bd0d0e89cac3 src/util.c --- a/src/util.c Mon Jun 09 20:34:58 2003 +0000 +++ b/src/util.c Tue Jun 10 01:09:26 2003 +0000 @@ -1205,3 +1205,27 @@ return ret; } + +char *gaim_get_size_string(size_t size) +{ + static const char *size_str[4] = { "bytes", "KB", "MB", "GB" }; + float size_mag; + int size_index = 0; + + if (size == -1) { + return g_strdup(_("Calculating...")); + } + else if (size == 0) { + return g_strdup(_("Unknown.")); + } + else { + size_mag = (float)size; + + while ((size_index < 4) && (size_mag > 1024)) { + size_mag /= 1024; + size_index++; + } + + return g_strdup_printf("%.2f %s", size_mag, size_str[size_index]); + } +} diff -r 729e688fd2e7 -r bd0d0e89cac3 src/util.h --- a/src/util.h Mon Jun 09 20:34:58 2003 +0000 +++ b/src/util.h Tue Jun 10 01:09:26 2003 +0000 @@ -344,4 +344,11 @@ */ gchar *gaim_strreplace(const gchar *string, const gchar *delimiter, const gchar *replacement); +/** + * Returns a string representing a filesize in the appropriate units (MB, KB, GB, etc.) + * + * @param size The size + */ +char *gaim_get_size_string(size_t size); + #endif /* _GAIM_UTIL_H_ */