xref: /trunk/main/avmedia/source/viewer/mediawindow.cxx (revision 46880872fedb27c2d4aea27d378c5f20891d16b4)
1f39251c4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f39251c4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f39251c4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f39251c4SAndrew Rist  * distributed with this work for additional information
6f39251c4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f39251c4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f39251c4SAndrew Rist  * "License"); you may not use this file except in compliance
9f39251c4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f39251c4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f39251c4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f39251c4SAndrew Rist  * software distributed under the License is distributed on an
15f39251c4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f39251c4SAndrew Rist  * KIND, either express or implied.  See the License for the
17f39251c4SAndrew Rist  * specific language governing permissions and limitations
18f39251c4SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f39251c4SAndrew Rist  *************************************************************/
21f39251c4SAndrew Rist 
22f39251c4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <stdio.h>
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <avmedia/mediawindow.hxx>
27cdf0e10cSrcweir #include "mediawindow_impl.hxx"
28cdf0e10cSrcweir #include "mediamisc.hxx"
29cdf0e10cSrcweir #include "mediawindow.hrc"
30cdf0e10cSrcweir #include <tools/urlobj.hxx>
31cdf0e10cSrcweir #include <vcl/msgbox.hxx>
32cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
33cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
34cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
35cdf0e10cSrcweir #include <com/sun/star/media/XManager.hpp>
36cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #define AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME 3.0
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::com::sun::star;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace avmedia {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // ---------------
45cdf0e10cSrcweir // - MediaWindow -
46cdf0e10cSrcweir // ---------------
47cdf0e10cSrcweir 
MediaWindow(Window * parent,bool bInternalMediaControl)48cdf0e10cSrcweir MediaWindow::MediaWindow( Window* parent, bool bInternalMediaControl ) :
49cdf0e10cSrcweir     mpImpl( new priv::MediaWindowImpl( parent, this, bInternalMediaControl ) )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     mpImpl->Show();
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // -------------------------------------------------------------------------
55cdf0e10cSrcweir 
~MediaWindow()56cdf0e10cSrcweir MediaWindow::~MediaWindow()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     mpImpl->cleanUp();
59cdf0e10cSrcweir     delete mpImpl;
60cdf0e10cSrcweir     mpImpl = NULL;
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // -------------------------------------------------------------------------
64cdf0e10cSrcweir 
setURL(const::rtl::OUString & rURL)65cdf0e10cSrcweir void MediaWindow::setURL( const ::rtl::OUString& rURL )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     if( mpImpl )
68cdf0e10cSrcweir         mpImpl->setURL( rURL );
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir // -------------------------------------------------------------------------
72cdf0e10cSrcweir 
getURL() const73cdf0e10cSrcweir const ::rtl::OUString& MediaWindow::getURL() const
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     return mpImpl->getURL();
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir // -------------------------------------------------------------------------
79cdf0e10cSrcweir 
isValid() const80cdf0e10cSrcweir bool MediaWindow::isValid() const
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     return( mpImpl != NULL && mpImpl->isValid() );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir // -------------------------------------------------------------------------
86cdf0e10cSrcweir 
MouseMove(const MouseEvent &)87cdf0e10cSrcweir void MediaWindow::MouseMove( const MouseEvent& /* rMEvt */ )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir // ---------------------------------------------------------------------
92cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent &)93cdf0e10cSrcweir void MediaWindow::MouseButtonDown( const MouseEvent& /* rMEvt */ )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir // ---------------------------------------------------------------------
98cdf0e10cSrcweir 
MouseButtonUp(const MouseEvent &)99cdf0e10cSrcweir void MediaWindow::MouseButtonUp( const MouseEvent& /* rMEvt */ )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // -------------------------------------------------------------------------
104cdf0e10cSrcweir 
KeyInput(const KeyEvent &)105cdf0e10cSrcweir void MediaWindow::KeyInput( const KeyEvent& /* rKEvt */ )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir // -------------------------------------------------------------------------
110cdf0e10cSrcweir 
KeyUp(const KeyEvent &)111cdf0e10cSrcweir void MediaWindow::KeyUp( const KeyEvent& /* rKEvt */ )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // -------------------------------------------------------------------------
116cdf0e10cSrcweir 
Command(const CommandEvent &)117cdf0e10cSrcweir void MediaWindow::Command( const CommandEvent& /* rCEvt */ )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir // -------------------------------------------------------------------------
122cdf0e10cSrcweir 
AcceptDrop(const AcceptDropEvent &)123cdf0e10cSrcweir sal_Int8 MediaWindow::AcceptDrop( const AcceptDropEvent& /* rEvt */ )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     return 0;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // -------------------------------------------------------------------------
129cdf0e10cSrcweir 
ExecuteDrop(const ExecuteDropEvent &)130cdf0e10cSrcweir sal_Int8 MediaWindow::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     return 0;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir // -------------------------------------------------------------------------
136cdf0e10cSrcweir 
StartDrag(sal_Int8,const Point &)137cdf0e10cSrcweir void MediaWindow::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir // -------------------------------------------------------------------------
142cdf0e10cSrcweir 
hasPreferredSize() const143cdf0e10cSrcweir bool MediaWindow::hasPreferredSize() const
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     return( mpImpl != NULL && mpImpl->hasPreferredSize() );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir // -------------------------------------------------------------------------
149cdf0e10cSrcweir 
getPreferredSize() const150cdf0e10cSrcweir Size MediaWindow::getPreferredSize() const
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     return mpImpl->getPreferredSize();
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir // -------------------------------------------------------------------------
156cdf0e10cSrcweir 
setPosSize(const Rectangle & rNewRect)157cdf0e10cSrcweir void MediaWindow::setPosSize( const Rectangle& rNewRect )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     if( mpImpl )
160cdf0e10cSrcweir     {
161cdf0e10cSrcweir         mpImpl->setPosSize( rNewRect );
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir // -------------------------------------------------------------------------
166cdf0e10cSrcweir 
getPosSize() const167cdf0e10cSrcweir Rectangle MediaWindow::getPosSize() const
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     return Rectangle( mpImpl->GetPosPixel(), mpImpl->GetSizePixel() );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir // -------------------------------------------------------------------------
173cdf0e10cSrcweir 
setPointer(const Pointer & rPointer)174cdf0e10cSrcweir void MediaWindow::setPointer( const Pointer& rPointer )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     if( mpImpl )
177cdf0e10cSrcweir         mpImpl->setPointer( rPointer );
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir // -------------------------------------------------------------------------
181cdf0e10cSrcweir 
getPointer() const182cdf0e10cSrcweir const Pointer& MediaWindow::getPointer() const
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     return mpImpl->getPointer();
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // -------------------------------------------------------------------------
188cdf0e10cSrcweir 
setZoom(::com::sun::star::media::ZoomLevel eLevel)189cdf0e10cSrcweir bool MediaWindow::setZoom( ::com::sun::star::media::ZoomLevel eLevel )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     return( mpImpl != NULL && mpImpl->setZoom( eLevel ) );
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // -------------------------------------------------------------------------
195cdf0e10cSrcweir 
getZoom() const196cdf0e10cSrcweir ::com::sun::star::media::ZoomLevel MediaWindow::getZoom() const
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     return mpImpl->getZoom();
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // -------------------------------------------------------------------------
202cdf0e10cSrcweir 
start()203cdf0e10cSrcweir bool MediaWindow::start()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     return( mpImpl != NULL && mpImpl->start() );
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir // -------------------------------------------------------------------------
209cdf0e10cSrcweir 
stop()210cdf0e10cSrcweir void MediaWindow::stop()
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     if( mpImpl )
213cdf0e10cSrcweir         mpImpl->stop();
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir // -------------------------------------------------------------------------
217cdf0e10cSrcweir 
isPlaying() const218cdf0e10cSrcweir bool MediaWindow::isPlaying() const
219cdf0e10cSrcweir {
220cdf0e10cSrcweir     return( mpImpl != NULL && mpImpl->isPlaying() );
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir // -------------------------------------------------------------------------
224cdf0e10cSrcweir 
getDuration() const225cdf0e10cSrcweir double MediaWindow::getDuration() const
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     return mpImpl->getDuration();
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir // -------------------------------------------------------------------------
231cdf0e10cSrcweir 
setMediaTime(double fTime)232cdf0e10cSrcweir void MediaWindow::setMediaTime( double fTime )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     if( mpImpl )
235cdf0e10cSrcweir         mpImpl->setMediaTime( fTime );
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir // -------------------------------------------------------------------------
239cdf0e10cSrcweir 
getMediaTime() const240cdf0e10cSrcweir double MediaWindow::getMediaTime() const
241cdf0e10cSrcweir {
242cdf0e10cSrcweir     return mpImpl->getMediaTime();
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir // -------------------------------------------------------------------------
246cdf0e10cSrcweir 
setStopTime(double fTime)247cdf0e10cSrcweir void MediaWindow::setStopTime( double fTime )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir     if( mpImpl )
250cdf0e10cSrcweir         mpImpl->setStopTime( fTime );
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir // -------------------------------------------------------------------------
254cdf0e10cSrcweir 
getStopTime() const255cdf0e10cSrcweir double MediaWindow::getStopTime() const
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     return mpImpl->getStopTime();
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir // -------------------------------------------------------------------------
261cdf0e10cSrcweir 
setRate(double fRate)262cdf0e10cSrcweir void MediaWindow::setRate( double fRate )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     if( mpImpl )
265cdf0e10cSrcweir         mpImpl->setRate( fRate );
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir // -------------------------------------------------------------------------
269cdf0e10cSrcweir 
getRate() const270cdf0e10cSrcweir double MediaWindow::getRate() const
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     return mpImpl->getRate();
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir // -------------------------------------------------------------------------
276cdf0e10cSrcweir 
setPlaybackLoop(bool bSet)277cdf0e10cSrcweir void MediaWindow::setPlaybackLoop( bool bSet )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir     if( mpImpl )
280cdf0e10cSrcweir         mpImpl->setPlaybackLoop( bSet );
281cdf0e10cSrcweir }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir // -------------------------------------------------------------------------
284cdf0e10cSrcweir 
isPlaybackLoop() const285cdf0e10cSrcweir bool MediaWindow::isPlaybackLoop() const
286cdf0e10cSrcweir {
287cdf0e10cSrcweir     return mpImpl->isPlaybackLoop();
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir // -------------------------------------------------------------------------
291cdf0e10cSrcweir 
setMute(bool bSet)292cdf0e10cSrcweir void MediaWindow::setMute( bool bSet )
293cdf0e10cSrcweir {
294cdf0e10cSrcweir     if( mpImpl )
295cdf0e10cSrcweir         mpImpl->setMute( bSet );
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir // -------------------------------------------------------------------------
299cdf0e10cSrcweir 
isMute() const300cdf0e10cSrcweir bool MediaWindow::isMute() const
301cdf0e10cSrcweir {
302cdf0e10cSrcweir     return mpImpl->isMute();
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir // -------------------------------------------------------------------------
306cdf0e10cSrcweir 
updateMediaItem(MediaItem & rItem) const307cdf0e10cSrcweir void MediaWindow::updateMediaItem( MediaItem& rItem ) const
308cdf0e10cSrcweir {
309cdf0e10cSrcweir     if( mpImpl )
310cdf0e10cSrcweir         mpImpl->updateMediaItem( rItem );
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir // -------------------------------------------------------------------------
314cdf0e10cSrcweir 
executeMediaItem(const MediaItem & rItem)315cdf0e10cSrcweir void MediaWindow::executeMediaItem( const MediaItem& rItem )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     if( mpImpl )
318cdf0e10cSrcweir         mpImpl->executeMediaItem( rItem );
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir // -------------------------------------------------------------------------
322cdf0e10cSrcweir 
show()323cdf0e10cSrcweir void MediaWindow::show()
324cdf0e10cSrcweir {
325cdf0e10cSrcweir     if( mpImpl )
326cdf0e10cSrcweir         mpImpl->Show();
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir // -------------------------------------------------------------------------
330cdf0e10cSrcweir 
hide()331cdf0e10cSrcweir void MediaWindow::hide()
332cdf0e10cSrcweir {
333cdf0e10cSrcweir     if( mpImpl )
334cdf0e10cSrcweir         mpImpl->Hide();
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir // -------------------------------------------------------------------------
338cdf0e10cSrcweir 
enable()339cdf0e10cSrcweir void MediaWindow::enable()
340cdf0e10cSrcweir {
341cdf0e10cSrcweir     if( mpImpl )
342cdf0e10cSrcweir         mpImpl->Enable();
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir // -------------------------------------------------------------------------
346cdf0e10cSrcweir 
disable()347cdf0e10cSrcweir void MediaWindow::disable()
348cdf0e10cSrcweir {
349cdf0e10cSrcweir     if( mpImpl )
350cdf0e10cSrcweir         mpImpl->Disable();
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir // -------------------------------------------------------------------------
354cdf0e10cSrcweir 
getWindow() const355cdf0e10cSrcweir Window* MediaWindow::getWindow() const
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     return mpImpl;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir // -------------------------------------------------------------------------
361cdf0e10cSrcweir 
getMediaFilters(FilterNameVector & rFilterNameVector)362cdf0e10cSrcweir void MediaWindow::getMediaFilters( FilterNameVector& rFilterNameVector )
363cdf0e10cSrcweir {
364cdf0e10cSrcweir     static const char* pFilters[] = {   "AIF Audio", "aif;aiff",
365cdf0e10cSrcweir                                         "AU Audio", "au",
366cdf0e10cSrcweir                                         "AVI", "avi",
367cdf0e10cSrcweir                                         "CD Audio", "cda",
368a00e7f9fSAriel Constenla-Haile                                         "FLAC Audio", "flac",
369a00e7f9fSAriel Constenla-Haile                                         "Flash Video", "flv",
370cdf0e10cSrcweir                                         "Matroska Media", "mkv",
371cdf0e10cSrcweir                                         "MIDI Audio", "mid;midi",
372*6bd6a4b4Smseidel                                         "MPEG Audio", "mp2;mp3;mpa;m4a",
373cdf0e10cSrcweir                                         "MPEG Video", "mpg;mpeg;mpv;mp4",
374a00e7f9fSAriel Constenla-Haile                                         "Ogg bitstream", "ogg;oga;ogv",
375cdf0e10cSrcweir                                         "Quicktime Video", "mov",
376cdf0e10cSrcweir                                         "Vivo Video", "viv",
377a00e7f9fSAriel Constenla-Haile                                         "WAVE Audio", "wav",
378a00e7f9fSAriel Constenla-Haile                                         "Windows Media Video", "wmv" };
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     unsigned int i;
381cdf0e10cSrcweir     for( i = 0; i < ( sizeof( pFilters ) / sizeof( char* ) ); i += 2 )
382cdf0e10cSrcweir     {
383cdf0e10cSrcweir         rFilterNameVector.push_back( ::std::make_pair< ::rtl::OUString, ::rtl::OUString >(
384cdf0e10cSrcweir                                         ::rtl::OUString::createFromAscii( pFilters[ i ] ),
385cdf0e10cSrcweir                                         ::rtl::OUString::createFromAscii( pFilters[ i + 1 ] ) ) );
386cdf0e10cSrcweir     }
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir // -------------------------------------------------------------------------
390cdf0e10cSrcweir 
executeMediaURLDialog(Window *,::rtl::OUString & rURL,bool bInsertDialog)391cdf0e10cSrcweir bool MediaWindow::executeMediaURLDialog( Window* /* pParent */, ::rtl::OUString& rURL, bool bInsertDialog )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir     ::sfx2::FileDialogHelper        aDlg( com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
394cdf0e10cSrcweir     static const ::rtl::OUString    aWildcard( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
395cdf0e10cSrcweir     FilterNameVector                aFilters;
396cdf0e10cSrcweir     const ::rtl::OUString           aSeparator( RTL_CONSTASCII_USTRINGPARAM( ";" ) );
397cdf0e10cSrcweir     ::rtl::OUString                 aAllTypes;
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     aDlg.SetTitle( AVMEDIA_RESID( bInsertDialog ? AVMEDIA_STR_INSERTMEDIA_DLG : AVMEDIA_STR_OPENMEDIA_DLG ) );
400cdf0e10cSrcweir 
401cdf0e10cSrcweir     getMediaFilters( aFilters );
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     unsigned int i;
404cdf0e10cSrcweir     for( i = 0; i < aFilters.size(); ++i )
405cdf0e10cSrcweir     {
406cdf0e10cSrcweir         for( sal_Int32 nIndex = 0; nIndex >= 0; )
407cdf0e10cSrcweir         {
408144e4e62SHerbert Dürr             if( !aAllTypes.isEmpty() )
409cdf0e10cSrcweir                 aAllTypes += aSeparator;
410cdf0e10cSrcweir 
411cdf0e10cSrcweir             ( aAllTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex );
412cdf0e10cSrcweir         }
413cdf0e10cSrcweir     }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir     // add filter for all media types
416cdf0e10cSrcweir     aDlg.AddFilter( AVMEDIA_RESID( AVMEDIA_STR_ALL_MEDIAFILES ), aAllTypes );
417cdf0e10cSrcweir 
418cdf0e10cSrcweir     for( i = 0; i < aFilters.size(); ++i )
419cdf0e10cSrcweir     {
420cdf0e10cSrcweir         ::rtl::OUString aTypes;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir         for( sal_Int32 nIndex = 0; nIndex >= 0; )
423cdf0e10cSrcweir         {
424144e4e62SHerbert Dürr             if( !aTypes.isEmpty() )
425cdf0e10cSrcweir                 aTypes += aSeparator;
426cdf0e10cSrcweir 
427cdf0e10cSrcweir             ( aTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex );
428cdf0e10cSrcweir         }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir         // add single filters
431cdf0e10cSrcweir         aDlg.AddFilter( aFilters[ i ].first, aTypes );
432cdf0e10cSrcweir     }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir     // add filter for all types
435cdf0e10cSrcweir     aDlg.AddFilter( AVMEDIA_RESID( AVMEDIA_STR_ALL_FILES ), String( RTL_CONSTASCII_USTRINGPARAM( "*.*" ) ) );
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     if( aDlg.Execute() == ERRCODE_NONE )
438cdf0e10cSrcweir     {
439cdf0e10cSrcweir         const INetURLObject aURL( aDlg.GetPath() );
440cdf0e10cSrcweir         rURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
441cdf0e10cSrcweir     }
442144e4e62SHerbert Dürr     else if( !rURL.isEmpty() )
443cdf0e10cSrcweir         rURL = ::rtl::OUString();
444cdf0e10cSrcweir 
445144e4e62SHerbert Dürr     return !rURL.isEmpty();
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir // -------------------------------------------------------------------------
449cdf0e10cSrcweir 
executeFormatErrorBox(Window * pParent)450cdf0e10cSrcweir void MediaWindow::executeFormatErrorBox( Window* pParent )
451cdf0e10cSrcweir {
452cdf0e10cSrcweir     ErrorBox aErrBox( pParent, AVMEDIA_RESID( AVMEDIA_ERR_URL ) );
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     aErrBox.Execute();
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir // -------------------------------------------------------------------------
458cdf0e10cSrcweir 
isMediaURL(const::rtl::OUString & rURL,bool bDeep,Size * pPreferredSizePixel)459cdf0e10cSrcweir bool MediaWindow::isMediaURL( const ::rtl::OUString& rURL, bool bDeep, Size* pPreferredSizePixel )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir     const INetURLObject aURL( rURL );
462cdf0e10cSrcweir     bool                bRet = false;
463cdf0e10cSrcweir 
464cdf0e10cSrcweir     if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
465cdf0e10cSrcweir     {
466cdf0e10cSrcweir         if( bDeep || pPreferredSizePixel )
467cdf0e10cSrcweir         {
468cdf0e10cSrcweir             try
469cdf0e10cSrcweir             {
470cdf0e10cSrcweir                 sal_Bool bIsJavaBasedMediaWindow;
471cdf0e10cSrcweir                 uno::Reference< media::XPlayer > xPlayer( priv::MediaWindowImpl::createPlayer(
472cdf0e10cSrcweir                                                             aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ),
473cdf0e10cSrcweir                                                             bIsJavaBasedMediaWindow ) );
474cdf0e10cSrcweir 
475cdf0e10cSrcweir                 if( xPlayer.is() )
476cdf0e10cSrcweir                 {
477cdf0e10cSrcweir                     bRet = true;
478cdf0e10cSrcweir 
479cdf0e10cSrcweir                     if( pPreferredSizePixel )
480cdf0e10cSrcweir                     {
481cdf0e10cSrcweir                         const awt::Size aAwtSize( xPlayer->getPreferredPlayerWindowSize() );
482cdf0e10cSrcweir 
483cdf0e10cSrcweir                         pPreferredSizePixel->Width() = aAwtSize.Width;
484cdf0e10cSrcweir                         pPreferredSizePixel->Height() = aAwtSize.Height;
485cdf0e10cSrcweir                     }
486cdf0e10cSrcweir                 }
487cdf0e10cSrcweir             }
488cdf0e10cSrcweir             catch( ... )
489cdf0e10cSrcweir             {
490cdf0e10cSrcweir             }
491cdf0e10cSrcweir         }
492cdf0e10cSrcweir         else
493cdf0e10cSrcweir         {
494cdf0e10cSrcweir             FilterNameVector        aFilters;
495cdf0e10cSrcweir             const ::rtl::OUString   aExt( aURL.getExtension() );
496cdf0e10cSrcweir 
497cdf0e10cSrcweir             getMediaFilters( aFilters );
498cdf0e10cSrcweir 
499cdf0e10cSrcweir             unsigned int i;
500cdf0e10cSrcweir             for( i = 0; ( i < aFilters.size() ) && !bRet; ++i )
501cdf0e10cSrcweir             {
502cdf0e10cSrcweir                 for( sal_Int32 nIndex = 0; nIndex >= 0 && !bRet; )
503cdf0e10cSrcweir                 {
504cdf0e10cSrcweir                     if( aExt.equalsIgnoreAsciiCase( aFilters[ i ].second.getToken( 0, ';', nIndex ) ) )
505cdf0e10cSrcweir                         bRet = true;
506cdf0e10cSrcweir                 }
507cdf0e10cSrcweir             }
508cdf0e10cSrcweir         }
509cdf0e10cSrcweir     }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir     return bRet;
512cdf0e10cSrcweir }
513cdf0e10cSrcweir 
514cdf0e10cSrcweir // -------------------------------------------------------------------------
515cdf0e10cSrcweir 
createPlayer(const::rtl::OUString & rURL)516cdf0e10cSrcweir uno::Reference< media::XPlayer > MediaWindow::createPlayer( const ::rtl::OUString& rURL )
517cdf0e10cSrcweir {
518cdf0e10cSrcweir     sal_Bool bJavaBased = sal_False;
519cdf0e10cSrcweir     return priv::MediaWindowImpl::createPlayer( rURL, bJavaBased );
520cdf0e10cSrcweir }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir // -------------------------------------------------------------------------
523cdf0e10cSrcweir 
grabFrame(const::rtl::OUString & rURL,bool bAllowToCreateReplacementGraphic,double fMediaTime)524cdf0e10cSrcweir uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const ::rtl::OUString& rURL,
525cdf0e10cSrcweir                                                             bool bAllowToCreateReplacementGraphic,
526cdf0e10cSrcweir                                                             double fMediaTime )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir     uno::Reference< media::XPlayer >    xPlayer( createPlayer( rURL ) );
529cdf0e10cSrcweir     uno::Reference< graphic::XGraphic > xRet;
530cdf0e10cSrcweir     ::std::auto_ptr< Graphic >          apGraphic;
531cdf0e10cSrcweir 
532cdf0e10cSrcweir     if( xPlayer.is() )
533cdf0e10cSrcweir     {
534cdf0e10cSrcweir         uno::Reference< media::XFrameGrabber > xGrabber( xPlayer->createFrameGrabber() );
535cdf0e10cSrcweir 
536cdf0e10cSrcweir         if( xGrabber.is() )
537cdf0e10cSrcweir         {
538cdf0e10cSrcweir             if( AVMEDIA_FRAMEGRABBER_DEFAULTFRAME == fMediaTime )
539cdf0e10cSrcweir                 fMediaTime = AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME;
540cdf0e10cSrcweir 
541cdf0e10cSrcweir             if( fMediaTime >= xPlayer->getDuration() )
542cdf0e10cSrcweir                 fMediaTime = ( xPlayer->getDuration() * 0.5 );
543cdf0e10cSrcweir 
544cdf0e10cSrcweir             xRet = xGrabber->grabFrame( fMediaTime );
545cdf0e10cSrcweir         }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir         if( !xRet.is() && bAllowToCreateReplacementGraphic )
548cdf0e10cSrcweir         {
549cdf0e10cSrcweir             awt::Size aPrefSize( xPlayer->getPreferredPlayerWindowSize() );
550cdf0e10cSrcweir 
551cdf0e10cSrcweir             if( !aPrefSize.Width && !aPrefSize.Height )
552cdf0e10cSrcweir             {
553cdf0e10cSrcweir                 const BitmapEx aBmpEx( AVMEDIA_RESID( AVMEDIA_BMP_AUDIOLOGO ) );
554cdf0e10cSrcweir                 apGraphic.reset( new Graphic( aBmpEx ) );
555cdf0e10cSrcweir             }
556cdf0e10cSrcweir         }
557cdf0e10cSrcweir     }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir     if( !xRet.is() && !apGraphic.get() && bAllowToCreateReplacementGraphic )
560cdf0e10cSrcweir     {
561cdf0e10cSrcweir         const BitmapEx aBmpEx( AVMEDIA_RESID( AVMEDIA_BMP_EMPTYLOGO ) );
562cdf0e10cSrcweir         apGraphic.reset( new Graphic( aBmpEx ) );
563cdf0e10cSrcweir     }
564cdf0e10cSrcweir 
565cdf0e10cSrcweir     if( apGraphic.get() )
566cdf0e10cSrcweir         xRet = apGraphic->GetXGraphic();
567cdf0e10cSrcweir 
568cdf0e10cSrcweir     return xRet;
569cdf0e10cSrcweir }
570cdf0e10cSrcweir 
571*6bd6a4b4Smseidel } // namespace avmedia
572