fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / remotecontrol / Receiver.cxx
blobc3fe6fcb80dd2c269fc35625a271009f1d7e8b1d
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 "Receiver.hxx"
10 #include <string.h>
11 #include <com/sun/star/presentation/XSlideShowController.hpp>
12 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
13 #include <com/sun/star/presentation/XPresentation2.hpp>
14 #include <com/sun/star/frame/Desktop.hpp>
15 #include <com/sun/star/frame/XFramesSupplier.hpp>
16 #include <com/sun/star/uno/RuntimeException.hpp>
19 #include <comphelper/processfactory.hxx>
20 #include <osl/file.hxx>
21 #include <rtl/ustrbuf.hxx>
22 #include <rtl/strbuf.hxx>
24 using namespace sd;
25 using namespace ::com::sun::star;
26 using namespace ::osl;
27 using namespace std;
29 Receiver::Receiver( Transmitter *aTransmitter )
31 pTransmitter = aTransmitter;
32 SetTimeout( 0 );
35 Receiver::~Receiver()
39 // Bounce the commands to the main thread to avoid threading woes
40 void Receiver::pushCommand( const std::vector<OString> &rCommand )
42 SolarMutexGuard aGuard;
43 maExecQueue.push_back( rCommand );
44 Start();
47 void Receiver::Timeout()
49 if( maExecQueue.size() )
51 std::vector< OString > aCommands( maExecQueue.front() );
52 maExecQueue.pop_front();
53 if( !aCommands.empty() )
54 executeCommand( aCommands );
55 Start();
57 else
58 Stop();
61 void Receiver::executeCommand( const std::vector<OString> &aCommand )
63 uno::Reference<presentation::XSlideShowController> xSlideShowController;
64 uno::Reference<presentation::XPresentation2> xPresentation;
65 try {
66 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
67 uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_QUERY_THROW );
68 uno::Reference<presentation::XPresentationSupplier> xPS ( xFrame->getController()->getModel(), uno::UNO_QUERY_THROW);
69 xPresentation = uno::Reference<presentation::XPresentation2>(
70 xPS->getPresentation(), uno::UNO_QUERY_THROW);
71 // Throws an exception if now slideshow running
72 xSlideShowController = uno::Reference<presentation::XSlideShowController>(
73 xPresentation->getController(), uno::UNO_QUERY_THROW );
75 catch (uno::RuntimeException &)
79 if ( aCommand[0].equals( "transition_next" ) )
81 if ( xSlideShowController.is() )
82 xSlideShowController->gotoNextEffect();
84 else if ( aCommand[0].equals( "transition_previous" ) )
86 if ( xSlideShowController.is() )
87 xSlideShowController->gotoPreviousEffect();
89 else if ( aCommand[0].equals( "goto_slide" ) )
91 // FIXME: if 0 returned, then not a valid number
92 sal_Int32 aSlide = aCommand[1].toInt32();
93 if ( xSlideShowController.is() &&
94 xSlideShowController->getCurrentSlideIndex() != aSlide )
96 xSlideShowController->gotoSlideIndex( aSlide );
99 else if ( aCommand[0].equals( "presentation_start" ) )
101 if ( xPresentation.is() )
102 xPresentation->start();
104 else if ( aCommand[0].equals( "presentation_stop" ) )
106 if ( xPresentation.is() )
107 xPresentation->end();
109 else if ( aCommand[0].equals( "presentation_blank_screen" ) )
111 sal_Int32 aColour = 0; // Default is black
112 if ( aCommand.size() > 1 )
114 // aColour = FIXME: get the colour in some format from this string
115 // Determine the formatting first.
117 if ( xSlideShowController.is() )
119 xSlideShowController->blankScreen( aColour );
122 else if ( aCommand[0].equals( "presentation_resume" ) )
124 if ( xSlideShowController.is() )
126 xSlideShowController->resume();
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */