tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / remotecontrol / Communicator.cxx
blob0618675559db181fbb5e7d189c21ad445e5d3eb5
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 */
9 #include <algorithm>
10 #include <vector>
12 #include <com/sun/star/frame/Desktop.hpp>
13 #include <com/sun/star/presentation/XPresentation2.hpp>
14 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
15 #include <comphelper/processfactory.hxx>
16 #include <comphelper/documentinfo.hxx>
17 #include <config_version.h>
18 #include <rtl/string.hxx>
19 #include <sal/log.hxx>
21 #include "Communicator.hxx"
22 #include "IBluetoothSocket.hxx"
23 #include "Listener.hxx"
24 #include "Receiver.hxx"
25 #include "Transmitter.hxx"
26 #include <RemoteServer.hxx>
28 using namespace sd;
29 using namespace com::sun::star;
30 using namespace osl;
32 Communicator::Communicator( std::unique_ptr<IBluetoothSocket> pSocket ):
33 Thread( "CommunicatorThread" ),
34 mpSocket( std::move(pSocket) )
38 Communicator::~Communicator()
42 /// Close the underlying socket from another thread to force
43 /// an early exit / termination
44 void Communicator::forceClose()
46 if( mpSocket )
47 mpSocket->close();
50 // Run as a thread
51 void Communicator::execute()
53 pTransmitter.reset( new Transmitter( mpSocket.get() ) );
54 pTransmitter->create();
56 pTransmitter->addMessage( "LO_SERVER_SERVER_PAIRED\n\n"_ostr,
57 Transmitter::PRIORITY_HIGH );
59 pTransmitter->addMessage( "LO_SERVER_INFO\n" LIBO_VERSION_DOTTED "\n\n"_ostr,
60 Transmitter::PRIORITY_HIGH );
62 Receiver aReceiver( pTransmitter.get() );
63 try {
64 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
65 uno::Reference< frame::XFrame > xFrame = xFramesSupplier->getActiveFrame();
67 uno::Reference<presentation::XPresentationSupplier> xPS;
68 if( xFrame.is() )
69 xPS.set( xFrame->getController()->getModel(), uno::UNO_QUERY );
70 uno::Reference<presentation::XPresentation2> xPresentation;
71 if( xPS.is() )
72 xPresentation.set( xPS->getPresentation(), uno::UNO_QUERY );
73 if ( xPresentation.is() && xPresentation->isRunning() )
75 presentationStarted( xPresentation->getController() );
76 OString aBuffer =
77 "slideshow_info\n" +
78 OUStringToOString( ::comphelper::DocumentInfo::getDocumentTitle( xFrame->getController()->getModel() ), RTL_TEXTENCODING_UTF8 ) +
79 "\n\n";
81 pTransmitter->addMessage( aBuffer, Transmitter::PRIORITY_LOW );
83 else
85 pTransmitter->addMessage( "slideshow_finished\n\n"_ostr,
86 Transmitter::PRIORITY_HIGH );
89 catch (uno::RuntimeException &)
93 sal_uInt64 aRet;
94 std::vector<OString> aCommand;
95 while ( true )
97 OString aLine;
98 aRet = mpSocket->readLine( aLine );
99 if ( aRet == 0 )
101 break; // I.e. transmission finished.
103 if ( aLine.getLength() )
105 aCommand.push_back( aLine );
107 else
109 aReceiver.pushCommand( aCommand );
110 aCommand.clear();
114 SAL_INFO ("sdremote", "Exiting transmission loop");
116 disposeListener();
118 pTransmitter->notifyFinished();
119 pTransmitter->join();
120 pTransmitter = nullptr;
122 mpSocket->close();
123 mpSocket.reset();
125 RemoteServer::removeCommunicator( this );
128 void Communicator::informListenerDestroyed()
130 // called only from the Listener::disposing() method
131 // during disposal of this communicator
133 if ( pTransmitter )
134 pTransmitter->addMessage( "slideshow_finished\n\n"_ostr,
135 Transmitter::PRIORITY_HIGH );
138 void Communicator::presentationStarted( const css::uno::Reference<
139 css::presentation::XSlideShowController > &rController )
141 if ( pTransmitter )
143 mListener.set( new Listener( this, pTransmitter.get() ) );
144 mListener->init( rController );
148 void Communicator::disposeListener()
150 if ( mListener.is() )
152 mListener->dispose();
153 mListener = nullptr;
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */