From 34c6421bddddb2128dd59acc867f73739ac1ca62 Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Mon, 6 Aug 2012 15:29:17 +0200 Subject: tubes: handle TeleConference internally in Collaboration Hopefully, this simplifies the tubes <-> app interface Change-Id: I8933fde490941b259d5d133972db26a09ab380d5 --- tubes/Library_tubes.mk | 1 + tubes/Package_inc.mk | 1 - tubes/inc/tubes/collaboration.hxx | 28 +++++++++++++--------- tubes/inc/tubes/conference.hxx | 9 ++++--- tubes/source/collaboration.cxx | 50 +++++++++++++++++++++++++++++++++++++++ tubes/source/conference.cxx | 11 +++++---- tubes/source/contacts.cxx | 15 +++++------- tubes/source/manager.cxx | 16 ++++++++----- 8 files changed, 95 insertions(+), 36 deletions(-) create mode 100644 tubes/source/collaboration.cxx (limited to 'tubes') diff --git a/tubes/Library_tubes.mk b/tubes/Library_tubes.mk index 2ff9ab2407dd..b9edab9577d2 100644 --- a/tubes/Library_tubes.mk +++ b/tubes/Library_tubes.mk @@ -55,6 +55,7 @@ $(eval $(call gb_Library_use_externals,tubes,\ )) $(eval $(call gb_Library_add_exception_objects,tubes,\ + tubes/source/collaboration \ tubes/source/conference \ tubes/source/contact-list \ tubes/source/contacts \ diff --git a/tubes/Package_inc.mk b/tubes/Package_inc.mk index 1aff70bb00ec..be6266aeca49 100644 --- a/tubes/Package_inc.mk +++ b/tubes/Package_inc.mk @@ -27,7 +27,6 @@ $(eval $(call gb_Package_Package,tubes_inc,$(SRCDIR)/tubes/inc)) $(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/collaboration.hxx,tubes/collaboration.hxx)) -$(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/conference.hxx,tubes/conference.hxx)) $(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/contacts.hxx,tubes/contacts.hxx)) $(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/manager.hxx,tubes/manager.hxx)) $(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/tubesdllapi.h,tubes/tubesdllapi.h)) diff --git a/tubes/inc/tubes/collaboration.hxx b/tubes/inc/tubes/collaboration.hxx index 65595cde1143..15d59d4abf66 100644 --- a/tubes/inc/tubes/collaboration.hxx +++ b/tubes/inc/tubes/collaboration.hxx @@ -13,23 +13,29 @@ #include #include +#include class TeleConference; typedef struct _TpContact TpContact; -class Collaboration +class TUBES_DLLPUBLIC Collaboration { + TeleConference* mpConference; public: - Collaboration() {} - virtual ~Collaboration() {} - - virtual void ContactLeft() = 0; - virtual TeleConference* GetConference() = 0; - virtual sal_uInt64 GetId() = 0; - virtual void PacketReceived( const OString& rPacket ) = 0; - virtual void SetCollaboration( TeleConference* pConference ) = 0; - // TODO: I think this could be moved to TeleManager later. - virtual void SendFile( TpContact* pContact, const OUString& rURL ) = 0; + Collaboration(); + virtual ~Collaboration(); + + virtual void ContactLeft() const = 0; + virtual void PacketReceived( const OString& rPacket ) const = 0; + virtual void SaveAndSendFile( TpContact* pContact, const OUString& rURL ) const = 0; + virtual void StartCollaboration( TeleConference* pConference ) = 0; + + TUBES_DLLPRIVATE TeleConference* GetConference() const; + TUBES_DLLPRIVATE sal_uInt64 GetId() const; + + void SendFile( TpContact* pContact, const OUString& rURL ) const; + void SendPacket( const OString& rPacket ) const; + void SetConference( TeleConference* pConference ); }; #endif // INCLUDED_TUBES_COLLABORATION_HXX diff --git a/tubes/inc/tubes/conference.hxx b/tubes/inc/tubes/conference.hxx index 3f600e06a650..1514b141cd0b 100644 --- a/tubes/inc/tubes/conference.hxx +++ b/tubes/inc/tubes/conference.hxx @@ -30,7 +30,6 @@ #define INCLUDED_TUBES_CONFERENCE_HXX #include -#include "tubes/tubesdllapi.h" #include class Collaboration; @@ -52,21 +51,21 @@ public: ~TeleConference(); /// Close channel and call finalize() - TUBES_DLLPUBLIC void close(); + void close(); /// Unrefs, unregisters from manager and calls dtor if last reference! void finalize(); - TUBES_DLLPUBLIC bool sendPacket( const OString& rPacket ); + bool sendPacket( const OString& rPacket ); void invite( TpContact *pContact ); typedef void (*FileSentCallback)( bool aSuccess, void* pUserData); - TUBES_DLLPUBLIC void sendFile( TpContact* pContact, rtl::OUString &localUri, FileSentCallback pCallback, void* pUserData); + void sendFile( TpContact* pContact, const OUString& rURL, FileSentCallback pCallback, void* pUserData); const OString& getUuid() const { return msUuid; } Collaboration* getCollaboration() const; - TUBES_DLLPUBLIC void setCollaboration( Collaboration* pCollaboration ); + void setCollaboration( Collaboration* pCollaboration ); // --- following only to be called only by manager's callbacks --- // TODO: make friends instead diff --git a/tubes/source/collaboration.cxx b/tubes/source/collaboration.cxx new file mode 100644 index 000000000000..846f5dc51cc7 --- /dev/null +++ b/tubes/source/collaboration.cxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include + +Collaboration::Collaboration() +{ +} + +Collaboration::~Collaboration() +{ + if (mpConference) + mpConference->close(); +} + +TeleConference* Collaboration::GetConference() const +{ + return mpConference; +} + +sal_uInt64 Collaboration::GetId() const +{ + return reinterpret_cast (this); +} + +void Collaboration::SendFile( TpContact* pContact, const OUString& rURL ) const +{ + mpConference->sendFile( pContact, rURL, NULL, NULL ); +} + +void Collaboration::SendPacket( const OString& rPacket ) const +{ + mpConference->sendPacket( rPacket ); +} + +void Collaboration::SetConference( TeleConference* pConference ) +{ + mpConference = pConference; + mpConference->setCollaboration( this ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tubes/source/conference.cxx b/tubes/source/conference.cxx index 88109df68429..bf33ebd27582 100644 --- a/tubes/source/conference.cxx +++ b/tubes/source/conference.cxx @@ -489,7 +489,8 @@ static void TeleConference_TransferDone( EmpathyFTHandler *handler, TpFileTransf { SendFileRequest *request = reinterpret_cast(user_data); - request->mpCallback(true, request->mpUserData); + if (request->mpCallback) + request->mpCallback(true, request->mpUserData); delete request; g_object_unref (handler); } @@ -500,7 +501,8 @@ static void TeleConference_TransferError( EmpathyFTHandler *handler, const GErro SAL_INFO( "tubes", "TeleConference_TransferError: " << error->message); - request->mpCallback(false, request->mpUserData); + if (request->mpCallback) + request->mpCallback(false, request->mpUserData); delete request; g_object_unref (handler); } @@ -511,7 +513,8 @@ static void TeleConference_FTReady( EmpathyFTHandler *handler, GError *error, gp if ( error != 0 ) { - request->mpCallback(error == 0, request->mpUserData); + if (request->mpCallback) + request->mpCallback(error == 0, request->mpUserData); delete request; g_object_unref (handler); } @@ -528,7 +531,7 @@ static void TeleConference_FTReady( EmpathyFTHandler *handler, GError *error, gp // TODO: move sending file to TeleManager extern void TeleManager_fileReceived( const OUString& ); -void TeleConference::sendFile( TpContact* pContact, rtl::OUString &localUri, FileSentCallback pCallback, void* pUserData) +void TeleConference::sendFile( TpContact* pContact, const OUString& localUri, FileSentCallback pCallback, void* pUserData) { INFO_LOGGER( "TeleConference::sendFile"); diff --git a/tubes/source/contacts.cxx b/tubes/source/contacts.cxx index 62cb7bfe0902..508322a69257 100644 --- a/tubes/source/contacts.cxx +++ b/tubes/source/contacts.cxx @@ -98,7 +98,7 @@ class TubeContacts : public ModelessDialog { TpContact* pContact = pAC->mpContact; mpCollaboration->GetConference()->invite( pContact ); - mpCollaboration->SendFile( pContact, OStringToOUString( + mpCollaboration->SaveAndSendFile( pContact, OStringToOUString( mpCollaboration->GetConference()->getUuid(), RTL_TEXTENCODING_UTF8 ) ); } } @@ -117,9 +117,8 @@ class TubeContacts : public ModelessDialog SAL_WARN( "tubes", "Could not start demo session!" ); else { - pConference->setCollaboration( mpCollaboration ); - mpCollaboration->SetCollaboration( pConference ); - mpCollaboration->SendFile( NULL, OStringToOUString( + mpCollaboration->StartCollaboration( pConference ); + mpCollaboration->SaveAndSendFile( NULL, OStringToOUString( pConference->getUuid(), RTL_TEXTENCODING_UTF8 ) ); } } @@ -140,9 +139,8 @@ class TubeContacts : public ModelessDialog tp_contact_get_identifier( pContact ) ); else { - pConference->setCollaboration( mpCollaboration ); - mpCollaboration->SetCollaboration( pConference ); - mpCollaboration->SendFile( pContact, OStringToOUString( + mpCollaboration->StartCollaboration( pConference ); + mpCollaboration->SaveAndSendFile( pContact, OStringToOUString( pConference->getUuid(), RTL_TEXTENCODING_UTF8 ) ); } } @@ -163,8 +161,7 @@ class TubeContacts : public ModelessDialog SAL_WARN( "tubes", "Could not start group session." ); else { - pConference->setCollaboration( mpCollaboration ); - mpCollaboration->SetCollaboration( pConference ); + mpCollaboration->StartCollaboration( pConference ); } } } diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx index f3714978191d..3d87f1969393 100644 --- a/tubes/source/manager.cxx +++ b/tubes/source/manager.cxx @@ -115,12 +115,13 @@ static void account_presence_changed_cb( TpAccount* pAccount, guint /* type */, gchar* /* status */, gchar* /* message */, - gpointer pConference ) + gpointer pUserData ) { if (!tb_account_is_online( pAccount )) { - Collaboration* pCollaboration = - reinterpret_cast (pConference)->getCollaboration(); + TeleConference* pConference = reinterpret_cast (pUserData); + pConference->close(); + Collaboration* pCollaboration = pConference->getCollaboration(); if (pCollaboration) pCollaboration->ContactLeft(); } @@ -130,12 +131,13 @@ static void contact_presence_changed_cb( TpContact* pContact, guint /* type */, gchar* /* status */, gchar* /* message */, - gpointer pConference ) + gpointer pUserData ) { if (!tb_contact_is_online( pContact )) { - Collaboration* pCollaboration = - reinterpret_cast (pConference)->getCollaboration(); + TeleConference* pConference = reinterpret_cast (pUserData); + pConference->close(); + Collaboration* pCollaboration = pConference->getCollaboration(); if (pCollaboration) pCollaboration->ContactLeft(); } @@ -205,6 +207,8 @@ void TeleManager_DBusChannelHandler( void TeleManager::addConference( TeleConference* pConference ) { + SAL_WARN_IF( pConference->getUuid().isEmpty(), "tubes", + "Adding conference with empty UUID should not happen!" ); pImpl->maAcceptedConferences[ pConference->getUuid() ] = pConference; } -- cgit v1.2.3