]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-avatar.c
Make use of tp-glib debug system.
[empathy.git] / libempathy / empathy-avatar.c
index e08dd28c46d9757d85a42496fb829eefce51b61b..41395d6e9880647d5fcdaf73607cd352ba2d6242 100644 (file)
@@ -1,33 +1,35 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
- * Copyright (C) 2002-2007 Imendio AB
+ * Copyright (C) 2006 Xavier Claessens <xclaesse@gmail.com>
+ * Copyright (C) 2007-2008 Collabora Ltd.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * Authors: Martyn Russell <martyn@imendio.com>
- *          Xavier Claessens <xclaesse@gmail.com>
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
  */
 
+
 #include "config.h"
 
+#include <telepathy-glib/util.h>
+
 #include "empathy-avatar.h"
 #include "empathy-utils.h"
-#include "empathy-debug.h"
 
-#define DEBUG_DOMAIN "Avatar"
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include "empathy-debug.h"
 
 GType
 empathy_avatar_get_type (void)
@@ -57,7 +59,7 @@ avatar_get_filename (const gchar *token)
                                        NULL);
        g_mkdir_with_parents (avatar_path, 0700);
 
-       token_escaped = empathy_escape_as_identifier (token);
+       token_escaped = tp_escape_as_identifier (token);
        avatar_file = g_build_filename (avatar_path, token_escaped, NULL);
 
        g_free (token_escaped);
@@ -67,18 +69,18 @@ avatar_get_filename (const gchar *token)
 }
 
 static EmpathyAvatar *
-avatar_new (const guchar *data,
-           const gsize   len,
-           const gchar  *format,
-           const gchar  *token)
+avatar_new (guchar *data,
+           gsize   len,
+           gchar  *format,
+           gchar  *token)
 {
        EmpathyAvatar *avatar;
 
        avatar = g_slice_new0 (EmpathyAvatar);
-       avatar->data = g_memdup (data, len);
+       avatar->data = data;
        avatar->len = len;
-       avatar->format = g_strdup (format);
-       avatar->token = g_strdup (token);
+       avatar->format = format;
+       avatar->token = token;
        avatar->refcount = 1;
 
        return avatar;
@@ -99,18 +101,20 @@ empathy_avatar_new (const guchar *data,
        g_return_val_if_fail (format != NULL, NULL);
        g_return_val_if_fail (!G_STR_EMPTY (token), NULL);
 
-       avatar = avatar_new (data, len, format, token);
+       avatar = avatar_new (g_memdup (data, len),
+                            len,
+                            g_strdup (format),
+                            g_strdup (token));
 
        /* Save to cache if not yet in it */
        filename = avatar_get_filename (token);
        if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
                if (!g_file_set_contents (filename, data, len, &error)) {
-                       empathy_debug (DEBUG_DOMAIN,
-                                      "Failed to save avatar in cache: %s",
-                                      error ? error->message : "No error given");
+                       DEBUG ("Failed to save avatar in cache: %s",
+                               error ? error->message : "No error given");
                        g_clear_error (&error);
                } else {
-                       empathy_debug (DEBUG_DOMAIN, "Avatar saved to %s", filename);
+                       DEBUG ("Avatar saved to %s", filename);
                }
        }
        g_free (filename);
@@ -133,16 +137,15 @@ empathy_avatar_new_from_cache (const gchar *token)
        filename = avatar_get_filename (token);
        if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
                if (!g_file_get_contents (filename, &data, &len, &error)) {
-                       empathy_debug (DEBUG_DOMAIN,
-                                      "Failed to load avatar from cache: %s",
-                                      error ? error->message : "No error given");
+                       DEBUG ("Failed to load avatar from cache: %s",
+                               error ? error->message : "No error given");
                        g_clear_error (&error);
                }
        }
 
        if (data) {
-               empathy_debug (DEBUG_DOMAIN, "Avatar loaded from %s", filename);
-               avatar = avatar_new (data, len, NULL, token);
+               DEBUG ("Avatar loaded from %s", filename);
+               avatar = avatar_new (data, len, NULL, g_strdup (token));
        }
 
        g_free (filename);