/dev/tomkiewicz/new-smileys: 3203e0f1b1bd: PidginSmileyTheme: pr...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Mon Mar 31 09:33:29 EDT 2014
Changeset: 3203e0f1b1bd85c01a6b33e87830e2f6a21701fd
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-03-31 15:33 +0200
Branch: default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/3203e0f1b1bd
Description:
PidginSmileyTheme: probe themes
diffstat:
pidgin/gtksmiley-theme.c | 117 +++++++++++++++++++++++++++++++++++++++++++++-
pidgin/gtksmiley-theme.h | 6 ++
pidgin/libpidgin.c | 1 +
3 files changed, 121 insertions(+), 3 deletions(-)
diffs (185 lines):
diff --git a/pidgin/gtksmiley-theme.c b/pidgin/gtksmiley-theme.c
--- a/pidgin/gtksmiley-theme.c
+++ b/pidgin/gtksmiley-theme.c
@@ -21,16 +21,100 @@
#include "gtksmiley-theme.h"
+#include <glib/gstdio.h>
+
#define PIDGIN_SMILEY_THEME_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), PIDGIN_TYPE_SMILEY_THEME, \
- PurpleSmileyThemePrivate))
+ PidginSmileyThemePrivate))
typedef struct
{
-} PurpleSmileyThemePrivate;
+ gchar *path;
+} PidginSmileyThemePrivate;
static GObjectClass *parent_class;
+static gchar **probe_dirs;
+static GList *smiley_themes = NULL;
+
+/*******************************************************************************
+ * Theme loading
+ ******************************************************************************/
+
+static void
+pidgin_smiley_theme_load(const gchar *theme_path)
+{
+ PidginSmileyTheme *theme;
+ PidginSmileyThemePrivate *priv;
+ GList *it;
+ gchar *index_path;
+
+ /* it's not super-efficient, but we don't expect huge amount of
+ * installed themes */
+ for (it = smiley_themes; it; it = g_list_next(it)) {
+ PidginSmileyThemePrivate *priv =
+ PIDGIN_SMILEY_THEME_GET_PRIVATE(it->data);
+
+ /* theme is already loaded */
+ if (g_strcmp0(priv->path, theme_path) == 0)
+ return;
+ }
+
+ index_path = g_build_filename(theme_path, "theme", NULL);
+
+ theme = g_object_new(PIDGIN_TYPE_SMILEY_THEME, NULL);
+ priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(theme);
+
+ priv->path = g_strdup(theme_path);
+
+ /* TODO: parse index_path */
+
+ g_free(index_path);
+}
+
+static void
+pidgin_smiley_theme_probe(void)
+{
+ GList *it, *next;
+ int i;
+
+ /* remove non-existing themes */
+ for (it = smiley_themes; it; it = next) {
+ PidginSmileyTheme *theme = it->data;
+ PidginSmileyThemePrivate *priv =
+ PIDGIN_SMILEY_THEME_GET_PRIVATE(theme);
+
+ next = g_list_next(it);
+
+ if (g_file_test(priv->path, G_FILE_TEST_EXISTS))
+ continue;
+ smiley_themes = g_list_remove_link(smiley_themes, it);
+ g_object_unref(theme);
+ }
+
+ /* scan for themes */
+ for (i = 0; probe_dirs[i]; i++) {
+ GDir *dir = g_dir_open(probe_dirs[i], 0, NULL);
+ const gchar *theme_dir_name;
+
+ if (!dir)
+ continue;
+
+ while ((theme_dir_name = g_dir_read_name(dir))) {
+ gchar *theme_path = g_build_filename(
+ probe_dirs[i], theme_dir_name, NULL);
+
+ if (g_file_test(theme_path, G_FILE_TEST_IS_DIR))
+ pidgin_smiley_theme_load(theme_path);
+
+ g_free(theme_path);
+ }
+
+ g_dir_close(dir);
+ }
+}
+
+
/*******************************************************************************
* API implementation
******************************************************************************/
@@ -44,8 +128,31 @@ pidgin_smiley_theme_get_smileys_impl(Pur
void
pidgin_smiley_theme_init(void)
{
+ const gchar *user_smileys_dir;
+
+ probe_dirs = g_new0(gchar*, 3);
+ probe_dirs[0] = g_build_filename(
+ DATADIR, "pixmaps", "pidgin", "emotes", NULL);
+ user_smileys_dir = probe_dirs[1] = g_build_filename(
+ purple_user_dir(), "smileys", NULL);
+
+ if (!g_file_test(user_smileys_dir, G_FILE_TEST_IS_DIR))
+ g_mkdir(user_smileys_dir, S_IRUSR | S_IWUSR | S_IXUSR);
}
+void
+pidgin_smiley_theme_uninit(void)
+{
+ g_strfreev(probe_dirs);
+}
+
+GList *
+pidgin_smiley_theme_get_all(void)
+{
+ pidgin_smiley_theme_probe();
+
+ return NULL;
+}
/*******************************************************************************
* Object stuff
@@ -54,6 +161,10 @@ pidgin_smiley_theme_init(void)
static void
pidgin_smiley_theme_finalize(GObject *obj)
{
+ PidginSmileyThemePrivate *priv = PIDGIN_SMILEY_THEME_GET_PRIVATE(obj);
+
+ g_free(priv->path);
+
G_OBJECT_CLASS(parent_class)->finalize(obj);
}
@@ -65,7 +176,7 @@ pidgin_smiley_theme_class_init(PurpleSmi
parent_class = g_type_class_peek_parent(klass);
- g_type_class_add_private(klass, sizeof(PurpleSmileyThemePrivate));
+ g_type_class_add_private(klass, sizeof(PidginSmileyThemePrivate));
gobj_class->finalize = pidgin_smiley_theme_finalize;
diff --git a/pidgin/gtksmiley-theme.h b/pidgin/gtksmiley-theme.h
--- a/pidgin/gtksmiley-theme.h
+++ b/pidgin/gtksmiley-theme.h
@@ -71,6 +71,12 @@ pidgin_smiley_theme_get_type(void);
void
pidgin_smiley_theme_init(void);
+void
+pidgin_smiley_theme_uninit(void);
+
+GList *
+pidgin_smiley_theme_get_all(void);
+
G_END_DECLS
#endif /* _PIDGIN_SMILEY_THEME_H_ */
diff --git a/pidgin/libpidgin.c b/pidgin/libpidgin.c
--- a/pidgin/libpidgin.c
+++ b/pidgin/libpidgin.c
@@ -307,6 +307,7 @@ pidgin_quit(void)
/* Uninit */
pidgin_utils_uninit();
pidgin_notify_uninit();
+ pidgin_smiley_theme_uninit();
pidgin_smileys_uninit();
pidgin_conversations_uninit();
pidgin_status_uninit();
More information about the Commits
mailing list