aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2009-03-06 19:51:32 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2009-03-06 19:51:32 +0800
commitb51a83c1297f7ba3f550d8f31439b2d5b4e86c99 (patch)
tree5f67ad4ac3867947d7937d96c0068a170d75a4ba /libempathy
parent255122bf7551636726abccf659e68a9c9e1b6bd7 (diff)
downloadgsoc2013-empathy-b51a83c1297f7ba3f550d8f31439b2d5b4e86c99.tar
gsoc2013-empathy-b51a83c1297f7ba3f550d8f31439b2d5b4e86c99.tar.gz
gsoc2013-empathy-b51a83c1297f7ba3f550d8f31439b2d5b4e86c99.tar.bz2
gsoc2013-empathy-b51a83c1297f7ba3f550d8f31439b2d5b4e86c99.tar.lz
gsoc2013-empathy-b51a83c1297f7ba3f550d8f31439b2d5b4e86c99.tar.xz
gsoc2013-empathy-b51a83c1297f7ba3f550d8f31439b2d5b4e86c99.tar.zst
gsoc2013-empathy-b51a83c1297f7ba3f550d8f31439b2d5b4e86c99.zip
Made EmpathyLogSource an interface and EmpathyLogSourceEmpathy extend it.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk> svn path=/trunk/; revision=2582
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/Makefile.am2
-rw-r--r--libempathy/empathy-log-manager.c71
-rw-r--r--libempathy/empathy-log-manager.h19
-rw-r--r--libempathy/empathy-log-source-empathy.c171
-rw-r--r--libempathy/empathy-log-source.c112
-rw-r--r--libempathy/empathy-log-source.h87
6 files changed, 334 insertions, 128 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am
index 053c0c8e9..085c6b999 100644
--- a/libempathy/Makefile.am
+++ b/libempathy/Makefile.am
@@ -36,6 +36,8 @@ libempathy_la_SOURCES = \
empathy-irc-network-manager.c \
empathy-irc-server.c \
empathy-log-manager.c \
+ empathy-log-source.c \
+ empathy-log-source-empathy.c \
empathy-message.c \
empathy-status-presets.c \
empathy-time.c \
diff --git a/libempathy/empathy-log-manager.c b/libempathy/empathy-log-manager.c
index abd4d7515..c9b5a3049 100644
--- a/libempathy/empathy-log-manager.c
+++ b/libempathy/empathy-log-manager.c
@@ -29,8 +29,8 @@
#include <glib/gstdio.h>
#include "empathy-log-manager.h"
-#include "empathy-contact.h"
-#include "empathy-time.h"
+#include "empathy-log-source-empathy.h"
+#include "empathy-log-source.h"
#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
@@ -64,7 +64,8 @@ log_manager_finalize (GObject *object)
for (l = priv->sources; l; l = l->next)
{
- g_slice_free (EmpathyLogSource, l->data);
+ EmpathyLogSource *source = (EmpathyLogSource *) l->data;
+ g_object_unref (source);
}
g_list_free (priv->sources);
@@ -115,7 +116,10 @@ empathy_log_manager_init (EmpathyLogManager *manager)
EMPATHY_TYPE_LOG_MANAGER, EmpathyLogManagerPriv);
priv->sources = g_list_append (priv->sources,
- empathy_log_source_empathy_get_source ());
+ g_object_new (EMPATHY_TYPE_LOG_SOURCE_EMPATHY, NULL));
+
+/* priv->sources = g_list_append (priv->sources,
+ g_object_new (EMPATHY_LOG_SOURCE_PIDGIN, NULL));*/
manager->priv = priv;
@@ -146,12 +150,8 @@ empathy_log_manager_add_message (EmpathyLogManager *manager,
for (l = priv->sources; l; l = l->next)
{
- EmpathyLogSource *source = (EmpathyLogSource *) l->data;
-
- if (!source->add_message)
- continue;
-
- source->add_message (manager, chat_id, chatroom, message);
+ empathy_log_source_add_message (EMPATHY_LOG_SOURCE (l->data),
+ chat_id, chatroom, message);
}
}
@@ -172,12 +172,8 @@ empathy_log_manager_exists (EmpathyLogManager *manager,
for (l = priv->sources; l; l = l->next)
{
- EmpathyLogSource *source = (EmpathyLogSource *) l->data;
-
- if (!source->exists)
- continue;
-
- if (source->exists (manager, account, chat_id, chatroom))
+ if (empathy_log_source_exists (EMPATHY_LOG_SOURCE (l->data),
+ account, chat_id, chatroom))
return TRUE;
}
@@ -212,16 +208,14 @@ empathy_log_manager_get_dates (EmpathyLogManager *manager,
for (l = priv->sources; l; l = l->next)
{
- EmpathyLogSource *source = (EmpathyLogSource *) l->data;
-
- if (!source->get_dates)
- continue;
+ EmpathyLogSource *source = EMPATHY_LOG_SOURCE (l->data);
if (!out)
- out = source->get_dates (manager, account, chat_id, chatroom);
+ out = empathy_log_source_get_dates (source, account, chat_id, chatroom);
else
{
- GList *new = source->get_dates (manager, account, chat_id, chatroom);
+ GList *new = empathy_log_source_get_dates (source, account, chat_id,
+ chatroom);
g_list_foreach (new, log_manager_get_dates_foreach, out);
g_list_foreach (new, (GFunc) g_free, NULL);
@@ -253,17 +247,14 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager,
for (l = priv->sources; l; l = l->next)
{
- EmpathyLogSource *source = (EmpathyLogSource *) l->data;
-
- if (!source->get_messages_for_date)
- continue;
+ EmpathyLogSource *source = EMPATHY_LOG_SOURCE (l->data);
if (!out)
- out = source->get_messages_for_date (manager, account, chat_id,
- chatroom, date);
+ out = empathy_log_source_get_messages_for_date (source, account,
+ chat_id, chatroom, date);
else
- out = g_list_concat (out, source->get_messages_for_date (manager,
- account, chat_id, chatroom, date));
+ out = g_list_concat (out, empathy_log_source_get_messages_for_date (
+ source, account, chat_id, chatroom, date));
}
return out;
@@ -310,15 +301,13 @@ empathy_log_manager_get_chats (EmpathyLogManager *manager,
for (l = priv->sources; l; l = l->next)
{
- EmpathyLogSource *source = (EmpathyLogSource *) l->data;
-
- if (!source->get_chats)
- continue;
+ EmpathyLogSource *source = EMPATHY_LOG_SOURCE (l->data);
if (!out)
- out = source->get_chats (manager, account);
+ out = empathy_log_source_get_chats (source, account);
else
- out = g_list_concat (out, source->get_chats (manager, account));
+ out = g_list_concat (out,
+ empathy_log_source_get_chats (source, account));
}
return out;
@@ -338,15 +327,13 @@ empathy_log_manager_search_new (EmpathyLogManager *manager,
for (l = priv->sources; l; l = l->next)
{
- EmpathyLogSource *source = (EmpathyLogSource *) l->data;
-
- if (!source->search_new)
- continue;
+ EmpathyLogSource *source = EMPATHY_LOG_SOURCE (l->data);
if (!out)
- out = source->search_new (manager, text);
+ out = empathy_log_source_search_new (source, text);
else
- out = g_list_concat (out, source->search_new (manager, text));
+ out = g_list_concat (out,
+ empathy_log_source_search_new (source, text));
}
return out;
diff --git a/libempathy/empathy-log-manager.h b/libempathy/empathy-log-manager.h
index b8f86efd7..fa9e39b7b 100644
--- a/libempathy/empathy-log-manager.h
+++ b/libempathy/empathy-log-manager.h
@@ -50,7 +50,6 @@ G_BEGIN_DECLS
typedef struct _EmpathyLogManager EmpathyLogManager;
typedef struct _EmpathyLogManagerClass EmpathyLogManagerClass;
typedef struct _EmpathyLogSearchHit EmpathyLogSearchHit;
-typedef struct _EmpathyLogSource EmpathyLogSource;
struct _EmpathyLogManager
{
@@ -72,24 +71,6 @@ struct _EmpathyLogSearchHit
gchar *date;
};
-struct _EmpathyLogSource
-{
- gboolean (*exists) (EmpathyLogManager *manager, McAccount *account,
- const gchar *chat_id, gboolean chatroom);
- void (*add_message) (EmpathyLogManager *manager, const gchar *chat_id,
- gboolean chatroom, EmpathyMessage *message);
- GList * (*get_dates) (EmpathyLogManager *manager, McAccount *account,
- const gchar *chat_id, gboolean chatroom);
- GList * (*get_messages_for_date) (EmpathyLogManager *manager,
- McAccount *account, const gchar *chat_id, gboolean chatroom,
- const gchar *date);
- GList * (*get_last_messages) (EmpathyLogManager *manager, McAccount *account,
- const gchar *chat_id, gboolean chatroom);
- GList * (*get_chats) (EmpathyLogManager *manager,
- McAccount *account);
- GList * (*search_new) (EmpathyLogManager *manager, const gchar *text);
-};
-
GType empathy_log_manager_get_type (void) G_GNUC_CONST;
EmpathyLogManager *empathy_log_manager_dup_singleton (void);
void empathy_log_manager_add_message (EmpathyLogManager *manager,
diff --git a/libempathy/empathy-log-source-empathy.c b/libempathy/empathy-log-source-empathy.c
index d6804683c..25270ae74 100644
--- a/libempathy/empathy-log-source-empathy.c
+++ b/libempathy/empathy-log-source-empathy.c
@@ -19,6 +19,7 @@
* Boston, MA 02111-1307, USA.
*
* Authors: Xavier Claessens <xclaesse@gmail.com>
+ * Jonny Lamb <jonny.lamb@collabora.co.uk>
*/
#include <config.h>
@@ -28,8 +29,9 @@
#include <stdlib.h>
#include <glib/gstdio.h>
-#include "empathy-log-manager.h"
+#include "empathy-log-source.h"
#include "empathy-log-source-empathy.h"
+#include "empathy-log-manager.h"
#include "empathy-contact.h"
#include "empathy-time.h"
#include "empathy-utils.h"
@@ -51,35 +53,71 @@
#define LOG_FOOTER \
"</log>\n"
-static gchar *
-log_source_empathy_get_basedir (void)
+
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLogSourceEmpathy)
+typedef struct
+{
+ gchar *basedir;
+} EmpathyLogSourceEmpathyPriv;
+
+static void log_source_iface_init (gpointer g_iface,gpointer iface_data);
+
+G_DEFINE_TYPE_WITH_CODE (EmpathyLogSourceEmpathy, empathy_log_source_empathy,
+ G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_LOG_SOURCE,
+ log_source_iface_init));
+
+static void
+log_source_empathy_finalize (GObject *object)
+{
+ EmpathyLogSourceEmpathy *self = EMPATHY_LOG_SOURCE_EMPATHY (object);
+ EmpathyLogSourceEmpathyPriv *priv = GET_PRIV (self);
+
+ g_free (priv->basedir);
+}
+
+static void
+empathy_log_source_empathy_class_init (EmpathyLogSourceEmpathyClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = log_source_empathy_finalize;
+
+ g_type_class_add_private (object_class, sizeof (EmpathyLogSourceEmpathyPriv));
+}
+
+static void
+empathy_log_source_empathy_init (EmpathyLogSourceEmpathy *self)
{
- return g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (),
+ EmpathyLogSourceEmpathyPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EMPATHY_TYPE_LOG_SOURCE_EMPATHY, EmpathyLogSourceEmpathyPriv);
+
+ self->priv = priv;
+
+ priv->basedir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (),
".gnome2", PACKAGE_NAME, "logs", NULL);
}
static gchar *
-log_source_empathy_get_dir (EmpathyLogManager *manager,
+log_source_empathy_get_dir (EmpathyLogSource *self,
McAccount *account,
const gchar *chat_id,
gboolean chatroom)
{
const gchar *account_id;
- gchar *basedir, *log_dir;
+ gchar *basedir;
+ EmpathyLogSourceEmpathyPriv *priv;
- account_id = mc_account_get_unique_name (account);
+ priv = GET_PRIV (self);
- log_dir = log_source_empathy_get_basedir ();
+ account_id = mc_account_get_unique_name (account);
if (chatroom)
- basedir = g_build_path (G_DIR_SEPARATOR_S, log_dir, account_id,
+ basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, account_id,
LOG_DIR_CHATROOMS, chat_id, NULL);
else
- basedir = g_build_path (G_DIR_SEPARATOR_S, log_dir,
+ basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir,
account_id, chat_id, NULL);
- g_free (log_dir);
-
return basedir;
}
@@ -111,7 +149,7 @@ log_source_empathy_get_timestamp_from_message (EmpathyMessage *message)
}
static gchar *
-log_source_empathy_get_filename (EmpathyLogManager *manager,
+log_source_empathy_get_filename (EmpathyLogSource *self,
McAccount *account,
const gchar *chat_id,
gboolean chatroom)
@@ -120,7 +158,7 @@ log_source_empathy_get_filename (EmpathyLogManager *manager,
gchar *timestamp;
gchar *filename;
- basedir = log_source_empathy_get_dir (manager, account, chat_id, chatroom);
+ basedir = log_source_empathy_get_dir (self, account, chat_id, chatroom);
timestamp = log_source_empathy_get_timestamp_filename ();
filename = g_build_filename (basedir, timestamp, NULL);
@@ -131,7 +169,7 @@ log_source_empathy_get_filename (EmpathyLogManager *manager,
}
static void
-log_source_empathy_add_message (EmpathyLogManager *manager,
+log_source_empathy_add_message (EmpathyLogSource *self,
const gchar *chat_id,
gboolean chatroom,
EmpathyMessage *message)
@@ -151,7 +189,7 @@ log_source_empathy_add_message (EmpathyLogManager *manager,
gchar *contact_id;
TpChannelTextMessageType msg_type;
- g_return_if_fail (EMPATHY_IS_LOG_MANAGER (manager));
+ g_return_if_fail (EMPATHY_IS_LOG_SOURCE (self));
g_return_if_fail (chat_id != NULL);
g_return_if_fail (EMPATHY_IS_MESSAGE (message));
@@ -163,7 +201,7 @@ log_source_empathy_add_message (EmpathyLogManager *manager,
if (G_STR_EMPTY (body_str))
return;
- filename = log_source_empathy_get_filename (manager, account, chat_id, chatroom);
+ filename = log_source_empathy_get_filename (self, account, chat_id, chatroom);
basedir = g_path_get_dirname (filename);
if (!g_file_test (basedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
{
@@ -219,7 +257,7 @@ log_source_empathy_add_message (EmpathyLogManager *manager,
}
static gboolean
-log_source_empathy_exists (EmpathyLogManager *manager,
+log_source_empathy_exists (EmpathyLogSource *self,
McAccount *account,
const gchar *chat_id,
gboolean chatroom)
@@ -227,7 +265,7 @@ log_source_empathy_exists (EmpathyLogManager *manager,
gchar *dir;
gboolean exists;
- dir = log_source_empathy_get_dir (manager, account, chat_id, chatroom);
+ dir = log_source_empathy_get_dir (self, account, chat_id, chatroom);
exists = g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR);
g_free (dir);
@@ -235,7 +273,7 @@ log_source_empathy_exists (EmpathyLogManager *manager,
}
static GList *
-log_source_empathy_get_dates (EmpathyLogManager *manager,
+log_source_empathy_get_dates (EmpathyLogSource *self,
McAccount *account,
const gchar *chat_id,
gboolean chatroom)
@@ -247,11 +285,11 @@ log_source_empathy_get_dates (EmpathyLogManager *manager,
const gchar *filename;
const gchar *p;
- g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL);
+ g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), NULL);
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (chat_id != NULL, NULL);
- directory = log_source_empathy_get_dir (manager, account, chat_id, chatroom);
+ directory = log_source_empathy_get_dir (self, account, chat_id, chatroom);
dir = g_dir_open (directory, 0, NULL);
if (!dir)
{
@@ -288,7 +326,7 @@ log_source_empathy_get_dates (EmpathyLogManager *manager,
}
static gchar *
-log_source_empathy_get_filename_for_date (EmpathyLogManager *manager,
+log_source_empathy_get_filename_for_date (EmpathyLogSource *self,
McAccount *account,
const gchar *chat_id,
gboolean chatroom,
@@ -298,7 +336,7 @@ log_source_empathy_get_filename_for_date (EmpathyLogManager *manager,
gchar *timestamp;
gchar *filename;
- basedir = log_source_empathy_get_dir (manager, account, chat_id, chatroom);
+ basedir = log_source_empathy_get_dir (self, account, chat_id, chatroom);
timestamp = g_strconcat (date, LOG_FILENAME_SUFFIX, NULL);
filename = g_build_filename (basedir, timestamp, NULL);
@@ -309,7 +347,7 @@ log_source_empathy_get_filename_for_date (EmpathyLogManager *manager,
}
static EmpathyLogSearchHit *
-log_source_empathy_search_hit_new (EmpathyLogManager *manager,
+log_source_empathy_search_hit_new (EmpathyLogSource *self,
const gchar *filename)
{
EmpathyLogSearchHit *hit;
@@ -345,7 +383,7 @@ log_source_empathy_search_hit_new (EmpathyLogManager *manager,
}
static GList *
-log_source_empathy_get_messages_for_file (EmpathyLogManager *manager,
+log_source_empathy_get_messages_for_file (EmpathyLogSource *self,
const gchar *filename)
{
GList *messages = NULL;
@@ -356,7 +394,7 @@ log_source_empathy_get_messages_for_file (EmpathyLogManager *manager,
EmpathyLogSearchHit *hit;
McAccount *account;
- g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL);
+ g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), NULL);
g_return_val_if_fail (filename != NULL, NULL);
DEBUG ("Attempting to parse filename:'%s'...", filename);
@@ -368,7 +406,7 @@ log_source_empathy_get_messages_for_file (EmpathyLogManager *manager,
}
/* Get the account from the filename */
- hit = log_source_empathy_search_hit_new (manager, filename);
+ hit = log_source_empathy_search_hit_new (self, filename);
account = g_object_ref (hit->account);
empathy_log_manager_search_hit_free (hit);
@@ -459,22 +497,22 @@ log_source_empathy_get_messages_for_file (EmpathyLogManager *manager,
}
static GList *
-log_source_empathy_get_all_files (EmpathyLogManager *manager,
+log_source_empathy_get_all_files (EmpathyLogSource *self,
const gchar *dir)
{
GDir *gdir;
GList *files = NULL;
const gchar *name;
- gchar *basedir;
+ const gchar *basedir;
+ EmpathyLogSourceEmpathyPriv *priv;
- basedir = dir ? g_strdup (dir) : log_source_empathy_get_basedir ();
+ priv = GET_PRIV (self);
+
+ basedir = dir ? dir : priv->basedir;
gdir = g_dir_open (basedir, 0, NULL);
if (!gdir)
- {
- g_free (basedir);
- return NULL;
- }
+ return NULL;
while ((name = g_dir_read_name (gdir)) != NULL)
{
@@ -490,32 +528,32 @@ log_source_empathy_get_all_files (EmpathyLogManager *manager,
if (g_file_test (filename, G_FILE_TEST_IS_DIR))
{
/* Recursively get all log files */
- files = g_list_concat (files, log_source_empathy_get_all_files (manager, filename));
+ files = g_list_concat (files,
+ log_source_empathy_get_all_files (self, filename));
}
g_free (filename);
}
g_dir_close (gdir);
- g_free (basedir);
return files;
}
static GList *
-log_source_empathy_search_new (EmpathyLogManager *manager,
+log_source_empathy_search_new (EmpathyLogSource *self,
const gchar *text)
{
GList *files, *l;
GList *hits = NULL;
gchar *text_casefold;
- g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL);
+ g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), NULL);
g_return_val_if_fail (!G_STR_EMPTY (text), NULL);
text_casefold = g_utf8_casefold (text, -1);
- files = log_source_empathy_get_all_files (manager, NULL);
+ files = log_source_empathy_get_all_files (self, NULL);
DEBUG ("Found %d log files in total", g_list_length (files));
for (l = files; l; l = l->next)
@@ -542,7 +580,7 @@ log_source_empathy_search_new (EmpathyLogManager *manager,
{
EmpathyLogSearchHit *hit;
- hit = log_source_empathy_search_hit_new (manager, filename);
+ hit = log_source_empathy_search_hit_new (self, filename);
if (hit)
{
@@ -563,7 +601,7 @@ log_source_empathy_search_new (EmpathyLogManager *manager,
}
static GList *
-log_source_empathy_get_chats_for_dir (EmpathyLogManager *manager,
+log_source_empathy_get_chats_for_dir (EmpathyLogSource *self,
const gchar *dir,
gboolean is_chatroom)
{
@@ -583,7 +621,8 @@ log_source_empathy_get_chats_for_dir (EmpathyLogManager *manager,
filename = g_build_filename (dir, name, NULL);
if (strcmp (name, LOG_DIR_CHATROOMS) == 0)
{
- hits = g_list_concat (hits, log_source_empathy_get_chats_for_dir (manager, dir, TRUE));
+ hits = g_list_concat (hits, log_source_empathy_get_chats_for_dir (
+ self, dir, TRUE));
g_free (filename);
continue;
}
@@ -602,7 +641,7 @@ log_source_empathy_get_chats_for_dir (EmpathyLogManager *manager,
static GList *
-log_source_empathy_get_messages_for_date (EmpathyLogManager *manager,
+log_source_empathy_get_messages_for_date (EmpathyLogSource *self,
McAccount *account,
const gchar *chat_id,
gboolean chatroom,
@@ -611,50 +650,48 @@ log_source_empathy_get_messages_for_date (EmpathyLogManager *manager,
gchar *filename;
GList *messages;
- g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL);
+ g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), NULL);
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (chat_id != NULL, NULL);
- filename = log_source_empathy_get_filename_for_date (manager, account,
+ filename = log_source_empathy_get_filename_for_date (self, account,
chat_id, chatroom, date);
- messages = log_source_empathy_get_messages_for_file (manager, filename);
+ messages = log_source_empathy_get_messages_for_file (self, filename);
g_free (filename);
return messages;
}
static GList *
-log_source_empathy_get_chats (EmpathyLogManager *manager,
+log_source_empathy_get_chats (EmpathyLogSource *self,
McAccount *account)
{
- gchar *basedir;
gchar *dir;
GList *hits;
+ EmpathyLogSourceEmpathyPriv *priv;
- basedir = log_source_empathy_get_basedir ();
- dir = g_build_filename (basedir, mc_account_get_unique_name (account),
- NULL);
- g_free (basedir);
+ priv = GET_PRIV (self);
+
+ dir = g_build_filename (priv->basedir,
+ mc_account_get_unique_name (account), NULL);
- hits = log_source_empathy_get_chats_for_dir (manager, dir, FALSE);
+ hits = log_source_empathy_get_chats_for_dir (self, dir, FALSE);
g_free (dir);
return hits;
}
-EmpathyLogSource *
-empathy_log_source_empathy_get_source (void)
+static void
+log_source_iface_init (gpointer g_iface,
+ gpointer iface_data)
{
- EmpathyLogSource *source;
- source = g_slice_new0 (EmpathyLogSource);
-
- source->exists = log_source_empathy_exists;
- source->add_message = log_source_empathy_add_message;
- source->get_dates = log_source_empathy_get_dates;
- source->get_messages_for_date = log_source_empathy_get_messages_for_date;
- source->get_chats = log_source_empathy_get_chats;
- source->search_new = log_source_empathy_search_new;
-
- return source;
+ EmpathyLogSourceInterface *iface = (EmpathyLogSourceInterface *) g_iface;
+
+ iface->exists = log_source_empathy_exists;
+ iface->add_message = log_source_empathy_add_message;
+ iface->get_dates = log_source_empathy_get_dates;
+ iface->get_messages_for_date = log_source_empathy_get_messages_for_date;
+ iface->get_chats = log_source_empathy_get_chats;
+ iface->search_new = log_source_empathy_search_new;
}
diff --git a/libempathy/empathy-log-source.c b/libempathy/empathy-log-source.c
new file mode 100644
index 000000000..e2bc4a67b
--- /dev/null
+++ b/libempathy/empathy-log-source.c
@@ -0,0 +1,112 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Collabora Ltd.
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
+ */
+
+#include "empathy-log-source.h"
+
+GType
+empathy_log_source_get_type (void)
+{
+ static GType type = 0;
+ if (type == 0) {
+ static const GTypeInfo info = {
+ sizeof (EmpathyLogSourceInterface),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ NULL, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ 0,
+ 0, /* n_preallocs */
+ NULL /* instance_init */
+ };
+ type = g_type_register_static (G_TYPE_INTERFACE, "EmpathyLogSource",
+ &info, 0);
+ }
+ return type;
+}
+
+gboolean
+empathy_log_source_exists (EmpathyLogSource *self,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom)
+{
+ return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->exists (
+ self, account, chat_id, chatroom);
+}
+
+
+
+void
+empathy_log_source_add_message (EmpathyLogSource *self,
+ const gchar *chat_id,
+ gboolean chatroom,
+ EmpathyMessage *message)
+{
+ EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->add_message (
+ self, chat_id, chatroom, message);
+}
+
+GList *
+empathy_log_source_get_dates (EmpathyLogSource *self,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom)
+{
+ return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_dates (
+ self, account, chat_id, chatroom);
+}
+
+GList *
+empathy_log_source_get_messages_for_date (EmpathyLogSource *self,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom,
+ const gchar *date)
+{
+ return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_messages_for_date (
+ self, account, chat_id, chatroom, date);
+}
+
+GList *
+empathy_log_source_get_last_messages (EmpathyLogSource *self,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom)
+{
+ return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_last_messages (
+ self, account, chat_id, chatroom);
+}
+
+GList *
+empathy_log_source_get_chats (EmpathyLogSource *self,
+ McAccount *account)
+{
+ return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_chats (self, account);
+}
+
+GList *
+empathy_log_source_search_new (EmpathyLogSource *self,
+ const gchar *text)
+{
+ return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->search_new (self, text);
+}
diff --git a/libempathy/empathy-log-source.h b/libempathy/empathy-log-source.h
new file mode 100644
index 000000000..50c7876fa
--- /dev/null
+++ b/libempathy/empathy-log-source.h
@@ -0,0 +1,87 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Collabora Ltd.
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
+ */
+
+#ifndef __EMPATHY_LOG_SOURCE_H__
+#define __EMPATHY_LOG_SOURCE_H__
+
+#include <glib-object.h>
+
+#include <libmissioncontrol/mc-account.h>
+
+#include "empathy-message.h"
+
+G_BEGIN_DECLS
+
+#define EMPATHY_TYPE_LOG_SOURCE (empathy_log_source_get_type ())
+#define EMPATHY_LOG_SOURCE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_LOG_SOURCE, \
+ EmpathyLogSource))
+#define EMPATHY_IS_LOG_SOURCE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_LOG_SOURCE))
+#define EMPATHY_LOG_SOURCE_GET_INTERFACE(inst) \
+ (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EMPATHY_TYPE_LOG_SOURCE, \
+ EmpathyLogSourceInterface))
+
+typedef struct _EmpathyLogSource EmpathyLogSource; /* dummy object */
+typedef struct _EmpathyLogSourceInterface EmpathyLogSourceInterface;
+
+struct _EmpathyLogSourceInterface
+{
+ GTypeInterface parent;
+
+ gboolean (*exists) (EmpathyLogSource *self, McAccount *account,
+ const gchar *chat_id, gboolean chatroom);
+ void (*add_message) (EmpathyLogSource *self, const gchar *chat_id,
+ gboolean chatroom, EmpathyMessage *message);
+ GList * (*get_dates) (EmpathyLogSource *self, McAccount *account,
+ const gchar *chat_id, gboolean chatroom);
+ GList * (*get_messages_for_date) (EmpathyLogSource *self,
+ McAccount *account, const gchar *chat_id, gboolean chatroom,
+ const gchar *date);
+ GList * (*get_last_messages) (EmpathyLogSource *self, McAccount *account,
+ const gchar *chat_id, gboolean chatroom);
+ GList * (*get_chats) (EmpathyLogSource *self,
+ McAccount *account);
+ GList * (*search_new) (EmpathyLogSource *self, const gchar *text);
+};
+
+GType empathy_log_source_get_type (void) G_GNUC_CONST;
+
+gboolean empathy_log_source_exists (EmpathyLogSource *self,
+ McAccount *account, const gchar *chat_id, gboolean chatroom);
+void empathy_log_source_add_message (EmpathyLogSource *self,
+ const gchar *chat_id, gboolean chatroom, EmpathyMessage *message);
+GList *empathy_log_source_get_dates (EmpathyLogSource *self,
+ McAccount *account, const gchar *chat_id, gboolean chatroom);
+GList *empathy_log_source_get_messages_for_date (EmpathyLogSource *self,
+ McAccount *account, const gchar *chat_id, gboolean chatroom,
+ const gchar *date);
+GList *empathy_log_source_get_last_messages (EmpathyLogSource *self,
+ McAccount *account, const gchar *chat_id, gboolean chatroom);
+GList *empathy_log_source_get_chats (EmpathyLogSource *self,
+ McAccount *account);
+GList *empathy_log_source_search_new (EmpathyLogSource *self,
+ const gchar *text);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_LOG_SOURCE_H__ */