From 2e950aee6b42d1298a11af611b0b190be168e49c Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Fri, 6 Mar 2009 11:52:04 +0000 Subject: Moved dispatcher observing and logging into EmpathyLogManager. Signed-off-by: Jonny Lamb svn path=/trunk/; revision=2592 --- libempathy/empathy-log-manager.c | 75 ++++++++++++++++++++++++++++++++++++++++ libempathy/empathy-log-manager.h | 3 ++ 2 files changed, 78 insertions(+) (limited to 'libempathy') 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 #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 -- cgit v1.2.3