diff options
-rw-r--r-- | libempathy/empathy-log-manager.c | 34 | ||||
-rw-r--r-- | libempathy/empathy-log-manager.h | 5 | ||||
-rw-r--r-- | libempathy/empathy-log-source-empathy.c | 15 | ||||
-rw-r--r-- | libempathy/empathy-log-source.c | 11 | ||||
-rw-r--r-- | libempathy/empathy-log-source.h | 9 | ||||
-rw-r--r-- | src/empathy.c | 12 |
6 files changed, 60 insertions, 26 deletions
diff --git a/libempathy/empathy-log-manager.c b/libempathy/empathy-log-manager.c index 46463733f..1593ff4d0 100644 --- a/libempathy/empathy-log-manager.c +++ b/libempathy/empathy-log-manager.c @@ -28,6 +28,8 @@ #include <stdlib.h> #include <glib/gstdio.h> +#include <telepathy-glib/util.h> + #include "empathy-log-manager.h" #include "empathy-log-source-empathy.h" #include "empathy-log-source.h" @@ -120,26 +122,44 @@ empathy_log_manager_dup_singleton (void) return g_object_new (EMPATHY_TYPE_LOG_MANAGER, NULL); } -void +gboolean empathy_log_manager_add_message (EmpathyLogManager *manager, const gchar *chat_id, gboolean chatroom, - EmpathyMessage *message) + EmpathyMessage *message, + GError **error) { EmpathyLogManagerPriv *priv; GList *l; + gboolean out = FALSE; + gboolean found = FALSE; - g_return_if_fail (EMPATHY_IS_LOG_MANAGER (manager)); - g_return_if_fail (chat_id != NULL); - g_return_if_fail (EMPATHY_IS_MESSAGE (message)); + /* TODO: When multiple log sources appear with add_message implementations + * make this customisable. */ + const gchar *add_source = "Empathy"; + + g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), FALSE); + g_return_val_if_fail (chat_id != NULL, FALSE); + g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE); priv = GET_PRIV (manager); for (l = priv->sources; l; l = l->next) { - empathy_log_source_add_message (EMPATHY_LOG_SOURCE (l->data), - chat_id, chatroom, message); + if (!tp_strdiff (empathy_log_source_get_name ( + EMPATHY_LOG_SOURCE (l->data)), add_source)) + { + out = empathy_log_source_add_message (EMPATHY_LOG_SOURCE (l->data), + chat_id, chatroom, message, error); + found = TRUE; + break; + } } + + if (!found) + DEBUG ("Failed to find chosen log source to write to."); + + return out; } gboolean diff --git a/libempathy/empathy-log-manager.h b/libempathy/empathy-log-manager.h index fa9e39b7b..688cb11ff 100644 --- a/libempathy/empathy-log-manager.h +++ b/libempathy/empathy-log-manager.h @@ -73,8 +73,9 @@ struct _EmpathyLogSearchHit GType empathy_log_manager_get_type (void) G_GNUC_CONST; EmpathyLogManager *empathy_log_manager_dup_singleton (void); -void empathy_log_manager_add_message (EmpathyLogManager *manager, - const gchar *chat_id, gboolean chatroom, EmpathyMessage *message); +gboolean empathy_log_manager_add_message (EmpathyLogManager *manager, + const gchar *chat_id, gboolean chatroom, EmpathyMessage *message, + GError **error); gboolean empathy_log_manager_exists (EmpathyLogManager *manager, McAccount *account, const gchar *chat_id, gboolean chatroom); GList *empathy_log_manager_get_dates (EmpathyLogManager *manager, diff --git a/libempathy/empathy-log-source-empathy.c b/libempathy/empathy-log-source-empathy.c index fd744f94b..baad6c965 100644 --- a/libempathy/empathy-log-source-empathy.c +++ b/libempathy/empathy-log-source-empathy.c @@ -172,11 +172,12 @@ log_source_empathy_get_filename (EmpathyLogSource *self, return filename; } -static void +static gboolean log_source_empathy_add_message (EmpathyLogSource *self, const gchar *chat_id, gboolean chatroom, - EmpathyMessage *message) + EmpathyMessage *message, + GError **error) { FILE *file; McAccount *account; @@ -193,9 +194,9 @@ log_source_empathy_add_message (EmpathyLogSource *self, gchar *contact_id; TpChannelTextMessageType msg_type; - g_return_if_fail (EMPATHY_IS_LOG_SOURCE (self)); - g_return_if_fail (chat_id != NULL); - g_return_if_fail (EMPATHY_IS_MESSAGE (message)); + g_return_val_if_fail (EMPATHY_IS_LOG_SOURCE (self), FALSE); + g_return_val_if_fail (chat_id != NULL, FALSE); + g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE); sender = empathy_message_get_sender (message); account = empathy_contact_get_account (sender); @@ -203,7 +204,7 @@ log_source_empathy_add_message (EmpathyLogSource *self, msg_type = empathy_message_get_tptype (message); if (G_STR_EMPTY (body_str)) - return; + return FALSE; filename = log_source_empathy_get_filename (self, account, chat_id, chatroom); basedir = g_path_get_dirname (filename); @@ -258,6 +259,8 @@ log_source_empathy_add_message (EmpathyLogSource *self, g_free (timestamp); g_free (body); g_free (avatar_token); + + return TRUE; } static gboolean diff --git a/libempathy/empathy-log-source.c b/libempathy/empathy-log-source.c index 4080d5a6c..f1e37fa79 100644 --- a/libempathy/empathy-log-source.c +++ b/libempathy/empathy-log-source.c @@ -68,17 +68,18 @@ empathy_log_source_exists (EmpathyLogSource *self, -void +gboolean empathy_log_source_add_message (EmpathyLogSource *self, const gchar *chat_id, gboolean chatroom, - EmpathyMessage *message) + EmpathyMessage *message, + GError **error) { if (!EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->add_message) - return; + return FALSE; - EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->add_message ( - self, chat_id, chatroom, message); + return EMPATHY_LOG_SOURCE_GET_INTERFACE (self)->add_message ( + self, chat_id, chatroom, message, error); } GList * diff --git a/libempathy/empathy-log-source.h b/libempathy/empathy-log-source.h index c00571813..03d920c28 100644 --- a/libempathy/empathy-log-source.h +++ b/libempathy/empathy-log-source.h @@ -51,8 +51,8 @@ struct _EmpathyLogSourceInterface const gchar * (*get_name) (EmpathyLogSource *self); gboolean (*exists) (EmpathyLogSource *self, McAccount *account, const gchar *chat_id, gboolean chatroom); - void (*add_message) (EmpathyLogSource *self, const gchar *chat_id, - gboolean chatroom, EmpathyMessage *message); + gboolean (*add_message) (EmpathyLogSource *self, const gchar *chat_id, + gboolean chatroom, EmpathyMessage *message, GError **error); GList * (*get_dates) (EmpathyLogSource *self, McAccount *account, const gchar *chat_id, gboolean chatroom); GList * (*get_messages_for_date) (EmpathyLogSource *self, @@ -72,8 +72,9 @@ GType empathy_log_source_get_type (void) G_GNUC_CONST; const gchar *empathy_log_source_get_name (EmpathyLogSource *self); gboolean empathy_log_source_exists (EmpathyLogSource *self, McAccount *account, const gchar *chat_id, gboolean chatroom); -void empathy_log_source_add_message (EmpathyLogSource *self, - const gchar *chat_id, gboolean chatroom, EmpathyMessage *message); +gboolean empathy_log_source_add_message (EmpathyLogSource *self, + const gchar *chat_id, gboolean chatroom, EmpathyMessage *message, + GError **error); GList *empathy_log_source_get_dates (EmpathyLogSource *self, McAccount *account, const gchar *chat_id, gboolean chatroom); GList *empathy_log_source_get_messages_for_date (EmpathyLogSource *self, diff --git a/src/empathy.c b/src/empathy.c index ce380588f..9357b2cb7 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -136,13 +136,21 @@ received_message_cb (EmpathyTpChat *tp_chat, { EmpathyLogManager *log_manager; EmpathyContact *contact; + GError *error = NULL; contact = empathy_tp_chat_get_remote_contact (tp_chat); log_manager = empathy_log_manager_dup_singleton (); - empathy_log_manager_add_message (log_manager, - empathy_contact_get_id (contact), is_chatroom, message); + if (!empathy_log_manager_add_message (log_manager, + empathy_contact_get_id (contact), + is_chatroom, + message, + &error)) { + DEBUG ("Failed to write message: %s", + error ? error->message : "No error message"); + } + g_object_unref (contact); g_object_unref (log_manager); |