/soc/2015/igor.gajowiak/chatlog: 0a6e7f41b611: Add an initial ch...

Igor Gajowiak igor.gajowiak at gmail.com
Wed Jun 24 13:31:31 EDT 2015


Changeset: 0a6e7f41b6115553a6fc4efe2806dd9f7b4f455a
Author:	 Igor Gajowiak <igor.gajowiak at gmail.com>
Date:	 2015-06-21 22:29 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/igor.gajowiak/chatlog/rev/0a6e7f41b611

Description:

Add an initial chat log interface.

diffstat:

 libpurple/Makefile.am  |    2 +
 libpurple/genericlog.c |  197 +++++++++++++++++++++++++++++++++++++++++++++++++
 libpurple/genericlog.h |  111 +++++++++++++++++++++++++++
 3 files changed, 310 insertions(+), 0 deletions(-)

diffs (truncated from 337 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -72,6 +72,7 @@ purple_coresources = \
 	image-store.c \
 	keyring.c \
 	log.c \
+	genericlog.c \
 	media/backend-fs2.c \
 	media/backend-iface.c \
 	media/candidate.c \
@@ -158,6 +159,7 @@ purple_coreheaders = \
 	image-store.h \
 	keyring.h \
 	log.h \
+	genericlog.h \
 	media.h \
 	mediamanager.h \
 	memorypool.h \
diff --git a/libpurple/genericlog.c b/libpurple/genericlog.c
new file mode 100644
--- /dev/null
+++ b/libpurple/genericlog.c
@@ -0,0 +1,197 @@
+/* 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 "genericlog.h"
+
+#define PURPLE_GENERICLOG_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_GENERICLOG, PurpleGenericLogPrivate))
+
+typedef struct
+{
+	gchar *id;
+	gchar *name;
+} PurpleGenericLogPrivate;
+
+enum
+{
+	PROP_0,
+	PROP_ID,
+	PROP_NAME,
+	PROP_LAST
+};
+
+static GObjectClass *parent_class;
+static GParamSpec *properties[PROP_LAST];
+
+/**************************************************************************/
+/* API implementation
+/**************************************************************************/
+
+
+
+/**************************************************************************/
+/* Error Codes
+/**************************************************************************/
+
+GQuark purple_genericlog_error_domain(void)
+{
+	return g_quark_from_static_string("libpurple generic log");
+}
+
+/**************************************************************************/
+/* GObject stuff
+/**************************************************************************/
+
+static void
+purple_genericlog_instance_init(GTypeInstance *instance, gpointer klass)
+{
+}
+
+static void
+purple_genericlog_finalize(GObject *obj)
+{
+	PurpleGenericLog *log = PURPLE_GENERICLOG(obj);
+	PurpleGenericLogPrivate *priv = PURPLE_GENERICLOG_GET_PRIVATE(log);
+
+	g_free(priv->id);
+	g_free(priv->name);
+
+	G_OBJECT_CLASS(parent_class)->finalize(obj);
+}
+
+static void
+purple_genericlog_get_property(GObject *object, guint par_id, GValue *value,
+    GParamSpec *pspec)
+{
+	PurpleGenericLog *log = PURPLE_GENERICLOG(object);
+	PurpleGenericLogPrivate *priv = PURPLE_GENERICLOG_GET_PRIVATE(log);
+
+	switch (par_id) {
+		case PROP_ID:
+			g_value_set_string(value, priv->id);
+			break;
+		case PROP_NAME:
+			g_value_set_string(value, priv->name);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, par_id, pspec);
+			break;
+	}
+}
+
+static void
+purple_genericlog_set_property(GObject *object, guint par_id, const GValue *value,
+    GParamSpec *pspec)
+{
+	PurpleGenericLog *log = PURPLE_GENERICLOG(object);
+	PurpleGenericLogPrivate *priv = PURPLE_GENERICLOG_GET_PRIVATE(log);
+
+	switch (par_id) {
+		case PROP_ID:
+			g_free(priv->id);
+			priv->id = g_strdup(g_value_get_string(value));
+			break;
+		case PROP_NAME:
+			g_free(priv->name);
+			priv->name = g_strdup(g_value_get_string(value));
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, par_id, pspec);
+			break;
+	}
+}
+
+static void
+purple_genericlog_class_init(PurpleGenericLogClass *klass)
+{
+	/*
+	 * Implemented by derived types
+	 */
+	klass->log_im = NULL;
+	klass->mark_as_read = NULL;
+	klass->get_conversations = NULL;
+	klass->get_messages = NULL;
+
+	klass->reserved1 = NULL;
+	klass->reserved2 = NULL;
+	klass->reserved3 = NULL;
+	klass->reserved4 = NULL;
+
+	GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
+
+	parent_class = g_type_class_peek_parent(klass);
+
+	g_type_class_add_private(klass, sizeof(PurpleGenericLogPrivate));
+
+	gobj_class->finalize = purple_genericlog_finalize;
+	gobj_class->get_property = purple_genericlog_get_property;
+	gobj_class->set_property = purple_genericlog_set_property;
+
+	properties[PROP_ID] = g_param_spec_string("id",
+		"ID", "The ID of the log.",
+		NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+	properties[PROP_NAME] = g_param_spec_string("name",
+		"Name", "A user friendly log name.",
+		NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+	g_object_class_install_properties(gobj_class, PROP_LAST, properties);
+}
+
+GType purple_genericlog_get_type(void)
+{
+	static GType type = 0;
+	if (G_UNLIKELY(type == 0)) {
+
+		static const GTypeInfo info = {
+			.class_size = sizeof(PurpleGenericLogClass),
+			.class_init = (GClassInitFunc)purple_genericlog_class_init,
+			.instance_size = sizeof(PurpleMessage),
+			.instance_init = purple_genericlog_instance_init,
+		};
+
+		type = g_type_register_static(G_TYPE_OBJECT, "PurpleGenericLog", &info, 0);
+	}
+
+	return type;
+}
+
+/**************************************************************************/
+/* Log Subsystem
+/**************************************************************************/
+
+void
+purple_logng_init(void)
+{
+	// TODO: implement this
+}
+
+void
+purple_logng_uninit(void)
+{
+	// TODO: implement this
+}
+
+void *
+purple_logng_get_handle(void)
+{
+	static int handle;
+	return &handle;
+}
diff --git a/libpurple/genericlog.h b/libpurple/genericlog.h
new file mode 100644
--- /dev/null
+++ b/libpurple/genericlog.h
@@ -0,0 +1,111 @@
+/* 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_GENERICLOG_H_
+#define _PURPLE_GENERICLOG_H_
+
+#include <stddef.h>
+#include <time.h>
+
+#include <glib-object.h>
+
+#include "account.h"
+#include "conversation.h"
+#include "message.h"
+
+#define PURPLE_TYPE_GENERICLOG              (purple_genericlog_get_type())
+#define PURPLE_GENERICLOG(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_TYPE_GENERICLOG, PurpleGenericLog))
+#define PURPLE_IS_GENERICLOG(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_TYPE_GENERICLOG))
+#define PURPLE_GENERICLOG_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_TYPE_GENERICLOG, PurpleGenericLogClass))
+#define PURPLE_IS_GENERICLOG_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_TYPE_GENERICLOG))
+#define PURPLE_GENERICLOG_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_TYPE_GENERICLOG, PurpleGenericLogClass))
+
+typedef struct _PurpleGenericLog        PurpleGenericLog;
+typedef struct _PurpleGenericLogClass   PurpleGenericLogClass;
+
+struct _PurpleGenericLog
+{
+	/*< private >*/
+	GObject parent_instance;
+};
+
+struct _PurpleGenericLogClass
+{
+	/*< private >*/
+	GObjectClass parent_class;
+
+	GError* (*log_im) (PurpleAccount *account,
+	    PurpleConversation* conv, PurpleMessage *message);
+
+	GError* (*mark_as_read)(PurpleMessage *message);
+
+	GError* (*get_conversations)(PurpleAccount *account,
+	    GList **result, time_t timestamp, size_t limit);
+
+	GError* (*get_messages)(PurpleAccount *account, PurpleConversation* conv,
+		GList **result, time_t timestamp, size_t limit);
+
+	// TODO: Other APIs?
+
+	void (*reserved1)(void);
+	void (*reserved2)(void);
+	void (*reserved3)(void);
+	void (*reserved4)(void);
+};
+
+/**************************************************************************/



More information about the Commits mailing list