diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-05-26 12:33:32 +0200 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-05-26 12:33:32 +0200 |
commit | 62223ff3a7fd8fc0eb008d9e9186625c022112ed (patch) | |
tree | 02cfdde8490d0e704c11470c9fb627fdd104b189 | |
parent | bcbd2edb2558651a760839804423cfcb9afd805c (diff) | |
parent | 3093b25b89535a174a5fc13e0531c98cf2382afa (diff) |
Merge branch 'ka-misc-27642'
Conflicts:
telepathy-logger/contact.h
-rw-r--r-- | telepathy-logger/channel-text.c | 21 | ||||
-rw-r--r-- | telepathy-logger/contact.c | 51 | ||||
-rw-r--r-- | telepathy-logger/contact.h | 22 | ||||
-rw-r--r-- | telepathy-logger/log-entry-text.c | 18 | ||||
-rw-r--r-- | telepathy-logger/log-entry.c | 8 | ||||
-rw-r--r-- | telepathy-logger/log-store-sqlite.c | 4 |
6 files changed, 107 insertions, 17 deletions
diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c index 1221360b9..9a1563f36 100644 --- a/telepathy-logger/channel-text.c +++ b/telepathy-logger/channel-text.c @@ -225,7 +225,7 @@ pendingproc_get_remote_handle_type (TplActionChain *ctx, break; case TP_HANDLE_TYPE_NONE: PATH_DEBUG (tpl_text, "HANDLE_TYPE_NONE received, probably an anonymous " - "chat, like MSN ones. TODO: implement this possibility"); + "chat, like MSN ones. NOT IMPLEMENTED"); _tpl_action_chain_terminate (ctx); return; break; @@ -936,12 +936,12 @@ get_chatroom_id_cb (TpConnection *proxy, if (error != NULL) { - PATH_DEBUG (proxy, "retrieving chatroom identifier: %s", error->message); + PATH_DEBUG (tpl_text, "retrieving chatroom identifier: %s", error->message); _tpl_action_chain_terminate (ctx); return; } - PATH_DEBUG (proxy, "Chatroom id: %s", identifiers[0]); + PATH_DEBUG (tpl_text, "Chatroom id: %s", identifiers[0]); tpl_channel_text_set_chatroom_id (tpl_text, identifiers[0]); _tpl_action_chain_continue (ctx); @@ -1208,6 +1208,10 @@ on_sent_signal_cb (TpChannel *proxy, } +/* the only function of this CB is resolving the remote TpHandle, in case + * cannot be known at preparation time (ie on chatrooms channels) + * + * It sets gets a TplLogEntryText as weak_ref and sets the sender for it */ static void on_received_signal_with_contact_cb (TpConnection *connection, guint n_contacts, @@ -1284,7 +1288,6 @@ keepon_on_receiving_signal (TplLogEntryText *log) tpl_contact_get_alias (tpl_contact_sender), tpl_log_entry_text_get_message (log)); - /* Initialise LogStore and store the message */ if (!tpl_channel_text_is_chatroom (tpl_text)) tpl_log_entry_text_set_chat_id (log, tpl_contact_get_identifier ( @@ -1300,11 +1303,12 @@ keepon_on_receiving_signal (TplLogEntryText *log) _tpl_log_manager_add_message (logmanager, TPL_LOG_ENTRY (log), &e); if (e != NULL) { - DEBUG ("LogStore: %s", e->message); + DEBUG ("%s", e->message); g_error_free (e); } g_object_unref (tpl_contact_sender); + g_object_unref (log); g_object_unref (logmanager); } @@ -1370,7 +1374,8 @@ on_received_signal_cb (TpChannel *proxy, tpl_log_entry_text_set_tpl_channel_text (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_text_set_signal_type (log, TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED); + tpl_log_entry_text_set_signal_type (log, + TPL_LOG_ENTRY_TEXT_SIGNAL_RECEIVED); me = tpl_channel_text_get_my_contact (tpl_text); tpl_contact_receiver = _tpl_contact_from_tp_contact (me); @@ -1393,9 +1398,7 @@ out: g_object_unref (tpl_contact_receiver); g_object_unref (index); - - if (log != NULL) - g_object_unref (log); + /* log is unrefed in keepon_on_receiving_signal() */ g_free (log_id); } diff --git a/telepathy-logger/contact.c b/telepathy-logger/contact.c index 743b4fc2a..76bdca494 100644 --- a/telepathy-logger/contact.c +++ b/telepathy-logger/contact.c @@ -171,6 +171,39 @@ tpl_contact_init (TplContact *self) } +/* tpl_contact_from_room_id: + * @chatroom_id: the chatroom id which will be the identifier for the contact + * + * Return a TplContact instance with identifier, alias copied from + * @chatroom_id. It also sets %TPL_CONTACT_GROUP as contact type for + * the #TplContact returned. + */ +TplContact * +tpl_contact_from_room_id (const gchar *chatroom_id) +{ + TplContact *ret; + + g_return_val_if_fail (chatroom_id != NULL, NULL); + + ret = _tpl_contact_new (chatroom_id); + tpl_contact_set_alias (ret, chatroom_id); + tpl_contact_set_contact_type (ret, TPL_CONTACT_GROUP); + + DEBUG ("Chatroom id: %s", chatroom_id); + return ret; +} + + +/* tpl_contact_from_tp_contact: + * @contact: the TpContact instance to create the TplContact from + * + * Return a TplContact instance with identifier, alias and + * avatar's token copied. It also sets %TPL_CONTACT_USER as contact type for + * the #TplContact returned. The client needs to set it to %TPL_CONTACT_SELF + * in case the contact is the account's onwer. + * + * @see #tpl_contact_set_contact_type() and %TPL_CONTACT_SELF description. + */ TplContact * _tpl_contact_from_tp_contact (TpContact *contact) { @@ -185,6 +218,11 @@ _tpl_contact_from_tp_contact (TpContact *contact) if (tp_contact_get_avatar_token (contact) != NULL) tpl_contact_set_avatar_token (ret, tp_contact_get_avatar_token (contact)); + /* set contact type to TPL_CONTACT_USER by default, the client need to set + * it to TPL_CONTACT_SELF in case the contact is actually the account's + * owner */ + tpl_contact_set_contact_type (ret, TPL_CONTACT_USER); + DEBUG ("ID: %s, TOK: %s", tpl_contact_get_identifier (ret), tpl_contact_get_avatar_token (ret)); return ret; @@ -261,6 +299,19 @@ tpl_contact_set_identifier (TplContact *self, } +/* tpl_contact_set_contact_type: + * @self: a TplContact instance + * @data: the contact type for @self + * + * Set a contact type for @self. + * + * Note: %TPL_CONTACT_USER and %TPL_CONTACT_GROUP are automatically set after + * #tpl_contact_from_tp_contact() and #tpl_contact_from_chatroom_id(), + * respectively. Though, the client will need to set %TPL_CONTACT_SELF after + * those function calls when @self represents the owner of the account. + * + * @see #TplContactType + */ void tpl_contact_set_contact_type (TplContact *self, TplContactType data) diff --git a/telepathy-logger/contact.h b/telepathy-logger/contact.h index 04f39b3db..9202b2544 100644 --- a/telepathy-logger/contact.h +++ b/telepathy-logger/contact.h @@ -33,11 +33,26 @@ G_BEGIN_DECLS #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)) +/* TplContactType: + * + * @TPL_CONTACT_UNKNOWN: the current contact's type is unknown + * @TPL_CONTACT_USER: the contact's type represents a user (buddy), but not + * the the account's owner for which @TPL_CONTACT_SELF is used + * @TPL_CONTACT_GROUP: a named chatroom (#TP_HANDLE_TYPE_ROOM) + * @TPL_CONTACT_SELF: the contact's type represents the owner of the account + * whose channel has been logged, as opposed to @TPL_CONTACT_USER which + * represents any other user + */ typedef enum { TPL_CONTACT_UNKNOWN, + /* contact is a user (buddy) */ TPL_CONTACT_USER, - TPL_CONTACT_GROUP + /* contact is a chatroom, meaning that the related message has been sent to + * a chatroom instead of to a 1-1 channel */ + TPL_CONTACT_GROUP, + /* contact is both a USER and the account's owner (self-handle) */ + TPL_CONTACT_SELF } TplContactType; typedef struct _TplContactPriv TplContactPriv; @@ -52,6 +67,11 @@ typedef struct GType tpl_contact_get_type (void); +TplContact *tpl_contact_from_room_id (const gchar *chatroom_id); +TplContact *tpl_contact_from_tp_contact (TpContact *contact); + +TpContact *tpl_contact_get_contact (TplContact *self); + const gchar *tpl_contact_get_alias (TplContact *self); const gchar *tpl_contact_get_identifier (TplContact *self); TplContactType tpl_contact_get_contact_type (TplContact *self); diff --git a/telepathy-logger/log-entry-text.c b/telepathy-logger/log-entry-text.c index 84248f000..fbfbf84fa 100644 --- a/telepathy-logger/log-entry-text.c +++ b/telepathy-logger/log-entry-text.c @@ -266,8 +266,6 @@ tpl_log_entry_text_get_message (TplLogEntryText * self) TpChannelTextMessageType tpl_log_entry_text_get_message_type (TplLogEntryText * self) { - /* 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); @@ -292,11 +290,13 @@ tpl_log_entry_text_set_tpl_channel_text (TplLogEntryText * self, void -tpl_log_entry_text_set_message (TplLogEntryText *self, const gchar *data) +tpl_log_entry_text_set_message (TplLogEntryText *self, + const gchar *data) { TplLogEntryTextPriv *priv; g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (self)); + g_return_if_fail (data != NULL); /* allow zero length */ priv = self->priv; @@ -433,6 +433,12 @@ tpl_log_entry_text_set_chat_id (TplLogEntryText *self, } +/* tpl_log_entry_text_set_sender: + * @self: a log entry text entry + * @data: a TPL contact instance for the sender + * + * Set who sent this log entry. + */ void tpl_log_entry_text_set_sender (TplLogEntryText *self, TplContact *data) @@ -442,6 +448,12 @@ tpl_log_entry_text_set_sender (TplLogEntryText *self, } +/* tpl_log_entry_text_set_receiver: + * @self: a log entry text entry + * @data: a TPL contact instance for the receiver + * + * Set who received this log entry. + */ void tpl_log_entry_text_set_receiver (TplLogEntryText *self, TplContact *data) diff --git a/telepathy-logger/log-entry.c b/telepathy-logger/log-entry.c index a03e4b864..4c95e334a 100644 --- a/telepathy-logger/log-entry.c +++ b/telepathy-logger/log-entry.c @@ -409,10 +409,11 @@ tpl_log_entry_get_pending_msg_id (TplLogEntry *self) gboolean tpl_log_entry_is_pending (TplLogEntry *self) { - return (tpl_log_entry_get_pending_msg_id (self) != - TPL_LOG_ENTRY_MSG_ID_ACKNOWLEDGED); + return TPL_LOG_ENTRY_MSG_ID_IS_VALID ( + tpl_log_entry_get_pending_msg_id (self)); } + TplLogEntrySignalType tpl_log_entry_get_signal_type (TplLogEntry *self) { @@ -580,9 +581,12 @@ tpl_log_entry_set_receiver (TplLogEntry *self, g_return_if_fail (TPL_IS_CONTACT (data) || data == NULL); priv = self->priv; + if (priv->receiver != NULL) g_object_unref (priv->receiver); + priv->receiver = g_object_ref (data); + g_object_notify (G_OBJECT (self), "receiver"); } diff --git a/telepathy-logger/log-store-sqlite.c b/telepathy-logger/log-store-sqlite.c index aaa51397c..8a25290e2 100644 --- a/telepathy-logger/log-store-sqlite.c +++ b/telepathy-logger/log-store-sqlite.c @@ -426,7 +426,7 @@ tpl_log_store_sqlite_add_message_counter (TplLogStore *self, TplLogStoreSqlitePrivate *priv = GET_PRIV (self); const char *account, *identifier; gboolean chatroom; - char *date; + char *date = NULL; int count = 0; sqlite3_stmt *sql = NULL; gboolean retval = FALSE; @@ -786,7 +786,7 @@ out: * It gets all the log-ids for messages matching the object-path of * @channel and older than @timestamp. * - * If @channel is %NULL, it will get all the exiting log-ids. + * If @channel is %NULL, it will get all the existing log-ids. * * All the entries will be filtered against @timestamp, returning only log-ids * older than this value (time_t). Set it to %G_MAXUINT or any other value in |