]> git.0d.be Git - empathy.git/commitdiff
Made EmpathyLogSource an interface and EmpathyLogSourceEmpathy extend it.
authorJonny Lamb <jonny.lamb@collabora.co.uk>
Fri, 6 Mar 2009 11:51:32 +0000 (11:51 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 6 Mar 2009 11:51:32 +0000 (11:51 +0000)
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
svn path=/trunk/; revision=2582

libempathy/Makefile.am
libempathy/empathy-log-manager.c
libempathy/empathy-log-manager.h
libempathy/empathy-log-source-empathy.c
libempathy/empathy-log-source.c [new file with mode: 0644]
libempathy/empathy-log-source.h [new file with mode: 0644]

index 053c0c8e9c6fc1e0ce652629001c09782b744f6d..085c6b999a656d5d77252d87c2131cbb7a7d1d3e 100644 (file)
@@ -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                                  \
index abd4d75151805cd81f1ec99a1cfa1600effb306a..c9b5a304932c2c2265810ef666c3fb36bd1d364c 100644 (file)
@@ -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;
index b8f86efd74702d98c5fa48712e7ab78232848876..fa9e39b7b6fb6f29b43dbaf3ccad3f3d0001314c 100644 (file)
@@ -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,
index d6804683cc0ea5ab00ddb8d3ffa03291d29c9371..25270ae745d6f36a7ad78369974f5d74d859514f 100644 (file)
@@ -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"
 #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 (file)
index 0000000..e2bc4a6
--- /dev/null
@@ -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 (file)
index 0000000..50c7876
--- /dev/null
@@ -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__ */