empathy r2592 - in trunk: libempathy src



Author: xclaesse
Date: Fri Mar  6 11:52:04 2009
New Revision: 2592
URL: http://svn.gnome.org/viewvc/empathy?rev=2592&view=rev

Log:
Moved dispatcher observing and logging into EmpathyLogManager.

Signed-off-by: Jonny Lamb <jonny lamb collabora co uk>

Modified:
   trunk/libempathy/empathy-log-manager.c
   trunk/libempathy/empathy-log-manager.h
   trunk/src/empathy.c

Modified: trunk/libempathy/empathy-log-manager.c
==============================================================================
--- trunk/libempathy/empathy-log-manager.c	(original)
+++ trunk/libempathy/empathy-log-manager.c	Fri Mar  6 11:52:04 2009
@@ -33,6 +33,7 @@
 #include "empathy-log-manager.h"
 #include "empathy-log-source-empathy.h"
 #include "empathy-log-source.h"
+#include "empathy-tp-chat.h"
 #include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
@@ -372,3 +373,77 @@
 
   return empathy_time_to_string_local (t, "%a %d %b %Y");
 }
+
+typedef struct
+{
+  EmpathyLogManager *log_manager;
+  TpChannel *channel;
+} MessageObserveData;
+
+static void
+message_observe_data_free (MessageObserveData *data)
+{
+  g_slice_free (MessageObserveData, data);
+}
+
+static void
+log_manager_chat_received_message_cb (EmpathyTpChat *tp_chat,
+                                      EmpathyMessage *message,
+                                      MessageObserveData *data)
+{
+  GError *error = NULL;
+  TpHandleType handle_type;
+
+  tp_channel_get_handle (data->channel, &handle_type);
+
+  if (!empathy_log_manager_add_message (data->log_manager,
+        tp_channel_get_identifier (data->channel),
+        handle_type == TP_HANDLE_TYPE_ROOM,
+        message, &error))
+    {
+      DEBUG ("Failed to write message: %s",
+          error ? error->message : "No error message");
+
+      if (error)
+        g_error_free (error);
+    }
+}
+
+static void
+log_manager_dispatcher_observe_cb (EmpathyDispatcher *dispatcher,
+                                   EmpathyDispatchOperation *operation,
+                                   EmpathyLogManager *log_manager)
+{
+  GQuark channel_type;
+
+  channel_type = empathy_dispatch_operation_get_channel_type_id (operation);
+
+  if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
+    {
+      EmpathyTpChat *tp_chat;
+      TpChannel *channel;
+      MessageObserveData *data;
+
+      tp_chat = EMPATHY_TP_CHAT (
+          empathy_dispatch_operation_get_channel_wrapper (operation));
+
+      channel = empathy_dispatch_operation_get_channel (operation);
+
+      data = g_slice_new0 (MessageObserveData);
+      data->log_manager = log_manager;
+      data->channel = channel;
+
+      g_signal_connect_data (tp_chat, "message-received",
+          G_CALLBACK (log_manager_chat_received_message_cb), data,
+          (GClosureNotify) message_observe_data_free, 0);
+    }
+}
+
+
+void
+empathy_log_manager_observe (EmpathyLogManager *log_manager,
+                             EmpathyDispatcher *dispatcher)
+{
+  g_signal_connect (dispatcher, "observe",
+      G_CALLBACK (log_manager_dispatcher_observe_cb), log_manager);
+}

Modified: trunk/libempathy/empathy-log-manager.h
==============================================================================
--- trunk/libempathy/empathy-log-manager.h	(original)
+++ trunk/libempathy/empathy-log-manager.h	Fri Mar  6 11:52:04 2009
@@ -29,6 +29,7 @@
 #include <libmissioncontrol/mc-account.h>
 
 #include "empathy-message.h"
+#include "empathy-dispatcher.h"
 
 G_BEGIN_DECLS
 
@@ -92,6 +93,8 @@
 void empathy_log_manager_search_free (GList *hits);
 gchar *empathy_log_manager_get_date_readable (const gchar *date);
 void empathy_log_manager_search_hit_free (EmpathyLogSearchHit *hit);
+void empathy_log_manager_observe (EmpathyLogManager *log_manager,
+    EmpathyDispatcher *dispatcher);
 
 G_END_DECLS
 

Modified: trunk/src/empathy.c
==============================================================================
--- trunk/src/empathy.c	(original)
+++ trunk/src/empathy.c	Fri Mar  6 11:52:04 2009
@@ -130,58 +130,6 @@
 }
 
 static void
-received_message_cb (EmpathyTpChat  *tp_chat,
-		     EmpathyMessage *message,
-		     TpChannel      *channel)
-{
-	EmpathyLogManager *log_manager;
-	GError            *error = NULL;
-	TpHandleType       handle_type;
-
-	tp_channel_get_handle (channel, &handle_type);
-
-	log_manager = empathy_log_manager_dup_singleton ();
-
-	if (!empathy_log_manager_add_message (log_manager,
-					     tp_channel_get_identifier (channel),
-					     handle_type == TP_HANDLE_TYPE_ROOM,
-					     message,
-					     &error)) {
-		DEBUG ("Failed to write message: %s",
-			error ? error->message : "No error message");
-
-		if (error) {
-			g_error_free (error);
-		}
-	}
-
-	g_object_unref (log_manager);
-}
-
-static void
-observe_cb (EmpathyDispatcher        *dispatcher,
-	    EmpathyDispatchOperation *operation,
-	    gpointer                  user_data)
-{
-	GQuark channel_type;
-
-	channel_type = empathy_dispatch_operation_get_channel_type_id (operation);
-
-	if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) {
-		EmpathyTpChat *tp_chat;
-		TpChannel *channel;
-
-		tp_chat = EMPATHY_TP_CHAT (
-			empathy_dispatch_operation_get_channel_wrapper (operation));
-
-		channel = empathy_dispatch_operation_get_channel (operation);
-
-		g_signal_connect (tp_chat, "message-received",
-			G_CALLBACK (received_message_cb), channel);
-	}
-}
-
-static void
 service_ended_cb (MissionControl *mc,
 		  gpointer        user_data)
 {
@@ -464,6 +412,7 @@
 	guint32            startup_timestamp;
 	EmpathyStatusIcon *icon;
 	EmpathyDispatcher *dispatcher;
+	EmpathyLogManager *log_manager;
 	EmpathyChatroomManager *chatroom_manager;
 	EmpathyCallFactory *call_factory;
 	GtkWidget         *window;
@@ -599,7 +548,10 @@
 	/* Handle channels */
 	dispatcher = empathy_dispatcher_dup_singleton ();
 	g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL);
-	g_signal_connect (dispatcher, "observe", G_CALLBACK (observe_cb), NULL);
+
+	/* Logging */
+	log_manager = empathy_log_manager_dup_singleton ();
+	empathy_log_manager_observe (log_manager, dispatcher);
 
 	chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
 	empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
@@ -617,6 +569,7 @@
 	g_object_unref (mc);
 	g_object_unref (idle);
 	g_object_unref (icon);
+	g_object_unref (log_manager);
 	g_object_unref (dispatcher);
 	g_object_unref (chatroom_manager);
 



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