LCOV - code coverage report
Current view: top level - libreoffice/cui/source/dialogs - cuigaldlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 608 0.2 %
Date: 2012-12-17 Functions: 2 76 2.6 %
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 "sal/config.h"
      21             : 
      22             : #include <algorithm>
      23             : #include <cassert>
      24             : 
      25             : #include <ucbhelper/content.hxx>
      26             : #include <osl/mutex.hxx>
      27             : #include <vcl/svapp.hxx>
      28             : #include <vcl/msgbox.hxx>
      29             : #include <avmedia/mediawindow.hxx>
      30             : #include <unotools/pathoptions.hxx>
      31             : #include <sfx2/opengrf.hxx>
      32             : #include <svtools/filter.hxx>
      33             : #include <svx/gallery1.hxx>
      34             : #include <svx/galtheme.hxx>
      35             : #include "cuigaldlg.hxx"
      36             : #include "helpid.hrc"
      37             : #include <unotools/syslocale.hxx>
      38             : #include <cppuhelper/implbase1.hxx>
      39             : #include <com/sun/star/uno/Reference.hxx>
      40             : #include <com/sun/star/lang/XInitialization.hpp>
      41             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      42             : #include <comphelper/processfactory.hxx>
      43             : #include <com/sun/star/sdbc/XResultSet.hpp>
      44             : #include <com/sun/star/sdbc/XRow.hpp>
      45             : #include <com/sun/star/ucb/XContentAccess.hpp>
      46             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      47             : #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
      48             : #include <sfx2/sfxuno.hxx>
      49             : #include "dialmgr.hxx"
      50             : #include "gallery.hrc"
      51             : #include <svx/dialogs.hrc>
      52             : #include <svx/dialmgr.hxx>
      53             : 
      54             : 
      55             : // --------------
      56             : // - Namespaces -
      57             : // --------------
      58             : 
      59             : using namespace ::ucbhelper;
      60             : using namespace ::rtl;
      61             : using namespace ::cppu;
      62             : using namespace ::com::sun::star::lang;
      63             : using namespace ::com::sun::star::sdbc;
      64             : using namespace ::com::sun::star::ucb;
      65             : using namespace ::com::sun::star::ui::dialogs;
      66             : using namespace ::com::sun::star::uno;
      67             : 
      68             : // ----------------
      69             : // - SearchThread -
      70             : // ----------------
      71             : 
      72           0 : SearchThread::SearchThread( SearchProgress* pProgess,
      73             :                             TPGalleryThemeProperties* pBrowser,
      74             :                             const INetURLObject& rStartURL ) :
      75             :         Thread      ( "cuiSearchThread" ),
      76             :         mpProgress  ( pProgess ),
      77             :         mpBrowser   ( pBrowser ),
      78           0 :         maStartURL  ( rStartURL )
      79             : {
      80           0 : }
      81             : 
      82             : // ------------------------------------------------------------------------
      83             : 
      84           0 : SearchThread::~SearchThread()
      85             : {
      86           0 : }
      87             : 
      88             : // ------------------------------------------------------------------------
      89             : 
      90           0 : void SearchThread::execute()
      91             : {
      92           0 :     const String aFileType( mpBrowser->aCbbFileType.GetText() );
      93             : 
      94           0 :     if( aFileType.Len() )
      95             :     {
      96           0 :         const sal_uInt16        nFileNumber = mpBrowser->aCbbFileType.GetEntryPos( aFileType );
      97             :         sal_uInt16              nBeginFormat, nEndFormat;
      98           0 :         ::std::vector< String > aFormats;
      99             : 
     100           0 :         if( !nFileNumber || ( nFileNumber >= mpBrowser->aCbbFileType.GetEntryCount() ) )
     101             :         {
     102           0 :             nBeginFormat = 1;
     103           0 :             nEndFormat = mpBrowser->aCbbFileType.GetEntryCount() - 1;
     104             :         }
     105             :         else
     106           0 :             nBeginFormat = nEndFormat = nFileNumber;
     107             : 
     108           0 :         for( sal_uInt16 i = nBeginFormat; i <= nEndFormat; ++i )
     109           0 :             aFormats.push_back( mpBrowser->aFilterEntryList[ i ]->aFilterName.ToLowerAscii() );
     110             : 
     111           0 :         ImplSearch( maStartURL, aFormats, mpBrowser->bSearchRecursive );
     112             :     }
     113             : 
     114           0 :     Application::PostUserEvent( LINK( mpProgress, SearchProgress, CleanUpHdl ) );
     115           0 : }
     116             : 
     117             : // ------------------------------------------------------------------------
     118             : 
     119           0 : void SearchThread::ImplSearch( const INetURLObject& rStartURL,
     120             :                                const ::std::vector< String >& rFormats,
     121             :                                sal_Bool bRecursive )
     122             : {
     123             :     {
     124           0 :         SolarMutexGuard aGuard;
     125             : 
     126           0 :         mpProgress->SetDirectory( rStartURL );
     127           0 :         mpProgress->Sync();
     128             :     }
     129             : 
     130             :     try
     131             :     {
     132           0 :         ::com::sun::star::uno::Reference< XCommandEnvironment > xEnv;
     133           0 :         Content aCnt( rStartURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv, comphelper::getProcessComponentContext() );
     134           0 :         Sequence< OUString > aProps( 2 );
     135             : 
     136           0 :         aProps.getArray()[ 0 ] = OUString(RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ));
     137           0 :         aProps.getArray()[ 1 ] = OUString(RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ));
     138             :         ::com::sun::star::uno::Reference< XResultSet > xResultSet(
     139           0 :             aCnt.createCursor( aProps, INCLUDE_FOLDERS_AND_DOCUMENTS ) );
     140             : 
     141           0 :         if( xResultSet.is() )
     142             :         {
     143           0 :             ::com::sun::star::uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
     144           0 :             ::com::sun::star::uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
     145             : 
     146           0 :             while( xResultSet->next() && schedule() )
     147             :             {
     148           0 :                 INetURLObject   aFoundURL( xContentAccess->queryContentIdentifierString() );
     149             :                 DBG_ASSERT( aFoundURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     150             : 
     151           0 :                 sal_Bool bFolder = xRow->getBoolean( 1 ); // property "IsFolder"
     152           0 :                 if ( xRow->wasNull() )
     153           0 :                     bFolder = sal_False;
     154             : 
     155           0 :                 if( bRecursive && bFolder )
     156           0 :                     ImplSearch( aFoundURL, rFormats, sal_True );
     157             :                 else
     158             :                 {
     159           0 :                     sal_Bool bDocument = xRow->getBoolean( 2 ); // property "IsDocument"
     160           0 :                     if ( xRow->wasNull() )
     161           0 :                         bDocument = sal_False;
     162             : 
     163           0 :                     if( bDocument )
     164             :                     {
     165           0 :                         GraphicDescriptor   aDesc( aFoundURL );
     166           0 :                         String              aFileName;
     167             : 
     168           0 :                         if( ( aDesc.Detect() &&
     169             :                               ::std::find( rFormats.begin(),
     170             :                                            rFormats.end(),
     171             :                                            aDesc.GetImportFormatShortName(
     172           0 :                                                aDesc.GetFileFormat() ).ToLowerAscii() )
     173           0 :                               != rFormats.end() ) ||
     174             :                             ::std::find( rFormats.begin(),
     175             :                                          rFormats.end(),
     176           0 :                                          String(aFoundURL.GetExtension().toAsciiLowerCase()) )
     177           0 :                             != rFormats.end() )
     178             :                         {
     179           0 :                             SolarMutexGuard aGuard;
     180             : 
     181             :                             mpBrowser->aFoundList.push_back(
     182           0 :                                 new String( aFoundURL.GetMainURL( INetURLObject::NO_DECODE ) )
     183           0 :                             );
     184             :                             mpBrowser->aLbxFound.InsertEntry(
     185             :                                 GetReducedString( aFoundURL, 50 ),
     186           0 :                                 (sal_uInt16) mpBrowser->aFoundList.size() - 1 );
     187           0 :                         }
     188             :                     }
     189             :                 }
     190           0 :             }
     191           0 :         }
     192             :     }
     193           0 :     catch (const ContentCreationException&)
     194             :     {
     195             :     }
     196           0 :     catch (const ::com::sun::star::uno::RuntimeException&)
     197             :     {
     198             :     }
     199           0 :     catch (const ::com::sun::star::uno::Exception&)
     200             :     {
     201             :     }
     202           0 : }
     203             : 
     204             : // ------------------
     205             : // - SearchProgress -
     206             : // ------------------
     207             : 
     208           0 : SearchProgress::SearchProgress( Window* pParent, const INetURLObject& rStartURL ) :
     209           0 :     ModalDialog     ( pParent, CUI_RES(RID_SVXDLG_GALLERY_SEARCH_PROGRESS ) ),
     210           0 :     aFtSearchDir    ( this, CUI_RES( FT_SEARCH_DIR ) ),
     211           0 :     aFLSearchDir   ( this, CUI_RES( FL_SEARCH_DIR ) ),
     212           0 :     aFtSearchType   ( this, CUI_RES( FT_SEARCH_TYPE ) ),
     213           0 :     aFLSearchType  ( this, CUI_RES( FL_SEARCH_TYPE ) ),
     214           0 :     aBtnCancel      ( this, CUI_RES( BTN_CANCEL ) ),
     215           0 :     parent_(pParent), startUrl_(rStartURL)
     216             : {
     217           0 :     FreeResource();
     218           0 :     aBtnCancel.SetClickHdl( LINK( this, SearchProgress, ClickCancelBtn ) );
     219           0 : }
     220             : 
     221             : // ------------------------------------------------------------------------
     222             : 
     223           0 : void SearchProgress::Terminate()
     224             : {
     225           0 :     if (maSearchThread.is()) {
     226           0 :         maSearchThread->terminate();
     227           0 :         maSearchThread->join();
     228             :     }
     229           0 : }
     230             : 
     231             : // ------------------------------------------------------------------------
     232             : 
     233           0 : IMPL_LINK_NOARG(SearchProgress, ClickCancelBtn)
     234             : {
     235           0 :     Terminate();
     236           0 :     return 0L;
     237             : }
     238             : 
     239             : // ------------------------------------------------------------------------
     240             : 
     241           0 : IMPL_LINK_NOARG(SearchProgress, CleanUpHdl)
     242             : {
     243           0 :     EndDialog( RET_OK );
     244           0 :     delete this;
     245           0 :     return 0L;
     246             : }
     247             : 
     248             : // ------------------------------------------------------------------------
     249             : 
     250           0 : short SearchProgress::Execute()
     251             : {
     252             :     OSL_FAIL( "SearchProgress cannot be executed via Dialog::Execute!\n"
     253             :                "It creates a thread that will call back to VCL apartment => deadlock!\n"
     254             :                "Use Dialog::StartExecuteModal to execute the dialog!" );
     255           0 :     return RET_CANCEL;
     256             : }
     257             : 
     258             : // ------------------------------------------------------------------------
     259             : 
     260           0 : void SearchProgress::StartExecuteModal( const Link& rEndDialogHdl )
     261             : {
     262             :     assert(!maSearchThread.is());
     263             :     maSearchThread = new SearchThread(
     264           0 :         this, static_cast< TPGalleryThemeProperties * >(parent_), startUrl_);
     265           0 :     maSearchThread->launch();
     266           0 :     ModalDialog::StartExecuteModal( rEndDialogHdl );
     267           0 : }
     268             : 
     269             : // --------------
     270             : // - TakeThread -
     271             : // --------------
     272             : 
     273           0 : TakeThread::TakeThread(
     274             :     TakeProgress* pProgess,
     275             :     TPGalleryThemeProperties* pBrowser,
     276             :     TokenList_impl& rTakenList
     277             : ) :
     278             :     Thread      ( "cuiTakeThread" ),
     279             :     mpProgress  ( pProgess ),
     280             :     mpBrowser   ( pBrowser ),
     281           0 :     mrTakenList ( rTakenList )
     282             : {
     283           0 : }
     284             : 
     285             : // ------------------------------------------------------------------------
     286             : 
     287           0 : TakeThread::~TakeThread()
     288             : {
     289           0 : }
     290             : 
     291             : // ------------------------------------------------------------------------
     292             : 
     293           0 : void TakeThread::execute()
     294             : {
     295           0 :     String              aName;
     296           0 :     INetURLObject       aURL;
     297             :     sal_uInt16          nEntries;
     298           0 :     GalleryTheme*       pThm = mpBrowser->GetXChgData()->pTheme;
     299             :     sal_uInt16          nPos;
     300             :     GalleryProgress*    pStatusProgress;
     301             : 
     302             :     {
     303           0 :         SolarMutexGuard aGuard;
     304           0 :         pStatusProgress = new GalleryProgress;
     305           0 :         nEntries = mpBrowser->bTakeAll ? mpBrowser->aLbxFound.GetEntryCount() : mpBrowser->aLbxFound.GetSelectEntryCount();
     306           0 :         pThm->LockBroadcaster();
     307             :     }
     308             : 
     309           0 :     for( sal_uInt16 i = 0; i < nEntries && schedule(); i++ )
     310             :     {
     311           0 :         if( mpBrowser->bTakeAll )
     312           0 :             aURL = INetURLObject( *mpBrowser->aFoundList[ nPos = i ] );
     313             :         else
     314           0 :             aURL = INetURLObject(*mpBrowser->aFoundList[ nPos = mpBrowser->aLbxFound.GetSelectEntryPos( i ) ]);
     315             : 
     316           0 :         mrTakenList.push_back( (sal_uLong)nPos );
     317             : 
     318             :         {
     319           0 :             SolarMutexGuard aGuard;
     320             : 
     321           0 :             mpProgress->SetFile( aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
     322           0 :             pStatusProgress->Update( i, nEntries - 1 );
     323           0 :             mpProgress->Sync();
     324           0 :             pThm->InsertURL( aURL );
     325             :         }
     326             :     }
     327             : 
     328             :     {
     329           0 :         SolarMutexGuard aGuard;
     330             : 
     331           0 :         pThm->UnlockBroadcaster();
     332           0 :         delete pStatusProgress;
     333             :     }
     334             : 
     335           0 :     Application::PostUserEvent( LINK( mpProgress, TakeProgress, CleanUpHdl ) );
     336           0 : }
     337             : 
     338             : // ----------------
     339             : // - TakeProgress -
     340             : // ----------------
     341             : 
     342           0 : TakeProgress::TakeProgress( Window* pWindow ) :
     343           0 :     ModalDialog     ( pWindow, CUI_RES( RID_SVXDLG_GALLERY_TAKE_PROGRESS ) ),
     344           0 :     aFtTakeFile     ( this, CUI_RES( FT_TAKE_FILE ) ),
     345           0 :     aFLTakeProgress( this, CUI_RES( FL_TAKE_PROGRESS ) ),
     346           0 :     aBtnCancel      ( this, CUI_RES( BTN_CANCEL ) ),
     347           0 :     window_(pWindow)
     348             : {
     349           0 :     FreeResource();
     350           0 :     aBtnCancel.SetClickHdl( LINK( this, TakeProgress, ClickCancelBtn ) );
     351           0 : }
     352             : 
     353             : // ------------------------------------------------------------------------
     354             : 
     355             : 
     356           0 : void TakeProgress::Terminate()
     357             : {
     358           0 :     if (maTakeThread.is()) {
     359           0 :         maTakeThread->terminate();
     360           0 :         maTakeThread->join();
     361             :     }
     362           0 : }
     363             : 
     364             : // ------------------------------------------------------------------------
     365             : 
     366           0 : IMPL_LINK_NOARG(TakeProgress, ClickCancelBtn)
     367             : {
     368           0 :     Terminate();
     369           0 :     return 0L;
     370             : }
     371             : 
     372             : // ------------------------------------------------------------------------
     373             : 
     374           0 : IMPL_LINK_NOARG(TakeProgress, CleanUpHdl)
     375             : {
     376           0 :     TPGalleryThemeProperties*   mpBrowser = (TPGalleryThemeProperties*) GetParent();
     377           0 :     ::std::vector<bool, std::allocator<bool> >           aRemoveEntries( mpBrowser->aFoundList.size(), false );
     378           0 :     ::std::vector< String >     aRemainingVector;
     379             :     sal_uInt32                  i, nCount;
     380             : 
     381           0 :     GetParent()->EnterWait();
     382           0 :     mpBrowser->aLbxFound.SetUpdateMode( sal_False );
     383           0 :     mpBrowser->aLbxFound.SetNoSelection();
     384             : 
     385             :     // mark all taken positions in aRemoveEntries
     386           0 :     for( i = 0, nCount = maTakenList.size(); i < nCount; ++i )
     387           0 :         aRemoveEntries[ maTakenList[ i ] ] = true;
     388           0 :     maTakenList.clear();
     389             : 
     390             :     // refill found list
     391           0 :     for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
     392           0 :         if( !aRemoveEntries[ i ] )
     393           0 :             aRemainingVector.push_back( *mpBrowser->aFoundList[ i ] );
     394             : 
     395           0 :     for ( i = 0, nCount = mpBrowser->aFoundList.size(); i < nCount; ++i )
     396           0 :         delete mpBrowser->aFoundList[ i ];
     397           0 :     mpBrowser->aFoundList.clear();
     398             : 
     399           0 :     for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
     400           0 :         mpBrowser->aFoundList.push_back( new String( aRemainingVector[ i ] ) );
     401             : 
     402           0 :     aRemainingVector.clear();
     403             : 
     404             :     // refill list box
     405           0 :     for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
     406           0 :         if( !aRemoveEntries[ i ] )
     407           0 :             aRemainingVector.push_back( mpBrowser->aLbxFound.GetEntry( (sal_uInt16) i ) );
     408             : 
     409           0 :     mpBrowser->aLbxFound.Clear();
     410             : 
     411           0 :     for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
     412           0 :         mpBrowser->aLbxFound.InsertEntry( aRemainingVector[ i ] );
     413             : 
     414           0 :     aRemainingVector.clear();
     415             : 
     416           0 :     mpBrowser->aLbxFound.SetUpdateMode( sal_True );
     417           0 :     mpBrowser->SelectFoundHdl( NULL );
     418           0 :     GetParent()->LeaveWait();
     419             : 
     420           0 :     EndDialog( RET_OK );
     421           0 :     delete this;
     422           0 :     return 0L;
     423             : }
     424             : 
     425             : // ------------------------------------------------------------------------
     426             : 
     427           0 : short TakeProgress::Execute()
     428             : {
     429             :     OSL_FAIL( "TakeProgress cannot be executed via Dialog::Execute!\n"
     430             :                "It creates a thread that will call back to VCL apartment => deadlock!\n"
     431             :                "Use Dialog::StartExecuteModal to execute the dialog!" );
     432           0 :     return RET_CANCEL;
     433             : }
     434             : 
     435             : // ------------------------------------------------------------------------
     436             : 
     437           0 : void TakeProgress::StartExecuteModal( const Link& rEndDialogHdl )
     438             : {
     439             :     assert(!maTakeThread.is());
     440             :     maTakeThread = new TakeThread(
     441           0 :         this, static_cast< TPGalleryThemeProperties * >(window_), maTakenList);
     442           0 :     maTakeThread->launch();
     443           0 :     ModalDialog::StartExecuteModal( rEndDialogHdl );
     444           0 : }
     445             : 
     446             : // ---------------------
     447             : // - ActualizeProgress -
     448             : // ---------------------
     449             : 
     450           0 : ActualizeProgress::ActualizeProgress( Window* pWindow, GalleryTheme* pThm ) :
     451           0 :     ModalDialog             ( pWindow, CUI_RES( RID_SVXDLG_GALLERY_ACTUALIZE_PROGRESS ) ),
     452           0 :     aFtActualizeFile        ( this, CUI_RES( FT_ACTUALIZE_FILE ) ),
     453           0 :     aFLActualizeProgress   ( this, CUI_RES( FL_ACTUALIZE_PROGRESS ) ),
     454           0 :     aBtnCancel              ( this, CUI_RES( BTN_CANCEL ) ),
     455           0 :     pTheme                  ( pThm )
     456             : {
     457           0 :     FreeResource();
     458           0 :     aBtnCancel.SetClickHdl( LINK( this, ActualizeProgress, ClickCancelBtn ) );
     459           0 : }
     460             : 
     461             : // ------------------------------------------------------------------------
     462             : 
     463           0 : short ActualizeProgress::Execute()
     464             : {
     465             :     short nRet;
     466             : 
     467           0 :     pTimer = new Timer;
     468             : 
     469           0 :     if ( pTimer )
     470             :     {
     471           0 :         pTimer->SetTimeoutHdl( LINK( this, ActualizeProgress, TimeoutHdl ) );
     472           0 :         pTimer->SetTimeout( 500 );
     473           0 :         pTimer->Start();
     474             :     }
     475             : 
     476           0 :     nRet = ModalDialog::Execute();
     477             : 
     478           0 :     return nRet;
     479             : }
     480             : 
     481             : // ------------------------------------------------------------------------
     482             : 
     483           0 : IMPL_LINK_NOARG(ActualizeProgress, ClickCancelBtn)
     484             : {
     485           0 :     pTheme->AbortActualize();
     486           0 :     EndDialog( RET_OK );
     487             : 
     488           0 :     return 0L;
     489             : }
     490             : 
     491             : // ------------------------------------------------------------------------
     492             : 
     493           0 : IMPL_LINK( ActualizeProgress, TimeoutHdl, Timer*, _pTimer )
     494             : {
     495           0 :     if ( _pTimer )
     496             :     {
     497           0 :         _pTimer->Stop();
     498           0 :         delete _pTimer;
     499             :     }
     500             : 
     501           0 :     pTheme->Actualize( LINK( this, ActualizeProgress, ActualizeHdl ), &aStatusProgress );
     502           0 :     ClickCancelBtn( NULL );
     503             : 
     504           0 :     return 0;
     505             : }
     506             : 
     507             : // ------------------------------------------------------------------------
     508             : 
     509           0 : IMPL_LINK( ActualizeProgress, ActualizeHdl, INetURLObject*, pURL )
     510             : {
     511           0 :   for( long i = 0; i < 128; i++ )
     512           0 :     Application::Reschedule();
     513             : 
     514           0 :     Flush();
     515           0 :     Sync();
     516             : 
     517           0 :     if( pURL )
     518             :     {
     519           0 :         aFtActualizeFile.SetText( GetReducedString( *pURL, 30 ) );
     520           0 :         aFtActualizeFile.Flush();
     521           0 :         aFtActualizeFile.Sync();
     522             :     }
     523             : 
     524           0 :     return 0;
     525             : }
     526             : 
     527             : // ---------------
     528             : // - TitleDialog -
     529             : // ---------------
     530             : 
     531           0 : TitleDialog::TitleDialog( Window* pParent, const String& rOldTitle ) :
     532           0 :     ModalDialog ( pParent, CUI_RES( RID_SVXDLG_GALLERY_TITLE ) ),
     533           0 :     maOk        ( this, CUI_RES( BTN_OK ) ),
     534           0 :     maCancel    ( this, CUI_RES( BTN_CANCEL ) ),
     535           0 :     maHelp      ( this, CUI_RES( BTN_HELP ) ),
     536           0 :     maFL       ( this, CUI_RES( FL_TITLE ) ),
     537           0 :     maEdit      ( this, CUI_RES( EDT_TITLE ) )
     538             : {
     539           0 :     FreeResource();
     540           0 :     maEdit.SetText( rOldTitle );
     541           0 :     maEdit.GrabFocus();
     542           0 : }
     543             : 
     544             : // -------------------
     545             : // - GalleryIdDialog -
     546             : // -------------------
     547             : 
     548           0 : GalleryIdDialog::GalleryIdDialog( Window* pParent, GalleryTheme* _pThm ) :
     549           0 :             ModalDialog ( pParent, CUI_RES( RID_SVXDLG_GALLERY_THEMEID ) ),
     550           0 :             aBtnOk      ( this, CUI_RES( BTN_OK ) ),
     551           0 :             aBtnCancel  ( this, CUI_RES( BTN_CANCEL ) ),
     552           0 :             aFLId      ( this, CUI_RES( FL_ID ) ),
     553           0 :             aLbResName  ( this, CUI_RES( LB_RESNAME ) ),
     554           0 :             pThm        ( _pThm )
     555             : {
     556           0 :     FreeResource();
     557             : 
     558           0 :     aLbResName.InsertEntry( String( RTL_CONSTASCII_USTRINGPARAM( "!!! No Id !!!" ) ) );
     559             : 
     560           0 :     GalleryTheme::InsertAllThemes( aLbResName );
     561             : 
     562           0 :     aLbResName.SelectEntryPos( (sal_uInt16) pThm->GetId() );
     563           0 :     aLbResName.GrabFocus();
     564             : 
     565           0 :     aBtnOk.SetClickHdl( LINK( this, GalleryIdDialog, ClickOkHdl ) );
     566           0 : }
     567             : 
     568             : // -----------------------------------------------------------------------------
     569             : 
     570           0 : IMPL_LINK_NOARG(GalleryIdDialog, ClickOkHdl)
     571             : {
     572           0 :     Gallery*    pGal = pThm->GetParent();
     573           0 :     const sal_uLong nId = GetId();
     574           0 :     sal_Bool        bDifferentThemeExists = sal_False;
     575             : 
     576           0 :     for( sal_uLong i = 0, nCount = pGal->GetThemeCount(); i < nCount && !bDifferentThemeExists; i++ )
     577             :     {
     578           0 :         const GalleryThemeEntry* pInfo = pGal->GetThemeInfo( i );
     579             : 
     580           0 :         if( ( pInfo->GetId() == nId ) && ( pInfo->GetThemeName() != pThm->GetName() ) )
     581             :         {
     582           0 :             String aStr( CUI_RES( RID_SVXSTR_GALLERY_ID_EXISTS ) );
     583             : 
     584           0 :             aStr += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
     585           0 :             aStr += pInfo->GetThemeName();
     586           0 :             aStr += ')';
     587             : 
     588           0 :             InfoBox aBox( this, aStr );
     589           0 :             aBox.Execute();
     590           0 :             aLbResName.GrabFocus();
     591           0 :             bDifferentThemeExists = sal_True;
     592             :         }
     593             :     }
     594             : 
     595           0 :     if( !bDifferentThemeExists )
     596           0 :         EndDialog( RET_OK );
     597             : 
     598           0 :     return 0L;
     599             : }
     600             : 
     601             : 
     602             : // --------------------------
     603             : // - GalleryThemeProperties -
     604             : // --------------------------
     605             : 
     606           0 : GalleryThemeProperties::GalleryThemeProperties( Window* pParent, ExchangeData* _pData, SfxItemSet* pItemSet  ) :
     607           0 :             SfxTabDialog    ( pParent, CUI_RES( RID_SVXTABDLG_GALLERYTHEME ), pItemSet ),
     608           0 :             pData           ( _pData )
     609             : {
     610           0 :     FreeResource();
     611             : 
     612           0 :     AddTabPage( RID_SVXTABPAGE_GALLERY_GENERAL, TPGalleryThemeGeneral::Create, 0 );
     613           0 :     AddTabPage( RID_SVXTABPAGE_GALLERYTHEME_FILES, TPGalleryThemeProperties::Create, 0 );
     614             : 
     615           0 :     if( pData->pTheme->IsReadOnly() )
     616           0 :         RemoveTabPage( RID_SVXTABPAGE_GALLERYTHEME_FILES );
     617             : 
     618           0 :     String aText( GetText() );
     619             : 
     620           0 :     aText += pData->pTheme->GetName();
     621             : 
     622           0 :     if( pData->pTheme->IsReadOnly() )
     623           0 :         aText += String( CUI_RES( RID_SVXSTR_GALLERY_READONLY ) );
     624             : 
     625           0 :     SetText( aText );
     626           0 : }
     627             : 
     628             : // ------------------------------------------------------------------------
     629             : 
     630           0 : void GalleryThemeProperties::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
     631             : {
     632           0 :     if( RID_SVXTABPAGE_GALLERY_GENERAL == nId )
     633           0 :         ( (TPGalleryThemeGeneral&) rPage ).SetXChgData( pData );
     634             :     else
     635           0 :         ( (TPGalleryThemeProperties&) rPage ).SetXChgData( pData );
     636           0 : }
     637             : 
     638             : // -------------------------
     639             : // - TPGalleryThemeGeneral -
     640             : // -------------------------
     641             : 
     642           0 : TPGalleryThemeGeneral::TPGalleryThemeGeneral( Window* pParent, const SfxItemSet& rSet ) :
     643           0 :             SfxTabPage              ( pParent, CUI_RES( RID_SVXTABPAGE_GALLERY_GENERAL ), rSet ),
     644           0 :             aFiMSImage              ( this, CUI_RES( FI_MS_IMAGE ) ),
     645           0 :             aEdtMSName              ( this, CUI_RES( EDT_MS_NAME ) ),
     646           0 :             aFlMSGeneralFirst       ( this, CUI_RES( FL_MS_GENERAL_FIRST ) ),
     647           0 :             aFtMSType               ( this, CUI_RES( FT_MS_TYPE ) ),
     648           0 :             aFtMSShowType           ( this, CUI_RES( FT_MS_SHOW_TYPE ) ),
     649           0 :             aFtMSPath               ( this, CUI_RES( FT_MS_PATH ) ),
     650           0 :             aFtMSShowPath           ( this, CUI_RES( FT_MS_SHOW_PATH ) ),
     651           0 :             aFtMSContent            ( this, CUI_RES( FT_MS_CONTENT ) ),
     652           0 :             aFtMSShowContent        ( this, CUI_RES( FT_MS_SHOW_CONTENT ) ),
     653           0 :             aFlMSGeneralSecond      ( this, CUI_RES( FL_MS_GENERAL_SECOND ) ),
     654           0 :             aFtMSChangeDate         ( this, CUI_RES( FT_MS_CHANGEDATE ) ),
     655           0 :             aFtMSShowChangeDate     ( this, CUI_RES( FT_MS_SHOW_CHANGEDATE ) )
     656             : {
     657           0 :     FreeResource();
     658             : 
     659           0 :     String aAccName(SVX_RES(RID_SVXSTR_GALLERY_THEMENAME));
     660           0 :     aEdtMSName.SetAccessibleName(aAccName);
     661           0 :     aFiMSImage.SetAccessibleName(aAccName);
     662           0 :     aEdtMSName.SetAccessibleRelationLabeledBy( &aFiMSImage );
     663           0 : }
     664             : 
     665             : // ------------------------------------------------------------------------
     666             : 
     667           0 : void TPGalleryThemeGeneral::SetXChgData( ExchangeData* _pData )
     668             : {
     669           0 :     pData = _pData;
     670             : 
     671           0 :     GalleryTheme*       pThm = pData->pTheme;
     672           0 :     String              aOutStr( String::CreateFromInt32( pThm->GetObjectCount() ) );
     673           0 :     String              aObjStr( CUI_RES( RID_SVXSTR_GALLERYPROPS_OBJECT ) );
     674           0 :     String              aAccess;
     675           0 :     String              aType( SVX_RES( RID_SVXSTR_GALLERYPROPS_GALTHEME ) );
     676           0 :     sal_Bool            bReadOnly = pThm->IsReadOnly();
     677             : 
     678           0 :     aEdtMSName.SetHelpId( HID_GALLERY_EDIT_MSNAME );
     679           0 :     aEdtMSName.SetText( pThm->GetName() );
     680           0 :     aEdtMSName.SetReadOnly( bReadOnly );
     681             : 
     682           0 :     if( bReadOnly )
     683           0 :         aEdtMSName.Disable();
     684             :     else
     685           0 :         aEdtMSName.Enable();
     686             : 
     687           0 :     if( pThm->IsReadOnly() )
     688           0 :         aType += String( CUI_RES( RID_SVXSTR_GALLERY_READONLY ) );
     689             : 
     690           0 :     aFtMSShowType.SetText( aType );
     691           0 :     aFtMSShowPath.SetText( pThm->GetSdgURL().GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
     692             : 
     693             :     // singular or plural?
     694           0 :     if ( 1 == pThm->GetObjectCount() )
     695           0 :         aObjStr = aObjStr.GetToken( 0 );
     696             :     else
     697           0 :         aObjStr = aObjStr.GetToken( 1 );
     698             : 
     699           0 :     aOutStr += ' ';
     700           0 :     aOutStr += aObjStr;
     701             : 
     702           0 :     aFtMSShowContent.SetText( aOutStr );
     703             : 
     704             :     // get locale wrapper (singleton)
     705           0 :     const SvtSysLocale aSysLocale;
     706           0 :     const LocaleDataWrapper&    aLocaleData = aSysLocale.GetLocaleData();
     707             : 
     708             :     // ChangeDate/Time
     709           0 :     aAccess = aLocaleData.getDate( pData->aThemeChangeDate );
     710           0 :     aAccess += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
     711           0 :     aAccess += aLocaleData.getTime( pData->aThemeChangeTime );
     712           0 :     aFtMSShowChangeDate.SetText( aAccess );
     713             : 
     714             :     // set image
     715             :     sal_uInt16 nId;
     716             : 
     717           0 :     if( pThm->IsReadOnly() )
     718           0 :         nId = RID_SVXBMP_THEME_READONLY_BIG;
     719           0 :     else if( pThm->IsDefault() )
     720           0 :         nId = RID_SVXBMP_THEME_DEFAULT_BIG;
     721             :     else
     722           0 :         nId = RID_SVXBMP_THEME_NORMAL_BIG;
     723             : 
     724           0 :     aFiMSImage.SetImage( Image( Bitmap( CUI_RES( nId ) ), COL_LIGHTMAGENTA ) );
     725           0 : }
     726             : 
     727             : // ------------------------------------------------------------------------
     728             : 
     729           0 : sal_Bool TPGalleryThemeGeneral::FillItemSet( SfxItemSet& /*rSet*/ )
     730             : {
     731           0 :     pData->aEditedTitle = aEdtMSName.GetText();
     732           0 :     return sal_True;
     733             : }
     734             : 
     735             : // ------------------------------------------------------------------------
     736             : 
     737           0 : SfxTabPage* TPGalleryThemeGeneral::Create( Window* pParent, const SfxItemSet& rSet )
     738             : {
     739           0 :     return new TPGalleryThemeGeneral( pParent, rSet );
     740             : }
     741             : 
     742             : // ----------------------------
     743             : // - TPGalleryThemeProperties -
     744             : // ----------------------------
     745             : 
     746           0 : TPGalleryThemeProperties::TPGalleryThemeProperties( Window* pWindow, const SfxItemSet& rSet ) :
     747           0 :         SfxTabPage          ( pWindow, CUI_RES( RID_SVXTABPAGE_GALLERYTHEME_FILES ), rSet ),
     748           0 :         aFtFileType         ( this, CUI_RES(FT_FILETYPE ) ),
     749           0 :         aCbbFileType        ( this, CUI_RES(CBB_FILETYPE ) ),
     750           0 :         aLbxFound           ( this, CUI_RES(LBX_FOUND ) ),
     751           0 :         aBtnSearch          ( this, CUI_RES(BTN_SEARCH ) ),
     752           0 :         aBtnTake            ( this, CUI_RES(BTN_TAKE ) ),
     753           0 :         aBtnTakeAll         ( this, CUI_RES(BTN_TAKEALL ) ),
     754           0 :         aCbxPreview         ( this, CUI_RES(CBX_PREVIEW ) ),
     755           0 :         aWndPreview         ( this, CUI_RES( WND_BRSPRV ) ),
     756             :         nCurFilterPos       (0),
     757             :         nFirstExtFilterPos  (0),
     758             :         bEntriesFound       (sal_False),
     759             :         bInputAllowed       (sal_True),
     760             :         bSearchRecursive    (sal_False),
     761           0 :         xDialogListener     ( new ::svt::DialogClosedListener() )
     762             : {
     763           0 :     FreeResource();
     764             : 
     765           0 :     xDialogListener->SetDialogClosedLink( LINK( this, TPGalleryThemeProperties, DialogClosedHdl ) );
     766           0 :     aLbxFound.SetAccessibleName(String(SVX_RES(RID_SVXSTR_GALLERY_FILESFOUND)));
     767           0 :     aWndPreview.SetAccessibleName(aCbxPreview.GetText());
     768           0 :     aLbxFound.SetAccessibleRelationLabeledBy(&aLbxFound);
     769           0 : }
     770             : 
     771             : // ------------------------------------------------------------------------
     772             : 
     773           0 : void TPGalleryThemeProperties::SetXChgData( ExchangeData* _pData )
     774             : {
     775           0 :     pData = _pData;
     776             : 
     777           0 :     aPreviewTimer.SetTimeoutHdl( LINK( this, TPGalleryThemeProperties, PreviewTimerHdl ) );
     778           0 :     aPreviewTimer.SetTimeout( 500 );
     779           0 :     aBtnSearch.SetClickHdl(LINK(this, TPGalleryThemeProperties, ClickSearchHdl));
     780           0 :     aBtnTake.SetClickHdl(LINK(this, TPGalleryThemeProperties, ClickTakeHdl));
     781           0 :     aBtnTakeAll.SetClickHdl(LINK(this, TPGalleryThemeProperties, ClickTakeAllHdl));
     782           0 :     aCbxPreview.SetClickHdl(LINK(this, TPGalleryThemeProperties, ClickPreviewHdl));
     783           0 :     aCbbFileType.SetSelectHdl(LINK(this, TPGalleryThemeProperties, SelectFileTypeHdl));
     784           0 :     aCbbFileType.EnableDDAutoWidth( sal_False );
     785           0 :     aLbxFound.SetDoubleClickHdl(LINK(this, TPGalleryThemeProperties, DClickFoundHdl));
     786           0 :     aLbxFound.SetSelectHdl(LINK(this, TPGalleryThemeProperties, SelectFoundHdl));
     787           0 :     aLbxFound.InsertEntry(String(CUI_RES(RID_SVXSTR_GALLERY_NOFILES)));
     788           0 :     aLbxFound.Show();
     789             : 
     790           0 :     FillFilterList();
     791             : 
     792           0 :     aBtnTake.Enable();
     793           0 :     aBtnTakeAll.Disable();
     794           0 :     aCbxPreview.Disable();
     795           0 : }
     796             : 
     797             : // ------------------------------------------------------------------------
     798             : 
     799           0 : void TPGalleryThemeProperties::StartSearchFiles( const String& _rFolderURL, short _nDlgResult )
     800             : {
     801           0 :     if ( RET_OK == _nDlgResult )
     802             :     {
     803           0 :         aURL = INetURLObject( _rFolderURL );
     804           0 :         bSearchRecursive = sal_True;    // UI choice no longer possible, windows file picker allows no user controls
     805           0 :         SearchFiles();
     806             :     }
     807             : 
     808           0 :     nCurFilterPos = aCbbFileType.GetEntryPos( aCbbFileType.GetText() );
     809           0 : }
     810             : 
     811             : // ------------------------------------------------------------------------
     812             : 
     813           0 : TPGalleryThemeProperties::~TPGalleryThemeProperties()
     814             : {
     815           0 :     xMediaPlayer.clear();
     816           0 :     xDialogListener.clear();
     817             : 
     818           0 :     for ( size_t i = 0, n = aFoundList.size(); i < n; ++i )
     819           0 :         delete aFoundList[ i ];
     820             : 
     821           0 :     for ( size_t i = 0, n = aFilterEntryList.size(); i < n; ++i ) {
     822           0 :         delete aFilterEntryList[ i ];
     823             :     }
     824           0 : }
     825             : 
     826             : // ------------------------------------------------------------------------
     827             : 
     828           0 : SfxTabPage* TPGalleryThemeProperties::Create( Window* pParent, const SfxItemSet& rSet )
     829             : {
     830           0 :     return new TPGalleryThemeProperties( pParent, rSet );
     831             : }
     832             : 
     833             : // ------------------------------------------------------------------------
     834             : 
     835           0 : ::rtl::OUString TPGalleryThemeProperties::addExtension( const ::rtl::OUString& _rDisplayText, const ::rtl::OUString& _rExtension )
     836             : {
     837           0 :     ::rtl::OUString sAllFilter( RTL_CONSTASCII_USTRINGPARAM( "(*.*)" ) );
     838           0 :     ::rtl::OUString sOpenBracket( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
     839           0 :     ::rtl::OUString sCloseBracket( RTL_CONSTASCII_USTRINGPARAM( ")" ) );
     840           0 :     ::rtl::OUString sRet = _rDisplayText;
     841             : 
     842           0 :     if ( sRet.indexOf( sAllFilter ) == -1 )
     843             :     {
     844           0 :         String sExt = _rExtension;
     845           0 :         sRet += sOpenBracket;
     846           0 :         sRet += sExt;
     847           0 :         sRet += sCloseBracket;
     848             :     }
     849           0 :     return sRet;
     850             : }
     851             : 
     852             : // ------------------------------------------------------------------------
     853             : 
     854           0 : void TPGalleryThemeProperties::FillFilterList()
     855             : {
     856           0 :     GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter();
     857           0 :     String              aExt;
     858           0 :     String              aName;
     859             :     FilterEntry*        pFilterEntry;
     860             :     FilterEntry*        pTestEntry;
     861             :     sal_uInt16          i, nKeyCount;
     862             :     sal_Bool                bInList;
     863             : 
     864             :     // graphic filters
     865           0 :     for( i = 0, nKeyCount = rFilter.GetImportFormatCount(); i < nKeyCount; i++ )
     866             :     {
     867           0 :         aExt = rFilter.GetImportFormatShortName( i );
     868           0 :         aName = rFilter.GetImportFormatName( i );
     869           0 :         size_t entryIndex = 0;
     870           0 :         pTestEntry = aFilterEntryList.empty() ? NULL : aFilterEntryList[ entryIndex ];
     871           0 :         bInList = sal_False;
     872             : 
     873           0 :         String aExtensions;
     874           0 :         int j = 0;
     875           0 :         String sWildcard;
     876           0 :         while( sal_True )
     877             :         {
     878           0 :             sWildcard = rFilter.GetImportWildcard( i, j++ );
     879           0 :             if ( !sWildcard.Len() )
     880           0 :                 break;
     881           0 :             if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
     882             :             {
     883           0 :                 if ( aExtensions.Len() )
     884           0 :                     aExtensions += sal_Unicode(';');
     885           0 :                 aExtensions += sWildcard;
     886             :             }
     887             :         }
     888           0 :         aName = addExtension( aName, aExtensions );
     889             : 
     890           0 :         while( pTestEntry )
     891             :         {
     892           0 :             if ( pTestEntry->aFilterName == aExt )
     893             :             {
     894           0 :                 bInList = sal_True;
     895           0 :                 break;
     896             :             }
     897           0 :             pTestEntry = ( ++entryIndex < aFilterEntryList.size() )
     898           0 :                        ? aFilterEntryList[ entryIndex ] : NULL;
     899             :         }
     900           0 :         if ( !bInList )
     901             :         {
     902           0 :             pFilterEntry = new FilterEntry;
     903           0 :             pFilterEntry->aFilterName = aExt;
     904           0 :             size_t pos = aCbbFileType.InsertEntry( aName );
     905           0 :             if ( pos < aFilterEntryList.size() ) {
     906           0 :                 aFilterEntryList.insert( aFilterEntryList.begin() + pos, pFilterEntry );
     907             :             } else {
     908           0 :                 aFilterEntryList.push_back( pFilterEntry );
     909             :             }
     910             :         }
     911           0 :     }
     912             : 
     913             :     // media filters
     914           0 :     static const ::rtl::OUString aWildcard( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
     915           0 :     ::avmedia::FilterNameVector     aFilters;
     916           0 :     ::avmedia::MediaWindow::getMediaFilters( aFilters );
     917             : 
     918           0 :     for( unsigned long l = 0; l < aFilters.size(); ++l )
     919             :     {
     920           0 :         for( sal_Int32 nIndex = 0; nIndex >= 0; )
     921             :         {
     922           0 :             ::rtl::OUString aFilterWildcard( aWildcard );
     923             : 
     924           0 :             pFilterEntry = new FilterEntry;
     925           0 :             pFilterEntry->aFilterName = aFilters[ l ].second.getToken( 0, ';', nIndex );
     926             :             nFirstExtFilterPos = aCbbFileType.InsertEntry(
     927             :                 addExtension(
     928           0 :                     aFilters[ l ].first,
     929           0 :                     aFilterWildcard += pFilterEntry->aFilterName
     930             :                 )
     931           0 :             );
     932           0 :             if ( nFirstExtFilterPos < aFilterEntryList.size() ) {
     933             :                 aFilterEntryList.insert(
     934           0 :                     aFilterEntryList.begin() + nFirstExtFilterPos,
     935             :                     pFilterEntry
     936           0 :                 );
     937             :             } else {
     938           0 :                 aFilterEntryList.push_back( pFilterEntry );
     939             :             }
     940           0 :         }
     941             :     }
     942             : 
     943             :     // 'All' filters
     944           0 :     String aExtensions;
     945             : 
     946             :     // graphic filters
     947           0 :     for ( i = 0; i < nKeyCount; ++i )
     948             :     {
     949           0 :         int j = 0;
     950           0 :         String sWildcard;
     951           0 :         while( sal_True )
     952             :         {
     953           0 :             sWildcard = rFilter.GetImportWildcard( i, j++ );
     954           0 :             if ( !sWildcard.Len() )
     955           0 :                 break;
     956           0 :             if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
     957             :             {
     958           0 :                 if ( aExtensions.Len() )
     959           0 :                     aExtensions += sal_Unicode( ';' );
     960             : 
     961           0 :                 aExtensions += sWildcard;
     962             :             }
     963             :         }
     964           0 :     }
     965             : 
     966             :     // media filters
     967           0 :     for( unsigned long k = 0; k < aFilters.size(); ++k )
     968             :     {
     969           0 :         for( sal_Int32 nIndex = 0; nIndex >= 0; )
     970             :         {
     971           0 :             if ( aExtensions.Len() )
     972           0 :                 aExtensions += sal_Unicode( ';' );
     973           0 :             ( aExtensions += String( aWildcard ) ) += String( aFilters[ k ].second.getToken( 0, ';', nIndex ) );
     974             :         }
     975             :      }
     976             : 
     977             : #if defined(WNT)
     978             :     if ( aExtensions.Len() > 240 )
     979             :         aExtensions = DEFINE_CONST_UNICODE( "*.*" );
     980             : #endif
     981             : 
     982           0 :     pFilterEntry = new FilterEntry;
     983           0 :     pFilterEntry->aFilterName = String( CUI_RES( RID_SVXSTR_GALLERY_ALLFILES ) );
     984           0 :     pFilterEntry->aFilterName = addExtension( pFilterEntry->aFilterName, aExtensions );
     985           0 :     size_t pos = aCbbFileType.InsertEntry( pFilterEntry->aFilterName, 0 );
     986           0 :     if ( pos < aFilterEntryList.size() ) {
     987           0 :         aFilterEntryList.insert( aFilterEntryList.begin() + pos, pFilterEntry );
     988             :     } else {
     989           0 :         aFilterEntryList.push_back( pFilterEntry );
     990             :     }
     991           0 :     aCbbFileType.SetText( pFilterEntry->aFilterName );
     992           0 : }
     993             : 
     994             : // ------------------------------------------------------------------------
     995             : 
     996           0 : IMPL_LINK_NOARG(TPGalleryThemeProperties, SelectFileTypeHdl)
     997             : {
     998           0 :     String aText( aCbbFileType.GetText() );
     999             : 
    1000           0 :     if( bInputAllowed && ( aLastFilterName != aText ) )
    1001             :     {
    1002           0 :         aLastFilterName = aText;
    1003             : 
    1004           0 :         if( QueryBox( this, WB_YES_NO, String( CUI_RES( RID_SVXSTR_GALLERY_SEARCH ) ) ).Execute() == RET_YES )
    1005           0 :             SearchFiles();
    1006             :     }
    1007             : 
    1008           0 :     return 0L;
    1009             : }
    1010             : 
    1011             : // ------------------------------------------------------------------------
    1012             : 
    1013           0 : void TPGalleryThemeProperties::SearchFiles()
    1014             : {
    1015           0 :     SearchProgress* pProgress = new SearchProgress( this, aURL );
    1016             : 
    1017           0 :     for ( size_t i = 0, n = aFoundList.size(); i < n; ++i )
    1018           0 :         delete aFoundList[ i ];
    1019           0 :     aFoundList.clear();
    1020             : 
    1021           0 :     aLbxFound.Clear();
    1022             : 
    1023           0 :     pProgress->SetFileType( aCbbFileType.GetText() );
    1024           0 :     pProgress->SetDirectory( rtl::OUString() );
    1025           0 :     pProgress->Update();
    1026             : 
    1027           0 :     pProgress->StartExecuteModal( LINK( this, TPGalleryThemeProperties, EndSearchProgressHdl ) );
    1028           0 : }
    1029             : 
    1030             : // ------------------------------------------------------------------------
    1031             : 
    1032           0 : IMPL_LINK_NOARG(TPGalleryThemeProperties, ClickSearchHdl)
    1033             : {
    1034           0 :     if( bInputAllowed )
    1035             :     {
    1036             :         try
    1037             :         {
    1038             :             // setup folder picker
    1039           0 :             com::sun::star::uno::Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
    1040           0 :             xFolderPicker = FolderPicker::create(xContext);
    1041             : 
    1042           0 :             String  aDlgPathName( SvtPathOptions().GetGraphicPath() );
    1043           0 :             xFolderPicker->setDisplayDirectory(aDlgPathName);
    1044             : 
    1045           0 :             aPreviewTimer.Stop();
    1046             : 
    1047           0 :             com::sun::star::uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
    1048           0 :             if ( xAsyncDlg.is() )
    1049           0 :                 xAsyncDlg->startExecuteModal( xDialogListener.get() );
    1050             :             else
    1051             :             {
    1052           0 :                 if( xFolderPicker->execute() == RET_OK )
    1053             :                 {
    1054           0 :                     aURL = INetURLObject( xFolderPicker->getDirectory() );
    1055           0 :                     bSearchRecursive = sal_True;    // UI choice no longer possible, windows file picker allows no user controls
    1056           0 :                     SearchFiles();
    1057             :                 }
    1058             : 
    1059           0 :                 nCurFilterPos = aCbbFileType.GetEntryPos( aCbbFileType.GetText() );
    1060           0 :             }
    1061             :         }
    1062           0 :         catch (const IllegalArgumentException&)
    1063             :         {
    1064             :             OSL_FAIL( "Folder picker failed with illegal arguments" );
    1065             :         }
    1066             :     }
    1067             : 
    1068           0 :     return 0L;
    1069             : }
    1070             : 
    1071             : // ------------------------------------------------------------------------
    1072             : 
    1073           0 : void TPGalleryThemeProperties::TakeFiles()
    1074             : {
    1075           0 :     if( aLbxFound.GetSelectEntryCount() || ( bTakeAll && bEntriesFound ) )
    1076             :     {
    1077           0 :         TakeProgress* pTakeProgress = new TakeProgress( this );
    1078           0 :         pTakeProgress->Update();
    1079             : 
    1080             :         pTakeProgress->StartExecuteModal(
    1081             :             Link() /* no postprocessing needed, pTakeProgress
    1082           0 :                       will be deleted in TakeProgress::CleanupHdl */ );
    1083             :     }
    1084           0 : }
    1085             : 
    1086             : // ------------------------------------------------------------------------
    1087             : 
    1088           0 : IMPL_LINK_NOARG(TPGalleryThemeProperties, ClickPreviewHdl)
    1089             : {
    1090           0 :     if ( bInputAllowed )
    1091             :     {
    1092           0 :         aPreviewTimer.Stop();
    1093           0 :         aPreviewString.Erase();
    1094             : 
    1095           0 :         if( !aCbxPreview.IsChecked() )
    1096             :         {
    1097           0 :             xMediaPlayer.clear();
    1098           0 :             aWndPreview.SetGraphic( Graphic() );
    1099           0 :             aWndPreview.Invalidate();
    1100             :         }
    1101             :         else
    1102           0 :             DoPreview();
    1103             :     }
    1104             : 
    1105           0 :     return 0;
    1106             : }
    1107             : 
    1108             : // ------------------------------------------------------------------------
    1109             : 
    1110           0 : void TPGalleryThemeProperties::DoPreview()
    1111             : {
    1112           0 :     String aString( aLbxFound.GetSelectEntry() );
    1113             : 
    1114           0 :     if( aString != aPreviewString )
    1115             :     {
    1116           0 :         INetURLObject   _aURL( *aFoundList[ aLbxFound.GetEntryPos( aString ) ] );
    1117           0 :         bInputAllowed = sal_False;
    1118             : 
    1119           0 :         if ( !aWndPreview.SetGraphic( _aURL ) )
    1120             :         {
    1121           0 :             GetParent()->LeaveWait();
    1122           0 :             ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTSPATH );
    1123           0 :             GetParent()->EnterWait();
    1124             :         }
    1125           0 :         else if( ::avmedia::MediaWindow::isMediaURL( _aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
    1126             :         {
    1127           0 :             xMediaPlayer = ::avmedia::MediaWindow::createPlayer( _aURL.GetMainURL( INetURLObject::NO_DECODE ) );
    1128           0 :             if( xMediaPlayer.is() )
    1129           0 :                 xMediaPlayer->start();
    1130             :         }
    1131             : 
    1132           0 :         bInputAllowed = sal_True;
    1133           0 :         aPreviewString = aString;
    1134           0 :     }
    1135           0 : }
    1136             : 
    1137             : // ------------------------------------------------------------------------
    1138             : 
    1139           0 : IMPL_LINK_NOARG(TPGalleryThemeProperties, ClickTakeHdl)
    1140             : {
    1141           0 :     if( bInputAllowed )
    1142             :     {
    1143           0 :         aPreviewTimer.Stop();
    1144             : 
    1145           0 :         if( !aLbxFound.GetSelectEntryCount() || !bEntriesFound )
    1146             :         {
    1147           0 :             SvxOpenGraphicDialog aDlg(String( RTL_CONSTASCII_USTRINGPARAM( "Gallery" ) ) );
    1148           0 :             aDlg.EnableLink(sal_False);
    1149           0 :             aDlg.AsLink(sal_False);
    1150             : 
    1151           0 :             if( !aDlg.Execute() )
    1152           0 :                 pData->pTheme->InsertURL( INetURLObject( aDlg.GetPath() ) );
    1153             :         }
    1154             :         else
    1155             :         {
    1156           0 :             bTakeAll = sal_False;
    1157           0 :             TakeFiles();
    1158             :         }
    1159             :     }
    1160             : 
    1161           0 :     return 0L;
    1162             : }
    1163             : 
    1164             : // ------------------------------------------------------------------------
    1165             : 
    1166           0 : IMPL_LINK_NOARG(TPGalleryThemeProperties, ClickTakeAllHdl)
    1167             : {
    1168           0 :     if( bInputAllowed )
    1169             :     {
    1170           0 :         aPreviewTimer.Stop();
    1171           0 :         bTakeAll = sal_True;
    1172           0 :         TakeFiles();
    1173             :     }
    1174             : 
    1175           0 :     return 0L;
    1176             : }
    1177             : 
    1178             : // ------------------------------------------------------------------------
    1179             : 
    1180           0 : IMPL_LINK_NOARG(TPGalleryThemeProperties, SelectFoundHdl)
    1181             : {
    1182           0 :     if( bInputAllowed )
    1183             :     {
    1184           0 :         sal_Bool bPreviewPossible = sal_False;
    1185             : 
    1186           0 :         aPreviewTimer.Stop();
    1187             : 
    1188           0 :         if( bEntriesFound )
    1189             :         {
    1190           0 :             if( aLbxFound.GetSelectEntryCount() == 1 )
    1191             :             {
    1192           0 :                 aCbxPreview.Enable();
    1193           0 :                 bPreviewPossible = sal_True;
    1194             :             }
    1195             :             else
    1196           0 :                 aCbxPreview.Disable();
    1197             : 
    1198           0 :             if( !aFoundList.empty() )
    1199           0 :                 aBtnTakeAll.Enable();
    1200             :             else
    1201           0 :                 aBtnTakeAll.Disable();
    1202             :         }
    1203             : 
    1204           0 :         if( bPreviewPossible && aCbxPreview.IsChecked() )
    1205           0 :             aPreviewTimer.Start();
    1206             :     }
    1207             : 
    1208           0 :     return 0;
    1209             : }
    1210             : 
    1211             : // ------------------------------------------------------------------------
    1212             : 
    1213           0 : IMPL_LINK_NOARG(TPGalleryThemeProperties, DClickFoundHdl)
    1214             : {
    1215           0 :     if( bInputAllowed )
    1216             :     {
    1217           0 :         aPreviewTimer.Stop();
    1218             : 
    1219           0 :         return (aLbxFound.GetSelectEntryCount() == 1 && bEntriesFound) ?
    1220           0 :             ClickTakeHdl(NULL) : 0;
    1221             :     }
    1222             :     else
    1223           0 :         return 0;
    1224             : }
    1225             : 
    1226             : // ------------------------------------------------------------------------
    1227             : 
    1228           0 : IMPL_LINK_NOARG(TPGalleryThemeProperties, PreviewTimerHdl)
    1229             : {
    1230           0 :     aPreviewTimer.Stop();
    1231           0 :     DoPreview();
    1232           0 :     return 0L;
    1233             : }
    1234             : 
    1235             : // ------------------------------------------------------------------------
    1236             : 
    1237           0 : IMPL_LINK_NOARG(TPGalleryThemeProperties, EndSearchProgressHdl)
    1238             : {
    1239           0 :   if( !aFoundList.empty() )
    1240             :   {
    1241           0 :       aLbxFound.SelectEntryPos( 0 );
    1242           0 :       aBtnTakeAll.Enable();
    1243           0 :       aCbxPreview.Enable();
    1244           0 :       bEntriesFound = sal_True;
    1245             :   }
    1246             :   else
    1247             :   {
    1248           0 :       aLbxFound.InsertEntry( String( CUI_RES( RID_SVXSTR_GALLERY_NOFILES ) ) );
    1249           0 :       aBtnTakeAll.Disable();
    1250           0 :       aCbxPreview.Disable();
    1251           0 :       bEntriesFound = sal_False;
    1252             :   }
    1253           0 :   return 0L;
    1254             : }
    1255             : 
    1256             : // ------------------------------------------------------------------------
    1257             : 
    1258           0 : IMPL_LINK( TPGalleryThemeProperties, DialogClosedHdl, ::com::sun::star::ui::dialogs::DialogClosedEvent*, pEvt )
    1259             : {
    1260             :     DBG_ASSERT( xFolderPicker.is() == sal_True, "TPGalleryThemeProperties::DialogClosedHdl(): no folder picker" );
    1261             : 
    1262           0 :     String sURL = String( xFolderPicker->getDirectory() );
    1263           0 :     StartSearchFiles( sURL, pEvt->DialogResult );
    1264             : 
    1265           0 :     return 0L;
    1266           6 : }
    1267             : 
    1268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10