]> git.0d.be Git - empathy.git/commitdiff
Only write messages to one specified log source, hardcoded at the moment.
authorJonny Lamb <jonny.lamb@collabora.co.uk>
Fri, 6 Mar 2009 11:51:58 +0000 (11:51 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 6 Mar 2009 11:51:58 +0000 (11:51 +0000)
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
svn path=/trunk/; revision=2590

libempathy/empathy-log-manager.c
libempathy/empathy-log-manager.h
libempathy/empathy-log-source-empathy.c
libempathy/empathy-log-source.c
libempathy/empathy-log-source.h
src/empathy.c

index 46463733fbe315d4150fcaa7ee2e11bb68d563a7..1593ff4d06e9d8b38e9449308bbf649b3735346b 100644 (file)
@@ -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
index fa9e39b7b6fb6f29b43dbaf3ccad3f3d0001314c..688cb11ffe7b4510902a3017b3226c370d158fff 100644 (file)
@@ -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,
index fd744f94bdd097a7524b097ed8c054f65bf177f8..baad6c9658dacacbb51cde969c7d9904835f4aef 100644 (file)
@@ -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
index 4080d5a6cb7352cb0a1dba3598349dd049298b92..f1e37fa79b0c64f527515a7a9e0bd629173d19c3 100644 (file)
@@ -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 *
index c00571813747e6923fd839e39b8290efeb664dd8..03d920c28c0b5e00fd5f9ba0bc7f8533ef0a7f00 100644 (file)
@@ -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,
index ce380588f77776e96f057dbdcc5ca23cc555b241..9357b2cb7db873e13e07624d7b12725fa1c6602c 100644 (file)
@@ -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);