LCOV - code coverage report
Current view: top level - sd/source/ui/dlg - filedlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 108 0.0 %
Date: 2012-08-25 Functions: 0 15 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 307 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <tools/debug.hxx>
      30                 :            : #include <cppuhelper/implbase1.hxx>
      31                 :            : #include <comphelper/processfactory.hxx>
      32                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      33                 :            : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
      34                 :            : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      35                 :            : #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
      36                 :            : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
      37                 :            : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      38                 :            : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
      39                 :            : #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
      40                 :            : #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
      41                 :            : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      42                 :            : #include <vcl/msgbox.hxx>
      43                 :            : #include <sal/types.h>
      44                 :            : #include <osl/thread.hxx>
      45                 :            : #include <osl/mutex.hxx>
      46                 :            : #include <vcl/svapp.hxx>
      47                 :            : #include <sfx2/filedlghelper.hxx>
      48                 :            : #include <avmedia/mediawindow.hxx>
      49                 :            : #include "filedlg.hxx"
      50                 :            : #include "sdresid.hxx"
      51                 :            : #include "strings.hrc"
      52                 :            : #include <svtools/filter.hxx>
      53                 :            : 
      54                 :            : 
      55                 :            : //-----------------------------------------------------------------------------
      56                 :            : 
      57                 :            : namespace css = ::com::sun::star;
      58                 :            : 
      59                 :            : 
      60                 :            : // --------------------------------------------------------------------
      61                 :            : // -----------      SdFileDialog_Imp        ---------------------------
      62                 :            : // --------------------------------------------------------------------
      63                 :            : class SdFileDialog_Imp : public sfx2::FileDialogHelper
      64                 :            : {
      65                 :            : private:
      66                 :            : #if defined __SUNPRO_CC
      67                 :            :     using sfx2::FileDialogHelper::Execute;
      68                 :            : #endif
      69                 :            : 
      70                 :            :     friend class SdOpenSoundFileDialog;
      71                 :            : 
      72                 :            :     css::uno::Reference< css::ui::dialogs::XFilePickerControlAccess >   mxControlAccess;
      73                 :            : 
      74                 :            :     css::uno::Reference< css::media::XPlayer > mxPlayer;
      75                 :            :     sal_uLong                       mnPlaySoundEvent;
      76                 :            :     sal_Bool                        mbUsableSelection;
      77                 :            :     sal_Bool                        mbLabelPlaying;
      78                 :            : 
      79                 :            :     void                        CheckSelectionState();
      80                 :            : 
      81                 :            :                                 DECL_LINK( PlayMusicHdl, void * );
      82                 :            : 
      83                 :            :     Timer                       maUpdateTimer;
      84                 :            : 
      85                 :            :                                 DECL_LINK( IsMusicStoppedHdl, void * );
      86                 :            : 
      87                 :            : public:
      88                 :            :                                 SdFileDialog_Imp( const short nDialogType, sal_Bool bUsableSelection );
      89                 :            :                                    ~SdFileDialog_Imp();
      90                 :            : 
      91                 :            :     ErrCode                     Execute();
      92                 :            : 
      93                 :            :     // overwritten from FileDialogHelper, to receive user feedback
      94                 :            :     virtual void SAL_CALL       ControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent );
      95                 :            : };
      96                 :            : 
      97                 :            : // ------------------------------------------------------------------------
      98                 :          0 : void SAL_CALL SdFileDialog_Imp::ControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent )
      99                 :            : {
     100         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     101                 :            : 
     102      [ #  #  # ]:          0 :     switch( aEvent.ElementId )
     103                 :            :     {
     104                 :            :         case css::ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER:
     105         [ #  # ]:          0 :             CheckSelectionState();
     106                 :          0 :             break;
     107                 :            : 
     108                 :            :         case css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
     109         [ #  # ]:          0 :             if( mxControlAccess.is() )
     110                 :            :             {
     111         [ #  # ]:          0 :                 if( mnPlaySoundEvent )
     112         [ #  # ]:          0 :                     Application::RemoveUserEvent( mnPlaySoundEvent );
     113                 :            : 
     114 [ #  # ][ #  # ]:          0 :                 mnPlaySoundEvent = Application::PostUserEvent( LINK( this, SdFileDialog_Imp, PlayMusicHdl ) );
     115                 :            :             }
     116                 :          0 :             break;
     117         [ #  # ]:          0 :     }
     118                 :          0 : }
     119                 :            : 
     120                 :            : // ------------------------------------------------------------------------
     121                 :          0 : IMPL_LINK_NOARG(SdFileDialog_Imp, PlayMusicHdl)
     122                 :            : {
     123                 :          0 :     maUpdateTimer.Stop();
     124                 :          0 :     mnPlaySoundEvent = 0;
     125                 :            : 
     126         [ #  # ]:          0 :     if (mxPlayer.is())
     127                 :            :     {
     128         [ #  # ]:          0 :         if (mxPlayer->isPlaying())
     129                 :          0 :             mxPlayer->stop();
     130                 :          0 :         mxPlayer.clear();
     131                 :            :     }
     132                 :            : 
     133         [ #  # ]:          0 :     if( mbLabelPlaying )
     134                 :            :     {
     135                 :            :         try
     136                 :            :         {
     137         [ #  # ]:          0 :             mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY,
     138 [ #  # ][ #  # ]:          0 :                                        String( SdResId( STR_PLAY ) ) );
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     139                 :            : 
     140                 :          0 :             mbLabelPlaying = sal_False;
     141                 :            :         }
     142                 :          0 :         catch(const css::lang::IllegalArgumentException&)
     143                 :            :         {
     144                 :            : #ifdef DBG_UTIL
     145                 :            :             OSL_FAIL( "Cannot access play button" );
     146                 :            : #endif
     147                 :            :         }
     148                 :            :     }
     149                 :            :     else
     150                 :            :     {
     151 [ #  # ][ #  # ]:          0 :         rtl::OUString aUrl( GetPath() );
                 [ #  # ]
     152         [ #  # ]:          0 :         if ( !aUrl.isEmpty() )
     153                 :            :         {
     154                 :            :             try
     155                 :            :             {
     156 [ #  # ][ #  # ]:          0 :                 mxPlayer.set( avmedia::MediaWindow::createPlayer( aUrl ), css::uno::UNO_QUERY_THROW );
                 [ #  # ]
     157 [ #  # ][ #  # ]:          0 :                 mxPlayer->start();
     158         [ #  # ]:          0 :                 maUpdateTimer.SetTimeout( 100 );
     159         [ #  # ]:          0 :                 maUpdateTimer.Start();
     160                 :            :             }
     161         [ #  # ]:          0 :             catch (const css::uno::Exception&)
     162                 :            :             {
     163                 :          0 :                 mxPlayer.clear();
     164                 :            :             }
     165                 :            : 
     166         [ #  # ]:          0 :             if (mxPlayer.is())
     167                 :            :             {
     168                 :            :                 try
     169                 :            :                 {
     170         [ #  # ]:          0 :                     mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY,
     171 [ #  # ][ #  # ]:          0 :                                                String( SdResId( STR_STOP ) ) );
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     172                 :            : 
     173                 :          0 :                     mbLabelPlaying = sal_True;
     174                 :            :                 }
     175         [ #  # ]:          0 :                 catch (const css::lang::IllegalArgumentException&)
     176                 :            :                 {
     177                 :            : #ifdef DBG_UTIL
     178                 :            :                     OSL_FAIL( "Cannot access play button" );
     179                 :            : #endif
     180                 :            :                 }
     181                 :            :             }
     182                 :          0 :         }
     183                 :            :     }
     184                 :            : 
     185                 :          0 :     return 0;
     186                 :            : }
     187                 :            : 
     188                 :            : // ------------------------------------------------------------------------
     189                 :          0 : IMPL_LINK_NOARG(SdFileDialog_Imp, IsMusicStoppedHdl)
     190                 :            : {
     191         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     192                 :            : 
     193 [ #  # ][ #  # ]:          0 :     if (
         [ #  # ][ #  # ]
     194 [ #  # ][ #  # ]:          0 :         mxPlayer.is() && mxPlayer->isPlaying() &&
     195 [ #  # ][ #  # ]:          0 :         mxPlayer->getMediaTime() < mxPlayer->getDuration()
         [ #  # ][ #  # ]
     196                 :            :        )
     197                 :            :     {
     198         [ #  # ]:          0 :         maUpdateTimer.Start();
     199                 :          0 :         return 0L;
     200                 :            :     }
     201                 :            : 
     202                 :            : 
     203         [ #  # ]:          0 :     if( mxControlAccess.is() )
     204                 :            :     {
     205                 :            :         try
     206                 :            :         {
     207         [ #  # ]:          0 :             mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY,
     208 [ #  # ][ #  # ]:          0 :                                        String( SdResId( STR_PLAY ) ) );
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     209                 :          0 :             mbLabelPlaying = sal_False;
     210                 :            :         }
     211         [ #  # ]:          0 :         catch (const css::lang::IllegalArgumentException&)
     212                 :            :         {
     213                 :            : #ifdef DBG_UTIL
     214                 :            :             OSL_FAIL( "Cannot access play button" );
     215                 :            : #endif
     216                 :            :         }
     217                 :            :     }
     218                 :            : 
     219         [ #  # ]:          0 :     return( 0L );
     220                 :            : }
     221                 :            : 
     222                 :            : // check whether to disable the "selection" checkbox
     223                 :          0 : void SdFileDialog_Imp::CheckSelectionState()
     224                 :            : {
     225 [ #  # ][ #  # ]:          0 :     if( mbUsableSelection && mxControlAccess.is() )
                 [ #  # ]
     226                 :            :     {
     227         [ #  # ]:          0 :         String  aCurrFilter( GetCurrentFilter() );
     228                 :            : 
     229                 :            :         try
     230                 :            :         {
     231 [ #  # ][ #  # ]:          0 :             if( !aCurrFilter.Len() || ( aCurrFilter == String( SdResId( STR_EXPORT_HTML_NAME ) ) ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
             #  #  #  # ]
     232 [ #  # ][ #  # ]:          0 :                 mxControlAccess->enableControl( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, sal_False );
     233                 :            :             else
     234 [ #  # ][ #  # ]:          0 :                 mxControlAccess->enableControl( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, sal_True );
     235                 :            :         }
     236         [ #  # ]:          0 :         catch (const css::lang::IllegalArgumentException&)
     237                 :            :         {
     238                 :            : #ifdef DBG_UTIL
     239                 :            :             OSL_FAIL( "Cannot access \"selection\" checkbox" );
     240                 :            : #endif
     241         [ #  # ]:          0 :         }
     242                 :            :     }
     243                 :          0 : }
     244                 :            : 
     245                 :            : //-----------------------------------------------------------------------------
     246                 :          0 : SdFileDialog_Imp::SdFileDialog_Imp( const short     nDialogType,
     247                 :            :                                     sal_Bool        bUsableSelection    ) :
     248                 :            :     FileDialogHelper( nDialogType, 0 ),
     249                 :            :     mnPlaySoundEvent( 0 ),
     250                 :            :     mbUsableSelection( bUsableSelection ),
     251         [ #  # ]:          0 :     mbLabelPlaying(sal_False)
     252                 :            : {
     253         [ #  # ]:          0 :     maUpdateTimer.SetTimeoutHdl(LINK(this, SdFileDialog_Imp, IsMusicStoppedHdl));
     254                 :            : 
     255         [ #  # ]:          0 :     css::uno::Reference < ::com::sun::star::ui::dialogs::XFilePicker > xFileDlg = GetFilePicker();
     256                 :            : 
     257                 :            :     // get the control access
     258 [ #  # ][ #  # ]:          0 :     mxControlAccess = css::uno::Reference< css::ui::dialogs::XFilePickerControlAccess > ( xFileDlg, css::uno::UNO_QUERY );
     259                 :            : 
     260         [ #  # ]:          0 :     if( mxControlAccess.is() )
     261                 :            :     {
     262         [ #  # ]:          0 :         if( nDialogType ==
     263                 :            :             css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY )
     264                 :            :         {
     265                 :            :             try
     266                 :            :             {
     267         [ #  # ]:          0 :                 mxControlAccess->setLabel( css::ui::dialogs::ExtendedFilePickerElementIds::PUSHBUTTON_PLAY,
     268 [ #  # ][ #  # ]:          0 :                                            String( SdResId( STR_PLAY ) ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     269                 :            :             }
     270   [ #  #  #  # ]:          0 :             catch (const css::lang::IllegalArgumentException&)
     271                 :            :             {
     272                 :            : #ifdef DBG_UTIL
     273                 :            :                 OSL_FAIL( "Cannot set play button label" );
     274                 :            : #endif
     275                 :            :             }
     276                 :            :         }
     277         [ #  # ]:          0 :         else if( mbUsableSelection != sal_True )
     278                 :            :         {
     279                 :            :             try
     280                 :            :             {
     281 [ #  # ][ #  # ]:          0 :                 mxControlAccess->enableControl( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, sal_False );
     282                 :            :             }
     283         [ #  # ]:          0 :             catch (const css::lang::IllegalArgumentException&)
     284                 :            :             {
     285                 :            : #ifdef DBG_UTIL
     286                 :            :                 OSL_FAIL( "Cannot disable selection checkbox" );
     287                 :            : #endif
     288                 :            :             }
     289                 :            :         }
     290                 :          0 :     }
     291                 :          0 : }
     292                 :            : 
     293                 :            : 
     294                 :            : // ------------------------------------------------------------------------
     295         [ #  # ]:          0 : SdFileDialog_Imp::~SdFileDialog_Imp()
     296                 :            : {
     297         [ #  # ]:          0 :     if( mnPlaySoundEvent )
     298         [ #  # ]:          0 :         Application::RemoveUserEvent( mnPlaySoundEvent );
     299         [ #  # ]:          0 : }
     300                 :            : 
     301                 :            : // ------------------------------------------------------------------------
     302                 :          0 : ErrCode SdFileDialog_Imp::Execute()
     303                 :            : {
     304                 :            :     // make sure selection checkbox is disabled if
     305                 :            :     // HTML is current filter!
     306                 :          0 :     CheckSelectionState();
     307                 :          0 :     return FileDialogHelper::Execute();
     308                 :            : }
     309                 :            : 
     310                 :            : // --------------------------------------------------------------------
     311                 :            : // -----------      SdOpenSoundFileDialog       -----------------------
     312                 :            : // --------------------------------------------------------------------
     313                 :            : 
     314                 :            : // these are simple forwarders
     315                 :          0 : SdOpenSoundFileDialog::SdOpenSoundFileDialog() :
     316                 :            :     mpImpl(
     317                 :            :         new SdFileDialog_Imp(
     318         [ #  # ]:          0 :             css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY, sal_False ) )
     319                 :            : {
     320         [ #  # ]:          0 :     String aDescr;
     321 [ #  # ][ #  # ]:          0 :     aDescr = String(SdResId(STR_ALL_FILES));
         [ #  # ][ #  # ]
     322 [ #  # ][ #  # ]:          0 :     mpImpl->AddFilter( aDescr, rtl::OUString("*.*"));
                 [ #  # ]
     323                 :            : 
     324                 :            :     // setup filter
     325                 :            : #if defined UNX
     326 [ #  # ][ #  # ]:          0 :     aDescr = String(SdResId(STR_AU_FILE));
         [ #  # ][ #  # ]
     327 [ #  # ][ #  # ]:          0 :     mpImpl->AddFilter( aDescr, rtl::OUString("*.au;*.snd" ));
                 [ #  # ]
     328 [ #  # ][ #  # ]:          0 :     aDescr = String(SdResId(STR_VOC_FILE));
         [ #  # ][ #  # ]
     329 [ #  # ][ #  # ]:          0 :     mpImpl->AddFilter( aDescr, rtl::OUString("*.voc" ));
                 [ #  # ]
     330 [ #  # ][ #  # ]:          0 :     aDescr = String(SdResId(STR_WAV_FILE));
         [ #  # ][ #  # ]
     331 [ #  # ][ #  # ]:          0 :     mpImpl->AddFilter( aDescr, rtl::OUString("*.wav" ));
                 [ #  # ]
     332 [ #  # ][ #  # ]:          0 :     aDescr = String(SdResId(STR_AIFF_FILE));
         [ #  # ][ #  # ]
     333 [ #  # ][ #  # ]:          0 :     mpImpl->AddFilter( aDescr, rtl::OUString("*.aiff" ));
                 [ #  # ]
     334 [ #  # ][ #  # ]:          0 :     aDescr = String(SdResId(STR_SVX_FILE));
         [ #  # ][ #  # ]
     335 [ #  # ][ #  # ]:          0 :     mpImpl->AddFilter( aDescr, rtl::OUString("*.svx" ));
         [ #  # ][ #  # ]
     336                 :            : #else
     337                 :            :     aDescr = String(SdResId(STR_WAV_FILE));
     338                 :            :     mpImpl->AddFilter( aDescr, rtl::OUString("*.wav;*.mp3;*.ogg" ));
     339                 :            :     aDescr = String(SdResId(STR_MIDI_FILE));
     340                 :            :     mpImpl->AddFilter( aDescr, rtl::OUString("*.mid" ));
     341                 :            : #endif
     342                 :          0 : }
     343                 :            : 
     344                 :            : // ------------------------------------------------------------------------
     345                 :          0 : SdOpenSoundFileDialog::~SdOpenSoundFileDialog()
     346                 :            : {
     347                 :          0 : }
     348                 :            : 
     349                 :            : // ------------------------------------------------------------------------
     350                 :          0 : ErrCode SdOpenSoundFileDialog::Execute()
     351                 :            : {
     352                 :          0 :     return mpImpl->Execute();
     353                 :            : }
     354                 :            : 
     355                 :            : // ------------------------------------------------------------------------
     356                 :          0 : String SdOpenSoundFileDialog::GetPath() const
     357                 :            : {
     358                 :          0 :     return mpImpl->GetPath();
     359                 :            : }
     360                 :            : 
     361                 :            : // ------------------------------------------------------------------------
     362                 :          0 : void SdOpenSoundFileDialog::SetPath( const String& rPath )
     363                 :            : {
     364                 :          0 :     mpImpl->SetDisplayDirectory( rPath );
     365                 :          0 : }
     366                 :            : 
     367                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10