/dev/tomkiewicz/new-smileys: 6bf3252bf6db: Smiley manager: edit ...

Tomasz Wasilczyk twasilczyk at pidgin.im
Wed Apr 2 10:47:01 EDT 2014


Changeset: 6bf3252bf6dbb29d4f63c9d5cacd052cce398453
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-02 16:46 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/6bf3252bf6db

Description:

Smiley manager: edit window

diffstat:

 pidgin/gtksmiley-manager.c |  347 ++++++++++++++++++++++++++------------------
 1 files changed, 206 insertions(+), 141 deletions(-)

diffs (truncated from 686 to 300 lines):

diff --git a/pidgin/gtksmiley-manager.c b/pidgin/gtksmiley-manager.c
--- a/pidgin/gtksmiley-manager.c
+++ b/pidgin/gtksmiley-manager.c
@@ -37,6 +37,7 @@
 
 #define PIDGIN_RESPONSE_MODIFY 1000
 
+#if 0
 typedef struct _PidginSmiley PidginSmiley;
 struct _PidginSmiley
 {
@@ -50,10 +51,20 @@ struct _PidginSmiley
 	gsize datasize;
 	gint entry_len;
 };
+#endif
 
 typedef struct
 {
-	GtkWidget *window;
+	gchar *filename;
+
+	GtkDialog *window;
+	GtkImage *thumbnail;
+	GtkEntry *shortcut;
+} SmileyEditDialog;
+
+typedef struct
+{
+	GtkDialog *window;
 
 	GtkWidget *treeview;
 	GtkListStore *model;
@@ -70,31 +81,74 @@ enum
 
 static SmileyManager *smiley_manager = NULL;
 
+/******************************************************************************
+ * New routines (TODO)
+ *****************************************************************************/
+
 static void
-pidgin_smiley_destroy(PidginSmiley *smiley)
+edit_dialog_destroy(GtkWidget *window, gpointer _edit_dialog)
 {
-	if (smiley->smiley)
-		g_object_set_data(G_OBJECT(smiley->smiley), "edit-dialog", NULL);
-	gtk_widget_destroy(smiley->parent);
-	g_free(smiley->filename);
-	if (smiley->custom_pixbuf)
-		g_object_unref(G_OBJECT(smiley->custom_pixbuf));
-	g_free(smiley);
+	SmileyEditDialog *edit_dialog = _edit_dialog;
+
+	g_free(edit_dialog->filename);
+	g_free(edit_dialog);
 }
 
+static void
+edit_dialog_update_thumb(SmileyEditDialog *edit_dialog)
+{
+	GdkPixbuf *pixbuf = NULL;
+
+	if (edit_dialog->filename) {
+		pixbuf = pidgin_pixbuf_new_from_file_at_scale(
+			edit_dialog->filename, 64, 64, TRUE);
+		if (!pixbuf) {
+			g_free(edit_dialog->filename);
+			edit_dialog->filename = NULL;
+		}
+	}
+	if (!pixbuf) {
+		GtkIconSize icon_size =
+			gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_SMALL);
+		pixbuf = gtk_widget_render_icon(GTK_WIDGET(edit_dialog->window),
+			PIDGIN_STOCK_TOOLBAR_SELECT_AVATAR, icon_size,
+			"PidginSmiley");
+	}
+	g_return_if_fail(pixbuf != NULL);
+
+	gtk_image_set_from_pixbuf(GTK_IMAGE(edit_dialog->thumbnail), pixbuf);
+
+	g_object_unref(G_OBJECT(pixbuf));
+}
+
+static void
+edit_dialog_update_buttons(SmileyEditDialog *edit_dialog)
+{
+	gboolean shortcut_ok, image_ok;
+
+	shortcut_ok = (gtk_entry_get_text_length(edit_dialog->shortcut) > 0);
+	image_ok = (edit_dialog->filename != NULL);
+
+	gtk_dialog_set_response_sensitive(edit_dialog->window,
+		GTK_RESPONSE_ACCEPT, shortcut_ok && image_ok);
+}
+
+
 /******************************************************************************
  * Manager stuff
  *****************************************************************************/
 
