LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/cui/source/dialogs - cuigaldlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 596 0.0 %
Date: 2013-07-09 Functions: 0 76 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10