From 2617a96e629c78e9c3b7a983ce47d96174136b2c Mon Sep 17 00:00:00 2001 From: Cosimo Alfarano Date: Tue, 29 Dec 2009 11:11:27 +0000 Subject: Added tpl-log-reader for the read only API * added tpl-log-reader.[ch] * moved headers from include/ to src/ * bug fixing in tpl-log-empathy, especially on the pre-requisites checks --- TODO | 2 + include/config.h | 0 include/tpl-channel.h | 100 ---------- include/tpl-contact.h | 99 ---------- include/tpl-log-entry-text.h | 145 --------------- include/tpl-log-entry.h | 79 -------- include/tpl-log-manager.h | 106 ----------- include/tpl-log-store-empathy.h | 66 ------- include/tpl-log-store.h | 100 ---------- include/tpl-observer.h | 75 -------- include/tpl-text-channel-context.h | 88 --------- include/tpl-time.h | 48 ----- include/tpl-utils.h | 39 ---- src/Makefile.am | 9 +- src/config.h | 0 src/test.c | 60 +++++- src/tpl-channel.h | 100 ++++++++++ src/tpl-contact.h | 99 ++++++++++ src/tpl-log-entry-text.h | 145 +++++++++++++++ src/tpl-log-entry.h | 79 ++++++++ src/tpl-log-manager.c | 3 + src/tpl-log-manager.h | 106 +++++++++++ src/tpl-log-reader.c | 368 +++++++++++++++++++++++++++++++++++++ src/tpl-log-reader.h | 91 +++++++++ src/tpl-log-store-empathy.c | 133 +++++++++----- src/tpl-log-store-empathy.h | 68 +++++++ src/tpl-log-store.c | 1 + src/tpl-log-store.h | 100 ++++++++++ src/tpl-observer.h | 75 ++++++++ src/tpl-text-channel-context.h | 88 +++++++++ src/tpl-time.h | 48 +++++ src/tpl-utils.h | 39 ++++ 32 files changed, 1563 insertions(+), 996 deletions(-) delete mode 100644 include/config.h delete mode 100644 include/tpl-channel.h delete mode 100644 include/tpl-contact.h delete mode 100644 include/tpl-log-entry-text.h delete mode 100644 include/tpl-log-entry.h delete mode 100644 include/tpl-log-manager.h delete mode 100644 include/tpl-log-store-empathy.h delete mode 100644 include/tpl-log-store.h delete mode 100644 include/tpl-observer.h delete mode 100644 include/tpl-text-channel-context.h delete mode 100644 include/tpl-time.h delete mode 100644 include/tpl-utils.h create mode 100644 src/config.h create mode 100644 src/tpl-channel.h create mode 100644 src/tpl-contact.h create mode 100644 src/tpl-log-entry-text.h create mode 100644 src/tpl-log-entry.h create mode 100644 src/tpl-log-manager.h create mode 100644 src/tpl-log-reader.c create mode 100644 src/tpl-log-reader.h create mode 100644 src/tpl-log-store-empathy.h create mode 100644 src/tpl-log-store.h create mode 100644 src/tpl-observer.h create mode 100644 src/tpl-text-channel-context.h create mode 100644 src/tpl-time.h create mode 100644 src/tpl-utils.h diff --git a/TODO b/TODO index 72c059c..0aa1c4d 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,8 @@ Those are mini tasks still to do. They should be filed against a bug trucker as soon as TPL will have one: +- add a logstore-ro interface or split the current one in rw and ro + depending on what/who is using it - global configuration object (ie disable logging partially or totally, choose the logstore, etc) - understand if direction from tpl_log_entry_text is to be removed diff --git a/include/config.h b/include/config.h deleted file mode 100644 index e69de29..0000000 diff --git a/include/tpl-channel.h b/include/tpl-channel.h deleted file mode 100644 index 0fc9e30..0000000 --- a/include/tpl-channel.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_CHANNEL_H__ -#define __TPL_CHANNEL_H__ - -#include -#include -#include -#include -#include -#include - -#include -#include - -G_BEGIN_DECLS - -#define TPL_TYPE_CHANNEL (tpl_channel_get_type ()) -#define TPL_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CHANNEL, TplChannel)) -#define TPL_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CHANNEL, TplChannelClass)) -#define TPL_IS_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CHANNEL)) -#define TPL_IS_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CHANNEL)) -#define TPL_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CHANNEL, TplChannelClass)) -// TODO test the following macros -//#define TPL_CHANNEL_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), TPL_TYPE_CHANNEL, TplChannelClass)) - -typedef struct { - GObject parent; - - /* private */ - TpChannel *channel; - const gchar *channel_path; - const gchar *channel_type; - GHashTable *channel_properties; - - TpAccount *account; - const gchar *account_path; - TpConnection *connection; - const gchar *connection_path; - - TpSvcClientObserver *observer; -} TplChannel; - -typedef struct { - GObjectClass parent_class; -} TplChannelClass; - - -GType tpl_channel_get_type (void); - -TplChannel* tpl_channel_new (TpSvcClientObserver *observer); -void tpl_channel_free(TplChannel* tpl_chan); - -TpSvcClientObserver *tpl_channel_get_observer(TplChannel *self); -TpAccount *tpl_channel_get_account(TplChannel *self); -const gchar *tpl_channel_get_account_path(TplChannel *self); -TpConnection *tpl_channel_get_connection(TplChannel *self); -const gchar *tpl_channel_get_connection_path(TplChannel *self); -TpChannel *tpl_channel_get_channel(TplChannel *self); -const gchar *tpl_channel_get_channel_path(TplChannel *self); -const gchar *tpl_channel_get_channel_type(TplChannel *self); -GHashTable *tpl_channel_get_channel_properties(TplChannel *self); - - -void tpl_channel_set_observer(TplChannel *self, - TpSvcClientObserver *data); -void tpl_channel_set_account(TplChannel *self, TpAccount *data); -void tpl_channel_set_account_path(TplChannel *self, const gchar *data); -void tpl_channel_set_connection(TplChannel *self, TpConnection *data); -void tpl_channel_set_connection_path(TplChannel *self, const gchar *data); -void tpl_channel_set_channel(TplChannel *self, TpChannel *data); -void tpl_channel_set_channel_path(TplChannel *self, const gchar *data); -void tpl_channel_set_channel_type(TplChannel *self, const gchar *data); -void tpl_channel_set_channel_properties(TplChannel *self, GHashTable *data); - -gboolean tpl_channel_register_to_observer(TplChannel *self); -gboolean tpl_channel_unregister_from_observer(TplChannel *self); - -G_END_DECLS - -#endif // __TPL_CHANNEL_H__ diff --git a/include/tpl-contact.h b/include/tpl-contact.h deleted file mode 100644 index 1d28bbc..0000000 --- a/include/tpl-contact.h +++ /dev/null @@ -1,99 +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_CONTACT_H__ -#define __TPL_CONTACT_H__ - -#include -#include - -G_BEGIN_DECLS - -#define TPL_TYPE_CONTACT (tpl_contact_get_type ()) -#define TPL_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CONTACT, TplContact)) -#define TPL_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CONTACT, TplContactClass)) -#define TPL_IS_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CONTACT)) -#define TPL_IS_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CONTACT)) -#define TPL_CONTACT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CONTACT, TplContactClass)) - - -typedef enum { - TPL_CONTACT_USER, - TPL_CONTACT_GROUP -} TplContactType; - -typedef struct { - GObject parent; - - /* Private */ - TpContact *contact; - TplContactType contact_type; - const gchar *alias; - const gchar *identifier; - const gchar *presence_status; - const gchar *presence_message; - - TpAccount *account; -} TplContact; - - -typedef struct { - GObjectClass parent_class; -} TplContactClass; - - -GType tpl_contact_get_type (void); - -TplContact *tpl_contact_from_tp_contact(TpContact *contact); - -TplContact *tpl_contact_new(void); - -TpContact *tpl_contact_get_contact(TplContact *self); - -const gchar *tpl_contact_get_alias(TplContact *self); - -const gchar *tpl_contact_get_identifier(TplContact *self); - -const gchar *tpl_contact_get_presence_status(TplContact *self); - -const gchar *tpl_contact_get_presence_message(TplContact *self); - -TplContactType tpl_contact_get_contact_type(TplContact *self); - -TpAccount *tpl_contact_get_account(TplContact *self); - -void tpl_contact_set_contact(TplContact *self, TpContact *data); - -void tpl_contact_set_account(TplContact *self, TpAccount *data); - -void tpl_contact_set_alias(TplContact *self, const gchar *data); - -void tpl_contact_set_identifier(TplContact *self, const gchar *data); - -void tpl_contact_set_presence_status(TplContact *self, const gchar *data); - -void tpl_contact_set_presence_message(TplContact *self, const gchar *data); - -void tpl_contact_set_contact_type(TplContact *self, TplContactType data); - -G_END_DECLS - -#endif // __TPL_CONTACT_H__ diff --git a/include/tpl-log-entry-text.h b/include/tpl-log-entry-text.h deleted file mode 100644 index 61c4be1..0000000 --- a/include/tpl-log-entry-text.h +++ /dev/null @@ -1,145 +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_LOG_ENTRY_TEXT_H__ -#define __TPL_LOG_ENTRY_TEXT_H__ - -#include -#include - -#include -#include - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_ENTRY_TEXT (tpl_log_entry_text_get_type ()) -#define TPL_LOG_ENTRY_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_ENTRY_TEXT, TplLogEntryText)) -#define TPL_LOG_ENTRY_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_LOG_ENTRY_TEXT, TplLogEntryTextClass)) -#define TPL_IS_LOG_ENTRY_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_ENTRY_TEXT)) -#define TPL_IS_LOG_ENTRY_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_LOG_ENTRY_TEXT)) -#define TPL_LOG_ENTRY_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_LOG_ENTRY_TEXT, TplLogEntryTextClass)) - - -/* Valid for org.freedesktop.Telepathy.Channel.Type.Text */ - -typedef enum { - TPL_LOG_ENTRY_TEXT_SIGNAL_SENT, - TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED, - TPL_LOG_ENTRY_TEXT_SIGNAL_SEND_ERROR, - TPL_LOG_ENTRY_TEXT_SIGNAL_LOST_MESSAGE, - TPL_LOG_ENTRY_TEXT_SIGNAL_CHAT_STATUS_CHANGED, - TPL_LOG_ENTRY_TEXT_SIGNAL_CHANNEL_CLOSED -} TplLogEntryTextSignalType; - -/* wether the log entry is referring to something outgoing on incoming */ -typedef enum { - TPL_LOG_ENTRY_TEXT_CHANNEL_IN, - TPL_LOG_ENTRY_TEXT_CHANNEL_OUT -} TplLogEntryTextDirection; - -typedef struct { - GObject parent; - - /* Private */ - - // tpl_channel has informations about channel/account/connection - TplTextChannel *tpl_text; - // what kind of signal produced this log entry - TplLogEntryTextSignalType signal_type; - TpChannelTextMessageType message_type; - // is the this entry produced by something incoming or outgoing - TplLogEntryTextDirection direction; - - // message and receiver may be NULL depending on the signal. ie. - // status changed signals set only the sender - TplContact *sender; - TplContact *receiver; - const gchar *message; - guint message_id; - const gchar *chat_id; - gboolean chatroom; -} TplLogEntryText; - -typedef struct { - GObjectClass parent_class; -} TplLogEntryTextClass; - -GType tpl_log_entry_text_get_type (void); - -TplLogEntryText *tpl_log_entry_text_new (void); - -TpChannelTextMessageType tpl_log_entry_text_message_type_from_str ( - const gchar *type_str); - -const gchar * -tpl_log_entry_text_message_type_to_str ( - TpChannelTextMessageType msg_type); - -TplChannel * -tpl_log_entry_text_get_tpl_channel (TplLogEntryText *self); - -TplTextChannel * -tpl_log_entry_text_get_tpl_text_channel (TplLogEntryText *self); - -TplContact * -tpl_log_entry_text_get_sender (TplLogEntryText *self); - -TplContact * -tpl_log_entry_text_get_receiver (TplLogEntryText *self); - -const gchar * -tpl_log_entry_text_get_message (TplLogEntryText *self); - -TpChannelTextMessageType -tpl_log_entry_text_get_message_type (TplLogEntryText *self); - -TplLogEntryTextSignalType -tpl_log_entry_text_get_signal_type (TplLogEntryText *self); - -TplLogEntryTextDirection -tpl_log_entry_text_get_direction (TplLogEntryText *self); - -guint -tpl_log_entry_text_get_message_id (TplLogEntryText *self); - -const gchar * -tpl_log_entry_text_get_chat_id (TplLogEntryText *self); - -gboolean -tpl_log_entry_text_is_chatroom (TplLogEntryText *self); - -void -tpl_log_entry_text_set_tpl_text_channel (TplLogEntryText *self, - TplTextChannel *data); - -void tpl_log_entry_text_set_sender (TplLogEntryText *self, TplContact *data); -void tpl_log_entry_text_set_receiver (TplLogEntryText *self, TplContact *data); -void tpl_log_entry_text_set_message (TplLogEntryText *self, const gchar *data); -void tpl_log_entry_text_set_message_type (TplLogEntryText *self, TpChannelTextMessageType data); -void tpl_log_entry_text_set_signal_type (TplLogEntryText *self, TplLogEntryTextSignalType data); -void tpl_log_entry_text_set_direction (TplLogEntryText *self, TplLogEntryTextDirection data); -void tpl_log_entry_text_set_message_id (TplLogEntryText *self, guint data); -void tpl_log_entry_text_set_chat_id (TplLogEntryText *self, const gchar *data); -void tpl_log_entry_text_set_chatroom (TplLogEntryText *self, gboolean data); - -G_END_DECLS - -#endif // __TPL_LOG_ENTRY_TEXT_H__ diff --git a/include/tpl-log-entry.h b/include/tpl-log-entry.h deleted file mode 100644 index 7a5a531..0000000 --- a/include/tpl-log-entry.h +++ /dev/null @@ -1,79 +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_LOG_ENTRY_H__ -#define __TPL_LOG_ENTRY_H__ - -#include - -#include - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_ENTRY (tpl_log_entry_get_type ()) -#define TPL_LOG_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_ENTRY, TplLogEntry)) -#define TPL_LOG_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_LOG_ENTRY, TplLogEntryClass)) -#define TPL_IS_LOG_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_ENTRY)) -#define TPL_IS_LOG_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_LOG_ENTRY)) -#define TPL_LOG_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_LOG_ENTRY, TplLogEntryClass)) - - -typedef enum { - TPL_LOG_ENTRY_ERROR, - TPL_LOG_ENTRY_TEXT -} TplLogEntryType; - -typedef struct { - GObject parent; - - /* Private */ - TplLogEntryType type; - union { - TplLogEntryText *text; - void* generic; - } entry; - time_t timestamp; -} TplLogEntry; - -typedef struct { - GObjectClass parent_class; -} TplLogEntryClass; - -GType tpl_log_entry_get_type (void); - -TplLogEntry *tpl_log_entry_new (void); - -TplLogEntryType -tpl_log_entry_get_entry_type(TplLogEntry *data); -void * -tpl_log_entry_get_entry(TplLogEntry *data); -time_t -tpl_log_entry_get_timestamp (TplLogEntry *self); - -// sets entry type and its object -void -tpl_log_entry_set_entry(TplLogEntry *self, void* entry); -void -tpl_log_entry_set_timestamp (TplLogEntry *self, time_t data); - -G_END_DECLS - -#endif // __TPL_LOG_ENTRY_H__ diff --git a/include/tpl-log-manager.h b/include/tpl-log-manager.h deleted file mode 100644 index a27ab23..0000000 --- a/include/tpl-log-manager.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003-2007 Imendio AB - * Copyright (C) 2007-2008 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens - */ - -#ifndef __TPL_LOG_MANAGER_H__ -#define __TPL_LOG_MANAGER_H__ - -#include - -#include - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_MANAGER (tpl_log_manager_get_type ()) -#define TPL_LOG_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TPL_TYPE_LOG_MANAGER, TplLogManager)) -#define TPL_LOG_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TPL_TYPE_LOG_MANAGER, TplLogManagerClass)) -#define TPL_IS_LOG_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TPL_TYPE_LOG_MANAGER)) -#define TPL_IS_LOG_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TPL_TYPE_LOG_MANAGER)) -#define TPL_LOG_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TPL_TYPE_LOG_MANAGER, TplLogManagerClass)) - -typedef struct -{ - GObject parent; - - gpointer priv; -} TplLogManager; - -typedef struct -{ - GObjectClass parent_class; -} TplLogManagerClass; - -typedef struct -{ - TpAccount *account; - gchar *chat_id; - gboolean is_chatroom; - gchar *filename; - gchar *date; -} TplLogSearchHit; - -typedef gboolean (*TplLogMessageFilter) (TplLogEntry *message, - gpointer user_data); - -GType tpl_log_manager_get_type (void); - -TplLogManager *tpl_log_manager_dup_singleton (void); - -gboolean tpl_log_manager_add_message (TplLogManager *manager, - const gchar *chat_id, gboolean chatroom, - TplLogEntry *message, GError **error); - -gboolean tpl_log_manager_exists (TplLogManager *manager, - TpAccount *account, const gchar *chat_id, - gboolean chatroom); - -GList *tpl_log_manager_get_dates (TplLogManager *manager, - TpAccount *account, const gchar *chat_id, - gboolean chatroom); - -GList *tpl_log_manager_get_messages_for_date (TplLogManager *manager, - TpAccount *account, const gchar *chat_id, - gboolean chatroom, const gchar *date); - -GList *tpl_log_manager_get_filtered_messages (TplLogManager *manager, - TpAccount *account, const gchar *chat_id, gboolean chatroom, - guint num_messages, TplLogMessageFilter filter, - gpointer user_data); - -GList *tpl_log_manager_get_chats (TplLogManager *manager, - TpAccount *account); - -GList *tpl_log_manager_search_new (TplLogManager *manager, - const gchar *text); - -void tpl_log_manager_search_free (GList *hits); - -gchar *tpl_log_manager_get_date_readable (const gchar *date); - -void tpl_log_manager_search_hit_free (TplLogSearchHit *hit); - -//void tpl_log_manager_observe (TplLogManager *log_manager, -// EmpathyDispatcher *dispatcher); - -G_END_DECLS - -#endif /* __TPL_LOG_MANAGER_H__ */ diff --git a/include/tpl-log-store-empathy.h b/include/tpl-log-store-empathy.h deleted file mode 100644 index 86b5e77..0000000 --- a/include/tpl-log-store-empathy.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003-2007 Imendio AB - * Copyright (C) 2007-2008 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens - * Jonny Lamb - */ - -#ifndef __TPL_LOG_STORE_EMPATHY_H__ -#define __TPL_LOG_STORE_EMPATHY_H__ - -#include - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_STORE_EMPATHY \ - (tpl_log_store_empathy_get_type ()) -#define TPL_LOG_STORE_EMPATHY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_STORE_EMPATHY, \ - TplLogStoreEmpathy)) -#define TPL_LOG_STORE_EMPATHY_CLASS(vtable) \ - (G_TYPE_CHECK_CLASS_CAST ((vtable), TPL_TYPE_LOG_STORE_EMPATHY, \ - TplLogStoreEmpathyClass)) -#define TPL_IS_LOG_STORE_EMPATHY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_STORE_EMPATHY)) -#define TPL_IS_LOG_STORE_EMPATHY_CLASS(vtable) \ - (G_TYPE_CHECK_CLASS_TYPE ((vtable), TPL_TYPE_LOG_STORE_EMPATHY)) -#define TPL_LOG_STORE_EMPATHY_GET_CLASS(inst) \ - (G_TYPE_INSTANCE_GET_CLASS ((inst), TPL_TYPE_LOG_STORE_EMPATHY, \ - TplLogStoreEmpathyClass)) - -typedef struct _TplLogStoreEmpathy TplLogStoreEmpathy; -typedef struct _TplLogStoreEmpathyClass TplLogStoreEmpathyClass; - -struct _TplLogStoreEmpathy -{ - GObject parent; - gpointer priv; -}; - -struct _TplLogStoreEmpathyClass -{ - GObjectClass parent; -}; - -GType tpl_log_store_empathy_get_type (void); - -G_END_DECLS - -#endif /* __TPL_LOG_STORE_EMPATHY_H__ */ diff --git a/include/tpl-log-store.h b/include/tpl-log-store.h deleted file mode 100644 index 5f3e81c..0000000 --- a/include/tpl-log-store.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2008 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: Jonny Lamb - */ - -#ifndef __TPL_LOG_STORE_H__ -#define __TPL_LOG_STORE_H__ - -#include -#include - -#include -#include - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_STORE (tpl_log_store_get_type ()) -#define TPL_LOG_STORE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_STORE, \ - TplLogStore)) -#define TPL_IS_LOG_STORE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_STORE)) -#define TPL_LOG_STORE_GET_INTERFACE(inst) \ - (G_TYPE_INSTANCE_GET_INTERFACE ((inst), TPL_TYPE_LOG_STORE, \ - TplLogStoreInterface)) - -typedef struct _TplLogStore TplLogStore; /* dummy object */ -typedef struct _TplLogStoreInterface TplLogStoreInterface; - -struct _TplLogStoreInterface -{ - GTypeInterface parent; - - const gchar * (*get_name) (TplLogStore *self); - gboolean (*exists) (TplLogStore *self, TpAccount *account, - const gchar *chat_id, gboolean chatroom); - gboolean (*add_message) (TplLogStore *self, const gchar *chat_id, - gboolean chatroom, TplLogEntry *message, GError **error); - GList * (*get_dates) (TplLogStore *self, TpAccount *account, - const gchar *chat_id, gboolean chatroom); - GList * (*get_messages_for_date) (TplLogStore *self, - TpAccount *account, const gchar *chat_id, gboolean chatroom, - const gchar *date); - GList * (*get_last_messages) (TplLogStore *self, TpAccount *account, - const gchar *chat_id, gboolean chatroom); - GList * (*get_chats) (TplLogStore *self, - TpAccount *account); - GList * (*search_new) (TplLogStore *self, const gchar *text); - void (*ack_message) (TplLogStore *self, const gchar *chat_id, - gboolean chatroom, TplLogEntry *message); - GList * (*get_filtered_messages) (TplLogStore *self, TpAccount *account, - const gchar *chat_id, gboolean chatroom, guint num_messages, - TplLogMessageFilter filter, gpointer user_data); -}; - -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 *chat_id, gboolean chatroom); -gboolean tpl_log_store_add_message (TplLogStore *self, - const gchar *chat_id, gboolean chatroom, TplLogEntry *message, - GError **error); -GList *tpl_log_store_get_dates (TplLogStore *self, - TpAccount *account, const gchar *chat_id, gboolean chatroom); -GList *tpl_log_store_get_messages_for_date (TplLogStore *self, - TpAccount *account, const gchar *chat_id, gboolean chatroom, - const gchar *date); -GList *tpl_log_store_get_last_messages (TplLogStore *self, - TpAccount *account, const gchar *chat_id, gboolean chatroom); -GList *tpl_log_store_get_chats (TplLogStore *self, - TpAccount *account); -GList *tpl_log_store_search_new (TplLogStore *self, - const gchar *text); -void tpl_log_store_ack_message (TplLogStore *self, - const gchar *chat_id, gboolean chatroom, TplLogEntry *message); -GList *tpl_log_store_get_filtered_messages (TplLogStore *self, - TpAccount *account, const gchar *chat_id, gboolean chatroom, - guint num_messages, TplLogMessageFilter filter, gpointer user_data); - -G_END_DECLS - -#endif /* __TPL_LOG_STORE_H__ */ diff --git a/include/tpl-observer.h b/include/tpl-observer.h deleted file mode 100644 index 06ff92d..0000000 --- a/include/tpl-observer.h +++ /dev/null @@ -1,75 +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_OBSERVER_H__ -#define __TPL_OBSERVER_H__ - -#include -#include - -#define TP_IFACE_CHAN_TEXT "org.freedesktop.Telepathy.Channel.Type.Text" -#define TPL_OBSERVER_WELL_KNOWN_BUS_NAME \ - "org.freedesktop.Telepathy.Client.HeadlessLogger" -#define TPL_OBSERVER_OBJECT_PATH \ - "/org/freedesktop/Telepathy/Client/HeadlessLogger" - - -G_BEGIN_DECLS - -#define TYPE_TPL_OBSERVER (tpl_observer_get_type ()) -#define TPL_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TPL_OBSERVER, TplObserver)) -#define TPL_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), TYPE_TPL_OBSERVER, TplObserverClass)) -#define TPL_IS_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TPL_OBSERVER)) -#define TPL_IS_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_TPL_OBSERVER)) -#define TPL_OBSERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TPL_OBSERVER, TplObserverClass)) - - - -typedef struct _TplObserver TplObserver; -struct _TplObserver -{ - GObject parent; - - /* private */ - - // mapping channel_path_str->TplChannel instances - GHashTable *channel_map; -}; - -typedef struct _TplObserverClass TplObserverClass; -struct _TplObserverClass -{ - GObjectClass parent_class; - TpDBusPropertiesMixinClass dbus_props_class; -}; - -GType tpl_observer_get_type (void); - -TplObserver *tpl_observer_new (void); - -void tpl_headless_logger_init(void); - -GHashTable *tpl_observer_get_channel_map(TplObserver *self); -void tpl_observer_set_channel_map(TplObserver *self, GHashTable *data); - -G_END_DECLS - -#endif // __TPL_OBSERVER_H__ diff --git a/include/tpl-text-channel-context.h b/include/tpl-text-channel-context.h deleted file mode 100644 index 94a1e1f..0000000 --- a/include/tpl-text-channel-context.h +++ /dev/null @@ -1,88 +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_TEXT_CHANNEL_H__ -#define __TPL_TEXT_CHANNEL_H__ - -/* - * http://telepathy.freedesktop.org/doc/telepathy-glib/telepathy-glib-channel-text.html#tp-cli-channel-type-text-connect-to-received - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -G_BEGIN_DECLS - -#define TPL_TYPE_TEXT_CHANNEL (tpl_text_channel_get_type ()) -#define TPL_TEXT_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_TEXT_CHANNEL, TplTextChannel)) -#define TPL_TEXT_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_TEXT_CHANNEL, TplTextChannelClass)) -#define TPL_IS_TEXT_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_TEXT_CHANNEL)) -#define TPL_IS_TEXT_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_TEXT_CHANNEL)) -#define TPL_TEXT_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_TEXT_CHANNEL, TplTextChannelClass)) - - -typedef struct { - GObject parent; - - /* private */ - TplChannel *tpl_channel; - gboolean chatroom; - TpContact *my_contact; - TpContact *remote_contact; // only set if chatroom==FALSE - const gchar *chatroom_id; // only set if chatroom==TRUE - - GQueue *chain; // queue of TplPendingProc - - // only used as metadata in CB data passing - guint selector; -} TplTextChannel; - -typedef struct { - GObjectClass parent_class; -} TplTextChannelClass; - -GType tpl_text_channel_get_type (void); - -TplTextChannel* tpl_text_channel_new(TplChannel* tpl_channel); - -TplChannel *tpl_text_channel_get_tpl_channel(TplTextChannel *self); -TpContact *tpl_text_channel_get_remote_contact(TplTextChannel *self); -TpContact *tpl_text_channel_get_my_contact(TplTextChannel *self); -gboolean tpl_text_channel_is_chatroom(TplTextChannel *self); -const gchar *tpl_text_channel_get_chatroom_id(TplTextChannel *self); - -void tpl_text_channel_set_tpl_channel(TplTextChannel *self, TplChannel *tpl_chan); -void tpl_text_channel_set_remote_contact(TplTextChannel *self, TpContact *data); -void tpl_text_channel_set_my_contact(TplTextChannel *self, TpContact *data); -void tpl_text_channel_set_chatroom(TplTextChannel *self, gboolean data); -void tpl_text_channel_set_chatroom_id(TplTextChannel *self, const gchar *data); - -G_END_DECLS - -#endif // __TPL_TEXT_CHANNEL_H__ diff --git a/include/tpl-time.h b/include/tpl-time.h deleted file mode 100644 index 5fc5cf3..0000000 --- a/include/tpl-time.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004 Imendio AB - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - -#ifndef __TPL_TIME_H__ -#define __TPL_TIME_H__ - -#ifndef __USE_XOPEN -#define __USE_XOPEN -#endif -#include - -#include - -G_BEGIN_DECLS - -#define TPL_TIME_FORMAT_DISPLAY_SHORT "%H:%M" -#define TPL_TIME_FORMAT_DISPLAY_LONG "%a %d %b %Y" - -time_t tpl_time_get_current (void); -time_t tpl_time_get_local_time (struct tm *tm); -time_t tpl_time_parse (const gchar *str); -gchar *tpl_time_to_string_utc (time_t t, - const gchar *format); -gchar *tpl_time_to_string_local (time_t t, - const gchar *format); -gchar *tpl_time_to_string_relative (time_t t); - -G_END_DECLS - -#endif /* __TPL_TIME_H__ */ - diff --git a/include/tpl-utils.h b/include/tpl-utils.h deleted file mode 100644 index 6eccf97..0000000 --- a/include/tpl-utils.h +++ /dev/null @@ -1,39 +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_UTILS_H__ -#define __TPL_UTILS_H__ - -#include - -#define TPL_GET_PRIV(obj,type) ((type##Priv *) ((type *) obj)->priv) -#define TPL_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0') - -/* -#define tpl_object_ref_if_not_null(obj) if (obj && G_IS_OBJECT(obj)) \ - g_object_ref(obj); -#define tpl_object_unref_if_not_null(obj) if (obj && G_IS_OBJECT(obj)) \ - g_object_unref(obj); -*/ -void tpl_object_unref_if_not_null(void* data); -void tpl_object_ref_if_not_null(void* data); - -#endif // __TPL_UTILS_H__ diff --git a/src/Makefile.am b/src/Makefile.am index be491a5..160bf97 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,14 +4,14 @@ include $(top_srcdir)/tools/flymake.mk AM_CPPFLAGS = \ $(ERROR_CFLAGS) \ -I$(top_srcdir) \ - -I$(top_srcdir)/include \ - -DG_LOG_DOMAIN=\"TPLogger\" \ + -I$(top_srcdir)/src \ + -DG_LOG_DOMAIN=\"TPLogger\" \ $(TPL_CFLAGS) \ - $(LIBTPL_CFLAGS) \ + $(LIBTPL_CFLAGS) \ $(DISABLE_DEPRECATED) \ $(WARN_CFLAGS) -LDADD = $(TPL_LIBS) \ +LDADD = $(TPL_LIBS) \ $(LIBTPL_LIBS) bin_PROGRAMS = telepathy-logger @@ -28,6 +28,7 @@ telepathy_logger_handwritten_source = \ tpl-log-entry-text.c \ tpl-contact.c \ tpl-log-manager.c \ + tpl-log-reader.c \ tpl-log-store.c \ tpl-log-store-empathy.c \ tpl-utils.c \ diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..e69de29 diff --git a/src/test.c b/src/test.c index 0042001..ac75b43 100644 --- a/src/test.c +++ b/src/test.c @@ -20,19 +20,69 @@ */ #include +#include -#include +#include +#include +#include -static GMainLoop *loop = NULL; +//static GMainLoop *loop = NULL; int main(int argc, char *argv[]) { + TplLogReader *reader; + GList *l; + TpAccount *acc; + //DBusGConnection *bus; + TpDBusDaemon *tp_bus; + GError *err=NULL; g_type_init (); - tpl_headless_logger_init (); + //tpl_headless_logger_init (); + + //bus = tp_get_bus(); + tp_bus = tp_dbus_daemon_dup(&err); + acc = tp_account_new(tp_bus, + "/org/freedesktop/Telepathy/Account/gabble/jabber/cosimo_2ealfarano_40collabora_2eco_2euk0", + &err); - loop = g_main_loop_new (NULL, FALSE); - g_main_loop_run (loop); + if(err) { + g_debug(err->message); + return 0; + } + + reader = tpl_log_reader_dup_singleton (); + + tpl_log_reader_search_new(reader, "foo"); + + + l = tpl_log_reader_get_chats(reader, acc); + int lenght = g_list_length(l); + for(int i=0;ifilename); + GList *gl; + + gl = tpl_log_reader_get_dates (reader, acc, hit->chat_id, hit->is_chatroom); + g_list_foreach (gl, (GFunc) puts, NULL); + + for(guint ii=0;iichat_id, + hit->is_chatroom, date); + for(guint m=0;m + */ + +#ifndef __TPL_CHANNEL_H__ +#define __TPL_CHANNEL_H__ + +#include +#include +#include +#include +#include +#include + +#include +#include + +G_BEGIN_DECLS + +#define TPL_TYPE_CHANNEL (tpl_channel_get_type ()) +#define TPL_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CHANNEL, TplChannel)) +#define TPL_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CHANNEL, TplChannelClass)) +#define TPL_IS_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CHANNEL)) +#define TPL_IS_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CHANNEL)) +#define TPL_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CHANNEL, TplChannelClass)) +// TODO test the following macros +//#define TPL_CHANNEL_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj), TPL_TYPE_CHANNEL, TplChannelClass)) + +typedef struct { + GObject parent; + + /* private */ + TpChannel *channel; + const gchar *channel_path; + const gchar *channel_type; + GHashTable *channel_properties; + + TpAccount *account; + const gchar *account_path; + TpConnection *connection; + const gchar *connection_path; + + TpSvcClientObserver *observer; +} TplChannel; + +typedef struct { + GObjectClass parent_class; +} TplChannelClass; + + +GType tpl_channel_get_type (void); + +TplChannel* tpl_channel_new (TpSvcClientObserver *observer); +void tpl_channel_free(TplChannel* tpl_chan); + +TpSvcClientObserver *tpl_channel_get_observer(TplChannel *self); +TpAccount *tpl_channel_get_account(TplChannel *self); +const gchar *tpl_channel_get_account_path(TplChannel *self); +TpConnection *tpl_channel_get_connection(TplChannel *self); +const gchar *tpl_channel_get_connection_path(TplChannel *self); +TpChannel *tpl_channel_get_channel(TplChannel *self); +const gchar *tpl_channel_get_channel_path(TplChannel *self); +const gchar *tpl_channel_get_channel_type(TplChannel *self); +GHashTable *tpl_channel_get_channel_properties(TplChannel *self); + + +void tpl_channel_set_observer(TplChannel *self, + TpSvcClientObserver *data); +void tpl_channel_set_account(TplChannel *self, TpAccount *data); +void tpl_channel_set_account_path(TplChannel *self, const gchar *data); +void tpl_channel_set_connection(TplChannel *self, TpConnection *data); +void tpl_channel_set_connection_path(TplChannel *self, const gchar *data); +void tpl_channel_set_channel(TplChannel *self, TpChannel *data); +void tpl_channel_set_channel_path(TplChannel *self, const gchar *data); +void tpl_channel_set_channel_type(TplChannel *self, const gchar *data); +void tpl_channel_set_channel_properties(TplChannel *self, GHashTable *data); + +gboolean tpl_channel_register_to_observer(TplChannel *self); +gboolean tpl_channel_unregister_from_observer(TplChannel *self); + +G_END_DECLS + +#endif // __TPL_CHANNEL_H__ diff --git a/src/tpl-contact.h b/src/tpl-contact.h new file mode 100644 index 0000000..1d28bbc --- /dev/null +++ b/src/tpl-contact.h @@ -0,0 +1,99 @@ +/* -*- 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_CONTACT_H__ +#define __TPL_CONTACT_H__ + +#include +#include + +G_BEGIN_DECLS + +#define TPL_TYPE_CONTACT (tpl_contact_get_type ()) +#define TPL_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CONTACT, TplContact)) +#define TPL_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CONTACT, TplContactClass)) +#define TPL_IS_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CONTACT)) +#define TPL_IS_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CONTACT)) +#define TPL_CONTACT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CONTACT, TplContactClass)) + + +typedef enum { + TPL_CONTACT_USER, + TPL_CONTACT_GROUP +} TplContactType; + +typedef struct { + GObject parent; + + /* Private */ + TpContact *contact; + TplContactType contact_type; + const gchar *alias; + const gchar *identifier; + const gchar *presence_status; + const gchar *presence_message; + + TpAccount *account; +} TplContact; + + +typedef struct { + GObjectClass parent_class; +} TplContactClass; + + +GType tpl_contact_get_type (void); + +TplContact *tpl_contact_from_tp_contact(TpContact *contact); + +TplContact *tpl_contact_new(void); + +TpContact *tpl_contact_get_contact(TplContact *self); + +const gchar *tpl_contact_get_alias(TplContact *self); + +const gchar *tpl_contact_get_identifier(TplContact *self); + +const gchar *tpl_contact_get_presence_status(TplContact *self); + +const gchar *tpl_contact_get_presence_message(TplContact *self); + +TplContactType tpl_contact_get_contact_type(TplContact *self); + +TpAccount *tpl_contact_get_account(TplContact *self); + +void tpl_contact_set_contact(TplContact *self, TpContact *data); + +void tpl_contact_set_account(TplContact *self, TpAccount *data); + +void tpl_contact_set_alias(TplContact *self, const gchar *data); + +void tpl_contact_set_identifier(TplContact *self, const gchar *data); + +void tpl_contact_set_presence_status(TplContact *self, const gchar *data); + +void tpl_contact_set_presence_message(TplContact *self, const gchar *data); + +void tpl_contact_set_contact_type(TplContact *self, TplContactType data); + +G_END_DECLS + +#endif // __TPL_CONTACT_H__ diff --git a/src/tpl-log-entry-text.h b/src/tpl-log-entry-text.h new file mode 100644 index 0000000..61c4be1 --- /dev/null +++ b/src/tpl-log-entry-text.h @@ -0,0 +1,145 @@ +/* -*- 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_LOG_ENTRY_TEXT_H__ +#define __TPL_LOG_ENTRY_TEXT_H__ + +#include +#include + +#include +#include + +G_BEGIN_DECLS + +#define TPL_TYPE_LOG_ENTRY_TEXT (tpl_log_entry_text_get_type ()) +#define TPL_LOG_ENTRY_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_ENTRY_TEXT, TplLogEntryText)) +#define TPL_LOG_ENTRY_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_LOG_ENTRY_TEXT, TplLogEntryTextClass)) +#define TPL_IS_LOG_ENTRY_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_ENTRY_TEXT)) +#define TPL_IS_LOG_ENTRY_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_LOG_ENTRY_TEXT)) +#define TPL_LOG_ENTRY_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_LOG_ENTRY_TEXT, TplLogEntryTextClass)) + + +/* Valid for org.freedesktop.Telepathy.Channel.Type.Text */ + +typedef enum { + TPL_LOG_ENTRY_TEXT_SIGNAL_SENT, + TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED, + TPL_LOG_ENTRY_TEXT_SIGNAL_SEND_ERROR, + TPL_LOG_ENTRY_TEXT_SIGNAL_LOST_MESSAGE, + TPL_LOG_ENTRY_TEXT_SIGNAL_CHAT_STATUS_CHANGED, + TPL_LOG_ENTRY_TEXT_SIGNAL_CHANNEL_CLOSED +} TplLogEntryTextSignalType; + +/* wether the log entry is referring to something outgoing on incoming */ +typedef enum { + TPL_LOG_ENTRY_TEXT_CHANNEL_IN, + TPL_LOG_ENTRY_TEXT_CHANNEL_OUT +} TplLogEntryTextDirection; + +typedef struct { + GObject parent; + + /* Private */ + + // tpl_channel has informations about channel/account/connection + TplTextChannel *tpl_text; + // what kind of signal produced this log entry + TplLogEntryTextSignalType signal_type; + TpChannelTextMessageType message_type; + // is the this entry produced by something incoming or outgoing + TplLogEntryTextDirection direction; + + // message and receiver may be NULL depending on the signal. ie. + // status changed signals set only the sender + TplContact *sender; + TplContact *receiver; + const gchar *message; + guint message_id; + const gchar *chat_id; + gboolean chatroom; +} TplLogEntryText; + +typedef struct { + GObjectClass parent_class; +} TplLogEntryTextClass; + +GType tpl_log_entry_text_get_type (void); + +TplLogEntryText *tpl_log_entry_text_new (void); + +TpChannelTextMessageType tpl_log_entry_text_message_type_from_str ( + const gchar *type_str); + +const gchar * +tpl_log_entry_text_message_type_to_str ( + TpChannelTextMessageType msg_type); + +TplChannel * +tpl_log_entry_text_get_tpl_channel (TplLogEntryText *self); + +TplTextChannel * +tpl_log_entry_text_get_tpl_text_channel (TplLogEntryText *self); + +TplContact * +tpl_log_entry_text_get_sender (TplLogEntryText *self); + +TplContact * +tpl_log_entry_text_get_receiver (TplLogEntryText *self); + +const gchar * +tpl_log_entry_text_get_message (TplLogEntryText *self); + +TpChannelTextMessageType +tpl_log_entry_text_get_message_type (TplLogEntryText *self); + +TplLogEntryTextSignalType +tpl_log_entry_text_get_signal_type (TplLogEntryText *self); + +TplLogEntryTextDirection +tpl_log_entry_text_get_direction (TplLogEntryText *self); + +guint +tpl_log_entry_text_get_message_id (TplLogEntryText *self); + +const gchar * +tpl_log_entry_text_get_chat_id (TplLogEntryText *self); + +gboolean +tpl_log_entry_text_is_chatroom (TplLogEntryText *self); + +void +tpl_log_entry_text_set_tpl_text_channel (TplLogEntryText *self, + TplTextChannel *data); + +void tpl_log_entry_text_set_sender (TplLogEntryText *self, TplContact *data); +void tpl_log_entry_text_set_receiver (TplLogEntryText *self, TplContact *data); +void tpl_log_entry_text_set_message (TplLogEntryText *self, const gchar *data); +void tpl_log_entry_text_set_message_type (TplLogEntryText *self, TpChannelTextMessageType data); +void tpl_log_entry_text_set_signal_type (TplLogEntryText *self, TplLogEntryTextSignalType data); +void tpl_log_entry_text_set_direction (TplLogEntryText *self, TplLogEntryTextDirection data); +void tpl_log_entry_text_set_message_id (TplLogEntryText *self, guint data); +void tpl_log_entry_text_set_chat_id (TplLogEntryText *self, const gchar *data); +void tpl_log_entry_text_set_chatroom (TplLogEntryText *self, gboolean data); + +G_END_DECLS + +#endif // __TPL_LOG_ENTRY_TEXT_H__ diff --git a/src/tpl-log-entry.h b/src/tpl-log-entry.h new file mode 100644 index 0000000..7a5a531 --- /dev/null +++ b/src/tpl-log-entry.h @@ -0,0 +1,79 @@ +/* -*- 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_LOG_ENTRY_H__ +#define __TPL_LOG_ENTRY_H__ + +#include + +#include + +G_BEGIN_DECLS + +#define TPL_TYPE_LOG_ENTRY (tpl_log_entry_get_type ()) +#define TPL_LOG_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_ENTRY, TplLogEntry)) +#define TPL_LOG_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_LOG_ENTRY, TplLogEntryClass)) +#define TPL_IS_LOG_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_ENTRY)) +#define TPL_IS_LOG_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_LOG_ENTRY)) +#define TPL_LOG_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_LOG_ENTRY, TplLogEntryClass)) + + +typedef enum { + TPL_LOG_ENTRY_ERROR, + TPL_LOG_ENTRY_TEXT +} TplLogEntryType; + +typedef struct { + GObject parent; + + /* Private */ + TplLogEntryType type; + union { + TplLogEntryText *text; + void* generic; + } entry; + time_t timestamp; +} TplLogEntry; + +typedef struct { + GObjectClass parent_class; +} TplLogEntryClass; + +GType tpl_log_entry_get_type (void); + +TplLogEntry *tpl_log_entry_new (void); + +TplLogEntryType +tpl_log_entry_get_entry_type(TplLogEntry *data); +void * +tpl_log_entry_get_entry(TplLogEntry *data); +time_t +tpl_log_entry_get_timestamp (TplLogEntry *self); + +// sets entry type and its object +void +tpl_log_entry_set_entry(TplLogEntry *self, void* entry); +void +tpl_log_entry_set_timestamp (TplLogEntry *self, time_t data); + +G_END_DECLS + +#endif // __TPL_LOG_ENTRY_H__ diff --git a/src/tpl-log-manager.c b/src/tpl-log-manager.c index dce5c67..7ac169b 100644 --- a/src/tpl-log-manager.c +++ b/src/tpl-log-manager.c @@ -323,6 +323,8 @@ tpl_log_manager_get_filtered_messages (TplLogManager *manager, return out; } + + GList * tpl_log_manager_get_chats (TplLogManager *manager, TpAccount *account) @@ -331,6 +333,7 @@ tpl_log_manager_get_chats (TplLogManager *manager, TplLogManagerPriv *priv; g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); + g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); priv = GET_PRIV (manager); diff --git a/src/tpl-log-manager.h b/src/tpl-log-manager.h new file mode 100644 index 0000000..a27ab23 --- /dev/null +++ b/src/tpl-log-manager.h @@ -0,0 +1,106 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * Copyright (C) 2007-2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + */ + +#ifndef __TPL_LOG_MANAGER_H__ +#define __TPL_LOG_MANAGER_H__ + +#include + +#include + +G_BEGIN_DECLS + +#define TPL_TYPE_LOG_MANAGER (tpl_log_manager_get_type ()) +#define TPL_LOG_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TPL_TYPE_LOG_MANAGER, TplLogManager)) +#define TPL_LOG_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TPL_TYPE_LOG_MANAGER, TplLogManagerClass)) +#define TPL_IS_LOG_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TPL_TYPE_LOG_MANAGER)) +#define TPL_IS_LOG_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TPL_TYPE_LOG_MANAGER)) +#define TPL_LOG_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TPL_TYPE_LOG_MANAGER, TplLogManagerClass)) + +typedef struct +{ + GObject parent; + + gpointer priv; +} TplLogManager; + +typedef struct +{ + GObjectClass parent_class; +} TplLogManagerClass; + +typedef struct +{ + TpAccount *account; + gchar *chat_id; + gboolean is_chatroom; + gchar *filename; + gchar *date; +} TplLogSearchHit; + +typedef gboolean (*TplLogMessageFilter) (TplLogEntry *message, + gpointer user_data); + +GType tpl_log_manager_get_type (void); + +TplLogManager *tpl_log_manager_dup_singleton (void); + +gboolean tpl_log_manager_add_message (TplLogManager *manager, + const gchar *chat_id, gboolean chatroom, + TplLogEntry *message, GError **error); + +gboolean tpl_log_manager_exists (TplLogManager *manager, + TpAccount *account, const gchar *chat_id, + gboolean chatroom); + +GList *tpl_log_manager_get_dates (TplLogManager *manager, + TpAccount *account, const gchar *chat_id, + gboolean chatroom); + +GList *tpl_log_manager_get_messages_for_date (TplLogManager *manager, + TpAccount *account, const gchar *chat_id, + gboolean chatroom, const gchar *date); + +GList *tpl_log_manager_get_filtered_messages (TplLogManager *manager, + TpAccount *account, const gchar *chat_id, gboolean chatroom, + guint num_messages, TplLogMessageFilter filter, + gpointer user_data); + +GList *tpl_log_manager_get_chats (TplLogManager *manager, + TpAccount *account); + +GList *tpl_log_manager_search_new (TplLogManager *manager, + const gchar *text); + +void tpl_log_manager_search_free (GList *hits); + +gchar *tpl_log_manager_get_date_readable (const gchar *date); + +void tpl_log_manager_search_hit_free (TplLogSearchHit *hit); + +//void tpl_log_manager_observe (TplLogManager *log_manager, +// EmpathyDispatcher *dispatcher); + +G_END_DECLS + +#endif /* __TPL_LOG_MANAGER_H__ */ diff --git a/src/tpl-log-reader.c b/src/tpl-log-reader.c new file mode 100644 index 0000000..2bf13bf --- /dev/null +++ b/src/tpl-log-reader.c @@ -0,0 +1,368 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * Copyright (C) 2007-2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + * Cosimo Alfarano + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +//#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +//#include + +#define DEBUG g_debug + +#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplLogReader) +typedef struct +{ + GList *stores; +} TplLogReaderPriv; + +G_DEFINE_TYPE (TplLogReader, tpl_log_reader, G_TYPE_OBJECT); + +static TplLogReader * reader_singleton = NULL; + +static void +log_reader_finalize (GObject *object) +{ + TplLogReaderPriv *priv; + + priv = GET_PRIV (object); + + g_list_foreach (priv->stores, (GFunc) g_object_unref, NULL); + g_list_free (priv->stores); +} + +/* + * - Singleton LogReader constructor - + * Initialises LogStores with LogStoreEmpathy instance + */ +static GObject * +log_reader_constructor (GType type, + guint n_props, + GObjectConstructParam *props) +{ + GObject *retval; + TplLogReaderPriv *priv; + + if (reader_singleton) + { + retval = g_object_ref (reader_singleton); + } + else + { + retval = G_OBJECT_CLASS (tpl_log_reader_parent_class)->constructor + (type, n_props, props); + + reader_singleton = TPL_LOG_READER (retval); + g_object_add_weak_pointer (retval, (gpointer *) &reader_singleton); + + priv = GET_PRIV (reader_singleton); + + priv->stores = g_list_append (priv->stores, + g_object_new (TPL_TYPE_LOG_STORE_EMPATHY, NULL)); + } + + return retval; +} + +static void +tpl_log_reader_class_init (TplLogReaderClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructor = log_reader_constructor; + object_class->finalize = log_reader_finalize; + + g_type_class_add_private (object_class, sizeof (TplLogReaderPriv)); +} + +static void +tpl_log_reader_init (TplLogReader *reader) +{ + TplLogReaderPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (reader, + TPL_TYPE_LOG_READER, TplLogReaderPriv); + + reader->priv = priv; +} + +TplLogReader * +tpl_log_reader_dup_singleton (void) +{ + return g_object_new (TPL_TYPE_LOG_READER, NULL); +} + +gboolean +tpl_log_reader_exists (TplLogReader *reader, + TpAccount *account, + const gchar *chat_id, + gboolean chatroom) +{ + GList *l; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), FALSE); + g_return_val_if_fail (chat_id != NULL, FALSE); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + if (tpl_log_store_exists (TPL_LOG_STORE (l->data), + account, chat_id, chatroom)) + return TRUE; + } + + return FALSE; +} + +// returns a list of gchar dates +GList * +tpl_log_reader_get_dates (TplLogReader *reader, + TpAccount *account, + const gchar *chat_id, + gboolean chatroom) +{ + GList *l, *out = NULL; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (chat_id != NULL, NULL); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + GList *new; + + /* Insert dates of each store in the out list. Keep the out list sorted + * and avoid to insert dups. */ + new = tpl_log_store_get_dates (store, account, chat_id, chatroom); + while (new) + { + if (g_list_find_custom (out, new->data, (GCompareFunc) strcmp)) + g_free (new->data); + else + out = g_list_insert_sorted (out, new->data, (GCompareFunc) strcmp); + + new = g_list_delete_link (new, new); + } + } + + return out; +} + +GList * +tpl_log_reader_get_messages_for_date (TplLogReader *reader, + TpAccount *account, + const gchar *chat_id, + gboolean chatroom, + const gchar *date) +{ + GList *l, *out = NULL; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (chat_id != NULL, NULL); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + + out = g_list_concat (out, tpl_log_store_get_messages_for_date ( + store, account, chat_id, chatroom, date)); + } + + return out; +} + +static gint +log_reader_message_date_cmp (gconstpointer a, + gconstpointer b) +{ + TplLogEntry *one = (TplLogEntry *) a; + TplLogEntry *two = (TplLogEntry *) b; + time_t one_time, two_time; + + one_time = tpl_log_entry_get_timestamp (one); + two_time = tpl_log_entry_get_timestamp (two); + + /* Return -1 of message1 is older than message2 */ + return one_time < two_time ? -1 : one_time - two_time; +} + +GList * +tpl_log_reader_get_filtered_messages (TplLogReader *reader, + TpAccount *account, + const gchar *chat_id, + gboolean chatroom, + guint num_messages, + TplLogMessageFilter filter, + gpointer user_data) +{ + TplLogReaderPriv *priv; + GList *out = NULL; + GList *l; + guint i = 0; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (chat_id != NULL, NULL); + + priv = GET_PRIV (reader); + + /* Get num_messages from each log store and keep only the + * newest ones in the out list. Keep that list sorted: Older first. */ + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + GList *new; + + new = tpl_log_store_get_filtered_messages (store, account, chat_id, + chatroom, num_messages, filter, user_data); + while (new) + { + if (i < num_messages) + { + /* We have less message than needed so far. Keep this message */ + out = g_list_insert_sorted (out, new->data, + (GCompareFunc) log_reader_message_date_cmp); + i++; + } + else if (log_reader_message_date_cmp (new->data, out->data) > 0) + { + /* This message is newer than the oldest message we have in out + * list. Remove the head of out list and insert this message */ + g_object_unref (out->data); + out = g_list_delete_link (out, out); + out = g_list_insert_sorted (out, new->data, + (GCompareFunc) log_reader_message_date_cmp); + } + else + { + /* This message is older than the oldest message we have in out + * list. Drop it. */ + g_object_unref (new->data); + } + + new = g_list_delete_link (new, new); + } + } + + return out; +} + +GList * +tpl_log_reader_get_chats (TplLogReader *reader, + TpAccount *account) +{ + GList *l, *out = NULL; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + + out = g_list_concat (out, + tpl_log_store_get_chats (store, account)); + } + + return out; +} + +GList * +tpl_log_reader_search_new (TplLogReader *reader, + const gchar *text) +{ + GList *l, *out = NULL; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + + out = g_list_concat (out, + tpl_log_store_search_new (store, text)); + } + + return out; +} + +void +tpl_log_reader_search_hit_free (TplLogSearchHit *hit) +{ + if (hit->account != NULL) + g_object_unref (hit->account); + + g_free (hit->date); + g_free (hit->filename); + g_free (hit->chat_id); + + g_slice_free (TplLogSearchHit, hit); +} + +void +tpl_log_reader_search_free (GList *hits) +{ + GList *l; + + for (l = hits; l; l = g_list_next (l)) + { + tpl_log_reader_search_hit_free (l->data); + } + + g_list_free (hits); +} + +/* Format is just date, 20061201. */ +gchar * +tpl_log_reader_get_date_readable (const gchar *date) +{ + time_t t; + + t = tpl_time_parse (date); + + return tpl_time_to_string_local (t, "%a %d %b %Y"); +} diff --git a/src/tpl-log-reader.h b/src/tpl-log-reader.h new file mode 100644 index 0000000..5179b37 --- /dev/null +++ b/src/tpl-log-reader.h @@ -0,0 +1,91 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * Copyright (C) 2007-2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + */ + +#ifndef __TPL_LOG_READER_H__ +#define __TPL_LOG_READER_H__ + + +#include +//TODO remove it +#include + +G_BEGIN_DECLS + +#define TPL_TYPE_LOG_READER (tpl_log_reader_get_type ()) +#define TPL_LOG_READER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TPL_TYPE_LOG_READER, TplLogReader)) +#define TPL_LOG_READER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TPL_TYPE_LOG_READER, TplLogReaderClass)) +#define TPL_IS_LOG_READER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TPL_TYPE_LOG_READER)) +#define TPL_IS_LOG_READER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TPL_TYPE_LOG_READER)) +#define TPL_LOG_READER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TPL_TYPE_LOG_READER, TplLogReaderClass)) + +typedef struct +{ + GObject parent; + + gpointer priv; +} TplLogReader; + +typedef struct +{ + GObjectClass parent_class; +} TplLogReaderClass; + +GType tpl_log_reader_get_type (void); + +TplLogReader *tpl_log_reader_dup_singleton (void); + +gboolean tpl_log_reader_exists (TplLogReader *manager, + TpAccount *account, const gchar *chat_id, + gboolean chatroom); + +GList *tpl_log_reader_get_dates (TplLogReader *manager, + TpAccount *account, const gchar *chat_id, + gboolean chatroom); + +GList *tpl_log_reader_get_messages_for_date (TplLogReader *manager, + TpAccount *account, const gchar *chat_id, + gboolean chatroom, const gchar *date); + +GList *tpl_log_reader_get_filtered_messages (TplLogReader *manager, + TpAccount *account, const gchar *chat_id, gboolean chatroom, + guint num_messages, TplLogMessageFilter filter, + gpointer user_data); + +GList *tpl_log_reader_get_chats (TplLogReader *manager, + TpAccount *account); + +GList *tpl_log_reader_search_new (TplLogReader *manager, + const gchar *text); + +void tpl_log_reader_search_free (GList *hits); + +gchar *tpl_log_reader_get_date_readable (const gchar *date); + +void tpl_log_reader_search_hit_free (TplLogSearchHit *hit); + +//void tpl_log_reader_observe (TplLogReader *log_reader, +// EmpathyDispatcher *dispatcher); + +G_END_DECLS + +#endif /* __TPL_LOG_READER_H__ */ diff --git a/src/tpl-log-store-empathy.c b/src/tpl-log-store-empathy.c index 65fd395..5ca2200 100644 --- a/src/tpl-log-store-empathy.c +++ b/src/tpl-log-store-empathy.c @@ -142,6 +142,9 @@ static gchar * log_store_account_to_dirname (TpAccount *account) { const gchar *name; + + g_return_val_if_fail(TP_IS_ACCOUNT(account), NULL); + name = tp_proxy_get_object_path (account); if (g_str_has_prefix (name, TP_ACCOUNT_OBJECT_PATH_BASE)) name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); @@ -160,6 +163,11 @@ log_store_empathy_get_dir (TplLogStore *self, gchar *escaped; TplLogStoreEmpathyPriv *priv; + g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); + g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); + // chat_id may be NULL, in order to obtain the account part of the + // path. + priv = GET_PRIV (self); escaped = log_store_account_to_dirname (account); @@ -243,7 +251,7 @@ static gboolean _log_store_empathy_write_to_store ( TplLogStore *self, } g_free (basedir); - DEBUG ("Adding log to file: '%s'", filename); + DEBUG ("Adding log to file: '%s': %s", filename, entry); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { @@ -267,6 +275,7 @@ static gboolean _log_store_empathy_write_to_store ( TplLogStore *self, return TRUE; } +/* currently unused */ static gboolean _log_store_empathy_add_message_text_status_changed ( TplLogStore *self, @@ -432,10 +441,14 @@ _log_store_empathy_add_message_text (TplLogStore *self, chat_id, chatroom, message, error); break; case TPL_LOG_ENTRY_TEXT_SIGNAL_SEND_ERROR: + g_warning("SEND_ERROR log entry not currently handled"); + return FALSE; case TPL_LOG_ENTRY_TEXT_SIGNAL_LOST_MESSAGE: + g_warning("LOST_MESSAGE log entry not currently handled"); + return FALSE; default: - g_warning("received an not handled signal type/signal type unknown"); - return FALSE; + g_warning("LogEntry's signal type unknown"); + return FALSE; } } @@ -470,6 +483,10 @@ log_store_empathy_exists (TplLogStore *self, gchar *dir; gboolean exists; + g_return_val_if_fail(TPL_IS_LOG_ENTRY (self), FALSE); + g_return_val_if_fail(TP_IS_ACCOUNT (account), FALSE); + g_return_val_if_fail(!TPL_STR_EMPTY (chat_id), FALSE); + dir = log_store_empathy_get_dir (self, account, chat_id, chatroom); exists = g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR); g_free (dir); @@ -491,9 +508,11 @@ log_store_empathy_get_dates (TplLogStore *self, const gchar *p; g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - g_return_val_if_fail (chat_id != NULL, NULL); + g_return_val_if_fail( TP_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (chat_id), NULL); directory = log_store_empathy_get_dir (self, account, chat_id, chatroom); + g_message("dir %s\n", directory); dir = g_dir_open (directory, 0, NULL); if (!dir) { @@ -540,6 +559,12 @@ log_store_empathy_get_filename_for_date (TplLogStore *self, gchar *timestamp; gchar *filename; + + g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); + g_return_val_if_fail( TP_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (chat_id), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (date), NULL); + basedir = log_store_empathy_get_dir (self, account, chat_id, chatroom); timestamp = g_strconcat (date, LOG_FILENAME_SUFFIX, NULL); filename = g_build_filename (basedir, timestamp, NULL); @@ -562,8 +587,9 @@ log_store_empathy_search_hit_new (TplLogStore *self, guint len; GList *accounts, *l; - if (!g_str_has_suffix (filename, LOG_FILENAME_SUFFIX)) - return NULL; + g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (filename), NULL); + g_return_val_if_fail (g_str_has_suffix (filename, LOG_FILENAME_SUFFIX), NULL); strv = g_strsplit (filename, G_DIR_SEPARATOR_S, -1); len = g_strv_length (strv); @@ -575,6 +601,8 @@ log_store_empathy_search_hit_new (TplLogStore *self, hit->chat_id = g_strdup (strv[len-2]); hit->is_chatroom = (strcmp (strv[len-3], LOG_DIR_CHATROOMS) == 0); + g_debug("end %s, date %s, id %s\n", end, hit->date, hit->chat_id); + if (hit->is_chatroom) account_name = strv[len-4]; else @@ -619,7 +647,7 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, xmlNodePtr node; g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (!TPL_STR_EMPTY(filename), NULL); DEBUG ("Attempting to parse filename:'%s'...", filename); @@ -844,47 +872,59 @@ log_store_empathy_search_new (TplLogStore *self, return hits; } +/* +static gboolean +log_store_empathy_is_logfile (gchar const *filename) { + gchar **path; + guint len; + g_return_val_if_fail(!TPL_STR_EMPTY(filename), FALSE); + + + path = g_strsplit (filename, G_DIR_SEPARATOR_S, -1); + len = g_strv_length (path); + + return g_regex_match_simple ( + TPL_LOG_STORE_EMPATHY_LOGFILE_REGEX, path[len-1], 0, 0); +} +*/ static GList * log_store_empathy_get_chats_for_dir (TplLogStore *self, - const gchar *dir, - gboolean is_chatroom) + const gchar *dir, gboolean is_chatroom) { - GDir *gdir; - GList *hits = NULL; - const gchar *name; - GError *error = NULL; + GDir *gdir; + GList *hits = NULL; + const gchar *name; + GError *error = NULL; + + gdir = g_dir_open (dir, 0, &error); + if (!gdir) { + DEBUG ("Failed to open directory: %s, error: %s", dir, error->message); + g_error_free (error); + return NULL; + } - gdir = g_dir_open (dir, 0, &error); - if (!gdir) - { - DEBUG ("Failed to open directory: %s, error: %s", dir, error->message); - g_error_free (error); - return NULL; - } - while ((name = g_dir_read_name (gdir)) != NULL) - { - TplLogSearchHit *hit; + while ((name = g_dir_read_name (gdir)) != NULL) { + TplLogSearchHit *hit; - if (!is_chatroom && strcmp (name, LOG_DIR_CHATROOMS) == 0) - { - gchar *filename = g_build_filename (dir, name, NULL); - hits = g_list_concat (hits, log_store_empathy_get_chats_for_dir ( - self, filename, TRUE)); - g_free (filename); - continue; - } - hit = g_slice_new0 (TplLogSearchHit); - hit->chat_id = g_strdup (name); - hit->is_chatroom = is_chatroom; + if (!is_chatroom && strcmp (name, LOG_DIR_CHATROOMS) == 0) { + gchar *filename = g_build_filename (dir, name, NULL); + hits = g_list_concat (hits, log_store_empathy_get_chats_for_dir ( + self, filename, TRUE)); + g_free (filename); + continue; + } + hit = g_slice_new0 (TplLogSearchHit); + hit->chat_id = g_strdup (name); + hit->is_chatroom = is_chatroom; - hits = g_list_prepend (hits, hit); - } + hits = g_list_prepend (hits, hit); + } - g_dir_close (gdir); + g_dir_close (gdir); - return hits; + return hits; } @@ -899,13 +939,13 @@ log_store_empathy_get_messages_for_date (TplLogStore *self, GList *messages; g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - g_return_val_if_fail (chat_id != NULL, NULL); - g_return_val_if_fail (account != NULL, NULL); + g_return_val_if_fail (TP_IS_ACCOUNT(account), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY(chat_id), NULL); filename = log_store_empathy_get_filename_for_date (self, account, - chat_id, chatroom, date); + chat_id, chatroom, date); messages = log_store_empathy_get_messages_for_file (self, account, - filename); + filename); g_free (filename); return messages; @@ -927,6 +967,15 @@ log_store_empathy_get_chats (TplLogStore *self, g_free (dir); + g_message("len: %d\n", g_list_length(hits)); + for(guint i=0; ichat_id); + g_message("hit: %s\n", hit->filename); + } + + return hits; } diff --git a/src/tpl-log-store-empathy.h b/src/tpl-log-store-empathy.h new file mode 100644 index 0000000..a0cb5ac --- /dev/null +++ b/src/tpl-log-store-empathy.h @@ -0,0 +1,68 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * Copyright (C) 2007-2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + * Jonny Lamb + */ + +#ifndef __TPL_LOG_STORE_EMPATHY_H__ +#define __TPL_LOG_STORE_EMPATHY_H__ + +#include + +G_BEGIN_DECLS + +#define TPL_LOG_STORE_EMPATHY_LOGFILE_REGEX "\\d{8}.log" + +#define TPL_TYPE_LOG_STORE_EMPATHY \ + (tpl_log_store_empathy_get_type ()) +#define TPL_LOG_STORE_EMPATHY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_STORE_EMPATHY, \ + TplLogStoreEmpathy)) +#define TPL_LOG_STORE_EMPATHY_CLASS(vtable) \ + (G_TYPE_CHECK_CLASS_CAST ((vtable), TPL_TYPE_LOG_STORE_EMPATHY, \ + TplLogStoreEmpathyClass)) +#define TPL_IS_LOG_STORE_EMPATHY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_STORE_EMPATHY)) +#define TPL_IS_LOG_STORE_EMPATHY_CLASS(vtable) \ + (G_TYPE_CHECK_CLASS_TYPE ((vtable), TPL_TYPE_LOG_STORE_EMPATHY)) +#define TPL_LOG_STORE_EMPATHY_GET_CLASS(inst) \ + (G_TYPE_INSTANCE_GET_CLASS ((inst), TPL_TYPE_LOG_STORE_EMPATHY, \ + TplLogStoreEmpathyClass)) + +typedef struct _TplLogStoreEmpathy TplLogStoreEmpathy; +typedef struct _TplLogStoreEmpathyClass TplLogStoreEmpathyClass; + +struct _TplLogStoreEmpathy +{ + GObject parent; + gpointer priv; +}; + +struct _TplLogStoreEmpathyClass +{ + GObjectClass parent; +}; + +GType tpl_log_store_empathy_get_type (void); + +G_END_DECLS + +#endif /* __TPL_LOG_STORE_EMPATHY_H__ */ diff --git a/src/tpl-log-store.c b/src/tpl-log-store.c index 7ed6a98..a3e76de 100644 --- a/src/tpl-log-store.c +++ b/src/tpl-log-store.c @@ -135,6 +135,7 @@ tpl_log_store_get_chats (TplLogStore *self, return TPL_LOG_STORE_GET_INTERFACE (self)->get_chats (self, account); } + GList * tpl_log_store_search_new (TplLogStore *self, const gchar *text) diff --git a/src/tpl-log-store.h b/src/tpl-log-store.h new file mode 100644 index 0000000..5f3e81c --- /dev/null +++ b/src/tpl-log-store.h @@ -0,0 +1,100 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Jonny Lamb + */ + +#ifndef __TPL_LOG_STORE_H__ +#define __TPL_LOG_STORE_H__ + +#include +#include + +#include +#include + +G_BEGIN_DECLS + +#define TPL_TYPE_LOG_STORE (tpl_log_store_get_type ()) +#define TPL_LOG_STORE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_STORE, \ + TplLogStore)) +#define TPL_IS_LOG_STORE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_STORE)) +#define TPL_LOG_STORE_GET_INTERFACE(inst) \ + (G_TYPE_INSTANCE_GET_INTERFACE ((inst), TPL_TYPE_LOG_STORE, \ + TplLogStoreInterface)) + +typedef struct _TplLogStore TplLogStore; /* dummy object */ +typedef struct _TplLogStoreInterface TplLogStoreInterface; + +struct _TplLogStoreInterface +{ + GTypeInterface parent; + + const gchar * (*get_name) (TplLogStore *self); + gboolean (*exists) (TplLogStore *self, TpAccount *account, + const gchar *chat_id, gboolean chatroom); + gboolean (*add_message) (TplLogStore *self, const gchar *chat_id, + gboolean chatroom, TplLogEntry *message, GError **error); + GList * (*get_dates) (TplLogStore *self, TpAccount *account, + const gchar *chat_id, gboolean chatroom); + GList * (*get_messages_for_date) (TplLogStore *self, + TpAccount *account, const gchar *chat_id, gboolean chatroom, + const gchar *date); + GList * (*get_last_messages) (TplLogStore *self, TpAccount *account, + const gchar *chat_id, gboolean chatroom); + GList * (*get_chats) (TplLogStore *self, + TpAccount *account); + GList * (*search_new) (TplLogStore *self, const gchar *text); + void (*ack_message) (TplLogStore *self, const gchar *chat_id, + gboolean chatroom, TplLogEntry *message); + GList * (*get_filtered_messages) (TplLogStore *self, TpAccount *account, + const gchar *chat_id, gboolean chatroom, guint num_messages, + TplLogMessageFilter filter, gpointer user_data); +}; + +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 *chat_id, gboolean chatroom); +gboolean tpl_log_store_add_message (TplLogStore *self, + const gchar *chat_id, gboolean chatroom, TplLogEntry *message, + GError **error); +GList *tpl_log_store_get_dates (TplLogStore *self, + TpAccount *account, const gchar *chat_id, gboolean chatroom); +GList *tpl_log_store_get_messages_for_date (TplLogStore *self, + TpAccount *account, const gchar *chat_id, gboolean chatroom, + const gchar *date); +GList *tpl_log_store_get_last_messages (TplLogStore *self, + TpAccount *account, const gchar *chat_id, gboolean chatroom); +GList *tpl_log_store_get_chats (TplLogStore *self, + TpAccount *account); +GList *tpl_log_store_search_new (TplLogStore *self, + const gchar *text); +void tpl_log_store_ack_message (TplLogStore *self, + const gchar *chat_id, gboolean chatroom, TplLogEntry *message); +GList *tpl_log_store_get_filtered_messages (TplLogStore *self, + TpAccount *account, const gchar *chat_id, gboolean chatroom, + guint num_messages, TplLogMessageFilter filter, gpointer user_data); + +G_END_DECLS + +#endif /* __TPL_LOG_STORE_H__ */ diff --git a/src/tpl-observer.h b/src/tpl-observer.h new file mode 100644 index 0000000..06ff92d --- /dev/null +++ b/src/tpl-observer.h @@ -0,0 +1,75 @@ +/* -*- 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_OBSERVER_H__ +#define __TPL_OBSERVER_H__ + +#include +#include + +#define TP_IFACE_CHAN_TEXT "org.freedesktop.Telepathy.Channel.Type.Text" +#define TPL_OBSERVER_WELL_KNOWN_BUS_NAME \ + "org.freedesktop.Telepathy.Client.HeadlessLogger" +#define TPL_OBSERVER_OBJECT_PATH \ + "/org/freedesktop/Telepathy/Client/HeadlessLogger" + + +G_BEGIN_DECLS + +#define TYPE_TPL_OBSERVER (tpl_observer_get_type ()) +#define TPL_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TPL_OBSERVER, TplObserver)) +#define TPL_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), TYPE_TPL_OBSERVER, TplObserverClass)) +#define TPL_IS_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TPL_OBSERVER)) +#define TPL_IS_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_TPL_OBSERVER)) +#define TPL_OBSERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TPL_OBSERVER, TplObserverClass)) + + + +typedef struct _TplObserver TplObserver; +struct _TplObserver +{ + GObject parent; + + /* private */ + + // mapping channel_path_str->TplChannel instances + GHashTable *channel_map; +}; + +typedef struct _TplObserverClass TplObserverClass; +struct _TplObserverClass +{ + GObjectClass parent_class; + TpDBusPropertiesMixinClass dbus_props_class; +}; + +GType tpl_observer_get_type (void); + +TplObserver *tpl_observer_new (void); + +void tpl_headless_logger_init(void); + +GHashTable *tpl_observer_get_channel_map(TplObserver *self); +void tpl_observer_set_channel_map(TplObserver *self, GHashTable *data); + +G_END_DECLS + +#endif // __TPL_OBSERVER_H__ diff --git a/src/tpl-text-channel-context.h b/src/tpl-text-channel-context.h new file mode 100644 index 0000000..94a1e1f --- /dev/null +++ b/src/tpl-text-channel-context.h @@ -0,0 +1,88 @@ +/* -*- 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_TEXT_CHANNEL_H__ +#define __TPL_TEXT_CHANNEL_H__ + +/* + * http://telepathy.freedesktop.org/doc/telepathy-glib/telepathy-glib-channel-text.html#tp-cli-channel-type-text-connect-to-received + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +G_BEGIN_DECLS + +#define TPL_TYPE_TEXT_CHANNEL (tpl_text_channel_get_type ()) +#define TPL_TEXT_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_TEXT_CHANNEL, TplTextChannel)) +#define TPL_TEXT_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_TEXT_CHANNEL, TplTextChannelClass)) +#define TPL_IS_TEXT_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_TEXT_CHANNEL)) +#define TPL_IS_TEXT_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_TEXT_CHANNEL)) +#define TPL_TEXT_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_TEXT_CHANNEL, TplTextChannelClass)) + + +typedef struct { + GObject parent; + + /* private */ + TplChannel *tpl_channel; + gboolean chatroom; + TpContact *my_contact; + TpContact *remote_contact; // only set if chatroom==FALSE + const gchar *chatroom_id; // only set if chatroom==TRUE + + GQueue *chain; // queue of TplPendingProc + + // only used as metadata in CB data passing + guint selector; +} TplTextChannel; + +typedef struct { + GObjectClass parent_class; +} TplTextChannelClass; + +GType tpl_text_channel_get_type (void); + +TplTextChannel* tpl_text_channel_new(TplChannel* tpl_channel); + +TplChannel *tpl_text_channel_get_tpl_channel(TplTextChannel *self); +TpContact *tpl_text_channel_get_remote_contact(TplTextChannel *self); +TpContact *tpl_text_channel_get_my_contact(TplTextChannel *self); +gboolean tpl_text_channel_is_chatroom(TplTextChannel *self); +const gchar *tpl_text_channel_get_chatroom_id(TplTextChannel *self); + +void tpl_text_channel_set_tpl_channel(TplTextChannel *self, TplChannel *tpl_chan); +void tpl_text_channel_set_remote_contact(TplTextChannel *self, TpContact *data); +void tpl_text_channel_set_my_contact(TplTextChannel *self, TpContact *data); +void tpl_text_channel_set_chatroom(TplTextChannel *self, gboolean data); +void tpl_text_channel_set_chatroom_id(TplTextChannel *self, const gchar *data); + +G_END_DECLS + +#endif // __TPL_TEXT_CHANNEL_H__ diff --git a/src/tpl-time.h b/src/tpl-time.h new file mode 100644 index 0000000..5fc5cf3 --- /dev/null +++ b/src/tpl-time.h @@ -0,0 +1,48 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2004 Imendio AB + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __TPL_TIME_H__ +#define __TPL_TIME_H__ + +#ifndef __USE_XOPEN +#define __USE_XOPEN +#endif +#include + +#include + +G_BEGIN_DECLS + +#define TPL_TIME_FORMAT_DISPLAY_SHORT "%H:%M" +#define TPL_TIME_FORMAT_DISPLAY_LONG "%a %d %b %Y" + +time_t tpl_time_get_current (void); +time_t tpl_time_get_local_time (struct tm *tm); +time_t tpl_time_parse (const gchar *str); +gchar *tpl_time_to_string_utc (time_t t, + const gchar *format); +gchar *tpl_time_to_string_local (time_t t, + const gchar *format); +gchar *tpl_time_to_string_relative (time_t t); + +G_END_DECLS + +#endif /* __TPL_TIME_H__ */ + diff --git a/src/tpl-utils.h b/src/tpl-utils.h new file mode 100644 index 0000000..6eccf97 --- /dev/null +++ b/src/tpl-utils.h @@ -0,0 +1,39 @@ +/* -*- 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_UTILS_H__ +#define __TPL_UTILS_H__ + +#include + +#define TPL_GET_PRIV(obj,type) ((type##Priv *) ((type *) obj)->priv) +#define TPL_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0') + +/* +#define tpl_object_ref_if_not_null(obj) if (obj && G_IS_OBJECT(obj)) \ + g_object_ref(obj); +#define tpl_object_unref_if_not_null(obj) if (obj && G_IS_OBJECT(obj)) \ + g_object_unref(obj); +*/ +void tpl_object_unref_if_not_null(void* data); +void tpl_object_ref_if_not_null(void* data); + +#endif // __TPL_UTILS_H__ -- cgit v1.2.1