summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2009-12-29 18:04:36 +0000
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2009-12-29 18:04:36 +0000
commit87a30fdddcbc41d88b5937de33c2e4be7d0f33ad (patch)
tree2833a435a7f7e0d15ae69ab3b98f1c259c569a90 /src
parent2062463f1d28d873e856744c2328e5a6668e30b4 (diff)
downloadtelepathy-logger-87a30fdddcbc41d88b5937de33c2e4be7d0f33ad.tar.gz
Added method to search among just one identifier messages
* added tpl_log_store_search_in_identifier_chats_new
Diffstat (limited to 'src')
-rw-r--r--src/test_api.c9
-rw-r--r--src/tpl-log-manager.c27
-rw-r--r--src/tpl-log-manager.h4
-rw-r--r--src/tpl-log-store-empathy.c67
-rw-r--r--src/tpl-log-store.c14
-rw-r--r--src/tpl-log-store.h5
6 files changed, 107 insertions, 19 deletions
diff --git a/src/test_api.c b/src/test_api.c
index 5e77712..71161b1 100644
--- a/src/test_api.c
+++ b/src/test_api.c
@@ -31,7 +31,7 @@
int main(int argc, char *argv[])
{
TplLogManager *manager;
- GList *l;
+ //GList *l;
TpAccount *acc;
//DBusGConnection *bus;
TpDBusDaemon *tp_bus;
@@ -53,9 +53,14 @@ int main(int argc, char *argv[])
manager = tpl_log_manager_dup_singleton ();
+ tpl_log_manager_search_in_identifier_chats_new(manager,
+ acc, "echo@test.collabora.co.uk", "foo");
+
tpl_log_manager_search_new(manager, "foo");
+
+/*
l = tpl_log_manager_get_chats(manager, acc);
int lenght = g_list_length(l);
for(int i=0;i<lenght;++i) {
@@ -80,7 +85,7 @@ int main(int argc, char *argv[])
}
}
-
+*/
//loop = g_main_loop_new (NULL, FALSE);
//g_main_loop_run (loop);
diff --git a/src/tpl-log-manager.c b/src/tpl-log-manager.c
index bf34031..905f5e3 100644
--- a/src/tpl-log-manager.c
+++ b/src/tpl-log-manager.c
@@ -352,6 +352,33 @@ tpl_log_manager_get_chats (TplLogManager *manager,
}
GList *
+tpl_log_manager_search_in_identifier_chats_new(TplLogManager *manager,
+ TpAccount *account, gchar const* identifier,
+ const gchar *text)
+{
+ GList *l, *out = NULL;
+ TplLogManagerPriv *priv;
+
+ g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL);
+ g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
+ g_return_val_if_fail (!TPL_STR_EMPTY (identifier), NULL);
+ g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL);
+
+ priv = GET_PRIV (manager);
+
+ for (l = priv->stores; l; l = g_list_next (l))
+ {
+ TplLogStore *store = TPL_LOG_STORE (l->data);
+
+ out = g_list_concat (out,
+ tpl_log_store_search_in_identifier_chats_new (store, account,
+ identifier, text));
+ }
+
+ return out;
+}
+
+GList *
tpl_log_manager_search_new (TplLogManager *manager,
const gchar *text)
{
diff --git a/src/tpl-log-manager.h b/src/tpl-log-manager.h
index f56cf69..f3c3a40 100644
--- a/src/tpl-log-manager.h
+++ b/src/tpl-log-manager.h
@@ -88,6 +88,10 @@ GList *tpl_log_manager_get_filtered_messages (TplLogManager *manager,
GList *tpl_log_manager_get_chats (TplLogManager *manager,
TpAccount *account);
+GList *tpl_log_manager_search_in_identifier_chats_new(
+ TplLogManager *manager, TpAccount *account,
+ gchar const* identifier, const gchar *text);
+
GList *tpl_log_manager_search_new (TplLogManager *manager,
const gchar *text);
diff --git a/src/tpl-log-store-empathy.c b/src/tpl-log-store-empathy.c
index 5ca2200..307e97e 100644
--- a/src/tpl-log-store-empathy.c
+++ b/src/tpl-log-store-empathy.c
@@ -47,9 +47,6 @@
#include <tpl-log-entry-text.h>
#include <tpl-contact.h>
-//#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-//#include <empathy-debug.h>
-
#define DEBUG g_debug
#define LOG_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
@@ -380,7 +377,6 @@ _log_store_empathy_add_message_text_chat (TplLogStore *self,
str = tpl_contact_get_identifier (sender);
- g_message("%s\n", tpl_contact_get_identifier(sender));
contact_id = g_markup_escape_text (str, -1);
/*
avatar = empathy_contact_get_avatar (sender);
@@ -512,7 +508,6 @@ log_store_empathy_get_dates (TplLogStore *self,
g_return_val_if_fail (!TPL_STR_EMPTY (chat_id), NULL);
directory = log_store_empathy_get_dir (self, account, chat_id, chatroom);
- g_message("dir %s\n", directory);
dir = g_dir_open (directory, 0, NULL);
if (!dir)
{
@@ -601,8 +596,6 @@ log_store_empathy_search_hit_new (TplLogStore *self,
hit->chat_id = g_strdup (strv[len-2]);
hit->is_chatroom = (strcmp (strv[len-3], LOG_DIR_CHATROOMS) == 0);
- g_debug("end %s, date %s, id %s\n", end, hit->date, hit->chat_id);
-
if (hit->is_chatroom)
account_name = strv[len-4];
else
@@ -781,6 +774,9 @@ log_store_empathy_get_all_files (TplLogStore *self,
priv = GET_PRIV (self);
+ g_return_val_if_fail(TPL_IS_LOG_STORE (self), NULL);
+ // dir can be NULL, and basedir will be searched instead
+
basedir = dir ? dir : priv->basedir;
gdir = g_dir_open (basedir, 0, NULL);
@@ -813,11 +809,12 @@ log_store_empathy_get_all_files (TplLogStore *self,
return files;
}
+
static GList *
-log_store_empathy_search_new (TplLogStore *self,
- const gchar *text)
+_log_store_empathy_search_in_files (TplLogStore *self,
+ const gchar *text, GList *files)
{
- GList *files, *l;
+ GList *l;
GList *hits = NULL;
gchar *text_casefold;
@@ -826,9 +823,6 @@ log_store_empathy_search_new (TplLogStore *self,
text_casefold = g_utf8_casefold (text, -1);
- 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 = g_list_next (l))
{
gchar *filename;
@@ -872,6 +866,48 @@ log_store_empathy_search_new (TplLogStore *self,
return hits;
}
+
+
+static GList *
+log_store_empathy_search_in_identifier_chats_new (TplLogStore *self,
+ TpAccount *account, gchar const *identifier,
+ const gchar *text)
+{
+ GList *files;
+ gchar *dir, *account_dir;
+ TplLogStoreEmpathyPriv *priv = GET_PRIV (self);
+
+ g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL);
+ g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
+ g_return_val_if_fail (!TPL_STR_EMPTY (identifier), NULL);
+ g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL);
+
+ account_dir = log_store_account_to_dirname(account);
+ dir = g_build_path(G_DIR_SEPARATOR_S, priv->basedir, account_dir, G_DIR_SEPARATOR_S, identifier, NULL);
+
+ files = log_store_empathy_get_all_files (self, dir);
+ DEBUG ("Found %d log files in total", g_list_length (files));
+
+ return _log_store_empathy_search_in_files(self, text, files);
+}
+
+
+
+static GList *
+log_store_empathy_search_new (TplLogStore *self,
+ const gchar *text)
+{
+ GList *files;
+
+ g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL);
+ g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL);
+
+ files = log_store_empathy_get_all_files (self, NULL);
+ DEBUG ("Found %d log files in total", g_list_length (files));
+
+ return _log_store_empathy_search_in_files(self, text, files);
+}
+
/*
static gboolean
log_store_empathy_is_logfile (gchar const *filename) {
@@ -904,7 +940,6 @@ log_store_empathy_get_chats_for_dir (TplLogStore *self,
return NULL;
}
-
while ((name = g_dir_read_name (gdir)) != NULL) {
TplLogSearchHit *hit;
@@ -967,12 +1002,9 @@ log_store_empathy_get_chats (TplLogStore *self,
g_free (dir);
- g_message("len: %d\n", g_list_length(hits));
for(guint i=0; i<g_list_length(hits);++i) {
TplLogSearchHit *hit;
hit = g_list_nth_data(hits, i);
- g_message("hit: %s\n", hit->chat_id);
- g_message("hit: %s\n", hit->filename);
}
@@ -1046,6 +1078,7 @@ log_store_iface_init (gpointer g_iface,
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_in_identifier_chats_new = log_store_empathy_search_in_identifier_chats_new;
iface->search_new = log_store_empathy_search_new;
iface->ack_message = NULL;
iface->get_filtered_messages = log_store_empathy_get_filtered_messages;
diff --git a/src/tpl-log-store.c b/src/tpl-log-store.c
index a3e76de..a32581e 100644
--- a/src/tpl-log-store.c
+++ b/src/tpl-log-store.c
@@ -136,6 +136,20 @@ tpl_log_store_get_chats (TplLogStore *self,
}
+
+GList *
+tpl_log_store_search_in_identifier_chats_new(TplLogStore *self,
+ TpAccount *account, gchar const *identifier,
+ const gchar *text)
+{
+ if (!TPL_LOG_STORE_GET_INTERFACE (self)->search_new)
+ return NULL;
+
+ return TPL_LOG_STORE_GET_INTERFACE (self)->search_in_identifier_chats_new (self,
+ account, identifier, text);
+}
+
+
GList *
tpl_log_store_search_new (TplLogStore *self,
const gchar *text)
diff --git a/src/tpl-log-store.h b/src/tpl-log-store.h
index 5f3e81c..9b3e589 100644
--- a/src/tpl-log-store.h
+++ b/src/tpl-log-store.h
@@ -63,6 +63,8 @@ struct _TplLogStoreInterface
GList * (*get_chats) (TplLogStore *self,
TpAccount *account);
GList * (*search_new) (TplLogStore *self, const gchar *text);
+ GList * (*search_in_identifier_chats_new) (TplLogStore *self,
+ TpAccount *account, gchar const* identifier, const gchar *text);
void (*ack_message) (TplLogStore *self, const gchar *chat_id,
gboolean chatroom, TplLogEntry *message);
GList * (*get_filtered_messages) (TplLogStore *self, TpAccount *account,
@@ -87,6 +89,9 @@ GList *tpl_log_store_get_last_messages (TplLogStore *self,
TpAccount *account, const gchar *chat_id, gboolean chatroom);
GList *tpl_log_store_get_chats (TplLogStore *self,
TpAccount *account);
+GList *tpl_log_store_search_in_identifier_chats_new (TplLogStore *self,
+ TpAccount *account, gchar const *identifier,
+ const gchar *text);
GList *tpl_log_store_search_new (TplLogStore *self,
const gchar *text);
void tpl_log_store_ack_message (TplLogStore *self,