Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <stdio.h>
30 : :
31 : : #include <avmedia/mediawindow.hxx>
32 : : #include "mediawindow_impl.hxx"
33 : : #include "mediamisc.hxx"
34 : : #include "mediawindow.hrc"
35 : : #include <tools/urlobj.hxx>
36 : : #include <vcl/msgbox.hxx>
37 : : #include <unotools/pathoptions.hxx>
38 : : #include <sfx2/filedlghelper.hxx>
39 : : #include <comphelper/processfactory.hxx>
40 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 : : #include <com/sun/star/media/XManager.hpp>
42 : : #include "com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp"
43 : : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
44 : : #include "com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp"
45 : :
46 : : #define AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME 3.0
47 : :
48 : : using namespace ::com::sun::star;
49 : :
50 : : namespace avmedia {
51 : :
52 : : // ---------------
53 : : // - MediaWindow -
54 : : // ---------------
55 : :
56 : 0 : MediaWindow::MediaWindow( Window* parent, bool bInternalMediaControl ) :
57 [ # # ][ # # ]: 0 : mpImpl( new priv::MediaWindowImpl( parent, this, bInternalMediaControl ) )
58 : : {
59 [ # # ]: 0 : mpImpl->Show();
60 : 0 : }
61 : :
62 : : // -------------------------------------------------------------------------
63 : :
64 : 0 : MediaWindow::~MediaWindow()
65 : : {
66 [ # # ]: 0 : mpImpl->cleanUp();
67 [ # # ][ # # ]: 0 : delete mpImpl;
68 : 0 : mpImpl = NULL;
69 [ # # ]: 0 : }
70 : :
71 : : // -------------------------------------------------------------------------
72 : :
73 : 0 : void MediaWindow::setURL( const ::rtl::OUString& rURL )
74 : : {
75 [ # # ]: 0 : if( mpImpl )
76 [ # # ]: 0 : mpImpl->setURL( rURL, ::rtl::OUString() );
77 : 0 : }
78 : :
79 : : // -------------------------------------------------------------------------
80 : :
81 : 0 : const ::rtl::OUString& MediaWindow::getURL() const
82 : : {
83 : 0 : return mpImpl->getURL();
84 : : }
85 : :
86 : : // -------------------------------------------------------------------------
87 : :
88 : 0 : bool MediaWindow::isValid() const
89 : : {
90 [ # # ][ # # ]: 0 : return( mpImpl != NULL && mpImpl->isValid() );
91 : : }
92 : :
93 : : // -------------------------------------------------------------------------
94 : :
95 : 0 : void MediaWindow::MouseMove( const MouseEvent& /* rMEvt */ )
96 : : {
97 : 0 : }
98 : :
99 : : // ---------------------------------------------------------------------
100 : :
101 : 0 : void MediaWindow::MouseButtonDown( const MouseEvent& /* rMEvt */ )
102 : : {
103 : 0 : }
104 : :
105 : : // ---------------------------------------------------------------------
106 : :
107 : 0 : void MediaWindow::MouseButtonUp( const MouseEvent& /* rMEvt */ )
108 : : {
109 : 0 : }
110 : :
111 : : // -------------------------------------------------------------------------
112 : :
113 : 0 : void MediaWindow::KeyInput( const KeyEvent& /* rKEvt */ )
114 : : {
115 : 0 : }
116 : :
117 : : // -------------------------------------------------------------------------
118 : :
119 : 0 : void MediaWindow::KeyUp( const KeyEvent& /* rKEvt */ )
120 : : {
121 : 0 : }
122 : :
123 : : // -------------------------------------------------------------------------
124 : :
125 : 0 : void MediaWindow::Command( const CommandEvent& /* rCEvt */ )
126 : : {
127 : 0 : }
128 : :
129 : : // -------------------------------------------------------------------------
130 : :
131 : 0 : sal_Int8 MediaWindow::AcceptDrop( const AcceptDropEvent& /* rEvt */ )
132 : : {
133 : 0 : return 0;
134 : : }
135 : :
136 : : // -------------------------------------------------------------------------
137 : :
138 : 0 : sal_Int8 MediaWindow::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ )
139 : : {
140 : 0 : return 0;
141 : : }
142 : :
143 : : // -------------------------------------------------------------------------
144 : :
145 : 0 : void MediaWindow::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ )
146 : : {
147 : 0 : }
148 : :
149 : : // -------------------------------------------------------------------------
150 : :
151 : 0 : Size MediaWindow::getPreferredSize() const
152 : : {
153 : 0 : return mpImpl->getPreferredSize();
154 : : }
155 : :
156 : : // -------------------------------------------------------------------------
157 : :
158 : 0 : void MediaWindow::setPosSize( const Rectangle& rNewRect )
159 : : {
160 [ # # ]: 0 : if( mpImpl )
161 : : {
162 : 0 : mpImpl->setPosSize( rNewRect );
163 : : }
164 : 0 : }
165 : :
166 : : // -------------------------------------------------------------------------
167 : :
168 : 0 : void MediaWindow::setPointer( const Pointer& rPointer )
169 : : {
170 [ # # ]: 0 : if( mpImpl )
171 : 0 : mpImpl->setPointer( rPointer );
172 : 0 : }
173 : :
174 : : // -------------------------------------------------------------------------
175 : :
176 : 0 : bool MediaWindow::start()
177 : : {
178 [ # # ][ # # ]: 0 : return( mpImpl != NULL && mpImpl->start() );
179 : : }
180 : :
181 : : // -------------------------------------------------------------------------
182 : :
183 : 0 : void MediaWindow::updateMediaItem( MediaItem& rItem ) const
184 : : {
185 [ # # ]: 0 : if( mpImpl )
186 : 0 : mpImpl->updateMediaItem( rItem );
187 : 0 : }
188 : :
189 : : // -------------------------------------------------------------------------
190 : :
191 : 0 : void MediaWindow::executeMediaItem( const MediaItem& rItem )
192 : : {
193 [ # # ]: 0 : if( mpImpl )
194 : 0 : mpImpl->executeMediaItem( rItem );
195 : 0 : }
196 : :
197 : : // -------------------------------------------------------------------------
198 : :
199 : 0 : void MediaWindow::show()
200 : : {
201 [ # # ]: 0 : if( mpImpl )
202 : 0 : mpImpl->Show();
203 : 0 : }
204 : :
205 : : // -------------------------------------------------------------------------
206 : :
207 : 0 : void MediaWindow::hide()
208 : : {
209 [ # # ]: 0 : if( mpImpl )
210 : 0 : mpImpl->Hide();
211 : 0 : }
212 : :
213 : : // -------------------------------------------------------------------------
214 : :
215 : 0 : Window* MediaWindow::getWindow() const
216 : : {
217 : 0 : return mpImpl;
218 : : }
219 : :
220 : : // -------------------------------------------------------------------------
221 : :
222 : 10 : void MediaWindow::getMediaFilters( FilterNameVector& rFilterNameVector )
223 : : {
224 : : static const char* pFilters[] = { "AIF Audio", "aif;aiff",
225 : : "AU Audio", "au",
226 : : "AVI", "avi",
227 : : "CD Audio", "cda",
228 : : "FLAC Audio", "flac",
229 : : "Matroska Media", "mkv",
230 : : "MIDI Audio", "mid;midi",
231 : : "MPEG Audio", "mp2;mp3;mpa",
232 : : "MPEG Video", "mpg;mpeg;mpv;mp4",
233 : : "Ogg bitstream", "ogg",
234 : : "Quicktime Video", "mov",
235 : : "Vivo Video", "viv",
236 : : "WAVE Audio", "wav",
237 : : "WebM Video", "webm" };
238 : :
239 [ + + ]: 150 : for( size_t i = 0; i < SAL_N_ELEMENTS(pFilters); i += 2 )
240 : : {
241 : : rFilterNameVector.push_back( ::std::make_pair< ::rtl::OUString, ::rtl::OUString >(
242 : : ::rtl::OUString::createFromAscii(pFilters[i]),
243 [ + - ]: 140 : ::rtl::OUString::createFromAscii(pFilters[i+1]) ) );
244 : : }
245 : 10 : }
246 : :
247 : : // -------------------------------------------------------------------------
248 : :
249 : 0 : bool MediaWindow::executeMediaURLDialog(Window* /* pParent */,
250 : : ::rtl::OUString& rURL, bool *const o_pbLink)
251 : : {
252 : : ::sfx2::FileDialogHelper aDlg( (o_pbLink)
253 : : ? ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW
254 [ # # ][ # # ]: 0 : : ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
255 [ # # ][ # # ]: 0 : static const ::rtl::OUString aWildcard( "*." );
256 [ # # ]: 0 : FilterNameVector aFilters;
257 : 0 : const ::rtl::OUString aSeparator( ";" );
258 : 0 : ::rtl::OUString aAllTypes;
259 : :
260 [ # # ]: 0 : aDlg.SetTitle( AVMEDIA_RESID( (o_pbLink)
261 [ # # ][ # # ]: 0 : ? AVMEDIA_STR_INSERTMEDIA_DLG : AVMEDIA_STR_OPENMEDIA_DLG ) );
[ # # ][ # # ]
262 : :
263 [ # # ]: 0 : getMediaFilters( aFilters );
264 : :
265 : : unsigned int i;
266 [ # # ]: 0 : for( i = 0; i < aFilters.size(); ++i )
267 : : {
268 [ # # ]: 0 : for( sal_Int32 nIndex = 0; nIndex >= 0; )
269 : : {
270 [ # # ]: 0 : if( !aAllTypes.isEmpty() )
271 : 0 : aAllTypes += aSeparator;
272 : :
273 : 0 : ( aAllTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex );
274 : : }
275 : : }
276 : :
277 : : // add filter for all media types
278 [ # # ][ # # ]: 0 : aDlg.AddFilter( AVMEDIA_RESID( AVMEDIA_STR_ALL_MEDIAFILES ), aAllTypes );
[ # # ][ # # ]
[ # # ][ # # ]
279 : :
280 [ # # ]: 0 : for( i = 0; i < aFilters.size(); ++i )
281 : : {
282 : 0 : ::rtl::OUString aTypes;
283 : :
284 [ # # ]: 0 : for( sal_Int32 nIndex = 0; nIndex >= 0; )
285 : : {
286 [ # # ]: 0 : if( !aTypes.isEmpty() )
287 : 0 : aTypes += aSeparator;
288 : :
289 : 0 : ( aTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex );
290 : : }
291 : :
292 : : // add single filters
293 [ # # ][ # # ]: 0 : aDlg.AddFilter( aFilters[ i ].first, aTypes );
[ # # ][ # # ]
[ # # ]
294 : 0 : }
295 : :
296 : : // add filter for all types
297 [ # # ][ # # ]: 0 : aDlg.AddFilter( AVMEDIA_RESID( AVMEDIA_STR_ALL_FILES ), String( "*.*" ) );
[ # # ][ # # ]
[ # # ][ # # ]
298 : :
299 [ # # ]: 0 : uno::Reference<ui::dialogs::XFilePicker> const xFP(aDlg.GetFilePicker());
300 : : uno::Reference<ui::dialogs::XFilePickerControlAccess> const xCtrlAcc(xFP,
301 [ # # ]: 0 : uno::UNO_QUERY_THROW);
302 [ # # ]: 0 : if (o_pbLink)
303 : : {
304 : : // for video link should be the default
305 [ # # ]: 0 : xCtrlAcc->setValue(
306 : : ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0,
307 [ # # ][ # # ]: 0 : uno::makeAny(sal_True) );
308 : : // disabled for now: TODO: preview?
309 [ # # ]: 0 : xCtrlAcc->enableControl(
310 : : ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW,
311 [ # # ]: 0 : sal_False);
312 : : }
313 : :
314 [ # # ][ # # ]: 0 : if( aDlg.Execute() == ERRCODE_NONE )
315 : : {
316 [ # # ][ # # ]: 0 : const INetURLObject aURL( aDlg.GetPath() );
[ # # ][ # # ]
317 [ # # ]: 0 : rURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
318 : :
319 [ # # ]: 0 : if (o_pbLink)
320 : : {
321 [ # # ]: 0 : uno::Any const any = xCtrlAcc->getValue(
322 [ # # ]: 0 : ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0);
323 [ # # ]: 0 : if (!(any >>= *o_pbLink))
324 : : {
325 : : SAL_WARN("avmedia", "invalid link property");
326 : 0 : *o_pbLink = true;
327 : 0 : }
328 [ # # ]: 0 : }
329 : : }
330 [ # # ]: 0 : else if( !rURL.isEmpty() )
331 : 0 : rURL = ::rtl::OUString();
332 : :
333 [ # # ]: 0 : return( !rURL.isEmpty() );
334 : : }
335 : :
336 : : // -------------------------------------------------------------------------
337 : :
338 : 0 : void MediaWindow::executeFormatErrorBox( Window* pParent )
339 : : {
340 [ # # ][ # # ]: 0 : ErrorBox aErrBox( pParent, AVMEDIA_RESID( AVMEDIA_ERR_URL ) );
341 : :
342 [ # # ][ # # ]: 0 : aErrBox.Execute();
343 : 0 : }
344 : :
345 : : // -------------------------------------------------------------------------
346 : :
347 : 10 : bool MediaWindow::isMediaURL( const ::rtl::OUString& rURL, bool bDeep, Size* pPreferredSizePixel )
348 : : {
349 [ + - ]: 10 : const INetURLObject aURL( rURL );
350 : 10 : bool bRet = false;
351 : :
352 [ + - ]: 10 : if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
353 : : {
354 [ + - ][ - + ]: 10 : if( bDeep || pPreferredSizePixel )
355 : : {
356 : : try
357 : : {
358 : : uno::Reference< media::XPlayer > xPlayer( priv::MediaWindowImpl::createPlayer(
359 [ # # ][ # # ]: 0 : aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) );
360 : :
361 [ # # ]: 0 : if( xPlayer.is() )
362 : : {
363 : 0 : bRet = true;
364 : :
365 [ # # ]: 0 : if( pPreferredSizePixel )
366 : : {
367 [ # # ][ # # ]: 0 : const awt::Size aAwtSize( xPlayer->getPreferredPlayerWindowSize() );
368 : :
369 : 0 : pPreferredSizePixel->Width() = aAwtSize.Width;
370 : 0 : pPreferredSizePixel->Height() = aAwtSize.Height;
371 : : }
372 : 0 : }
373 : : }
374 [ # # ]: 0 : catch( ... )
375 : : {
376 : 0 : }
377 : : }
378 : : else
379 : : {
380 [ + - ]: 10 : FilterNameVector aFilters;
381 [ + - ]: 10 : const ::rtl::OUString aExt( aURL.getExtension() );
382 : :
383 [ + - ]: 10 : getMediaFilters( aFilters );
384 : :
385 : : unsigned int i;
386 [ + + ][ + - ]: 150 : for( i = 0; ( i < aFilters.size() ) && !bRet; ++i )
[ + + ]
387 : : {
388 [ + + ][ + - ]: 350 : for( sal_Int32 nIndex = 0; nIndex >= 0 && !bRet; )
[ + + ]
389 : : {
390 [ - + ]: 210 : if( aExt.equalsIgnoreAsciiCase( aFilters[ i ].second.getToken( 0, ';', nIndex ) ) )
391 : 0 : bRet = true;
392 : : }
393 : 10 : }
394 : : }
395 : : }
396 : :
397 [ + - ]: 10 : return bRet;
398 : : }
399 : :
400 : : // -------------------------------------------------------------------------
401 : :
402 : 0 : uno::Reference< media::XPlayer > MediaWindow::createPlayer( const ::rtl::OUString& rURL )
403 : : {
404 : 0 : return priv::MediaWindowImpl::createPlayer( rURL );
405 : : }
406 : :
407 : : // -------------------------------------------------------------------------
408 : :
409 : 0 : uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const ::rtl::OUString& rURL,
410 : : bool bAllowToCreateReplacementGraphic,
411 : : double fMediaTime )
412 : : {
413 [ # # ]: 0 : uno::Reference< media::XPlayer > xPlayer( createPlayer( rURL ) );
414 : 0 : uno::Reference< graphic::XGraphic > xRet;
415 : 0 : ::std::auto_ptr< Graphic > apGraphic;
416 : :
417 [ # # ]: 0 : if( xPlayer.is() )
418 : : {
419 [ # # ][ # # ]: 0 : uno::Reference< media::XFrameGrabber > xGrabber( xPlayer->createFrameGrabber() );
420 : :
421 [ # # ]: 0 : if( xGrabber.is() )
422 : : {
423 [ # # ]: 0 : if( AVMEDIA_FRAMEGRABBER_DEFAULTFRAME == fMediaTime )
424 : 0 : fMediaTime = AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME;
425 : :
426 [ # # ][ # # ]: 0 : if( fMediaTime >= xPlayer->getDuration() )
[ # # ]
427 [ # # ][ # # ]: 0 : fMediaTime = ( xPlayer->getDuration() * 0.5 );
428 : :
429 [ # # ][ # # ]: 0 : xRet = xGrabber->grabFrame( fMediaTime );
[ # # ]
430 : : }
431 : :
432 [ # # ][ # # ]: 0 : if( !xRet.is() && bAllowToCreateReplacementGraphic )
[ # # ]
433 : : {
434 [ # # ][ # # ]: 0 : awt::Size aPrefSize( xPlayer->getPreferredPlayerWindowSize() );
435 : :
436 [ # # ][ # # ]: 0 : if( !aPrefSize.Width && !aPrefSize.Height )
437 : : {
438 [ # # ][ # # ]: 0 : const BitmapEx aBmpEx( AVMEDIA_RESID( AVMEDIA_BMP_AUDIOLOGO ) );
439 [ # # ][ # # ]: 0 : apGraphic.reset( new Graphic( aBmpEx ) );
[ # # ]
440 : : }
441 : 0 : }
442 : : }
443 : :
444 [ # # ][ # # ]: 0 : if( !xRet.is() && !apGraphic.get() && bAllowToCreateReplacementGraphic )
[ # # ][ # # ]
445 : : {
446 [ # # ][ # # ]: 0 : const BitmapEx aBmpEx( AVMEDIA_RESID( AVMEDIA_BMP_EMPTYLOGO ) );
447 [ # # ][ # # ]: 0 : apGraphic.reset( new Graphic( aBmpEx ) );
[ # # ]
448 : : }
449 : :
450 [ # # ]: 0 : if( apGraphic.get() )
451 [ # # ][ # # ]: 0 : xRet = apGraphic->GetXGraphic();
452 : :
453 [ # # ]: 0 : return xRet;
454 : : }
455 : :
456 : : } // namespace avemdia
457 : :
458 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|