1*5b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5b190011SAndrew Rist * distributed with this work for additional information 6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance 9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5b190011SAndrew Rist * software distributed under the License is distributed on an 15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the 17*5b190011SAndrew Rist * specific language governing permissions and limitations 18*5b190011SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*5b190011SAndrew Rist *************************************************************/ 21*5b190011SAndrew Rist 22*5b190011SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sd.hxx" 26cdf0e10cSrcweir #include <tools/debug.hxx> 27cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 28cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 29cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 30cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 31cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 32cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp> 33cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 34cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 35cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> 36cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp> 37cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp> 38cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp> 39cdf0e10cSrcweir #include <vcl/msgbox.hxx> 40cdf0e10cSrcweir #include <sal/types.h> 41cdf0e10cSrcweir #include <tools/urlobj.hxx> 42cdf0e10cSrcweir #include <vos/thread.hxx> 43cdf0e10cSrcweir #include <vos/mutex.hxx> 44cdf0e10cSrcweir #include <vcl/svapp.hxx> 45cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx> 46cdf0e10cSrcweir #include <avmedia/mediawindow.hxx> 47cdf0e10cSrcweir #include "filedlg.hxx" 48cdf0e10cSrcweir #include "sdresid.hxx" 49cdf0e10cSrcweir #include "strings.hrc" 50cdf0e10cSrcweir #include <svtools/filter.hxx> 51cdf0e10cSrcweir 52cdf0e10cSrcweir 53cdf0e10cSrcweir //----------------------------------------------------------------------------- 54cdf0e10cSrcweir 55cdf0e10cSrcweir namespace css = ::com::sun::star; 56cdf0e10cSrcweir 57cdf0e10cSrcweir 58cdf0e10cSrcweir // -------------------------------------------------------------------- 59cdf0e10cSrcweir // ----------- SdFileDialog_Imp --------------------------- 60cdf0e10cSrcweir // -------------------------------------------------------------------- 61cdf0e10cSrcweir class SdFileDialog_Imp : public sfx2::FileDialogHelper 62cdf0e10cSrcweir { 63cdf0e10cSrcweir private: 64cdf0e10cSrcweir #if defined __SUNPRO_CC 65cdf0e10cSrcweir using sfx2::FileDialogHelper::Execute; 66cdf0e10cSrcweir #endif 67cdf0e10cSrcweir 68cdf0e10cSrcweir friend class SdOpenSoundFileDialog; 69cdf0e10cSrcweir 70cdf0e10cSrcweir css::uno::Reference< css::ui::dialogs::XFilePickerControlAccess > mxControlAccess; 71cdf0e10cSrcweir 72cdf0e10cSrcweir css::uno::Reference< css::media::XPlayer > mxPlayer; 73cdf0e10cSrcweir sal_uLong mnPlaySoundEvent; 74cdf0e10cSrcweir sal_Bool mbUsableSelection; 75cdf0e10cSrcweir sal_Bool mbLabelPlaying; 76cdf0e10cSrcweir 77cdf0e10cSrcweir void CheckSelectionState(); 78cdf0e10cSrcweir 79cdf0e10cSrcweir DECL_LINK( PlayMusicHdl, void * ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir Timer maUpdateTimer; 82cdf0e10cSrcweir 83cdf0e10cSrcweir DECL_LINK( IsMusicStoppedHdl, void * ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir public: 86cdf0e10cSrcweir SdFileDialog_Imp( const short nDialogType, sal_Bool bUsableSelection ); 87cdf0e10cSrcweir ~SdFileDialog_Imp(); 88cdf0e10cSrcweir 89cdf0e10cSrcweir ErrCode Execute(); 90cdf0e10cSrcweir 91cdf0e10cSrcweir // overwritten from FileDialogHelper, to receive user feedback 92cdf0e10cSrcweir virtual void SAL_CALL ControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent ); 93cdf0e10cSrcweir }; 94cdf0e10cSrcweir 95cdf0e10cSrcweir // ------------------------------------------------------------------------ 96cdf0e10cSrcweir void SAL_CALL SdFileDialog_Imp::ControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir switch( aEvent.ElementId ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir case css::ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER: 103cdf0e10cSrcweir CheckSelectionState(); 104cdf0e10cSrcweir break; 105cdf0e10cSrcweir 106cdf0e10cSrcweir case css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY: 107cdf0e10cSrcweir if( mxControlAccess.is() ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir if( mnPlaySoundEvent ) 110cdf0e10cSrcweir Application::RemoveUserEvent( mnPlaySoundEvent ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir mnPlaySoundEvent = Application::PostUserEvent( LINK( this, SdFileDialog_Imp, PlayMusicHdl ) ); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir break; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir // ------------------------------------------------------------------------ 119cdf0e10cSrcweir IMPL_LINK( SdFileDialog_Imp, PlayMusicHdl, void *, EMPTYARG ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir maUpdateTimer.Stop(); 122cdf0e10cSrcweir mnPlaySoundEvent = 0; 123cdf0e10cSrcweir 124cdf0e10cSrcweir if (mxPlayer.is()) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir if (mxPlayer->isPlaying()) 127cdf0e10cSrcweir mxPlayer->stop(); 128cdf0e10cSrcweir mxPlayer.clear(); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir if( mbLabelPlaying ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir try 134cdf0e10cSrcweir { 135cdf0e10cSrcweir mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY, 136cdf0e10cSrcweir String( SdResId( STR_PLAY ) ) ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir mbLabelPlaying = sal_False; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir catch( css::lang::IllegalArgumentException ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir #ifdef DBG_UTIL 143cdf0e10cSrcweir DBG_ERROR( "Cannot access play button" ); 144cdf0e10cSrcweir #endif 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir else 148cdf0e10cSrcweir { 149cdf0e10cSrcweir rtl::OUString aUrl( GetPath() ); 150cdf0e10cSrcweir if ( aUrl.getLength() ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir try 153cdf0e10cSrcweir { 154cdf0e10cSrcweir mxPlayer.set( avmedia::MediaWindow::createPlayer( aUrl ), css::uno::UNO_QUERY_THROW ); 155cdf0e10cSrcweir mxPlayer->start(); 156cdf0e10cSrcweir maUpdateTimer.SetTimeout( 100 ); 157cdf0e10cSrcweir maUpdateTimer.Start(); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir catch( css::uno::Exception& e ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir (void)e; 162cdf0e10cSrcweir mxPlayer.clear(); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir if (mxPlayer.is()) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir try 168cdf0e10cSrcweir { 169cdf0e10cSrcweir mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY, 170cdf0e10cSrcweir String( SdResId( STR_STOP ) ) ); 171cdf0e10cSrcweir 172cdf0e10cSrcweir mbLabelPlaying = sal_True; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir catch( css::lang::IllegalArgumentException ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir #ifdef DBG_UTIL 177cdf0e10cSrcweir DBG_ERROR( "Cannot access play button" ); 178cdf0e10cSrcweir #endif 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir return 0; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir // ------------------------------------------------------------------------ 188cdf0e10cSrcweir IMPL_LINK( SdFileDialog_Imp, IsMusicStoppedHdl, void *, EMPTYARG ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 191cdf0e10cSrcweir 192cdf0e10cSrcweir if ( 193cdf0e10cSrcweir mxPlayer.is() && mxPlayer->isPlaying() && 194cdf0e10cSrcweir mxPlayer->getMediaTime() < mxPlayer->getDuration() 195cdf0e10cSrcweir ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir maUpdateTimer.Start(); 198cdf0e10cSrcweir return 0L; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir 202cdf0e10cSrcweir if( mxControlAccess.is() ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir try 205cdf0e10cSrcweir { 206cdf0e10cSrcweir mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY, 207cdf0e10cSrcweir String( SdResId( STR_PLAY ) ) ); 208cdf0e10cSrcweir mbLabelPlaying = sal_False; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir catch( css::lang::IllegalArgumentException ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir #ifdef DBG_UTIL 213cdf0e10cSrcweir DBG_ERROR( "Cannot access play button" ); 214cdf0e10cSrcweir #endif 215cdf0e10cSrcweir } 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir return( 0L ); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir // check whether to disable the "selection" checkbox 222cdf0e10cSrcweir void SdFileDialog_Imp::CheckSelectionState() 223cdf0e10cSrcweir { 224cdf0e10cSrcweir if( mbUsableSelection && mxControlAccess.is() ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir String aCurrFilter( GetCurrentFilter() ); 227cdf0e10cSrcweir 228cdf0e10cSrcweir try 229cdf0e10cSrcweir { 230cdf0e10cSrcweir if( !aCurrFilter.Len() || ( aCurrFilter == String( SdResId( STR_EXPORT_HTML_NAME ) ) ) ) 231cdf0e10cSrcweir mxControlAccess->enableControl( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, sal_False ); 232cdf0e10cSrcweir else 233cdf0e10cSrcweir mxControlAccess->enableControl( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, sal_True ); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir catch( css::lang::IllegalArgumentException ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir #ifdef DBG_UTIL 238cdf0e10cSrcweir DBG_ERROR( "Cannot access \"selection\" checkbox" ); 239cdf0e10cSrcweir #endif 240cdf0e10cSrcweir } 241cdf0e10cSrcweir } 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir //----------------------------------------------------------------------------- 245cdf0e10cSrcweir SdFileDialog_Imp::SdFileDialog_Imp( const short nDialogType, 246cdf0e10cSrcweir sal_Bool bUsableSelection ) : 247cdf0e10cSrcweir FileDialogHelper( nDialogType, 0 ), 248cdf0e10cSrcweir mnPlaySoundEvent( 0 ), 249cdf0e10cSrcweir mbUsableSelection( bUsableSelection ), 250cdf0e10cSrcweir mbLabelPlaying(sal_False) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir maUpdateTimer.SetTimeoutHdl(LINK(this, SdFileDialog_Imp, IsMusicStoppedHdl)); 253cdf0e10cSrcweir 254cdf0e10cSrcweir css::uno::Reference < ::com::sun::star::ui::dialogs::XFilePicker > xFileDlg = GetFilePicker(); 255cdf0e10cSrcweir 256cdf0e10cSrcweir // get the control access 257cdf0e10cSrcweir mxControlAccess = css::uno::Reference< css::ui::dialogs::XFilePickerControlAccess > ( xFileDlg, css::uno::UNO_QUERY ); 258cdf0e10cSrcweir 259cdf0e10cSrcweir if( mxControlAccess.is() ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir if( nDialogType == 262cdf0e10cSrcweir css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir try 265cdf0e10cSrcweir { 266cdf0e10cSrcweir mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY, 267cdf0e10cSrcweir String( SdResId( STR_PLAY ) ) ); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir catch( css::lang::IllegalArgumentException ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir #ifdef DBG_UTIL 272cdf0e10cSrcweir DBG_ERROR( "Cannot set play button label" ); 273cdf0e10cSrcweir #endif 274cdf0e10cSrcweir } 275cdf0e10cSrcweir } 276cdf0e10cSrcweir else if( mbUsableSelection != sal_True ) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir try 279cdf0e10cSrcweir { 280cdf0e10cSrcweir mxControlAccess->enableControl( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, sal_False ); 281cdf0e10cSrcweir } 282cdf0e10cSrcweir catch( css::lang::IllegalArgumentException ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir #ifdef DBG_UTIL 285cdf0e10cSrcweir DBG_ERROR( "Cannot disable selection checkbox" ); 286cdf0e10cSrcweir #endif 287cdf0e10cSrcweir } 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir 293cdf0e10cSrcweir // ------------------------------------------------------------------------ 294cdf0e10cSrcweir SdFileDialog_Imp::~SdFileDialog_Imp() 295cdf0e10cSrcweir { 296cdf0e10cSrcweir if( mnPlaySoundEvent ) 297cdf0e10cSrcweir Application::RemoveUserEvent( mnPlaySoundEvent ); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir // ------------------------------------------------------------------------ 301cdf0e10cSrcweir ErrCode SdFileDialog_Imp::Execute() 302cdf0e10cSrcweir { 303cdf0e10cSrcweir // make sure selection checkbox is disabled if 304cdf0e10cSrcweir // HTML is current filter! 305cdf0e10cSrcweir CheckSelectionState(); 306cdf0e10cSrcweir return FileDialogHelper::Execute(); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir // -------------------------------------------------------------------- 310cdf0e10cSrcweir // ----------- SdOpenSoundFileDialog ----------------------- 311cdf0e10cSrcweir // -------------------------------------------------------------------- 312cdf0e10cSrcweir 313cdf0e10cSrcweir // these are simple forwarders 314cdf0e10cSrcweir SdOpenSoundFileDialog::SdOpenSoundFileDialog() : 315cdf0e10cSrcweir mpImpl( 316cdf0e10cSrcweir new SdFileDialog_Imp( 317cdf0e10cSrcweir css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY, sal_False ) ) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir String aDescr; 320cdf0e10cSrcweir aDescr = String(SdResId(STR_ALL_FILES)); 321cdf0e10cSrcweir mpImpl->AddFilter( aDescr, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.*" ) ) ); 322cdf0e10cSrcweir 323cdf0e10cSrcweir // setup filter 324cdf0e10cSrcweir #if defined UNX 325cdf0e10cSrcweir aDescr = String(SdResId(STR_AU_FILE)); 326cdf0e10cSrcweir mpImpl->AddFilter( aDescr, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.au;*.snd" ) ) ); 327cdf0e10cSrcweir aDescr = String(SdResId(STR_VOC_FILE)); 328cdf0e10cSrcweir mpImpl->AddFilter( aDescr, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.voc" ) ) ); 329cdf0e10cSrcweir aDescr = String(SdResId(STR_WAV_FILE)); 330cdf0e10cSrcweir mpImpl->AddFilter( aDescr, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.wav" ) ) ); 331cdf0e10cSrcweir aDescr = String(SdResId(STR_AIFF_FILE)); 332cdf0e10cSrcweir mpImpl->AddFilter( aDescr, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.aiff" ) ) ); 333cdf0e10cSrcweir aDescr = String(SdResId(STR_SVX_FILE)); 334cdf0e10cSrcweir mpImpl->AddFilter( aDescr, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.svx" ) ) ); 335cdf0e10cSrcweir #else 336cdf0e10cSrcweir aDescr = String(SdResId(STR_WAV_FILE)); 337cdf0e10cSrcweir mpImpl->AddFilter( aDescr, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.wav;*.mp3;*.ogg" ) ) ); 338cdf0e10cSrcweir aDescr = String(SdResId(STR_MIDI_FILE)); 339cdf0e10cSrcweir mpImpl->AddFilter( aDescr, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.mid" ) ) ); 340cdf0e10cSrcweir #endif 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir // ------------------------------------------------------------------------ 344cdf0e10cSrcweir SdOpenSoundFileDialog::~SdOpenSoundFileDialog() 345cdf0e10cSrcweir { 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir // ------------------------------------------------------------------------ 349cdf0e10cSrcweir ErrCode SdOpenSoundFileDialog::Execute() 350cdf0e10cSrcweir { 351cdf0e10cSrcweir return mpImpl->Execute(); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir // ------------------------------------------------------------------------ 355cdf0e10cSrcweir String SdOpenSoundFileDialog::GetPath() const 356cdf0e10cSrcweir { 357cdf0e10cSrcweir return mpImpl->GetPath(); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir // ------------------------------------------------------------------------ 361cdf0e10cSrcweir void SdOpenSoundFileDialog::SetPath( const String& rPath ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir mpImpl->SetDisplayDirectory( rPath ); 364cdf0e10cSrcweir } 365