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