pidgin.next.minor: 07fc1ad3: Modified patch from malu to "Add context...

sadrul at pidgin.im sadrul at pidgin.im
Wed May 21 14:06:18 EDT 2008


-----------------------------------------------------------------
Revision: 07fc1ad334326d74e31bc239fc0064b83c4c6086
Ancestor: da1a6dad30a42a8b2616c0ec10dca356a9d592ce
Author: sadrul at pidgin.im
Date: 2008-05-21T17:56:20
Branch: im.pidgin.pidgin.next.minor
URL: http://d.pidgin.im/viewmtn/revision/info/07fc1ad334326d74e31bc239fc0064b83c4c6086

Modified files:
        pidgin/gtkimhtml.c pidgin/gtksmiley.c pidgin/gtksmiley.h

ChangeLog: 

Modified patch from malu to "Add context menu alternative to add received
custom smiley". Closes #5855.

-------------- next part --------------
============================================================
--- pidgin/gtkimhtml.c	444ed6f16bda133375f6d7f67d2862c2d26c0bf8
+++ pidgin/gtkimhtml.c	b9e9d47d83f9cca6c68de08cc4d6b731eb4689f1
@@ -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_imhtml_image_save(GtkWidget *w, GtkI
 	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 @@ static gboolean gtk_imhtml_image_clicked
 			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 @@ static gboolean gtk_imhtml_smiley_clicke
 	GdkPixbufAnimation *anim = NULL;
 	GtkIMHtmlScalable *image = NULL;
 	gboolean ret;
-	
+
 	if (event->type != GDK_BUTTON_RELEASE || ((GdkEventButton*)event)->button != 3)
 		return FALSE;
 
============================================================
--- pidgin/gtksmiley.c	4bbae1499b0e3ecb30ce737997930946801f3ffa
+++ pidgin/gtksmiley.c	752a7bc1724ba5b7553837ec4b77684cdbd25889
@@ -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 @@ pidgin_smiley_destroy(PidginSmiley *smil
 {
 	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 @@ static void do_add(GtkWidget *widget, Pi
 		}
 		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 @@ static void do_add(GtkWidget *widget, Pi
 		}
 
 		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 @@ open_image_selector(GtkWidget *widget, P
 	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 @@ void pidgin_smiley_edit(GtkWidget *widge
 	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,8 +398,26 @@ void pidgin_smiley_edit(GtkWidget *widge
 	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);
+}
+
 /******************************************************************************
  * Delete smiley
  *****************************************************************************/
@@ -648,7 +686,7 @@ void pidgin_smiley_manager_show(void)
 	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);
 
============================================================
--- pidgin/gtksmiley.h	2cc3593f42a5c3c63c6a7aa231e3ad42b53026e7
+++ pidgin/gtksmiley.h	a59d0f3a60f348da398d669f7b79789f6de5ffc1
@@ -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 @@ void pidgin_smiley_manager_show(void);
 /**
  * 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_*/


More information about the Commits mailing list