aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-log-source-empathy.c
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/empathy-log-source-empathy.c
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/empathy-log-source-empathy.c')
-rw-r--r--libempathy/empathy-log-source-empathy.c171
1 files changed, 104 insertions, 67 deletions
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;
}