diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2009-03-06 19:52:08 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-03-06 19:52:08 +0800 |
commit | 6b3b79f073995d33a2da2686a7eee70b963037b2 (patch) | |
tree | 0e07cf87d6b99576749a819dd79a03edb7668e06 /libempathy | |
parent | 2e950aee6b42d1298a11af611b0b190be168e49c (diff) | |
download | gsoc2013-empathy-6b3b79f073995d33a2da2686a7eee70b963037b2.tar gsoc2013-empathy-6b3b79f073995d33a2da2686a7eee70b963037b2.tar.gz gsoc2013-empathy-6b3b79f073995d33a2da2686a7eee70b963037b2.tar.bz2 gsoc2013-empathy-6b3b79f073995d33a2da2686a7eee70b963037b2.tar.lz gsoc2013-empathy-6b3b79f073995d33a2da2686a7eee70b963037b2.tar.xz gsoc2013-empathy-6b3b79f073995d33a2da2686a7eee70b963037b2.tar.zst gsoc2013-empathy-6b3b79f073995d33a2da2686a7eee70b963037b2.zip |
Renamed EmpathyLogSource to EmpathyLogStore.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
svn path=/trunk/; revision=2593
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/Makefile.am | 4 | ||||
-rw-r--r-- | libempathy/empathy-log-manager.c | 64 | ||||
-rw-r--r-- | libempathy/empathy-log-source.c | 156 | ||||
-rw-r--r-- | libempathy/empathy-log-source.h | 94 | ||||
-rw-r--r-- | libempathy/empathy-log-store-empathy.c (renamed from libempathy/empathy-log-source-empathy.c) | 196 | ||||
-rw-r--r-- | libempathy/empathy-log-store-empathy.h | 66 | ||||
-rw-r--r-- | libempathy/empathy-log-store.c | 156 | ||||
-rw-r--r-- | libempathy/empathy-log-store.h | 94 |
8 files changed, 448 insertions, 382 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 085c6b999..cffb922da 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -36,8 +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-log-store.c \ + empathy-log-store-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 2b001ac0a..4125add7c 100644 --- a/libempathy/empathy-log-manager.c +++ b/libempathy/empathy-log-manager.c @@ -31,8 +31,8 @@ #include <telepathy-glib/util.h> #include "empathy-log-manager.h" -#include "empathy-log-source-empathy.h" -#include "empathy-log-source.h" +#include "empathy-log-store-empathy.h" +#include "empathy-log-store.h" #include "empathy-tp-chat.h" #include "empathy-utils.h" @@ -42,7 +42,7 @@ #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLogManager) typedef struct { - GList *sources; + GList *stores; } EmpathyLogManagerPriv; G_DEFINE_TYPE (EmpathyLogManager, empathy_log_manager, G_TYPE_OBJECT); @@ -57,13 +57,13 @@ log_manager_finalize (GObject *object) priv = GET_PRIV (object); - for (l = priv->sources; l; l = l->next) + for (l = priv->stores; l; l = l->next) { - EmpathyLogSource *source = (EmpathyLogSource *) l->data; - g_object_unref (source); + EmpathyLogStore *store = (EmpathyLogStore *) l->data; + g_object_unref (store); } - g_list_free (priv->sources); + g_list_free (priv->stores); } static GObject * @@ -111,8 +111,8 @@ empathy_log_manager_init (EmpathyLogManager *manager) EmpathyLogManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, EMPATHY_TYPE_LOG_MANAGER, EmpathyLogManagerPriv); - priv->sources = g_list_append (priv->sources, - g_object_new (EMPATHY_TYPE_LOG_SOURCE_EMPATHY, NULL)); + priv->stores = g_list_append (priv->stores, + g_object_new (EMPATHY_TYPE_LOG_STORE_EMPATHY, NULL)); manager->priv = priv; } @@ -135,9 +135,9 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, gboolean out = FALSE; gboolean found = FALSE; - /* TODO: When multiple log sources appear with add_message implementations + /* TODO: When multiple log stores appear with add_message implementations * make this customisable. */ - const gchar *add_source = "Empathy"; + const gchar *add_store = "Empathy"; g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), FALSE); g_return_val_if_fail (chat_id != NULL, FALSE); @@ -145,12 +145,12 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, priv = GET_PRIV (manager); - for (l = priv->sources; l; l = l->next) + for (l = priv->stores; l; l = l->next) { - if (!tp_strdiff (empathy_log_source_get_name ( - EMPATHY_LOG_SOURCE (l->data)), add_source)) + if (!tp_strdiff (empathy_log_store_get_name ( + EMPATHY_LOG_STORE (l->data)), add_store)) { - out = empathy_log_source_add_message (EMPATHY_LOG_SOURCE (l->data), + out = empathy_log_store_add_message (EMPATHY_LOG_STORE (l->data), chat_id, chatroom, message, error); found = TRUE; break; @@ -158,7 +158,7 @@ empathy_log_manager_add_message (EmpathyLogManager *manager, } if (!found) - DEBUG ("Failed to find chosen log source to write to."); + DEBUG ("Failed to find chosen log store to write to."); return out; } @@ -178,9 +178,9 @@ empathy_log_manager_exists (EmpathyLogManager *manager, priv = GET_PRIV (manager); - for (l = priv->sources; l; l = l->next) + for (l = priv->stores; l; l = l->next) { - if (empathy_log_source_exists (EMPATHY_LOG_SOURCE (l->data), + if (empathy_log_store_exists (EMPATHY_LOG_STORE (l->data), account, chat_id, chatroom)) return TRUE; } @@ -214,15 +214,15 @@ empathy_log_manager_get_dates (EmpathyLogManager *manager, priv = GET_PRIV (manager); - for (l = priv->sources; l; l = l->next) + for (l = priv->stores; l; l = l->next) { - EmpathyLogSource *source = EMPATHY_LOG_SOURCE (l->data); + EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data); if (!out) - out = empathy_log_source_get_dates (source, account, chat_id, chatroom); + out = empathy_log_store_get_dates (store, account, chat_id, chatroom); else { - GList *new = empathy_log_source_get_dates (source, account, chat_id, + GList *new = empathy_log_store_get_dates (store, account, chat_id, chatroom); g_list_foreach (new, log_manager_get_dates_foreach, out); @@ -253,12 +253,12 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager, priv = GET_PRIV (manager); - for (l = priv->sources; l; l = l->next) + for (l = priv->stores; l; l = l->next) { - EmpathyLogSource *source = EMPATHY_LOG_SOURCE (l->data); + EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data); - out = g_list_concat (out, empathy_log_source_get_messages_for_date ( - source, account, chat_id, chatroom, date)); + out = g_list_concat (out, empathy_log_store_get_messages_for_date ( + store, account, chat_id, chatroom, date)); } return out; @@ -303,12 +303,12 @@ empathy_log_manager_get_chats (EmpathyLogManager *manager, priv = GET_PRIV (manager); - for (l = priv->sources; l; l = l->next) + for (l = priv->stores; l; l = l->next) { - EmpathyLogSource *source = EMPATHY_LOG_SOURCE (l->data); + EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data); out = g_list_concat (out, - empathy_log_source_get_chats (source, account)); + empathy_log_store_get_chats (store, account)); } return out; @@ -326,12 +326,12 @@ empathy_log_manager_search_new (EmpathyLogManager *manager, priv = GET_PRIV (manager); - for (l = priv->sources; l; l = l->next) + for (l = priv->stores; l; l = l->next) { - EmpathyLogSource *source = EMPATHY_LOG_SOURCE (l->data); + EmpathyLogStore *store = EMPATHY_LOG_STORE (l->data); out = g_list_concat (out, - empathy_log_source_search_new (source, text)); + empathy_log_store_search_new (store, text)); } return out; diff --git a/libempathy/empathy-log-source.c b/libempathy/empathy-log-source.c deleted file mode 100644 index f1e37fa79..000000000 --- a/libempathy/empathy-log-source.c +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- 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; -} - -const gchar * -empathy_log_source_get_name (EmpathyLogSource *self) -{ - if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_name) - return NULL; - - return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_name (self); -} - -gboolean -empathy_log_source_exists (EmpathyLogSource *self, - McAccount *account, - const gchar *chat_id, - gboolean chatroom) -{ - if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->exists) - return FALSE; - - return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->exists ( - self, account, chat_id, chatroom); -} - - - -gboolean -empathy_log_source_add_message (EmpathyLogSource *self, - const gchar *chat_id, - gboolean chatroom, - EmpathyMessage *message, - GError **error) -{ - if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->add_message) - return FALSE; - - return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->add_message ( - self, chat_id, chatroom, message, error); -} - -GList * -empathy_log_source_get_dates (EmpathyLogSource *self, - McAccount *account, - const gchar *chat_id, - gboolean chatroom) -{ - if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_dates) - return NULL; - - 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) -{ - if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_messages_for_date) - return NULL; - - 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) -{ - if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_last_messages) - return NULL; - - 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) -{ - if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_chats) - return NULL; - - return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->get_chats (self, account); -} - -GList * -empathy_log_source_search_new (EmpathyLogSource *self, - const gchar *text) -{ - if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->search_new) - return NULL; - - return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->search_new (self, text); -} - -void -empathy_log_source_ack_message (EmpathyLogSource *self, - const gchar *chat_id, - gboolean chatroom, - EmpathyMessage *message) -{ - if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->ack_message) - return; - - EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->ack_message ( - self, chat_id, chatroom, message); -} diff --git a/libempathy/empathy-log-source.h b/libempathy/empathy-log-source.h deleted file mode 100644 index 03d920c28..000000000 --- a/libempathy/empathy-log-source.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- 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; - - const gchar * (*get_name) (EmpathyLogSource *self); - gboolean (*exists) (EmpathyLogSource *self, McAccount *account, - const gchar *chat_id, gboolean chatroom); - gboolean (*add_message) (EmpathyLogSource *self, const gchar *chat_id, - gboolean chatroom, EmpathyMessage *message, GError **error); - 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); - void (*ack_message) (EmpathyLogSource *self, const gchar *chat_id, - gboolean chatroom, EmpathyMessage *message); -}; - -GType empathy_log_source_get_type (void) G_GNUC_CONST; - -const gchar *empathy_log_source_get_name (EmpathyLogSource *self); -gboolean empathy_log_source_exists (EmpathyLogSource *self, - McAccount *account, const gchar *chat_id, gboolean chatroom); -gboolean empathy_log_source_add_message (EmpathyLogSource *self, - const gchar *chat_id, gboolean chatroom, EmpathyMessage *message, - GError **error); -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); -void empathy_log_source_ack_message (EmpathyLogSource *self, - const gchar *chat_id, gboolean chatroom, EmpathyMessage *message); - -G_END_DECLS - -#endif /* __EMPATHY_LOG_SOURCE_H__ */ diff --git a/libempathy/empathy-log-source-empathy.c b/libempathy/empathy-log-store-empathy.c index baad6c965..e9cf887b2 100644 --- a/libempathy/empathy-log-source-empathy.c +++ b/libempathy/empathy-log-store-empathy.c @@ -29,8 +29,8 @@ #include <stdlib.h> #include <glib/gstdio.h> -#include "empathy-log-source.h" -#include "empathy-log-source-empathy.h" +#include "empathy-log-store.h" +#include "empathy-log-store-empathy.h" #include "empathy-log-manager.h" #include "empathy-contact.h" #include "empathy-time.h" @@ -54,44 +54,44 @@ "</log>\n" -#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLogSourceEmpathy) +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLogStoreEmpathy) typedef struct { gchar *basedir; gchar *name; -} EmpathyLogSourceEmpathyPriv; +} EmpathyLogStoreEmpathyPriv; -static void log_source_iface_init (gpointer g_iface,gpointer iface_data); +static void log_store_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)); +G_DEFINE_TYPE_WITH_CODE (EmpathyLogStoreEmpathy, empathy_log_store_empathy, + G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_LOG_STORE, + log_store_iface_init)); static void -log_source_empathy_finalize (GObject *object) +log_store_empathy_finalize (GObject *object) { - EmpathyLogSourceEmpathy *self = EMPATHY_LOG_SOURCE_EMPATHY (object); - EmpathyLogSourceEmpathyPriv *priv = GET_PRIV (self); + EmpathyLogStoreEmpathy *self = EMPATHY_LOG_STORE_EMPATHY (object); + EmpathyLogStoreEmpathyPriv *priv = GET_PRIV (self); g_free (priv->basedir); g_free (priv->name); } static void -empathy_log_source_empathy_class_init (EmpathyLogSourceEmpathyClass *klass) +empathy_log_store_empathy_class_init (EmpathyLogStoreEmpathyClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = log_source_empathy_finalize; + object_class->finalize = log_store_empathy_finalize; - g_type_class_add_private (object_class, sizeof (EmpathyLogSourceEmpathyPriv)); + g_type_class_add_private (object_class, sizeof (EmpathyLogStoreEmpathyPriv)); } static void -empathy_log_source_empathy_init (EmpathyLogSourceEmpathy *self) +empathy_log_store_empathy_init (EmpathyLogStoreEmpathy *self) { - EmpathyLogSourceEmpathyPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - EMPATHY_TYPE_LOG_SOURCE_EMPATHY, EmpathyLogSourceEmpathyPriv); + EmpathyLogStoreEmpathyPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + EMPATHY_TYPE_LOG_STORE_EMPATHY, EmpathyLogStoreEmpathyPriv); self->priv = priv; @@ -102,14 +102,14 @@ empathy_log_source_empathy_init (EmpathyLogSourceEmpathy *self) } static gchar * -log_source_empathy_get_dir (EmpathyLogSource *self, - McAccount *account, - const gchar *chat_id, - gboolean chatroom) +log_store_empathy_get_dir (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom) { const gchar *account_id; gchar *basedir; - EmpathyLogSourceEmpathyPriv *priv; + EmpathyLogStoreEmpathyPriv *priv; priv = GET_PRIV (self); @@ -126,7 +126,7 @@ log_source_empathy_get_dir (EmpathyLogSource *self, } static gchar * -log_source_empathy_get_timestamp_filename (void) +log_store_empathy_get_timestamp_filename (void) { time_t t; gchar *time_str; @@ -142,7 +142,7 @@ log_source_empathy_get_timestamp_filename (void) } static gchar * -log_source_empathy_get_timestamp_from_message (EmpathyMessage *message) +log_store_empathy_get_timestamp_from_message (EmpathyMessage *message) { time_t t; @@ -153,17 +153,17 @@ log_source_empathy_get_timestamp_from_message (EmpathyMessage *message) } static gchar * -log_source_empathy_get_filename (EmpathyLogSource *self, - McAccount *account, - const gchar *chat_id, - gboolean chatroom) +log_store_empathy_get_filename (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom) { gchar *basedir; gchar *timestamp; gchar *filename; - basedir = log_source_empathy_get_dir (self, account, chat_id, chatroom); - timestamp = log_source_empathy_get_timestamp_filename (); + basedir = log_store_empathy_get_dir (self, account, chat_id, chatroom); + timestamp = log_store_empathy_get_timestamp_filename (); filename = g_build_filename (basedir, timestamp, NULL); g_free (basedir); @@ -173,11 +173,11 @@ log_source_empathy_get_filename (EmpathyLogSource *self, } static gboolean -log_source_empathy_add_message (EmpathyLogSource *self, - const gchar *chat_id, - gboolean chatroom, - EmpathyMessage *message, - GError **error) +log_store_empathy_add_message (EmpathyLogStore *self, + const gchar *chat_id, + gboolean chatroom, + EmpathyMessage *message, + GError **error) { FILE *file; McAccount *account; @@ -194,7 +194,7 @@ log_source_empathy_add_message (EmpathyLogSource *self, gchar *contact_id; TpChannelTextMessageType msg_type; - g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), FALSE); + g_return_val_if_fail (EMPATHY_IS_LOG_STORE (self), FALSE); g_return_val_if_fail (chat_id != NULL, FALSE); g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE); @@ -206,7 +206,7 @@ log_source_empathy_add_message (EmpathyLogSource *self, if (G_STR_EMPTY (body_str)) return FALSE; - filename = log_source_empathy_get_filename (self, account, chat_id, chatroom); + filename = log_store_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)) { @@ -233,7 +233,7 @@ log_source_empathy_add_message (EmpathyLogSource *self, } body = g_markup_escape_text (body_str, -1); - timestamp = log_source_empathy_get_timestamp_from_message (message); + timestamp = log_store_empathy_get_timestamp_from_message (message); str = empathy_contact_get_name (sender); contact_name = g_markup_escape_text (str, -1); @@ -264,15 +264,15 @@ log_source_empathy_add_message (EmpathyLogSource *self, } static gboolean -log_source_empathy_exists (EmpathyLogSource *self, - McAccount *account, - const gchar *chat_id, - gboolean chatroom) +log_store_empathy_exists (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom) { gchar *dir; gboolean exists; - dir = log_source_empathy_get_dir (self, account, chat_id, chatroom); + dir = log_store_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); @@ -280,10 +280,10 @@ log_source_empathy_exists (EmpathyLogSource *self, } static GList * -log_source_empathy_get_dates (EmpathyLogSource *self, - McAccount *account, - const gchar *chat_id, - gboolean chatroom) +log_store_empathy_get_dates (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom) { GList *dates = NULL; gchar *date; @@ -292,11 +292,11 @@ log_source_empathy_get_dates (EmpathyLogSource *self, const gchar *filename; const gchar *p; - g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), NULL); + g_return_val_if_fail (EMPATHY_IS_LOG_STORE (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 (self, account, chat_id, chatroom); + directory = log_store_empathy_get_dir (self, account, chat_id, chatroom); dir = g_dir_open (directory, 0, NULL); if (!dir) { @@ -333,17 +333,17 @@ log_source_empathy_get_dates (EmpathyLogSource *self, } static gchar * -log_source_empathy_get_filename_for_date (EmpathyLogSource *self, - McAccount *account, - const gchar *chat_id, - gboolean chatroom, - const gchar *date) +log_store_empathy_get_filename_for_date (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom, + const gchar *date) { gchar *basedir; gchar *timestamp; gchar *filename; - basedir = log_source_empathy_get_dir (self, account, chat_id, chatroom); + basedir = log_store_empathy_get_dir (self, account, chat_id, chatroom); timestamp = g_strconcat (date, LOG_FILENAME_SUFFIX, NULL); filename = g_build_filename (basedir, timestamp, NULL); @@ -354,8 +354,8 @@ log_source_empathy_get_filename_for_date (EmpathyLogSource *self, } static EmpathyLogSearchHit * -log_source_empathy_search_hit_new (EmpathyLogSource *self, - const gchar *filename) +log_store_empathy_search_hit_new (EmpathyLogStore *self, + const gchar *filename) { EmpathyLogSearchHit *hit; const gchar *account_name; @@ -390,8 +390,8 @@ log_source_empathy_search_hit_new (EmpathyLogSource *self, } static GList * -log_source_empathy_get_messages_for_file (EmpathyLogSource *self, - const gchar *filename) +log_store_empathy_get_messages_for_file (EmpathyLogStore *self, + const gchar *filename) { GList *messages = NULL; xmlParserCtxtPtr ctxt; @@ -401,7 +401,7 @@ log_source_empathy_get_messages_for_file (EmpathyLogSource *self, EmpathyLogSearchHit *hit; McAccount *account; - g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), NULL); + g_return_val_if_fail (EMPATHY_IS_LOG_STORE (self), NULL); g_return_val_if_fail (filename != NULL, NULL); DEBUG ("Attempting to parse filename:'%s'...", filename); @@ -413,7 +413,7 @@ log_source_empathy_get_messages_for_file (EmpathyLogSource *self, } /* Get the account from the filename */ - hit = log_source_empathy_search_hit_new (self, filename); + hit = log_store_empathy_search_hit_new (self, filename); account = g_object_ref (hit->account); empathy_log_manager_search_hit_free (hit); @@ -504,14 +504,14 @@ log_source_empathy_get_messages_for_file (EmpathyLogSource *self, } static GList * -log_source_empathy_get_all_files (EmpathyLogSource *self, - const gchar *dir) +log_store_empathy_get_all_files (EmpathyLogStore *self, + const gchar *dir) { GDir *gdir; GList *files = NULL; const gchar *name; const gchar *basedir; - EmpathyLogSourceEmpathyPriv *priv; + EmpathyLogStoreEmpathyPriv *priv; priv = GET_PRIV (self); @@ -536,7 +536,7 @@ log_source_empathy_get_all_files (EmpathyLogSource *self, { /* Recursively get all log files */ files = g_list_concat (files, - log_source_empathy_get_all_files (self, filename)); + log_store_empathy_get_all_files (self, filename)); } g_free (filename); @@ -548,19 +548,19 @@ log_source_empathy_get_all_files (EmpathyLogSource *self, } static GList * -log_source_empathy_search_new (EmpathyLogSource *self, - const gchar *text) +log_store_empathy_search_new (EmpathyLogStore *self, + const gchar *text) { GList *files, *l; GList *hits = NULL; gchar *text_casefold; - g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), NULL); + g_return_val_if_fail (EMPATHY_IS_LOG_STORE (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 (self, NULL); + files = log_store_empathy_get_all_files (self, NULL); DEBUG ("Found %d log files in total", g_list_length (files)); for (l = files; l; l = l->next) @@ -587,7 +587,7 @@ log_source_empathy_search_new (EmpathyLogSource *self, { EmpathyLogSearchHit *hit; - hit = log_source_empathy_search_hit_new (self, filename); + hit = log_store_empathy_search_hit_new (self, filename); if (hit) { @@ -608,9 +608,9 @@ log_source_empathy_search_new (EmpathyLogSource *self, } static GList * -log_source_empathy_get_chats_for_dir (EmpathyLogSource *self, - const gchar *dir, - gboolean is_chatroom) +log_store_empathy_get_chats_for_dir (EmpathyLogStore *self, + const gchar *dir, + gboolean is_chatroom) { GDir *gdir; GList *hits = NULL; @@ -628,7 +628,7 @@ log_source_empathy_get_chats_for_dir (EmpathyLogSource *self, 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 ( + hits = g_list_concat (hits, log_store_empathy_get_chats_for_dir ( self, dir, TRUE)); g_free (filename); continue; @@ -648,41 +648,41 @@ log_source_empathy_get_chats_for_dir (EmpathyLogSource *self, static GList * -log_source_empathy_get_messages_for_date (EmpathyLogSource *self, - McAccount *account, - const gchar *chat_id, - gboolean chatroom, - const gchar *date) +log_store_empathy_get_messages_for_date (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom, + const gchar *date) { gchar *filename; GList *messages; - g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), NULL); + g_return_val_if_fail (EMPATHY_IS_LOG_STORE (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 (self, account, + filename = log_store_empathy_get_filename_for_date (self, account, chat_id, chatroom, date); - messages = log_source_empathy_get_messages_for_file (self, filename); + messages = log_store_empathy_get_messages_for_file (self, filename); g_free (filename); return messages; } static GList * -log_source_empathy_get_chats (EmpathyLogSource *self, +log_store_empathy_get_chats (EmpathyLogStore *self, McAccount *account) { gchar *dir; GList *hits; - EmpathyLogSourceEmpathyPriv *priv; + EmpathyLogStoreEmpathyPriv *priv; 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 (self, dir, FALSE); + hits = log_store_empathy_get_chats_for_dir (self, dir, FALSE); g_free (dir); @@ -690,25 +690,25 @@ log_source_empathy_get_chats (EmpathyLogSource *self, } static const gchar * -log_source_empathy_get_name (EmpathyLogSource *self) +log_store_empathy_get_name (EmpathyLogStore *self) { - EmpathyLogSourceEmpathyPriv *priv = GET_PRIV (self); + EmpathyLogStoreEmpathyPriv *priv = GET_PRIV (self); return priv->name; } static void -log_source_iface_init (gpointer g_iface, - gpointer iface_data) +log_store_iface_init (gpointer g_iface, + gpointer iface_data) { - EmpathyLogSourceInterface *iface = (EmpathyLogSourceInterface *) g_iface; - - iface->get_name = log_source_empathy_get_name; - 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; + EmpathyLogStoreInterface *iface = (EmpathyLogStoreInterface *) g_iface; + + iface->get_name = log_store_empathy_get_name; + iface->exists = log_store_empathy_exists; + iface->add_message = log_store_empathy_add_message; + iface->get_dates = log_store_empathy_get_dates; + iface->get_messages_for_date = log_store_empathy_get_messages_for_date; + iface->get_chats = log_store_empathy_get_chats; + iface->search_new = log_store_empathy_search_new; iface->ack_message = NULL; } diff --git a/libempathy/empathy-log-store-empathy.h b/libempathy/empathy-log-store-empathy.h new file mode 100644 index 000000000..3bc9997c0 --- /dev/null +++ b/libempathy/empathy-log-store-empathy.h @@ -0,0 +1,66 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * Copyright (C) 2007-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: Xavier Claessens <xclaesse@gmail.com> + * Jonny Lamb <jonny.lamb@collabora.co.uk> + */ + +#ifndef __EMPATHY_LOG_STORE_EMPATHY_H__ +#define __EMPATHY_LOG_STORE_EMPATHY_H__ + +#include <glib.h> + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_LOG_STORE_EMPATHY \ + (empathy_log_store_empathy_get_type ()) +#define EMPATHY_LOG_STORE_EMPATHY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_LOG_STORE_EMPATHY, \ + EmpathyLogStoreEmpathy)) +#define EMPATHY_LOG_STORE_EMPATHY_CLASS(vtable) \ + (G_TYPE_CHECK_CLASS_CAST ((vtable), EMPATHY_TYPE_LOG_STORE_EMPATHY, \ + EmpathyLogStoreEmpathyClass)) +#define EMPATHY_IS_LOG_STORE_EMPATHY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_LOG_STORE_EMPATHY)) +#define EMPATHY_IS_LOG_STORE_EMPATHY_CLASS(vtable) \ + (G_TYPE_CHECK_CLASS_TYPE ((vtable), EMPATHY_TYPE_LOG_STORE_EMPATHY)) +#define EMPATHY_LOG_STORE_EMPATHY_GET_CLASS(inst) \ + (G_TYPE_INSTANCE_GET_CLASS ((inst), EMPATHY_TYPE_LOG_STORE_EMPATHY, \ + EmpathyLogStoreEmpathyClass)) + +typedef struct _EmpathyLogStoreEmpathy EmpathyLogStoreEmpathy; +typedef struct _EmpathyLogStoreEmpathyClass EmpathyLogStoreEmpathyClass; + +struct _EmpathyLogStoreEmpathy +{ + GObject parent; + gpointer priv; +}; + +struct _EmpathyLogStoreEmpathyClass +{ + GObjectClass parent; +}; + +GType empathy_log_store_empathy_get_type (void); + +G_END_DECLS + +#endif /* __EMPATHY_LOG_STORE_EMPATHY_H__ */ diff --git a/libempathy/empathy-log-store.c b/libempathy/empathy-log-store.c new file mode 100644 index 000000000..54681fed9 --- /dev/null +++ b/libempathy/empathy-log-store.c @@ -0,0 +1,156 @@ +/* -*- 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-store.h" + +GType +empathy_log_store_get_type (void) +{ + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (EmpathyLogStoreInterface), + 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, "EmpathyLogStore", + &info, 0); + } + return type; +} + +const gchar * +empathy_log_store_get_name (EmpathyLogStore *self) +{ + if (!EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_name) + return NULL; + + return EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_name (self); +} + +gboolean +empathy_log_store_exists (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom) +{ + if (!EMPATHY_LOG_STORE_GET_INTERFACE (self)->exists) + return FALSE; + + return EMPATHY_LOG_STORE_GET_INTERFACE (self)->exists ( + self, account, chat_id, chatroom); +} + + + +gboolean +empathy_log_store_add_message (EmpathyLogStore *self, + const gchar *chat_id, + gboolean chatroom, + EmpathyMessage *message, + GError **error) +{ + if (!EMPATHY_LOG_STORE_GET_INTERFACE (self)->add_message) + return FALSE; + + return EMPATHY_LOG_STORE_GET_INTERFACE (self)->add_message ( + self, chat_id, chatroom, message, error); +} + +GList * +empathy_log_store_get_dates (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom) +{ + if (!EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_dates) + return NULL; + + return EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_dates ( + self, account, chat_id, chatroom); +} + +GList * +empathy_log_store_get_messages_for_date (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom, + const gchar *date) +{ + if (!EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_messages_for_date) + return NULL; + + return EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_messages_for_date ( + self, account, chat_id, chatroom, date); +} + +GList * +empathy_log_store_get_last_messages (EmpathyLogStore *self, + McAccount *account, + const gchar *chat_id, + gboolean chatroom) +{ + if (!EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_last_messages) + return NULL; + + return EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_last_messages ( + self, account, chat_id, chatroom); +} + +GList * +empathy_log_store_get_chats (EmpathyLogStore *self, + McAccount *account) +{ + if (!EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_chats) + return NULL; + + return EMPATHY_LOG_STORE_GET_INTERFACE (self)->get_chats (self, account); +} + +GList * +empathy_log_store_search_new (EmpathyLogStore *self, + const gchar *text) +{ + if (!EMPATHY_LOG_STORE_GET_INTERFACE (self)->search_new) + return NULL; + + return EMPATHY_LOG_STORE_GET_INTERFACE (self)->search_new (self, text); +} + +void +empathy_log_store_ack_message (EmpathyLogStore *self, + const gchar *chat_id, + gboolean chatroom, + EmpathyMessage *message) +{ + if (!EMPATHY_LOG_STORE_GET_INTERFACE (self)->ack_message) + return; + + EMPATHY_LOG_STORE_GET_INTERFACE (self)->ack_message ( + self, chat_id, chatroom, message); +} diff --git a/libempathy/empathy-log-store.h b/libempathy/empathy-log-store.h new file mode 100644 index 000000000..c14f7f1c4 --- /dev/null +++ b/libempathy/empathy-log-store.h @@ -0,0 +1,94 @@ +/* -*- 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_STORE_H__ +#define __EMPATHY_LOG_STORE_H__ + +#include <glib-object.h> + +#include <libmissioncontrol/mc-account.h> + +#include "empathy-message.h" + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_LOG_STORE (empathy_log_store_get_type ()) +#define EMPATHY_LOG_STORE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_LOG_STORE, \ + EmpathyLogStore)) +#define EMPATHY_IS_LOG_STORE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_LOG_STORE)) +#define EMPATHY_LOG_STORE_GET_INTERFACE(inst) \ + (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EMPATHY_TYPE_LOG_STORE, \ + EmpathyLogStoreInterface)) + +typedef struct _EmpathyLogStore EmpathyLogStore; /* dummy object */ +typedef struct _EmpathyLogStoreInterface EmpathyLogStoreInterface; + +struct _EmpathyLogStoreInterface +{ + GTypeInterface parent; + + const gchar * (*get_name) (EmpathyLogStore *self); + gboolean (*exists) (EmpathyLogStore *self, McAccount *account, + const gchar *chat_id, gboolean chatroom); + gboolean (*add_message) (EmpathyLogStore *self, const gchar *chat_id, + gboolean chatroom, EmpathyMessage *message, GError **error); + GList * (*get_dates) (EmpathyLogStore *self, McAccount *account, + const gchar *chat_id, gboolean chatroom); + GList * (*get_messages_for_date) (EmpathyLogStore *self, + McAccount *account, const gchar *chat_id, gboolean chatroom, + const gchar *date); + GList * (*get_last_messages) (EmpathyLogStore *self, McAccount *account, + const gchar *chat_id, gboolean chatroom); + GList * (*get_chats) (EmpathyLogStore *self, + McAccount *account); + GList * (*search_new) (EmpathyLogStore *self, const gchar *text); + void (*ack_message) (EmpathyLogStore *self, const gchar *chat_id, + gboolean chatroom, EmpathyMessage *message); +}; + +GType empathy_log_store_get_type (void) G_GNUC_CONST; + +const gchar *empathy_log_store_get_name (EmpathyLogStore *self); +gboolean empathy_log_store_exists (EmpathyLogStore *self, + McAccount *account, const gchar *chat_id, gboolean chatroom); +gboolean empathy_log_store_add_message (EmpathyLogStore *self, + const gchar *chat_id, gboolean chatroom, EmpathyMessage *message, + GError **error); +GList *empathy_log_store_get_dates (EmpathyLogStore *self, + McAccount *account, const gchar *chat_id, gboolean chatroom); +GList *empathy_log_store_get_messages_for_date (EmpathyLogStore *self, + McAccount *account, const gchar *chat_id, gboolean chatroom, + const gchar *date); +GList *empathy_log_store_get_last_messages (EmpathyLogStore *self, + McAccount *account, const gchar *chat_id, gboolean chatroom); +GList *empathy_log_store_get_chats (EmpathyLogStore *self, + McAccount *account); +GList *empathy_log_store_search_new (EmpathyLogStore *self, + const gchar *text); +void empathy_log_store_ack_message (EmpathyLogStore *self, + const gchar *chat_id, gboolean chatroom, EmpathyMessage *message); + +G_END_DECLS + +#endif /* __EMPATHY_LOG_STORE_H__ */ |