diff options
-rw-r--r-- | telepathy-logger/Makefile.am | 4 | ||||
-rw-r--r-- | telepathy-logger/channel-text.c | 102 | ||||
-rw-r--r-- | telepathy-logger/channel.h | 2 | ||||
-rw-r--r-- | telepathy-logger/conf.c | 2 | ||||
-rw-r--r-- | telepathy-logger/contact.c | 71 | ||||
-rw-r--r-- | telepathy-logger/log-entry-text.c | 292 | ||||
-rw-r--r-- | telepathy-logger/log-entry-text.h | 86 | ||||
-rw-r--r-- | telepathy-logger/log-entry.c | 395 | ||||
-rw-r--r-- | telepathy-logger/log-entry.h | 60 | ||||
-rw-r--r-- | telepathy-logger/log-manager-priv.h | 4 | ||||
-rw-r--r-- | telepathy-logger/log-manager.c | 14 | ||||
-rw-r--r-- | telepathy-logger/log-store-empathy.c | 153 | ||||
-rw-r--r-- | telepathy-logger/log-store.c | 2 | ||||
-rw-r--r-- | telepathy-logger/log-store.h | 4 | ||||
-rw-r--r-- | telepathy-logger/util.c (renamed from telepathy-logger/utils.c) | 6 | ||||
-rw-r--r-- | telepathy-logger/util.h (renamed from telepathy-logger/utils.h) | 0 |
16 files changed, 737 insertions, 460 deletions
diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am index 1fdd313..79c1893 100644 --- a/telepathy-logger/Makefile.am +++ b/telepathy-logger/Makefile.am @@ -15,7 +15,7 @@ lib_LTLIBRARIES = libtelepathy-logger.la LIBTPLdir = $(includedir)/telepathy-logger LIBTPL_HEADERS = \ - utils.h \ + util.h \ contact.h \ log-entry.h \ log-entry-text.h \ @@ -35,7 +35,7 @@ libtelepathy_logger_la_SOURCES = \ log-store.c \ log-store-empathy.c \ observer.c \ - utils.c + util.c check_c_sources = \ $(libtelepathy_logger_la_SOURCES) \ diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c index acece74..933181f 100644 --- a/telepathy-logger/channel-text.c +++ b/telepathy-logger/channel-text.c @@ -101,8 +101,7 @@ _channel_on_sent_signal_cb (TpChannel * proxy, TpContact *remote, *me; TplContact *tpl_contact_sender; TplContact *tpl_contact_receiver; - TplLogEntryText *tlog; - TplLogEntry *log; + TplLogEntryText *log; TplLogManager *logmanager; gchar *chat_id; @@ -122,39 +121,36 @@ _channel_on_sent_signal_cb (TpChannel * proxy, tpl_contact_receiver = tpl_contact_from_tp_contact (remote); tpl_contact_set_contact_type (tpl_contact_receiver, TPL_CONTACT_USER); - g_message ("%s (%s): %s", + g_message ("sent: %s (%s): %s", tpl_contact_get_identifier (tpl_contact_sender), - tpl_contact_get_alias (tpl_contact_sender), arg_Text); - - /* Initialize TplLogEntryText */ - log = tpl_log_entry_new (); - tlog = tpl_log_entry_text_new (); - - tpl_log_entry_text_set_tpl_text_channel (tlog, tpl_text); - tpl_log_entry_text_set_sender (tlog, tpl_contact_sender); - tpl_log_entry_text_set_receiver (tlog, tpl_contact_receiver); - tpl_log_entry_text_set_message (tlog, arg_Text); - tpl_log_entry_text_set_message_type (tlog, arg_Type); - tpl_log_entry_text_set_signal_type (tlog, TPL_LOG_ENTRY_TEXT_SIGNAL_SENT); - tpl_log_entry_text_set_message_id (tlog, arg_Timestamp); - - tpl_log_entry_set_entry (log, tlog); - tpl_log_entry_set_timestamp (log, (time_t) arg_Timestamp); + tpl_contact_get_alias (tpl_contact_sender), + arg_Text); - /* Initialized LogStore and send the log entry */ + /* Initialise TplLogEntryText */ if (!tpl_text_channel_is_chatroom (tpl_text)) chat_id = g_strdup (tpl_contact_get_identifier (tpl_contact_receiver)); else chat_id = g_strdup (tpl_text_channel_get_chatroom_id (tpl_text)); - tpl_log_entry_text_set_chat_id (tlog, chat_id); - tpl_log_entry_text_set_chatroom (tlog, + log = tpl_log_entry_text_new (arg_Timestamp, chat_id, + TPL_LOG_ENTRY_DIRECTION_OUT); + g_free (chat_id); + + tpl_log_entry_set_timestamp (TPL_LOG_ENTRY (log), (time_t) arg_Timestamp); + tpl_log_entry_set_signal_type (TPL_LOG_ENTRY (log), TPL_LOG_ENTRY_TEXT_SIGNAL_SENT); + tpl_log_entry_set_sender (TPL_LOG_ENTRY (log), tpl_contact_sender); + tpl_log_entry_set_receiver (TPL_LOG_ENTRY (log), tpl_contact_receiver); + tpl_log_entry_text_set_message (log, arg_Text); + tpl_log_entry_text_set_message_type (log, arg_Type); + tpl_log_entry_text_set_tpl_text_channel (log, tpl_text); + + /* Initialized LogStore and send the log entry */ + tpl_log_entry_text_set_chatroom (log, tpl_text_channel_is_chatroom (tpl_text)); logmanager = tpl_log_manager_dup_singleton (); - tpl_log_manager_add_message (logmanager, - log, &error); + tpl_log_manager_add_message (logmanager, (gpointer) log, &error); if (error != NULL) { @@ -167,7 +163,6 @@ _channel_on_sent_signal_cb (TpChannel * proxy, g_object_unref (tpl_contact_sender); g_object_unref (logmanager); g_object_unref (log); - g_free (chat_id); } static void @@ -180,24 +175,22 @@ _channel_on_received_signal_with_contact_cb (TpConnection * connection, gpointer user_data, GObject * weak_object) { - TplLogEntry *log = TPL_LOG_ENTRY (user_data); - TplLogEntryText *tlog = TPL_LOG_ENTRY_TEXT (tpl_log_entry_get_entry (log)); - TplTextChannel *tpl_text = tpl_log_entry_text_get_tpl_text_channel (tlog); + TplLogEntryText *log = TPL_LOG_ENTRY_TEXT (user_data); + TplTextChannel *tpl_text = tpl_log_entry_text_get_tpl_text_channel (log); GError *e = NULL; TplLogManager *logmanager; TplContact *tpl_contact_sender; TpContact *remote; gchar *chat_id; - g_return_if_fail (TPL_IS_LOG_ENTRY (log)); - g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (tlog)); + g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (log)); if (error != NULL) { g_error ("Unrecoverable error retrieving remote contact " "information: %s", error->message); g_error ("Not able to log the received message: %s", - tpl_log_entry_text_get_message (tlog)); + tpl_log_entry_text_get_message (log)); return; } @@ -206,7 +199,7 @@ _channel_on_received_signal_with_contact_cb (TpConnection * connection, g_error ("%d invalid handle(s) passed to " "tp_connection_get_contacts_by_handle()", n_failed); g_error ("Not able to log the received message: %s", - tpl_log_entry_text_get_message (tlog)); + tpl_log_entry_text_get_message (log)); return; } @@ -215,27 +208,26 @@ _channel_on_received_signal_with_contact_cb (TpConnection * connection, tpl_contact_sender = tpl_contact_from_tp_contact (remote); tpl_contact_set_contact_type (tpl_contact_sender, TPL_CONTACT_USER); - tpl_log_entry_text_set_sender (tlog, tpl_contact_sender); + tpl_log_entry_set_sender (TPL_LOG_ENTRY (log), tpl_contact_sender); - g_message ("%s (%s): %s", + g_message ("recvd: %s (%s): %s", tpl_contact_get_identifier (tpl_contact_sender), tpl_contact_get_alias (tpl_contact_sender), - tpl_log_entry_text_get_message (tlog)); + tpl_log_entry_text_get_message (log)); - /* Initialize LogStore and store the message */ + /* Initialise LogStore and store the message */ if (!tpl_text_channel_is_chatroom (tpl_text)) chat_id = g_strdup (tpl_contact_get_identifier (tpl_contact_sender)); else chat_id = g_strdup (tpl_text_channel_get_chatroom_id (tpl_text)); - tpl_log_entry_text_set_chat_id (tlog, chat_id); - tpl_log_entry_text_set_chatroom (tlog, + tpl_log_entry_set_chat_id (TPL_LOG_ENTRY (log), chat_id); + tpl_log_entry_text_set_chatroom (log, tpl_text_channel_is_chatroom (tpl_text)); logmanager = tpl_log_manager_dup_singleton (); - tpl_log_manager_add_message (logmanager, - log, &e); + tpl_log_manager_add_message (logmanager, (gpointer) log, &e); if (e != NULL) { g_error ("LogStore: %s", e->message); @@ -263,8 +255,7 @@ _channel_on_received_signal_cb (TpChannel * proxy, TplChannel *tpl_chan = tpl_text_channel_get_tpl_channel (tpl_text); TpContact *me; TplContact *tpl_contact_receiver; - TplLogEntry *log; - TplLogEntryText *tlog; + TplLogEntryText *log; // TODO use the Message iface to check the delivery // notification and handle it correctly @@ -277,23 +268,20 @@ _channel_on_received_signal_cb (TpChannel * proxy, } /* Initialize TplLogEntryText (part 1) */ - log = tpl_log_entry_new (); - tlog = tpl_log_entry_text_new (); - tpl_log_entry_set_entry (log, tlog); + log = tpl_log_entry_text_new (arg_Timestamp, NULL, + TPL_LOG_ENTRY_DIRECTION_IN); - tpl_log_entry_text_set_tpl_text_channel (tlog, tpl_text); - tpl_log_entry_text_set_message (tlog, arg_Text); - tpl_log_entry_text_set_message_type (tlog, arg_Type); - tpl_log_entry_text_set_signal_type (tlog, - TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED); - tpl_log_entry_text_set_message_id (tlog, arg_Timestamp); //TODO set a real Id + tpl_log_entry_text_set_tpl_text_channel (log, tpl_text); + tpl_log_entry_text_set_message (log, arg_Text); + tpl_log_entry_text_set_message_type (log, arg_Type); + tpl_log_entry_set_signal_type (TPL_LOG_ENTRY (log), TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED); me = tpl_text_channel_get_my_contact (tpl_text); tpl_contact_receiver = tpl_contact_from_tp_contact (me); tpl_contact_set_contact_type (tpl_contact_receiver, TPL_CONTACT_USER); - tpl_log_entry_text_set_receiver (tlog, tpl_contact_receiver); + tpl_log_entry_set_receiver (TPL_LOG_ENTRY (log), tpl_contact_receiver); - tpl_log_entry_set_timestamp (log, (time_t) arg_Timestamp); + tpl_log_entry_set_timestamp (TPL_LOG_ENTRY (log), (time_t) arg_Timestamp); tp_connection_get_contacts_by_handle (tpl_channel_get_connection (tpl_chan), 1, &remote_handle, @@ -566,14 +554,6 @@ tpl_text_channel_class_init (TplTextChannelClass * klass) static void tpl_text_channel_init (TplTextChannel * self) { - /* Init TplTextChannel's members to zero/NULL */ - /* - tpl_text_channel_set_tpl_channel (self, NULL); - tpl_text_channel_set_my_contact (self, NULL); - tpl_text_channel_set_remote_contact (self, NULL); - tpl_text_channel_set_chatroom_id (self, NULL); - tpl_text_channel_set_chatroom (self, FALSE); - */ } TplTextChannel * diff --git a/telepathy-logger/channel.h b/telepathy-logger/channel.h index 7d0071d..6b1da88 100644 --- a/telepathy-logger/channel.h +++ b/telepathy-logger/channel.h @@ -30,7 +30,7 @@ #include <telepathy-glib/svc-client.h> #include <telepathy-logger/observer.h> -#include <telepathy-logger/utils.h> +#include <telepathy-logger/util.h> G_BEGIN_DECLS #define TPL_TYPE_CHANNEL (tpl_channel_get_type ()) diff --git a/telepathy-logger/conf.c b/telepathy-logger/conf.c index 79caca4..d9cf21f 100644 --- a/telepathy-logger/conf.c +++ b/telepathy-logger/conf.c @@ -23,7 +23,7 @@ #include <glib.h> -#include <telepathy-logger/utils.h> +#include <telepathy-logger/util.h> //#define DEBUG(...) #define GET_PRIV(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TPL_TYPE_CONF, TplConfPriv)) diff --git a/telepathy-logger/contact.c b/telepathy-logger/contact.c index 93496fd..a502c6d 100644 --- a/telepathy-logger/contact.c +++ b/telepathy-logger/contact.c @@ -23,7 +23,7 @@ #include <telepathy-glib/account.h> -#include <telepathy-logger/utils.h> +#include <telepathy-logger/util.h> G_DEFINE_TYPE (TplContact, tpl_contact, G_TYPE_OBJECT) @@ -41,6 +41,13 @@ struct _TplContactPriv TpAccount *account; }; +enum +{ + PROP0, + PROP_IDENTIFIER, + PROP_ALIAS +}; + static void tpl_contact_finalize (GObject * obj) { @@ -71,14 +78,71 @@ tpl_contact_dispose (GObject * obj) G_OBJECT_CLASS (tpl_contact_parent_class)->dispose (obj); } +static void +tpl_contact_get_prop (GObject *object, guint param_id, GValue *value, + GParamSpec *pspec) +{ + TplContactPriv *priv = GET_PRIV (object); + + switch (param_id) + { + case PROP_IDENTIFIER: + g_value_set_string (value, priv->identifier); + break; + case PROP_ALIAS: + g_value_set_string (value, priv->alias); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + + +static void +tpl_contact_set_prop (GObject *object, guint param_id, const GValue *value, + GParamSpec *pspec) +{ + TplContact *self = TPL_CONTACT (object); + + switch (param_id) { + case PROP_IDENTIFIER: + tpl_contact_set_identifier (self, g_value_get_string (value)); + break; + case PROP_ALIAS: + tpl_contact_set_alias (self, g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; + +} static void tpl_contact_class_init (TplContactClass * klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; object_class->finalize = tpl_contact_finalize; object_class->dispose = tpl_contact_dispose; + object_class->get_property = tpl_contact_get_prop; + object_class->set_property = tpl_contact_set_prop; + + param_spec = g_param_spec_string ("identifier", + "Identifier", + "The contact's identifier", + NULL, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_IDENTIFIER, param_spec); + + param_spec = g_param_spec_string ("alias", + "Alias", + "The contact's alias", + NULL, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_ALIAS, param_spec); g_type_class_add_private (object_class, sizeof (TplContactPriv)); } @@ -116,7 +180,9 @@ tpl_contact_new (const gchar *identifier) { g_return_val_if_fail (!TPL_STR_EMPTY (identifier), NULL); - return g_object_new (TPL_TYPE_CONTACT, NULL); + return g_object_new (TPL_TYPE_CONTACT, + "identifier", identifier, + NULL); } TpContact * @@ -232,7 +298,6 @@ tpl_contact_set_alias (TplContact * self, const gchar * data) TplContactPriv *priv = GET_PRIV (self); g_return_if_fail (TPL_IS_CONTACT (self)); - g_return_if_fail (!TPL_STR_EMPTY (data)); g_free (priv->alias); priv->alias = g_strdup (data); diff --git a/telepathy-logger/log-entry-text.c b/telepathy-logger/log-entry-text.c index 0d01447..92d5d97 100644 --- a/telepathy-logger/log-entry-text.c +++ b/telepathy-logger/log-entry-text.c @@ -21,37 +21,37 @@ #include "log-entry-text.h" -#include <telepathy-logger/channel.h> -#include <telepathy-logger/contact.h> -#include <telepathy-logger/utils.h> +//#include <telepathy-logger/channel.h> +#include <telepathy-logger/util.h> +#include <telepathy-logger/log-entry.h> -G_DEFINE_TYPE (TplLogEntryText, tpl_log_entry_text, G_TYPE_OBJECT) - static void tpl_log_entry_text_finalize (GObject * obj); - static void tpl_log_entry_text_dispose (GObject * obj); +G_DEFINE_TYPE (TplLogEntryText, tpl_log_entry_text, TPL_TYPE_LOG_ENTRY) - static void tpl_log_entry_text_class_init (TplLogEntryTextClass * klass) +#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplLogEntryText) +struct _TplLogEntryTextPriv { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = tpl_log_entry_text_finalize; - object_class->dispose = tpl_log_entry_text_dispose; -} + TplTextChannel *tpl_text; + TpChannelTextMessageType message_type; + gchar *message; + gboolean chatroom; +}; -static void -tpl_log_entry_text_init (TplLogEntryText * self) +enum { -} + PROP0, + PROP_MESSAGE_TYPE, + PROP_MESSAGE, + PROP_TPL_TEXT_CHANNEL +}; static void tpl_log_entry_text_dispose (GObject * obj) { TplLogEntryText *self = TPL_LOG_ENTRY_TEXT (obj); + TplLogEntryTextPriv *priv = GET_PRIV (self); - tpl_object_unref_if_not_null (self->tpl_text); - self->tpl_text = NULL; - tpl_object_unref_if_not_null (self->sender); - self->sender = NULL; - tpl_object_unref_if_not_null (self->receiver); - self->receiver = NULL; + tpl_object_unref_if_not_null (priv->tpl_text); + priv->tpl_text = NULL; G_OBJECT_CLASS (tpl_log_entry_text_parent_class)->finalize (obj); } @@ -60,22 +60,113 @@ static void tpl_log_entry_text_finalize (GObject * obj) { TplLogEntryText *self = TPL_LOG_ENTRY_TEXT (obj); + TplLogEntryTextPriv *priv = GET_PRIV (self); - g_free (self->message); - self->message = NULL; - g_free (self->chat_id); - self->chat_id = NULL; + g_free (priv->message); + priv->message = NULL; G_OBJECT_CLASS (tpl_log_entry_text_parent_class)->dispose (obj); } -TplLogEntryText * -tpl_log_entry_text_new (void) +static void +tpl_log_entry_text_get_prop (GObject *object, guint param_id, GValue *value, + GParamSpec *pspec) { - return g_object_new (TPL_TYPE_LOG_ENTRY_TEXT, NULL); + TplLogEntryTextPriv *priv = GET_PRIV (object); + + switch (param_id) + { + case PROP_MESSAGE_TYPE: + g_value_set_uint (value, priv->message_type); + break; + case PROP_MESSAGE: + g_value_set_string (value, priv->message); + break; + case PROP_TPL_TEXT_CHANNEL: + g_value_set_object (value, priv->tpl_text); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; } +static void +tpl_log_entry_text_set_prop (GObject *object, guint param_id, const GValue *value, + GParamSpec *pspec) +{ + TplLogEntryText *self = TPL_LOG_ENTRY_TEXT (object); + + switch (param_id) { + case PROP_MESSAGE_TYPE: + tpl_log_entry_text_set_message_type (self, g_value_get_uint (value)); + break; + case PROP_MESSAGE: + tpl_log_entry_text_set_message (self, g_value_get_string (value)); + break; + case PROP_TPL_TEXT_CHANNEL: + tpl_log_entry_text_set_tpl_text_channel (self, + g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; + +} + +static void tpl_log_entry_text_class_init (TplLogEntryTextClass * klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + object_class->finalize = tpl_log_entry_text_finalize; + object_class->dispose = tpl_log_entry_text_dispose; + object_class->get_property = tpl_log_entry_text_get_prop; + object_class->set_property = tpl_log_entry_text_set_prop; + + param_spec = g_param_spec_uint ("message-type", + "MessageType", + "The message type for a Text log entry", + 0, G_MAXUINT32, TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_MESSAGE_TYPE, param_spec); + + param_spec = g_param_spec_string ("message", + "Message", + "The text message of the log entry", + NULL, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_MESSAGE, param_spec); + + param_spec = g_param_spec_object ("tpl-channel-text", + "TplChannelText", + "The TplChannelText instance associated with the log entry, if any", + TPL_TYPE_TEXT_CHANNEL, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_TPL_TEXT_CHANNEL, param_spec); + + g_type_class_add_private (object_class, sizeof (TplLogEntryTextPriv)); +} + +static void +tpl_log_entry_text_init (TplLogEntryText * self) +{ + TplLogEntryTextPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + TPL_TYPE_LOG_ENTRY_TEXT, TplLogEntryTextPriv); + self->priv = priv; +} + +TplLogEntryText * +tpl_log_entry_text_new (guint log_id, const gchar *chat_id, + TplLogEntryDirection direction) +{ + return g_object_new (TPL_TYPE_LOG_ENTRY_TEXT, + "log-id", log_id, + "chat-id", chat_id, + NULL); +} TpChannelTextMessageType @@ -122,9 +213,12 @@ tpl_log_entry_text_message_type_to_str (TpChannelTextMessageType msg_type) gboolean tpl_log_entry_text_is_chatroom (TplLogEntryText * self) { + TplLogEntryTextPriv *priv; + g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), FALSE); - return self->chatroom; + priv = GET_PRIV (self); + return priv->chatroom; } TplChannel * @@ -132,164 +226,96 @@ tpl_log_entry_text_get_tpl_channel (TplLogEntryText * self) { g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), NULL); - return - tpl_text_channel_get_tpl_channel (tpl_log_entry_text_get_tpl_text_channel - (self)); + return tpl_text_channel_get_tpl_channel ( + tpl_log_entry_text_get_tpl_text_channel (self)); } TplTextChannel * tpl_log_entry_text_get_tpl_text_channel (TplLogEntryText * self) { - g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), NULL); - return self->tpl_text; -} + TplLogEntryTextPriv *priv; -TplContact * -tpl_log_entry_text_get_sender (TplLogEntryText * self) -{ g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), NULL); - return self->sender; -} -TplContact * -tpl_log_entry_text_get_receiver (TplLogEntryText * self) -{ - g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), NULL); - return self->receiver; + priv = GET_PRIV (self); + return priv->tpl_text; } + const gchar * tpl_log_entry_text_get_message (TplLogEntryText * self) { + TplLogEntryTextPriv *priv; + g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), NULL); - return self->message; + + priv = GET_PRIV (self); + return priv->message; } TpChannelTextMessageType tpl_log_entry_text_get_message_type (TplLogEntryText * self) { - return self->message_type; -} - -TplLogEntryTextSignalType -tpl_log_entry_text_get_signal_type (TplLogEntryText * self) -{ - return self->signal_type; -} - -TplLogEntryTextDirection -tpl_log_entry_text_get_direction (TplLogEntryText * self) -{ - return self->direction; -} + TplLogEntryTextPriv *priv; -guint -tpl_log_entry_text_get_message_id (TplLogEntryText * self) -{ - g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), 0); - return self->message_id; -} + /* TODO is TYPE_NORMAL the right value to return in case of error? I doubt + * :) */ + g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), + TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL); -const gchar * -tpl_log_entry_text_get_chat_id (TplLogEntryText * self) -{ - g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (self), NULL); - return self->chat_id; + priv = GET_PRIV (self); + return priv->message_type; } void tpl_log_entry_text_set_tpl_text_channel (TplLogEntryText * self, - TplTextChannel * data) + TplTextChannel * data) { - g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); - g_return_if_fail (TPL_IS_TEXT_CHANNEL (data) || data == NULL); + TplLogEntryTextPriv *priv; - tpl_object_unref_if_not_null (self->tpl_text); - self->tpl_text = data; - tpl_object_ref_if_not_null (data); -} - -void -tpl_log_entry_text_set_sender (TplLogEntryText * self, TplContact * data) -{ g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); - g_return_if_fail (TPL_IS_CONTACT (data) || data == NULL); + g_return_if_fail (TPL_IS_TEXT_CHANNEL (data) || data == NULL); - tpl_object_unref_if_not_null (self->sender); - self->sender = data; + priv = GET_PRIV (self); + tpl_object_unref_if_not_null (priv->tpl_text); + priv->tpl_text = data; tpl_object_ref_if_not_null (data); } void -tpl_log_entry_text_set_receiver (TplLogEntryText * self, TplContact * data) +tpl_log_entry_text_set_message (TplLogEntryText *self, const gchar *data) { - g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); - g_return_if_fail (TPL_IS_CONTACT (data) || data == NULL); + TplLogEntryTextPriv *priv; - tpl_object_unref_if_not_null (self->receiver); - self->receiver = data; - tpl_object_ref_if_not_null (data); -} - -void -tpl_log_entry_text_set_message (TplLogEntryText * self, const gchar * data) -{ g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); - g_free (self->message); - self->message = g_strdup (data); + priv = GET_PRIV (self); + g_free (priv->message); + priv->message = g_strdup (data); } void tpl_log_entry_text_set_message_type (TplLogEntryText * self, - TpChannelTextMessageType data) + TpChannelTextMessageType data) { - g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); + TplLogEntryTextPriv *priv; - self->message_type = data; -} - -void -tpl_log_entry_text_set_signal_type (TplLogEntryText * self, - TplLogEntryTextSignalType data) -{ g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); - self->signal_type = data; -} + priv = GET_PRIV (self); -void -tpl_log_entry_text_set_direction (TplLogEntryText * self, - TplLogEntryTextDirection data) -{ - g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); - - self->direction = data; + priv->message_type = data; } void -tpl_log_entry_text_set_message_id (TplLogEntryText * self, guint data) +tpl_log_entry_text_set_chatroom (TplLogEntryText * self, gboolean data) { - g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); + TplLogEntryTextPriv *priv; - self->message_id = data; -} - -void -tpl_log_entry_text_set_chat_id (TplLogEntryText * self, const gchar * data) -{ g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); - g_free (self->chat_id); - self->chat_id = g_strdup (data); -} - - -void -tpl_log_entry_text_set_chatroom (TplLogEntryText * self, gboolean data) -{ - g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); + priv = GET_PRIV (self); - self->chatroom = data; + priv->chatroom = data; } diff --git a/telepathy-logger/log-entry-text.h b/telepathy-logger/log-entry-text.h index 7b5d547..a301395 100644 --- a/telepathy-logger/log-entry-text.h +++ b/telepathy-logger/log-entry-text.h @@ -27,6 +27,7 @@ #include <telepathy-logger/channel-text.h> #include <telepathy-logger/contact.h> +#include <telepathy-logger/log-entry.h> G_BEGIN_DECLS #define TPL_TYPE_LOG_ENTRY_TEXT (tpl_log_entry_text_get_type ()) @@ -35,67 +36,49 @@ G_BEGIN_DECLS #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 + +typedef enum { + TPL_LOG_ENTRY_TEXT_SIGNAL_NONE = 0, 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 + TPL_LOG_ENTRY_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 _TplLogEntryTextPriv TplLogEntryTextPriv; typedef struct { - GObject parent; + TplLogEntry 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; - gchar *message; - guint message_id; - gchar *chat_id; - gboolean chatroom; + TplLogEntryTextPriv *priv; } TplLogEntryText; typedef struct { - GObjectClass parent_class; + TplLogEntryClass parent_class; } TplLogEntryTextClass; GType tpl_log_entry_text_get_type (void); -TplLogEntryText *tpl_log_entry_text_new (void); +TplLogEntryText *tpl_log_entry_text_new (guint log_id, const gchar *chat_id, + TplLogEntryDirection direction); -TpChannelTextMessageType tpl_log_entry_text_message_type_from_str (const gchar - * type_str); +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); +const gchar *tpl_log_entry_text_message_type_to_str ( + TpChannelTextMessageType msg_type); -TplChannel *tpl_log_entry_text_get_tpl_channel (TplLogEntryText * self); +TplChannel *tpl_log_entry_text_get_tpl_channel (TplLogEntryText *self); -TplTextChannel *tpl_log_entry_text_get_tpl_text_channel (TplLogEntryText * - self); +TplTextChannel *tpl_log_entry_text_get_tpl_text_channel ( + TplLogEntryText *self); TplContact *tpl_log_entry_text_get_sender (TplLogEntryText * self); @@ -103,40 +86,25 @@ 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); +TpChannelTextMessageType tpl_log_entry_text_get_message_type (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_tpl_text_channel (TplLogEntryText * self, + TplTextChannel * data); void tpl_log_entry_text_set_sender (TplLogEntryText * self, - TplContact * data); + TplContact * data); void tpl_log_entry_text_set_receiver (TplLogEntryText * self, - TplContact * data); + TplContact * data); void tpl_log_entry_text_set_message (TplLogEntryText * self, - const gchar * data); + 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); + TpChannelTextMessageType data); void tpl_log_entry_text_set_chat_id (TplLogEntryText * self, - const gchar * data); + const gchar * data); void tpl_log_entry_text_set_chatroom (TplLogEntryText * self, gboolean data); G_END_DECLS diff --git a/telepathy-logger/log-entry.c b/telepathy-logger/log-entry.c index b5b9f48..1ce7cc7 100644 --- a/telepathy-logger/log-entry.c +++ b/telepathy-logger/log-entry.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2009 Collabora Ltd. * @@ -24,11 +23,49 @@ #include <glib.h> #include <telepathy-glib/util.h> +#include <telepathy-logger/contact.h> #include <telepathy-logger/debug.h> +#include <telepathy-logger/util.h> G_DEFINE_TYPE (TplLogEntry, tpl_log_entry, G_TYPE_OBJECT) - static void tpl_log_entry_finalize (GObject * obj) + +static void _set_log_id (TplLogEntry * self, guint data); + +#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplLogEntry) +struct _TplLogEntryPriv +{ + guint log_id; + time_t timestamp; + TplLogEntrySignalType signal_type; + gchar *chat_id; + + /* incoming/outgoing */ + TplLogEntryDirection direction; + + /* message and receiver may be NULL depending on the signal. ie. status + * changed signals set only the sender */ + TplContact *sender; + TplContact *receiver; +}; + +enum { + PROP0, + PROP_TIMESTAMP, + PROP_SIGNAL_TYPE, + PROP_LOG_ID, + PROP_DIRECTION, + PROP_CHAT_ID, + PROP_SENDER, + PROP_RECEIVER +}; + +static void tpl_log_entry_finalize (GObject * obj) { + TplLogEntryPriv *priv = GET_PRIV (obj); + + g_free (priv->chat_id); + priv->chat_id = NULL; + G_OBJECT_CLASS (tpl_log_entry_parent_class)->finalize (obj); } @@ -36,114 +73,354 @@ static void tpl_log_entry_dispose (GObject * obj) { TplLogEntry *self = TPL_LOG_ENTRY (obj); + TplLogEntryPriv *priv = GET_PRIV (self); - tpl_object_unref_if_not_null (tpl_log_entry_get_entry (self)); - self->entry.generic = NULL; + tpl_object_unref_if_not_null (priv->sender); + priv->sender = NULL; + tpl_object_unref_if_not_null (priv->receiver); + priv->receiver = NULL; G_OBJECT_CLASS (tpl_log_entry_parent_class)->dispose (obj); } +static void +tpl_log_entry_get_prop (GObject *object, guint param_id, GValue *value, + GParamSpec *pspec) +{ + TplLogEntryPriv *priv = GET_PRIV (object); + + switch (param_id) + { + case PROP_TIMESTAMP: + g_value_set_uint (value, priv->timestamp); + break; + case PROP_SIGNAL_TYPE: + g_value_set_uint (value, priv->signal_type); + break; + case PROP_LOG_ID: + g_value_set_uint (value, priv->log_id); + break; + case PROP_DIRECTION: + g_value_set_uint (value, priv->direction); + break; + case PROP_CHAT_ID: + g_value_set_string (value, priv->chat_id); + break; + case PROP_SENDER: + g_value_set_object (value, priv->sender); + break; + case PROP_RECEIVER: + g_value_set_object (value, priv->receiver); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +tpl_log_entry_set_prop (GObject *object, guint param_id, const GValue *value, + GParamSpec *pspec) +{ + TplLogEntry *self = TPL_LOG_ENTRY (object); + + switch (param_id) { + case PROP_TIMESTAMP: + tpl_log_entry_set_timestamp (self, g_value_get_uint (value)); + break; + case PROP_SIGNAL_TYPE: + tpl_log_entry_set_signal_type (self, g_value_get_uint (value)); + break; + case PROP_LOG_ID: + _set_log_id (self, g_value_get_uint (value)); + break; + case PROP_DIRECTION: + tpl_log_entry_set_direction (self, g_value_get_uint (value)); + break; + case PROP_CHAT_ID: + tpl_log_entry_set_chat_id (self, g_value_get_string (value)); + break; + case PROP_SENDER: + tpl_log_entry_set_sender (self, g_value_get_object (value)); + break; + case PROP_RECEIVER: + tpl_log_entry_set_receiver (self, g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + static void tpl_log_entry_class_init (TplLogEntryClass * klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *param_spec; + + object_class->get_property = tpl_log_entry_get_prop; + object_class->set_property = tpl_log_entry_set_prop; object_class->finalize = tpl_log_entry_finalize; object_class->dispose = tpl_log_entry_dispose; + + param_spec = g_param_spec_uint ("timestamp", + "Timestamp", + "The timestamp (time_t) for the log entry", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_TIMESTAMP, param_spec); + + param_spec = g_param_spec_uint ("signal-type", + "SignalType", + "The signal type which caused the log entry", + 0, G_MAXUINT32, TPL_LOG_ENTRY_SIGNAL_NONE, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_SIGNAL_TYPE, param_spec); + + param_spec = g_param_spec_uint ("log-id", + "LogId", + "Log identification number: the triple LogId+AccountName+ChatId is unique", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_LOG_ID, param_spec); + + param_spec = g_param_spec_uint ("direction", + "Direction", + "The direction of the log entry (in/out)", + 0, G_MAXUINT32, TPL_LOG_ENTRY_DIRECTION_NONE, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_DIRECTION, param_spec); + + param_spec = g_param_spec_string ("chat-id", + "ChatId", + "The chat id relative to the log entry's account name", + NULL, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_CHAT_ID, param_spec); + + param_spec = g_param_spec_object ("sender", + "Sender", + "TplContact instance who originated the log entry", + TPL_TYPE_CONTACT, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_SENDER, param_spec); + + param_spec = g_param_spec_object ("receiver", + "Receiver", + "TplContact instance destination for the log entry", + TPL_TYPE_CONTACT, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_RECEIVER, param_spec); + + g_type_class_add_private (object_class, sizeof (TplLogEntryPriv)); } static void tpl_log_entry_init (TplLogEntry * self) { + TplLogEntryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + TPL_TYPE_LOG_ENTRY, TplLogEntryPriv); + self->priv = priv; +} + +TplLogEntry * +tpl_log_entry_new (guint log_id, const gchar *chat_id, + TplLogEntryDirection direction) +{ + return g_object_new (TPL_TYPE_LOG_ENTRY, + "log-id", log_id, + "chat-id", chat_id, + "direction", direction, + NULL); +} + +time_t +tpl_log_entry_get_timestamp (TplLogEntry * self) +{ + TplLogEntryPriv *priv = GET_PRIV (self); + + g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), -1); + + priv = GET_PRIV (self); + return priv->timestamp; +} + +TplLogEntrySignalType +tpl_log_entry_get_signal_type (TplLogEntry * self) +{ + TplLogEntryPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), + TPL_LOG_ENTRY_SIGNAL_NONE); + + priv = GET_PRIV (self); + return priv->signal_type; +} + +guint +tpl_log_entry_get_log_id (TplLogEntry * self) +{ + TplLogEntryPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), 0); + + priv = GET_PRIV (self); + return priv->log_id; +} + +TplLogEntryDirection +tpl_log_entry_get_direction (TplLogEntry * self) +{ + TplLogEntryPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), + TPL_LOG_ENTRY_DIRECTION_NONE); + + priv = GET_PRIV (self); + return priv->direction; +} + +TplContact * +tpl_log_entry_get_sender (TplLogEntry * self) +{ + TplLogEntryPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), NULL); + + priv = GET_PRIV (self); + return priv->sender; } +TplContact * +tpl_log_entry_get_receiver (TplLogEntry * self) +{ + TplLogEntryPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), NULL); + + priv = GET_PRIV (self); + return priv->receiver; +} +const gchar * +tpl_log_entry_get_chat_id (TplLogEntry * self) +{ + TplLogEntryPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), NULL); + + priv = GET_PRIV (self); + return priv->chat_id; +} void -tpl_log_entry_set_entry (TplLogEntry * self, void *entry) +tpl_log_entry_set_timestamp (TplLogEntry * self, time_t data) { + TplLogEntryPriv *priv = GET_PRIV (self); + g_return_if_fail (TPL_IS_LOG_ENTRY (self)); - g_return_if_fail (self->entry.generic == NULL); - if (TPL_IS_LOG_ENTRY_TEXT (entry)) - { - self->type = TPL_LOG_ENTRY_TEXT; - self->entry.text = entry; - } - else - { - g_error ("TplLogEntry does handle only Text channels"); - } + priv = GET_PRIV (self); + priv->timestamp = data; + g_object_notify (G_OBJECT(self), "timestamp"); } -TplLogEntryType -tpl_log_entry_get_entry_type (TplLogEntry * self) +void +tpl_log_entry_set_signal_type (TplLogEntry * self, + TplLogEntrySignalType data) { - g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), TPL_LOG_ENTRY_ERROR); + TplLogEntryPriv *priv; - return self->type; + g_return_if_fail (TPL_IS_LOG_ENTRY (self)); + + priv = GET_PRIV (self); + priv->signal_type = data; + g_object_notify (G_OBJECT(self), "signal-type"); } -void * -tpl_log_entry_get_entry (TplLogEntry * self) +static void +_set_log_id (TplLogEntry * self, guint data) { - g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), NULL); + TplLogEntryPriv *priv; - switch (self->type) - { - case TPL_LOG_ENTRY_TEXT: - if (!TPL_IS_LOG_ENTRY_TEXT (self->entry.text)) - { - g_error ("TplLogEntry->entry->text not a TplLogEntryText instance"); - return NULL; - } - return self->entry.text; - break; - default: - g_warning ("TplLogEntry type not handled\n"); - return NULL; - break; - } + g_return_if_fail (TPL_IS_LOG_ENTRY (self)); + + priv = GET_PRIV (self); + priv->log_id = data; + g_object_notify (G_OBJECT(self), "log-id"); } -TplLogEntry * -tpl_log_entry_new (void) +void +tpl_log_entry_set_direction (TplLogEntry * self, + TplLogEntryDirection data) { - return g_object_new (TPL_TYPE_LOG_ENTRY, NULL); + TplLogEntryPriv *priv; + + g_return_if_fail (TPL_IS_LOG_ENTRY (self)); + + priv = GET_PRIV (self); + priv->direction = data; + g_object_notify (G_OBJECT(self), "direction"); } +void +tpl_log_entry_set_sender (TplLogEntry * self, TplContact * data) +{ + TplLogEntryPriv *priv; -time_t -tpl_log_entry_get_timestamp (TplLogEntry * self) + g_return_if_fail (TPL_IS_LOG_ENTRY (self)); + g_return_if_fail (TPL_IS_CONTACT (data) || data == NULL); + + priv = GET_PRIV (self); + + tpl_object_unref_if_not_null (priv->sender); + priv->sender = data; + tpl_object_ref_if_not_null (data); + g_object_notify (G_OBJECT(self), "sender"); +} + +void +tpl_log_entry_set_receiver (TplLogEntry * self, TplContact * data) { - g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), -1); - return self->timestamp; + TplLogEntryPriv *priv; + + g_return_if_fail (TPL_IS_LOG_ENTRY (self)); + g_return_if_fail (TPL_IS_CONTACT (data) || data == NULL); + + priv = GET_PRIV (self); + tpl_object_unref_if_not_null (priv->receiver); + priv->receiver = data; + tpl_object_ref_if_not_null (data); + g_object_notify (G_OBJECT(self), "receiver"); } void -tpl_log_entry_set_timestamp (TplLogEntry * self, time_t data) +tpl_log_entry_set_chat_id (TplLogEntry * self, const gchar * data) { + TplLogEntryPriv *priv; + g_return_if_fail (TPL_IS_LOG_ENTRY (self)); - self->timestamp = data; + priv = GET_PRIV (self); + g_free (priv->chat_id); + priv->chat_id = g_strdup (data); } gboolean tpl_log_entry_equal (TplLogEntry *message1, TplLogEntry *message2) { - //TplLogEntryPriv *priv1; - //TplLogEntryPriv *priv2; - - g_return_val_if_fail (TPL_IS_LOG_ENTRY (message1), FALSE); - g_return_val_if_fail (TPL_IS_LOG_ENTRY (message2), FALSE); + TplLogEntryPriv *priv1 = GET_PRIV (message1); + TplLogEntryPriv *priv2 = GET_PRIV (message2); - //priv1 = GET_PRIV (message1); - //priv2 = GET_PRIV (message2); + g_return_val_if_fail (TPL_IS_LOG_ENTRY (message1), FALSE); + g_return_val_if_fail (TPL_IS_LOG_ENTRY (message2), FALSE); - //if (priv1->id == priv2->id && !tp_strdiff (priv1->body, priv2->body)) { - if (message1->type == message2->type) - if (!tp_strdiff (message1->entry.text->message, message2->entry.text->message)) { - return TRUE; - } + //if (priv1->id == priv2->id && !tp_strdiff (priv1->body, priv2->body)) { + //if (priv1->type == priv2->type) + //if (!tp_strdiff (priv1->entry.text->message, priv2->entry.text->message)) { + //} + g_debug ("TODO: tpl_log_entry_equal update!"); + return priv1->log_id == priv2->log_id; - return FALSE; + return FALSE; } diff --git a/telepathy-logger/log-entry.h b/telepathy-logger/log-entry.h index 8f9f5f3..df74eeb 100644 --- a/telepathy-logger/log-entry.h +++ b/telepathy-logger/log-entry.h @@ -24,7 +24,7 @@ #include <glib-object.h> -#include <telepathy-logger/log-entry-text.h> +#include <telepathy-logger/contact.h> G_BEGIN_DECLS #define TPL_TYPE_LOG_ENTRY (tpl_log_entry_get_type ()) @@ -33,24 +33,43 @@ G_BEGIN_DECLS #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 + +typedef enum +{ + TPL_LOG_ENTRY_DIRECTION_NONE = 0, + + TPL_LOG_ENTRY_DIRECTION_IN, + TPL_LOG_ENTRY_DIRECTION_OUT +} TplLogEntryDirection; + +typedef enum +{ + TPL_LOG_ENTRY_SIGNAL_NONE = 0, + + TPL_LOG_ENTRY_CHANNEL_TEXT_SIGNAL_SENT, + TPL_LOG_ENTRY_CHANNEL_TEXT_SIGNAL_RECEIVED, + TPL_LOG_ENTRY_CHANNEL_TEXT_SIGNAL_SEND_ERROR, + TPL_LOG_ENTRY_CHANELL_TEXT_SIGNAL_LOST_MESSAGE, + TPL_LOG_ENTRY_CHANNEL_TEXT_SIGNAL_CHAT_STATUS_CHANGED, + + TPL_LOG_ENTRY_CHANNEL_SIGNAL_CHANNEL_CLOSED + +} TplLogEntrySignalType; + +typedef enum { TPL_LOG_ENTRY_ERROR, TPL_LOG_ENTRY_TEXT } TplLogEntryType; +typedef struct _TplLogEntryPriv TplLogEntryPriv; + typedef struct { GObject parent; /* Private */ - TplLogEntryType type; - union - { - TplLogEntryText *text; - void *generic; - } entry; - time_t timestamp; + TplLogEntryPriv *priv; } TplLogEntry; typedef struct @@ -59,19 +78,28 @@ typedef struct } TplLogEntryClass; GType tpl_log_entry_get_type (void); +TplLogEntry *tpl_log_entry_new (guint log_id, const gchar *chat_id, + TplLogEntryDirection direction); -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); +TplLogEntrySignalType tpl_log_entry_get_signal_type (TplLogEntry * self); +guint tpl_log_entry_get_log_id (TplLogEntry *self); +const gchar *tpl_log_entry_get_chat_id (TplLogEntry * self); + +TplLogEntryDirection tpl_log_entry_get_direction (TplLogEntry * self); +TplContact *tpl_log_entry_get_sender (TplLogEntry * self); +TplContact *tpl_log_entry_get_receiver (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); +void tpl_log_entry_set_signal_type (TplLogEntry *self, + TplLogEntrySignalType data); +void tpl_log_entry_set_direction (TplLogEntry * self, + TplLogEntryDirection data); +void tpl_log_entry_set_chat_id (TplLogEntry * self, const gchar * data); +void tpl_log_entry_set_sender (TplLogEntry * self, TplContact * data); +void tpl_log_entry_set_receiver (TplLogEntry * self, TplContact * data); gboolean tpl_log_entry_equal (TplLogEntry *message1, TplLogEntry *message2); - G_END_DECLS #endif // __TPL_LOG_ENTRY_H__ diff --git a/telepathy-logger/log-manager-priv.h b/telepathy-logger/log-manager-priv.h index a8ed7b9..5611e4d 100644 --- a/telepathy-logger/log-manager-priv.h +++ b/telepathy-logger/log-manager-priv.h @@ -27,10 +27,10 @@ #include <telepathy-logger/log-manager.h> gboolean tpl_log_manager_add_message (TplLogManager * manager, - TplLogEntry * message, GError ** error); + gpointer message, GError ** error); void tpl_log_manager_add_message_async (TplLogManager * manager, - TplLogEntry * message, + gpointer message, TplLogManagerAsyncCallback callback, gpointer user_data, GDestroyNotify destroy); diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c index e00aea4..5b47dbf 100644 --- a/telepathy-logger/log-manager.c +++ b/telepathy-logger/log-manager.c @@ -38,7 +38,7 @@ #include <telepathy-logger/log-store.h> #include <telepathy-logger/log-store-empathy.h> #include <telepathy-logger/datetime.h> -#include <telepathy-logger/utils.h> +#include <telepathy-logger/util.h> //#define DEBUG_FLAG EMPATHY_DEBUG_OTHER //#include <empathy-debug.h> @@ -74,7 +74,7 @@ typedef struct TplLogMessageFilter filter; gchar *search_text; gpointer user_data; - TplLogEntry *logentry; + gpointer logentry; } TplLogManagerChatInfo; @@ -164,10 +164,12 @@ tpl_log_manager_dup_singleton (void) return g_object_new (TPL_TYPE_LOG_MANAGER, NULL); } - +/* + * @message: a TplLogEntry subclass + */ gboolean tpl_log_manager_add_message (TplLogManager * manager, - TplLogEntry * message, GError ** error) + gpointer message, GError ** error) { TplLogManagerPriv *priv; GList *l; @@ -593,7 +595,7 @@ _add_message_async_thread (GSimpleAsyncResult * simple, GObject * object, void tpl_log_manager_add_message_async (TplLogManager * manager, - TplLogEntry * message, + gpointer message, TplLogManagerAsyncCallback callback, gpointer user_data, GDestroyNotify destroy) @@ -634,7 +636,7 @@ tpl_log_manager_add_message_async (TplLogManager * manager, async_data->user_data = user_data; _tpl_log_manager_call_async_operation (manager, _add_message_async_thread, - async_data, callback); + async_data, callback); } /* End of get_dates async implementation */ diff --git a/telepathy-logger/log-store-empathy.c b/telepathy-logger/log-store-empathy.c index 7b4c714..b6a604a 100644 --- a/telepathy-logger/log-store-empathy.c +++ b/telepathy-logger/log-store-empathy.c @@ -270,74 +270,9 @@ _log_store_empathy_write_to_store (TplLogStore * self, return TRUE; } -/* currently unused */ -static gboolean -_log_store_empathy_add_message_text_status_changed (TplLogStore * self, - TplLogEntry * message, - GError ** error) -{ - TpAccount *account; - TplContact *sender; - const gchar *str; - gchar *timestamp; - gchar *contact_name; - gchar *contact_id; - gchar *contact_status; - gchar *contact_presence; - gchar *entry; - gboolean ret = FALSE; - TplLogEntryText *tmessage; - const gchar *chat_id; - gboolean chatroom; - - tmessage = tpl_log_entry_get_entry (message); - chat_id = tpl_log_entry_text_get_chat_id(tmessage); - chatroom = tpl_log_entry_text_is_chatroom(tmessage); - sender = tpl_log_entry_text_get_sender (tmessage); - account = - tpl_channel_get_account (tpl_log_entry_text_get_tpl_channel (tmessage)); - - timestamp = log_store_empathy_get_timestamp_from_message (message); - - str = tpl_contact_get_alias (sender); - contact_name = g_markup_escape_text (str, -1); - - str = tpl_contact_get_identifier (sender); - contact_id = g_markup_escape_text (str, -1); - - str = tpl_contact_get_presence_status (sender); - contact_presence = g_markup_escape_text (str, -1); - - str = tpl_contact_get_presence_message (sender); - contact_status = g_markup_escape_text (str, -1); - - entry = - g_strdup_printf ("<statusUpdate time='%s' id='%s' name='%s' isuser='%s'" - "presence='%s' status='%s'/>\n" LOG_FOOTER, timestamp, - contact_id, contact_name, - tpl_contact_get_contact_type (sender) == - TPL_CONTACT_USER ? "true" : "false", contact_presence, - contact_status); - - - ret = _log_store_empathy_write_to_store (self, - account, chat_id, chatroom, entry, - error); - - g_free (contact_id); - g_free (contact_name); - g_free (contact_presence); - g_free (contact_status); - g_free (timestamp); - g_free (entry); - - return ret; -} - - static gboolean _log_store_empathy_add_message_text_chat (TplLogStore * self, - TplLogEntry * message, + TplLogEntryText *message, GError ** error) { gboolean ret; @@ -355,24 +290,23 @@ _log_store_empathy_add_message_text_chat (TplLogStore * self, const gchar *chat_id; gboolean chatroom; TpChannelTextMessageType msg_type; - TplLogEntryText *tmessage; - tmessage = tpl_log_entry_get_entry (message); - chat_id = tpl_log_entry_text_get_chat_id(tmessage); - chatroom = tpl_log_entry_text_is_chatroom(tmessage); + chat_id = tpl_log_entry_get_chat_id(TPL_LOG_ENTRY (message)); + chatroom = tpl_log_entry_text_is_chatroom(message); - sender = tpl_log_entry_text_get_sender (tmessage); + sender = tpl_log_entry_get_sender (TPL_LOG_ENTRY (message)); account = - tpl_channel_get_account (tpl_log_entry_text_get_tpl_channel (tmessage)); - body_str = tpl_log_entry_text_get_message (tmessage); - msg_type = tpl_log_entry_text_get_message_type (tmessage); + tpl_channel_get_account (tpl_log_entry_text_get_tpl_channel (message)); + body_str = tpl_log_entry_text_get_message (message); + msg_type = tpl_log_entry_text_get_message_type (message); if (TPL_STR_EMPTY (body_str)) return FALSE; body = g_markup_escape_text (body_str, -1); - timestamp = log_store_empathy_get_timestamp_from_message (message); + timestamp = log_store_empathy_get_timestamp_from_message ( + TPL_LOG_ENTRY (message)); str = tpl_contact_get_alias (sender); contact_name = g_markup_escape_text (str, -1); @@ -388,7 +322,7 @@ _log_store_empathy_add_message_text_chat (TplLogStore * self, entry = g_strdup_printf ("<message time='%s' cm_id='%d' id='%s' name='%s' " "token='%s' isuser='%s' type='%s'>" "%s</message>\n" LOG_FOOTER, timestamp, - tpl_log_entry_text_get_message_id (tmessage), + tpl_log_entry_get_log_id (TPL_LOG_ENTRY (message)), contact_id, contact_name, //avatar_token ? avatar_token : "", // instead force to "" as //follow @@ -415,20 +349,18 @@ _log_store_empathy_add_message_text_chat (TplLogStore * self, static gboolean _log_store_empathy_add_message_text (TplLogStore * self, - TplLogEntry * message, GError ** error) + TplLogEntryText *message, GError ** error) { TplLogEntryTextSignalType signal_type; - TplLogEntryText *tmessage; const gchar *chat_id; gboolean chatroom; g_return_val_if_fail (TPL_IS_LOG_STORE (self), FALSE); - g_return_val_if_fail (TPL_IS_LOG_ENTRY (message), FALSE); + g_return_val_if_fail (TPL_IS_LOG_ENTRY_TEXT (message), FALSE); - tmessage = tpl_log_entry_get_entry (message); - chat_id = tpl_log_entry_text_get_chat_id (tmessage); - chatroom = tpl_log_entry_text_is_chatroom (tmessage); - signal_type = tpl_log_entry_text_get_signal_type (tmessage); + chat_id = tpl_log_entry_get_chat_id (TPL_LOG_ENTRY (message)); + chatroom = tpl_log_entry_text_is_chatroom (message); + signal_type = tpl_log_entry_get_signal_type (TPL_LOG_ENTRY (message)); switch (signal_type) { @@ -438,9 +370,8 @@ _log_store_empathy_add_message_text (TplLogStore * self, message, error); break; case TPL_LOG_ENTRY_TEXT_SIGNAL_CHAT_STATUS_CHANGED: - return _log_store_empathy_add_message_text_status_changed (self, - message, - error); + g_warning ("STATUS_CHANGED log entry not currently handled"); + return FALSE; break; case TPL_LOG_ENTRY_TEXT_SIGNAL_SEND_ERROR: g_warning ("SEND_ERROR log entry not currently handled"); @@ -458,16 +389,21 @@ _log_store_empathy_add_message_text (TplLogStore * self, /* First of two phases selection: understand the type LogEntry */ static gboolean log_store_empathy_add_message (TplLogStore * self, - TplLogEntry * message, GError ** error) + gpointer message, GError ** error) { g_return_val_if_fail (TPL_IS_LOG_ENTRY (message), FALSE); - switch (tpl_log_entry_get_entry_type (message)) + switch (tpl_log_entry_get_signal_type (TPL_LOG_ENTRY (message))) { - case TPL_LOG_ENTRY_TEXT: - return _log_store_empathy_add_message_text (self, message, error); - default: - return FALSE; + case TPL_LOG_ENTRY_CHANNEL_TEXT_SIGNAL_SENT: + case TPL_LOG_ENTRY_CHANNEL_TEXT_SIGNAL_RECEIVED: + case TPL_LOG_ENTRY_CHANNEL_TEXT_SIGNAL_SEND_ERROR: + case TPL_LOG_ENTRY_CHANELL_TEXT_SIGNAL_LOST_MESSAGE: + case TPL_LOG_ENTRY_CHANNEL_TEXT_SIGNAL_CHAT_STATUS_CHANGED: + return _log_store_empathy_add_message_text (self, + TPL_LOG_ENTRY_TEXT (message), error); + default: + return FALSE; } } @@ -674,8 +610,7 @@ log_store_empathy_get_messages_for_file (TplLogStore * self, /* Now get the messages. */ for (node = log_node->children; node; node = node->next) { - TplLogEntry *message; - TplLogEntryText *tmessage; + TplLogEntryText *message; TplContact *sender; gchar *time_; time_t t; @@ -691,7 +626,7 @@ log_store_empathy_get_messages_for_file (TplLogStore * self, TpChannelTextMessageType msg_type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; if (strcmp ((const gchar *) node->name, "message") != 0) - continue; + continue; body = (gchar *) xmlNodeGetContent (node); time_ = (gchar *) xmlGetProp (node, (const xmlChar *) "time"); @@ -706,19 +641,20 @@ log_store_empathy_get_messages_for_file (TplLogStore * self, cm_id_str = (gchar *) xmlGetProp (node, (const xmlChar *) "cm_id"); if (is_user_str) - is_user = strcmp (is_user_str, "true") == 0; + is_user = strcmp (is_user_str, "true") == 0; if (msg_type_str) - msg_type = tpl_log_entry_text_message_type_from_str (msg_type_str); + msg_type = tpl_log_entry_text_message_type_from_str (msg_type_str); if (cm_id_str) - cm_id = atoi (cm_id_str); + cm_id = atoi (cm_id_str); + else + cm_id = 0; t = tpl_time_parse (time_); - sender = tpl_contact_new (); + sender = tpl_contact_new (sender_id); tpl_contact_set_account (sender, account); - tpl_contact_set_identifier (sender, sender_id); tpl_contact_set_alias (sender, sender_name); /* TODO remove avatar code @@ -727,20 +663,15 @@ log_store_empathy_get_messages_for_file (TplLogStore * self, sender_avatar_token); */ - tmessage = tpl_log_entry_text_new (); - tpl_log_entry_text_set_message (tmessage, body); - tpl_log_entry_text_set_sender (tmessage, sender); - tpl_log_entry_text_set_message_type (tmessage, msg_type); + message = tpl_log_entry_text_new (cm_id, NULL, + TPL_LOG_ENTRY_DIRECTION_NONE); + tpl_log_entry_set_sender (TPL_LOG_ENTRY (message), sender); + tpl_log_entry_set_timestamp (TPL_LOG_ENTRY (message), t); + tpl_log_entry_text_set_message (message, body); + tpl_log_entry_text_set_message_type (message, msg_type); //TODO uderstand if useful //tpl_log_entry_text_set_is_backlog (message, TRUE); - message = tpl_log_entry_new (); - tpl_log_entry_set_timestamp (message, t); - tpl_log_entry_set_entry (message, tmessage); - - if (cm_id_str) - tpl_log_entry_text_set_message_id (tmessage, cm_id); - messages = g_list_append (messages, message); g_object_unref (sender); diff --git a/telepathy-logger/log-store.c b/telepathy-logger/log-store.c index 550b0f4..a98f5db 100644 --- a/telepathy-logger/log-store.c +++ b/telepathy-logger/log-store.c @@ -70,7 +70,7 @@ tpl_log_store_exists (TplLogStore * self, gboolean tpl_log_store_add_message (TplLogStore * self, - TplLogEntry * message, GError ** error) + gpointer message, GError ** error) { if (!TPL_LOG_STORE_GET_INTERFACE (self)->add_message) { diff --git a/telepathy-logger/log-store.h b/telepathy-logger/log-store.h index cc9262a..83408b8 100644 --- a/telepathy-logger/log-store.h +++ b/telepathy-logger/log-store.h @@ -49,7 +49,7 @@ struct _TplLogStoreInterface const gchar *(*get_name) (TplLogStore * self); gboolean (*exists) (TplLogStore * self, TpAccount * account, const gchar * chat_id, gboolean chatroom); - gboolean (*add_message) (TplLogStore * self, TplLogEntry * message, + gboolean (*add_message) (TplLogStore * self, gpointer message, GError ** error); GList *(*get_dates) (TplLogStore * self, TpAccount * account, const gchar * chat_id, gboolean chatroom); @@ -79,7 +79,7 @@ const gchar *tpl_log_store_get_name (TplLogStore * self); gboolean tpl_log_store_exists (TplLogStore * self, TpAccount * account, const gchar * chat_id, gboolean chatroom); -gboolean tpl_log_store_add_message (TplLogStore * self, TplLogEntry * message, +gboolean tpl_log_store_add_message (TplLogStore * self, gpointer message, GError ** error); GList *tpl_log_store_get_dates (TplLogStore * self, TpAccount * account, const gchar * chat_id, gboolean chatroom); diff --git a/telepathy-logger/utils.c b/telepathy-logger/util.c index 89840c9..41aaf44 100644 --- a/telepathy-logger/utils.c +++ b/telepathy-logger/util.c @@ -19,12 +19,12 @@ * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> */ -#include "utils.h" +#include "util.h" #include <telepathy-glib/util.h> void -tpl_object_unref_if_not_null (void *data) +tpl_object_unref_if_not_null (gpointer data) { if (data && G_IS_OBJECT (data)) { @@ -33,7 +33,7 @@ tpl_object_unref_if_not_null (void *data) } void -tpl_object_ref_if_not_null (void *data) +tpl_object_ref_if_not_null (gpointer data) { if (data && G_IS_OBJECT (data)) { diff --git a/telepathy-logger/utils.h b/telepathy-logger/util.h index 00b6ee0..00b6ee0 100644 --- a/telepathy-logger/utils.h +++ b/telepathy-logger/util.h |