diff options
author | Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> | 2010-01-14 17:23:58 +0000 |
---|---|---|
committer | Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> | 2010-01-14 17:23:58 +0000 |
commit | 29c7fb4da417adebc65b7a0a44ee49a0bfdd2797 (patch) | |
tree | 5ea4482ad66b2cf3d8ca70ed3db485f52df5f403 | |
parent | c5a57433eb4c2ade0fc110d98093eea2bb42de3e (diff) | |
download | telepathy-logger-29c7fb4da417adebc65b7a0a44ee49a0bfdd2797.tar.gz |
GConf enabled
* gconf enabled using TplConf. Schema defined in telepathy-logger.schemas file
* fixes for the Async API
* add_message and add_message_async modified: chat_id, is_chatroom not needed anymore, while using TplLogEntry
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | src/test_api.c | 94 | ||||
-rw-r--r-- | telepathy-logger/Makefile.am | 18 | ||||
-rw-r--r-- | telepathy-logger/channel-text.c | 64 | ||||
-rw-r--r-- | telepathy-logger/channel-text.h | 10 | ||||
-rw-r--r-- | telepathy-logger/channel.c | 37 | ||||
-rw-r--r-- | telepathy-logger/channel.h | 8 | ||||
-rw-r--r-- | telepathy-logger/conf.c | 258 | ||||
-rw-r--r-- | telepathy-logger/conf.h | 70 | ||||
-rw-r--r-- | telepathy-logger/log-entry-text.c | 39 | ||||
-rw-r--r-- | telepathy-logger/log-entry-text.h | 7 | ||||
-rw-r--r-- | telepathy-logger/log-entry.c | 4 | ||||
-rw-r--r-- | telepathy-logger/log-manager-priv.h | 9 | ||||
-rw-r--r-- | telepathy-logger/log-manager.c | 262 | ||||
-rw-r--r-- | telepathy-logger/log-manager.h | 135 | ||||
-rw-r--r-- | telepathy-logger/log-store-empathy.c | 28 | ||||
-rw-r--r-- | telepathy-logger/log-store.c | 5 | ||||
-rw-r--r-- | telepathy-logger/log-store.h | 6 | ||||
-rw-r--r-- | telepathy-logger/observer.c | 24 | ||||
-rw-r--r-- | telepathy-logger/telepathy-logger.schemas | 14 | ||||
-rw-r--r-- | telepathy-logger/utils.h | 1 |
22 files changed, 765 insertions, 335 deletions
@@ -25,6 +25,7 @@ stamp-h1 config.* *~ +*.swp src/*.o src/*.lo diff --git a/Makefile.am b/Makefile.am index c5909b2..b81d15b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,5 +37,11 @@ ChangeLog: echo A git checkout and git-log is required to generate this file >> $@); \ fi +ctags: + $(MAKE) -C telepathy-logger ctags + $(MAKE) -C src ctags + cat telepathy-logger/tags src/tags >> tags + + .PHONY: ChangeLog diff --git a/src/test_api.c b/src/test_api.c index 755b966..5ca6a4a 100644 --- a/src/test_api.c +++ b/src/test_api.c @@ -20,84 +20,64 @@ */ #include <glib.h> -#include <telepathy-logger/log-manager.h> -#include <telepathy-logger/datetime.h> +#include <telepathy-logger/conf.h> #define ACCOUNT_PATH "/org/freedesktop/Telepathy/Account/gabble/jabber/cosimo_2ealfarano_40collabora_2eco_2euk0" #define ID "echo@test.collabora.co.uk" static GMainLoop *loop = NULL; -static void -get_messages_cb (TplLogManager * manager, gpointer result, GError * error, - gpointer user_data) +int +main (int argc, char *argv[]) { - guint len; - if (result) - len = g_list_length ((GList *) result); - else - len = 0; - g_message ("GOTCHA: %d\n", len); - - if(error) { - g_error("get messages: %s", error->message); - return; - } - for (guint i = g_list_length (result); i > 0; --i) - { - TplLogEntry *entry = (TplLogEntry *) g_list_nth_data (result, i - 1); - time_t t = tpl_log_entry_get_timestamp (entry); - g_print ("LIST msgs(%d): %s\n", i, - tpl_time_to_string_utc (t, "%Y%m%d %H%M-%S")); - } -} + TplConf *conf; + GSList *list; + GSList *newlist = NULL; -static void -get_dates_cb (TplLogManager * manager, gpointer result, GError * error, - gpointer user_data) -{ - guint len; + g_type_init (); - if(error) { - g_error("get dates: %s", error->message); - g_clear_error(&error); - g_error_free(error); - return; - } + conf = tpl_conf_dup(); - if (result) - len = g_list_length ((GList *) result); - else - len = 0; - g_message ("GOTCHAi: %d\n", len); + g_message ("enabled: %d\n", + tpl_conf_is_globally_enabled(conf, NULL)); - for (guint i = g_list_length (result); i > 0; --i) - g_print ("LIST dates(%d): %s\n", i, (gchar *) g_list_nth_data (result, i - 1)); -} -int -main (int argc, char *argv[]) -{ - g_type_init (); - TpDBusDaemon *tpbus; - TpAccount *acc; + list = tpl_conf_get_accounts_ignorelist(conf, NULL); + while (list) + { + g_message("list elemnet: %s\n",(gchar*)list->data); + list = g_slist_next(list); + } + g_message("FINISH\n"); - TplLogManager *manager = tpl_log_manager_dup_singleton (); + /* set */ + tpl_conf_togle_globally_enable(conf, FALSE, NULL); + newlist = g_slist_append(newlist, "foo"); + newlist = g_slist_append(newlist, "bar"); + tpl_conf_set_accounts_ignorelist(conf, newlist, NULL); - tpbus = tp_dbus_daemon_dup (NULL); - acc = tp_account_new (tpbus, ACCOUNT_PATH, NULL); + /* re-read */ + g_message ("enabled: %d\n", + tpl_conf_is_globally_enabled(conf, NULL)); - tpl_log_manager_get_dates_async (manager, acc, ID, FALSE, - get_dates_cb, NULL, NULL); - tpl_log_manager_get_messages_for_date_async (manager, acc, ID, - FALSE, "20091230", - get_messages_cb, NULL, NULL); + list = tpl_conf_get_accounts_ignorelist(conf, NULL); + while (list) + { + g_message("list elemnet: %s\n",(gchar*)list->data); + list = g_slist_next(list); + } + g_message("FINISH\n"); + + g_message("FOUND: %d\n", + tpl_conf_is_account_ignored(conf, "fooa", NULL)); + loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); + return 0; } diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am index 34ce6dd..f1fd25e 100644 --- a/telepathy-logger/Makefile.am +++ b/telepathy-logger/Makefile.am @@ -15,8 +15,10 @@ lib_LTLIBRARIES = libtelepathy-logger.la LIBTPLdir = $(includedir)/telepathy-logger LIBTPL_HEADERS = \ - observer.h \ + utils.h \ channel.h \ + channel-text.h \ + conf.h \ contact.h \ log-entry.h \ log-entry-text.h \ @@ -24,23 +26,23 @@ LIBTPL_HEADERS = \ log-manager-priv.h \ log-store-empathy.h \ log-store.h \ - channel-text.h \ - datetime.h \ - utils.h + observer.h \ + datetime.h libtelepathy_logger_la_SOURCES = \ - observer.c \ + datetime.c \ channel.c \ channel-text.c \ + conf.c \ + contact.c \ log-entry.c \ log-entry-text.c \ - contact.c \ log-manager.c \ log-store.c \ log-store-empathy.c \ - utils.c \ - datetime.c + observer.c \ + utils.c schemadir = @GCONF_SCHEMA_FILE_DIR@ schema_DATA = telepathy-logger.schemas diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c index ca8e679..cedf19b 100644 --- a/telepathy-logger/channel-text.c +++ b/telepathy-logger/channel-text.c @@ -137,7 +137,7 @@ _channel_on_sent_signal_cb (TpChannel * proxy, tpl_log_entry_text_set_message (tlog, arg_Text); tpl_log_entry_text_set_message_type (tlog, arg_Type); tpl_log_entry_text_set_signal_type (tlog, TPL_LOG_ENTRY_TEXT_SIGNAL_SENT); - tpl_log_entry_text_set_message_id (tlog, 123); + tpl_log_entry_text_set_message_id (tlog, arg_Timestamp); tpl_log_entry_set_entry (log, tlog); tpl_log_entry_set_timestamp (log, (time_t) arg_Timestamp); @@ -150,11 +150,11 @@ _channel_on_sent_signal_cb (TpChannel * proxy, chat_id = g_strdup (tpl_text_channel_get_chatroom_id (tpl_text)); tpl_log_entry_text_set_chat_id (tlog, chat_id); + tpl_log_entry_text_set_chatroom (tlog, + tpl_text_channel_is_chatroom (tpl_text)); logmanager = tpl_log_manager_dup_singleton (); - - tpl_log_manager_add_message (logmanager, chat_id, - tpl_text_channel_is_chatroom (tpl_text), + tpl_log_manager_add_message (logmanager, log, &error); if (error != NULL) @@ -231,11 +231,11 @@ _channel_on_received_signal_with_contact_cb (TpConnection * connection, chat_id = g_strdup (tpl_text_channel_get_chatroom_id (tpl_text)); tpl_log_entry_text_set_chat_id (tlog, chat_id); + tpl_log_entry_text_set_chatroom (tlog, + tpl_text_channel_is_chatroom (tpl_text)); logmanager = tpl_log_manager_dup_singleton (); tpl_log_manager_add_message (logmanager, - tpl_log_entry_text_get_chat_id (tlog), - tpl_text_channel_is_chatroom (tpl_text), log, &e); if (e != NULL) { @@ -267,8 +267,6 @@ _channel_on_received_signal_cb (TpChannel * proxy, TplLogEntry *log; TplLogEntryText *tlog; - g_message ("ID: %d\n", arg_ID); - // TODO use the Message iface to check the delivery // notification and handle it correctly if (arg_Flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT) @@ -289,7 +287,7 @@ _channel_on_received_signal_cb (TpChannel * proxy, tpl_log_entry_text_set_message_type (tlog, arg_Type); tpl_log_entry_text_set_signal_type (tlog, TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED); - tpl_log_entry_text_set_message_id (tlog, 123); //TODO set a real Id + tpl_log_entry_text_set_message_id (tlog, arg_Timestamp); //TODO set a real Id me = tpl_text_channel_get_my_contact (tpl_text); tpl_contact_receiver = tpl_contact_from_tp_contact (me); @@ -530,12 +528,11 @@ _tpl_text_channel_pendingproc_get_my_contact (TplTextChannel * ctx) G_DEFINE_TYPE (TplTextChannel, tpl_text_channel, G_TYPE_OBJECT) - static void tpl_text_channel_dispose (GObject * obj) + +static void tpl_text_channel_dispose (GObject * obj) { TplTextChannel *self = TPL_TEXT_CHANNEL (obj); - g_debug ("TplTextChannel: disposing\n"); - tpl_object_unref_if_not_null (self->tpl_channel); self->tpl_channel = NULL; tpl_object_unref_if_not_null (self->my_contact); @@ -546,8 +543,6 @@ G_DEFINE_TYPE (TplTextChannel, tpl_text_channel, G_TYPE_OBJECT) self->chain = NULL; G_OBJECT_CLASS (tpl_text_channel_parent_class)->dispose (obj); - - g_debug ("TplTextChannel: disposed\n"); } static void @@ -555,12 +550,8 @@ tpl_text_channel_finalize (GObject * obj) { TplTextChannel *self = TPL_TEXT_CHANNEL (obj); - g_debug ("TplTextChannel: finalizing\n"); - - g_free ((gchar *) self->chatroom_id); + g_free (self->chatroom_id); G_OBJECT_CLASS (tpl_text_channel_parent_class)->finalize (obj); - - g_debug ("TplTextChannel: finalized\n"); } static void @@ -577,12 +568,13 @@ static void tpl_text_channel_init (TplTextChannel * self) { /* Init TplTextChannel's members to zero/NULL */ -#undef TPL_SET_NULL + /* tpl_text_channel_set_tpl_channel (self, NULL); tpl_text_channel_set_my_contact (self, NULL); tpl_text_channel_set_remote_contact (self, NULL); tpl_text_channel_set_chatroom_id (self, NULL); tpl_text_channel_set_chatroom (self, FALSE); + */ } TplTextChannel * @@ -591,14 +583,18 @@ tpl_text_channel_new (TplChannel * tpl_channel) TplTextChannel *ret = g_object_new (TPL_TYPE_TEXT_CHANNEL, NULL); tpl_text_channel_set_tpl_channel (ret, tpl_channel); - // here some post instance-initialization, the object needs - // to set some type's members and probably access (futurely) some - // props + /* here some post instance-initialization, the object needs + to set some type's members and probably access (futurely) some + props */ TpHandleType remote_handle_type; tp_channel_get_handle (tpl_channel_get_channel (tpl_channel), &remote_handle_type); ret->chain = g_queue_new (); + + g_queue_push_tail (ret->chain, + _tpl_text_channel_pendingproc_connect_signals); + g_queue_push_tail (ret->chain, _tpl_text_channel_pendingproc_get_my_contact); @@ -631,10 +627,7 @@ tpl_text_channel_new (TplChannel * tpl_channel) break; } - g_queue_push_tail (ret->chain, - _tpl_text_channel_pendingproc_connect_signals); - - // start the chain consuming + // start the queue consuming context_continue (ret); return ret; } @@ -661,18 +654,23 @@ tpl_text_channel_get_my_contact (TplTextChannel * self) gboolean tpl_text_channel_is_chatroom (TplTextChannel * self) { + g_return_val_if_fail(TPL_IS_TEXT_CHANNEL (self), FALSE); return self->chatroom; } const gchar * tpl_text_channel_get_chatroom_id (TplTextChannel * self) { + g_return_val_if_fail(TPL_IS_TEXT_CHANNEL (self), NULL); return self->chatroom_id; } void tpl_text_channel_set_tpl_channel (TplTextChannel * self, TplChannel * data) { + g_return_if_fail (TPL_IS_TEXT_CHANNEL (self)); + g_return_if_fail (TPL_IS_CHANNEL (data)); + tpl_object_unref_if_not_null (self->tpl_channel); self->tpl_channel = data; tpl_object_ref_if_not_null (data); @@ -681,6 +679,9 @@ tpl_text_channel_set_tpl_channel (TplTextChannel * self, TplChannel * data) void tpl_text_channel_set_remote_contact (TplTextChannel * self, TpContact * data) { + g_return_if_fail (TPL_IS_TEXT_CHANNEL (self)); + g_return_if_fail (TP_IS_CONTACT (data)); + tpl_object_unref_if_not_null (self->remote_contact); self->remote_contact = data; tpl_object_ref_if_not_null (data); @@ -689,6 +690,9 @@ tpl_text_channel_set_remote_contact (TplTextChannel * self, TpContact * data) void tpl_text_channel_set_my_contact (TplTextChannel * self, TpContact * data) { + g_return_if_fail (TPL_IS_TEXT_CHANNEL (self)); + g_return_if_fail (TP_IS_CONTACT (data)); + tpl_object_unref_if_not_null (self->my_contact); self->my_contact = data; tpl_object_ref_if_not_null (data); @@ -697,12 +701,16 @@ tpl_text_channel_set_my_contact (TplTextChannel * self, TpContact * data) void tpl_text_channel_set_chatroom (TplTextChannel * self, gboolean data) { + g_return_if_fail (TPL_IS_TEXT_CHANNEL (self)); + self->chatroom = data; } void tpl_text_channel_set_chatroom_id (TplTextChannel * self, const gchar * data) { - g_free ((gchar *) self->chatroom_id); + g_return_if_fail (TPL_IS_TEXT_CHANNEL (self)); + + g_free (self->chatroom_id); self->chatroom_id = g_strdup (data); } diff --git a/telepathy-logger/channel-text.h b/telepathy-logger/channel-text.h index 069f077..878b0d6 100644 --- a/telepathy-logger/channel-text.h +++ b/telepathy-logger/channel-text.h @@ -52,12 +52,12 @@ G_BEGIN_DECLS TplChannel *tpl_channel; gboolean chatroom; TpContact *my_contact; - TpContact *remote_contact; // only set if chatroom==FALSE - const gchar *chatroom_id; // only set if chatroom==TRUE + TpContact *remote_contact; /* only set if chatroom==FALSE */ + gchar *chatroom_id; /* only set if chatroom==TRUE */ - GQueue *chain; // queue of TplPendingProc + GQueue *chain; /* queue of TplPendingProc */ - // only used as metadata in CB data passing + /* only used as metadata in CB data passing */ guint selector; } TplTextChannel; @@ -87,4 +87,4 @@ void tpl_text_channel_set_chatroom_id (TplTextChannel * self, const gchar * data); G_END_DECLS -#endif // __TPL_TEXT_CHANNEL_H__ +#endif /* __TPL_TEXT_CHANNEL_H__ */ diff --git a/telepathy-logger/channel.c b/telepathy-logger/channel.c index 7a75449..b83c2fc 100644 --- a/telepathy-logger/channel.c +++ b/telepathy-logger/channel.c @@ -27,12 +27,11 @@ #include <telepathy-logger/observer.h> G_DEFINE_TYPE (TplChannel, tpl_channel, G_TYPE_OBJECT) - static void tpl_channel_dispose (GObject * obj) + +static void tpl_channel_dispose (GObject * obj) { TplChannel *self = TPL_CHANNEL (obj); - g_debug ("TplChannel dispose start\n"); - tpl_object_unref_if_not_null (self->channel); self->channel = NULL; @@ -50,21 +49,18 @@ G_DEFINE_TYPE (TplChannel, tpl_channel, G_TYPE_OBJECT) self->observer = NULL; G_OBJECT_CLASS (tpl_channel_parent_class)->dispose (obj); - g_debug ("TplChannel dispose end\n"); } static void tpl_channel_finalize (GObject * obj) { TplChannel *self = TPL_CHANNEL (obj); - g_free ((gchar *) self->channel_path); - g_free ((gchar *) self->channel_type); - g_free ((gchar *) self->account_path); - g_free ((gchar *) self->connection_path); + g_free (self->channel_path); + g_free (self->channel_type); + g_free (self->account_path); + g_free (self->connection_path); G_OBJECT_CLASS (tpl_channel_parent_class)->finalize (obj); - - g_debug ("TplChannel instance finalized\n"); } static void @@ -200,7 +196,7 @@ tpl_channel_set_account_path (TplChannel * self, const gchar * data) g_return_if_fail (TPL_IS_CHANNEL (self)); // TODO check validity of data - g_free ((gchar *) self->account_path); + g_free (self->account_path); self->account_path = g_strdup (data); } @@ -221,7 +217,7 @@ tpl_channel_set_connection_path (TplChannel * self, const gchar * data) g_return_if_fail (TPL_IS_CHANNEL (self)); // TODO check validity of data - g_free ((gchar *) self->connection_path); + g_free (self->connection_path); self->connection_path = g_strdup (data); } @@ -242,7 +238,7 @@ tpl_channel_set_channel_path (TplChannel * self, const gchar * data) g_return_if_fail (TPL_IS_CHANNEL (self)); // TODO check validity of data - g_free ((gchar *) self->channel_path); + g_free (self->channel_path); self->channel_path = g_strdup (data); } @@ -252,7 +248,7 @@ tpl_channel_set_channel_type (TplChannel * self, const gchar * data) g_return_if_fail (TPL_IS_CHANNEL (self)); // TODO check validity of data - g_free ((gchar *) self->channel_type); + g_free (self->channel_type); self->channel_type = g_strdup (data); } @@ -292,12 +288,12 @@ tpl_channel_register_to_observer (TplChannel * self) g_debug ("Channel path not found, registering %s\n", key); } - // Instantiate and delegate channel handling to the right object + /* Instantiate and delegate channel handling to the right object */ if (0 == g_strcmp0 (TP_IFACE_CHAN_TEXT, tpl_channel_get_channel_type (self))) { - // when removed, automatically frees the Key and unrefs - // its Value + /* when removed, automatically frees the Key and unrefs + its Value */ TplTextChannel *chan_text = tpl_text_channel_new (self); g_hash_table_insert (glob_map, key, chan_text); } @@ -327,8 +323,9 @@ tpl_channel_unregister_from_observer (TplChannel * self) key = tpl_channel_get_channel_path (self); g_debug ("Unregistering channel path %s\n", key); - // this will destroy the associated value object: at this point - // the hash table reference should be the only one for the - // value's object + /* this will destroy the associated value object: at this point + the hash table reference should be the only one for the + value's object + */ return g_hash_table_remove (glob_map, key); } diff --git a/telepathy-logger/channel.h b/telepathy-logger/channel.h index 9b47ade..fc93916 100644 --- a/telepathy-logger/channel.h +++ b/telepathy-logger/channel.h @@ -47,14 +47,14 @@ G_BEGIN_DECLS /* private */ TpChannel *channel; - const gchar *channel_path; - const gchar *channel_type; + gchar *channel_path; + gchar *channel_type; GHashTable *channel_properties; TpAccount *account; - const gchar *account_path; + gchar *account_path; TpConnection *connection; - const gchar *connection_path; + gchar *connection_path; TpSvcClientObserver *observer; } TplChannel; diff --git a/telepathy-logger/conf.c b/telepathy-logger/conf.c index a38dc0d..ed2b350 100644 --- a/telepathy-logger/conf.c +++ b/telepathy-logger/conf.c @@ -1,33 +1,52 @@ - /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - /* - * Copyright (C) 2009 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> + */ #include "conf.h" #include <glib.h> -#define DEBUG(...) +#include <telepathy-logger/utils.h> + +//#define DEBUG(...) +#define GET_PRIV(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TPL_TYPE_CONF, TplConfPriv)) +//#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplConf) +#define GCONF_KEY_LOGGING_TURNED_ON "/apps/telepathy-logger/logging/turned_on" +#define GCONF_KEY_LOGGING_ACCOUNTS_IGNORELIST "/apps/telepathy-logger/logging/accounts/ignorelist" G_DEFINE_TYPE (TplConf, tpl_conf, G_TYPE_OBJECT) - static void tpl_conf_finalize (GObject * obj) + +static TplConf *conf_singleton = NULL; + +typedef struct { + GConfClient *client; +} TplConfPriv; + +static void tpl_conf_finalize (GObject * obj) { + TplConfPriv *priv; + + priv = GET_PRIV (TPL_CONF (obj)); + + tpl_object_unref_if_not_null (priv->client); + priv->client = NULL; G_OBJECT_CLASS (tpl_conf_parent_class)->finalize (obj); } @@ -35,59 +54,212 @@ G_DEFINE_TYPE (TplConf, tpl_conf, G_TYPE_OBJECT) static void tpl_conf_dispose (GObject * obj) { - TplConf *self = TPL_CONF (obj); - - tpl_object_unref_if_not_null (tpl_conf_get_entry (self)); - self->entry.generic = NULL; + /* TplConf *self = TPL_CONF (obj); */ G_OBJECT_CLASS (tpl_conf_parent_class)->dispose (obj); } +/* + * - TplConf constructor - + * Initialises GConfClient + */ + +static GObject * +tpl_conf_constructor (GType type, + guint n_props, GObjectConstructParam * props) +{ + GObject *retval; + + if (conf_singleton) + { + retval = g_object_ref (conf_singleton); + } + else + { + retval = G_OBJECT_CLASS (tpl_conf_parent_class)->constructor + (type, n_props, props); + conf_singleton = TPL_CONF (retval); + g_object_add_weak_pointer (retval, (gpointer *) &conf_singleton); + } + return retval; +} + + static void tpl_conf_class_init (TplConfClass * klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = tpl_conf_finalize; object_class->dispose = tpl_conf_dispose; + object_class->constructor = tpl_conf_constructor; + + g_type_class_add_private (object_class, sizeof (TplConfPriv)); } static void tpl_conf_init (TplConf * self) { - self->client = gconf_client_get_default (); +/* + TplConfPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + TPL_TYPE_CONF, TplConfPriv); +*/ + TplConfPriv *priv = GET_PRIV (self); + priv->client = gconf_client_get_default (); + +} + +/* + * You probably won't need to access directly the GConf client. + * In case you really need, remember to ref/unref properly. + */ +GConfClient * +tpl_conf_get_gconf_client(TplConf *self) { + return GET_PRIV(self)->client; } TplConf * -tpl_conf_new (void) +tpl_conf_dup (void) { return g_object_new (TPL_TYPE_CONF, NULL); } -#define GCONF_KEY_DISABLING_GLOBAL "/apps/telepathy-logger/disabling/global"; -#define GCONF_KEY_DISABLING_ACCOUNT_LIST "/apps/telepathy-logger/disabling/accounts/blocklist" -gboolean * -tpl_conf_is_enabled_globally (TplConf * self) +gboolean +tpl_conf_is_globally_enabled (TplConf * self, GError **error) { - GConfValue *val = - gconf_client_get (self->client, GCONF_KEY_DISABLING_GLOBAL, &error); - return !gconf_value_get_bool (val); + gboolean ret; + GError *loc_error = NULL; + + g_return_val_if_fail (TPL_IS_CONF (self), FALSE); + + ret = gconf_client_get_bool (GET_PRIV(self)->client, GCONF_KEY_LOGGING_TURNED_ON, + &loc_error); + if (loc_error != NULL) + { + g_warning("Accessing " GCONF_KEY_LOGGING_TURNED_ON": %s", loc_error->message); + g_propagate_error(error, loc_error); + g_clear_error(&loc_error); + g_error_free(loc_error); + return FALSE; + } + + return ret; } void -tpl_conf_enable_globally (TplConf * self) +tpl_conf_togle_globally_enable (TplConf *self, gboolean enable, GError **error) { - GConfValue *val = gconf_value_new (GCONF_VALUE_BOOL); - gconf_value_set_bool (val, FALSE); // not disabling - gconf_client_set (self->client, GCONF_KEY_DISABLING_GLOBAL, val); + GError *loc_error = NULL; + + g_return_if_fail (TPL_IS_CONF (self)); + + gconf_client_set_bool (GET_PRIV(self)->client, + GCONF_KEY_LOGGING_TURNED_ON, enable, &loc_error); + + /* According to GConf ref manual, an error is raised only if <key> is + * actually holding a differnt type than gboolean. It means something wrong + * is happening outside the library. + * + * TODO: is it better to return a GError as well? The above situation is not + * a real run-time error and can occur only on bad updated systems. 99.9% of + * times the schema+APIs will match and no error will be raised. + */ + if (loc_error != NULL) + { + g_error("Probably the Telepathy-Logger GConf's schema has changed " + "and you're using an out of date library\n"); + g_propagate_error(error, loc_error); + g_clear_error(&loc_error); + g_error_free(loc_error); + return; + } + } +GSList * +tpl_conf_get_accounts_ignorelist (TplConf * self, GError **error) +{ + GSList *ret; + GError *loc_error = NULL; + + g_return_val_if_fail (TPL_IS_CONF (self), NULL); + + ret = gconf_client_get_list (GET_PRIV(self)->client, + GCONF_KEY_LOGGING_ACCOUNTS_IGNORELIST, GCONF_VALUE_STRING, + &loc_error); + if (loc_error != NULL) + { + g_warning("Accessing " GCONF_KEY_LOGGING_ACCOUNTS_IGNORELIST": %s", loc_error->message); + g_propagate_error(error, loc_error); + g_clear_error(&loc_error); + g_error_free(loc_error); + return NULL; + } + + return ret; +} void -tpl_conf_enable_globally (TplConf * self) +tpl_conf_set_accounts_ignorelist (TplConf *self, GSList *newlist, + GError **error) +{ + GError *loc_error = NULL; + + g_return_if_fail (TPL_IS_CONF (self)); + + gconf_client_set_list (GET_PRIV(self)->client, + GCONF_KEY_LOGGING_ACCOUNTS_IGNORELIST, GCONF_VALUE_STRING, + newlist, &loc_error); + + /* According to GConf ref manual, an error is raised only if <key> is + * actually holding a differnt type than list. It means something wrong + * is happening outside the library. + * + * The above situation can occur only on bad updated systems. 99.9% of times + * the schema+APIs will match and no error will be raised. + */ + if (loc_error != NULL) + { + g_error("Probably the Telepathy-Logger GConf's schema has changed " + "and you're using an out of date library\n"); + g_propagate_error(error, loc_error); + g_clear_error(&loc_error); + g_error_free(loc_error); + return; + } +} + + +gboolean +tpl_conf_is_account_ignored (TplConf *self, const gchar *account_path, + GError **error) { - GConfValue *val = gconf_value_new (GCONF_VALUE_BOOL); - gconf_value_set_bool (val, TRUE); // disabling - gconf_client_set (self->client, GCONF_KEY_DISABLING_GLOBAL, val); + GError *loc_error = NULL; + GSList *ignored_list; + GSList *found_element; + + g_return_val_if_fail (TPL_IS_CONF (self), FALSE); + g_return_val_if_fail (!TPL_STR_EMPTY(account_path), FALSE); + + ignored_list = gconf_client_get_list (GET_PRIV(self)->client, + GCONF_KEY_LOGGING_ACCOUNTS_IGNORELIST, GCONF_VALUE_STRING, + &loc_error); + if (loc_error != NULL) + { + g_warning("Accessing " GCONF_KEY_LOGGING_ACCOUNTS_IGNORELIST": %s", loc_error->message); + g_propagate_error(error, loc_error); + g_clear_error(&loc_error); + g_error_free(loc_error); + return FALSE; + } + + found_element = g_slist_find_custom(ignored_list, + account_path, (GCompareFunc) g_strcmp0); + if(found_element != NULL) { + return TRUE; + } + + return FALSE; } diff --git a/telepathy-logger/conf.h b/telepathy-logger/conf.h new file mode 100644 index 0000000..4dc0798 --- /dev/null +++ b/telepathy-logger/conf.h @@ -0,0 +1,70 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> + */ + +#ifndef __TPL_CONF_H__ +#define __TPL_CONF_H__ + +#include <gconf/gconf-client.h> +#include <glib-object.h> + +G_BEGIN_DECLS + +#define TPL_TYPE_CONF (tpl_conf_get_type ()) +#define TPL_CONF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CONF, TplConf)) +#define TPL_CONF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CONF, TplConfClass)) +#define TPL_IS_CONF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CONF)) +#define TPL_IS_CONF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CONF)) +#define TPL_CONF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CONF, TplConfClass)) + +typedef struct +{ + GObject parent; + + /* private */ + gpointer priv; +} TplConf; + +typedef struct +{ + GObjectClass parent_class; +} TplConfClass; + +GType tpl_conf_get_type (void); + +TplConf *tpl_conf_dup (void); + +GConfClient *tpl_conf_get_gconf_client(TplConf *self); + +gboolean tpl_conf_is_globally_enabled (TplConf * self, GError **error); + +void tpl_conf_set_accounts_ignorelist (TplConf *self, GSList *newlist, GError + **error); + +void tpl_conf_togle_globally_enable (TplConf *self, gboolean enable, GError **error); + +GSList *tpl_conf_get_accounts_ignorelist (TplConf * self, GError **error); + +gboolean tpl_conf_is_account_ignored (TplConf *self, const gchar *account_path, GError **error); + + +G_END_DECLS + +#endif // __TPL_CONF_H__ diff --git a/telepathy-logger/log-entry-text.c b/telepathy-logger/log-entry-text.c index 0332f9d..0d01447 100644 --- a/telepathy-logger/log-entry-text.c +++ b/telepathy-logger/log-entry-text.c @@ -39,20 +39,12 @@ G_DEFINE_TYPE (TplLogEntryText, tpl_log_entry_text, G_TYPE_OBJECT) static void tpl_log_entry_text_init (TplLogEntryText * self) { -#define TPL_SET_NULL(x) tpl_log_entry_text_set_##x(self, NULL) - TPL_SET_NULL (tpl_text_channel); - TPL_SET_NULL (sender); - TPL_SET_NULL (receiver); - TPL_SET_NULL (message); - TPL_SET_NULL (chat_id); -#undef TPL_SET_NULL } static void tpl_log_entry_text_dispose (GObject * obj) { TplLogEntryText *self = TPL_LOG_ENTRY_TEXT (obj); - g_debug ("TplLogEntryText: disposing\n"); tpl_object_unref_if_not_null (self->tpl_text); self->tpl_text = NULL; @@ -62,8 +54,6 @@ tpl_log_entry_text_dispose (GObject * obj) self->receiver = NULL; G_OBJECT_CLASS (tpl_log_entry_text_parent_class)->finalize (obj); - - g_debug ("TplLogEntryText: disposed\n"); } static void @@ -71,16 +61,12 @@ tpl_log_entry_text_finalize (GObject * obj) { TplLogEntryText *self = TPL_LOG_ENTRY_TEXT (obj); - g_debug ("TplLogEntryText: finalizing\n"); - - g_free ((gchar *) self->message); + g_free (self->message); self->message = NULL; - g_free ((gchar *) self->chat_id); + g_free (self->chat_id); self->chat_id = NULL; G_OBJECT_CLASS (tpl_log_entry_text_parent_class)->dispose (obj); - - g_debug ("TplLogEntryText: finalized\n"); } @@ -133,6 +119,14 @@ tpl_log_entry_text_message_type_to_str (TpChannelTextMessageType msg_type) } +gboolean +tpl_log_entry_text_is_chatroom (TplLogEntryText * self) +{ + g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), FALSE); + + return self->chatroom; +} + TplChannel * tpl_log_entry_text_get_tpl_channel (TplLogEntryText * self) { @@ -243,7 +237,7 @@ tpl_log_entry_text_set_message (TplLogEntryText * self, const gchar * data) { g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); - g_free ((gchar *) self->message); + g_free (self->message); self->message = g_strdup (data); } @@ -287,6 +281,15 @@ tpl_log_entry_text_set_chat_id (TplLogEntryText * self, const gchar * data) { g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); - g_free ((gchar *) self->chat_id); + g_free (self->chat_id); self->chat_id = g_strdup (data); } + + +void +tpl_log_entry_text_set_chatroom (TplLogEntryText * self, gboolean data) +{ + g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); + + self->chatroom = data; +} diff --git a/telepathy-logger/log-entry-text.h b/telepathy-logger/log-entry-text.h index 7d6c32d..7b5d547 100644 --- a/telepathy-logger/log-entry-text.h +++ b/telepathy-logger/log-entry-text.h @@ -71,9 +71,9 @@ typedef struct // status changed signals set only the sender TplContact *sender; TplContact *receiver; - const gchar *message; + gchar *message; guint message_id; - const gchar *chat_id; + gchar *chat_id; gboolean chatroom; } TplLogEntryText; @@ -87,8 +87,7 @@ GType tpl_log_entry_text_get_type (void); TplLogEntryText *tpl_log_entry_text_new (void); TpChannelTextMessageType tpl_log_entry_text_message_type_from_str (const gchar - * - type_str); + * type_str); const gchar *tpl_log_entry_text_message_type_to_str (TpChannelTextMessageType msg_type); diff --git a/telepathy-logger/log-entry.c b/telepathy-logger/log-entry.c index cddddb0..99d0316 100644 --- a/telepathy-logger/log-entry.c +++ b/telepathy-logger/log-entry.c @@ -36,14 +36,10 @@ tpl_log_entry_dispose (GObject * obj) { TplLogEntry *self = TPL_LOG_ENTRY (obj); - DEBUG ("TplLogEntry: disposing\n"); - tpl_object_unref_if_not_null (tpl_log_entry_get_entry (self)); self->entry.generic = NULL; G_OBJECT_CLASS (tpl_log_entry_parent_class)->dispose (obj); - - DEBUG ("TplLogEntry: disposed\n"); } diff --git a/telepathy-logger/log-manager-priv.h b/telepathy-logger/log-manager-priv.h index 2bfcaea..a8ed7b9 100644 --- a/telepathy-logger/log-manager-priv.h +++ b/telepathy-logger/log-manager-priv.h @@ -27,8 +27,13 @@ #include <telepathy-logger/log-manager.h> gboolean tpl_log_manager_add_message (TplLogManager * manager, - const gchar * chat_id, - gboolean chatroom, TplLogEntry * message, GError ** error); +void tpl_log_manager_add_message_async (TplLogManager * manager, + TplLogEntry * message, + TplLogManagerAsyncCallback callback, + gpointer user_data, + GDestroyNotify destroy); + + #endif /* __TPL_LOG_MANAGER_PRIV_H__ */ diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c index f9f1a75..97ef591 100644 --- a/telepathy-logger/log-manager.c +++ b/telepathy-logger/log-manager.c @@ -51,6 +51,33 @@ typedef struct GList *stores; } TplLogManagerPriv; + +typedef void (*TplLogManagerFreeFunc) (gpointer * data); + +typedef struct +{ + TplLogManager *manager; + gpointer request; + TplLogManagerFreeFunc request_free; + TplLogManagerAsyncCallback cb; + gpointer user_data; +} TplLogManagerAsyncData; + + +typedef struct +{ + TpAccount *account; + gchar *chat_id; + gboolean is_chatroom; + gchar *date; + guint num_messages; + TplLogMessageFilter filter; + gchar *search_text; + gpointer user_data; + TplLogEntry *logentry; +} TplLogManagerChatInfo; + + G_DEFINE_TYPE (TplLogManager, tpl_log_manager, G_TYPE_OBJECT); static TplLogManager *manager_singleton = NULL; @@ -92,8 +119,8 @@ log_manager_constructor (GType type, priv = GET_PRIV (manager_singleton); priv->stores = g_list_append (priv->stores, - g_object_new (TPL_TYPE_LOG_STORE_EMPATHY, - NULL)); + g_object_new (TPL_TYPE_LOG_STORE_EMPATHY, + NULL)); } return retval; @@ -116,8 +143,19 @@ tpl_log_manager_init (TplLogManager * manager) TplLogManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, TPL_TYPE_LOG_MANAGER, TplLogManagerPriv); - manager->priv = priv; + + /* initialise thread support. It can be called just once, so check it already + * ON and call if if it's not. + * Threads are needed by Async APIs. + */ + if (!g_thread_supported ()) + { + g_debug ("Initializing GThread\n"); + g_thread_init (NULL); + } + else + g_debug ("GThread already initialized. Brilliant.\n"); } TplLogManager * @@ -129,8 +167,6 @@ tpl_log_manager_dup_singleton (void) gboolean tpl_log_manager_add_message (TplLogManager * manager, - const gchar * chat_id, - gboolean chatroom, TplLogEntry * message, GError ** error) { TplLogManagerPriv *priv; @@ -143,7 +179,6 @@ tpl_log_manager_add_message (TplLogManager * manager, const gchar *add_store = "TpLogger"; g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), FALSE); - g_return_val_if_fail (!TPL_STR_EMPTY (chat_id), FALSE); g_return_val_if_fail (TPL_IS_LOG_ENTRY (message), FALSE); priv = GET_PRIV (manager); @@ -154,7 +189,7 @@ tpl_log_manager_add_message (TplLogManager * manager, (tpl_log_store_get_name (TPL_LOG_STORE (l->data)), add_store)) { out = tpl_log_store_add_message (TPL_LOG_STORE (l->data), - chat_id, chatroom, message, error); + message, error); found = TRUE; break; } @@ -442,13 +477,13 @@ tpl_log_manager_get_date_readable (const gchar * date) /* Async */ -TplLogManagerAsyncData * +static TplLogManagerAsyncData * tpl_log_manager_async_data_new (void) { return g_slice_new (TplLogManagerAsyncData); } - -void +/* +static void tpl_log_manager_async_data_free (TplLogManagerAsyncData * data) { g_return_if_fail (TPL_IS_LOG_MANAGER (data->manager)); @@ -458,16 +493,16 @@ tpl_log_manager_async_data_free (TplLogManagerAsyncData * data) data->request_free (data->request); g_free (data); } +*/ - -TplLogManagerChatInfo * +static TplLogManagerChatInfo * tpl_log_manager_chat_info_new (void) { return g_slice_new0 (TplLogManagerChatInfo); } -void +static void tpl_log_manager_chat_info_free (TplLogManagerChatInfo * data) { tpl_object_unref_if_not_null (data->account); @@ -486,7 +521,6 @@ _tpl_log_manager_async_operation_finish (TplLogManager * manager, TplLogManagerAsyncData * async_data) { GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - g_print ("FINISH CALLED\n"); return g_simple_async_result_get_op_res_gpointer (simple); } @@ -499,7 +533,6 @@ _tpl_log_manager_async_operation_cb (GObject * source_object, TplLogManagerAsyncData *async_data = (TplLogManagerAsyncData *) user_data; gpointer retval; - g_message ("GSimple CB called: calling _finish to retrieve the result\n"); retval = _tpl_log_manager_async_operation_finish (manager, result, async_data); @@ -522,7 +555,6 @@ _tpl_log_manager_call_async_operation (TplLogManager * manager, { GSimpleAsyncResult *simple; - g_message ("called async\n"); simple = g_simple_async_result_new (G_OBJECT (manager), _tpl_log_manager_async_operation_cb, async_data, @@ -534,11 +566,78 @@ _tpl_log_manager_call_async_operation (TplLogManager * manager, /* end of Async common function */ -gboolean +/* Start of add_message async implementation */ + +static void +_add_message_async_thread (GSimpleAsyncResult * simple, GObject * object, + GCancellable * cancellable) +{ + TplLogManagerAsyncData *async_data; + TplLogManagerChatInfo *chat_info; + GError *error; + + async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); + chat_info = async_data->request; + + tpl_log_manager_add_message (async_data->manager, chat_info->logentry, + &error); + + if(error!=NULL) { + g_error("synchronous operation error: %s", error->message); + g_simple_async_result_set_from_error(simple, error); + g_clear_error(&error); + g_error_free(error); + } else + g_simple_async_result_set_op_res_gboolean (simple, TRUE); +} + +void tpl_log_manager_add_message_async (TplLogManager * manager, - const gchar * chat_id, - gboolean chatroom, - TplLogEntry * message, GError ** error) + TplLogEntry * message, + TplLogManagerAsyncCallback callback, + gpointer user_data, + GDestroyNotify destroy) +{ + TplLogManagerChatInfo *chat_info = tpl_log_manager_chat_info_new (); + TplLogManagerAsyncData *async_data = tpl_log_manager_async_data_new (); + + tpl_call_with_err_if_fail (TPL_IS_LOG_MANAGER (manager), manager, + TPL_LOG_MANAGER, FAILED, + "manager argument passed is not a TplManager instance", + callback, user_data); + tpl_call_with_err_if_fail (TPL_IS_LOG_ENTRY (message), manager, + TPL_LOG_MANAGER, FAILED, + "message argument passed is not a TplLogEntry instance", + callback, user_data); + + /* TODO check account, chat_id within entry, after TplLogEntry refactoring + tpl_call_with_err_if_fail (TP_IS_ACCOUNT (account), manager, + TPL_LOG_MANAGER, FAILED, + "account argument is not a TpAccount instance", + callback, user_data); + tpl_call_with_err_if_fail (!TPL_STR_EMPTY (chat_id), manager, + TPL_LOG_MANAGER, FAILED, + "chat_id argument passed cannot be empty string or NULL ptr", + callback, user_data); + */ + + + chat_info->logentry = message; + g_object_ref (chat_info->logentry); + + async_data->manager = manager; + g_object_ref (manager); + async_data->request = (gpointer) chat_info; + async_data->request_free = + (TplLogManagerFreeFunc) tpl_log_manager_chat_info_free; + async_data->cb = callback; + async_data->user_data = user_data; + + _tpl_log_manager_call_async_operation (manager, _add_message_async_thread, + async_data, callback); +} + +/* End of get_dates async implementation */ /* Start of get_dates async implementation */ @@ -553,13 +652,11 @@ _get_dates_async_thread (GSimpleAsyncResult * simple, GObject * object, async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); chat_info = async_data->request; - // use the sync method lst = tpl_log_manager_get_dates (async_data->manager, chat_info->account, chat_info->chat_id, chat_info->is_chatroom); g_simple_async_result_set_op_res_gpointer (simple, lst, NULL); // TODO add destructor - g_message ("THREAD!: GASYNC RESULT: SET GLIST PTR\n"); } @@ -624,7 +721,6 @@ _get_messages_for_date_async_thread (GSimpleAsyncResult * simple, async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); chat_info = async_data->request; - // use the sync method lst = tpl_log_manager_get_messages_for_date (async_data->manager, chat_info->account, chat_info->chat_id, @@ -632,7 +728,6 @@ _get_messages_for_date_async_thread (GSimpleAsyncResult * simple, chat_info->date); g_simple_async_result_set_op_res_gpointer (simple, lst, NULL); // TODO add destructor - g_message ("THREAD!: GASYNC RESULT: SET GLIST PTR\n"); } @@ -703,7 +798,6 @@ _get_filtered_messages_thread (GSimpleAsyncResult * simple, GObject * object, async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); chat_info = async_data->request; - // use the sync method lst = tpl_log_manager_get_filtered_messages (async_data->manager, chat_info->account, chat_info->chat_id, @@ -713,7 +807,6 @@ _get_filtered_messages_thread (GSimpleAsyncResult * simple, GObject * object, chat_info->user_data); g_simple_async_result_set_op_res_gpointer (simple, lst, NULL); // TODO add destructor - g_message ("THREAD!: GASYNC RESULT: SET GLIST PTR\n"); } @@ -789,7 +882,6 @@ _get_chats_thread (GSimpleAsyncResult * simple, GObject * object, async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); chat_info = async_data->request; - // use the sync method lst = tpl_log_manager_get_chats (async_data->manager, chat_info->account); g_simple_async_result_set_op_res_gpointer (simple, lst, NULL); // TODO add destructor @@ -831,3 +923,119 @@ tpl_log_manager_get_chats_async (TplLogManager * manager, } /* End of get_filtered_messages async implementation */ + +/* Start of tpl_log_manager_search_in_identifier_chats_new async implementation */ +static void +_search_in_identifier_chats_new_thread (GSimpleAsyncResult * simple, + GObject * object, + GCancellable * cancellable) +{ + TplLogManagerAsyncData *async_data; + TplLogManagerChatInfo *chat_info; + GList *lst; + + async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); + chat_info = async_data->request; + + lst = tpl_log_manager_search_in_identifier_chats_new (async_data->manager, chat_info->account, + chat_info->chat_id, chat_info->search_text); + + // TODO add destructor + g_simple_async_result_set_op_res_gpointer (simple, lst, NULL); +} + + +void +tpl_log_manager_search_in_identifier_chats_new_async (TplLogManager * + manager, + TpAccount * account, + gchar const + *identifier, + const gchar * text, + TplLogManagerAsyncCallback callback, + gpointer user_data, + GDestroyNotify destroy) +{ + TplLogManagerChatInfo *chat_info = tpl_log_manager_chat_info_new (); + TplLogManagerAsyncData *async_data = tpl_log_manager_async_data_new (); + + tpl_call_with_err_if_fail (TPL_IS_LOG_MANAGER (manager), manager, + TPL_LOG_MANAGER, FAILED, + "manager argument is not a TplManager instance", + callback, user_data); + tpl_call_with_err_if_fail (TP_IS_ACCOUNT (account), manager, + TPL_LOG_MANAGER, FAILED, + "account argument is not a TpAccount instance", + callback, user_data); + + chat_info->account = account; + g_object_ref (account); + chat_info->chat_id = g_strdup(identifier); + chat_info->search_text = g_strdup(text); + + async_data->manager = manager; + g_object_ref (manager); + async_data->request = (gpointer) chat_info; + async_data->request_free = + (TplLogManagerFreeFunc) tpl_log_manager_chat_info_free; + async_data->cb = callback; + async_data->user_data = user_data; + + _tpl_log_manager_call_async_operation (manager, + _search_in_identifier_chats_new_thread, + async_data, callback); +} +/* End of tpl_log_manager_search_in_identifier_chats_new async implementation */ + + +/* Start of tpl_log_manager_search_new async implementation */ +static void +_search_new_thread (GSimpleAsyncResult * simple, + GObject * object, + GCancellable * cancellable) +{ + TplLogManagerAsyncData *async_data; + TplLogManagerChatInfo *chat_info; + GList *lst; + + async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); + chat_info = async_data->request; + + lst = tpl_log_manager_search_new (async_data->manager, chat_info->search_text); + + // TODO add destructor + g_simple_async_result_set_op_res_gpointer (simple, lst, NULL); +} + + +void +tpl_log_manager_search_new_async (TplLogManager * manager, + const gchar * text, + TplLogManagerAsyncCallback callback, + gpointer user_data, + GDestroyNotify destroy) +{ + TplLogManagerChatInfo *chat_info = tpl_log_manager_chat_info_new (); + TplLogManagerAsyncData *async_data = tpl_log_manager_async_data_new (); + + tpl_call_with_err_if_fail (TPL_IS_LOG_MANAGER (manager), manager, + TPL_LOG_MANAGER, FAILED, + "manager argument is not a TplManager instance", + callback, user_data); + + chat_info->search_text = g_strdup(text); + + async_data->manager = manager; + g_object_ref (manager); + async_data->request = (gpointer) chat_info; + async_data->request_free = + (TplLogManagerFreeFunc) tpl_log_manager_chat_info_free; + async_data->cb = callback; + async_data->user_data = user_data; + + _tpl_log_manager_call_async_operation (manager, + _search_new_thread, + async_data, callback); +} + +/* End of tpl_log_manager_search_new async implementation */ diff --git a/telepathy-logger/log-manager.h b/telepathy-logger/log-manager.h index 8bcdf7f..0c7110b 100644 --- a/telepathy-logger/log-manager.h +++ b/telepathy-logger/log-manager.h @@ -39,13 +39,16 @@ G_BEGIN_DECLS #define TPL_LOG_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TPL_TYPE_LOG_MANAGER, TplLogManagerClass)) #define TPL_LOG_MANAGER_ERROR g_quark_from_static_string ("tpl-log-manager-error-quark") - typedef enum + +typedef enum { - TPL_LOG_MANAGER_ERROR_FAILED + /* generic error */ + TPL_LOG_MANAGER_ERROR_FAILED, + /* arg passed is not a valid GObject or in the expected format */ + TPL_LOG_MANAGER_ERROR_BAD_ARG } TplLogManagerError; - typedef struct { GObject parent; @@ -70,6 +73,10 @@ typedef struct typedef gboolean (*TplLogMessageFilter) (TplLogEntry * message, gpointer user_data); +typedef void (*TplLogManagerAsyncCallback) (TplLogManager * manager, + gpointer result, GError * error, + gpointer user_data); + GType tpl_log_manager_get_type (void); TplLogManager *tpl_log_manager_dup_singleton (void); @@ -82,77 +89,6 @@ GList *tpl_log_manager_get_dates (TplLogManager * manager, TpAccount * account, const gchar * chat_id, gboolean chatroom); - -GList *tpl_log_manager_get_messages_for_date (TplLogManager * manager, - TpAccount * account, - const gchar * chat_id, - gboolean chatroom, - const gchar * date); - -GList *tpl_log_manager_get_filtered_messages (TplLogManager * manager, - TpAccount * account, - const gchar * chat_id, - gboolean chatroom, - guint num_messages, - TplLogMessageFilter filter, - gpointer user_data); - -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); - -void tpl_log_manager_search_free (GList * hits); - -gchar *tpl_log_manager_get_date_readable (const gchar * date); - -void tpl_log_manager_search_hit_free (TplLogSearchHit * hit); - - -/* Async */ -typedef void (*TplLogManagerAsyncCallback) (TplLogManager * manager, - gpointer result, GError * error, - gpointer user_data); - -typedef void (*TplLogManagerFreeFunc) (gpointer * data); - -typedef struct -{ - TplLogManager *manager; - gpointer request; - TplLogManagerFreeFunc request_free; - TplLogManagerAsyncCallback cb; - gpointer user_data; -} TplLogManagerAsyncData; - -TplLogManagerAsyncData *tpl_log_manager_async_data_new (void); - -void tpl_log_manager_async_data_free (TplLogManagerAsyncData * data); - - -typedef struct -{ - TpAccount *account; - gchar *chat_id; - gboolean is_chatroom; - gchar *date; - guint num_messages; - TplLogMessageFilter filter; - gpointer user_data; -} TplLogManagerChatInfo; - -TplLogManagerChatInfo *tpl_log_manager_chat_info_new (void); - -void tpl_log_manager_chat_info_free (TplLogManagerChatInfo * data); - void tpl_log_manager_get_dates_async (TplLogManager * manager, TpAccount * account, const gchar * chat_id, @@ -162,6 +98,13 @@ void tpl_log_manager_get_dates_async (TplLogManager * manager, GDestroyNotify destroy); + +GList *tpl_log_manager_get_messages_for_date (TplLogManager * manager, + TpAccount * account, + const gchar * chat_id, + gboolean chatroom, + const gchar * date); + void tpl_log_manager_get_messages_for_date_async (TplLogManager * manager, TpAccount * account, const gchar * chat_id, @@ -172,6 +115,15 @@ void tpl_log_manager_get_messages_for_date_async (TplLogManager * manager, gpointer user_data, GDestroyNotify destroy); + +GList *tpl_log_manager_get_filtered_messages (TplLogManager * manager, + TpAccount * account, + const gchar * chat_id, + gboolean chatroom, + guint num_messages, + TplLogMessageFilter filter, + gpointer user_data); + void tpl_log_manager_get_filtered_messages_async (TplLogManager * manager, TpAccount * account, const gchar * chat_id, @@ -184,15 +136,44 @@ void tpl_log_manager_get_filtered_messages_async (TplLogManager * manager, gpointer user_data, GDestroyNotify destroy); -void -tpl_log_manager_get_chats_async (TplLogManager * manager, + +GList *tpl_log_manager_get_chats (TplLogManager * manager, + TpAccount * account); + +void tpl_log_manager_get_chats_async (TplLogManager * manager, TpAccount * account, TplLogManagerAsyncCallback callback, gpointer user_data, GDestroyNotify destroy); -/* End of Async */ +GList *tpl_log_manager_search_in_identifier_chats_new (TplLogManager *manager, + TpAccount * account, + gchar const *chat_id, + const gchar * text); + +void tpl_log_manager_search_in_identifier_chats_new_async (TplLogManager *manager, + TpAccount * account, + gchar const *chat_id, + const gchar *text, + TplLogManagerAsyncCallback callback, + gpointer user_data, + GDestroyNotify destroy); + + +GList *tpl_log_manager_search_new (TplLogManager * manager, + const gchar * text); + +void tpl_log_manager_search_new_async (TplLogManager * manager, + const gchar * text, + TplLogManagerAsyncCallback callback, + gpointer user_data, + GDestroyNotify destroy); +void tpl_log_manager_search_free (GList * hits); + +gchar *tpl_log_manager_get_date_readable (const gchar * date); + +void tpl_log_manager_search_hit_free (TplLogSearchHit * hit); G_END_DECLS #endif /* __TPL_LOG_MANAGER_H__ */ diff --git a/telepathy-logger/log-store-empathy.c b/telepathy-logger/log-store-empathy.c index eb35aec..81c83bf 100644 --- a/telepathy-logger/log-store-empathy.c +++ b/telepathy-logger/log-store-empathy.c @@ -273,8 +273,6 @@ _log_store_empathy_write_to_store (TplLogStore * self, /* currently unused */ static gboolean _log_store_empathy_add_message_text_status_changed (TplLogStore * self, - const gchar * chat_id, - gboolean chatroom, TplLogEntry * message, GError ** error) { @@ -289,8 +287,12 @@ _log_store_empathy_add_message_text_status_changed (TplLogStore * self, gchar *entry; gboolean ret = FALSE; TplLogEntryText *tmessage; + const gchar *chat_id; + gboolean chatroom; tmessage = tpl_log_entry_get_entry (message); + chat_id = tpl_log_entry_text_get_chat_id(tmessage); + chatroom = tpl_log_entry_text_is_chatroom(tmessage); sender = tpl_log_entry_text_get_sender (tmessage); account = tpl_channel_get_account (tpl_log_entry_text_get_tpl_channel (tmessage)); @@ -335,8 +337,6 @@ _log_store_empathy_add_message_text_status_changed (TplLogStore * self, static gboolean _log_store_empathy_add_message_text_chat (TplLogStore * self, - const gchar * chat_id, - gboolean chatroom, TplLogEntry * message, GError ** error) { @@ -352,10 +352,15 @@ _log_store_empathy_add_message_text_chat (TplLogStore * self, gchar *contact_name; gchar *contact_id; gchar *entry; + const gchar *chat_id; + gboolean chatroom; TpChannelTextMessageType msg_type; TplLogEntryText *tmessage; tmessage = tpl_log_entry_get_entry (message); + chat_id = tpl_log_entry_text_get_chat_id(tmessage); + chatroom = tpl_log_entry_text_is_chatroom(tmessage); + sender = tpl_log_entry_text_get_sender (tmessage); account = @@ -410,18 +415,19 @@ _log_store_empathy_add_message_text_chat (TplLogStore * self, static gboolean _log_store_empathy_add_message_text (TplLogStore * self, - const gchar * chat_id, - gboolean chatroom, TplLogEntry * message, GError ** error) { TplLogEntryTextSignalType signal_type; TplLogEntryText *tmessage; + const gchar *chat_id; + gboolean chatroom; g_return_val_if_fail (TPL_IS_LOG_STORE (self), FALSE); - g_return_val_if_fail (chat_id != NULL, FALSE); g_return_val_if_fail (TPL_IS_LOG_ENTRY (message), FALSE); tmessage = tpl_log_entry_get_entry (message); + chat_id = tpl_log_entry_text_get_chat_id (tmessage); + chatroom = tpl_log_entry_text_is_chatroom (tmessage); signal_type = tpl_log_entry_text_get_signal_type (tmessage); switch (signal_type) @@ -429,13 +435,10 @@ _log_store_empathy_add_message_text (TplLogStore * self, case TPL_LOG_ENTRY_TEXT_SIGNAL_SENT: case TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED: return _log_store_empathy_add_message_text_chat (self, - chat_id, chatroom, message, error); break; case TPL_LOG_ENTRY_TEXT_SIGNAL_CHAT_STATUS_CHANGED: return _log_store_empathy_add_message_text_status_changed (self, - chat_id, - chatroom, message, error); break; @@ -455,8 +458,6 @@ _log_store_empathy_add_message_text (TplLogStore * self, /* First of two phases selection: understand the type LogEntry */ static gboolean log_store_empathy_add_message (TplLogStore * self, - const gchar * chat_id, - gboolean chatroom, TplLogEntry * message, GError ** error) { g_return_val_if_fail (TPL_IS_LOG_ENTRY (message), FALSE); @@ -464,8 +465,7 @@ log_store_empathy_add_message (TplLogStore * self, switch (tpl_log_entry_get_entry_type (message)) { case TPL_LOG_ENTRY_TEXT: - return _log_store_empathy_add_message_text (self, chat_id, chatroom, - message, error); + return _log_store_empathy_add_message_text (self, message, error); default: return FALSE; } diff --git a/telepathy-logger/log-store.c b/telepathy-logger/log-store.c index 03f98a3..550b0f4 100644 --- a/telepathy-logger/log-store.c +++ b/telepathy-logger/log-store.c @@ -70,8 +70,6 @@ tpl_log_store_exists (TplLogStore * self, gboolean tpl_log_store_add_message (TplLogStore * self, - const gchar * chat_id, - gboolean chatroom, TplLogEntry * message, GError ** error) { if (!TPL_LOG_STORE_GET_INTERFACE (self)->add_message) @@ -80,8 +78,7 @@ tpl_log_store_add_message (TplLogStore * self, return FALSE; } - return TPL_LOG_STORE_GET_INTERFACE (self)->add_message (self, chat_id, - chatroom, message, + return TPL_LOG_STORE_GET_INTERFACE (self)->add_message (self, message, error); } diff --git a/telepathy-logger/log-store.h b/telepathy-logger/log-store.h index f24f45c..cc9262a 100644 --- a/telepathy-logger/log-store.h +++ b/telepathy-logger/log-store.h @@ -49,8 +49,7 @@ struct _TplLogStoreInterface const gchar *(*get_name) (TplLogStore * self); gboolean (*exists) (TplLogStore * self, TpAccount * account, const gchar * chat_id, gboolean chatroom); - gboolean (*add_message) (TplLogStore * self, const gchar * chat_id, - gboolean chatroom, TplLogEntry * message, + gboolean (*add_message) (TplLogStore * self, TplLogEntry * message, GError ** error); GList *(*get_dates) (TplLogStore * self, TpAccount * account, const gchar * chat_id, gboolean chatroom); @@ -80,8 +79,7 @@ const gchar *tpl_log_store_get_name (TplLogStore * self); gboolean tpl_log_store_exists (TplLogStore * self, TpAccount * account, const gchar * chat_id, gboolean chatroom); -gboolean tpl_log_store_add_message (TplLogStore * self, const gchar * chat_id, - gboolean chatroom, TplLogEntry * message, +gboolean tpl_log_store_add_message (TplLogStore * self, TplLogEntry * message, GError ** error); GList *tpl_log_store_get_dates (TplLogStore * self, TpAccount * account, const gchar * chat_id, gboolean chatroom); diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c index 03457d1..5685f11 100644 --- a/telepathy-logger/observer.c +++ b/telepathy-logger/observer.c @@ -29,6 +29,7 @@ #include <telepathy-glib/svc-generic.h> #include <telepathy-glib/svc-client.h> +#include <telepathy-logger/conf.h> #include <telepathy-logger/channel.h> #include <telepathy-logger/channel-text.h> #include <telepathy-logger/log-manager.h> @@ -81,7 +82,6 @@ _observe_channel_when_ready_cb (TpChannel * channel, tpl_channel_set_channel_type (tpl_chan, tp_channel_get_channel_type (tpl_chan->channel)); - tpl_channel_register_to_observer (tpl_chan); } @@ -109,8 +109,22 @@ tpl_observer_observe_channels (TpSvcClientObserver * self, TpAccount *tp_acc; TpConnection *tp_conn; TpDBusDaemon *tp_bus_daemon; + TplConf *conf; GError *error = NULL; + g_return_if_fail (TP_IS_ACCOUNT (account) ); + g_return_if_fail (TP_IS_CONNECTION (connection) ); + + /* Check if logging if enabled globally and for the given account_path, + * return imemdiatly if it's not + */ + + conf = tpl_conf_dup(); + if (!tpl_conf_is_globally_enabled(conf, NULL)) + return; + if (tpl_conf_is_account_ignored(conf, account, NULL)) + return; + tp_bus_daemon = tp_dbus_daemon_dup (&error); if (tp_bus_daemon == NULL) { @@ -354,8 +368,6 @@ tpl_observer_dispose (GObject * obj) { TplObserver *self = TPL_OBSERVER (obj); - g_debug ("TplObserver: disposing\n"); - if (self->channel_map != NULL) { g_object_unref (self->channel_map); @@ -368,8 +380,6 @@ tpl_observer_dispose (GObject * obj) } G_OBJECT_CLASS (tpl_observer_parent_class)->dispose (obj); - - g_debug ("TplObserver: disposed\n"); } static void @@ -377,11 +387,7 @@ tpl_observer_finalize (GObject * obj) { //TplObserver *self = TPL_OBSERVER(obj); - g_debug ("TplObserver: finalizing\n"); - G_OBJECT_CLASS (tpl_observer_parent_class)->finalize (obj); - - g_debug ("TplObserver: finalized\n"); } TplObserver * diff --git a/telepathy-logger/telepathy-logger.schemas b/telepathy-logger/telepathy-logger.schemas index 511dc94..5b7fdb2 100644 --- a/telepathy-logger/telepathy-logger.schemas +++ b/telepathy-logger/telepathy-logger.schemas @@ -2,21 +2,21 @@ <schemalist> <schema> - <key>/schemas/apps/telepathy-logger/disabling/global</key> - <applyto>/apps/telepathy-logger/disabling/global</applyto> + <key>/schemas/apps/telepathy-logger/logging/turned_on</key> + <applyto>/apps/telepathy-logger/logging/turned_on</applyto> <owner>telepathy-logger</owner> <type>bool</type> <default>TRUE</default> <locale name="C"> - <short>Globally enable or to disable logging</short> + <short>Turn on/off logging</short> <long>Globally enable or disable the telepathy logging system. -Setting it to "false" will completely disable any logging</long> +Setting it to "false" will completely disable any logging facility (it won't shut down the service)</long> </locale> </schema> <schema> - <key>/schemas/apps/telepathy-logger/disabling/accounts/blocklist</key> - <applyto>/apps/telepathy-logger/disabling/accounts/blocklist</applyto> + <key>/schemas/apps/telepathy-logger/logging/accounts/ignorelist</key> + <applyto>/apps/telepathy-logger/logging/accounts/ignorelist</applyto> <owner>telepathy-logger</owner> <type>list</type> <list_type>string</list_type> @@ -24,7 +24,7 @@ Setting it to "false" will completely disable any logging</long> <locale name="C"> <short>A list of accounts for which logging is disabled</short> <long>Disables logging for the named accounts, when logging is -globally enabled. Globally disabling logging will ignore this key.</long> +globally enabled. Meaningful only if global logging is turned on/enabled</long> </locale> </schema> diff --git a/telepathy-logger/utils.h b/telepathy-logger/utils.h index acf4740..56fac99 100644 --- a/telepathy-logger/utils.h +++ b/telepathy-logger/utils.h @@ -25,6 +25,7 @@ #include <glib-object.h> #define TPL_GET_PRIV(obj,type) ((type##Priv *) ((type *) obj)->priv) + #define TPL_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0') /* |