1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_features.h>
22 #include <sal/config.h>
27 #include <vcl/errinf.hxx>
28 #include <ucbhelper/content.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/weld.hxx>
31 #include <avmedia/mediawindow.hxx>
32 #include <unotools/pathoptions.hxx>
33 #include <sfx2/opengrf.hxx>
34 #include <vcl/graphicfilter.hxx>
35 #include <svx/gallery1.hxx>
36 #include <svx/galtheme.hxx>
37 #include <cuigaldlg.hxx>
38 #include <bitmaps.hlst>
39 #include <unotools/localedatawrapper.hxx>
40 #include <unotools/syslocale.hxx>
41 #include <com/sun/star/uno/Reference.hxx>
42 #include <com/sun/star/lang/IllegalArgumentException.hpp>
43 #include <comphelper/processfactory.hxx>
44 #include <com/sun/star/sdbc/XResultSet.hpp>
45 #include <com/sun/star/sdbc/XRow.hpp>
46 #include <com/sun/star/ucb/ContentCreationException.hpp>
47 #include <com/sun/star/ucb/XContentAccess.hpp>
48 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
49 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
50 #include <dialmgr.hxx>
51 #include <strings.hrc>
52 #include <svx/dialmgr.hxx>
53 #include <svx/strings.hrc>
55 using namespace ::ucbhelper
;
56 using namespace ::cppu
;
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::sdbc
;
59 using namespace ::com::sun::star::ucb
;
60 using namespace ::com::sun::star::ui::dialogs
;
61 using namespace ::com::sun::star::uno
;
64 SearchThread::SearchThread(SearchProgress
* pProgress
,
65 TPGalleryThemeProperties
* pBrowser
,
66 const INetURLObject
& rStartURL
)
67 : Thread("cuiSearchThread")
68 , mpProgress(pProgress
)
70 , maStartURL(rStartURL
)
74 SearchThread::~SearchThread()
78 void SearchThread::execute()
80 const OUString
aFileType(mpBrowser
->m_xCbbFileType
->get_active_text());
82 if (!aFileType
.isEmpty())
84 const int nFileNumber
= mpBrowser
->m_xCbbFileType
->find_text(aFileType
);
85 sal_Int32 nBeginFormat
, nEndFormat
;
86 std::vector
< OUString
> aFormats
;
88 if( !nFileNumber
|| nFileNumber
== -1)
91 nEndFormat
= mpBrowser
->m_xCbbFileType
->get_count() - 1;
94 nBeginFormat
= nEndFormat
= nFileNumber
;
96 for (sal_Int32 i
= nBeginFormat
; i
<= nEndFormat
; ++i
)
97 aFormats
.push_back( mpBrowser
->aFilterEntryList
[ i
]->aFilterName
.toAsciiLowerCase() );
99 ImplSearch( maStartURL
, aFormats
, mpBrowser
->bSearchRecursive
);
102 Application::PostUserEvent(LINK(mpProgress
, SearchProgress
, CleanUpHdl
));
106 void SearchThread::ImplSearch( const INetURLObject
& rStartURL
,
107 const std::vector
< OUString
>& rFormats
,
111 SolarMutexGuard aGuard
;
113 mpProgress
->SetDirectory( rStartURL
);
118 css::uno::Reference
< XCommandEnvironment
> xEnv
;
119 Content
aCnt( rStartURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), xEnv
, comphelper::getProcessComponentContext() );
120 Sequence
< OUString
> aProps( 2 );
122 aProps
.getArray()[ 0 ] = "IsFolder";
123 aProps
.getArray()[ 1 ] = "IsDocument";
124 css::uno::Reference
< XResultSet
> xResultSet(
125 aCnt
.createCursor( aProps
) );
127 if( xResultSet
.is() )
129 css::uno::Reference
< XContentAccess
> xContentAccess( xResultSet
, UNO_QUERY_THROW
);
130 css::uno::Reference
< XRow
> xRow( xResultSet
, UNO_QUERY_THROW
);
132 while( xResultSet
->next() && schedule() )
134 INetURLObject
aFoundURL( xContentAccess
->queryContentIdentifierString() );
135 DBG_ASSERT( aFoundURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
137 bool bFolder
= xRow
->getBoolean( 1 ); // property "IsFolder"
138 if ( xRow
->wasNull() )
141 if( bRecursive
&& bFolder
)
142 ImplSearch( aFoundURL
, rFormats
, true );
145 bool bDocument
= xRow
->getBoolean( 2 ); // property "IsDocument"
146 if ( xRow
->wasNull() )
151 GraphicDescriptor
aDesc( aFoundURL
);
153 if( ( aDesc
.Detect() &&
154 std::find( rFormats
.begin(),
156 GraphicDescriptor::GetImportFormatShortName(
157 aDesc
.GetFileFormat() ).toAsciiLowerCase() )
158 != rFormats
.end() ) ||
159 std::find( rFormats
.begin(),
161 aFoundURL
.GetFileExtension().toAsciiLowerCase())
164 SolarMutexGuard aGuard
;
166 mpBrowser
->aFoundList
.push_back(
167 aFoundURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
)
169 mpBrowser
->m_xLbxFound
->insert_text(
170 mpBrowser
->aFoundList
.size() - 1,
171 GetReducedString(aFoundURL
, 50));
178 catch (const ContentCreationException
&)
181 catch (const css::uno::RuntimeException
&)
184 catch (const css::uno::Exception
&)
189 SearchProgress::SearchProgress(weld::Window
* pParent
, TPGalleryThemeProperties
* pTabPage
, const INetURLObject
& rStartURL
)
190 : GenericDialogController(pParent
, "cui/ui/gallerysearchprogress.ui", "GallerySearchProgress")
191 , startUrl_(rStartURL
)
192 , m_pTabPage(pTabPage
)
193 , m_xFtSearchDir(m_xBuilder
->weld_label("dir"))
194 , m_xFtSearchType(m_xBuilder
->weld_label("file"))
195 , m_xBtnCancel(m_xBuilder
->weld_button("cancel"))
197 m_xFtSearchType
->set_size_request(m_xFtSearchType
->get_preferred_size().Width(), -1);
198 m_xBtnCancel
->connect_clicked(LINK(this, SearchProgress
, ClickCancelBtn
));
201 SearchProgress::~SearchProgress()
205 IMPL_LINK_NOARG(SearchProgress
, ClickCancelBtn
, weld::Button
&, void)
207 if (m_aSearchThread
.is())
208 m_aSearchThread
->terminate();
211 IMPL_LINK_NOARG(SearchProgress
, CleanUpHdl
, void*, void)
213 if (m_aSearchThread
.is())
214 m_aSearchThread
->join();
216 m_xDialog
->response(RET_OK
);
219 void SearchProgress::LaunchThread()
221 assert(!m_aSearchThread
.is());
222 m_aSearchThread
= new SearchThread(this, m_pTabPage
, startUrl_
);
223 m_aSearchThread
->launch();
226 TakeThread::TakeThread(
227 TakeProgress
* pProgress
,
228 TPGalleryThemeProperties
* pBrowser
,
229 TokenList_impl
& rTakenList
231 Thread ( "cuiTakeThread" ),
232 mpProgress ( pProgress
),
233 mpBrowser ( pBrowser
),
234 mrTakenList ( rTakenList
)
239 TakeThread::~TakeThread()
243 void TakeThread::execute()
246 GalleryTheme
* pThm
= mpBrowser
->GetXChgData()->pTheme
;
247 std::unique_ptr
<GalleryProgress
> pStatusProgress
;
249 std::vector
<int> aSelectedRows
;
252 SolarMutexGuard aGuard
;
253 pStatusProgress
.reset(new GalleryProgress
);
254 if (mpBrowser
->bTakeAll
)
255 nEntries
= mpBrowser
->m_xLbxFound
->n_children();
258 aSelectedRows
= mpBrowser
->m_xLbxFound
->get_selected_rows();
259 nEntries
= aSelectedRows
.size();
261 pThm
->LockBroadcaster();
264 for( sal_Int32 i
= 0; i
< nEntries
&& schedule(); ++i
)
266 const sal_Int32 nPos
= mpBrowser
->bTakeAll
? i
: aSelectedRows
[i
];
267 const INetURLObject
aURL( mpBrowser
->aFoundList
[ nPos
]);
269 mrTakenList
.push_back( static_cast<sal_uLong
>(nPos
) );
272 SolarMutexGuard aGuard
;
274 mpProgress
->SetFile( aURL
);
275 pStatusProgress
->Update( i
, nEntries
- 1 );
276 pThm
->InsertURL( aURL
);
281 SolarMutexGuard aGuard
;
283 pThm
->UnlockBroadcaster();
284 pStatusProgress
.reset();
287 Application::PostUserEvent(LINK(mpProgress
, TakeProgress
, CleanUpHdl
));
290 TakeProgress::TakeProgress(weld::Window
* pParent
, TPGalleryThemeProperties
* pTabPage
)
291 : GenericDialogController(pParent
, "cui/ui/galleryapplyprogress.ui",
292 "GalleryApplyProgress")
294 , m_pTabPage(pTabPage
)
295 , m_xFtTakeFile(m_xBuilder
->weld_label("file"))
296 , m_xBtnCancel(m_xBuilder
->weld_button("cancel"))
298 m_xBtnCancel
->connect_clicked(LINK(this, TakeProgress
, ClickCancelBtn
));
301 TakeProgress::~TakeProgress()
305 IMPL_LINK_NOARG(TakeProgress
, ClickCancelBtn
, weld::Button
&, void)
307 if (maTakeThread
.is())
308 maTakeThread
->terminate();
312 IMPL_LINK_NOARG(TakeProgress
, CleanUpHdl
, void*, void)
314 if (maTakeThread
.is())
315 maTakeThread
->join();
317 std::vector
<bool, std::allocator
<bool> > aRemoveEntries(m_pTabPage
->aFoundList
.size(), false);
318 std::vector
< OUString
> aRemainingVector
;
319 sal_uInt32 i
, nCount
;
321 std::unique_ptr
<weld::WaitObject
> xWait(new weld::WaitObject(m_pParent
));
323 m_pTabPage
->m_xLbxFound
->select(-1);
324 m_pTabPage
->m_xLbxFound
->freeze();
326 // mark all taken positions in aRemoveEntries
327 for( i
= 0, nCount
= maTakenList
.size(); i
< nCount
; ++i
)
328 aRemoveEntries
[ maTakenList
[ i
] ] = true;
332 for( i
= 0, nCount
= aRemoveEntries
.size(); i
< nCount
; ++i
)
333 if( !aRemoveEntries
[ i
] )
334 aRemainingVector
.push_back( m_pTabPage
->aFoundList
[i
] );
336 m_pTabPage
->aFoundList
.clear();
338 for( i
= 0, nCount
= aRemainingVector
.size(); i
< nCount
; ++i
)
339 m_pTabPage
->aFoundList
.push_back( aRemainingVector
[ i
] );
341 aRemainingVector
.clear();
344 for( i
= 0, nCount
= aRemoveEntries
.size(); i
< nCount
; ++i
)
345 if( !aRemoveEntries
[ i
] )
346 aRemainingVector
.push_back(m_pTabPage
->m_xLbxFound
->get_text(i
));
348 m_pTabPage
->m_xLbxFound
->clear();
350 for( i
= 0, nCount
= aRemainingVector
.size(); i
< nCount
; ++i
)
351 m_pTabPage
->m_xLbxFound
->append_text(aRemainingVector
[i
]);
353 aRemainingVector
.clear();
355 m_pTabPage
->m_xLbxFound
->thaw();
356 m_pTabPage
->SelectFoundHdl( *m_pTabPage
->m_xLbxFound
);
360 m_xDialog
->response(RET_OK
);
363 void TakeProgress::LaunchThread()
365 assert(!maTakeThread
.is());
366 maTakeThread
= new TakeThread(this, m_pTabPage
, maTakenList
);
367 maTakeThread
->launch();
370 ActualizeProgress::ActualizeProgress(weld::Window
* pWindow
, GalleryTheme
* pThm
)
371 : GenericDialogController(pWindow
, "cui/ui/galleryupdateprogress.ui",
372 "GalleryUpdateProgress")
375 , m_xFtActualizeFile(m_xBuilder
->weld_label("file"))
376 , m_xBtnCancel(m_xBuilder
->weld_button("cancel"))
378 m_xBtnCancel
->connect_clicked(LINK(this, ActualizeProgress
, ClickCancelBtn
));
381 ActualizeProgress::~ActualizeProgress()
385 short ActualizeProgress::run()
387 pIdle
= new Idle("ActualizeProgressTimeout");
388 pIdle
->SetInvokeHandler( LINK( this, ActualizeProgress
, TimeoutHdl
) );
389 pIdle
->SetPriority( TaskPriority::LOWEST
);
392 return GenericDialogController::run();
395 IMPL_LINK_NOARG(ActualizeProgress
, ClickCancelBtn
, weld::Button
&, void)
397 pTheme
->AbortActualize();
398 m_xDialog
->response(RET_OK
);
401 IMPL_LINK( ActualizeProgress
, TimeoutHdl
, Timer
*, _pTimer
, void)
409 pTheme
->Actualize(LINK(this, ActualizeProgress
, ActualizeHdl
), &aStatusProgress
);
410 ClickCancelBtn(*m_xBtnCancel
);
413 IMPL_LINK( ActualizeProgress
, ActualizeHdl
, const INetURLObject
&, rURL
, void )
415 Application::Reschedule(true);
416 m_xFtActualizeFile
->set_label(GetReducedString(rURL
, 30));
419 TitleDialog::TitleDialog(weld::Window
* pParent
, const OUString
& rOldTitle
)
420 : GenericDialogController(pParent
, "cui/ui/gallerytitledialog.ui", "GalleryTitleDialog")
421 , m_xEdit(m_xBuilder
->weld_entry("entry"))
423 m_xEdit
->set_text(rOldTitle
);
424 m_xEdit
->grab_focus();
427 TitleDialog::~TitleDialog()
431 GalleryIdDialog::GalleryIdDialog(weld::Window
* pParent
, GalleryTheme
* _pThm
)
432 : GenericDialogController(pParent
, "cui/ui/gallerythemeiddialog.ui", "GalleryThemeIDDialog")
434 , m_xBtnOk(m_xBuilder
->weld_button("ok"))
435 , m_xLbResName(m_xBuilder
->weld_combo_box("entry"))
437 m_xLbResName
->append_text("!!! No Id !!!");
439 GalleryTheme::InsertAllThemes(*m_xLbResName
);
441 m_xLbResName
->set_active(m_pThm
->GetId());
442 m_xLbResName
->grab_focus();
444 m_xBtnOk
->connect_clicked(LINK(this, GalleryIdDialog
, ClickOkHdl
));
447 GalleryIdDialog::~GalleryIdDialog()
451 IMPL_LINK_NOARG(GalleryIdDialog
, ClickOkHdl
, weld::Button
&, void)
453 Gallery
* pGal
= m_pThm
->GetParent();
454 const sal_uLong nId
= GetId();
455 bool bDifferentThemeExists
= false;
457 for( sal_uLong i
= 0, nCount
= pGal
->GetThemeCount(); i
< nCount
&& !bDifferentThemeExists
; i
++ )
459 const GalleryThemeEntry
* pInfo
= pGal
->GetThemeInfo( i
);
461 if ((pInfo
->GetId() == nId
) && (pInfo
->GetThemeName() != m_pThm
->GetName()))
463 OUString aStr
= CuiResId( RID_SVXSTR_GALLERY_ID_EXISTS
) +
464 " (" + pInfo
->GetThemeName() + ")";
466 std::unique_ptr
<weld::MessageDialog
> xInfoBox(Application::CreateMessageDialog(m_xDialog
.get(),
467 VclMessageType::Info
, VclButtonsType::Ok
,
470 m_xLbResName
->grab_focus();
471 bDifferentThemeExists
= true;
475 if (!bDifferentThemeExists
)
476 m_xDialog
->response(RET_OK
);
479 GalleryThemeProperties::GalleryThemeProperties(weld::Window
* pParent
,
480 ExchangeData
* _pData
, SfxItemSet
const * pItemSet
)
481 : SfxTabDialogController(pParent
, "cui/ui/gallerythemedialog.ui",
482 "GalleryThemeDialog", pItemSet
)
485 AddTabPage("general", TPGalleryThemeGeneral::Create
, nullptr);
486 AddTabPage("files", TPGalleryThemeProperties::Create
, nullptr);
487 if (pData
->pTheme
->IsReadOnly())
488 RemoveTabPage("files");
490 OUString aText
= m_xDialog
->get_title().replaceFirst( "%1", pData
->pTheme
->GetName() );
492 if (pData
->pTheme
->IsReadOnly())
493 aText
+= " " + CuiResId( RID_SVXSTR_GALLERY_READONLY
);
495 m_xDialog
->set_title(aText
);
498 void GalleryThemeProperties::PageCreated(const OString
& rId
, SfxTabPage
&rPage
)
500 if (rId
== "general")
501 static_cast<TPGalleryThemeGeneral
&>( rPage
).SetXChgData( pData
);
503 static_cast<TPGalleryThemeProperties
&>( rPage
).SetXChgData( pData
);
506 TPGalleryThemeGeneral::TPGalleryThemeGeneral(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
507 : SfxTabPage(pPage
, pController
, "cui/ui/gallerygeneralpage.ui", "GalleryGeneralPage", &rSet
)
509 , m_xFiMSImage(m_xBuilder
->weld_image("image"))
510 , m_xEdtMSName(m_xBuilder
->weld_entry("name"))
511 , m_xFtMSShowType(m_xBuilder
->weld_label("type"))
512 , m_xFtMSShowPath(m_xBuilder
->weld_label("location"))
513 , m_xFtMSShowContent(m_xBuilder
->weld_label("contents"))
514 , m_xFtMSShowChangeDate(m_xBuilder
->weld_label("modified"))
518 void TPGalleryThemeGeneral::SetXChgData( ExchangeData
* _pData
)
522 GalleryTheme
* pThm
= pData
->pTheme
;
523 OUString
aOutStr( OUString::number(pThm
->GetObjectCount()) );
524 OUString
aObjStr( CuiResId( RID_SVXSTR_GALLERYPROPS_OBJECT
) );
526 OUString
aType( SvxResId( RID_SVXSTR_GALLERYPROPS_GALTHEME
) );
527 bool bReadOnly
= pThm
->IsReadOnly();
529 m_xEdtMSName
->set_text(pThm
->GetName());
530 m_xEdtMSName
->set_editable(!bReadOnly
);
531 m_xEdtMSName
->set_sensitive(!bReadOnly
);
533 if( pThm
->IsReadOnly() )
534 aType
+= CuiResId( RID_SVXSTR_GALLERY_READONLY
);
536 m_xFtMSShowType
->set_label(aType
);
537 m_xFtMSShowPath
->set_label(pThm
->GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::Unambiguous
));
539 // singular or plural?
540 if ( 1 == pThm
->GetObjectCount() )
541 aObjStr
= aObjStr
.getToken( 0, ';' );
543 aObjStr
= aObjStr
.getToken( 1, ';' );
545 aOutStr
+= " " + aObjStr
;
547 m_xFtMSShowContent
->set_label(aOutStr
);
549 // get locale wrapper (singleton)
550 const SvtSysLocale aSysLocale
;
551 const LocaleDataWrapper
& aLocaleData
= aSysLocale
.GetLocaleData();
554 aAccess
= aLocaleData
.getDate( pData
->aThemeChangeDate
) + ", " + aLocaleData
.getTime( pData
->aThemeChangeTime
);
555 m_xFtMSShowChangeDate
->set_label(aAccess
);
560 if( pThm
->IsReadOnly() )
561 sId
= RID_SVXBMP_THEME_READONLY_BIG
;
562 else if( pThm
->IsDefault() )
563 sId
= RID_SVXBMP_THEME_DEFAULT_BIG
;
565 sId
= RID_SVXBMP_THEME_NORMAL_BIG
;
567 m_xFiMSImage
->set_from_icon_name(sId
);
570 bool TPGalleryThemeGeneral::FillItemSet( SfxItemSet
* /*rSet*/ )
572 pData
->aEditedTitle
= m_xEdtMSName
->get_text();
576 std::unique_ptr
<SfxTabPage
> TPGalleryThemeGeneral::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
578 return std::make_unique
<TPGalleryThemeGeneral
>(pPage
, pController
, *rSet
);
581 TPGalleryThemeProperties::TPGalleryThemeProperties(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
582 : SfxTabPage(pPage
, pController
, "cui/ui/galleryfilespage.ui", "GalleryFilesPage", &rSet
)
584 , bEntriesFound(false)
585 , bInputAllowed(true)
587 , bSearchRecursive(false)
588 , xDialogListener(new ::svt::DialogClosedListener())
589 , m_xCbbFileType(m_xBuilder
->weld_combo_box("filetype"))
590 , m_xLbxFound(m_xBuilder
->weld_tree_view("files"))
591 , m_xBtnSearch(m_xBuilder
->weld_button("findfiles"))
592 , m_xBtnTake(m_xBuilder
->weld_button("add"))
593 , m_xBtnTakeAll(m_xBuilder
->weld_button("addall"))
594 , m_xCbxPreview(m_xBuilder
->weld_check_button("preview"))
595 , m_xWndPreview(new weld::CustomWeld(*m_xBuilder
, "image", m_aWndPreview
))
597 m_xLbxFound
->set_size_request(m_xLbxFound
->get_approximate_digit_width() * 35,
598 m_xLbxFound
->get_height_rows(15));
599 m_xLbxFound
->set_selection_mode(SelectionMode::Multiple
);
600 xDialogListener
->SetDialogClosedLink( LINK( this, TPGalleryThemeProperties
, DialogClosedHdl
) );
603 void TPGalleryThemeProperties::SetXChgData( ExchangeData
* _pData
)
607 aPreviewTimer
.SetInvokeHandler( LINK( this, TPGalleryThemeProperties
, PreviewTimerHdl
) );
608 aPreviewTimer
.SetTimeout( 500 );
609 m_xBtnSearch
->connect_clicked(LINK(this, TPGalleryThemeProperties
, ClickSearchHdl
));
610 m_xBtnTake
->connect_clicked(LINK(this, TPGalleryThemeProperties
, ClickTakeHdl
));
611 m_xBtnTakeAll
->connect_clicked(LINK(this, TPGalleryThemeProperties
, ClickTakeAllHdl
));
612 m_xCbxPreview
->connect_toggled(LINK(this, TPGalleryThemeProperties
, ClickPreviewHdl
));
613 m_xCbbFileType
->connect_changed(LINK(this, TPGalleryThemeProperties
, SelectFileTypeHdl
));
614 m_xLbxFound
->connect_row_activated(LINK(this, TPGalleryThemeProperties
, DClickFoundHdl
));
615 m_xLbxFound
->connect_changed(LINK(this, TPGalleryThemeProperties
, SelectFoundHdl
));
616 m_xLbxFound
->append_text(CuiResId(RID_SVXSTR_GALLERY_NOFILES
));
621 m_xBtnTake
->set_sensitive(true);
622 m_xBtnTakeAll
->set_sensitive(false);
623 m_xCbxPreview
->set_sensitive(false);
626 void TPGalleryThemeProperties::StartSearchFiles( const OUString
& _rFolderURL
, short _nDlgResult
)
628 if ( RET_OK
== _nDlgResult
)
630 aURL
= INetURLObject( _rFolderURL
);
631 bSearchRecursive
= true; // UI choice no longer possible, windows file picker allows no user controls
636 TPGalleryThemeProperties::~TPGalleryThemeProperties()
638 xMediaPlayer
.clear();
639 xDialogListener
.clear();
640 aFilterEntryList
.clear();
643 std::unique_ptr
<SfxTabPage
> TPGalleryThemeProperties::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
645 return std::make_unique
<TPGalleryThemeProperties
>(pPage
, pController
, *rSet
);
648 OUString
TPGalleryThemeProperties::addExtension( const OUString
& _rDisplayText
, const OUString
& _rExtension
)
650 OUString sRet
= _rDisplayText
;
651 if ( sRet
.indexOf( "(*.*)" ) == -1 )
653 sRet
+= " (" + _rExtension
+ ")";
658 void TPGalleryThemeProperties::FillFilterList()
660 GraphicFilter
&rFilter
= GraphicFilter::GetGraphicFilter();
663 sal_uInt16 i
, nKeyCount
;
666 for( i
= 0, nKeyCount
= rFilter
.GetImportFormatCount(); i
< nKeyCount
; i
++ )
668 aExt
= rFilter
.GetImportFormatShortName( i
);
669 aName
= rFilter
.GetImportFormatName( i
);
670 size_t entryIndex
= 0;
671 FilterEntry
* pTestEntry
= aFilterEntryList
.empty() ? nullptr : aFilterEntryList
[ entryIndex
].get();
672 bool bInList
= false;
674 OUString aExtensions
;
679 sWildcard
= rFilter
.GetImportWildcard( i
, j
++ );
680 if ( sWildcard
.isEmpty() )
682 if ( aExtensions
.indexOf( sWildcard
) == -1 )
684 if ( !aExtensions
.isEmpty() )
686 aExtensions
+= sWildcard
;
689 aName
= addExtension( aName
, aExtensions
);
693 if ( pTestEntry
->aFilterName
== aExt
)
698 pTestEntry
= ( ++entryIndex
< aFilterEntryList
.size() )
699 ? aFilterEntryList
[ entryIndex
].get() : nullptr;
703 std::unique_ptr
<FilterEntry
> pFilterEntry(new FilterEntry
);
704 pFilterEntry
->aFilterName
= aExt
;
705 m_xCbbFileType
->append_text(aName
);
706 aFilterEntryList
.push_back(std::move(pFilterEntry
));
710 #if HAVE_FEATURE_AVMEDIA
712 static const char aWildcard
[] = "*.";
713 ::avmedia::FilterNameVector aFilters
= ::avmedia::MediaWindow::getMediaFilters();
715 for(const std::pair
<OUString
,OUString
> & aFilter
: aFilters
)
717 for( sal_Int32 nIndex
= 0; nIndex
>= 0; )
719 OUString
aFilterWildcard( aWildcard
);
721 std::unique_ptr
<FilterEntry
> pFilterEntry(new FilterEntry
);
722 pFilterEntry
->aFilterName
= aFilter
.second
.getToken( 0, ';', nIndex
);
723 aFilterWildcard
+= pFilterEntry
->aFilterName
;
724 m_xCbbFileType
->append_text(addExtension(aFilter
.first
, aFilterWildcard
));
725 aFilterEntryList
.push_back( std::move(pFilterEntry
) );
731 OUString aExtensions
;
734 for ( i
= 0; i
< nKeyCount
; ++i
)
740 sWildcard
= rFilter
.GetImportWildcard( i
, j
++ );
741 if ( sWildcard
.isEmpty() )
743 if ( aExtensions
.indexOf( sWildcard
) == -1 )
745 if ( !aExtensions
.isEmpty() )
748 aExtensions
+= sWildcard
;
753 #if HAVE_FEATURE_AVMEDIA
755 for(const std::pair
<OUString
,OUString
> & aFilter
: aFilters
)
757 for( sal_Int32 nIndex
= 0; nIndex
>= 0; )
759 if ( !aExtensions
.isEmpty() )
761 aExtensions
+= aWildcard
+ aFilter
.second
.getToken( 0, ';', nIndex
);
767 if (aExtensions
.getLength() > 240)
771 std::unique_ptr
<FilterEntry
> pFilterEntry(new FilterEntry
);
772 pFilterEntry
->aFilterName
= CuiResId(RID_SVXSTR_GALLERY_ALLFILES
);
773 pFilterEntry
->aFilterName
= addExtension(pFilterEntry
->aFilterName
, aExtensions
);
774 m_xCbbFileType
->insert_text(0, pFilterEntry
->aFilterName
);
775 m_xCbbFileType
->set_active(0);
776 aFilterEntryList
.insert(aFilterEntryList
.begin(), std::move(pFilterEntry
));
779 IMPL_LINK_NOARG(TPGalleryThemeProperties
, SelectFileTypeHdl
, weld::ComboBox
&, void)
781 OUString
aText(m_xCbbFileType
->get_active_text());
783 if( bInputAllowed
&& ( aLastFilterName
!= aText
) )
785 aLastFilterName
= aText
;
787 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryupdategalleryfilelistdialog.ui"));
788 std::unique_ptr
<weld::MessageDialog
> xQuery(xBuilder
->weld_message_dialog("QueryUpdateFileListDialog"));
789 if (xQuery
->run() == RET_YES
)
794 void TPGalleryThemeProperties::SearchFiles()
796 std::shared_ptr
<SearchProgress
> xProgress(new SearchProgress(GetFrameWeld(), this, aURL
));
799 m_xLbxFound
->clear();
801 xProgress
->SetFileType( m_xCbbFileType
->get_active_text() );
802 xProgress
->SetDirectory( INetURLObject() );
804 xProgress
->LaunchThread();
805 weld::DialogController::runAsync(xProgress
, [this](sal_Int32 nResult
) {
806 EndSearchProgressHdl(nResult
);
810 IMPL_LINK_NOARG(TPGalleryThemeProperties
, ClickSearchHdl
, weld::Button
&, void)
816 // setup folder picker
817 css::uno::Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
818 xFolderPicker
= FolderPicker::create(xContext
);
820 OUString
aDlgPathName( SvtPathOptions().GetGraphicPath() );
821 xFolderPicker
->setDisplayDirectory(aDlgPathName
);
823 aPreviewTimer
.Stop();
825 css::uno::Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
826 if ( xAsyncDlg
.is() )
827 xAsyncDlg
->startExecuteModal( xDialogListener
.get() );
830 if( xFolderPicker
->execute() == RET_OK
)
832 aURL
= INetURLObject( xFolderPicker
->getDirectory() );
833 bSearchRecursive
= true; // UI choice no longer possible, windows file picker allows no user controls
838 catch (const IllegalArgumentException
&)
840 OSL_FAIL( "Folder picker failed with illegal arguments" );
845 void TPGalleryThemeProperties::TakeFiles()
847 if (m_xLbxFound
->count_selected_rows() || (bTakeAll
&& bEntriesFound
))
849 std::shared_ptr
<TakeProgress
> xTakeProgress(new TakeProgress(GetFrameWeld(), this));
850 xTakeProgress
->LaunchThread();
851 weld::DialogController::runAsync(xTakeProgress
, [=](sal_Int32
/*nResult*/) {
852 /* no postprocessing needed, pTakeProgress
853 will be disposed in TakeProgress::CleanupHdl */
859 IMPL_LINK_NOARG(TPGalleryThemeProperties
, ClickPreviewHdl
, weld::ToggleButton
&, void)
863 aPreviewTimer
.Stop();
864 aPreviewString
.clear();
866 if (!m_xCbxPreview
->get_active())
868 xMediaPlayer
.clear();
869 m_aWndPreview
.SetGraphic(Graphic());
870 m_aWndPreview
.Invalidate();
877 void TPGalleryThemeProperties::DoPreview()
879 int nIndex
= m_xLbxFound
->get_selected_index();
880 OUString
aString(m_xLbxFound
->get_text(nIndex
));
882 if (aString
!= aPreviewString
)
884 INetURLObject
_aURL(aFoundList
[nIndex
]);
885 bInputAllowed
= false;
887 if (!m_aWndPreview
.SetGraphic(_aURL
))
889 weld::WaitObject
aWaitObject(GetFrameWeld());
890 ErrorHandler::HandleError(ERRCODE_IO_NOTEXISTSPATH
, GetFrameWeld());
892 #if HAVE_FEATURE_AVMEDIA
893 else if( ::avmedia::MediaWindow::isMediaURL( _aURL
.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous
), "" ) )
895 xMediaPlayer
= ::avmedia::MediaWindow::createPlayer( _aURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), "" );
896 if( xMediaPlayer
.is() )
897 xMediaPlayer
->start();
900 bInputAllowed
= true;
901 aPreviewString
= aString
;
905 IMPL_LINK_NOARG(TPGalleryThemeProperties
, ClickTakeHdl
, weld::Button
&, void)
909 aPreviewTimer
.Stop();
911 if (!m_xLbxFound
->count_selected_rows() || !bEntriesFound
)
913 SvxOpenGraphicDialog
aDlg(CuiResId(RID_SVXSTR_KEY_GALLERY_DIR
), GetFrameWeld());
914 aDlg
.EnableLink(false);
917 if( !aDlg
.Execute() )
918 pData
->pTheme
->InsertURL( INetURLObject( aDlg
.GetPath() ) );
928 IMPL_LINK_NOARG(TPGalleryThemeProperties
, ClickTakeAllHdl
, weld::Button
&, void)
932 aPreviewTimer
.Stop();
938 IMPL_LINK_NOARG(TPGalleryThemeProperties
, SelectFoundHdl
, weld::TreeView
&, void)
942 bool bPreviewPossible
= false;
944 aPreviewTimer
.Stop();
948 if (m_xLbxFound
->count_selected_rows() == 1)
950 m_xCbxPreview
->set_sensitive(true);
951 bPreviewPossible
= true;
954 m_xCbxPreview
->set_sensitive(false);
956 if( !aFoundList
.empty() )
957 m_xBtnTakeAll
->set_sensitive(true);
959 m_xBtnTakeAll
->set_sensitive(false);
962 if (bPreviewPossible
&& m_xCbxPreview
->get_active())
963 aPreviewTimer
.Start();
967 IMPL_LINK_NOARG(TPGalleryThemeProperties
, DClickFoundHdl
, weld::TreeView
&, bool)
971 aPreviewTimer
.Stop();
973 if (m_xLbxFound
->count_selected_rows() == 1 && bEntriesFound
)
974 ClickTakeHdl(*m_xBtnTake
);
979 IMPL_LINK_NOARG(TPGalleryThemeProperties
, PreviewTimerHdl
, Timer
*, void)
981 aPreviewTimer
.Stop();
985 void TPGalleryThemeProperties::EndSearchProgressHdl(sal_Int32
/*nResult*/)
987 if( !aFoundList
.empty() )
989 m_xLbxFound
->select(0);
990 m_xBtnTakeAll
->set_sensitive(true);
991 m_xCbxPreview
->set_sensitive(true);
992 bEntriesFound
= true;
996 m_xLbxFound
->append_text(CuiResId(RID_SVXSTR_GALLERY_NOFILES
));
997 m_xBtnTakeAll
->set_sensitive(false);
998 m_xCbxPreview
->set_sensitive(false);
999 bEntriesFound
= false;
1003 IMPL_LINK( TPGalleryThemeProperties
, DialogClosedHdl
, css::ui::dialogs::DialogClosedEvent
*, pEvt
, void )
1005 DBG_ASSERT( xFolderPicker
.is(), "TPGalleryThemeProperties::DialogClosedHdl(): no folder picker" );
1007 OUString sURL
= xFolderPicker
->getDirectory();
1008 StartSearchFiles( sURL
, pEvt
->DialogResult
);
1011 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */