LCOV - code coverage report
Current view: top level - sd/source/ui/dlg - filedlg.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 108 0.0 %
Date: 2014-04-14 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10