/dev/tomkiewicz/new-smileys: 0d7a84931572: Smileys: implement an...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Mon Mar 31 21:46:26 EDT 2014
Changeset: 0d7a84931572ccfd2ee78fddb08fc6dc427253f6
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-01 03:46 +0200
Branch: default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/0d7a84931572
Description:
Smileys: implement and use new parser, only themes for now
diffstat:
libpurple/Makefile.am | 2 +
libpurple/smiley-list.c | 23 +++++++---
libpurple/smiley-list.h | 7 +++
libpurple/smiley-parser.c | 67 ++++++++++++++++++++++++++++++
libpurple/smiley-parser.h | 30 +++++++++++++
libpurple/smiley-theme.c | 9 ++++
libpurple/smiley-theme.h | 1 +
libpurple/smiley.c | 13 +++++
pidgin/gtkconv.c | 4 +-
pidgin/gtksmiley-theme.c | 102 +++++++++++++++++++++++++++++++++++++++++----
10 files changed, 241 insertions(+), 17 deletions(-)
diffs (truncated from 496 to 300 lines):
diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -102,6 +102,7 @@ purple_coresources = \
server.c \
signals.c \
smiley-list.c \
+ smiley-parser.c \
smiley-theme.c \
smiley.c \
dnsquery.c \
@@ -179,6 +180,7 @@ purple_coreheaders = \
server.h \
signals.h \
smiley-list.h \
+ smiley-parser.h \
smiley-theme.h \
smiley.h \
dnsquery.h \
diff --git a/libpurple/smiley-list.c b/libpurple/smiley-list.c
--- a/libpurple/smiley-list.c
+++ b/libpurple/smiley-list.c
@@ -41,9 +41,6 @@ enum
PROP_LAST
};
-static GObjectClass *parent_class;
-static GParamSpec *properties[PROP_LAST];
-
static void
_list_append2(GList **head_p, GList **tail_p, gpointer data)
{
@@ -84,6 +81,12 @@ static void
* API implementation
******************************************************************************/
+PurpleSmileyList *
+purple_smiley_list_new(void)
+{
+ return g_object_new(PURPLE_TYPE_SMILEY_LIST, NULL);
+}
+
gboolean
purple_smiley_list_add(PurpleSmileyList *list, PurpleSmiley *smiley)
{
@@ -138,6 +141,16 @@ purple_smiley_list_remove(PurpleSmileyLi
g_object_unref(smiley);
}
+PurpleTrie *
+purple_smiley_list_get_trie(PurpleSmileyList *list)
+{
+ PurpleSmileyListPrivate *priv = PURPLE_SMILEY_LIST_GET_PRIVATE(list);
+
+ g_return_val_if_fail(priv != NULL, NULL);
+
+ return priv->trie;
+}
+
/*******************************************************************************
* Object stuff
@@ -211,15 +224,11 @@ purple_smiley_list_class_init(PurpleSmil
{
GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
- parent_class = g_type_class_peek_parent(klass);
-
g_type_class_add_private(klass, sizeof(PurpleSmileyListPrivate));
gobj_class->get_property = purple_smiley_list_get_property;
gobj_class->set_property = purple_smiley_list_set_property;
gobj_class->finalize = purple_smiley_list_finalize;
-
- g_object_class_install_properties(gobj_class, PROP_LAST, properties);
}
GType
diff --git a/libpurple/smiley-list.h b/libpurple/smiley-list.h
--- a/libpurple/smiley-list.h
+++ b/libpurple/smiley-list.h
@@ -25,6 +25,7 @@
#include <glib-object.h>
#include "smiley.h"
+#include "trie.h"
typedef struct _PurpleSmileyList PurpleSmileyList;
typedef struct _PurpleSmileyListClass PurpleSmileyListClass;
@@ -68,12 +69,18 @@ G_BEGIN_DECLS
GType
purple_smiley_list_get_type(void);
+PurpleSmileyList *
+purple_smiley_list_new(void);
+
gboolean
purple_smiley_list_add(PurpleSmileyList *list, PurpleSmiley *smiley);
void
purple_smiley_list_remove(PurpleSmileyList *list, PurpleSmiley *smiley);
+PurpleTrie *
+purple_smiley_list_get_trie(PurpleSmileyList *list);
+
G_END_DECLS
#endif /* _PURPLE_SMILEY_H_ */
diff --git a/libpurple/smiley-parser.c b/libpurple/smiley-parser.c
new file mode 100644
--- /dev/null
+++ b/libpurple/smiley-parser.c
@@ -0,0 +1,67 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#include "smiley-parser.h"
+
+#include "smiley-theme.h"
+
+static gboolean purple_smiley_parse_cb(GString *out, const gchar *word,
+ gpointer _smiley, gpointer _unused)
+{
+ PurpleSmiley *smiley = _smiley;
+
+ g_string_append_printf(out, "<img alt=\"%s\" src=\"%s\" />",
+ word, purple_smiley_get_path(smiley));
+
+ return TRUE;
+}
+
+gchar *
+purple_smiley_parse(const gchar *message, gpointer ui_data)
+{
+ PurpleSmileyTheme *theme;
+ PurpleSmileyList *theme_smileys;
+ PurpleTrie *theme_trie;
+
+ if (message == NULL || message[0] == '\0') {
+ purple_debug_info("tomo", "no msg");
+ return g_strdup(message);
+ }
+
+ theme = purple_smiley_theme_get_current();
+ if (theme == NULL) {
+ purple_debug_info("tomo", "no theme");
+ return g_strdup(message);
+ }
+
+ theme_smileys = purple_smiley_theme_get_smileys(theme, ui_data);
+ if (theme_smileys == NULL) {
+ purple_debug_info("tomo", "no smileys");
+ return g_strdup(message);
+ }
+
+ theme_trie = purple_smiley_list_get_trie(theme_smileys);
+ g_return_val_if_fail(theme_trie != NULL, g_strdup(message));
+
+ /* TODO: don't replace text within tags, ie. <span style=":)"> */
+ return purple_trie_replace(theme_trie, message,
+ purple_smiley_parse_cb, NULL);
+}
diff --git a/libpurple/smiley-parser.h b/libpurple/smiley-parser.h
new file mode 100644
--- /dev/null
+++ b/libpurple/smiley-parser.h
@@ -0,0 +1,30 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#ifndef _PURPLE_SMILEY_PARSER_H_
+#define _PURPLE_SMILEY_PARSER_H_
+
+#include "purple.h"
+
+gchar *
+purple_smiley_parse(const gchar *message, gpointer ui_data);
+
+#endif /* _PURPLE_SMILEY_PARSER_H_ */
diff --git a/libpurple/smiley-theme.c b/libpurple/smiley-theme.c
--- a/libpurple/smiley-theme.c
+++ b/libpurple/smiley-theme.c
@@ -43,6 +43,8 @@ purple_smiley_theme_get_smileys(PurpleSm
void
purple_smiley_theme_set_current(PurpleSmileyTheme *theme)
{
+ PurpleSmileyThemeClass *klass;
+
g_return_if_fail(theme == NULL || PURPLE_IS_SMILEY_THEME(theme));
if (theme)
@@ -50,6 +52,13 @@ purple_smiley_theme_set_current(PurpleSm
if (current)
g_object_unref(current);
current = theme;
+
+ if (!theme)
+ return;
+ klass = PURPLE_SMILEY_THEME_GET_CLASS(theme);
+ g_return_if_fail(klass != NULL);
+ if (klass->activate)
+ klass->activate(theme);
}
PurpleSmileyTheme *
diff --git a/libpurple/smiley-theme.h b/libpurple/smiley-theme.h
--- a/libpurple/smiley-theme.h
+++ b/libpurple/smiley-theme.h
@@ -55,6 +55,7 @@ struct _PurpleSmileyThemeClass
PurpleSmileyList * (*get_smileys)(PurpleSmileyTheme *theme,
gpointer ui_data);
+ void (*activate)(PurpleSmileyTheme *theme);
void (*purple_reserved1)(void);
void (*purple_reserved2)(void);
diff --git a/libpurple/smiley.c b/libpurple/smiley.c
--- a/libpurple/smiley.c
+++ b/libpurple/smiley.c
@@ -138,6 +138,12 @@ purple_smiley_get_property(GObject *obje
case PROP_SHORTCUT:
g_value_set_string(value, priv->shortcut);
break;
+ case PROP_IS_READY:
+ g_value_set_boolean(value, priv->is_ready);
+ break;
+ case PROP_PATH:
+ g_value_set_string(value, priv->path);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, par_id, pspec);
break;
@@ -156,6 +162,13 @@ purple_smiley_set_property(GObject *obje
g_free(priv->shortcut);
priv->shortcut = g_strdup(g_value_get_string(value));
break;
+ case PROP_IS_READY:
+ priv->is_ready = g_value_get_boolean(value);
+ break;
+ case PROP_PATH:
+ g_free(priv->path);
+ priv->path = g_strdup(g_value_get_string(value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, par_id, pspec);
break;
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -41,6 +41,7 @@
#include "notify.h"
#include "prpl.h"
#include "request.h"
+#include "smiley-parser.h"
#include "theme-loader.h"
#include "theme-manager.h"
#include "util.h"
@@ -6710,7 +6711,8 @@ pidgin_conv_write_conv(PurpleConversatio
gtkconv->last_flags = flags;
gtkconv->last_conversed = conv;
- smileyed = pidgin_smiley_parse_markup(displaying, purple_account_get_protocol_id(account));
+ smileyed = purple_smiley_parse(displaying,
+ (gpointer)purple_account_get_protocol_name(account));
More information about the Commits
mailing list