/dev/tomkiewicz/new-smileys: 34964f8d43fe: Remote smileys: initi...

Tomasz Wasilczyk twasilczyk at pidgin.im
Fri Apr 4 06:15:46 EDT 2014


Changeset: 34964f8d43fe2794678973f300bd2a2af5b781a9
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-04 12:15 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/34964f8d43fe

Description:

Remote smileys: initial implementation

diffstat:

 libpurple/Makefile.am     |    2 +
 libpurple/conversation.c  |   42 +++++++++++++
 libpurple/conversation.h  |    9 ++
 libpurple/imgstore.h      |    1 +
 libpurple/smiley-custom.c |    1 +
 libpurple/smiley-remote.c |  142 ++++++++++++++++++++++++++++++++++++++++++++++
 libpurple/smiley-remote.h |   81 ++++++++++++++++++++++++++
 libpurple/smiley.h        |    5 +-
 pidgin/gtksmiley-theme.h  |    1 +
 9 files changed, 281 insertions(+), 3 deletions(-)

diffs (truncated from 394 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -104,6 +104,7 @@ purple_coresources = \
 	smiley-custom.c \
 	smiley-list.c \
 	smiley-parser.c \
+	smiley-remote.c \
 	smiley-theme.c \
 	smiley.c \
 	dnsquery.c \
@@ -183,6 +184,7 @@ purple_coreheaders = \
 	smiley-custom.h \
 	smiley-list.h \
 	smiley-parser.h \
+	smiley-remote.h \
 	smiley-theme.h \
 	smiley.h \
 	dnsquery.h \
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -34,6 +34,7 @@
 #include "prpl.h"
 #include "request.h"
 #include "signals.h"
+#include "smiley-list.h"
 #include "util.h"
 
 #define PURPLE_CONVERSATION_GET_PRIVATE(obj) \
@@ -60,6 +61,11 @@ struct _PurpleConversationPrivate
 	                                       PurpleConversationMessage's       */
 
 	PurpleE2eeState *e2ee_state;      /* End-to-end encryption state.      */
+
+	/* The list of remote smileys. This should be per-buddy (PurpleBuddy),
+	 * but we don't have any class for people not on our buddy
+	 * list (PurpleDude?). So, if we have one, we should switch to it. */
+	PurpleSmileyList *remote_smileys;
 };
 
 /*
@@ -989,6 +995,42 @@ purple_conversation_get_max_message_size
 	return prpl_info->get_max_message_size(conv);
 }
 
+PurpleRemoteSmiley *
+purple_conversation_add_remote_smiley(PurpleConversation *conv,
+	const gchar *shortcut)
+{
+	PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+	PurpleSmiley *smiley;
+
+	g_return_val_if_fail(priv != NULL, NULL);
+	g_return_val_if_fail(shortcut != NULL, NULL);
+	g_return_val_if_fail(shortcut[0] != '\0', NULL);
+
+	if (priv->remote_smileys == NULL)
+		priv->remote_smileys = purple_smiley_list_new();
+
+	smiley = purple_smiley_list_get_by_shortcut(
+		priv->remote_smileys, shortcut);
+	if (!PURPLE_IS_REMOTE_SMILEY(smiley)) {
+		purple_debug_warning("conversation", "Invalid type of smiley "
+			"stored in remote smileys list");
+		return NULL;
+	}
+
+	return PURPLE_REMOTE_SMILEY(smiley);
+}
+
+PurpleSmileyList *
+purple_conversation_get_remote_smileys(PurpleConversation *conv)
+{
+	PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->remote_smileys;
+}
+
+
 /**************************************************************************
  * GObject code
  **************************************************************************/