+#if 0
 static void refresh_list(void);
+#endif
 
 /******************************************************************************
  * The Add dialog
  ******************************************************************************/
 
+#if 0
 static void do_add(GtkWidget *widget, PidginSmiley *s)
 {
-#if 0
 	const gchar *entry;
 	PurpleSmiley *emoticon;
 
@@ -174,117 +228,103 @@ static void do_add(GtkWidget *widget, Pi
 		refresh_list();
 
 	gtk_widget_destroy(s->parent);
+}
 #endif
-}
 
-static void do_add_select_cb(GtkWidget *widget, gint resp, PidginSmiley *s)
+static void
+pidgin_smiley_edit_response(GtkDialog *window, gint response_id,
+	gpointer _edit_dialog)
 {
-	switch (resp) {
+	SmileyEditDialog *edit_dialog = _edit_dialog;
+
+	switch (response_id) {
+#if 0
 		case GTK_RESPONSE_ACCEPT:
 			do_add(widget, s);
 			break;
+#endif
 		case GTK_RESPONSE_DELETE_EVENT:
 		case GTK_RESPONSE_CANCEL:
-			gtk_widget_destroy(s->parent);
+			gtk_widget_destroy(GTK_WIDGET(edit_dialog->window));
 			break;
 		default:
-			purple_debug_error("gtksmiley", "no valid response\n");
-			break;
+			g_warn_if_reached();
 	}
 }
 
-static void do_add_file_cb(const char *filename, gpointer data)
+static void do_add_file_cb(const char *filename, gpointer _edit_dialog)
 {
-	PidginSmiley *s = data;
-	GdkPixbuf *pixbuf;
+	SmileyEditDialog *edit_dialog = _edit_dialog;
 
 	if (!filename)
 		return;
 
-	g_free(s->filename);
-	s->filename = g_strdup(filename);
-	pixbuf = pidgin_pixbuf_new_from_file_at_scale(filename, 64, 64, FALSE);
-	gtk_image_set_from_pixbuf(GTK_IMAGE(s->smiley_image), pixbuf);
-	if (pixbuf)
-		g_object_unref(G_OBJECT(pixbuf));
-	gtk_widget_grab_focus(s->smile);
+	g_free(edit_dialog->filename);
+	edit_dialog->filename = g_strdup(filename);
 
-	if (s->entry_len > 0)
-		gtk_dialog_set_response_sensitive(GTK_DIALOG(s->parent), GTK_RESPONSE_ACCEPT, TRUE);
+	edit_dialog_update_thumb(edit_dialog);
+	edit_dialog_update_buttons(edit_dialog);
+
+	gtk_widget_grab_focus(GTK_WIDGET(edit_dialog->shortcut));
 }
 
 static void
-open_image_selector(GtkWidget *widget, PidginSmiley *psmiley)
+open_image_selector(GtkWidget *widget, gpointer _edit_dialog)
 {
 	GtkWidget *file_chooser;
-	file_chooser = pidgin_buddy_icon_chooser_new(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
-			do_add_file_cb, psmiley);
+	file_chooser = pidgin_buddy_icon_chooser_new(
+		GTK_WINDOW(gtk_widget_get_toplevel(widget)),
+		do_add_file_cb, _edit_dialog);
 	gtk_window_set_title(GTK_WINDOW(file_chooser), _("Custom Smiley"));
-	gtk_window_set_role(GTK_WINDOW(file_chooser), "file-selector-custom-smiley");
+	gtk_window_set_role(GTK_WINDOW(file_chooser),
+		"file-selector-custom-smiley");
 	gtk_widget_show_all(file_chooser);
 }
 
 static void
-smiley_name_insert_cb(GtkEditable *editable,
-                      gchar       *new_text,
-                      gint         new_text_length,
-                      gint        *position,
-                      gpointer     user_data)
+smiley_shortcut_changed(GtkEditable *shortcut, gpointer _edit_dialog)
 {
-	PidginSmiley *s = user_data;
-	if (new_text_length != -1)
-		s->entry_len += new_text_length;
-	else
-		s->entry_len += strlen(new_text);
+	SmileyEditDialog *edit_dialog = _edit_dialog;
 
-	if (s->filename != NULL || s->custom_pixbuf != NULL || s->smiley != NULL)
-		gtk_dialog_set_response_sensitive(GTK_DIALOG(s->parent), GTK_RESPONSE_ACCEPT, TRUE);
+	edit_dialog_update_buttons(edit_dialog);
 }
 
+/* TODO: is <widget> really necessary? */
 static void
-smiley_name_delete_cb(GtkEditable *editable,
-                      gint         start_pos,
-                      gint         end_pos,
-                      gpointer     user_data)
-{
-	PidginSmiley *s = user_data;
-	s->entry_len -= end_pos - start_pos;
-
-	if (s->entry_len <= 0)
-		gtk_dialog_set_response_sensitive(GTK_DIALOG(s->parent), GTK_RESPONSE_ACCEPT, FALSE);
-}
-
-static PidginSmiley *
 pidgin_smiley_edit(GtkWidget *widget, PurpleSmiley *smiley)
 {
-#if 0
+	SmileyEditDialog *edit_dialog;
+
 	GtkWidget *vbox;
 	GtkWidget *hbox;
 	GtkWidget *label;
 	GtkWidget *filech;
-	GtkWidget *window;
-	GdkPixbuf *pixbuf = NULL;
-	PurpleStoredImage *stored_img;
 
-	PidginSmiley *s = g_new0(PidginSmiley, 1);
-	s->smiley = smiley;
+	edit_dialog = g_new0(SmileyEditDialog, 1);
 
-	window = gtk_dialog_new_with_buttons(smiley ? _("Edit Smiley") : _("Add Smiley"),
+	if (smiley) {
+		edit_dialog->filename =
+			g_strdup(purple_smiley_get_path(smiley));
+	}
+
+	edit_dialog->window = GTK_DIALOG(gtk_dialog_new_with_buttons(smiley ? _("Edit Smiley") : _("Add Smiley"),
 			widget ? GTK_WINDOW(widget) : NULL,
 			GTK_DIALOG_DESTROY_WITH_PARENT,
 			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 			smiley ? GTK_STOCK_SAVE : GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT,
-			NULL);
-	s->parent = window;
-	if (smiley)
-		g_object_set_data(G_OBJECT(smiley), "edit-dialog", window);
+			NULL));
+//	if (smiley)
+//		g_object_set_data(G_OBJECT(smiley), "edit-dialog", window);
 
 #if !GTK_CHECK_VERSION(3,0,0)
-	gtk_container_set_border_width(GTK_CONTAINER(window), PIDGIN_HIG_BORDER);
+	gtk_container_set_border_width(
+		GTK_CONTAINER(edit_dialog->window), PIDGIN_HIG_BORDER);
 #endif
 
-	gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_ACCEPT);
-	g_signal_connect(window, "response", G_CALLBACK(do_add_select_cb), s);
+	gtk_dialog_set_default_response(
+		edit_dialog->window, GTK_RESPONSE_ACCEPT);
+	g_signal_connect(edit_dialog->window, "response",
+		G_CALLBACK(pidgin_smiley_edit_response), edit_dialog);
 
 	/* The vbox */
 #if GTK_CHECK_VERSION(3,0,0)
@@ -293,8 +333,8 @@ pidgin_smiley_edit(GtkWidget *widget, Pu
 #else
 	vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
 #endif
-	gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(window))),
-                    vbox);
+	gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(
+		edit_dialog->window)), vbox);
 	gtk_widget_show(vbox);
 
 	/* The hbox */
@@ -323,21 +363,12 @@ pidgin_smiley_edit(GtkWidget *widget, Pu
 #endif
 	pidgin_set_accessible_label(filech, label);
 
-	s->smiley_image = gtk_image_new();
-	gtk_container_add(GTK_CONTAINER(filech), s->smiley_image);
-	if (smiley && (stored_img = purple_smiley_get_stored_image(smiley))) {



More information about the Commits mailing list