From 539a135861699eed057511f753ba8793c07f53d5 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 10 Jan 2011 15:58:13 -0500 Subject: [PATCH] Renamed TplEntry* into TplEvent* --- doc/reference/libtelepathy-logger/Makefile.am | 4 +- doc/reference/libtelepathy-logger/docs.xml | 4 +- extensions/Logger.xml | 2 +- telepathy-logger/Makefile.am | 12 +- telepathy-logger/channel-text.c | 116 +++--- telepathy-logger/dbus-service.c | 30 +- telepathy-logger/debug-internal.h | 2 +- telepathy-logger/debug.c | 2 +- telepathy-logger/entry-internal.h | 86 ---- telepathy-logger/entry-text-internal.h | 100 ----- telepathy-logger/entry-text.c | 453 -------------------- telepathy-logger/entry-text.h | 48 --- telepathy-logger/entry.c | 556 ------------------------- telepathy-logger/entry.h | 62 --- telepathy-logger/event-internal.h | 86 ++++ telepathy-logger/event-text-internal.h | 100 +++++ telepathy-logger/event-text.c | 453 ++++++++++++++++++++ telepathy-logger/event-text.h | 48 +++ telepathy-logger/event.c | 556 +++++++++++++++++++++++++ telepathy-logger/event.h | 62 +++ telepathy-logger/log-manager-internal.h | 2 +- telepathy-logger/log-manager.c | 38 +- telepathy-logger/log-manager.h | 4 +- telepathy-logger/log-store-internal.h | 6 +- telepathy-logger/log-store-sqlite.c | 90 ++-- telepathy-logger/log-store-xml.c | 120 +++--- telepathy-logger/log-store.c | 10 +- telepathy-logger/telepathy-logger.h | 4 +- tests/test-tpl-log-manager.c | 2 +- 29 files changed, 1529 insertions(+), 1529 deletions(-) delete mode 100644 telepathy-logger/entry-internal.h delete mode 100644 telepathy-logger/entry-text-internal.h delete mode 100644 telepathy-logger/entry-text.c delete mode 100644 telepathy-logger/entry-text.h delete mode 100644 telepathy-logger/entry.c delete mode 100644 telepathy-logger/entry.h create mode 100644 telepathy-logger/event-internal.h create mode 100644 telepathy-logger/event-text-internal.h create mode 100644 telepathy-logger/event-text.c create mode 100644 telepathy-logger/event-text.h create mode 100644 telepathy-logger/event.c create mode 100644 telepathy-logger/event.h diff --git a/doc/reference/libtelepathy-logger/Makefile.am b/doc/reference/libtelepathy-logger/Makefile.am index 833adf8..ff8f263 100644 --- a/doc/reference/libtelepathy-logger/Makefile.am +++ b/doc/reference/libtelepathy-logger/Makefile.am @@ -65,8 +65,8 @@ IGNORE_HFILES=\ datetime-internal.h \ dbus-service-internal.h \ debug-internal.h \ - entry-internal.h \ - entry-text-internal.h \ + event-internal.h \ + event-text-internal.h \ log-manager-internal.h \ log-store-factory-internal.h \ log-store-internal.h \ diff --git a/doc/reference/libtelepathy-logger/docs.xml b/doc/reference/libtelepathy-logger/docs.xml index 880e8ac..79353cc 100644 --- a/doc/reference/libtelepathy-logger/docs.xml +++ b/doc/reference/libtelepathy-logger/docs.xml @@ -10,8 +10,8 @@ libtelepathy-logger API - - + + diff --git a/extensions/Logger.xml b/extensions/Logger.xml index 9f101e3..bb2a456 100644 --- a/extensions/Logger.xml +++ b/extensions/Logger.xml @@ -41,7 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Unix timestamp for the log entry + Unix timestamp for the log event diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am index 38c75a2..5887ed5 100644 --- a/telepathy-logger/Makefile.am +++ b/telepathy-logger/Makefile.am @@ -19,8 +19,8 @@ lib_LTLIBRARIES = libtelepathy-logger.la LIBTPLdir = $(includedir)/telepathy-logger-0.1/telepathy-logger LIBTPL_HEADERS = \ entity.h \ - entry.h \ - entry-text.h \ + event.h \ + event-text.h \ log-manager.h \ telepathy-logger.h \ $(NULL) @@ -55,10 +55,10 @@ libtelepathy_logger_la_SOURCES = \ dbus-service-internal.h \ debug-internal.h \ debug.c \ - entry.c \ - entry-internal.h \ - entry-text.c \ - entry-text-internal.h \ + event.c \ + event-internal.h \ + event-text.c \ + event-text-internal.h \ log-manager.c \ log-manager-internal.h \ log-store.c \ diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c index fdc990c..d7f4795 100644 --- a/telepathy-logger/channel-text.c +++ b/telepathy-logger/channel-text.c @@ -29,9 +29,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -95,7 +95,7 @@ static void pendingproc_cleanup_pending_messages_db (TplActionChain *ctx, gpointer user_data); #endif -static void keepon_on_receiving_signal (TplEntryText *log, +static void keepon_on_receiving_signal (TplEventText *log, TpContact *remote); static void got_message_pending_messages_cb (TpProxy *proxy, const GValue *out_Value, const GError *error, gpointer user_data, @@ -726,7 +726,7 @@ got_message_pending_messages_cb (TpProxy *proxy, { DEBUG ("pending-message-id not in a valid range, setting to " "UNKNOWN"); - message_id = TPL_ENTRY_MSG_ID_UNKNOWN; + message_id = TPL_EVENT_MSG_ID_UNKNOWN; } message_timestamp = tp_asv_get_uint64 (message_headers, "message-received", NULL); @@ -1050,8 +1050,8 @@ on_sent_signal_cb (TpChannel *proxy, TpContact *me; TplEntity *tpl_entity_sender; TplEntity *tpl_entity_receiver = NULL; - TplEntryText *text_log; - TplEntry *log; + TplEventText *text_log; + TplEvent *log; TplLogManager *logmanager; const gchar *chat_id; TpAccount *account; @@ -1062,7 +1062,7 @@ on_sent_signal_cb (TpChannel *proxy, channel_path = tp_proxy_get_object_path (TP_PROXY (tpl_text)); log_id = _tpl_create_message_token (channel_path, arg_Timestamp, - TPL_ENTRY_MSG_ID_ACKNOWLEDGED); + TPL_EVENT_MSG_ID_ACKNOWLEDGED); /* Initialize data for TplEntity */ me = _tpl_channel_text_get_my_contact (tpl_text); @@ -1102,7 +1102,7 @@ on_sent_signal_cb (TpChannel *proxy, arg_Text); } - /* Initialise TplEntryText */ + /* Initialise TplEventText */ if (!_tpl_channel_text_is_chatroom (tpl_text)) chat_id = tpl_entity_get_identifier (tpl_entity_receiver); else @@ -1110,30 +1110,30 @@ on_sent_signal_cb (TpChannel *proxy, account = _tpl_channel_get_account (TPL_CHANNEL (tpl_text)); - text_log = _tpl_entry_text_new (log_id, account, - TPL_ENTRY_DIRECTION_OUT); - log = TPL_ENTRY (text_log); + text_log = _tpl_event_text_new (log_id, account, + TPL_EVENT_DIRECTION_OUT); + log = TPL_EVENT (text_log); - _tpl_entry_text_set_pending_msg_id (text_log, - TPL_ENTRY_MSG_ID_ACKNOWLEDGED); - _tpl_entry_set_channel_path (TPL_ENTRY (log), channel_path); - _tpl_entry_set_chat_id (log, chat_id); - _tpl_entry_set_timestamp (log, (time_t) arg_Timestamp); - _tpl_entry_set_sender (log, tpl_entity_sender); + _tpl_event_text_set_pending_msg_id (text_log, + TPL_EVENT_MSG_ID_ACKNOWLEDGED); + _tpl_event_set_channel_path (TPL_EVENT (log), channel_path); + _tpl_event_set_chat_id (log, chat_id); + _tpl_event_set_timestamp (log, (time_t) arg_Timestamp); + _tpl_event_set_sender (log, tpl_entity_sender); /* NULL when it's a chatroom */ if (tpl_entity_receiver != NULL) - _tpl_entry_set_receiver (log, tpl_entity_receiver); - _tpl_entry_text_set_message (text_log, arg_Text); - _tpl_entry_text_set_signal_type (text_log, TPL_ENTRY_TEXT_SIGNAL_SENT); - _tpl_entry_text_set_message_type (text_log, arg_Type); - _tpl_entry_text_set_tpl_channel_text (text_log, tpl_text); - - /* Initialized LogStore and send the log entry */ - _tpl_entry_text_set_chatroom (text_log, + _tpl_event_set_receiver (log, tpl_entity_receiver); + _tpl_event_text_set_message (text_log, arg_Text); + _tpl_event_text_set_signal_type (text_log, TPL_EVENT_TEXT_SIGNAL_SENT); + _tpl_event_text_set_message_type (text_log, arg_Type); + _tpl_event_text_set_tpl_channel_text (text_log, tpl_text); + + /* Initialized LogStore and send the log event */ + _tpl_event_text_set_chatroom (text_log, _tpl_channel_text_is_chatroom (tpl_text)); logmanager = tpl_log_manager_dup_singleton (); - _tpl_log_manager_add_event (logmanager, TPL_ENTRY (log), &error); + _tpl_log_manager_add_event (logmanager, TPL_EVENT (log), &error); if (error != NULL) { @@ -1161,21 +1161,21 @@ on_received_signal_with_contact_cb (TpConnection *connection, gpointer user_data, GObject *weak_object) { - TplEntryText *log = user_data; + TplEventText *log = user_data; TplChannelText *tpl_text; TpContact *remote; TpHandle handle; - g_return_if_fail (TPL_IS_ENTRY_TEXT (log)); + g_return_if_fail (TPL_IS_EVENT_TEXT (log)); - tpl_text = _tpl_entry_text_get_tpl_channel_text (log); + tpl_text = _tpl_event_text_get_tpl_channel_text (log); if (error != NULL) { PATH_DEBUG (tpl_text, "An Unrecoverable error retrieving remote contact " "information occured: %s", error->message); PATH_DEBUG (tpl_text, "Unable to log the received message: %s", - tpl_entry_text_get_message (log)); + tpl_event_text_get_message (log)); g_object_unref (log); return; } @@ -1185,7 +1185,7 @@ on_received_signal_with_contact_cb (TpConnection *connection, PATH_DEBUG (tpl_text, "%d invalid handle(s) passed to " "tp_connection_get_contacts_by_handle()", n_failed); PATH_DEBUG (tpl_text, "Not able to log the received message: %s", - tpl_entry_text_get_message (log)); + tpl_event_text_get_message (log)); g_object_unref (log); return; } @@ -1201,10 +1201,10 @@ on_received_signal_with_contact_cb (TpConnection *connection, static void -keepon_on_receiving_signal (TplEntryText *text_log, +keepon_on_receiving_signal (TplEventText *text_log, TpContact *remote) { - TplEntry *log = TPL_ENTRY (text_log); + TplEvent *log = TPL_EVENT (text_log); TplChannelText *tpl_text; GError *e = NULL; TplLogManager *logmanager; @@ -1212,39 +1212,39 @@ keepon_on_receiving_signal (TplEntryText *text_log, TplEntity *tpl_entity_receiver; TpContact *local; - g_return_if_fail (TPL_IS_ENTRY_TEXT (text_log)); + g_return_if_fail (TPL_IS_EVENT_TEXT (text_log)); - tpl_text = _tpl_entry_text_get_tpl_channel_text (text_log); + tpl_text = _tpl_event_text_get_tpl_channel_text (text_log); local = _tpl_channel_text_get_my_contact (tpl_text); tpl_entity_sender = _tpl_entity_from_tp_contact (remote); _tpl_entity_set_entity_type (tpl_entity_sender, TPL_ENTITY_CONTACT); - _tpl_entry_set_sender (log, tpl_entity_sender); + _tpl_event_set_sender (log, tpl_entity_sender); tpl_entity_receiver = _tpl_entity_from_tp_contact (local); DEBUG ("recvd:\n\tlog_id=\"%s\"\n\tto=\"%s " "(%s)\"\n\tfrom=\"%s (%s)\"\n\tmsg=\"%s\"", - _tpl_entry_get_log_id (log), + _tpl_event_get_log_id (log), tpl_entity_get_identifier (tpl_entity_receiver), tpl_entity_get_alias (tpl_entity_receiver), tpl_entity_get_identifier (tpl_entity_sender), tpl_entity_get_alias (tpl_entity_sender), - tpl_entry_text_get_message (text_log)); + tpl_event_text_get_message (text_log)); if (!_tpl_channel_text_is_chatroom (tpl_text)) - _tpl_entry_set_chat_id (log, tpl_entity_get_identifier ( + _tpl_event_set_chat_id (log, tpl_entity_get_identifier ( tpl_entity_sender)); else - _tpl_entry_set_chat_id (log, _tpl_channel_text_get_chatroom_id ( + _tpl_event_set_chat_id (log, _tpl_channel_text_get_chatroom_id ( tpl_text)); - _tpl_entry_text_set_chatroom (text_log, + _tpl_event_text_set_chatroom (text_log, _tpl_channel_text_is_chatroom (tpl_text)); logmanager = tpl_log_manager_dup_singleton (); - _tpl_log_manager_add_event (logmanager, TPL_ENTRY (log), &e); + _tpl_log_manager_add_event (logmanager, TPL_EVENT (log), &e); if (e != NULL) { DEBUG ("%s", e->message); @@ -1273,8 +1273,8 @@ on_received_signal_cb (TpChannel *proxy, TpConnection *tp_conn; TpContact *me, *remote; TplEntity *tpl_entity_receiver = NULL; - TplEntryText *text_log = NULL; - TplEntry *log; + TplEventText *text_log = NULL; + TplEvent *log; TpAccount *account = _tpl_channel_get_account (TPL_CHANNEL (tpl_text)); TplLogStore *index = _tpl_log_store_sqlite_dup (); const gchar *channel_path = tp_proxy_get_object_path (TP_PROXY (tpl_text)); @@ -1315,25 +1315,25 @@ on_received_signal_cb (TpChannel *proxy, return; } - /* Initialize TplEntryText (part 1) - chat_id still unknown */ - text_log = _tpl_entry_text_new (log_id, account, - TPL_ENTRY_DIRECTION_IN); - log = TPL_ENTRY (text_log); + /* Initialize TplEventText (part 1) - chat_id still unknown */ + text_log = _tpl_event_text_new (log_id, account, + TPL_EVENT_DIRECTION_IN); + log = TPL_EVENT (text_log); - _tpl_entry_set_channel_path (log, channel_path); - _tpl_entry_text_set_pending_msg_id (text_log, arg_ID); - _tpl_entry_text_set_tpl_channel_text (text_log, tpl_text); - _tpl_entry_text_set_message (text_log, arg_Text); - _tpl_entry_text_set_message_type (text_log, arg_Type); - _tpl_entry_text_set_signal_type (text_log, - TPL_ENTRY_TEXT_SIGNAL_RECEIVED); + _tpl_event_set_channel_path (log, channel_path); + _tpl_event_text_set_pending_msg_id (text_log, arg_ID); + _tpl_event_text_set_tpl_channel_text (text_log, tpl_text); + _tpl_event_text_set_message (text_log, arg_Text); + _tpl_event_text_set_message_type (text_log, arg_Type); + _tpl_event_text_set_signal_type (text_log, + TPL_EVENT_TEXT_SIGNAL_RECEIVED); me = _tpl_channel_text_get_my_contact (tpl_text); tpl_entity_receiver = _tpl_entity_from_tp_contact (me); _tpl_entity_set_entity_type (tpl_entity_receiver, TPL_ENTITY_SELF); - _tpl_entry_set_receiver (log, tpl_entity_receiver); + _tpl_event_set_receiver (log, tpl_entity_receiver); - _tpl_entry_set_timestamp (log, (time_t) arg_Timestamp); + _tpl_event_set_timestamp (log, (time_t) arg_Timestamp); tp_conn = tp_channel_borrow_connection (TP_CHANNEL (tpl_chan)); remote = g_hash_table_lookup (tpl_text->priv->contacts, diff --git a/telepathy-logger/dbus-service.c b/telepathy-logger/dbus-service.c index 755ed8d..e6db2af 100644 --- a/telepathy-logger/dbus-service.c +++ b/telepathy-logger/dbus-service.c @@ -31,8 +31,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -109,12 +109,12 @@ favourite_contact_closure_new (TplDBusService *self, static gboolean -favourite_contacts_add_entry (TplDBusService *self, +favourite_contacts_add_event (TplDBusService *self, const gchar *account, const gchar *contact_id) { GHashTable *contacts; - gboolean new_entry = FALSE; + gboolean new_event = FALSE; TplDBusServicePriv *priv; g_return_val_if_fail (TPL_IS_DBUS_SERVICE (self), FALSE); @@ -133,14 +133,14 @@ favourite_contacts_add_entry (TplDBusService *self, (GDestroyNotify) g_free, NULL); g_hash_table_insert (priv->accounts_contacts_map, g_strdup (account), contacts); - new_entry = TRUE; + new_event = TRUE; } else if (g_hash_table_lookup (contacts, contact_id) == NULL) { - new_entry = TRUE; + new_event = TRUE; } - if (new_entry) + if (new_event) { /* add dummy string for the value just for the convenience of looking up * whether the key already exists */ @@ -148,7 +148,7 @@ favourite_contacts_add_entry (TplDBusService *self, GINT_TO_POINTER (TRUE)); } - return new_entry; + return new_event; } @@ -187,7 +187,7 @@ favourite_contacts_parse_line (TplDBusService *self, success = FALSE; } else - favourite_contacts_add_entry (self, elements[0], elements[1]); + favourite_contacts_add_event (self, elements[0], elements[1]); g_strfreev (elements); @@ -405,12 +405,12 @@ _get_events_return (GObject *manager, ptr != NULL && ctx->lines > 0; ptr = g_list_previous (ptr)) { - TplEntry *log = ptr->data; - const char *message = tpl_entry_text_get_message ( - TPL_ENTRY_TEXT (log)); + TplEvent *log = ptr->data; + const char *message = tpl_event_text_get_message ( + TPL_EVENT_TEXT (log)); const char *sender = tpl_entity_get_identifier ( - tpl_entry_get_sender (log)); - gint64 timestamp = tpl_entry_get_timestamp (log); + tpl_event_get_sender (log)); + gint64 timestamp = tpl_event_get_timestamp (log); DEBUG ("Message: %" G_GINT64_FORMAT " <%s> %s", timestamp, sender, message); @@ -775,7 +775,7 @@ pendingproc_add_favourite_contact (TplActionChain *action_chain, goto pendingproc_add_favourite_contact_ERROR; } - should_add = favourite_contacts_add_entry (closure->service, closure->account, + should_add = favourite_contacts_add_event (closure->service, closure->account, closure->contact_id); closure->cb = add_favourite_contact_file_save_cb; diff --git a/telepathy-logger/debug-internal.h b/telepathy-logger/debug-internal.h index 72a3c27..172c88b 100644 --- a/telepathy-logger/debug-internal.h +++ b/telepathy-logger/debug-internal.h @@ -40,7 +40,7 @@ typedef enum TPL_DEBUG_ENTITY = 1 << 2, TPL_DEBUG_CHANNEL = 1 << 3, TPL_DEBUG_DBUS_SERVICE = 1 << 4, - TPL_DEBUG_LOG_ENTRY = 1 << 5, + TPL_DEBUG_LOG_EVENT = 1 << 5, TPL_DEBUG_LOG_MANAGER = 1 << 6, TPL_DEBUG_LOG_STORE = 1 << 7, TPL_DEBUG_MAIN = 1 << 8, diff --git a/telepathy-logger/debug.c b/telepathy-logger/debug.c index c587505..c16dd36 100644 --- a/telepathy-logger/debug.c +++ b/telepathy-logger/debug.c @@ -34,7 +34,7 @@ static GDebugKey keys[] = { { "conf", TPL_DEBUG_CONF }, { "entity", TPL_DEBUG_ENTITY }, { "dbus-service", TPL_DEBUG_DBUS_SERVICE }, - { "log-entry", TPL_DEBUG_LOG_ENTRY }, + { "log-event", TPL_DEBUG_LOG_EVENT }, { "log-manager", TPL_DEBUG_LOG_MANAGER }, { "log-store", TPL_DEBUG_LOG_STORE }, { "main", TPL_DEBUG_MAIN }, diff --git a/telepathy-logger/entry-internal.h b/telepathy-logger/entry-internal.h deleted file mode 100644 index 84750f2..0000000 --- a/telepathy-logger/entry-internal.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- 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 - */ - -#ifndef __TPL_ENTRY_INTERNAL_H__ -#define __TPL_ENTRY_INTERNAL_H__ - -#include - -G_BEGIN_DECLS - -#define TPL_ENTRY_MSG_ID_IS_VALID(msg) (msg >= 0) - -#define TPL_ENTRY_MSG_ID_UNKNOWN -2 -#define TPL_ENTRY_MSG_ID_ACKNOWLEDGED -1 - -typedef enum -{ - TPL_ENTRY_ERROR, - TPL_ENTRY_TEXT -} TplEntryType; - - -struct _TplEntry -{ - GObject parent; - - /* Private */ - TplEntryPriv *priv; -}; - -struct _TplEntryClass { - GObjectClass parent_class; - - /* to be implemented only by subclasses */ - gboolean (*equal) (TplEntry *entry1, TplEntry *entry2); -}; - - -void _tpl_entry_set_timestamp (TplEntry *self, - gint64 data); - -void _tpl_entry_set_direction (TplEntry *self, - TplEntryDirection data); - -void _tpl_entry_set_chat_id (TplEntry *self, - const gchar *data); - -void _tpl_entry_set_channel_path (TplEntry *self, - const gchar *data); - -void _tpl_entry_set_sender (TplEntry *self, - TplEntity *data); - -void _tpl_entry_set_receiver (TplEntry *self, - TplEntity *data); - -const gchar * _tpl_entry_get_chat_id (TplEntry * self); -const gchar * _tpl_entry_get_channel_path (TplEntry *self); - -TplEntryDirection _tpl_entry_get_direction (TplEntry *self); - -gboolean _tpl_entry_equal (TplEntry *self, - TplEntry *data); - -const gchar * _tpl_entry_get_log_id (TplEntry *self); - -G_END_DECLS -#endif // __TPL_ENTRY_INTERNAL_H__ diff --git a/telepathy-logger/entry-text-internal.h b/telepathy-logger/entry-text-internal.h deleted file mode 100644 index 3b68f8d..0000000 --- a/telepathy-logger/entry-text-internal.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- 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 - */ - -#ifndef __TPL_ENTRY_TEXT_INTERNAL_H__ -#define __TPL_ENTRY_TEXT_INTERNAL_H__ - -#include -#include -#include - -G_BEGIN_DECLS - -typedef enum -{ - TPL_ENTRY_TEXT_SIGNAL_NONE = 0, - TPL_ENTRY_TEXT_SIGNAL_SENT, - TPL_ENTRY_TEXT_SIGNAL_RECEIVED, - TPL_ENTRY_TEXT_SIGNAL_SEND_ERROR, - TPL_ENTRY_TEXT_SIGNAL_LOST_MESSAGE, - TPL_ENTRY_TEXT_SIGNAL_CHAT_STATUS_CHANGED, - TPL_ENTRY_SIGNAL_CHANNEL_CLOSED -} TplEntryTextSignalType; - -struct _TplEntryText -{ - TplEntry parent; - - /* Private */ - TplEntryTextPriv *priv; -}; - -struct _TplEntryTextClass -{ - TplEntryClass parent_class; -}; - -TplEntryText * _tpl_entry_text_new (const gchar* log_id, - TpAccount *account, - TplEntryDirection direction); - -TpChannelTextMessageType _tpl_entry_text_message_type_from_str ( - const gchar *type_str); - -const gchar * _tpl_entry_text_message_type_to_str ( - TpChannelTextMessageType msg_type); - -TplChannelText * _tpl_entry_text_get_tpl_channel_text ( - TplEntryText *self); - -TplEntryTextSignalType _tpl_entry_text_get_signal_type ( - TplEntryText *self); - -void _tpl_entry_text_set_tpl_channel_text (TplEntryText *self, - TplChannelText *data); - -void _tpl_entry_text_set_message (TplEntryText *self, - const gchar *data); - -void _tpl_entry_text_set_message_type (TplEntryText *self, - TpChannelTextMessageType data); - -void _tpl_entry_text_set_chatroom (TplEntryText *self, - gboolean data); - -TpChannelTextMessageType _tpl_entry_text_get_message_type ( - TplEntryText *self); - -gboolean _tpl_entry_text_is_chatroom (TplEntryText *self); - -gboolean _tpl_entry_text_equal (TplEntry *message1, - TplEntry *message2); - -void _tpl_entry_text_set_pending_msg_id (TplEntryText *self, - gint data); - -void _tpl_entry_text_set_signal_type (TplEntryText *self, - TplEntryTextSignalType signal_type); - -gboolean _tpl_entry_text_is_pending (TplEntryText *self); - -G_END_DECLS -#endif // __TPL_ENTRY_TEXT_INTERNAL_H__ diff --git a/telepathy-logger/entry-text.c b/telepathy-logger/entry-text.c deleted file mode 100644 index ae2e9fa..0000000 --- a/telepathy-logger/entry-text.c +++ /dev/null @@ -1,453 +0,0 @@ -/* -*- 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 - */ - -#include "config.h" -#include "entry-text.h" -#include "entry-text-internal.h" - -#include -#include - -#include -#include - -#define DEBUG_FLAG TPL_DEBUG_LOG_STORE -#include -#include - -/** - * SECTION:entry-text - * @title: TplEntryText - * @short_description: Representation of a text log entry - * - * A subclass of #TplEntry representing a text log entry. - */ - -/** - * TplEntryText: - * - * An object representing a text log entry. - */ - -G_DEFINE_TYPE (TplEntryText, tpl_entry_text, TPL_TYPE_ENTRY) - -struct _TplEntryTextPriv -{ - TplEntryTextSignalType signal_type; - - TplChannelText *tpl_text; - TpChannelTextMessageType message_type; - gchar *message; - gboolean chatroom; - /* in specs it's guint, TplEntry needs a way to represent ACK'd messages: - * if pending_msg_id reachs G_MAXINT32, then the problem is elsewhere :-) */ - gint pending_msg_id; -}; - -enum -{ - PROP_MESSAGE_TYPE = 1, - PROP_MESSAGE, - PROP_PENDING_MSG_ID -}; - - -static void -tpl_entry_text_dispose (GObject * obj) -{ - TplEntryText *self = TPL_ENTRY_TEXT (obj); - TplEntryTextPriv *priv = self->priv; - - if (priv->tpl_text != NULL) - { - g_object_unref (priv->tpl_text); - priv->tpl_text = NULL; - } - - G_OBJECT_CLASS (tpl_entry_text_parent_class)->dispose (obj); -} - - -static void -tpl_entry_text_finalize (GObject * obj) -{ - TplEntryText *self = TPL_ENTRY_TEXT (obj); - TplEntryTextPriv *priv = self->priv; - - g_free (priv->message); - priv->message = NULL; - - G_OBJECT_CLASS (tpl_entry_text_parent_class)->finalize (obj); -} - - -static void -tpl_entry_text_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplEntryTextPriv *priv = TPL_ENTRY_TEXT (object)->priv; - - switch (param_id) - { - case PROP_MESSAGE_TYPE: - g_value_set_uint (value, priv->message_type); - break; - case PROP_MESSAGE: - g_value_set_string (value, priv->message); - break; - case PROP_PENDING_MSG_ID: - g_value_set_int (value, priv->pending_msg_id); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -tpl_entry_text_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplEntryText *self = TPL_ENTRY_TEXT (object); - - switch (param_id) { - case PROP_MESSAGE_TYPE: - _tpl_entry_text_set_message_type (self, g_value_get_uint (value)); - break; - case PROP_MESSAGE: - _tpl_entry_text_set_message (self, g_value_get_string (value)); - break; - case PROP_PENDING_MSG_ID: - _tpl_entry_text_set_pending_msg_id (self, g_value_get_int (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void tpl_entry_text_class_init (TplEntryTextClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - TplEntryClass *entry_class = TPL_ENTRY_CLASS (klass); - GParamSpec *param_spec; - - object_class->finalize = tpl_entry_text_finalize; - object_class->dispose = tpl_entry_text_dispose; - object_class->get_property = tpl_entry_text_get_property; - object_class->set_property = tpl_entry_text_set_property; - entry_class->equal = _tpl_entry_text_equal; - - param_spec = g_param_spec_uint ("message-type", - "MessageType", - "The message type for a Text log entry", - 0, G_MAXUINT32, TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_MESSAGE_TYPE, param_spec); - - param_spec = g_param_spec_string ("message", - "Message", - "The text message of the log entry", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_MESSAGE, param_spec); - - /** - * TplEntryText::pending-msg-id: - * - * The pending message id for the current log entry. - * The default value, is #TPL_ENTRY_MSG_ID_UNKNOWN, - * meaning that it's not possible to know if the message is pending or has - * been acknowledged. - * - * An object instantiating a TplEntry subclass should explicitly set it - * to a valid msg-id number (id>=0) or to #TPL_ENTRY_MSG_ID_ACKNOWLEDGED - * when acknowledged or if the entry is a result of - * 'sent' signal. - * In fact a sent entry is considered as 'automatically' ACK by TPL. - * - * The pending message id value is only meaningful when associated to the - * #TplEntry::channel-path property. - * The couple (channel-path, pending-msg-id) cannot be considered unique, - * though, since a message-id might be reused over time. - * - * Use #TplEntry::log-id for a unique identifier within TPL. - */ - param_spec = g_param_spec_int ("pending-msg-id", - "PendingMessageId", - "Pending Message ID, if set, the log entry is set as pending for ACK." - " Default to -1 meaning not pending.", - -1, G_MAXUINT32, TPL_ENTRY_MSG_ID_ACKNOWLEDGED, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_PENDING_MSG_ID, - param_spec); - - g_type_class_add_private (object_class, sizeof (TplEntryTextPriv)); - -} - - -static void -tpl_entry_text_init (TplEntryText *self) -{ - TplEntryTextPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_ENTRY_TEXT, TplEntryTextPriv); - self->priv = priv; -} - - -TplEntryText * -_tpl_entry_text_new (const gchar *log_id, - TpAccount *account, - TplEntryDirection direction) -{ - return g_object_new (TPL_TYPE_ENTRY_TEXT, - "log-id", log_id, - "account", account, - "direction", direction, - NULL); -} - -static gchar *message_types[] = { - "normal", - "action", - "notice", - "auto-reply", - "delivery-report", - NULL }; - - -/** - * _tpl_entry_text_message_type_from_str - * @type_str: string to transform into a #TpChannelTextMessageType - * - * Maps strings into enum #TpChannelTextMessageType values. - * - * Returns: the relative value from enum #TpChannelTextMessageType if a - * mapping is found, or defaults to %TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL if not. - */ -TpChannelTextMessageType -_tpl_entry_text_message_type_from_str (const gchar *type_str) -{ - guint i; - for (i = 0; i < G_N_ELEMENTS (message_types); ++i) - if (!tp_strdiff (type_str, message_types[i])) - return (TpChannelTextMessageType) i; - - /* default case */ - return TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; -} - - -/** - * _tpl_entry_text_message_type_to_str - * @msg_type: message type to transform into a string - * - * Maps enum #TpChannelTextMessageType values into strings - * - * Returns: a string representation for @msg_type or NULL if @msg_type is not - * a legal value for %TpChannelTextMessageType. - */ -const gchar * -_tpl_entry_text_message_type_to_str (TpChannelTextMessageType msg_type) -{ - g_return_val_if_fail (G_N_ELEMENTS (message_types) >= msg_type, NULL); - - return message_types[msg_type]; -} - - -gboolean -_tpl_entry_text_is_chatroom (TplEntryText * self) -{ - g_return_val_if_fail (TPL_IS_ENTRY_TEXT (self), FALSE); - - return self->priv->chatroom; -} - - -TplChannelText * -_tpl_entry_text_get_tpl_channel_text (TplEntryText * self) -{ - g_return_val_if_fail (TPL_IS_ENTRY_TEXT (self), NULL); - - return self->priv->tpl_text; -} - - -TplEntryTextSignalType -_tpl_entry_text_get_signal_type (TplEntryText *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY_TEXT (self), TPL_ENTRY_TEXT_SIGNAL_NONE); - - return self->priv->signal_type; -} - - -void -_tpl_entry_text_set_signal_type (TplEntryText *self, - TplEntryTextSignalType signal_type) -{ - g_return_if_fail (TPL_IS_ENTRY_TEXT (self)); - - self->priv->signal_type = signal_type; -} - -/** - * tpl_entry_text_get_message - * @self: a #TplEntryText - * - * Returns: the same message as the #TplEntryText:message property - */ -const gchar * -tpl_entry_text_get_message (TplEntryText * self) -{ - g_return_val_if_fail (TPL_IS_ENTRY_TEXT (self), NULL); - - return self->priv->message; -} - -TpChannelTextMessageType -_tpl_entry_text_get_message_type (TplEntryText * self) -{ - g_return_val_if_fail (TPL_IS_ENTRY_TEXT (self), - TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL); - - return self->priv->message_type; -} - - -void -_tpl_entry_text_set_tpl_channel_text (TplEntryText * self, - TplChannelText *data) -{ - TplEntryTextPriv *priv; - - g_return_if_fail (TPL_IS_ENTRY_TEXT (self)); - g_return_if_fail (TPL_IS_CHANNEL_TEXT (data) || data == NULL); - - priv = self->priv; - if (priv->tpl_text != NULL) - g_object_unref (priv->tpl_text); - priv->tpl_text = g_object_ref (data); -} - - -void -_tpl_entry_text_set_message (TplEntryText *self, - const gchar *data) -{ - TplEntryTextPriv *priv; - - if (data == NULL) - return; - - g_return_if_fail (TPL_IS_ENTRY_TEXT (self)); - - priv = self->priv; - - g_free (priv->message); - priv->message = g_strdup (data); -} - - -void -_tpl_entry_text_set_message_type (TplEntryText *self, - TpChannelTextMessageType data) -{ - g_return_if_fail (TPL_IS_ENTRY_TEXT (self)); - - self->priv->message_type = data; -} - - -void -_tpl_entry_text_set_chatroom (TplEntryText *self, - gboolean data) -{ - g_return_if_fail (TPL_IS_ENTRY_TEXT (self)); - - self->priv->chatroom = data; -} - -gboolean -_tpl_entry_text_equal (TplEntry *message1, - TplEntry *message2) -{ - g_return_val_if_fail (TPL_IS_ENTRY_TEXT (message1), FALSE); - g_return_val_if_fail (TPL_IS_ENTRY_TEXT (message2), FALSE); - - /* - if (priv1->id == priv2->id && !tp_strdiff (priv1->body, priv2->body)) { - if (priv1->type == priv2->type) - if (!tp_strdiff (priv1->entry.text->message, priv2->entry.text->message)) { - } - */ - return !tp_strdiff (_tpl_entry_get_log_id (message1), - _tpl_entry_get_log_id (message2)); -} - -/** - * _tpl_entry_set_pending_msg_id: - * @self: TplEntryText instance - * @data: the pending message ID - * - * Sets @self to be associated to pending message id @data. - * - * @see_also: #TplEntry::pending-msg-id for special values. - */ -void -_tpl_entry_text_set_pending_msg_id (TplEntryText *self, - gint data) -{ - g_return_if_fail (TPL_IS_ENTRY (self)); - - self->priv->pending_msg_id = data; - g_object_notify (G_OBJECT (self), "pending-msg-id"); -} - -/** - * tpl_entry_text_get_pending_msg_id - * @self: a #TplEntryText - * - * Returns: the id as the #TplEntryText:pending-msg-id property - */ -gint -tpl_entry_text_get_pending_msg_id (TplEntryText *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), -1); - - return self->priv->pending_msg_id; -} - - -gboolean -_tpl_entry_text_is_pending (TplEntryText *self) -{ - return TPL_ENTRY_MSG_ID_IS_VALID ( - tpl_entry_text_get_pending_msg_id (self)); -} diff --git a/telepathy-logger/entry-text.h b/telepathy-logger/entry-text.h deleted file mode 100644 index bb6c5c7..0000000 --- a/telepathy-logger/entry-text.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- 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 - */ - -#ifndef __TPL_ENTRY_TEXT_H__ -#define __TPL_ENTRY_TEXT_H__ - -#include - -#include - -G_BEGIN_DECLS -#define TPL_TYPE_ENTRY_TEXT (tpl_entry_text_get_type ()) -#define TPL_ENTRY_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_ENTRY_TEXT, TplEntryText)) -#define TPL_ENTRY_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_ENTRY_TEXT, TplEntryTextClass)) -#define TPL_IS_ENTRY_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_ENTRY_TEXT)) -#define TPL_IS_ENTRY_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_ENTRY_TEXT)) -#define TPL_ENTRY_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_ENTRY_TEXT, TplEntryTextClass)) - -typedef struct _TplEntryText TplEntryText; -typedef struct _TplEntryTextClass TplEntryTextClass; -typedef struct _TplEntryTextPriv TplEntryTextPriv; - -GType tpl_entry_text_get_type (void); - -const gchar *tpl_entry_text_get_message (TplEntryText *self); - -gint tpl_entry_text_get_pending_msg_id (TplEntryText *self); - -G_END_DECLS -#endif // __TPL_ENTRY_TEXT_H__ diff --git a/telepathy-logger/entry.c b/telepathy-logger/entry.c deleted file mode 100644 index f9dd091..0000000 --- a/telepathy-logger/entry.c +++ /dev/null @@ -1,556 +0,0 @@ -/* - * 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 - */ - -#include "config.h" -#include "entry.h" -#include "entry-internal.h" - -#include - -#define DEBUG_FLAG TPL_DEBUG_ENTRY -#include -#include - -/** - * SECTION:entry - * @title: TplEntry - * @short_description: Abstract representation of a log entry - * @see_also: #TplEntryText and other subclasses when they'll exist - * - * The TPLogger log entry represents a generic log entry, which will be - * specialized by subclasses of #TplEntry. - */ - -/** - * TplEntry: - * - * An object representing a generic log entry. - */ - -/** - * TPL_ENTRY_MSG_ID_IS_VALID: - * @msg: a message ID - * - * Return whether a message ID is valid. - * - * If %FALSE is returned, it means that either an invalid input has been - * passed, or the TplEntry is currently set to %TPL_ENTRY_MSG_ID_UNKNOWN - * or %TPL_ENTRY_MSG_ID_ACKNOWLEDGED. - * - * Returns: %TRUE if the argument is a valid message ID or %FALSE otherwise. - */ - -/** - * TPL_ENTRY_MSG_ID_UNKNOWN: - * - * Special value used instead of a message ID to indicate a message with an - * unknown status (before _tpl_entry_set_pending_msg_id() was called, or - * when it wasn't possible to obtain the message ID). - */ - -/** - * TPL_ENTRY_MSG_ID_ACKNOWLEDGED: - * - * Special value used instead of a message ID to indicate an acknowledged - * message. - */ - -G_DEFINE_ABSTRACT_TYPE (TplEntry, tpl_entry, G_TYPE_OBJECT) - -static void tpl_entry_set_log_id (TplEntry *self, const gchar *data); - -struct _TplEntryPriv -{ - gchar *log_id; - gint64 timestamp; - gchar *chat_id; - TpAccount *account; - gchar *channel_path; - - /* incoming/outgoing */ - TplEntryDirection direction; - - /* message and receiver may be NULL depending on the signal. ie. status - * changed signals set only the sender */ - TplEntity *sender; - TplEntity *receiver; -}; - -enum { - PROP_TIMESTAMP = 1, - PROP_LOG_ID, - PROP_DIRECTION, - PROP_CHAT_ID, - PROP_ACCOUNT, - PROP_ACCOUNT_PATH, - PROP_CHANNEL_PATH, - PROP_SENDER, - PROP_RECEIVER -}; - - -static void -tpl_entry_finalize (GObject *obj) -{ - TplEntry *self = TPL_ENTRY (obj); - TplEntryPriv *priv = self->priv; - - tp_clear_pointer (&priv->log_id, g_free); - tp_clear_pointer (&priv->chat_id, g_free); - tp_clear_pointer (&priv->channel_path, g_free); - - G_OBJECT_CLASS (tpl_entry_parent_class)->finalize (obj); -} - - -static void -tpl_entry_dispose (GObject *obj) -{ - TplEntry *self = TPL_ENTRY (obj); - TplEntryPriv *priv = self->priv; - - tp_clear_object (&priv->account); - tp_clear_object (&priv->sender); - tp_clear_object (&priv->receiver); - - G_OBJECT_CLASS (tpl_entry_parent_class)->dispose (obj); -} - - -static void -tpl_entry_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplEntry *self = TPL_ENTRY (object); - TplEntryPriv *priv = self->priv; - - switch (param_id) - { - case PROP_TIMESTAMP: - g_value_set_uint (value, priv->timestamp); - break; - case PROP_LOG_ID: - g_value_set_string (value, priv->log_id); - break; - case PROP_DIRECTION: - g_value_set_uint (value, priv->direction); - break; - case PROP_CHAT_ID: - g_value_set_string (value, priv->chat_id); - break; - case PROP_ACCOUNT: - g_value_set_object (value, priv->account); - break; - case PROP_ACCOUNT_PATH: - g_value_set_string (value, tpl_entry_get_account_path (self)); - break; - case PROP_CHANNEL_PATH: - g_value_set_string (value, priv->channel_path); - break; - case PROP_SENDER: - g_value_set_object (value, priv->sender); - break; - case PROP_RECEIVER: - g_value_set_object (value, priv->receiver); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - - -static void -tpl_entry_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplEntry *self = TPL_ENTRY (object); - - switch (param_id) { - case PROP_TIMESTAMP: - _tpl_entry_set_timestamp (self, g_value_get_uint (value)); - break; - case PROP_LOG_ID: - tpl_entry_set_log_id (self, g_value_get_string (value)); - break; - case PROP_DIRECTION: - _tpl_entry_set_direction (self, g_value_get_uint (value)); - break; - case PROP_CHAT_ID: - _tpl_entry_set_chat_id (self, g_value_get_string (value)); - break; - case PROP_ACCOUNT: - self->priv->account = g_value_dup_object (value); - break; - case PROP_CHANNEL_PATH: - _tpl_entry_set_channel_path (self, g_value_get_string (value)); - break; - case PROP_SENDER: - _tpl_entry_set_sender (self, g_value_get_object (value)); - break; - case PROP_RECEIVER: - _tpl_entry_set_receiver (self, g_value_get_object (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - - -static void -tpl_entry_class_init (TplEntryClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; - - /* to be used by subclasses */ - object_class->finalize = tpl_entry_finalize; - object_class->dispose = tpl_entry_dispose; - object_class->get_property = tpl_entry_get_property; - object_class->set_property = tpl_entry_set_property; - - klass->equal = NULL; - - param_spec = g_param_spec_uint ("timestamp", - "Timestamp", - "The timestamp (gint64) for the log entry", - 0, G_MAXUINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TIMESTAMP, param_spec); - - /** - * TplEntry::log-id: - * - * A token identifying the entry. - * - */ - param_spec = g_param_spec_string ("log-id", - "LogId", - "Log identification token, it's unique among existing Entry, if two " - "messages have the same token, they are the same entry (maybe logged " - "by two different TplLogStore)", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_LOG_ID, param_spec); - - param_spec = g_param_spec_uint ("direction", - "Direction", - "The direction of the log entry (in/out)", - 0, G_MAXUINT32, TPL_ENTRY_DIRECTION_NONE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DIRECTION, param_spec); - - param_spec = g_param_spec_string ("chat-id", - "ChatId", - "The chat identifier to which the log entry is related.", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CHAT_ID, param_spec); - - param_spec = g_param_spec_object ("account", - "TpAccount", - "The TpAccount to which the log entry is related", - TP_TYPE_ACCOUNT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec); - - param_spec = g_param_spec_string ("account-path", - "AccountPath", - "The account path of the TpAccount to which the log entry is related", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ACCOUNT_PATH, param_spec); - - param_spec = g_param_spec_string ("channel-path", - "ChannelPath", - "The channel path of the TpChannel to which the log entry is related", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CHANNEL_PATH, param_spec); - - param_spec = g_param_spec_object ("sender", - "Sender", - "TplEntity instance who originated the log entry", - TPL_TYPE_ENTITY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_SENDER, param_spec); - - param_spec = g_param_spec_object ("receiver", - "Receiver", - "TplEntity instance destination for the log entry", - TPL_TYPE_ENTITY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_RECEIVER, param_spec); - - g_type_class_add_private (object_class, sizeof (TplEntryPriv)); - } - - -static void -tpl_entry_init (TplEntry *self) -{ - TplEntryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_ENTRY, TplEntryPriv); - self->priv = priv; -} - -/** - * tpl_entry_get_timestamp - * @self: a #TplEntry - * - * Returns: the same timestamp as the #TplEntry:timestamp property - */ -gint64 -tpl_entry_get_timestamp (TplEntry *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), -1); - - return self->priv->timestamp; -} - -const gchar * -_tpl_entry_get_log_id (TplEntry *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), 0); - - return self->priv->log_id; -} - - -TplEntryDirection -_tpl_entry_get_direction (TplEntry *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), - TPL_ENTRY_DIRECTION_NONE); - - return self->priv->direction; -} - -/** - * tpl_entry_get_sender - * @self: a #TplEntry - * - * Returns: the same #TplEntity as the #TplEntry:sender property - */ -TplEntity * -tpl_entry_get_sender (TplEntry *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), NULL); - - return self->priv->sender; -} - -/** - * tpl_entry_get_receiver - * @self: a #TplEntry - * - * Returns: the same #TplEntity as the #TplEntry:receiver property - */ -TplEntity * -tpl_entry_get_receiver (TplEntry *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), NULL); - - return self->priv->receiver; -} - - -const gchar * -_tpl_entry_get_chat_id (TplEntry *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), NULL); - - return self->priv->chat_id; -} - - -/** - * tpl_entry_get_account - * @self: a #TplEntry - * - * - * - * Returns: the path as the #TplEntry:account property - */ -const gchar * -tpl_entry_get_account_path (TplEntry *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), NULL); - - return tp_proxy_get_object_path (self->priv->account); -} - - -const gchar * -_tpl_entry_get_channel_path (TplEntry *self) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), NULL); - - return self->priv->channel_path; -} - - -void -_tpl_entry_set_timestamp (TplEntry *self, - gint64 data) -{ - g_return_if_fail (TPL_IS_ENTRY (self)); - - self->priv->timestamp = data; - g_object_notify (G_OBJECT (self), "timestamp"); -} - - -/* set just on construction time */ -static void -tpl_entry_set_log_id (TplEntry *self, - const gchar* data) -{ - g_return_if_fail (TPL_IS_ENTRY (self)); - g_return_if_fail (!TPL_STR_EMPTY (data)); - g_return_if_fail (self->priv->log_id == NULL); - - self->priv->log_id = g_strdup (data); - g_object_notify (G_OBJECT (self), "log-id"); -} - - -void -_tpl_entry_set_direction (TplEntry *self, - TplEntryDirection data) -{ - g_return_if_fail (TPL_IS_ENTRY (self)); - - self->priv->direction = data; - g_object_notify (G_OBJECT (self), "direction"); -} - - -void -_tpl_entry_set_sender (TplEntry *self, - TplEntity *data) -{ - TplEntryPriv *priv; - - if (data == NULL) - return; - - g_return_if_fail (TPL_IS_ENTRY (self)); - g_return_if_fail (TPL_IS_ENTITY (data)); - - priv = self->priv; - - if (priv->sender != NULL) - g_object_unref (priv->sender); - priv->sender = g_object_ref (data); - g_object_notify (G_OBJECT (self), "sender"); -} - - -void -_tpl_entry_set_receiver (TplEntry *self, - TplEntity *data) -{ - TplEntryPriv *priv; - - if (data == NULL) - return; - - g_return_if_fail (TPL_IS_ENTRY (self)); - g_return_if_fail (TPL_IS_ENTITY (data)); - - priv = self->priv; - - if (priv->receiver != NULL) - g_object_unref (priv->receiver); - - priv->receiver = g_object_ref (data); - - g_object_notify (G_OBJECT (self), "receiver"); -} - - -void -_tpl_entry_set_chat_id (TplEntry *self, - const gchar *data) -{ - if (data == NULL) - return; - - g_return_if_fail (TPL_IS_ENTRY (self)); - g_return_if_fail (!TPL_STR_EMPTY (data)); - g_return_if_fail (self->priv->chat_id == NULL); - - self->priv->chat_id = g_strdup (data); - g_object_notify (G_OBJECT (self), "chat-id"); -} - -void -_tpl_entry_set_channel_path (TplEntry *self, - const gchar *data) -{ - if (data == NULL) - return; - - g_return_if_fail (TPL_IS_ENTRY (self)); - g_return_if_fail (!TPL_STR_EMPTY (data)); - g_return_if_fail (self->priv->channel_path == NULL); - - self->priv->channel_path = g_strdup (data); - g_object_notify (G_OBJECT (self), "channel-path"); -} - -/** - * _tpl_entry_equal: - * @self: TplEntry subclass instance - * @data: an instance of the same TplEntry subclass of @self - * - * Checks if two instances of TplEntry represent the same data - * - * Returns: %TRUE if @data is the same type of @self and they hold the same - * data, %FALSE otherwise - */ -gboolean -_tpl_entry_equal (TplEntry *self, - TplEntry *data) -{ - g_return_val_if_fail (TPL_IS_ENTRY (self), FALSE); - g_return_val_if_fail (TPL_IS_ENTRY (data), FALSE); - - return TPL_ENTRY_GET_CLASS (self)->equal (self, data); -} - -/** - * tpl_entry_get_account - * @self: a #TplEntry - * - * - * - * Returns: the same account as the #TplEntry:account property - */ -TpAccount * -tpl_entry_get_account (TplEntry *self) -{ - return self->priv->account; -} diff --git a/telepathy-logger/entry.h b/telepathy-logger/entry.h deleted file mode 100644 index ed35330..0000000 --- a/telepathy-logger/entry.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- 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 - */ - -#ifndef __TPL_ENTRY_H__ -#define __TPL_ENTRY_H__ - -#include - -#include - -#include - -G_BEGIN_DECLS -#define TPL_TYPE_ENTRY (tpl_entry_get_type ()) -#define TPL_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_ENTRY, TplEntry)) -#define TPL_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_ENTRY, TplEntryClass)) -#define TPL_IS_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_ENTRY)) -#define TPL_IS_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_ENTRY)) -#define TPL_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_ENTRY, TplEntryClass)) - -typedef struct _TplEntry TplEntry; -typedef struct _TplEntryClass TplEntryClass; -typedef struct _TplEntryPriv TplEntryPriv; - -GType tpl_entry_get_type (void); - -typedef enum -{ - TPL_ENTRY_DIRECTION_NONE = 0, - - TPL_ENTRY_DIRECTION_IN, - TPL_ENTRY_DIRECTION_OUT -} TplEntryDirection; - -gint64 tpl_entry_get_timestamp (TplEntry *self); - -const gchar *tpl_entry_get_account_path (TplEntry *self); -TpAccount * tpl_entry_get_account (TplEntry *self); - -TplEntity * tpl_entry_get_sender (TplEntry *self); -TplEntity * tpl_entry_get_receiver (TplEntry *self); - -G_END_DECLS -#endif // __TPL_ENTRY_H__ diff --git a/telepathy-logger/event-internal.h b/telepathy-logger/event-internal.h new file mode 100644 index 0000000..26b0d9d --- /dev/null +++ b/telepathy-logger/event-internal.h @@ -0,0 +1,86 @@ +/* -*- 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 + */ + +#ifndef __TPL_EVENT_INTERNAL_H__ +#define __TPL_EVENT_INTERNAL_H__ + +#include + +G_BEGIN_DECLS + +#define TPL_EVENT_MSG_ID_IS_VALID(msg) (msg >= 0) + +#define TPL_EVENT_MSG_ID_UNKNOWN -2 +#define TPL_EVENT_MSG_ID_ACKNOWLEDGED -1 + +typedef enum +{ + TPL_EVENT_ERROR, + TPL_EVENT_TEXT +} TplEventType; + + +struct _TplEvent +{ + GObject parent; + + /* Private */ + TplEventPriv *priv; +}; + +struct _TplEventClass { + GObjectClass parent_class; + + /* to be implemented only by subclasses */ + gboolean (*equal) (TplEvent *event1, TplEvent *event2); +}; + + +void _tpl_event_set_timestamp (TplEvent *self, + gint64 data); + +void _tpl_event_set_direction (TplEvent *self, + TplEventDirection data); + +void _tpl_event_set_chat_id (TplEvent *self, + const gchar *data); + +void _tpl_event_set_channel_path (TplEvent *self, + const gchar *data); + +void _tpl_event_set_sender (TplEvent *self, + TplEntity *data); + +void _tpl_event_set_receiver (TplEvent *self, + TplEntity *data); + +const gchar * _tpl_event_get_chat_id (TplEvent * self); +const gchar * _tpl_event_get_channel_path (TplEvent *self); + +TplEventDirection _tpl_event_get_direction (TplEvent *self); + +gboolean _tpl_event_equal (TplEvent *self, + TplEvent *data); + +const gchar * _tpl_event_get_log_id (TplEvent *self); + +G_END_DECLS +#endif // __TPL_EVENT_INTERNAL_H__ diff --git a/telepathy-logger/event-text-internal.h b/telepathy-logger/event-text-internal.h new file mode 100644 index 0000000..39750f0 --- /dev/null +++ b/telepathy-logger/event-text-internal.h @@ -0,0 +1,100 @@ +/* -*- 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 + */ + +#ifndef __TPL_EVENT_TEXT_INTERNAL_H__ +#define __TPL_EVENT_TEXT_INTERNAL_H__ + +#include +#include +#include + +G_BEGIN_DECLS + +typedef enum +{ + TPL_EVENT_TEXT_SIGNAL_NONE = 0, + TPL_EVENT_TEXT_SIGNAL_SENT, + TPL_EVENT_TEXT_SIGNAL_RECEIVED, + TPL_EVENT_TEXT_SIGNAL_SEND_ERROR, + TPL_EVENT_TEXT_SIGNAL_LOST_MESSAGE, + TPL_EVENT_TEXT_SIGNAL_CHAT_STATUS_CHANGED, + TPL_EVENT_SIGNAL_CHANNEL_CLOSED +} TplEventTextSignalType; + +struct _TplEventText +{ + TplEvent parent; + + /* Private */ + TplEventTextPriv *priv; +}; + +struct _TplEventTextClass +{ + TplEventClass parent_class; +}; + +TplEventText * _tpl_event_text_new (const gchar* log_id, + TpAccount *account, + TplEventDirection direction); + +TpChannelTextMessageType _tpl_event_text_message_type_from_str ( + const gchar *type_str); + +const gchar * _tpl_event_text_message_type_to_str ( + TpChannelTextMessageType msg_type); + +TplChannelText * _tpl_event_text_get_tpl_channel_text ( + TplEventText *self); + +TplEventTextSignalType _tpl_event_text_get_signal_type ( + TplEventText *self); + +void _tpl_event_text_set_tpl_channel_text (TplEventText *self, + TplChannelText *data); + +void _tpl_event_text_set_message (TplEventText *self, + const gchar *data); + +void _tpl_event_text_set_message_type (TplEventText *self, + TpChannelTextMessageType data); + +void _tpl_event_text_set_chatroom (TplEventText *self, + gboolean data); + +TpChannelTextMessageType _tpl_event_text_get_message_type ( + TplEventText *self); + +gboolean _tpl_event_text_is_chatroom (TplEventText *self); + +gboolean _tpl_event_text_equal (TplEvent *message1, + TplEvent *message2); + +void _tpl_event_text_set_pending_msg_id (TplEventText *self, + gint data); + +void _tpl_event_text_set_signal_type (TplEventText *self, + TplEventTextSignalType signal_type); + +gboolean _tpl_event_text_is_pending (TplEventText *self); + +G_END_DECLS +#endif // __TPL_EVENT_TEXT_INTERNAL_H__ diff --git a/telepathy-logger/event-text.c b/telepathy-logger/event-text.c new file mode 100644 index 0000000..995a4fc --- /dev/null +++ b/telepathy-logger/event-text.c @@ -0,0 +1,453 @@ +/* -*- 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 + */ + +#include "config.h" +#include "event-text.h" +#include "event-text-internal.h" + +#include +#include + +#include +#include + +#define DEBUG_FLAG TPL_DEBUG_LOG_STORE +#include +#include + +/** + * SECTION:event-text + * @title: TplEventText + * @short_description: Representation of a text log event + * + * A subclass of #TplEvent representing a text log event. + */ + +/** + * TplEventText: + * + * An object representing a text log event. + */ + +G_DEFINE_TYPE (TplEventText, tpl_event_text, TPL_TYPE_EVENT) + +struct _TplEventTextPriv +{ + TplEventTextSignalType signal_type; + + TplChannelText *tpl_text; + TpChannelTextMessageType message_type; + gchar *message; + gboolean chatroom; + /* in specs it's guint, TplEvent needs a way to represent ACK'd messages: + * if pending_msg_id reachs G_MAXINT32, then the problem is elsewhere :-) */ + gint pending_msg_id; +}; + +enum +{ + PROP_MESSAGE_TYPE = 1, + PROP_MESSAGE, + PROP_PENDING_MSG_ID +}; + + +static void +tpl_event_text_dispose (GObject * obj) +{ + TplEventText *self = TPL_EVENT_TEXT (obj); + TplEventTextPriv *priv = self->priv; + + if (priv->tpl_text != NULL) + { + g_object_unref (priv->tpl_text); + priv->tpl_text = NULL; + } + + G_OBJECT_CLASS (tpl_event_text_parent_class)->dispose (obj); +} + + +static void +tpl_event_text_finalize (GObject * obj) +{ + TplEventText *self = TPL_EVENT_TEXT (obj); + TplEventTextPriv *priv = self->priv; + + g_free (priv->message); + priv->message = NULL; + + G_OBJECT_CLASS (tpl_event_text_parent_class)->finalize (obj); +} + + +static void +tpl_event_text_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + TplEventTextPriv *priv = TPL_EVENT_TEXT (object)->priv; + + switch (param_id) + { + case PROP_MESSAGE_TYPE: + g_value_set_uint (value, priv->message_type); + break; + case PROP_MESSAGE: + g_value_set_string (value, priv->message); + break; + case PROP_PENDING_MSG_ID: + g_value_set_int (value, priv->pending_msg_id); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + + +static void +tpl_event_text_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + TplEventText *self = TPL_EVENT_TEXT (object); + + switch (param_id) { + case PROP_MESSAGE_TYPE: + _tpl_event_text_set_message_type (self, g_value_get_uint (value)); + break; + case PROP_MESSAGE: + _tpl_event_text_set_message (self, g_value_get_string (value)); + break; + case PROP_PENDING_MSG_ID: + _tpl_event_text_set_pending_msg_id (self, g_value_get_int (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + + +static void tpl_event_text_class_init (TplEventTextClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + TplEventClass *event_class = TPL_EVENT_CLASS (klass); + GParamSpec *param_spec; + + object_class->finalize = tpl_event_text_finalize; + object_class->dispose = tpl_event_text_dispose; + object_class->get_property = tpl_event_text_get_property; + object_class->set_property = tpl_event_text_set_property; + event_class->equal = _tpl_event_text_equal; + + param_spec = g_param_spec_uint ("message-type", + "MessageType", + "The message type for a Text log event", + 0, G_MAXUINT32, TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_MESSAGE_TYPE, param_spec); + + param_spec = g_param_spec_string ("message", + "Message", + "The text message of the log event", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_MESSAGE, param_spec); + + /** + * TplEventText::pending-msg-id: + * + * The pending message id for the current log event. + * The default value, is #TPL_EVENT_MSG_ID_UNKNOWN, + * meaning that it's not possible to know if the message is pending or has + * been acknowledged. + * + * An object instantiating a TplEvent subclass should explicitly set it + * to a valid msg-id number (id>=0) or to #TPL_EVENT_MSG_ID_ACKNOWLEDGED + * when acknowledged or if the event is a result of + * 'sent' signal. + * In fact a sent event is considered as 'automatically' ACK by TPL. + * + * The pending message id value is only meaningful when associated to the + * #TplEvent::channel-path property. + * The couple (channel-path, pending-msg-id) cannot be considered unique, + * though, since a message-id might be reused over time. + * + * Use #TplEvent::log-id for a unique identifier within TPL. + */ + param_spec = g_param_spec_int ("pending-msg-id", + "PendingMessageId", + "Pending Message ID, if set, the log event is set as pending for ACK." + " Default to -1 meaning not pending.", + -1, G_MAXUINT32, TPL_EVENT_MSG_ID_ACKNOWLEDGED, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_PENDING_MSG_ID, + param_spec); + + g_type_class_add_private (object_class, sizeof (TplEventTextPriv)); + +} + + +static void +tpl_event_text_init (TplEventText *self) +{ + TplEventTextPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + TPL_TYPE_EVENT_TEXT, TplEventTextPriv); + self->priv = priv; +} + + +TplEventText * +_tpl_event_text_new (const gchar *log_id, + TpAccount *account, + TplEventDirection direction) +{ + return g_object_new (TPL_TYPE_EVENT_TEXT, + "log-id", log_id, + "account", account, + "direction", direction, + NULL); +} + +static gchar *message_types[] = { + "normal", + "action", + "notice", + "auto-reply", + "delivery-report", + NULL }; + + +/** + * _tpl_event_text_message_type_from_str + * @type_str: string to transform into a #TpChannelTextMessageType + * + * Maps strings into enum #TpChannelTextMessageType values. + * + * Returns: the relative value from enum #TpChannelTextMessageType if a + * mapping is found, or defaults to %TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL if not. + */ +TpChannelTextMessageType +_tpl_event_text_message_type_from_str (const gchar *type_str) +{ + guint i; + for (i = 0; i < G_N_ELEMENTS (message_types); ++i) + if (!tp_strdiff (type_str, message_types[i])) + return (TpChannelTextMessageType) i; + + /* default case */ + return TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; +} + + +/** + * _tpl_event_text_message_type_to_str + * @msg_type: message type to transform into a string + * + * Maps enum #TpChannelTextMessageType values into strings + * + * Returns: a string representation for @msg_type or NULL if @msg_type is not + * a legal value for %TpChannelTextMessageType. + */ +const gchar * +_tpl_event_text_message_type_to_str (TpChannelTextMessageType msg_type) +{ + g_return_val_if_fail (G_N_ELEMENTS (message_types) >= msg_type, NULL); + + return message_types[msg_type]; +} + + +gboolean +_tpl_event_text_is_chatroom (TplEventText * self) +{ + g_return_val_if_fail (TPL_IS_EVENT_TEXT (self), FALSE); + + return self->priv->chatroom; +} + + +TplChannelText * +_tpl_event_text_get_tpl_channel_text (TplEventText * self) +{ + g_return_val_if_fail (TPL_IS_EVENT_TEXT (self), NULL); + + return self->priv->tpl_text; +} + + +TplEventTextSignalType +_tpl_event_text_get_signal_type (TplEventText *self) +{ + g_return_val_if_fail (TPL_IS_EVENT_TEXT (self), TPL_EVENT_TEXT_SIGNAL_NONE); + + return self->priv->signal_type; +} + + +void +_tpl_event_text_set_signal_type (TplEventText *self, + TplEventTextSignalType signal_type) +{ + g_return_if_fail (TPL_IS_EVENT_TEXT (self)); + + self->priv->signal_type = signal_type; +} + +/** + * tpl_event_text_get_message + * @self: a #TplEventText + * + * Returns: the same message as the #TplEventText:message property + */ +const gchar * +tpl_event_text_get_message (TplEventText * self) +{ + g_return_val_if_fail (TPL_IS_EVENT_TEXT (self), NULL); + + return self->priv->message; +} + +TpChannelTextMessageType +_tpl_event_text_get_message_type (TplEventText * self) +{ + g_return_val_if_fail (TPL_IS_EVENT_TEXT (self), + TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL); + + return self->priv->message_type; +} + + +void +_tpl_event_text_set_tpl_channel_text (TplEventText * self, + TplChannelText *data) +{ + TplEventTextPriv *priv; + + g_return_if_fail (TPL_IS_EVENT_TEXT (self)); + g_return_if_fail (TPL_IS_CHANNEL_TEXT (data) || data == NULL); + + priv = self->priv; + if (priv->tpl_text != NULL) + g_object_unref (priv->tpl_text); + priv->tpl_text = g_object_ref (data); +} + + +void +_tpl_event_text_set_message (TplEventText *self, + const gchar *data) +{ + TplEventTextPriv *priv; + + if (data == NULL) + return; + + g_return_if_fail (TPL_IS_EVENT_TEXT (self)); + + priv = self->priv; + + g_free (priv->message); + priv->message = g_strdup (data); +} + + +void +_tpl_event_text_set_message_type (TplEventText *self, + TpChannelTextMessageType data) +{ + g_return_if_fail (TPL_IS_EVENT_TEXT (self)); + + self->priv->message_type = data; +} + + +void +_tpl_event_text_set_chatroom (TplEventText *self, + gboolean data) +{ + g_return_if_fail (TPL_IS_EVENT_TEXT (self)); + + self->priv->chatroom = data; +} + +gboolean +_tpl_event_text_equal (TplEvent *message1, + TplEvent *message2) +{ + g_return_val_if_fail (TPL_IS_EVENT_TEXT (message1), FALSE); + g_return_val_if_fail (TPL_IS_EVENT_TEXT (message2), FALSE); + + /* + if (priv1->id == priv2->id && !tp_strdiff (priv1->body, priv2->body)) { + if (priv1->type == priv2->type) + if (!tp_strdiff (priv1->event.text->message, priv2->event.text->message)) { + } + */ + return !tp_strdiff (_tpl_event_get_log_id (message1), + _tpl_event_get_log_id (message2)); +} + +/** + * _tpl_event_set_pending_msg_id: + * @self: TplEventText instance + * @data: the pending message ID + * + * Sets @self to be associated to pending message id @data. + * + * @see_also: #TplEvent::pending-msg-id for special values. + */ +void +_tpl_event_text_set_pending_msg_id (TplEventText *self, + gint data) +{ + g_return_if_fail (TPL_IS_EVENT (self)); + + self->priv->pending_msg_id = data; + g_object_notify (G_OBJECT (self), "pending-msg-id"); +} + +/** + * tpl_event_text_get_pending_msg_id + * @self: a #TplEventText + * + * Returns: the id as the #TplEventText:pending-msg-id property + */ +gint +tpl_event_text_get_pending_msg_id (TplEventText *self) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), -1); + + return self->priv->pending_msg_id; +} + + +gboolean +_tpl_event_text_is_pending (TplEventText *self) +{ + return TPL_EVENT_MSG_ID_IS_VALID ( + tpl_event_text_get_pending_msg_id (self)); +} diff --git a/telepathy-logger/event-text.h b/telepathy-logger/event-text.h new file mode 100644 index 0000000..da43a78 --- /dev/null +++ b/telepathy-logger/event-text.h @@ -0,0 +1,48 @@ +/* -*- 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 + */ + +#ifndef __TPL_EVENT_TEXT_H__ +#define __TPL_EVENT_TEXT_H__ + +#include + +#include + +G_BEGIN_DECLS +#define TPL_TYPE_EVENT_TEXT (tpl_event_text_get_type ()) +#define TPL_EVENT_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_EVENT_TEXT, TplEventText)) +#define TPL_EVENT_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_EVENT_TEXT, TplEventTextClass)) +#define TPL_IS_EVENT_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_EVENT_TEXT)) +#define TPL_IS_EVENT_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_EVENT_TEXT)) +#define TPL_EVENT_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_EVENT_TEXT, TplEventTextClass)) + +typedef struct _TplEventText TplEventText; +typedef struct _TplEventTextClass TplEventTextClass; +typedef struct _TplEventTextPriv TplEventTextPriv; + +GType tpl_event_text_get_type (void); + +const gchar *tpl_event_text_get_message (TplEventText *self); + +gint tpl_event_text_get_pending_msg_id (TplEventText *self); + +G_END_DECLS +#endif // __TPL_EVENT_TEXT_H__ diff --git a/telepathy-logger/event.c b/telepathy-logger/event.c new file mode 100644 index 0000000..7da3bf1 --- /dev/null +++ b/telepathy-logger/event.c @@ -0,0 +1,556 @@ +/* + * 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 + */ + +#include "config.h" +#include "event.h" +#include "event-internal.h" + +#include + +#define DEBUG_FLAG TPL_DEBUG_EVENT +#include +#include + +/** + * SECTION:event + * @title: TplEvent + * @short_description: Abstract representation of a log event + * @see_also: #TplEventText and other subclasses when they'll exist + * + * The TPLogger log event represents a generic log event, which will be + * specialized by subclasses of #TplEvent. + */ + +/** + * TplEvent: + * + * An object representing a generic log event. + */ + +/** + * TPL_EVENT_MSG_ID_IS_VALID: + * @msg: a message ID + * + * Return whether a message ID is valid. + * + * If %FALSE is returned, it means that either an invalid input has been + * passed, or the TplEvent is currently set to %TPL_EVENT_MSG_ID_UNKNOWN + * or %TPL_EVENT_MSG_ID_ACKNOWLEDGED. + * + * Returns: %TRUE if the argument is a valid message ID or %FALSE otherwise. + */ + +/** + * TPL_EVENT_MSG_ID_UNKNOWN: + * + * Special value used instead of a message ID to indicate a message with an + * unknown status (before _tpl_event_set_pending_msg_id() was called, or + * when it wasn't possible to obtain the message ID). + */ + +/** + * TPL_EVENT_MSG_ID_ACKNOWLEDGED: + * + * Special value used instead of a message ID to indicate an acknowledged + * message. + */ + +G_DEFINE_ABSTRACT_TYPE (TplEvent, tpl_event, G_TYPE_OBJECT) + +static void tpl_event_set_log_id (TplEvent *self, const gchar *data); + +struct _TplEventPriv +{ + gchar *log_id; + gint64 timestamp; + gchar *chat_id; + TpAccount *account; + gchar *channel_path; + + /* incoming/outgoing */ + TplEventDirection direction; + + /* message and receiver may be NULL depending on the signal. ie. status + * changed signals set only the sender */ + TplEntity *sender; + TplEntity *receiver; +}; + +enum { + PROP_TIMESTAMP = 1, + PROP_LOG_ID, + PROP_DIRECTION, + PROP_CHAT_ID, + PROP_ACCOUNT, + PROP_ACCOUNT_PATH, + PROP_CHANNEL_PATH, + PROP_SENDER, + PROP_RECEIVER +}; + + +static void +tpl_event_finalize (GObject *obj) +{ + TplEvent *self = TPL_EVENT (obj); + TplEventPriv *priv = self->priv; + + tp_clear_pointer (&priv->log_id, g_free); + tp_clear_pointer (&priv->chat_id, g_free); + tp_clear_pointer (&priv->channel_path, g_free); + + G_OBJECT_CLASS (tpl_event_parent_class)->finalize (obj); +} + + +static void +tpl_event_dispose (GObject *obj) +{ + TplEvent *self = TPL_EVENT (obj); + TplEventPriv *priv = self->priv; + + tp_clear_object (&priv->account); + tp_clear_object (&priv->sender); + tp_clear_object (&priv->receiver); + + G_OBJECT_CLASS (tpl_event_parent_class)->dispose (obj); +} + + +static void +tpl_event_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + TplEvent *self = TPL_EVENT (object); + TplEventPriv *priv = self->priv; + + switch (param_id) + { + case PROP_TIMESTAMP: + g_value_set_uint (value, priv->timestamp); + break; + case PROP_LOG_ID: + g_value_set_string (value, priv->log_id); + break; + case PROP_DIRECTION: + g_value_set_uint (value, priv->direction); + break; + case PROP_CHAT_ID: + g_value_set_string (value, priv->chat_id); + break; + case PROP_ACCOUNT: + g_value_set_object (value, priv->account); + break; + case PROP_ACCOUNT_PATH: + g_value_set_string (value, tpl_event_get_account_path (self)); + break; + case PROP_CHANNEL_PATH: + g_value_set_string (value, priv->channel_path); + break; + case PROP_SENDER: + g_value_set_object (value, priv->sender); + break; + case PROP_RECEIVER: + g_value_set_object (value, priv->receiver); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + + +static void +tpl_event_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + TplEvent *self = TPL_EVENT (object); + + switch (param_id) { + case PROP_TIMESTAMP: + _tpl_event_set_timestamp (self, g_value_get_uint (value)); + break; + case PROP_LOG_ID: + tpl_event_set_log_id (self, g_value_get_string (value)); + break; + case PROP_DIRECTION: + _tpl_event_set_direction (self, g_value_get_uint (value)); + break; + case PROP_CHAT_ID: + _tpl_event_set_chat_id (self, g_value_get_string (value)); + break; + case PROP_ACCOUNT: + self->priv->account = g_value_dup_object (value); + break; + case PROP_CHANNEL_PATH: + _tpl_event_set_channel_path (self, g_value_get_string (value)); + break; + case PROP_SENDER: + _tpl_event_set_sender (self, g_value_get_object (value)); + break; + case PROP_RECEIVER: + _tpl_event_set_receiver (self, g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + + +static void +tpl_event_class_init (TplEventClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + /* to be used by subclasses */ + object_class->finalize = tpl_event_finalize; + object_class->dispose = tpl_event_dispose; + object_class->get_property = tpl_event_get_property; + object_class->set_property = tpl_event_set_property; + + klass->equal = NULL; + + param_spec = g_param_spec_uint ("timestamp", + "Timestamp", + "The timestamp (gint64) for the log event", + 0, G_MAXUINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_TIMESTAMP, param_spec); + + /** + * TplEvent::log-id: + * + * A token identifying the event. + * + */ + param_spec = g_param_spec_string ("log-id", + "LogId", + "Log identification token, it's unique among existing event, if two " + "messages have the same token, they are the same event (maybe logged " + "by two different TplLogStore)", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_LOG_ID, param_spec); + + param_spec = g_param_spec_uint ("direction", + "Direction", + "The direction of the log event (in/out)", + 0, G_MAXUINT32, TPL_EVENT_DIRECTION_NONE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_DIRECTION, param_spec); + + param_spec = g_param_spec_string ("chat-id", + "ChatId", + "The chat identifier to which the log event is related.", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_CHAT_ID, param_spec); + + param_spec = g_param_spec_object ("account", + "TpAccount", + "The TpAccount to which the log event is related", + TP_TYPE_ACCOUNT, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec); + + param_spec = g_param_spec_string ("account-path", + "AccountPath", + "The account path of the TpAccount to which the log event is related", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_ACCOUNT_PATH, param_spec); + + param_spec = g_param_spec_string ("channel-path", + "ChannelPath", + "The channel path of the TpChannel to which the log event is related", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_CHANNEL_PATH, param_spec); + + param_spec = g_param_spec_object ("sender", + "Sender", + "TplEntity instance who originated the log event", + TPL_TYPE_ENTITY, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_SENDER, param_spec); + + param_spec = g_param_spec_object ("receiver", + "Receiver", + "TplEntity instance destination for the log event", + TPL_TYPE_ENTITY, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_RECEIVER, param_spec); + + g_type_class_add_private (object_class, sizeof (TplEventPriv)); + } + + +static void +tpl_event_init (TplEvent *self) +{ + TplEventPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + TPL_TYPE_EVENT, TplEventPriv); + self->priv = priv; +} + +/** + * tpl_event_get_timestamp + * @self: a #TplEvent + * + * Returns: the same timestamp as the #TplEvent:timestamp property + */ +gint64 +tpl_event_get_timestamp (TplEvent *self) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), -1); + + return self->priv->timestamp; +} + +const gchar * +_tpl_event_get_log_id (TplEvent *self) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), 0); + + return self->priv->log_id; +} + + +TplEventDirection +_tpl_event_get_direction (TplEvent *self) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), + TPL_EVENT_DIRECTION_NONE); + + return self->priv->direction; +} + +/** + * tpl_event_get_sender + * @self: a #TplEvent + * + * Returns: the same #TplEntity as the #TplEvent:sender property + */ +TplEntity * +tpl_event_get_sender (TplEvent *self) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), NULL); + + return self->priv->sender; +} + +/** + * tpl_event_get_receiver + * @self: a #TplEvent + * + * Returns: the same #TplEntity as the #TplEvent:receiver property + */ +TplEntity * +tpl_event_get_receiver (TplEvent *self) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), NULL); + + return self->priv->receiver; +} + + +const gchar * +_tpl_event_get_chat_id (TplEvent *self) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), NULL); + + return self->priv->chat_id; +} + + +/** + * tpl_event_get_account + * @self: a #TplEvent + * + * + * + * Returns: the path as the #TplEvent:account property + */ +const gchar * +tpl_event_get_account_path (TplEvent *self) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), NULL); + + return tp_proxy_get_object_path (self->priv->account); +} + + +const gchar * +_tpl_event_get_channel_path (TplEvent *self) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), NULL); + + return self->priv->channel_path; +} + + +void +_tpl_event_set_timestamp (TplEvent *self, + gint64 data) +{ + g_return_if_fail (TPL_IS_EVENT (self)); + + self->priv->timestamp = data; + g_object_notify (G_OBJECT (self), "timestamp"); +} + + +/* set just on construction time */ +static void +tpl_event_set_log_id (TplEvent *self, + const gchar* data) +{ + g_return_if_fail (TPL_IS_EVENT (self)); + g_return_if_fail (!TPL_STR_EMPTY (data)); + g_return_if_fail (self->priv->log_id == NULL); + + self->priv->log_id = g_strdup (data); + g_object_notify (G_OBJECT (self), "log-id"); +} + + +void +_tpl_event_set_direction (TplEvent *self, + TplEventDirection data) +{ + g_return_if_fail (TPL_IS_EVENT (self)); + + self->priv->direction = data; + g_object_notify (G_OBJECT (self), "direction"); +} + + +void +_tpl_event_set_sender (TplEvent *self, + TplEntity *data) +{ + TplEventPriv *priv; + + if (data == NULL) + return; + + g_return_if_fail (TPL_IS_EVENT (self)); + g_return_if_fail (TPL_IS_ENTITY (data)); + + priv = self->priv; + + if (priv->sender != NULL) + g_object_unref (priv->sender); + priv->sender = g_object_ref (data); + g_object_notify (G_OBJECT (self), "sender"); +} + + +void +_tpl_event_set_receiver (TplEvent *self, + TplEntity *data) +{ + TplEventPriv *priv; + + if (data == NULL) + return; + + g_return_if_fail (TPL_IS_EVENT (self)); + g_return_if_fail (TPL_IS_ENTITY (data)); + + priv = self->priv; + + if (priv->receiver != NULL) + g_object_unref (priv->receiver); + + priv->receiver = g_object_ref (data); + + g_object_notify (G_OBJECT (self), "receiver"); +} + + +void +_tpl_event_set_chat_id (TplEvent *self, + const gchar *data) +{ + if (data == NULL) + return; + + g_return_if_fail (TPL_IS_EVENT (self)); + g_return_if_fail (!TPL_STR_EMPTY (data)); + g_return_if_fail (self->priv->chat_id == NULL); + + self->priv->chat_id = g_strdup (data); + g_object_notify (G_OBJECT (self), "chat-id"); +} + +void +_tpl_event_set_channel_path (TplEvent *self, + const gchar *data) +{ + if (data == NULL) + return; + + g_return_if_fail (TPL_IS_EVENT (self)); + g_return_if_fail (!TPL_STR_EMPTY (data)); + g_return_if_fail (self->priv->channel_path == NULL); + + self->priv->channel_path = g_strdup (data); + g_object_notify (G_OBJECT (self), "channel-path"); +} + +/** + * _tpl_event_equal: + * @self: TplEvent subclass instance + * @data: an instance of the same TplEvent subclass of @self + * + * Checks if two instances of TplEvent represent the same data + * + * Returns: %TRUE if @data is the same type of @self and they hold the same + * data, %FALSE otherwise + */ +gboolean +_tpl_event_equal (TplEvent *self, + TplEvent *data) +{ + g_return_val_if_fail (TPL_IS_EVENT (self), FALSE); + g_return_val_if_fail (TPL_IS_EVENT (data), FALSE); + + return TPL_EVENT_GET_CLASS (self)->equal (self, data); +} + +/** + * tpl_event_get_account + * @self: a #TplEvent + * + * + * + * Returns: the same account as the #TplEvent:account property + */ +TpAccount * +tpl_event_get_account (TplEvent *self) +{ + return self->priv->account; +} diff --git a/telepathy-logger/event.h b/telepathy-logger/event.h new file mode 100644 index 0000000..4dde592 --- /dev/null +++ b/telepathy-logger/event.h @@ -0,0 +1,62 @@ +/* -*- 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 + */ + +#ifndef __TPL_EVENT_H__ +#define __TPL_EVENT_H__ + +#include + +#include + +#include + +G_BEGIN_DECLS +#define TPL_TYPE_EVENT (tpl_event_get_type ()) +#define TPL_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_EVENT, TplEvent)) +#define TPL_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_EVENT, TplEventClass)) +#define TPL_IS_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_EVENT)) +#define TPL_IS_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_EVENT)) +#define TPL_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_EVENT, TplEventClass)) + +typedef struct _TplEvent TplEvent; +typedef struct _TplEventClass TplEventClass; +typedef struct _TplEventPriv TplEventPriv; + +GType tpl_event_get_type (void); + +typedef enum +{ + TPL_EVENT_DIRECTION_NONE = 0, + + TPL_EVENT_DIRECTION_IN, + TPL_EVENT_DIRECTION_OUT +} TplEventDirection; + +gint64 tpl_event_get_timestamp (TplEvent *self); + +const gchar *tpl_event_get_account_path (TplEvent *self); +TpAccount * tpl_event_get_account (TplEvent *self); + +TplEntity * tpl_event_get_sender (TplEvent *self); +TplEntity * tpl_event_get_receiver (TplEvent *self); + +G_END_DECLS +#endif // __TPL_EVENT_H__ diff --git a/telepathy-logger/log-manager-internal.h b/telepathy-logger/log-manager-internal.h index e9f8054..4f9353a 100644 --- a/telepathy-logger/log-manager-internal.h +++ b/telepathy-logger/log-manager-internal.h @@ -28,7 +28,7 @@ #include gboolean _tpl_log_manager_add_event (TplLogManager *manager, - TplEntry *event, GError **error); + TplEvent *event, GError **error); gboolean _tpl_log_manager_register_log_store (TplLogManager *self, TplLogStore *logstore); diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c index c956f77..e3b0156 100644 --- a/telepathy-logger/log-manager.c +++ b/telepathy-logger/log-manager.c @@ -35,8 +35,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -62,7 +62,7 @@ /** * TplLogEventFilter: - * @event: the #TplEntry to filter + * @event: the #TplEvent to filter * @user_data: user-supplied data * * Returns: %TRUE if @event should appear in the result @@ -97,7 +97,7 @@ typedef struct TplLogEventFilter filter; gchar *search_text; gpointer user_data; - TplEntry *logentry; + TplEvent *logevent; } TplLogManagerEventInfo; @@ -256,7 +256,7 @@ tpl_log_manager_dup_singleton (void) /** * _tpl_log_manager_add_event * @manager: the log manager - * @event: a TplEntry subclass's instance + * @event: a TplEvent subclass's instance * @error: the memory location of GError, filled if an error occurs * * It stores @event, sending it to all the registered TplLogStore which have @@ -271,7 +271,7 @@ tpl_log_manager_dup_singleton (void) */ gboolean _tpl_log_manager_add_event (TplLogManager *manager, - TplEntry *event, + TplEvent *event, GError **error) { TplLogManagerPriv *priv; @@ -280,7 +280,7 @@ _tpl_log_manager_add_event (TplLogManager *manager, g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), FALSE); - g_return_val_if_fail (TPL_IS_ENTRY (event), FALSE); + g_return_val_if_fail (TPL_IS_EVENT (event), FALSE); priv = manager->priv; @@ -311,7 +311,7 @@ _tpl_log_manager_add_event (TplLogManager *manager, if (!retval) { CRITICAL ("Failed to write to all " - "writable LogStores log-id %s.", _tpl_entry_get_log_id (event)); + "writable LogStores log-id %s.", _tpl_event_get_log_id (event)); g_set_error_literal (error, TPL_LOG_MANAGER_ERROR, TPL_LOG_MANAGER_ERROR_ADD_EVENT, "Non recoverable error occurred during log manager's " @@ -505,15 +505,15 @@ static gint log_manager_event_date_cmp (gconstpointer a, gconstpointer b) { - TplEntry *one = (TplEntry *) a; - TplEntry *two = (TplEntry *) b; + TplEvent *one = (TplEvent *) a; + TplEvent *two = (TplEvent *) b; gint64 one_time, two_time; - g_assert (TPL_IS_ENTRY (one)); - g_assert (TPL_IS_ENTRY (two)); + g_assert (TPL_IS_EVENT (one)); + g_assert (TPL_IS_EVENT (two)); - one_time = tpl_entry_get_timestamp (one); - two_time = tpl_entry_get_timestamp (two); + one_time = tpl_event_get_timestamp (one); + two_time = tpl_event_get_timestamp (two); /* return -1, 0 or 1 depending on event1 being newer, the same or older * than event2 */ @@ -802,7 +802,7 @@ static void tpl_log_manager_event_info_free (TplLogManagerEventInfo *data) { tp_clear_object (&data->account); - tp_clear_object (&data->logentry); + tp_clear_object (&data->logevent); tp_clear_pointer (&data->id, g_free); tp_clear_pointer (&data->date, g_date_free); @@ -1000,7 +1000,7 @@ tpl_log_manager_get_events_for_date_finish (TplLogManager *self, static void _get_events_for_date_async_result_free (gpointer data) { - GList *lst = data; /* list of TPL_ENTRY */ + GList *lst = data; /* list of TPL_EVENT */ g_list_foreach (lst, (GFunc) g_object_unref, NULL); g_list_free (lst); @@ -1039,7 +1039,7 @@ _get_events_for_date_async_thread (GSimpleAsyncResult *simple, * @callback: a callback to call when the request is satisfied * @user_data: data to pass to @callback * - * Retrieve a list of #TplEntry exchanged at @date with @id. + * Retrieve a list of #TplEvent exchanged at @date with @id. */ void tpl_log_manager_get_events_for_date_async (TplLogManager *manager, @@ -1085,7 +1085,7 @@ tpl_log_manager_get_events_for_date_async (TplLogManager *manager, * tpl_log_manager_get_filtered_events_finish: * @self: a #TplLogManager * @result: a #GAsyncResult - * @events: a pointer to a #GList used to return the list #TplEntry + * @events: a pointer to a #GList used to return the list #TplEvent * @error: a #GError to fill * * Returns: #TRUE if the operation was successful, #FALSE otherwise. @@ -1123,7 +1123,7 @@ tpl_log_manager_get_filtered_events_finish (TplLogManager *self, static void _get_filtered_events_async_result_free (gpointer data) { - GList *lst = data; /* list of TPL_ENTRY */ + GList *lst = data; /* list of TPL_EVENT */ g_list_foreach (lst, (GFunc) g_object_unref, NULL); g_list_free (lst); diff --git a/telepathy-logger/log-manager.h b/telepathy-logger/log-manager.h index b3a6d0b..d42ebb7 100644 --- a/telepathy-logger/log-manager.h +++ b/telepathy-logger/log-manager.h @@ -27,7 +27,7 @@ #include #include -#include +#include G_BEGIN_DECLS #define TPL_TYPE_LOG_MANAGER (tpl_log_manager_get_type ()) @@ -76,7 +76,7 @@ typedef struct GDate *date; } TplLogSearchHit; -typedef gboolean (*TplLogEventFilter) (TplEntry *event, +typedef gboolean (*TplLogEventFilter) (TplEvent *event, gpointer user_data); GType tpl_log_manager_get_type (void); diff --git a/telepathy-logger/log-store-internal.h b/telepathy-logger/log-store-internal.h index 7da098d..c09cdac 100644 --- a/telepathy-logger/log-store-internal.h +++ b/telepathy-logger/log-store-internal.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include G_BEGIN_DECLS @@ -64,7 +64,7 @@ typedef struct const gchar * (*get_name) (TplLogStore *self); gboolean (*exists) (TplLogStore *self, TpAccount *account, const gchar *id, TplEventSearchType type); - gboolean (*add_event) (TplLogStore *self, TplEntry *event, + gboolean (*add_event) (TplLogStore *self, TplEvent *event, GError **error); GList * (*get_dates) (TplLogStore *self, TpAccount *account, const gchar *id, TplEventSearchType type); @@ -87,7 +87,7 @@ GType _tpl_log_store_get_type (void); const gchar * _tpl_log_store_get_name (TplLogStore *self); gboolean _tpl_log_store_exists (TplLogStore *self, TpAccount *account, const gchar *id, TplEventSearchType type); -gboolean _tpl_log_store_add_event (TplLogStore *self, TplEntry *event, +gboolean _tpl_log_store_add_event (TplLogStore *self, TplEvent *event, GError **error); GList * _tpl_log_store_get_dates (TplLogStore *self, TpAccount *account, const gchar *id, TplEventSearchType type); diff --git a/telepathy-logger/log-store-sqlite.c b/telepathy-logger/log-store-sqlite.c index f68b15f..4d90118 100644 --- a/telepathy-logger/log-store-sqlite.c +++ b/telepathy-logger/log-store-sqlite.c @@ -26,9 +26,9 @@ #include #include -#include "entry-internal.h" -#include "entry-text.h" -#include "entry-text-internal.h" +#include "event-internal.h" +#include "event-text.h" +#include "event-text-internal.h" #include "log-store-sqlite-internal.h" #include "log-manager-internal.h" @@ -45,10 +45,10 @@ static void log_store_iface_init (TplLogStoreInterface *iface); static gboolean _insert_to_cache_table (TplLogStore *self, - TplEntry *message, GError **error); + TplEvent *message, GError **error); static void tpl_log_store_sqlite_purge (TplLogStoreSqlite *self, time_t delta, GError **error); -static gboolean purge_entry_timeout (gpointer logstore); +static gboolean purge_event_timeout (gpointer logstore); G_DEFINE_TYPE_WITH_CODE (TplLogStoreSqlite, _tpl_log_store_sqlite, @@ -239,7 +239,7 @@ _tpl_log_store_sqlite_init (TplLogStoreSqlite *self) } /* purge old entries every hour (60*60 secs) and purges 24h old entries */ - priv->purge_id = g_timeout_add_seconds (60*60, purge_entry_timeout, self); + priv->purge_id = g_timeout_add_seconds (60*60, purge_event_timeout, self); /* end of cache table init */ @@ -274,9 +274,9 @@ get_account_name (TpAccount *account) } static const char * -get_account_name_from_entry (TplEntry *entry) +get_account_name_from_event (TplEvent *event) { - return tpl_entry_get_account_path (entry) + + return tpl_event_get_account_path (event) + strlen (TP_ACCOUNT_OBJECT_PATH_BASE); } @@ -288,28 +288,28 @@ get_channel_name (TpChannel *chan) } static const char * -get_channel_name_from_entry (TplEntry *entry) +get_channel_name_from_event (TplEvent *event) { - return _tpl_entry_get_channel_path (entry) + + return _tpl_event_get_channel_path (event) + strlen (TP_CONN_OBJECT_PATH_BASE); } static char * -get_date (TplEntry *entry) +get_date (TplEvent *event) { time_t t; - t = tpl_entry_get_timestamp (entry); + t = tpl_event_get_timestamp (event); return _tpl_time_to_string_utc (t, "%Y-%m-%d"); } static char * -get_datetime (TplEntry *entry) +get_datetime (TplEvent *event) { time_t t; - t = tpl_entry_get_timestamp (entry); + t = tpl_event_get_timestamp (event); return _tpl_time_to_string_utc (t, TPL_LOG_STORE_SQLITE_TIMESTAMP_FORMAT); } @@ -354,7 +354,7 @@ _cache_msg_id_is_present (TplLogStore *self, sqlite3_bind_int (sql, 2, msg_id); e = sqlite3_step (sql); - /* return the first (most recent) entry if a raw is found */ + /* return the first (most recent) event if a raw is found */ if (e == SQLITE_ROW) retval = g_strdup ((const gchar *) sqlite3_column_text (sql, 0)); else if (e == SQLITE_ERROR) @@ -430,7 +430,7 @@ out: static gboolean tpl_log_store_sqlite_add_message_counter (TplLogStore *self, - TplEntry *message, + TplEvent *message, GError **error) { TplLogStoreSqlitePrivate *priv = GET_PRIV (self); @@ -445,21 +445,21 @@ tpl_log_store_sqlite_add_message_counter (TplLogStore *self, g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if ((TPL_IS_ENTRY_TEXT (message) == FALSE) || - (_tpl_entry_text_get_signal_type (TPL_ENTRY_TEXT (message)) != - TPL_ENTRY_TEXT_SIGNAL_RECEIVED)) + if ((TPL_IS_EVENT_TEXT (message) == FALSE) || + (_tpl_event_text_get_signal_type (TPL_EVENT_TEXT (message)) != + TPL_EVENT_TEXT_SIGNAL_RECEIVED)) { DEBUG ("ignoring msg %s, not interesting for message-counter", - _tpl_entry_get_log_id (message)); + _tpl_event_get_log_id (message)); retval = TRUE; goto out; } DEBUG ("message received"); - account = get_account_name_from_entry (message); - identifier = _tpl_entry_get_chat_id (message); - chatroom = _tpl_entry_text_is_chatroom (TPL_ENTRY_TEXT (message)); + account = get_account_name_from_event (message); + identifier = _tpl_event_get_chat_id (message); + chatroom = _tpl_event_text_is_chatroom (TPL_EVENT_TEXT (message)); date = get_date (message); DEBUG ("account = %s", account); @@ -580,7 +580,7 @@ out: static gboolean tpl_log_store_sqlite_add_message_cache (TplLogStore *self, - TplEntry *message, + TplEvent *message, GError **error) { const char *log_id; @@ -588,7 +588,7 @@ tpl_log_store_sqlite_add_message_cache (TplLogStore *self, g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - log_id = _tpl_entry_get_log_id (message); + log_id = _tpl_event_get_log_id (message); DEBUG ("received %s, considering if can be cached", log_id); if (_tpl_log_store_sqlite_log_id_is_present (self, log_id)) { @@ -614,24 +614,24 @@ out: /** * tpl_log_store_sqlite_add_event: * @self: TplLogstoreSqlite instance - * @message: a TplEntry instance + * @message: a TplEvent instance * @error: memory pointer use in case of error * * @message will be sent to the MessageCounter and MessageSqlite tables. * - * MessageSqlite will accept any instance of TplEntry for @message and will + * MessageSqlite will accept any instance of TplEvent for @message and will * return %FALSE with @error set when a fatal error occurs or when @message * has already been logged. * For the last case a TPL_LOG_STORE_ERROR_PRESENT will be set as error * code in @error, and is considered fatal, since it should never happen. * - * A module implementing a TplChannel should always check for TplEntry + * A module implementing a TplChannel should always check for TplEvent * log-id presence in the cache log-store if there is a chance to receive the * same log-id twice. * * MessageCounter only handles Text messages, which means that it will * silently (ie won't use @error) not log @message, when it won't be an - * instance ot TplEntryText, returning anyway %TRUE. This means "I could + * instance ot TplEventText, returning anyway %TRUE. This means "I could * store @message, but I'm discarding it because I'm not interested in it" and * is not cosidered an error (@error won't be set). * It will return %FALSE with @error set if a fatal error occurred, for @@ -644,7 +644,7 @@ out: */ static gboolean tpl_log_store_sqlite_add_event (TplLogStore *self, - TplEntry *message, + TplEvent *message, GError **error) { gboolean retval = FALSE; @@ -657,10 +657,10 @@ tpl_log_store_sqlite_add_event (TplLogStore *self, "TplLogStoreSqlite intance needed"); goto out; } - if (!TPL_IS_ENTRY (message)) + if (!TPL_IS_EVENT (message)) { g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, "TplEntry instance needed"); + TPL_LOG_STORE_ERROR_ADD_EVENT, "TplEvent instance needed"); goto out; } @@ -683,7 +683,7 @@ out: static gboolean _insert_to_cache_table (TplLogStore *self, - TplEntry *message, + TplEvent *message, GError **error) { TplLogStoreSqlitePrivate *priv = GET_PRIV (self); @@ -695,7 +695,7 @@ _insert_to_cache_table (TplLogStore *self, gboolean retval = FALSE; int e; - if (!TPL_IS_ENTRY_TEXT (message)) + if (!TPL_IS_EVENT_TEXT (message)) { g_set_error (error, TPL_LOG_STORE_ERROR, TPL_LOG_STORE_ERROR_ADD_EVENT, @@ -704,12 +704,12 @@ _insert_to_cache_table (TplLogStore *self, goto out; } - account = get_account_name_from_entry (message); - channel = get_channel_name_from_entry (message); - identifier = _tpl_entry_get_chat_id (message); - log_id = _tpl_entry_get_log_id (message); - msg_id = tpl_entry_text_get_pending_msg_id (TPL_ENTRY_TEXT (message)); - chatroom = _tpl_entry_text_is_chatroom (TPL_ENTRY_TEXT (message)); + account = get_account_name_from_event (message); + channel = get_channel_name_from_event (message); + identifier = _tpl_event_get_chat_id (message); + log_id = _tpl_event_get_log_id (message); + msg_id = tpl_event_text_get_pending_msg_id (TPL_EVENT_TEXT (message)); + chatroom = _tpl_event_text_is_chatroom (TPL_EVENT_TEXT (message)); date = get_datetime (message); DEBUG ("channel = %s", channel); @@ -717,7 +717,7 @@ _insert_to_cache_table (TplLogStore *self, DEBUG ("chat_identifier = %s", identifier); DEBUG ("log_identifier = %s", log_id); DEBUG ("pending_msg_id = %d (%s)", msg_id, - (TPL_ENTRY_MSG_ID_IS_VALID (msg_id) ? + (TPL_EVENT_MSG_ID_IS_VALID (msg_id) ? "pending" : "acknowledged or sent")); DEBUG ("chatroom = %i", chatroom); DEBUG ("date = %s", date); @@ -752,7 +752,7 @@ _insert_to_cache_table (TplLogStore *self, sqlite3_bind_text (sql, 2, account, -1, SQLITE_TRANSIENT); /* insert NULL if ACKNOWLEDGED (ie sent message's entries, which are created * ACK'd */ - if (!TPL_ENTRY_MSG_ID_IS_VALID (msg_id)) + if (!TPL_EVENT_MSG_ID_IS_VALID (msg_id)) sqlite3_bind_null (sql, 3); else sqlite3_bind_int (sql, 3, msg_id); @@ -813,7 +813,7 @@ out: * specific TpChannel instance with the same path or not, just knowking its * path. * This is not a problem, though, since log-ids are unique within TPL. If two - * log-ids match, they relates to the same TplEntry instance. + * log-ids match, they relates to the same TplEvent instance. * * Returns: a list of log-id */ @@ -909,7 +909,7 @@ out: * specific TpChannel instance with the same path or not, just knowking its * path. * This is not a problem, though, since log-ids are unique within TPL. If two - * log-ids match, they relates to the same TplEntry instance. + * log-ids match, they relates to the same TplEvent instance. * * Returns: a list of log-id */ @@ -1108,7 +1108,7 @@ out: } static gboolean -purge_entry_timeout (gpointer logstore) +purge_event_timeout (gpointer logstore) { GError *error = NULL; TplLogStoreSqlite *self = logstore; diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c index 864d1b0..37a53f3 100644 --- a/telepathy-logger/log-store-xml.c +++ b/telepathy-logger/log-store-xml.c @@ -39,9 +39,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -326,11 +326,11 @@ log_store_xml_get_timestamp_filename (void) static gchar * -log_store_xml_get_timestamp_from_event (TplEntry *event) +log_store_xml_get_timestamp_from_event (TplEvent *event) { time_t t; - t = tpl_entry_get_timestamp (event); + t = tpl_event_get_timestamp (event); /* We keep the timestamps in the events as UTC */ return _tpl_time_to_string_utc (t, LOG_TIME_FORMAT_FULL); @@ -366,14 +366,14 @@ log_store_xml_get_filename (TplLogStoreXml *self, /* this is a method used at the end of the add_event process, used by any - * Entry instance. it should the only method allowed to write to the + * Event instance. it should the only method allowed to write to the * store */ static gboolean _log_store_xml_write_to_store (TplLogStoreXml *self, TpAccount *account, const gchar *id, TplEventSearchType type, - const gchar *entry, + const gchar *event, GError **error) { FILE *file; @@ -385,7 +385,7 @@ _log_store_xml_write_to_store (TplLogStoreXml *self, g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), FALSE); g_return_val_if_fail (TP_IS_ACCOUNT (account), FALSE); g_return_val_if_fail (!TPL_STR_EMPTY (id), FALSE); - g_return_val_if_fail (!TPL_STR_EMPTY (entry), FALSE); + g_return_val_if_fail (!TPL_STR_EMPTY (event), FALSE); filename = log_store_xml_get_filename (self, account, id, type); @@ -419,8 +419,8 @@ _log_store_xml_write_to_store (TplLogStoreXml *self, ret = FALSE; goto out; } - g_fprintf (file, "%s", entry); - DEBUG ("%s: written: %s", filename, entry); + g_fprintf (file, "%s", event); + DEBUG ("%s: written: %s", filename, event); fclose (file); out: @@ -431,7 +431,7 @@ _log_store_xml_write_to_store (TplLogStoreXml *self, static gboolean add_event_text_chat (TplLogStoreXml *self, - TplEntryText *message, + TplEventText *message, GError **error) { gboolean ret = FALSE; @@ -444,12 +444,12 @@ add_event_text_chat (TplLogStoreXml *self, gchar *timestamp; gchar *contact_name = NULL; gchar *contact_id; - gchar *entry; + gchar *event; TpChannelTextMessageType msg_type; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), FALSE); - g_return_val_if_fail (TPL_IS_ENTRY_TEXT (message), FALSE); + g_return_val_if_fail (TPL_IS_EVENT_TEXT (message), FALSE); bus_daemon = tp_dbus_daemon_dup (error); if (bus_daemon == NULL) @@ -458,18 +458,18 @@ add_event_text_chat (TplLogStoreXml *self, goto out; } - account = tpl_entry_get_account (TPL_ENTRY (message)); + account = tpl_event_get_account (TPL_EVENT (message)); - body_str = tpl_entry_text_get_message (message); + body_str = tpl_event_text_get_message (message); if (TPL_STR_EMPTY (body_str)) goto out; body = g_markup_escape_text (body_str, -1); - msg_type = _tpl_entry_text_get_message_type (message); + msg_type = _tpl_event_text_get_message_type (message); timestamp = log_store_xml_get_timestamp_from_event ( - TPL_ENTRY (message)); + TPL_EVENT (message)); - sender = tpl_entry_get_sender (TPL_ENTRY (message)); + sender = tpl_event_get_sender (TPL_EVENT (message)); contact_id = g_markup_escape_text (tpl_entity_get_identifier (sender), -1); if (tpl_entity_get_alias (sender) != NULL) contact_name = g_markup_escape_text (tpl_entity_get_alias (sender), -1); @@ -477,32 +477,32 @@ add_event_text_chat (TplLogStoreXml *self, avatar_token = g_markup_escape_text (tpl_entity_get_avatar_token (sender), -1); - entry = g_strdup_printf ("" "%s\n" LOG_FOOTER, timestamp, - _tpl_entry_get_log_id (TPL_ENTRY (message)), + _tpl_event_get_log_id (TPL_EVENT (message)), contact_id, contact_name, avatar_token ? avatar_token : "", tpl_entity_get_entity_type (sender) == TPL_ENTITY_SELF ? "true" : "false", - _tpl_entry_text_message_type_to_str (msg_type), + _tpl_event_text_message_type_to_str (msg_type), body); DEBUG ("writing %s from %s (ts %s)", - _tpl_entry_get_log_id (TPL_ENTRY (message)), + _tpl_event_get_log_id (TPL_EVENT (message)), contact_id, timestamp); ret = _log_store_xml_write_to_store (self, account, - _tpl_entry_get_chat_id (TPL_ENTRY (message)), - _tpl_entry_text_is_chatroom (message), - entry, error); + _tpl_event_get_chat_id (TPL_EVENT (message)), + _tpl_event_text_is_chatroom (message), + event, error); out: g_free (contact_id); g_free (contact_name); g_free (timestamp); g_free (body); - g_free (entry); + g_free (event); g_free (avatar_token); if (bus_daemon != NULL) @@ -514,58 +514,58 @@ out: static gboolean add_event_text (TplLogStoreXml *self, - TplEntryText *message, + TplEventText *message, GError **error) { - TplEntryTextSignalType signal_type; + TplEventTextSignalType signal_type; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), FALSE); - g_return_val_if_fail (TPL_IS_ENTRY_TEXT (message), FALSE); + g_return_val_if_fail (TPL_IS_EVENT_TEXT (message), FALSE); - signal_type = _tpl_entry_text_get_signal_type (message); + signal_type = _tpl_event_text_get_signal_type (message); switch (signal_type) { - case TPL_ENTRY_TEXT_SIGNAL_SENT: - case TPL_ENTRY_TEXT_SIGNAL_RECEIVED: + case TPL_EVENT_TEXT_SIGNAL_SENT: + case TPL_EVENT_TEXT_SIGNAL_RECEIVED: return add_event_text_chat (self, message, error); break; - case TPL_ENTRY_TEXT_SIGNAL_CHAT_STATUS_CHANGED: - g_warning ("STATUS_CHANGED log entry not currently handled"); + case TPL_EVENT_TEXT_SIGNAL_CHAT_STATUS_CHANGED: + g_warning ("STATUS_CHANGED log event not currently handled"); return FALSE; break; - case TPL_ENTRY_TEXT_SIGNAL_SEND_ERROR: - g_warning ("SEND_ERROR log entry not currently handled"); + case TPL_EVENT_TEXT_SIGNAL_SEND_ERROR: + g_warning ("SEND_ERROR log event not currently handled"); return FALSE; - case TPL_ENTRY_TEXT_SIGNAL_LOST_MESSAGE: - g_warning ("LOST_MESSAGE log entry not currently handled"); + case TPL_EVENT_TEXT_SIGNAL_LOST_MESSAGE: + g_warning ("LOST_MESSAGE log event not currently handled"); return FALSE; default: - g_warning ("Entry's signal type unknown"); + g_warning ("Event's signal type unknown"); return FALSE; } } -/* First of two phases selection: understand the type Entry */ +/* First of two phases selection: understand the type Event */ static gboolean log_store_xml_add_event (TplLogStore *store, - TplEntry *event, + TplEvent *event, GError **error) { TplLogStoreXml *self = TPL_LOG_STORE_XML (store); - g_return_val_if_fail (TPL_IS_ENTRY (event), FALSE); + g_return_val_if_fail (TPL_IS_EVENT (event), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if (TPL_IS_ENTRY_TEXT (event)) - return add_event_text (self, TPL_ENTRY_TEXT (event), error); + if (TPL_IS_EVENT_TEXT (event)) + return add_event_text (self, TPL_EVENT_TEXT (event), error); - DEBUG ("TplEntrySignalType not handled by this LogStore (%s). " - "Ignoring Entry", log_store_xml_get_name (store)); + DEBUG ("TplEventSignalType not handled by this LogStore (%s). " + "Ignoring Event", log_store_xml_get_name (store)); /* do not consider it an error, this LogStore simply do not want/need - * this Entry */ + * this Event */ return TRUE; } @@ -767,7 +767,7 @@ log_store_xml_search_hit_new (TplLogStoreXml *self, return hit; } -/* returns a Glist of TplEntry instances */ +/* returns a Glist of TplEvent instances */ static GList * log_store_xml_get_events_for_file (TplLogStoreXml *self, TpAccount *account, @@ -815,8 +815,8 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, /* Now get the events. */ for (node = log_node->children; node; node = node->next) { - TplEntry *event; - TplEntryText *message; + TplEvent *event; + TplEventText *message; TplEntity *sender; gchar *time_; time_t t; @@ -851,14 +851,14 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, is_user = (!tp_strdiff (is_user_str, "true")); if (msg_type_str != NULL) - msg_type = _tpl_entry_text_message_type_from_str (msg_type_str); + msg_type = _tpl_event_text_message_type_from_str (msg_type_str); if (log_id != NULL && self->priv->empathy_legacy) /* in legacy mode, it's actually the pending message id before ACK */ pending_id = atoi (log_id); else /* we have no way in non empathy-legacy mode to know it */ - pending_id = TPL_ENTRY_MSG_ID_UNKNOWN; + pending_id = TPL_EVENT_MSG_ID_UNKNOWN; t = _tpl_time_parse (time_); @@ -883,15 +883,15 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, g_free (instead_of_channel_path); } - message = _tpl_entry_text_new (log_id, account, TPL_ENTRY_DIRECTION_NONE); - event = TPL_ENTRY (message); + message = _tpl_event_text_new (log_id, account, TPL_EVENT_DIRECTION_NONE); + event = TPL_EVENT (message); - _tpl_entry_text_set_pending_msg_id (message, + _tpl_event_text_set_pending_msg_id (message, pending_id); - _tpl_entry_set_sender (event, sender); - _tpl_entry_set_timestamp (event, t); - _tpl_entry_text_set_message (message, body); - _tpl_entry_text_set_message_type (message, msg_type); + _tpl_event_set_sender (event, sender); + _tpl_event_set_timestamp (event, t); + _tpl_event_text_set_message (message, body); + _tpl_event_text_set_message_type (message, msg_type); events = g_list_append (events, event); @@ -1126,7 +1126,7 @@ log_store_xml_get_events_for_dir (TplLogStoreXml *self, } -/* returns a Glist of TplEntry instances */ +/* returns a Glist of TplEvent instances */ static GList * log_store_xml_get_events_for_date (TplLogStore *store, TpAccount *account, diff --git a/telepathy-logger/log-store.c b/telepathy-logger/log-store.c index 48eef24..d62bed6 100644 --- a/telepathy-logger/log-store.c +++ b/telepathy-logger/log-store.c @@ -32,7 +32,7 @@ * @title: TplLogStore * @short_description: LogStore interface can register into #TplLogManager as * #TplLogStore:writable or #TplLogStore:readable log stores. - * @see_also: #entry-text:TplEntryText and other subclasses when they'll exist + * @see_also: #event-text:TplEventText and other subclasses when they'll exist * * The #TplLogStore defines all the public methods that a TPL Log Store has to * implement in order to be used into a #TplLogManager. @@ -136,7 +136,7 @@ _tpl_log_store_exists (TplLogStore *self, /** * _tpl_log_store_add_event: * @self: a TplLogStore - * @event: an instance of a subclass of TplEntry (ie TplEntryText) + * @event: an instance of a subclass of TplEvent (ie TplEventText) * @error: memory location used if an error occurs * * Sends @event to the LogStore @self, in order to be stored. @@ -145,7 +145,7 @@ _tpl_log_store_exists (TplLogStore *self, */ gboolean _tpl_log_store_add_event (TplLogStore *self, - TplEntry *event, + TplEvent *event, GError **error) { g_return_val_if_fail (TPL_IS_LOG_STORE (self), FALSE); @@ -203,7 +203,7 @@ _tpl_log_store_get_dates (TplLogStore *self, * * Retrieves a list of events, with timestamp matching @date. * - * Returns: a GList of TplEntryText, to be freed using something like + * Returns: a GList of TplEventText, to be freed using something like * g_list_foreach (lst, g_object_unref, NULL); * g_list_free (lst); */ @@ -331,7 +331,7 @@ _tpl_log_store_search_new (TplLogStore *self, * It will return at most the last (ie most recent) @num_events events. * Pass G_MAXUINT if all the events are needed. * - * Returns: a GList of TplEntryText, to be freed using something like + * Returns: a GList of TplEventText, to be freed using something like * g_list_foreach (lst, g_object_unref, NULL); * g_list_free (lst); */ diff --git a/telepathy-logger/telepathy-logger.h b/telepathy-logger/telepathy-logger.h index 32fccef..19aee37 100644 --- a/telepathy-logger/telepathy-logger.h +++ b/telepathy-logger/telepathy-logger.h @@ -22,8 +22,8 @@ #define __TELEPATHY_LOGGER_H__ #include -#include -#include +#include +#include #include #endif diff --git a/tests/test-tpl-log-manager.c b/tests/test-tpl-log-manager.c index 01739df..9d531ec 100644 --- a/tests/test-tpl-log-manager.c +++ b/tests/test-tpl-log-manager.c @@ -1,4 +1,4 @@ -#include +#include #define gconf_client_get_bool(obj,key,err) g_print ("%s", key) -- 1.7.3.4