Mercurial > pidgin
changeset 23161:99ef50c8da91
Modified patch from malu to "Add context menu alternative to add received
custom smiley". Closes #5855.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 21 May 2008 17:56:20 +0000 |
parents | e0e57b83b359 |
children | 78dad8135c72 |
files | pidgin/gtkimhtml.c pidgin/gtksmiley.c pidgin/gtksmiley.h |
diffstat | 3 files changed, 97 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c Wed May 21 12:29:27 2008 +0000 +++ b/pidgin/gtkimhtml.c Wed May 21 17:56:20 2008 +0000 @@ -32,10 +32,14 @@ #include "internal.h" #include "pidgin.h" #include "pidginstock.h" +#include "gtkutils.h" +#include "smiley.h" +#include "imgstore.h" #include "debug.h" #include "util.h" #include "gtkimhtml.h" +#include "gtksmiley.h" #include "gtksourceiter.h" #include "gtksourceundomanager.h" #include "gtksourceview-marshal.h" @@ -3687,6 +3691,15 @@ gtk_widget_show(image->filesel); } +static void +gtk_imhtml_custom_smiley_save(GtkWidget *w, GtkIMHtmlImage *image) +{ + /* Create an add dialog */ + PidginSmiley *editor = pidgin_smiley_edit(NULL, NULL); + pidgin_smiley_editor_set_shortcut(editor, image->filename); + pidgin_smiley_editor_set_image(editor, image->pixbuf); +} + /* * So, um, AIM Direct IM lets you send any file, not just images. You can * just insert a sound or a file or whatever in a conversation. It's @@ -3711,6 +3724,19 @@ g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + /* Add menu item for adding custom smiley to local smileys */ + /* we only add the menu if the image is of "custom smiley size" + <= 96x96 pixels */ + if (image->width <= 96 && image->height <= 96) { + text = g_strdup_printf(_("_Add Custom Smiley...")); + img = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU); + item = gtk_image_menu_item_new_with_mnemonic(text); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); + g_signal_connect(G_OBJECT(item), "activate", + G_CALLBACK(gtk_imhtml_custom_smiley_save), image); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + } + gtk_widget_show_all(menu); gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event_button->button, event_button->time); @@ -3732,7 +3758,7 @@ GdkPixbufAnimation *anim = NULL; GtkIMHtmlScalable *image = NULL; gboolean ret; - + if (event->type != GDK_BUTTON_RELEASE || ((GdkEventButton*)event)->button != 3) return FALSE;
--- a/pidgin/gtksmiley.c Wed May 21 12:29:27 2008 +0000 +++ b/pidgin/gtksmiley.c Wed May 21 17:56:20 2008 +0000 @@ -39,14 +39,15 @@ #define PIDGIN_RESPONSE_EDIT 1000 -typedef struct +struct _PidginSmiley { PurpleSmiley *smiley; GtkWidget *parent; GtkWidget *smile; GtkWidget *smiley_image; gchar *filename; -} PidginSmiley; + GdkPixbuf *custom_pixbuf; +}; typedef struct { @@ -72,6 +73,8 @@ { gtk_widget_destroy(smiley->parent); g_free(smiley->filename); + if (smiley->custom_pixbuf) + gdk_pixbuf_unref(smiley->custom_pixbuf); g_free(smiley); } @@ -230,7 +233,8 @@ } purple_smiley_set_shortcut(s->smiley, entry); } else { - if ((s->filename == NULL || *entry == 0)) { + if ((s->filename == NULL && s->custom_pixbuf == NULL) + || *entry == 0) { purple_notify_error(s->parent, _("Custom Smiley"), _("More Data needed"), s->filename ? _("Please provide a shortcut to associate with the smiley.") @@ -239,6 +243,21 @@ } purple_debug_info("gtksmiley", "adding a new smiley\n"); + + if (s->filename == NULL) { + /* Get the smiley from the custom pixbuf */ + gchar *buffer = NULL; + gsize size = 0; + gchar *filename; + + gdk_pixbuf_save_to_bufferv(s->custom_pixbuf, &buffer, &size, + "png", NULL, NULL, NULL); + filename = purple_util_get_image_filename(buffer, size); + s->filename = g_build_filename(purple_smileys_get_storing_dir(), filename, NULL); + purple_util_write_data_to_file_absolute(s->filename, buffer, size); + g_free(filename); + g_free(buffer); + } emoticon = purple_smiley_new_from_file(entry, s->filename); pidgin_smiley_add_to_list(emoticon); } @@ -293,7 +312,8 @@ gtk_widget_show_all(file_chooser); } -void pidgin_smiley_edit(GtkWidget *widget, PurpleSmiley *smiley) +PidginSmiley * +pidgin_smiley_edit(GtkWidget *widget, PurpleSmiley *smiley) { GtkWidget *vbox; GtkWidget *hbox; @@ -307,7 +327,7 @@ s->smiley = smiley; window = gtk_dialog_new_with_buttons(smiley ? _("Edit Smiley") : _("Add Smiley"), - GTK_WINDOW(widget), + widget ? GTK_WINDOW(widget) : NULL, GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, smiley ? GTK_STOCK_SAVE : GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, @@ -378,6 +398,24 @@ gtk_widget_show(GTK_WIDGET(window)); g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(pidgin_smiley_destroy), s); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(purple_notify_close_with_handle), s); + + return s; +} + +void +pidgin_smiley_editor_set_shortcut(PidginSmiley *editor, const gchar *shortcut) +{ + gtk_entry_set_text(GTK_ENTRY(editor->smile), shortcut ? shortcut : ""); +} + +void +pidgin_smiley_editor_set_image(PidginSmiley *editor, GdkPixbuf *image) +{ + if (editor->custom_pixbuf) + gdk_pixbuf_unref(editor->custom_pixbuf); + editor->custom_pixbuf = image ? gdk_pixbuf_ref(image) : NULL; + if (image) + gtk_image_set_from_pixbuf(GTK_IMAGE(editor->smiley_image), image); } /****************************************************************************** @@ -648,7 +686,7 @@ gtk_dialog_set_response_sensitive(GTK_DIALOG(win), GTK_RESPONSE_NO, FALSE); gtk_dialog_set_response_sensitive(GTK_DIALOG(win), PIDGIN_RESPONSE_EDIT, FALSE); - + g_signal_connect(win, "response", G_CALLBACK(smiley_manager_select_cb), dialog);
--- a/pidgin/gtksmiley.h Wed May 21 12:29:27 2008 +0000 +++ b/pidgin/gtksmiley.h Wed May 21 17:56:20 2008 +0000 @@ -1,6 +1,7 @@ /** * @file gtksmiley.h GTK+ Custom Smiley API * @ingroup pidgin + * @since 2.5.0 */ /* pidgin @@ -29,6 +30,8 @@ #include "smiley.h" +typedef struct _PidginSmiley PidginSmiley; + /** * Add a PurpleSmiley to the GtkIMHtmlSmiley's list to be able to use it * in pidgin @@ -72,9 +75,29 @@ /** * Shows an editor for a smiley. * - * @param widget The parent widget to be linked or @c NULL - * @param smiley The PurpleSmiley to be edited, or @c NULL for a new smiley + * @param widget The parent widget to be linked or @c NULL + * @param smiley The PurpleSmiley to be edited, or @c NULL for a new smiley + * @return The smiley add dialog + * + * @see pidgin_smiley_editor_set_shortcut + * @see pidgin_smiley_editor_set_image */ -void pidgin_smiley_edit(GtkWidget *widget, PurpleSmiley *smiley); +PidginSmiley *pidgin_smiley_edit(GtkWidget *widget, PurpleSmiley *smiley); + +/** + * Set the shortcut in a smiley add dialog + * + * @param editor A smiley editor dialog (created by pidgin_smiley_edit) + * @param shortcut The shortcut to set + */ +void pidgin_smiley_editor_set_shortcut(PidginSmiley *editor, const gchar *shortcut); + +/** + * Set the image in a smiley add dialog + * + * @param editor A smiley editor dialog + * @param image A GdkPixbuf image + */ +void pidgin_smiley_editor_set_image(PidginSmiley *editor, GdkPixbuf *image); #endif /* _PIDGIN_GTKSMILEY_H_*/