diff options
author | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2009-01-10 00:13:15 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-10 00:13:15 +0800 |
commit | 1e854701c64c93a7aa836504c9bd9c76ee2a6704 (patch) | |
tree | 63612498f583ff8c10ba987591d504b4c5519f5b /libempathy | |
parent | fece418a6d39950fbdf86db44b503029046250dc (diff) | |
download | gsoc2013-empathy-1e854701c64c93a7aa836504c9bd9c76ee2a6704.tar gsoc2013-empathy-1e854701c64c93a7aa836504c9bd9c76ee2a6704.tar.gz gsoc2013-empathy-1e854701c64c93a7aa836504c9bd9c76ee2a6704.tar.bz2 gsoc2013-empathy-1e854701c64c93a7aa836504c9bd9c76ee2a6704.tar.lz gsoc2013-empathy-1e854701c64c93a7aa836504c9bd9c76ee2a6704.tar.xz gsoc2013-empathy-1e854701c64c93a7aa836504c9bd9c76ee2a6704.tar.zst gsoc2013-empathy-1e854701c64c93a7aa836504c9bd9c76ee2a6704.zip |
Act as an observer
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
svn path=/trunk/; revision=2148
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-chatroom-manager.c | 88 | ||||
-rw-r--r-- | libempathy/empathy-chatroom-manager.h | 3 |
2 files changed, 91 insertions, 0 deletions
diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c index 3c2eb66bb..4bda38136 100644 --- a/libempathy/empathy-chatroom-manager.c +++ b/libempathy/empathy-chatroom-manager.c @@ -31,6 +31,7 @@ #include <libxml/parser.h> #include <libxml/tree.h> +#include "empathy-tp-chat.h" #include "empathy-chatroom-manager.h" #include "empathy-utils.h" @@ -652,3 +653,90 @@ chatroom_manager_file_save (EmpathyChatroomManager *manager) return TRUE; } + +static void +empathy_chatroom_manager_chat_destroyed_cb (EmpathyTpChat *chat, + gpointer user_data) +{ + EmpathyChatroomManager *manager = EMPATHY_CHATROOM_MANAGER (user_data); + McAccount *account = empathy_tp_chat_get_account (chat); + EmpathyChatroom *chatroom; + const gchar *roomname; + gboolean favorite; + + roomname = empathy_tp_chat_get_id (chat); + chatroom = empathy_chatroom_manager_find (manager, account, roomname); + + if (chatroom == NULL) + return; + + g_object_get (chatroom, "favorite", &favorite, NULL); + + if (!favorite) + { + /* Remove the chatroom from the list, unless it's in the list of + * favourites.. (seems strange to handle this at such a low level.. */ + empathy_chatroom_manager_remove (manager, chatroom); + } +} + +static void +empathy_chatroom_manager_observe_channel_cb (EmpathyDispatcher *dispatcher, + EmpathyDispatchOperation *operation, gpointer user_data) +{ + EmpathyChatroomManager *manager = EMPATHY_CHATROOM_MANAGER (user_data); + EmpathyChatroom *chatroom; + TpChannel *channel; + EmpathyTpChat *chat; + const gchar *roomname; + GQuark channel_type; + TpHandleType handle_type; + McAccount *account; + + channel_type = empathy_dispatch_operation_get_channel_type_id (operation); + + /* Observe Text channels to rooms only */ + if (channel_type != TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) + return; + + channel = empathy_dispatch_operation_get_channel (operation); + tp_channel_get_handle (channel, &handle_type); + + if (handle_type != TP_HANDLE_TYPE_ROOM) + goto out; + + chat = EMPATHY_TP_CHAT ( + empathy_dispatch_operation_get_channel_wrapper (operation)); + account = empathy_tp_chat_get_account (chat); + + roomname = empathy_tp_chat_get_id (chat); + + chatroom = empathy_chatroom_manager_find (manager, account, roomname); + + if (chatroom == NULL) + { + chatroom = empathy_chatroom_new_full (account, roomname, roomname, + FALSE); + empathy_chatroom_manager_add (manager, chatroom); + g_object_unref (chatroom); + } + + /* A TpChat is always destroyed as it only gets unreffed after the channel + * has been invalidated in the dispatcher.. */ + g_signal_connect (chat, "destroy", + G_CALLBACK (empathy_chatroom_manager_chat_destroyed_cb), + manager); + + g_object_unref (account); + g_object_unref (chat); +out: + g_object_unref (channel); +} + +void +empathy_chatroom_manager_observe (EmpathyChatroomManager *manager, + EmpathyDispatcher *dispatcher) +{ + g_signal_connect (dispatcher, "observe", + G_CALLBACK (empathy_chatroom_manager_observe_channel_cb), manager); +} diff --git a/libempathy/empathy-chatroom-manager.h b/libempathy/empathy-chatroom-manager.h index c070005ab..b8e739ad4 100644 --- a/libempathy/empathy-chatroom-manager.h +++ b/libempathy/empathy-chatroom-manager.h @@ -30,6 +30,7 @@ #include <libmissioncontrol/mc-account.h> #include "empathy-chatroom.h" +#include "empathy-dispatcher.h" G_BEGIN_DECLS @@ -65,6 +66,8 @@ GList * empathy_chatroom_manager_get_chatrooms (EmpathyChatroomMa McAccount *account); guint empathy_chatroom_manager_get_count (EmpathyChatroomManager *manager, McAccount *account); +void empathy_chatroom_manager_observe (EmpathyChatroomManager *manager, + EmpathyDispatcher *dispatcher); G_END_DECLS |