LCOV - code coverage report
Current view: top level - sd/source/ui/dlg - filedlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 108 0.9 %
Date: 2015-06-13 12:38:46 Functions: 2 17 11.8 %
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 <cppuhelper/implbase1.hxx>
      21             : #include <comphelper/processfactory.hxx>
      22             : #include <com/sun/star/lang/XInitialization.hpp>
      23             : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
      24             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      25             : #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
      26             : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
      27             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      28             : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
      29             : #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
      30             : #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
      31             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      32             : #include <vcl/msgbox.hxx>
      33             : #include <vcl/idle.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             : // -----------      SdFileDialog_Imp        ---------------------------
      46             : 
      47             : class SdFileDialog_Imp : public sfx2::FileDialogHelper
      48             : {
      49             : private:
      50             :     friend class SdOpenSoundFileDialog;
      51             : 
      52             :     css::uno::Reference< css::ui::dialogs::XFilePickerControlAccess >   mxControlAccess;
      53             : 
      54             :     css::uno::Reference< css::media::XPlayer > mxPlayer;
      55             :     ImplSVEvent *               mnPlaySoundEvent;
      56             :     bool                        mbUsableSelection;
      57             :     bool                        mbLabelPlaying;
      58             : 
      59             :     void                        CheckSelectionState();
      60             : 
      61             :                                 DECL_LINK( PlayMusicHdl, void * );
      62             : 
      63             :     Idle                        maUpdateIdle;
      64             : 
      65             :                                 DECL_LINK_TYPED( IsMusicStoppedHdl, Idle *, void );
      66             : 
      67             : public:
      68             :                                 SdFileDialog_Imp( const short nDialogType, bool bUsableSelection );
      69             :                                    virtual ~SdFileDialog_Imp();
      70             : 
      71             :     ErrCode                     Execute();
      72             : 
      73             :     // overwritten from FileDialogHelper, to receive user feedback
      74             :     virtual void SAL_CALL       ControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent ) SAL_OVERRIDE;
      75             : };
      76             : 
      77           0 : void SAL_CALL SdFileDialog_Imp::ControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent )
      78             : {
      79           0 :     SolarMutexGuard aGuard;
      80             : 
      81           0 :     switch( aEvent.ElementId )
      82             :     {
      83             :         case css::ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER:
      84           0 :             CheckSelectionState();
      85           0 :             break;
      86             : 
      87             :         case css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
      88           0 :             if( mxControlAccess.is() )
      89             :             {
      90           0 :                 if( mnPlaySoundEvent )
      91           0 :                     Application::RemoveUserEvent( mnPlaySoundEvent );
      92             : 
      93           0 :                 mnPlaySoundEvent = Application::PostUserEvent( LINK( this, SdFileDialog_Imp, PlayMusicHdl ) );
      94             :             }
      95           0 :             break;
      96           0 :     }
      97           0 : }
      98             : 
      99           0 : IMPL_LINK_NOARG(SdFileDialog_Imp, PlayMusicHdl)
     100             : {
     101           0 :     maUpdateIdle.Stop();
     102           0 :     mnPlaySoundEvent = 0;
     103             : 
     104           0 :     if (mxPlayer.is())
     105             :     {
     106           0 :         if (mxPlayer->isPlaying())
     107           0 :             mxPlayer->stop();
     108           0 :         mxPlayer.clear();
     109             :     }
     110             : 
     111           0 :     if( mbLabelPlaying )
     112             :     {
     113             :         try
     114             :         {
     115           0 :             mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY,
     116           0 :                                        SD_RESSTR( STR_PLAY ) );
     117             : 
     118           0 :             mbLabelPlaying = false;
     119             :         }
     120           0 :         catch(const css::lang::IllegalArgumentException&)
     121             :         {
     122             : #ifdef DBG_UTIL
     123             :             OSL_FAIL( "Cannot access play button" );
     124             : #endif
     125             :         }
     126             :     }
     127             :     else
     128             :     {
     129           0 :         OUString aUrl( GetPath() );
     130           0 :         if ( !aUrl.isEmpty() )
     131             :         {
     132             :             try
     133             :             {
     134           0 :                 mxPlayer.set( avmedia::MediaWindow::createPlayer( aUrl, "" ), css::uno::UNO_QUERY_THROW );
     135           0 :                 mxPlayer->start();
     136           0 :                 maUpdateIdle.SetPriority( SchedulerPriority::LOW );
     137           0 :                 maUpdateIdle.Start();
     138             :             }
     139           0 :             catch (const css::uno::Exception&)
     140             :             {
     141           0 :                 mxPlayer.clear();
     142             :             }
     143             : 
     144           0 :             if (mxPlayer.is())
     145             :             {
     146             :                 try
     147             :                 {
     148           0 :                     mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY,
     149           0 :                                                SD_RESSTR( STR_STOP ) );
     150             : 
     151           0 :                     mbLabelPlaying = true;
     152             :                 }
     153           0 :                 catch (const css::lang::IllegalArgumentException&)
     154             :                 {
     155             : #ifdef DBG_UTIL
     156             :                     OSL_FAIL( "Cannot access play button" );
     157             : #endif
     158             :                 }
     159             :             }
     160           0 :         }
     161             :     }
     162             : 
     163           0 :     return 0;
     164             : }
     165             : 
     166           0 : IMPL_LINK_NOARG_TYPED(SdFileDialog_Imp, IsMusicStoppedHdl, Idle *, void)
     167             : {
     168           0 :     SolarMutexGuard aGuard;
     169             : 
     170           0 :     if (
     171           0 :         mxPlayer.is() && mxPlayer->isPlaying() &&
     172           0 :         mxPlayer->getMediaTime() < mxPlayer->getDuration()
     173             :        )
     174             :     {
     175           0 :         maUpdateIdle.Start();
     176           0 :         return;
     177             :     }
     178             : 
     179           0 :     if( mxControlAccess.is() )
     180             :     {
     181             :         try
     182             :         {
     183           0 :             mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY,
     184           0 :                                        SD_RESSTR( STR_PLAY ) );
     185           0 :             mbLabelPlaying = false;
     186             :         }
     187           0 :         catch (const css::lang::IllegalArgumentException&)
     188             :         {
     189             : #ifdef DBG_UTIL
     190             :             OSL_FAIL( "Cannot access play button" );
     191             : #endif
     192             :         }
     193           0 :     }
     194             : }
     195             : 
     196             : // check whether to disable the "selection" checkbox
     197           0 : void SdFileDialog_Imp::CheckSelectionState()
     198             : {
     199           0 :     if( mbUsableSelection && mxControlAccess.is() )
     200             :     {
     201           0 :         OUString  aCurrFilter( GetCurrentFilter() );
     202             : 
     203             :         try
     204             :         {
     205           0 :             if( aCurrFilter.isEmpty() || ( aCurrFilter == SD_RESSTR( STR_EXPORT_HTML_NAME ) ) )
     206           0 :                 mxControlAccess->enableControl( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, sal_False );
     207             :             else
     208           0 :                 mxControlAccess->enableControl( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, sal_True );
     209             :         }
     210           0 :         catch (const css::lang::IllegalArgumentException&)
     211             :         {
     212             : #ifdef DBG_UTIL
     213             :             OSL_FAIL( "Cannot access \"selection\" checkbox" );
     214             : #endif
     215           0 :         }
     216             :     }
     217           0 : }
     218             : 
     219           0 : SdFileDialog_Imp::SdFileDialog_Imp( const short     nDialogType,
     220             :                                     bool        bUsableSelection    ) :
     221             :     FileDialogHelper( nDialogType, 0 ),
     222             :     mnPlaySoundEvent( 0 ),
     223             :     mbUsableSelection( bUsableSelection ),
     224           0 :     mbLabelPlaying(false)
     225             : {
     226           0 :     maUpdateIdle.SetIdleHdl(LINK(this, SdFileDialog_Imp, IsMusicStoppedHdl));
     227             : 
     228           0 :     css::uno::Reference < ::com::sun::star::ui::dialogs::XFilePicker > xFileDlg = GetFilePicker();
     229             : 
     230             :     // get the control access
     231           0 :     mxControlAccess = css::uno::Reference< css::ui::dialogs::XFilePickerControlAccess > ( xFileDlg, css::uno::UNO_QUERY );
     232             : 
     233           0 :     if( mxControlAccess.is() )
     234             :     {
     235           0 :         if( nDialogType ==
     236             :             css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY )
     237             :         {
     238             :             try
     239             :             {
     240           0 :                 mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY,
     241           0 :                                            SD_RESSTR( STR_PLAY ) );
     242             :             }
     243           0 :             catch (const css::lang::IllegalArgumentException&)
     244             :             {
     245             : #ifdef DBG_UTIL
     246             :                 OSL_FAIL( "Cannot set play button label" );
     247             : #endif
     248             :             }
     249             :         }
     250           0 :         else if( !mbUsableSelection )
     251             :         {
     252             :             try
     253             :             {
     254           0 :                 mxControlAccess->enableControl( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, sal_False );
     255             :             }
     256           0 :             catch (const css::lang::IllegalArgumentException&)
     257             :             {
     258             : #ifdef DBG_UTIL
     259             :                 OSL_FAIL( "Cannot disable selection checkbox" );
     260             : #endif
     261             :             }
     262             :         }
     263           0 :     }
     264           0 : }
     265             : 
     266           0 : SdFileDialog_Imp::~SdFileDialog_Imp()
     267             : {
     268           0 :     if( mnPlaySoundEvent )
     269           0 :         Application::RemoveUserEvent( mnPlaySoundEvent );
     270           0 : }
     271             : 
     272           0 : ErrCode SdFileDialog_Imp::Execute()
     273             : {
     274             :     // make sure selection checkbox is disabled if
     275             :     // HTML is current filter!
     276           0 :     CheckSelectionState();
     277           0 :     return FileDialogHelper::Execute();
     278             : }
     279             : 
     280             : // -----------      SdOpenSoundFileDialog       -----------------------
     281             : 
     282             : // these are simple forwarders
     283           0 : SdOpenSoundFileDialog::SdOpenSoundFileDialog() :
     284             :     mpImpl(
     285             :         new SdFileDialog_Imp(
     286           0 :             css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY, false ) )
     287             : {
     288           0 :     OUString aDescr;
     289           0 :     aDescr = SD_RESSTR(STR_ALL_FILES);
     290           0 :     mpImpl->AddFilter( aDescr, OUString("*.*"));
     291             : 
     292             :     // setup filter
     293             : #if defined UNX
     294           0 :     aDescr = SD_RESSTR(STR_AU_FILE);
     295           0 :     mpImpl->AddFilter( aDescr, OUString("*.au;*.snd" ));
     296           0 :     aDescr = SD_RESSTR(STR_VOC_FILE);
     297           0 :     mpImpl->AddFilter( aDescr, OUString("*.voc" ));
     298           0 :     aDescr = SD_RESSTR(STR_WAV_FILE);
     299           0 :     mpImpl->AddFilter( aDescr, OUString("*.wav" ));
     300           0 :     aDescr = SD_RESSTR(STR_AIFF_FILE);
     301           0 :     mpImpl->AddFilter( aDescr, OUString("*.aiff" ));
     302           0 :     aDescr = SD_RESSTR(STR_SVX_FILE);
     303           0 :     mpImpl->AddFilter( aDescr, OUString("*.svx" ));
     304             : #else
     305             :     aDescr = SD_RESSTR(STR_WAV_FILE);
     306             :     mpImpl->AddFilter( aDescr, OUString("*.wav;*.mp3;*.ogg" ));
     307             :     aDescr = SD_RESSTR(STR_MIDI_FILE);
     308             :     mpImpl->AddFilter( aDescr, OUString("*.mid" ));
     309             : #endif
     310           0 : }
     311             : 
     312           0 : SdOpenSoundFileDialog::~SdOpenSoundFileDialog()
     313             : {
     314           0 : }
     315             : 
     316           0 : ErrCode SdOpenSoundFileDialog::Execute()
     317             : {
     318           0 :     return mpImpl->Execute();
     319             : }
     320             : 
     321           0 : OUString SdOpenSoundFileDialog::GetPath() const
     322             : {
     323           0 :     return mpImpl->GetPath();
     324             : }
     325             : 
     326           0 : void SdOpenSoundFileDialog::SetPath( const OUString& rPath )
     327             : {
     328           0 :     mpImpl->SetDisplayDirectory( rPath );
     329          66 : }
     330             : 
     331             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11