]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-log-store-empathy.c
Updated Basque language
[empathy.git] / libempathy / empathy-log-store-empathy.c
index 94f4d14579718dcb6f791bb1968676e3d852eb1e..9963bfc44e1fb39265a54c9e8fb6f768d4cf0150 100644 (file)
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+
+/* FIXME: g_mapped_file_free has been deprecated in GLib 2.22, but the
+ * replacement symbol, g_mapped_file_unref is not available in older Glib
+ * and we're not ready to bump our version requirement just for this. When
+ * we're ready to bump our version requirement, just revert this patch. */
+#undef G_DISABLE_DEPRECATED
 #include <glib/gstdio.h>
+#define G_DISABLE_DEPRECATED
+
+#include <telepathy-glib/util.h>
+#include <telepathy-glib/defs.h>
 
 #include "empathy-log-store.h"
 #include "empathy-log-store-empathy.h"
 #include "empathy-log-manager.h"
+#include "empathy-account-manager.h"
 #include "empathy-contact.h"
 #include "empathy-time.h"
 #include "empathy-utils.h"
@@ -59,6 +70,7 @@ typedef struct
 {
   gchar *basedir;
   gchar *name;
+  EmpathyAccountManager *account_manager;
 } EmpathyLogStoreEmpathyPriv;
 
 static void log_store_iface_init (gpointer g_iface,gpointer iface_data);
@@ -73,6 +85,7 @@ log_store_empathy_finalize (GObject *object)
   EmpathyLogStoreEmpathy *self = EMPATHY_LOG_STORE_EMPATHY (object);
   EmpathyLogStoreEmpathyPriv *priv = GET_PRIV (self);
 
+  g_object_unref (priv->account_manager);
   g_free (priv->basedir);
   g_free (priv->name);
 }
@@ -95,32 +108,48 @@ empathy_log_store_empathy_init (EmpathyLogStoreEmpathy *self)
 
   self->priv = priv;
 
-  priv->basedir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (),
-      ".gnome2", PACKAGE_NAME, "logs", NULL);
+  priv->basedir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
+    PACKAGE_NAME, "logs", NULL);
 
   priv->name = g_strdup ("Empathy");
+  priv->account_manager = empathy_account_manager_dup_singleton ();
+}
+
+static gchar *
+log_store_account_to_dirname (EmpathyAccount *account)
+{
+  const gchar *name;
+
+  name = empathy_account_get_unique_name (account);
+  if (g_str_has_prefix (name, TP_ACCOUNT_OBJECT_PATH_BASE))
+    name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
+
+  return g_strdelimit (g_strdup (name), "/", '_');
 }
 
+
 static gchar *
 log_store_empathy_get_dir (EmpathyLogStore *self,
-                           McAccount *account,
+                           EmpathyAccount *account,
                            const gchar *chat_id,
                            gboolean chatroom)
 {
-  const gchar *account_id;
   gchar *basedir;
+  gchar *escaped;
   EmpathyLogStoreEmpathyPriv *priv;
 
   priv = GET_PRIV (self);
 
-  account_id = mc_account_get_unique_name (account);
+  escaped = log_store_account_to_dirname (account);
 
   if (chatroom)
-    basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, account_id,
+    basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir, escaped,
         LOG_DIR_CHATROOMS, chat_id, NULL);
   else
     basedir = g_build_path (G_DIR_SEPARATOR_S, priv->basedir,
-        account_id, chat_id, NULL);
+        escaped, chat_id, NULL);
+
+  g_free (escaped);
 
   return basedir;
 }
