diff options
author | Matúš Kukan <matus.kukan@gmail.com> | 2012-08-09 23:37:32 +0200 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2012-08-14 19:39:46 +0200 |
commit | 7f6b2321a5adbf63fdd50989e58418db93e90454 (patch) | |
tree | 46f33f6ebd468e183f2c554ef6db665de618d638 /tubes | |
parent | 0357b778956a453a700d7b7002a7850071bde70d (diff) |
tubes: use channel's signal closed to know when end the collaboration
Change-Id: I11e0aa2db3b41a166e23c85fd040f883e0d3be08
Diffstat (limited to 'tubes')
-rw-r--r-- | tubes/Library_tubes.mk | 1 | ||||
-rw-r--r-- | tubes/inc/tubes/collaboration.hxx | 2 | ||||
-rw-r--r-- | tubes/inc/tubes/manager.hxx | 1 | ||||
-rw-r--r-- | tubes/source/conference.cxx | 32 | ||||
-rw-r--r-- | tubes/source/contact-list.cxx | 9 | ||||
-rw-r--r-- | tubes/source/manager.cxx | 60 |
6 files changed, 42 insertions, 63 deletions
diff --git a/tubes/Library_tubes.mk b/tubes/Library_tubes.mk index b9edab9577d2..2cdac5f9dd97 100644 --- a/tubes/Library_tubes.mk +++ b/tubes/Library_tubes.mk @@ -51,6 +51,7 @@ $(eval $(call gb_Library_use_libraries,tubes,\ )) $(eval $(call gb_Library_use_externals,tubes,\ + gtk \ telepathy \ )) diff --git a/tubes/inc/tubes/collaboration.hxx b/tubes/inc/tubes/collaboration.hxx index 8aef9378bae6..e3f765c1eeea 100644 --- a/tubes/inc/tubes/collaboration.hxx +++ b/tubes/inc/tubes/collaboration.hxx @@ -27,7 +27,7 @@ public: Collaboration(); virtual ~Collaboration(); - virtual void ContactLeft() const = 0; + virtual void EndCollaboration() const = 0; virtual void PacketReceived( const OString& rPacket ) const = 0; virtual void SaveAndSendFile( TpContact* pContact ) const = 0; virtual void StartCollaboration( TeleConference* pConference ) = 0; diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx index b0825a34b59b..38e5d8cdca14 100644 --- a/tubes/inc/tubes/manager.hxx +++ b/tubes/inc/tubes/manager.hxx @@ -135,6 +135,7 @@ public: static void registerCollaboration( Collaboration* pCollaboration ); static void unregisterCollaboration( Collaboration* pCollaboration ); + static bool existsCollaboration( Collaboration* pCollaboration ); /** Display contact list dialog for all documents. */ static void displayAllContacts(); diff --git a/tubes/source/conference.cxx b/tubes/source/conference.cxx index 8be9cab727e9..ce46cdcf6500 100644 --- a/tubes/source/conference.cxx +++ b/tubes/source/conference.cxx @@ -33,6 +33,7 @@ #include <tubes/file-transfer-helper.h> #include <tubes/manager.hxx> +#include <gtk/gtk.h> #include <telepathy-glib/telepathy-glib.h> #if defined SAL_LOG_INFO @@ -246,6 +247,23 @@ TeleConference::~TeleConference() delete pImpl; } +static void channel_closed_cb( TpChannel *channel, gpointer user_data, GObject * /* weak_object */ ) +{ + Collaboration* pCollaboration = reinterpret_cast<Collaboration*> (user_data); + if (TeleManager::existsCollaboration( pCollaboration )) + { + GtkWidget *dialog = gtk_message_dialog_new( NULL, static_cast<GtkDialogFlags> (0), + GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, + "Contact %s lost, you'll now be working locally.", + tp_contact_get_alias (tp_channel_get_target_contact (channel)) ); + g_signal_connect_swapped (dialog, "response", + G_CALLBACK (gtk_widget_destroy), dialog); + gtk_widget_show_all (dialog); + + pCollaboration->EndCollaboration(); + } +} + void TeleConference::setChannel( TpAccount *pAccount, TpDBusTubeChannel* pChannel ) { @@ -373,8 +391,6 @@ void TeleConference::close() { INFO_LOGGER( "TeleConference::close"); - TeleManager::unregisterDemoConference( this ); - if (mpChannel) tp_cli_channel_call_close( TP_CHANNEL( mpChannel), 5000, TeleConference_ChannelCloseHandler, this, NULL, NULL); else @@ -386,6 +402,8 @@ void TeleConference::finalize() { INFO_LOGGER( "TeleConference::finalize"); + TeleManager::unregisterDemoConference( this ); + if (mpChannel) { g_object_unref( mpChannel); @@ -463,6 +481,16 @@ Collaboration* TeleConference::getCollaboration() const void TeleConference::setCollaboration( Collaboration* pCollaboration ) { mpCollaboration = pCollaboration; + if (mpChannel) + { + GError *error = NULL; + if (!tp_cli_channel_connect_to_closed( TP_CHANNEL (mpChannel), + channel_closed_cb, mpCollaboration, NULL, NULL, &error )) + { + SAL_WARN( "tubes", "Error when connecting to signal closed: " << error->message ); + g_error_free (error); + } + } } void TeleConference::invite( TpContact *pContact ) diff --git a/tubes/source/contact-list.cxx b/tubes/source/contact-list.cxx index 163f4e0b0030..03fc3b1f6956 100644 --- a/tubes/source/contact-list.cxx +++ b/tubes/source/contact-list.cxx @@ -71,7 +71,7 @@ ContactList::~ContactList() mpAccountManager = NULL; } -bool tb_presence_is_online( const TpConnectionPresenceType& presence ) +static bool tb_presence_is_online( const TpConnectionPresenceType& presence ) { switch (presence) { @@ -91,12 +91,7 @@ bool tb_presence_is_online( const TpConnectionPresenceType& presence ) } } -bool tb_account_is_online( TpAccount *account ) -{ - return tb_presence_is_online (tp_account_get_current_presence (account, NULL, NULL)); -} - -bool tb_contact_is_online( TpContact *contact ) +static bool tb_contact_is_online( TpContact *contact ) { return tb_presence_is_online (tp_contact_get_presence_type (contact)); } diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx index 340c0023579f..d900cb61d724 100644 --- a/tubes/source/manager.cxx +++ b/tubes/source/manager.cxx @@ -106,41 +106,6 @@ public: TeleManagerImpl* TeleManager::pImpl = new TeleManagerImpl(); -bool tb_account_is_online( TpAccount* pAccount ); -bool tb_contact_is_online( TpContact* pContact ); - -static void account_presence_changed_cb( TpAccount* pAccount, - guint /* type */, - gchar* /* status */, - gchar* /* message */, - gpointer pUserData ) -{ - if (!tb_account_is_online( pAccount )) - { - TeleConference* pConference = reinterpret_cast<TeleConference*> (pUserData); - pConference->close(); - Collaboration* pCollaboration = pConference->getCollaboration(); - if (pCollaboration) - pCollaboration->ContactLeft(); - } -} - -static void contact_presence_changed_cb( TpContact* pContact, - guint /* type */, - gchar* /* status */, - gchar* /* message */, - gpointer pUserData ) -{ - if (!tb_contact_is_online( pContact )) - { - TeleConference* pConference = reinterpret_cast<TeleConference*> (pUserData); - pConference->close(); - Collaboration* pCollaboration = pConference->getCollaboration(); - if (pCollaboration) - pCollaboration->ContactLeft(); - } -} - static void TeleManager_DBusChannelHandler( TpSimpleHandler* /*handler*/, TpAccount* pAccount, @@ -171,14 +136,6 @@ static void TeleManager_DBusChannelHandler( TeleConference* pConference = new TeleConference( pAccount, TP_DBUS_TUBE_CHANNEL( pChannel ) ); pConference->acceptTube(); TeleManager::addConference( pConference ); - - g_signal_connect( pAccount, "presence-changed", - G_CALLBACK (account_presence_changed_cb), pConference ); - - TpContact* pContact = tp_channel_get_target_contact( pChannel ); - if (pContact) - g_signal_connect( pContact, "presence-changed", - G_CALLBACK (contact_presence_changed_cb), pConference ); } else { @@ -236,6 +193,13 @@ void TeleManager::unregisterCollaboration( Collaboration* pCollaboration ) pImpl->maCollaborations.erase( pCollaboration ); } +bool TeleManager::existsCollaboration( Collaboration* pCollaboration ) +{ + MutexGuard aGuard( GetMutex()); + + return pImpl->maCollaborations.find( pCollaboration ) != pImpl->maCollaborations.end(); +} + void TeleManager::displayAllContacts() { MutexGuard aGuard( GetMutex()); @@ -447,7 +411,6 @@ static void TeleManager_ChannelReadyHandler( g_error_free( pError); return; } - pConference->setChannel( tp_account_channel_request_get_account( pChannelRequest), TP_DBUS_TUBE_CHANNEL (pChannel)); pConference->offerTube(); @@ -690,9 +653,6 @@ TeleConference* TeleManager::startGroupSession( TpAccount *pAccount, if (!pConference->isReady()) return NULL; - g_signal_connect( pAccount, "presence-changed", - G_CALLBACK (account_presence_changed_cb), pConference ); - return pConference; } @@ -768,12 +728,6 @@ TeleConference* TeleManager::startBuddySession( TpAccount *pAccount, TpContact * if (!pConference->isReady()) return NULL; - g_signal_connect( pAccount, "presence-changed", - G_CALLBACK (account_presence_changed_cb), pConference ); - - g_signal_connect( pBuddy, "presence-changed", - G_CALLBACK (contact_presence_changed_cb), pConference ); - return pConference; } |