/dev/tomkiewicz/new-smileys: 8903e6402d5b: PidginSmileyTheme: wo...

Tomasz Wasilczyk twasilczyk at pidgin.im
Mon Mar 31 20:11:26 EDT 2014


Changeset: 8903e6402d5b567a2a366eda86b71598053f1ae0
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-01 02:11 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/8903e6402d5b

Description:

PidginSmileyTheme: working implementation for gtkprefs

diffstat:

 pidgin/gtkconv.c         |   2 +-
 pidgin/gtkprefs.c        |  85 +++++++++++++++++++++++++++--------------------
 pidgin/gtksmiley-theme.c |  70 +++++++++++++++++++++++++++++++++++++++
 pidgin/gtksmiley-theme.h |  17 +++++++++
 pidgin/gtkthemes.c       |  17 +++++++++
 pidgin/gtkthemes.h       |   3 +-
 pidgin/smileyparser.c    |   2 +-
 7 files changed, 156 insertions(+), 40 deletions(-)

diffs (truncated from 327 to 300 lines):

diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -7246,7 +7246,7 @@ pidgin_conv_custom_smiley_add(PurpleConv
 	conv_sml = purple_account_get_protocol_name(purple_conversation_get_account(conv));
 	gtkconv = PIDGIN_CONVERSATION(conv);
 
-	for (list = (struct PidginSmileyList *)current_smiley_theme->list; list; list = list->next) {
+	for (list = (struct PidginSmileyList *)((struct PidginSmileyThemeREMOVEIT *)current_smiley_theme)->list; list; list = list->next) {
 		if (!strcmp(list->sml, conv_sml)) {
 			sml = list->sml;
 			break;
diff --git a/pidgin/gtkprefs.c b/pidgin/gtkprefs.c
--- a/pidgin/gtkprefs.c
+++ b/pidgin/gtkprefs.c
@@ -48,6 +48,7 @@
 #include "gtkdialogs.h"
 #include "gtkprefs.h"
 #include "gtksavedstatuses.h"
+#include "gtksmiley-theme.h"
 #include "gtksound.h"
 #include "gtkstatus-icon-theme.h"
 #include "gtkthemes.h"
@@ -587,38 +588,33 @@ get_theme_markup(const char *name, gbool
 static void
 smileys_refresh_theme_list(void)
 {
-	GdkPixbuf *pixbuf;
-	GSList *themes;
+	GList *it;
 	GtkTreeIter iter;
-
-	pidgin_themes_smiley_theme_probe();
-
-	if (!(themes = smiley_themes))
-		return;
-
-	while (themes) {
-		struct PidginSmileyTheme *theme = themes->data;
-		char *description = get_theme_markup(_(theme->name), FALSE,
-		                                     _(theme->author), _(theme->desc));
+	gchar *description;
+
+	description = get_theme_markup(_("none"), FALSE, _("Penguin Pimps"),
+		_("Selecting this disables graphical emoticons."));
+	gtk_list_store_append(prefs_smiley_themes, &iter);
+	gtk_list_store_set(prefs_smiley_themes, &iter,
+		0, NULL, 1, description, 2, "none", -1);
+	g_free(description);
+
+	for (it = pidgin_smiley_theme_get_all(); it; it = g_list_next(it)) {
+		PidginSmileyTheme *theme = it->data;
+
+		description = get_theme_markup(
+			_(pidgin_smiley_theme_get_name(theme)), FALSE,
+			_(pidgin_smiley_theme_get_author(theme)),
+			_(pidgin_smiley_theme_get_description(theme)));
+
 		gtk_list_store_append(prefs_smiley_themes, &iter);
-
-		/*
-		 * LEAK - Gentoo memprof thinks pixbuf is leaking here... but it
-		 * looks like it should be ok to me.  Anyone know what's up?  --Mark
-		 */
-		pixbuf = (theme->icon ? pidgin_pixbuf_new_from_file(theme->icon) : NULL);
-
 		gtk_list_store_set(prefs_smiley_themes, &iter,
-				   0, pixbuf,
-				   1, description,
-				   2, theme->name,
-				   -1);
-
-		if (pixbuf != NULL)
-			g_object_unref(G_OBJECT(pixbuf));
+			0, pidgin_smiley_theme_get_icon(theme),
+			1, description,
+			2, pidgin_smiley_theme_get_name(theme),
+			-1);
 
 		g_free(description);
-		themes = themes->next;
 	}
 }
 
@@ -4235,15 +4231,32 @@ static void
 smiley_theme_pref_cb(const char *name, PurplePrefType type,
 					 gconstpointer value, gpointer data)
 {
-	const char *themename = value;
-	GSList *themes;
-
-	for (themes = smiley_themes; themes; themes = themes->next) {
-		struct PidginSmileyTheme *smile = themes->data;
-		if (smile->name && strcmp(themename, smile->name) == 0) {
-			pidgin_themes_load_smiley_theme(smile->path, TRUE);
-			break;
-		}
+	const gchar *theme_name = value;
+	GList *themes, *it;
+
+	if (g_strcmp0(theme_name, "none") == 0) {
+		purple_smiley_theme_set_current(NULL);
+		pidgin_themes_load_smiley_theme(NULL, TRUE);
+		return;
+	}
+
+	/* XXX: could be cached when initializing prefs view */
+	themes = pidgin_smiley_theme_get_all();
+
+	for (it = themes; it; it = g_list_next(it)) {
+		PidginSmileyTheme *theme = it->data;
+		gchar *old_path;
+
+		if (g_strcmp0(pidgin_smiley_theme_get_name(theme), theme_name))
+			continue;
+
+		purple_smiley_theme_set_current(PURPLE_SMILEY_THEME(theme));
+
+		/* TODO: remove it */
+		old_path = g_build_filename(pidgin_smiley_theme_get_path(theme),
+			"theme", NULL);
+		pidgin_themes_load_smiley_theme(old_path, TRUE);
+		g_free(old_path);
 	}
 }
 
diff --git a/pidgin/gtksmiley-theme.c b/pidgin/gtksmiley-theme.c
--- a/pidgin/gtksmiley-theme.c
+++ b/pidgin/gtksmiley-theme.c
@@ -26,6 +26,8 @@
 
 #include "debug.h"
 
+#include "gtkutils.h"
+
 #include <glib/gstdio.h>
 
 #define PIDGIN_SMILEY_THEME_GET_PRIVATE(obj) \
@@ -43,6 +45,8 @@ typedef struct
 	gchar *desc;
 	gchar *icon;
 	gchar *author;
+
+	GdkPixbuf *icon_pixbuf;
 } PidginSmileyThemePrivate;
 
 static GObjectClass *parent_class;
@@ -361,6 +365,66 @@ pidgin_smiley_theme_probe(void)
  * API implementation
  ******************************************************************************/
 
+const gchar *
+pidgin_smiley_theme_get_path(PidginSmileyTheme *theme)
+{
+	PidginSmileyThemePrivate *priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(theme);
+
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->path;
+}
+
+const gchar *
+pidgin_smiley_theme_get_name(PidginSmileyTheme *theme)
+{
+	PidginSmileyThemePrivate *priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(theme);
+
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->name;
+}
+
+const gchar *
+pidgin_smiley_theme_get_description(PidginSmileyTheme *theme)
+{
+	PidginSmileyThemePrivate *priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(theme);
+
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->desc;
+}
+
+GdkPixbuf *
+pidgin_smiley_theme_get_icon(PidginSmileyTheme *theme)
+{
+	PidginSmileyThemePrivate *priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(theme);
+
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	if (priv->icon == NULL)
+		return NULL;
+
+	if (!priv->icon_pixbuf) {
+		gchar *icon_path = g_build_filename(
+			priv->path, priv->icon, NULL);
+		priv->icon_pixbuf = pidgin_pixbuf_new_from_file(icon_path);
+		g_free(icon_path);
+	}
+
+	return priv->icon_pixbuf;
+}
+
+const gchar *
+pidgin_smiley_theme_get_author(PidginSmileyTheme *theme)
+{
+	PidginSmileyThemePrivate *priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(theme);
+
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->author;
+}
+
 static PurpleSmileyList *
 pidgin_smiley_theme_get_smileys_impl(PurpleSmileyTheme *theme, gpointer ui_data)
 {
@@ -408,6 +472,12 @@ pidgin_smiley_theme_finalize(GObject *ob
 	PidginSmileyThemePrivate *priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(obj);
 
 	g_free(priv->path);
+	g_free(priv->name);
+	g_free(priv->desc);
+	g_free(priv->icon);
+	g_free(priv->author);
+	if (priv->icon_pixbuf)
+		g_object_unref(priv->icon_pixbuf);
 
 	G_OBJECT_CLASS(parent_class)->finalize(obj);
 }
diff --git a/pidgin/gtksmiley-theme.h b/pidgin/gtksmiley-theme.h
--- a/pidgin/gtksmiley-theme.h
+++ b/pidgin/gtksmiley-theme.h
@@ -23,6 +23,7 @@
 #define _PIDGIN_SMILEY_THEME_H_
 
 #include <glib-object.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include "smiley-theme.h"
 
@@ -68,6 +69,22 @@ G_BEGIN_DECLS
 GType
 pidgin_smiley_theme_get_type(void);
 
+/* TODO: remove it */
+const gchar *
+pidgin_smiley_theme_get_path(PidginSmileyTheme *theme);
+
+const gchar *
+pidgin_smiley_theme_get_name(PidginSmileyTheme *theme);
+
+const gchar *
+pidgin_smiley_theme_get_description(PidginSmileyTheme *theme);
+
+GdkPixbuf *
+pidgin_smiley_theme_get_icon(PidginSmileyTheme *theme);
+
+const gchar *
+pidgin_smiley_theme_get_author(PidginSmileyTheme *theme);
+
 void
 pidgin_smiley_theme_init(void);
 
diff --git a/pidgin/gtkthemes.c b/pidgin/gtkthemes.c
--- a/pidgin/gtkthemes.c
+++ b/pidgin/gtkthemes.c
@@ -34,6 +34,16 @@
 #include "gtkthemes.h"
 #include "gtkwebview.h"
 
+struct PidginSmileyTheme {
+	char *path;
+	char *name;
+	char *desc;
+	char *icon;
+	char *author;
+
+	struct PidginSmileyList *list;
+};
+
 GSList *smiley_themes = NULL;
 struct PidginSmileyTheme *current_smiley_theme;
 
@@ -216,6 +226,13 @@ void pidgin_themes_load_smiley_theme(con
 	GSList *lst = smiley_themes;
 	char *dirname;
 
+	if (file == NULL) {
+		if (current_smiley_theme)
+			pidgin_themes_destroy_smiley_theme_smileys(current_smiley_theme);
+		current_smiley_theme = NULL;
+		return;
+	}
+
 	if (!f)
 		return;
 
diff --git a/pidgin/gtkthemes.h b/pidgin/gtkthemes.h
--- a/pidgin/gtkthemes.h
+++ b/pidgin/gtkthemes.h
@@ -35,7 +35,7 @@ struct PidginSmileyList {
 	struct PidginSmileyList *next;



More information about the Commits mailing list