summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-02-17 14:59:42 +0000
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-02-22 12:34:29 +0000
commit993b4f4b9a14749dd7c36b0e605a3ef4aa04f76e (patch)
tree90156ef1b73c5e7600d5d071bdc1dd5b5f676948
parentcab4c064c3bbe0a30f83d0f935f9c549682a99ba (diff)
downloadtelepathy-logger-993b4f4b9a14749dd7c36b0e605a3ef4aa04f76e.tar.gz
added account-path property/member to TplLogStore
That way a client needing to obtain a TpAccount, can acquire it from its object-path. account-path is a PROP_CONSTRUCT_ONLY property, thus the _new method has been updated as well. Setting the avatar_token for queried log entries. Also, cleaned up some code and TP style fixes.
-rw-r--r--telepathy-logger/channel-text.c10
-rw-r--r--telepathy-logger/log-entry-text.c5
-rw-r--r--telepathy-logger/log-entry-text.h3
-rw-r--r--telepathy-logger/log-entry.c63
-rw-r--r--telepathy-logger/log-entry.h3
-rw-r--r--telepathy-logger/log-store-empathy.c66
-rw-r--r--tests/test-tpl-log-entry.c3
7 files changed, 119 insertions, 34 deletions
diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c
index 2660253..ce28ff6 100644
--- a/telepathy-logger/channel-text.c
+++ b/telepathy-logger/channel-text.c
@@ -734,7 +734,8 @@ on_sent_signal_cb (TpChannel *proxy,
TplContact *tpl_contact_receiver = NULL;
TplLogEntryText *log;
TplLogManager *logmanager;
- gchar *chat_id;
+ const gchar *account_path;
+ const gchar *chat_id;
g_return_if_fail (TPL_IS_CHANNEL_TEXT (tpl_text));
@@ -801,6 +802,7 @@ on_sent_signal_cb (TpChannel *proxy,
g_object_unref (log);
}
+
static void
on_received_signal_with_contact_cb (TpConnection *connection,
guint n_contacts,
@@ -845,6 +847,7 @@ on_received_signal_with_contact_cb (TpConnection *connection,
keepon_on_receiving_signal (log);
}
+
static void
keepon_on_receiving_signal (TplLogEntryText *log)
{
@@ -899,6 +902,7 @@ keepon_on_receiving_signal (TplLogEntryText *log)
g_object_unref (logmanager);
}
+
static void
on_received_signal_cb (TpChannel *proxy,
guint arg_ID,
@@ -917,6 +921,8 @@ on_received_signal_cb (TpChannel *proxy,
TpContact *me;
TplContact *tpl_contact_receiver;
TplLogEntryText *log;
+ TpAccount *account = tpl_channel_get_account (TPL_CHANNEL (tpl_text));
+ const gchar *account_path = tp_proxy_get_object_path (TP_PROXY (account));
/* TODO use the Message iface to check the delivery
notification and handle it correctly */
@@ -929,7 +935,7 @@ on_received_signal_cb (TpChannel *proxy,
}
/* Initialize TplLogEntryText (part 1) - chat_id still unknown */
- log = tpl_log_entry_text_new (arg_ID, NULL,
+ log = tpl_log_entry_text_new (arg_ID, account_path, NULL,
TPL_LOG_ENTRY_DIRECTION_IN);
tpl_log_entry_text_set_tpl_channel_text (log, tpl_text);
diff --git a/telepathy-logger/log-entry-text.c b/telepathy-logger/log-entry-text.c
index 43280d9..772f194 100644
--- a/telepathy-logger/log-entry-text.c
+++ b/telepathy-logger/log-entry-text.c
@@ -177,11 +177,14 @@ tpl_log_entry_text_init (TplLogEntryText * self)
TplLogEntryText *
-tpl_log_entry_text_new (guint log_id, const gchar *chat_id,
+tpl_log_entry_text_new (guint log_id,
+ const gchar *account_path,
+ const gchar *chat_id,
TplLogEntryDirection direction)
{
return g_object_new (TPL_TYPE_LOG_ENTRY_TEXT,
"log-id", log_id,
+ "account-path", account_path,
"chat-id", chat_id,
"direction", direction,
NULL);
diff --git a/telepathy-logger/log-entry-text.h b/telepathy-logger/log-entry-text.h
index 3070427..c0f474c 100644
--- a/telepathy-logger/log-entry-text.h
+++ b/telepathy-logger/log-entry-text.h
@@ -64,7 +64,8 @@ typedef struct
GType tpl_log_entry_text_get_type (void);
-TplLogEntryText *tpl_log_entry_text_new (guint log_id, const gchar *chat_id,
+TplLogEntryText *tpl_log_entry_text_new (guint log_id,
+ const gchar *account_path, const gchar *chat_id,
TplLogEntryDirection direction);
TpChannelTextMessageType tpl_log_entry_text_message_type_from_str (
diff --git a/telepathy-logger/log-entry.c b/telepathy-logger/log-entry.c
index c3647f9..43adb22 100644
--- a/telepathy-logger/log-entry.c
+++ b/telepathy-logger/log-entry.c
@@ -44,6 +44,9 @@
G_DEFINE_ABSTRACT_TYPE (TplLogEntry, tpl_log_entry, G_TYPE_OBJECT)
static void tpl_log_entry_set_log_id (TplLogEntry *self, guint data);
+static void tpl_log_entry_set_account_path (TplLogEntry *self,
+ const gchar *data);
+
#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplLogEntry)
struct _TplLogEntryPriv
@@ -52,6 +55,7 @@ struct _TplLogEntryPriv
gint64 timestamp;
TplLogEntrySignalType signal_type;
gchar *chat_id;
+ gchar *account_path;
/* incoming/outgoing */
TplLogEntryDirection direction;
@@ -68,6 +72,7 @@ enum {
PROP_LOG_ID,
PROP_DIRECTION,
PROP_CHAT_ID,
+ PROP_ACCOUNT_PATH,
PROP_SENDER,
PROP_RECEIVER
};
@@ -80,6 +85,8 @@ tpl_log_entry_finalize (GObject *obj)
g_free (priv->chat_id);
priv->chat_id = NULL;
+ g_free (priv->account_path);
+ priv->account_path = NULL;
G_OBJECT_CLASS (tpl_log_entry_parent_class)->finalize (obj);
}
@@ -96,7 +103,7 @@ tpl_log_entry_dispose (GObject *obj)
g_object_unref (priv->sender);
priv->sender = NULL;
}
- if (priv->receiver)
+ if (priv->receiver != NULL)
{
g_object_unref (priv->receiver);
priv->receiver = NULL;
@@ -131,6 +138,9 @@ tpl_log_entry_get_property (GObject *object,
case PROP_CHAT_ID:
g_value_set_string (value, priv->chat_id);
break;
+ case PROP_ACCOUNT_PATH:
+ g_value_set_string (value, priv->account_path);
+ break;
case PROP_SENDER:
g_value_set_object (value, priv->sender);
break;
@@ -168,6 +178,9 @@ tpl_log_entry_set_property (GObject *object,
case PROP_CHAT_ID:
tpl_log_entry_set_chat_id (self, g_value_get_string (value));
break;
+ case PROP_ACCOUNT_PATH:
+ tpl_log_entry_set_account_path (self, g_value_get_string (value));
+ break;
case PROP_SENDER:
tpl_log_entry_set_sender (self, g_value_get_object (value));
break;
@@ -236,13 +249,23 @@ tpl_log_entry_class_init (TplLogEntryClass *klass)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_DIRECTION, param_spec);
+ /* FIXME: G_PARAM_CONSTRUCT and not G_PARAM_CONSTRUCT_ONLY because it needs to be
+ * set not at instance time in channel_text.c on_received_signal.
+ * It would be much better using G_PARAM_CONSTRUCT_ONLY */
param_spec = g_param_spec_string ("chat-id",
"ChatId",
- "The chat id relative to the log entry's account name",
+ "The chat identifier to which the log entry is related.",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_CHAT_ID, param_spec);
+ param_spec = g_param_spec_string ("account-path",
+ "AccountPath",
+ "The account path of the TpAccount to which the log entry is related",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_ACCOUNT_PATH, param_spec);
+
param_spec = g_param_spec_object ("sender",
"Sender",
"TplContact instance who originated the log entry",
@@ -366,6 +389,18 @@ tpl_log_entry_get_chat_id (TplLogEntry *self)
}
+const gchar *
+tpl_log_entry_get_account_path (TplLogEntry *self)
+{
+ TplLogEntryPriv *priv;
+
+ g_return_val_if_fail (TPL_IS_LOG_ENTRY (self), NULL);
+
+ priv = GET_PRIV (self);
+ return priv->account_path;
+}
+
+
void
tpl_log_entry_set_timestamp (TplLogEntry *self,
gint64 data)
@@ -463,14 +498,34 @@ tpl_log_entry_set_chat_id (TplLogEntry *self,
{
TplLogEntryPriv *priv;
+ priv = GET_PRIV (self);
+
g_return_if_fail (TPL_IS_LOG_ENTRY (self));
+ g_return_if_fail (!TPL_STR_EMPTY (data));
+ g_return_if_fail (priv->chat_id == NULL);
- priv = GET_PRIV (self);
- g_free (priv->chat_id);
priv->chat_id = g_strdup (data);
g_object_notify (G_OBJECT(self), "chat-id");
}
+
+static void
+tpl_log_entry_set_account_path (TplLogEntry *self,
+ const gchar *data)
+{
+ TplLogEntryPriv *priv;
+
+ priv = GET_PRIV (self);
+
+ g_return_if_fail (TPL_IS_LOG_ENTRY (self));
+ g_return_if_fail (!TPL_STR_EMPTY (data));
+ g_return_if_fail (priv->account_path == NULL);
+
+ priv->account_path = g_strdup (data);
+ g_object_notify (G_OBJECT(self), "account-path");
+}
+
+
/**
* log_entry:
* @self: TplLogEntry subclass instance
diff --git a/telepathy-logger/log-entry.h b/telepathy-logger/log-entry.h
index 888912a..187cc89 100644
--- a/telepathy-logger/log-entry.h
+++ b/telepathy-logger/log-entry.h
@@ -86,6 +86,7 @@ typedef struct
TplContact * (*get_sender) (TplLogEntry *self);
TplContact * (*get_receiver) (TplLogEntry *self);
const gchar * (*get_chat_id) (TplLogEntry *self);
+ const gchar * (*get_account_path) (TplLogEntry *self);
void (*set_timestamp) (TplLogEntry *self, gint64 data);
void (*set_signal_type) (TplLogEntry *self, TplLogEntrySignalType data);
@@ -107,6 +108,8 @@ gint64 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);
+const gchar *tpl_log_entry_get_account_path (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);
diff --git a/telepathy-logger/log-store-empathy.c b/telepathy-logger/log-store-empathy.c
index 4e6c912..801be9e 100644
--- a/telepathy-logger/log-store-empathy.c
+++ b/telepathy-logger/log-store-empathy.c
@@ -36,6 +36,7 @@
#include <libxml/tree.h>
#include <telepathy-glib/account.h>
#include <telepathy-glib/account-manager.h>
+#include <telepathy-glib/dbus.h>
#include <telepathy-glib/defs.h>
#include <telepathy-glib/util.h>
@@ -261,7 +262,9 @@ tpl_log_store_empathy_class_init (TplLogStoreEmpathyClass *klass)
* TplLogStoreEmpathy:writable:
*
* Wether the log store is writable.
- * Default: %FALSE
+ * Default: %FALSE.
+ * Setting a LogStore to %TRUE might result in duplicate entries among logs.
+ *
* As defined in #TplLogStore.
*/
param_spec = g_param_spec_boolean ("writable",
@@ -407,7 +410,7 @@ _log_store_empathy_write_to_store (TplLogStore *self,
basedir = g_path_get_dirname (filename);
if (!g_file_test (basedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
{
- DEBUG ("Creating directory:'%s'", basedir);
+ DEBUG ("Creating directory: '%s'", basedir);
g_mkdir_with_parents (basedir, LOG_DIR_CREATE_MODE);
}
g_free (basedir);
@@ -440,45 +443,48 @@ add_message_text_chat (TplLogStore *self,
TplLogEntryText *message,
GError **error)
{
- gboolean ret;
+ gboolean ret = FALSE;
+ TpDBusDaemon *bus_daemon;
TpAccount *account;
TplContact *sender;
const gchar *body_str;
- const gchar *str;
gchar *avatar_token = NULL;
gchar *body;
gchar *timestamp;
gchar *contact_name;
gchar *contact_id;
gchar *entry;
- const gchar *chat_id;
- gboolean chatroom;
TpChannelTextMessageType msg_type;
- chat_id = tpl_log_entry_get_chat_id (TPL_LOG_ENTRY (message));
- chatroom = tpl_log_entry_text_is_chatroom (message);
+ bus_daemon = tp_dbus_daemon_dup (error);
+ if (bus_daemon == NULL)
+ {
+ DEBUG ("Error acquiring bus daemon: %s", (*error)->message);
+ goto out;
+ }
- sender = tpl_log_entry_get_sender (TPL_LOG_ENTRY (message));
- account =
- tpl_channel_get_account (TPL_CHANNEL (
- tpl_log_entry_text_get_tpl_channel_text (message)));
- body_str = tpl_log_entry_text_get_message (message);
- msg_type = tpl_log_entry_text_get_message_type (message);
+ account = tp_account_new (bus_daemon,
+ tpl_log_entry_get_account_path (TPL_LOG_ENTRY (message)), error);
+ if (account == NULL)
+ {
+ DEBUG ("Error acquiring TpAccount proxy: %s", (*error)->message);
+ goto out;
+ }
+ body_str = tpl_log_entry_text_get_message (message);
if (TPL_STR_EMPTY (body_str))
- return FALSE;
+ goto out;
body = g_markup_escape_text (body_str, -1);
+ msg_type = tpl_log_entry_text_get_message_type (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);
-
- str = tpl_contact_get_identifier (sender);
-
- contact_id = g_markup_escape_text (str, -1);
+ sender = tpl_log_entry_get_sender (TPL_LOG_ENTRY (message));
+ contact_name = g_markup_escape_text (tpl_contact_get_alias (sender), -1);
+ contact_id = g_markup_escape_text (tpl_contact_get_identifier (sender), -1);
avatar_token = g_markup_escape_text (tpl_contact_get_avatar_token (sender), -1);
+
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,
@@ -490,10 +496,12 @@ add_message_text_chat (TplLogStore *self,
tpl_log_entry_text_message_type_to_str (msg_type),
body);
- ret = _log_store_empathy_write_to_store (self,
- account, chat_id, chatroom, entry,
- error);
+ ret = _log_store_empathy_write_to_store (self, account,
+ tpl_log_entry_get_chat_id (TPL_LOG_ENTRY (message)),
+ tpl_log_entry_text_is_chatroom (message),
+ entry, error);
+out:
g_free (contact_id);
g_free (contact_name);
g_free (timestamp);
@@ -501,6 +509,11 @@ add_message_text_chat (TplLogStore *self,
g_free (entry);
g_free (avatar_token);
+ if (bus_daemon != NULL)
+ g_object_unref (bus_daemon);
+ if (account != NULL)
+ g_object_unref (account);
+
return ret;
}
@@ -739,6 +752,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 (TP_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (!TPL_STR_EMPTY (filename), NULL);
DEBUG ("Attempting to parse filename:'%s'...", filename);
@@ -817,8 +831,10 @@ log_store_empathy_get_messages_for_file (TplLogStore *self,
sender = tpl_contact_new (sender_id);
tpl_contact_set_account (sender, account);
tpl_contact_set_alias (sender, sender_name);
+ tpl_contact_set_avatar_token (sender, sender_avatar_token);
- message = tpl_log_entry_text_new (cm_id, NULL,
+ message = tpl_log_entry_text_new (cm_id,
+ tp_proxy_get_object_path (account), 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);
diff --git a/tests/test-tpl-log-entry.c b/tests/test-tpl-log-entry.c
index 9af158f..68d5357 100644
--- a/tests/test-tpl-log-entry.c
+++ b/tests/test-tpl-log-entry.c
@@ -3,6 +3,7 @@
#define gconf_client_get_bool(obj,key,err) g_print ("%s", key)
#define LOG_ID 0
+#define ACCOUNT_PATH "/org/freedesktop/Telepathy/Account/FOO/BAR/BAZ"
#define CHAT_ID "echo@test.collabora.co.uk"
#define DIRECTION TPL_LOG_ENTRY_DIRECTION_IN
@@ -12,7 +13,7 @@ int main (int argc, char **argv)
g_type_init ();
- log = tpl_log_entry_text_new (LOG_ID, CHAT_ID, DIRECTION);
+ log = tpl_log_entry_text_new (LOG_ID, ACCOUNT_PATH, CHAT_ID, DIRECTION);
return 0;