@@ -154,7 +183,7 @@ log_store_empathy_get_timestamp_from_message (EmpathyMessage *message)
 
 static gchar *
 log_store_empathy_get_filename (EmpathyLogStore *self,
-                                McAccount *account,
+                                EmpathyAccount *account,
                                 const gchar *chat_id,
                                 gboolean chatroom)
 {
@@ -180,7 +209,7 @@ log_store_empathy_add_message (EmpathyLogStore *self,
                                GError **error)
 {
   FILE *file;
-  McAccount *account;
+  EmpathyAccount *account;
   EmpathyContact *sender;
   const gchar *body_str;
   const gchar *str;
@@ -267,7 +296,7 @@ log_store_empathy_add_message (EmpathyLogStore *self,
 
 static gboolean
 log_store_empathy_exists (EmpathyLogStore *self,
-                          McAccount *account,
+                          EmpathyAccount *account,
                           const gchar *chat_id,
                           gboolean chatroom)
 {
@@ -283,7 +312,7 @@ log_store_empathy_exists (EmpathyLogStore *self,
 
 static GList *
 log_store_empathy_get_dates (EmpathyLogStore *self,
-                             McAccount *account,
+                             EmpathyAccount *account,
                              const gchar *chat_id,
                              gboolean chatroom)
 {
@@ -295,7 +324,6 @@ log_store_empathy_get_dates (EmpathyLogStore *self,
   const gchar *p;
 
   g_return_val_if_fail (EMPATHY_IS_LOG_STORE (self), NULL);
-  g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
   g_return_val_if_fail (chat_id != NULL, NULL);
 
   directory = log_store_empathy_get_dir (self, account, chat_id, chatroom);
@@ -336,7 +364,7 @@ log_store_empathy_get_dates (EmpathyLogStore *self,
 
 static gchar *
 log_store_empathy_get_filename_for_date (EmpathyLogStore *self,
-                                         McAccount *account,
+                                         EmpathyAccount *account,
                                          const gchar *chat_id,
                                          gboolean chatroom,
                                          const gchar *date)
@@ -359,11 +387,13 @@ static EmpathyLogSearchHit *
 log_store_empathy_search_hit_new (EmpathyLogStore *self,
                                   const gchar *filename)
 {
+  EmpathyLogStoreEmpathyPriv *priv = GET_PRIV (self);
   EmpathyLogSearchHit *hit;
-  const gchar *account_name;
+  gchar *account_name;
   const gchar *end;
   gchar **strv;
   guint len;
+  GList *accounts, *l;
 
   if (!g_str_has_suffix (filename, LOG_FILENAME_SUFFIX))
     return NULL;
@@ -383,7 +413,25 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self,
   else
     account_name = strv[len-3];
 
-  hit->account = mc_account_lookup (account_name);
+  accounts = empathy_account_manager_dup_accounts (priv->account_manager);
+
+  for (l = accounts; l != NULL; l = g_list_next (l))
+    {
+      EmpathyAccount *account = EMPATHY_ACCOUNT (l->data);
+      gchar *name;
+
+      name = log_store_account_to_dirname (account);
+      if (!tp_strdiff (name, account_name))
+        {
+          g_assert (hit->account == NULL);
+          hit->account = account;
+          g_object_ref (account);
+        }
+      g_object_unref (account);
+      g_free (name);
+    }
+  g_list_free (accounts);
+
   hit->filename = g_strdup (filename);
 
   g_strfreev (strv);
@@ -401,7 +449,7 @@ log_store_empathy_get_messages_for_file (EmpathyLogStore *self,
   xmlNodePtr log_node;
   xmlNodePtr node;
   EmpathyLogSearchHit *hit;
-  McAccount *account;
+  EmpathyAccount *account;
 
   g_return_val_if_fail (EMPATHY_IS_LOG_STORE (self), NULL);
   g_return_val_if_fail (filename != NULL, NULL);
@@ -416,9 +464,15 @@ log_store_empathy_get_messages_for_file (EmpathyLogStore *self,
 
   /* Get the account from the filename */
   hit = log_store_empathy_search_hit_new (self, filename);
-  account = g_object_ref (hit->account);
+
+  if (hit->account != NULL)
+    account = g_object_ref (hit->account);
+
   empathy_log_manager_search_hit_free (hit);
 
+  if (hit->account == NULL)
+    return NULL;
+
   /* Create parser. */
   ctxt = xmlNewParserCtxt ();
 
@@ -492,6 +546,7 @@ log_store_empathy_get_messages_for_file (EmpathyLogStore *self,
       empathy_message_set_sender (message, sender);
       empathy_message_set_timestamp (message, t);
       empathy_message_set_tptype (message, msg_type);
+      empathy_message_set_is_backlog (message, TRUE);
 
       if (cm_id_str)
         empathy_message_set_id (message, cm_id);
@@ -666,7 +721,7 @@ log_store_empathy_get_chats_for_dir (EmpathyLogStore *self,
 
 static GList *
 log_store_empathy_get_messages_for_date (EmpathyLogStore *self,
-                                         McAccount *account,
+                                         EmpathyAccount *account,
                                          const gchar *chat_id,
                                          gboolean chatroom,
                                          const gchar *date)
@@ -675,7 +730,6 @@ log_store_empathy_get_messages_for_date (EmpathyLogStore *self,
   GList *messages;
 
   g_return_val_if_fail (EMPATHY_IS_LOG_STORE (self), NULL);
-  g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
   g_return_val_if_fail (chat_id != NULL, NULL);
 
   filename = log_store_empathy_get_filename_for_date (self, account,
@@ -688,7 +742,7 @@ log_store_empathy_get_messages_for_date (EmpathyLogStore *self,
 
 static GList *
 log_store_empathy_get_chats (EmpathyLogStore *self,
-                              McAccount *account)
+                              EmpathyAccount *account)
 {
   gchar *dir;
   GList *hits;
@@ -696,8 +750,7 @@ log_store_empathy_get_chats (EmpathyLogStore *self,
 
   priv = GET_PRIV (self);
 
-  dir = g_build_filename (priv->basedir,
-      mc_account_get_unique_name (account), NULL);
+  dir = log_store_empathy_get_dir (self, account, NULL, FALSE);
 
   hits = log_store_empathy_get_chats_for_dir (self, dir, FALSE);
 
@@ -716,7 +769,7 @@ log_store_empathy_get_name (EmpathyLogStore *self)
 
 static GList *
 log_store_empathy_get_filtered_messages (EmpathyLogStore *self,
-                                         McAccount *account,
+                                         EmpathyAccount *account,
                                          const gchar *chat_id,
                                          gboolean chatroom,
                                          guint num_messages,