diff --git a/libpurple/conversation.h b/libpurple/conversation.h
--- a/libpurple/conversation.h
+++ b/libpurple/conversation.h
@@ -195,6 +195,8 @@ struct _PurpleConversationClass {
 #include "buddyicon.h"
 #include "e2ee.h"
 #include "log.h"
+#include "smiley-list.h"
+#include "smiley-remote.h"
 
 /**************************************************************************/
 /** PurpleConversationUiOps                                               */
@@ -734,6 +736,13 @@ gboolean purple_conversation_do_command(
 gssize
 purple_conversation_get_max_message_size(PurpleConversation *conv);
 
+PurpleRemoteSmiley *
+purple_conversation_add_remote_smiley(PurpleConversation *conv,
+	const gchar *shortcut);
+
+PurpleSmileyList *
+purple_conversation_get_remote_smileys(PurpleConversation *conv);
+
 /**************************************************************************/
 /* Conversation Helper API                                                */
 /**************************************************************************/
diff --git a/libpurple/imgstore.h b/libpurple/imgstore.h
--- a/libpurple/imgstore.h
+++ b/libpurple/imgstore.h
@@ -33,6 +33,7 @@
  */
 
 #include <glib.h>
+#include <glib-object.h>
 
 #define PURPLE_STORED_IMAGE_PROTOCOL "purple-image:"
 #define PURPLE_STOCK_IMAGE_PROTOCOL "purple-stock-image:"
diff --git a/libpurple/smiley-custom.c b/libpurple/smiley-custom.c
--- a/libpurple/smiley-custom.c
+++ b/libpurple/smiley-custom.c
@@ -22,6 +22,7 @@
 #include "smiley-custom.h"
 
 #include "debug.h"
+#include "util.h"
 
 #include <glib/gstdio.h>
 #include <errno.h>
diff --git a/libpurple/smiley-remote.c b/libpurple/smiley-remote.c
new file mode 100644
--- /dev/null
+++ b/libpurple/smiley-remote.c
@@ -0,0 +1,142 @@
+/* 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 "internal.h"
+#include "glibcompat.h"
+
+#include "smiley.h"
+#include "smiley-remote.h"
+
+#define PURPLE_REMOTE_SMILEY_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_REMOTE_SMILEY, PurpleRemoteSmileyPrivate))
+
+typedef struct {
+} PurpleRemoteSmileyPrivate;
+
+#if 0
+enum
+{
+	PROP_0,
+	PROP_LAST
+};
+
+enum
+{
+	SIG_READY,
+	SIG_LAST
+};
+#endif
+
+static GObjectClass *parent_class;
+
+#if 0
+static guint signals[SIG_LAST];
+static GParamSpec *properties[PROP_LAST];
+#endif
+
+/******************************************************************************
+ * API implementation
+ ******************************************************************************/
+
+/******************************************************************************
+ * Object stuff
+ ******************************************************************************/
+
+#if 0
+static void
+purple_remote_smiley_init(GTypeInstance *instance, gpointer klass)
+{
+	PurpleRemoteSmiley *smiley = PURPLE_REMOTE_SMILEY(instance);
+}
+
+static void
+purple_remote_smiley_finalize(GObject *obj)
+{
+	PurpleRemoteSmiley *smiley = PURPLE_REMOTE_SMILEY(obj);
+	PurpleRemoteSmileyPrivate *priv = PURPLE_REMOTE_SMILEY_GET_PRIVATE(smiley);
+}
+
+static void
+purple_remote_smiley_get_property(GObject *object, guint par_id, GValue *value,
+	GParamSpec *pspec)
+{
+	PurpleRemoteSmiley *remote_smiley = PURPLE_REMOTE_SMILEY(object);
+	PurpleRemoteSmileyPrivate *priv = PURPLE_REMOTE_SMILEY_GET_PRIVATE(remote_smiley);
+
+	switch (par_id) {
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, par_id, pspec);
+			break;
+	}
+}
+
+static void
+purple_remote_smiley_set_property(GObject *object, guint par_id, const GValue *value,
+	GParamSpec *pspec)
+{
+	PurpleRemoteSmiley *remote_smiley = PURPLE_REMOTE_SMILEY(object);
+	PurpleRemoteSmileyPrivate *priv = PURPLE_REMOTE_SMILEY_GET_PRIVATE(remote_smiley);
+
+	switch (par_id) {
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, par_id, pspec);
+			break;
+	}
+}
+#endif
+
+static void
+purple_remote_smiley_class_init(PurpleRemoteSmileyClass *klass)
+{
+//	GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
+
+	parent_class = g_type_class_peek_parent(klass);
+
+	g_type_class_add_private(klass, sizeof(PurpleRemoteSmileyPrivate));
+
+#if 0
+	gobj_class->get_property = purple_remote_smiley_get_property;
+	gobj_class->set_property = purple_remote_smiley_set_property;
+	gobj_class->finalize = purple_remote_smiley_finalize;
+
+	g_object_class_install_properties(gobj_class, PROP_LAST, properties);
+#endif
+}
+
+GType
+purple_remote_smiley_get_type(void)
+{
+	static GType type = 0;
+
+	if (G_UNLIKELY(type == 0)) {
+		static const GTypeInfo info = {
+			.class_size = sizeof(PurpleRemoteSmileyClass),
+			.class_init = (GClassInitFunc)purple_remote_smiley_class_init,
+			.instance_size = sizeof(PurpleRemoteSmiley),
+//			.instance_init = purple_remote_smiley_init,
+		};
+
+		type = g_type_register_static(PURPLE_TYPE_REMOTE_SMILEY,
+			"PurpleRemoteSmiley", &info, 0);
+	}
+
+	return type;
+}
diff --git a/libpurple/smiley-remote.h b/libpurple/smiley-remote.h
new file mode 100644
--- /dev/null
+++ b/libpurple/smiley-remote.h
@@ -0,0 +1,81 @@
+/* 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.



More information about the Commits mailing list