Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / collab / sccollaboration.cxx
blob7dd6ef9eba2ec4b43a6ba9981b6563f39a72a91d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "sccollaboration.hxx"
12 #include "docsh.hxx"
13 #include "sendfunc.hxx"
14 #include <com/sun/star/document/XDocumentRecovery.hpp>
15 #include <unotools/mediadescriptor.hxx>
16 #include <unotools/tempfile.hxx>
17 #include <unotools/localfilehelper.hxx>
19 ScCollaboration::ScCollaboration( ScDocShell* pScDocShell ) :
20 mpScDocShell( pScDocShell )
24 ScCollaboration::~ScCollaboration()
28 void ScCollaboration::EndCollaboration() const
30 ScDocFuncSend* pSender = GetScDocFuncSend();
31 if (pSender)
33 delete pSender;
34 mpScDocShell->SetDocFunc( new ScDocFuncDirect( *mpScDocShell ) );
38 void ScCollaboration::PacketReceived( const OString& rPacket ) const
40 ScDocFuncSend* pSender = GetScDocFuncSend();
41 if (pSender)
42 return pSender->RecvMessage( rPacket );
45 void ScCollaboration::SaveAndSendFile( TpContact* pContact ) const
47 OUString aTmpPath = utl::TempFile::CreateTempName();
48 aTmpPath += ".ods";
50 OUString aFileURL;
51 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aTmpPath, aFileURL );
53 utl::MediaDescriptor aDescriptor;
54 // some issue with hyperlinks:
55 aDescriptor[utl::MediaDescriptor::PROP_DOCUMENTBASEURL()] <<= OUString();
56 try {
57 css::uno::Reference< css::document::XDocumentRecovery > xDocRecovery(
58 mpScDocShell->GetBaseModel(), css::uno::UNO_QUERY_THROW);
60 xDocRecovery->storeToRecoveryFile( aFileURL, aDescriptor.getAsConstPropertyValueList() );
61 } catch (const css::uno::Exception &ex) {
62 SAL_WARN( "sc.tubes", "Exception when saving file " << aFileURL );
65 SendFile( pContact, aFileURL );
67 // FIXME: unlink the file after send ...
70 void ScCollaboration::StartCollaboration( TeleConference* pConference )
72 SetConference( pConference );
73 ScDocFunc* pDocFunc = &mpScDocShell->GetDocFunc();
74 ScDocFuncSend* pSender = dynamic_cast<ScDocFuncSend*> (pDocFunc);
75 if (!pSender)
77 // This means pDocFunc has to be ScDocFuncDirect* and we are not collaborating yet.
78 pSender = new ScDocFuncSend( *mpScDocShell, dynamic_cast<ScDocFuncDirect*> (pDocFunc), this );
79 mpScDocShell->SetDocFunc( pSender );
83 // --- private ---
85 ScDocFuncSend* ScCollaboration::GetScDocFuncSend() const
87 return dynamic_cast<ScDocFuncSend*> (&mpScDocShell->GetDocFunc());
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */