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

Generated by: LCOV version 1.10