diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2009-03-06 19:52:04 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-03-06 19:52:04 +0800 |
commit | 2e950aee6b42d1298a11af611b0b190be168e49c (patch) | |
tree | d4ae1f38f9be45453b9403b8bfebbfc54c559271 | |
parent | 80d1a3ed0b043624bf814fa6150bd22fedef80ad (diff) | |
download | gsoc2013-empathy-2e950aee6b42d1298a11af611b0b190be168e49c.tar gsoc2013-empathy-2e950aee6b42d1298a11af611b0b190be168e49c.tar.gz gsoc2013-empathy-2e950aee6b42d1298a11af611b0b190be168e49c.tar.bz2 gsoc2013-empathy-2e950aee6b42d1298a11af611b0b190be168e49c.tar.lz gsoc2013-empathy-2e950aee6b42d1298a11af611b0b190be168e49c.tar.xz gsoc2013-empathy-2e950aee6b42d1298a11af611b0b190be168e49c.tar.zst gsoc2013-empathy-2e950aee6b42d1298a11af611b0b190be168e49c.zip |
Moved dispatcher observing and logging into EmpathyLogManager.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
svn path=/trunk/; revision=2592
-rw-r--r-- | libempathy/empathy-log-manager.c | 75 | ||||
-rw-r--r-- | libempathy/empathy-log-manager.h | 3 | ||||
-rw-r--r-- | src/empathy.c | 59 |
3 files changed, 84 insertions, 53 deletions
diff --git a/libempathy/empathy-log-manager.c b/libempathy/empathy-log-manager.c index 1593ff4d0..2b001ac0a 100644 --- a/libempathy/empathy-log-manager.c +++ b/libempathy/empathy-log-manager.c @@ -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 @@ empathy_log_manager_get_date_readable (const gchar *date) 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); +} diff --git a/libempathy/empathy-log-manager.h b/libempathy/empathy-log-manager.h index 688cb11ff..4ec2c9019 100644 --- a/libempathy/empathy-log-manager.h +++ b/libempathy/empathy-log-manager.h @@ -29,6 +29,7 @@ #include <libmissioncontrol/mc-account.h> #include "empathy-message.h" +#include "empathy-dispatcher.h" G_BEGIN_DECLS @@ -92,6 +93,8 @@ GList *empathy_log_manager_search_new (EmpathyLogManager *manager, 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 diff --git a/src/empathy.c b/src/empathy.c index 5ad38a9e8..10a2ce75f 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -130,58 +130,6 @@ dispatch_cb (EmpathyDispatcher *dispatcher, } 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 @@ main (int argc, char *argv[]) guint32 startup_timestamp; EmpathyStatusIcon *icon; EmpathyDispatcher *dispatcher; + EmpathyLogManager *log_manager; EmpathyChatroomManager *chatroom_manager; EmpathyCallFactory *call_factory; GtkWidget *window; @@ -599,7 +548,10 @@ main (int argc, char *argv[]) /* 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 @@ main (int argc, char *argv[]) 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); |