]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-log-store-empathy.c
Merge commit 'upstream/master' into mc5
[empathy.git] / libempathy / empathy-log-store-empathy.c
index b814defe723e2b1605706fdaa00c345735625f8e..4bb17e4289700e1564bdedcd3ee149b3690e44d6 100644 (file)
@@ -36,6 +36,8 @@
 #include <glib/gstdio.h>
 #define G_DISABLE_DEPRECATED
 
+#include <telepathy-glib/util.h>
+
 #include "empathy-log-store.h"
 #include "empathy-log-store-empathy.h"
 #include "empathy-log-manager.h"
@@ -105,8 +107,8 @@ 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 ();
@@ -118,20 +120,26 @@ log_store_empathy_get_dir (EmpathyLogStore *self,
                            const gchar *chat_id,
                            gboolean chatroom)
 {
-  const gchar *account_id;
   gchar *basedir;
+  gchar *escaped;
   EmpathyLogStoreEmpathyPriv *priv;
 
   priv = GET_PRIV (self);
 
-  account_id = empathy_account_get_unique_name (account);
+  /* unique name is an object path, ignore the initial / and replace the others
+   * by % */
+  escaped = g_strdup (empathy_account_get_unique_name (account) + 1);
+
+  g_strdelimit (escaped, "/", '%');
 
   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;
 }
@@ -371,7 +379,8 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self,
 {
   EmpathyLogStoreEmpathyPriv *priv = GET_PRIV (self);
   EmpathyLogSearchHit *hit;
-  const gchar *account_name;
+  gchar *unescaped;
+  gchar *account_name;
   const gchar *end;
   gchar **strv;
   guint len;
@@ -394,10 +403,13 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self,
   else
     account_name = strv[len-3];
 
+  unescaped = g_strdup_printf ("/%s", g_strdelimit (account_name, "%", '/'));
+
   hit->account = empathy_account_manager_lookup (priv->account_manager,
-    account_name);
+    unescaped);
   hit->filename = g_strdup (filename);
 
+  g_free (unescaped);
   g_strfreev (strv);
 
   return hit;
@@ -428,9 +440,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 ();