LibreOffice Module sd (master) 1
Receiver.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 <com/sun/star/presentation/XSlideShowController.hpp>
11#include <com/sun/star/presentation/XPresentationSupplier.hpp>
12#include <com/sun/star/presentation/XPresentation2.hpp>
13#include <com/sun/star/frame/Desktop.hpp>
14#include <com/sun/star/uno/RuntimeException.hpp>
15
17#include <sal/log.hxx>
18#include <com/sun/star/beans/PropertyValue.hpp>
19#include <vcl/svapp.hxx>
21
22using namespace sd;
23using namespace ::osl;
24using namespace ::com::sun::star;
25using namespace ::com::sun::star::lang;
26using namespace ::com::sun::star::uno;
27using namespace ::com::sun::star::presentation;
28using namespace ::com::sun::star::beans;
29
30Receiver::Receiver( Transmitter *aTransmitter ) : Timer("sd Receiver")
31{
32 pTransmitter = aTransmitter;
33 SetTimeout( 0 );
34}
35
37{
38}
39
40// Bounce the commands to the main thread to avoid threading woes
41void Receiver::pushCommand( const std::vector<OString> &rCommand )
42{
43 SolarMutexGuard aGuard;
44 maExecQueue.push_back( rCommand );
45 Start();
46}
47
49{
50 if( !maExecQueue.empty() )
51 {
52 std::vector< OString > aCommands( maExecQueue.front() );
53 maExecQueue.pop_front();
54 if( !aCommands.empty() )
55 executeCommand( aCommands );
56 Start();
57 }
58 else
59 Stop();
60}
61
62void Receiver::executeCommand( const std::vector<OString> &aCommand )
63{
64 uno::Reference<presentation::XSlideShowController> xSlideShowController;
65 uno::Reference<presentation::XPresentation2> xPresentation;
66 uno::Reference<presentation::XSlideShow> xSlideShow;
67 try {
68 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
69 uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_SET_THROW );
70 uno::Reference<presentation::XPresentationSupplier> xPS ( xFrame->getController()->getModel(), uno::UNO_QUERY_THROW);
71 xPresentation.set( xPS->getPresentation(), uno::UNO_QUERY_THROW);
72 // Throws an exception if no slideshow running
73 xSlideShowController.set( xPresentation->getController(), uno::UNO_SET_THROW );
74 xSlideShow.set( xSlideShowController->getSlideShow(), uno::UNO_SET_THROW );
75 }
76 catch (uno::RuntimeException &)
77 {
78 }
79
80 if ( aCommand[0] == "transition_next" )
81 {
82 if ( xSlideShowController.is() )
83 xSlideShowController->gotoNextEffect();
84 }
85 else if ( aCommand[0] == "transition_previous" )
86 {
87 if ( xSlideShowController.is() )
88 xSlideShowController->gotoPreviousEffect();
89 }
90 else if ( aCommand[0] == "goto_slide" )
91 {
92 // FIXME: if 0 returned, then not a valid number
93 sal_Int32 aSlide = aCommand[1].toInt32();
94 if ( xSlideShowController.is() &&
95 xSlideShowController->getCurrentSlideIndex() != aSlide )
96 {
97 xSlideShowController->gotoSlideIndex( aSlide );
98 }
99 }
100 else if ( aCommand[0] == "presentation_start" )
101 {
102 if ( xPresentation.is() )
103 xPresentation->start();
104 }
105 else if ( aCommand[0] == "presentation_stop" )
106 {
107 if ( xPresentation.is() )
108 xPresentation->end();
109 }
110 else if ( aCommand[0] == "presentation_blank_screen" )
111 {
112 if ( aCommand.size() > 1 )
113 {
114// aColour = FIXME: get the colour in some format from this string
115// Determine the formatting first.
116 }
117 if ( xSlideShowController.is() )
118 {
119 xSlideShowController->blankScreen( 0 ); // Default is black
120 }
121 }
122 else if (aCommand[0] == "pointer_started" )
123 {
124 // std::cerr << "pointer_started" << std::endl;
125 float x = aCommand[1].toFloat();
126 float y = aCommand[2].toFloat();
127 SolarMutexGuard aSolarGuard;
128
129 const css::geometry::RealPoint2D pos(x,y);
130 // std::cerr << "Pointer at ("<<pos.X<<","<<pos.Y<<")" << std::endl;
131
132 if (xSlideShow.is())
133 {
134 try
135 {
136 // std::cerr << "pointer_coordination in the is" << std::endl;
137 xSlideShow->setProperty(beans::PropertyValue("PointerPosition", -1, Any(pos),
138 beans::PropertyState_DIRECT_VALUE));
139 }
140 catch (Exception&)
141 {
142 TOOLS_WARN_EXCEPTION("sdremote", "sd::SlideShowImpl::setPointerPosition()");
143 }
144
145 try
146 {
147 xSlideShow->setProperty(beans::PropertyValue("PointerVisible", -1, Any(true),
148 beans::PropertyState_DIRECT_VALUE));
149 }
150 catch (Exception&)
151 {
152 TOOLS_WARN_EXCEPTION("sdremote", "sd::SlideShowImpl::setPointerMode()");
153 }
154 }
155
156 SAL_INFO( "sdremote", "Pointer started, we display the pointer on screen" );
157 }
158 else if (aCommand[0] == "pointer_dismissed" )
159 {
160 SolarMutexGuard aSolarGuard;
161 if (xSlideShow.is()) try
162 {
163 xSlideShow->setProperty(
164 beans::PropertyValue( "PointerVisible" ,
165 -1,
166 Any( false ),
167 beans::PropertyState_DIRECT_VALUE ) );
168 }
169 catch ( Exception& )
170 {
171 TOOLS_WARN_EXCEPTION( "sdremote", "sd::SlideShowImpl::setPointerMode()" );
172 }
173
174 SAL_INFO( "sdremote", "Pointer dismissed, we hide the pointer on screen" );
175 }
176 else if (aCommand[0] == "pointer_coordination" )
177 {
178 float x = aCommand[1].toFloat();
179 float y = aCommand[2].toFloat();
180
181 SAL_INFO( "sdremote", "Pointer at ("<<x<<","<<y<<")" );
182 const css::geometry::RealPoint2D pos(x,y);
183
184 SolarMutexGuard aSolarGuard;
185 if (xSlideShow.is()) try
186 {
187 xSlideShow->setProperty(
188 beans::PropertyValue( "PointerPosition" ,
189 -1,
190 Any( pos ),
191 beans::PropertyState_DIRECT_VALUE ) );
192 }
193 catch ( Exception& )
194 {
195 TOOLS_WARN_EXCEPTION( "sdremote", "sd::SlideShowImpl::setPointerPosition()" );
196 }
197 }
198 else if ( aCommand[0] == "presentation_resume" )
199 {
200 if ( xSlideShowController.is() )
201 {
202 xSlideShowController->resume();
203 }
204 }
205}
206
207/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Stop()
void SetTimeout(sal_uInt64 nTimeoutMs)
virtual void Start(bool bStartTimer=true) override
virtual ~Receiver() override
Definition: Receiver.cxx:36
void pushCommand(const std::vector< OString > &rCommand)
Definition: Receiver.cxx:41
std::deque< std::vector< OString > > maExecQueue
Definition: Receiver.hxx:25
static void executeCommand(const std::vector< OString > &aCommand)
Definition: Receiver.cxx:62
Transmitter * pTransmitter
Definition: Receiver.hxx:34
virtual void Invoke() override
Definition: Receiver.cxx:48
#define TOOLS_WARN_EXCEPTION(area, stream)
float y
float x
#define SAL_INFO(area, stream)
@ Exception
Reference< XFrame > xFrame
OUString aCommand
size_t pos