empathy r1128 - in trunk: docs/libempathy libempathy libempathy-gtk megaphone/src python python/pyempathy



Author: xclaesse
Date: Tue May 27 17:34:44 2008
New Revision: 1128
URL: http://svn.gnome.org/viewvc/empathy?rev=1128&view=rev

Log:
Move avatar cache to ~/.cache and don't mix avatar from different contacts, tokens are not garanteed to be different.


Removed:
   trunk/libempathy/empathy-avatar.c
   trunk/libempathy/empathy-avatar.h
Modified:
   trunk/docs/libempathy/libempathy-docs.sgml
   trunk/docs/libempathy/libempathy.types
   trunk/libempathy-gtk/empathy-avatar-chooser.h
   trunk/libempathy-gtk/empathy-avatar-image.h
   trunk/libempathy-gtk/empathy-ui-utils.h
   trunk/libempathy/Makefile.am
   trunk/libempathy/empathy-contact.c
   trunk/libempathy/empathy-contact.h
   trunk/libempathy/empathy-log-manager.c
   trunk/libempathy/empathy-tp-contact-factory.c
   trunk/megaphone/src/megaphone-applet.c
   trunk/python/pyempathy/pyempathy.defs
   trunk/python/pyempathy/pyempathy.override
   trunk/python/update-binding.sh

Modified: trunk/docs/libempathy/libempathy-docs.sgml
==============================================================================
--- trunk/docs/libempathy/libempathy-docs.sgml	(original)
+++ trunk/docs/libempathy/libempathy-docs.sgml	Tue May 27 17:34:44 2008
@@ -16,7 +16,6 @@
   <title>API Reference</title>
     <chapter id="libempathy_api">
       <title>libempathy API reference</title>
-      <xi:include href="xml/empathy-avatar.xml"/>
       <xi:include href="xml/empathy-chatroom-manager.xml"/>
       <xi:include href="xml/empathy-chatroom.xml"/>
       <xi:include href="xml/empathy-contact-factory.xml"/>

Modified: trunk/docs/libempathy/libempathy.types
==============================================================================
--- trunk/docs/libempathy/libempathy.types	(original)
+++ trunk/docs/libempathy/libempathy.types	Tue May 27 17:34:44 2008
@@ -1,11 +1,23 @@
+empathy_chatroom_get_type
+empathy_chatroom_manager_get_type
+empathy_contact_factory_get_type
+empathy_contact_get_type
+empathy_avatar_get_type
 empathy_contact_list_get_type
 empathy_contact_manager_get_type
+empathy_dispatcher_get_type
+empathy_dispatcher_tube_get_type
+empathy_debug_flags_get_type
 empathy_reg_ex_type_get_type
 empathy_capabilities_get_type
+empathy_contact_ready_get_type
+empathy_tp_call_status_get_type
 empathy_idle_get_type
+empathy_irc_network_get_type
+empathy_irc_network_manager_get_type
+empathy_irc_server_get_type
 empathy_log_manager_get_type
 empathy_message_get_type
-empathy_tp_call_status_get_type
 empathy_tp_call_get_type
 empathy_tp_chat_get_type
 empathy_tp_contact_factory_get_type
@@ -14,8 +26,4 @@
 empathy_tp_roomlist_get_type
 empathy_tp_tube_get_type
 empathy_tube_handler_get_type
-empathy_irc_server_get_type
-empathy_irc_network_get_type
-empathy_irc_network_manager_get_type
-empathy_dispatcher_get_type
 

Modified: trunk/libempathy-gtk/empathy-avatar-chooser.h
==============================================================================
--- trunk/libempathy-gtk/empathy-avatar-chooser.h	(original)
+++ trunk/libempathy-gtk/empathy-avatar-chooser.h	Tue May 27 17:34:44 2008
@@ -26,7 +26,7 @@
 
 #include <gtk/gtkbutton.h>
 
-#include <libempathy/empathy-avatar.h>
+#include <libempathy/empathy-contact.h>
 
 G_BEGIN_DECLS
 

Modified: trunk/libempathy-gtk/empathy-avatar-image.h
==============================================================================
--- trunk/libempathy-gtk/empathy-avatar-image.h	(original)
+++ trunk/libempathy-gtk/empathy-avatar-image.h	Tue May 27 17:34:44 2008
@@ -26,7 +26,7 @@
 
 #include <gtk/gtkeventbox.h>
 
-#include <libempathy/empathy-avatar.h>
+#include <libempathy/empathy-contact.h>
 
 G_BEGIN_DECLS
 

Modified: trunk/libempathy-gtk/empathy-ui-utils.h
==============================================================================
--- trunk/libempathy-gtk/empathy-ui-utils.h	(original)
+++ trunk/libempathy-gtk/empathy-ui-utils.h	Tue May 27 17:34:44 2008
@@ -38,7 +38,6 @@
 #include <libmissioncontrol/mc-profile.h>
 
 #include <libempathy/empathy-contact.h>
-#include <libempathy/empathy-avatar.h>
 
 #include "empathy-chat-view.h"
 

Modified: trunk/libempathy/Makefile.am
==============================================================================
--- trunk/libempathy/Makefile.am	(original)
+++ trunk/libempathy/Makefile.am	Tue May 27 17:34:44 2008
@@ -16,7 +16,6 @@
 lib_LTLIBRARIES = libempathy.la
 
 libempathy_la_SOURCES =					\
-	empathy-avatar.c				\
 	empathy-time.c					\
 	empathy-status-presets.c			\
 	empathy-debug.c					\
@@ -57,7 +56,6 @@
        -export-symbols-regex ^empathy_
 
 libempathy_headers =				\
-	empathy-avatar.h			\
 	empathy-time.h				\
 	empathy-status-presets.h		\
 	empathy-debug.h				\

Modified: trunk/libempathy/empathy-contact.c
==============================================================================
--- trunk/libempathy/empathy-contact.c	(original)
+++ trunk/libempathy/empathy-contact.c	Tue May 27 17:34:44 2008
@@ -759,3 +759,166 @@
 				      loop);
 }
 
+static gchar *
+contact_get_avatar_filename (EmpathyContact *contact,
+			     const gchar    *token)
+{
+	EmpathyContactPriv *priv = GET_PRIV (contact);
+	gchar              *avatar_path;
+	gchar              *avatar_file;
+	gchar              *token_escaped;
+	gchar              *contact_escaped;
+
+	contact_escaped = tp_escape_as_identifier (priv->id);
+	token_escaped = tp_escape_as_identifier (token);
+
+	avatar_path = g_build_filename (g_get_user_cache_dir (),
+					PACKAGE_NAME,
+					"avatars",
+					mc_account_get_unique_name (priv->account),
+					contact_escaped,
+					NULL);
+	g_mkdir_with_parents (avatar_path, 0700);
+
+	avatar_file = g_build_filename (avatar_path, token_escaped, NULL);
+
+	g_free (contact_escaped);
+	g_free (token_escaped);
+	g_free (avatar_path);
+
+	return avatar_file;
+}
+
+void
+empathy_contact_load_avatar_data (EmpathyContact *contact,
+				  const guchar   *data,
+				  const gsize     len,
+				  const gchar    *format,
+				  const gchar    *token)
+{
+	EmpathyContactPriv *priv = GET_PRIV (contact);
+	EmpathyAvatar      *avatar;
+	gchar              *filename;
+	GError             *error = NULL;
+
+	g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+	g_return_if_fail (!G_STR_EMPTY (priv->id));
+	g_return_if_fail (data != NULL);
+	g_return_if_fail (len > 0);
+	g_return_if_fail (format != NULL);
+	g_return_if_fail (!G_STR_EMPTY (token));
+
+	/* Load and set the avatar */
+	avatar = empathy_avatar_new (g_memdup (data, len), len,
+				     g_strdup (format),
+				     g_strdup (token));
+	empathy_contact_set_avatar (contact, avatar);
+	empathy_avatar_unref (avatar);
+
+	/* Save to cache if not yet in it */
+	filename = contact_get_avatar_filename (contact, token);
+	if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
+		if (!g_file_set_contents (filename, data, len, &error)) {
+			DEBUG ("Failed to save avatar in cache: %s",
+				error ? error->message : "No error given");
+			g_clear_error (&error);
+		} else {
+			DEBUG ("Avatar saved to %s", filename);
+		}
+	}
+	g_free (filename);
+}
+
+gboolean
+empathy_contact_load_avatar_cache (EmpathyContact *contact,
+				   const gchar    *token)
+{
+	EmpathyContactPriv *priv = GET_PRIV (contact);
+	EmpathyAvatar      *avatar = NULL;
+	gchar              *filename;
+	gchar              *data = NULL;
+	gsize               len;
+	GError             *error = NULL;
+
+	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
+	g_return_val_if_fail (!G_STR_EMPTY (priv->id), FALSE);
+	g_return_val_if_fail (!G_STR_EMPTY (token), FALSE);
+
+	/* Load the avatar from file if it exists */
+	filename = contact_get_avatar_filename (contact, token);
+	if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
+		if (!g_file_get_contents (filename, &data, &len, &error)) {
+			DEBUG ("Failed to load avatar from cache: %s",
+				error ? error->message : "No error given");
+			g_clear_error (&error);
+		}
+	}
+
+	if (data) {
+		DEBUG ("Avatar loaded from %s", filename);
+		avatar = empathy_avatar_new (data, len, NULL, g_strdup (token));
+		empathy_contact_set_avatar (contact, avatar);
+		empathy_avatar_unref (avatar);
+	}
+
+	g_free (filename);
+
+	return data != NULL;
+}
+
+GType
+empathy_avatar_get_type (void)
+{
+	static GType type_id = 0;
+
+	if (!type_id) {
+		type_id = g_boxed_type_register_static ("EmpathyAvatar",
+							(GBoxedCopyFunc) empathy_avatar_ref,
+							(GBoxedFreeFunc) empathy_avatar_unref);
+	}
+
+	return type_id;
+}
+
+EmpathyAvatar *
+empathy_avatar_new (guchar *data,
+		    gsize   len,
+		    gchar  *format,
+		    gchar  *token)
+{
+	EmpathyAvatar *avatar;
+
+	avatar = g_slice_new0 (EmpathyAvatar);
+	avatar->data = data;
+	avatar->len = len;
+	avatar->format = format;
+	avatar->token = token;
+	avatar->refcount = 1;
+
+	return avatar;
+}
+
+void
+empathy_avatar_unref (EmpathyAvatar *avatar)
+{
+	g_return_if_fail (avatar != NULL);
+
+	avatar->refcount--;
+	if (avatar->refcount == 0) {
+		g_free (avatar->data);
+		g_free (avatar->format);
+		g_free (avatar->token);
+		g_slice_free (EmpathyAvatar, avatar);
+	}
+}
+
+EmpathyAvatar *
+empathy_avatar_ref (EmpathyAvatar *avatar)
+{
+	g_return_val_if_fail (avatar != NULL, NULL);
+
+	avatar->refcount++;
+
+	return avatar;
+}
+

Modified: trunk/libempathy/empathy-contact.h
==============================================================================
--- trunk/libempathy/empathy-contact.h	(original)
+++ trunk/libempathy/empathy-contact.h	Tue May 27 17:34:44 2008
@@ -31,8 +31,6 @@
 #include <libmissioncontrol/mc-account.h>
 #include <libmissioncontrol/mission-control.h>
 
-#include "empathy-avatar.h"
-
 G_BEGIN_DECLS
 
 #define EMPATHY_TYPE_CONTACT         (empathy_contact_get_type ())
@@ -54,6 +52,14 @@
 	GObjectClass parent_class;
 };
 
+typedef struct {
+	guchar *data;
+	gsize   len;
+	gchar  *format;
+	gchar  *token;
+	guint   refcount;
+} EmpathyAvatar;
+
 typedef enum {
 	EMPATHY_CAPABILITIES_NONE = 0,
 	EMPATHY_CAPABILITIES_AUDIO = 1 << 0,
@@ -111,6 +117,22 @@
 void                empathy_contact_run_until_ready    (EmpathyContact      *contact,
 							EmpathyContactReady  ready,
 							GMainLoop          **loop);
+void                empathy_contact_load_avatar_data   (EmpathyContact      *contact,
+							const guchar        *data,
+							const gsize          len,
+							const gchar         *format,
+							const gchar         *token);
+gboolean            empathy_contact_load_avatar_cache  (EmpathyContact      *contact,
+							const gchar         *token);
+
+#define EMPATHY_TYPE_AVATAR (empathy_avatar_get_type ())
+GType               empathy_avatar_get_type            (void) G_GNUC_CONST;
+EmpathyAvatar *     empathy_avatar_new                 (guchar              *data,
+							gsize                len,
+							gchar               *format,
+							gchar               *token);
+EmpathyAvatar *     empathy_avatar_ref                 (EmpathyAvatar       *avatar);
+void                empathy_avatar_unref               (EmpathyAvatar       *avatar);
 
 G_END_DECLS
 

Modified: trunk/libempathy/empathy-log-manager.c
==============================================================================
--- trunk/libempathy/empathy-log-manager.c	(original)
+++ trunk/libempathy/empathy-log-manager.c	Tue May 27 17:34:44 2008
@@ -337,7 +337,6 @@
 	for (node = log_node->children; node; node = node->next) {
 		EmpathyMessage     *message;
 		EmpathyContact     *sender;
-		EmpathyAvatar      *avatar = NULL;
 		gchar              *time;
 		time_t              t;
 		gchar              *sender_id;
@@ -361,9 +360,6 @@
 		is_user_str = xmlGetProp (node, "isuser");
 		msg_type_str = xmlGetProp (node, "type");
 
-		if (!G_STR_EMPTY (sender_avatar_token)) {
-			avatar = empathy_avatar_new_from_cache (sender_avatar_token);
-		}
 		if (is_user_str) {
 			is_user = strcmp (is_user_str, "true") == 0;
 		}
@@ -375,9 +371,9 @@
 
 		sender = empathy_contact_new_full (account, sender_id, sender_name);
 		empathy_contact_set_is_user (sender, is_user);
-		if (avatar) {
-			empathy_contact_set_avatar (sender, avatar);
-			empathy_avatar_unref (avatar);
+		if (!G_STR_EMPTY (sender_avatar_token)) {
+			empathy_contact_load_avatar_cache (sender,
+							   sender_avatar_token);
 		}
 
 		message = empathy_message_new (body);

Modified: trunk/libempathy/empathy-tp-contact-factory.c
==============================================================================
--- trunk/libempathy/empathy-tp-contact-factory.c	(original)
+++ trunk/libempathy/empathy-tp-contact-factory.c	Tue May 27 17:34:44 2008
@@ -323,7 +323,6 @@
 					GObject      *tp_factory)
 {
 	EmpathyContact *contact;
-	EmpathyAvatar  *avatar;
 
 	contact = tp_contact_factory_find_by_handle (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
 						     handle);
@@ -335,13 +334,11 @@
 		empathy_contact_get_id (contact),
 		handle);
 
-	avatar = empathy_avatar_new (avatar_data->data,
-				     avatar_data->len,
-				     mime_type,
-				     token);
-
-	empathy_contact_set_avatar (contact, avatar);
-	empathy_avatar_unref (avatar);
+	empathy_contact_load_avatar_data (contact,
+					  avatar_data->data,
+					  avatar_data->len,
+					  mime_type,
+					  token);
 }
 
 static void
@@ -381,11 +378,8 @@
 	}
 
 	/* The avatar changed, search the new one in the cache */
-	avatar = empathy_avatar_new_from_cache (token);
-	if (avatar) {
+	if (empathy_contact_load_avatar_cache (contact, token)) {
 		/* Got from cache, use it */
-		empathy_contact_set_avatar (contact, avatar);
-		empathy_avatar_unref (avatar);
 		return TRUE;
 	}
 
@@ -804,8 +798,6 @@
 						handle_needed_contacts, tp_contact_factory_list_free,
 						G_OBJECT (tp_factory));
 
-	tp_contact_factory_request_everything ((EmpathyTpContactFactory*) tp_factory,
-					       id_needed);
 	tp_cli_connection_call_inspect_handles (priv->connection,
 						-1,
 						TP_HANDLE_TYPE_CONTACT,
@@ -814,6 +806,9 @@
 						id_needed_contacts, tp_contact_factory_list_free,
 						G_OBJECT (tp_factory));
 
+	tp_contact_factory_request_everything ((EmpathyTpContactFactory*) tp_factory,
+					       id_needed);
+
 	g_array_free (handle_needed, TRUE);
 	g_array_free (id_needed, TRUE);
 }

Modified: trunk/megaphone/src/megaphone-applet.c
==============================================================================
--- trunk/megaphone/src/megaphone-applet.c	(original)
+++ trunk/megaphone/src/megaphone-applet.c	Tue May 27 17:34:44 2008
@@ -177,18 +177,16 @@
 							      "avatar_token",
 							      NULL);
 		if (!G_STR_EMPTY (avatar_token)) {
-			avatar = empathy_avatar_new_from_cache (avatar_token);
+			empathy_contact_load_avatar_cache (priv->contact, avatar_token);
+			avatar = empathy_contact_get_avatar (priv->contact);
 		}
 		g_free (avatar_token);
-	} else {
-		empathy_avatar_ref (avatar);
 	}
 
 	if (avatar) {
 		avatar_pixbuf = empathy_pixbuf_from_avatar_scaled (avatar,
 								   priv->image_size - 2,
 								   priv->image_size - 2);
-		empathy_avatar_unref (avatar);
 	} else {
 		GtkIconTheme *icon_theme;
 

Modified: trunk/python/pyempathy/pyempathy.defs
==============================================================================
--- trunk/python/pyempathy/pyempathy.defs	(original)
+++ trunk/python/pyempathy/pyempathy.defs	Tue May 27 17:34:44 2008
@@ -217,47 +217,6 @@
 )
 
 
-;; From empathy-avatar.h
-
-(define-function empathy_avatar_get_type
-  (c-name "empathy_avatar_get_type")
-  (return-type "GType")
-)
-
-(define-function empathy_avatar_new
-  (c-name "empathy_avatar_new")
-  (is-constructor-of "EmpathyAvatar")
-  (return-type "EmpathyAvatar*")
-  (parameters
-    '("const-guchar*" "avatar")
-    '("const-gsize" "len")
-    '("const-gchar*" "format")
-    '("const-gchar*" "token")
-  )
-)
-
-(define-function empathy_avatar_new_from_cache
-  (c-name "empathy_avatar_new_from_cache")
-  (return-type "EmpathyAvatar*")
-  (parameters
-    '("const-gchar*" "token")
-  )
-)
-
-(define-method ref
-  (of-object "EmpathyAvatar")
-  (c-name "empathy_avatar_ref")
-  (return-type "EmpathyAvatar*")
-)
-
-(define-method unref
-  (of-object "EmpathyAvatar")
-  (c-name "empathy_avatar_unref")
-  (return-type "none")
-)
-
-
-
 ;; From empathy-time.h
 
 (define-function empathy_time_get_current
@@ -1099,6 +1058,56 @@
   )
 )
 
+(define-method load_avatar_data
+  (of-object "EmpathyContact")
+  (c-name "empathy_contact_load_avatar_data")
+  (return-type "none")
+  (parameters
+    '("const-guchar*" "data")
+    '("const-gsize" "len")
+    '("const-gchar*" "format")
+    '("const-gchar*" "token")
+  )
+)
+
+(define-method load_avatar_cache
+  (of-object "EmpathyContact")
+  (c-name "empathy_contact_load_avatar_cache")
+  (return-type "gboolean")
+  (parameters
+    '("const-gchar*" "token")
+  )
+)
+
+(define-function empathy_avatar_get_type
+  (c-name "empathy_avatar_get_type")
+  (return-type "GType")
+)
+
+(define-function empathy_avatar_new
+  (c-name "empathy_avatar_new")
+  (is-constructor-of "EmpathyAvatar")
+  (return-type "EmpathyAvatar*")
+  (parameters
+    '("guchar*" "data")
+    '("gsize" "len")
+    '("gchar*" "format")
+    '("gchar*" "token")
+  )
+)
+
+(define-method ref
+  (of-object "EmpathyAvatar")
+  (c-name "empathy_avatar_ref")
+  (return-type "EmpathyAvatar*")
+)
+
+(define-method unref
+  (of-object "EmpathyAvatar")
+  (c-name "empathy_avatar_unref")
+  (return-type "none")
+)
+
 
 
 ;; From empathy-contact-groups.h

Modified: trunk/python/pyempathy/pyempathy.override
==============================================================================
--- trunk/python/pyempathy/pyempathy.override	(original)
+++ trunk/python/pyempathy/pyempathy.override	Tue May 27 17:34:44 2008
@@ -2,7 +2,6 @@
 headers
 #include <Python.h>
 #include <pygobject.h>
-#include "empathy-avatar.h"
 #include "empathy-chatroom.h"
 #include "empathy-chatroom-manager.h"
 #include "empathy-contact.h"

Modified: trunk/python/update-binding.sh
==============================================================================
--- trunk/python/update-binding.sh	(original)
+++ trunk/python/update-binding.sh	Tue May 27 17:34:44 2008
@@ -4,7 +4,6 @@
 # Update the list of headers from Makefile.am
 cd ../libempathy
 python /usr/share/pygtk/2.0/codegen/h2def.py	\
-	empathy-avatar.h			\
 	empathy-time.h				\
 	empathy-status-presets.h		\
 	empathy-debug.h				\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]