From 603c2cb9dd33ba7fbfc4865b20beee7896b2dc8a Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Fri, 8 Jun 2012 21:10:59 +0200 Subject: tubes: remove ScCollaboration layer --- sc/source/ui/collab/collab.cxx | 126 --------------------------------------- sc/source/ui/collab/sendfunc.cxx | 82 +++++++++++++++---------- sc/source/ui/inc/collab.hxx | 76 ----------------------- 3 files changed, 52 insertions(+), 232 deletions(-) delete mode 100644 sc/source/ui/collab/collab.cxx delete mode 100644 sc/source/ui/inc/collab.hxx (limited to 'sc/source') diff --git a/sc/source/ui/collab/collab.cxx b/sc/source/ui/collab/collab.cxx deleted file mode 100644 index d14b42e26eb2..000000000000 --- a/sc/source/ui/collab/collab.cxx +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * Version: MPL 1.1 / GPLv3+ / LGPLv3+ - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License or as specified alternatively below. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * Major Contributor(s): - * Copyright (C) 2012 Red Hat, Inc., Eike Rathke - * - * All Rights Reserved. - * - * For minor contributions see the git repository. - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 3 or later (the "GPLv3+"), or - * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), - * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable - * instead of those above. - */ - -#include "collab.hxx" -#include -#include -#include - -ScCollaboration::ScCollaboration() - : - mpAccount( NULL), - mpContact( NULL), - mpManager( NULL) -{ -} - - -ScCollaboration::~ScCollaboration() -{ - if (mpAccount) - g_object_unref( mpAccount); - if (mpContact) - g_object_unref( mpContact); - - mpManager->unref(); - mpManager = NULL; -} - - -void ScCollaboration::receivedFile( const rtl::OUString &rFileURL ) -{ - fprintf( stderr, "file recieved '%s'\n", - rtl::OUStringToOString( rFileURL, RTL_TEXTENCODING_UTF8 ).getStr() ); - sigFileReceived( rFileURL ); -} - -void ScCollaboration::packetReceivedCallback( TeleConference *pConference, TelePacket &rPacket ) -{ - rtl::OString aString( rPacket.getData(), rPacket.getSize()); - /* Relay the signal out… */ - sigPacketReceived( pConference, aString); -} - -bool ScCollaboration::initManager(bool bAcceptIncoming) -{ - mpManager = TeleManager::get(bAcceptIncoming); - mpManager->sigPacketReceived.connect( - boost::bind( &ScCollaboration::packetReceivedCallback, this, _1, _2 )); - mpManager->connect(); - mpManager->prepareAccountManager(); - mpManager->sigFileReceived.connect( - boost::bind( &ScCollaboration::receivedFile, this, _1 )); - return true; -} - - -bool ScCollaboration::initAccountContact() -{ - ContactList* pContactList = mpManager->getContactList(); - AccountContactPairV aVec( pContactList->getContacts()); - - fprintf( stderr, "%u contacts\n", (int) aVec.size() ); - if (aVec.empty()) - return false; - - /* TODO: select a pair, for now just take the first */ - mpAccount = aVec[0].first; - mpContact = aVec[0].second; - fprintf( stderr, "picked %s\n", tp_contact_get_identifier( mpContact ) ); - return true; -} - - -bool ScCollaboration::startCollaboration() -{ - bool bOk = mpManager->startBuddySession( mpAccount, mpContact); - return bOk; -} - - -bool ScCollaboration::sendPacket( const rtl::OString& rString ) -{ - TelePacket aPacket( "sender", rString.getStr(), rString.getLength()); - bool bOk = mpManager->sendPacket( aPacket); - return bOk; -} - - -extern "C" { - static void file_sent_cb( bool aSuccess, void* /* pUserData */ ) - { - fprintf( stderr, "File send %s\n", aSuccess ? "success" : "failed" ); - } -} - -void ScCollaboration::sendFile( rtl::OUString &rFileURL ) -{ - mpManager->sendFile( rFileURL, file_sent_cb, NULL ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/collab/sendfunc.cxx b/sc/source/ui/collab/sendfunc.cxx index aa16ce9c124d..9c04e0dbdc69 100644 --- a/sc/source/ui/collab/sendfunc.cxx +++ b/sc/source/ui/collab/sendfunc.cxx @@ -28,15 +28,16 @@ #include "sal/config.h" +#include #include #include "cell.hxx" +#include "contacts.hxx" #include "docsh.hxx" #include "docfunc.hxx" -#include "collab.hxx" -#include "contacts.hxx" #include #include +#include // new file send/recv fun ... #include @@ -257,7 +258,6 @@ public: class ScDocFuncRecv { boost::shared_ptr mpChain; - boost::shared_ptr mpCollab; protected: ScDocFuncRecv() {} @@ -270,12 +270,7 @@ public: } virtual ~ScDocFuncRecv() {} - void SetCollaboration( boost::shared_ptr& pCollab ) - { - mpCollab = pCollab; - } - - void packetReceived( TeleConference* pConference, const rtl::OString & ); + void packetReceived( TeleConference*, TelePacket &rPacket ); virtual void fileReceived( const rtl::OUString &rStr ); virtual void RecvMessage( const rtl::OString &rString ) @@ -315,9 +310,10 @@ public: } }; -void ScDocFuncRecv::packetReceived( TeleConference*, const rtl::OString &rStr) +void ScDocFuncRecv::packetReceived( TeleConference*, TelePacket &rPacket ) { - RecvMessage( rStr); + rtl::OString aString( rPacket.getData(), rPacket.getSize() ); + RecvMessage( aString ); } void ScDocFuncRecv::fileReceived( const rtl::OUString &rStr ) @@ -418,16 +414,27 @@ class ScDocFuncDemo : public ScDocFuncRecv } }; +extern "C" +{ + static void file_sent_cb( bool aSuccess, void* /* pUserData */ ) + { + fprintf( stderr, "File send %s\n", aSuccess ? "success" : "failed" ); + } +} + class ScDocFuncSend : public ScDocFunc { boost::shared_ptr mpDirect; - boost::shared_ptr mpCollab; + TeleManager *mpManager; void SendMessage( ScChangeOpWriter &rOp ) { fprintf( stderr, "Op: '%s'\n", rOp.toString().getStr() ); - if (mpCollab) - mpCollab->sendPacket( rOp.toString()); + if (mpManager) + { + TelePacket aPacket( "sender", rOp.toString().getStr(), rOp.toString().getLength() ); + mpManager->sendPacket( aPacket ); + } else // local demo mode mpDirect->RecvMessage( rOp.toString() ); } @@ -457,8 +464,8 @@ class ScDocFuncSend : public ScDocFunc fprintf( stderr, "Temp file is '%s'\n", rtl::OUStringToOString( aFileURL, RTL_TEXTENCODING_UTF8 ).getStr() ); - if ( mpCollab ) - mpCollab->sendFile( aFileURL ); + if (mpManager) + mpManager->sendFile( aFileURL, file_sent_cb, NULL ); else mpDirect->fileReceived( aFileURL ); @@ -470,15 +477,16 @@ public: // we don't need the rDocSh hack/pointer ScDocFuncSend( ScDocShell& rDocSh, boost::shared_ptr pDirect ) : ScDocFunc( rDocSh ), - mpDirect( pDirect ) + mpDirect( pDirect ), + mpManager( NULL ) { fprintf( stderr, "Sender created !\n" ); } virtual ~ScDocFuncSend() {} - void SetCollaboration( boost::shared_ptr& pCollab ) + void SetCollaboration( bool bIsMaster ) { - mpCollab = pCollab; + mpManager = TeleManager::get( !bIsMaster ); } virtual void EnterListAction( sal_uInt16 nNameResId ) @@ -625,27 +633,41 @@ SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc() boost::shared_ptr pDirect( new ScDocFuncDirect( *this ) ); boost::shared_ptr pReceiver( new ScDocFuncRecv( pDirect ) ); ScDocFuncSend* pSender = new ScDocFuncSend( *this, pReceiver ); - boost::shared_ptr pCollab( new ScCollaboration ); - pCollab->sigPacketReceived.connect( - boost::bind( &ScDocFuncRecv::packetReceived, pReceiver, _1, _2 )); - pCollab->sigFileReceived.connect( - boost::bind( &ScDocFuncRecv::fileReceived, pReceiver, _1)); + TeleManager *pManager = TeleManager::get( !bIsMaster ); bool bOk = true; - bOk = bOk && pCollab->initManager(!bIsMaster); + + pManager->sigPacketReceived.connect( + boost::bind( &ScDocFuncRecv::packetReceived, pReceiver.get(), _1, _2 )); + pManager->sigFileReceived.connect( + boost::bind( &ScDocFuncRecv::fileReceived, pReceiver.get(), _1 )); + + bOk = bOk && pManager->connect(); + pManager->prepareAccountManager(); + if (bIsMaster) { - bOk = bOk && pCollab->initAccountContact(); - bOk = bOk && pCollab->startCollaboration(); + ContactList* pContactList = pManager->getContactList(); + AccountContactPairV aVec( pContactList->getContacts()); + + fprintf( stderr, "%u contacts\n", (int) aVec.size() ); + if (aVec.empty()) + bOk = false; + else + { + /* TODO: select a pair, for now just take the first */ + TpAccount* pAccount = aVec[0].first; + TpContact* pContact = aVec[0].second; + fprintf( stderr, "picked %s\n", tp_contact_get_identifier( pContact ) ); + bOk = bOk && pManager->startBuddySession( pAccount, pContact ); + } } if (bOk) { - pReceiver->SetCollaboration( pCollab); - pSender->SetCollaboration( pCollab); + pSender->SetCollaboration( bIsMaster ); } else { fprintf( stderr, "Could not start collaboration.\n"); - // pCollab shared_ptr will be destructed } return pSender; } diff --git a/sc/source/ui/inc/collab.hxx b/sc/source/ui/inc/collab.hxx deleted file mode 100644 index 65700c94ebbe..000000000000 --- a/sc/source/ui/inc/collab.hxx +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * Version: MPL 1.1 / GPLv3+ / LGPLv3+ - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License or as specified alternatively below. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * Major Contributor(s): - * Copyright (C) 2012 Red Hat, Inc., Eike Rathke - * - * All Rights Reserved. - * - * For minor contributions see the git repository. - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 3 or later (the "GPLv3+"), or - * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), - * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable - * instead of those above. - */ - -#ifndef INCLUDED_SC_COLLAB_HXX -#define INCLUDED_SC_COLLAB_HXX - -#include -#include - -typedef struct _TpContact TpContact; -typedef struct _TpAccount TpAccount; -class TeleManager; -class TeleConference; -class TelePacket; -namespace rtl { class OString; class OUString; } - -class ScCollaboration -{ -public: - - ScCollaboration(); - ~ScCollaboration(); - - bool initManager(bool bAcceptIncoming); - bool initAccountContact(); - bool startCollaboration(); - - bool sendPacket( const rtl::OString& rString ); - /** Emitted when a packet is received - */ - boost::signals2::signal sigPacketReceived; - - void sendFile( rtl::OUString &rFileURL ); - /** Emitted when a file is received - */ - boost::signals2::signal sigFileReceived; - - /* Internal callbacks */ - void packetReceivedCallback( TeleConference *pConference, TelePacket &rPacket ); - void receivedFile( const rtl::OUString &rFileURL ); - -private: - - TpAccount* mpAccount; - TpContact* mpContact; - TeleManager* mpManager; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit