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>
28 #include <vcl/errinf.hxx>
29 #include <ucbhelper/content.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/weld.hxx>
32 #include <avmedia/mediawindow.hxx>
33 #include <unotools/pathoptions.hxx>
34 #include <sfx2/filedlghelper.hxx>
35 #include <sfx2/opengrf.hxx>
36 #include <vcl/graphicfilter.hxx>
37 #include <svx/gallery1.hxx>
38 #include <svx/galtheme.hxx>
39 #include <cuigaldlg.hxx>
40 #include <bitmaps.hlst>
41 #include <unotools/localedatawrapper.hxx>
42 #include <unotools/syslocale.hxx>
43 #include <com/sun/star/uno/Reference.hxx>
44 #include <com/sun/star/lang/IllegalArgumentException.hpp>
45 #include <comphelper/processfactory.hxx>
46 #include <com/sun/star/sdbc/XResultSet.hpp>
47 #include <com/sun/star/sdbc/XRow.hpp>
48 #include <com/sun/star/ucb/ContentCreationException.hpp>
49 #include <com/sun/star/ucb/XContentAccess.hpp>
50 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
51 #include <dialmgr.hxx>
52 #include <strings.hrc>
53 #include <svx/dialmgr.hxx>
54 #include <svx/strings.hrc>
55 #include <osl/diagnose.h>
56 #include <o3tl/string_view.hxx>
58 using namespace ::ucbhelper
;
59 using namespace ::cppu
;
60 using namespace ::com::sun::star::lang
;
61 using namespace ::com::sun::star::sdbc
;
62 using namespace ::com::sun::star::ucb
;
63 using namespace ::com::sun::star::ui::dialogs
;
64 using namespace ::com::sun::star::uno
;
67 SearchThread::SearchThread(SearchProgress
* pProgress
,
68 TPGalleryThemeProperties
* pBrowser
,
69 INetURLObject aStartURL
)
70 : Thread("cuiSearchThread")
71 , mpProgress(pProgress
)
73 , maStartURL(std::move(aStartURL
))
77 SearchThread::~SearchThread()
81 void SearchThread::execute()
83 const OUString
aFileType(mpBrowser
->m_xCbbFileType
->get_active_text());
85 if (!aFileType
.isEmpty())
87 const int nFileNumber
= mpBrowser
->m_xCbbFileType
->find_text(aFileType
);
88 sal_Int32 nBeginFormat
, nEndFormat
;
89 std::vector
< OUString
> aFormats
;
91 if( !nFileNumber
|| nFileNumber
== -1)
94 nEndFormat
= mpBrowser
->m_xCbbFileType
->get_count() - 1;
97 nBeginFormat
= nEndFormat
= nFileNumber
;
99 for (sal_Int32 i
= nBeginFormat
; i
<= nEndFormat
; ++i
)
100 aFormats
.push_back( mpBrowser
->aFilterEntryList
[ i
]->aFilterName
.toAsciiLowerCase() );
102 ImplSearch( maStartURL
, aFormats
, mpBrowser
->bSearchRecursive
);
105 Application::PostUserEvent(LINK(mpProgress
, SearchProgress
, CleanUpHdl
));
109 void SearchThread::ImplSearch( const INetURLObject
& rStartURL
,
110 const std::vector
< OUString
>& rFormats
,
114 SolarMutexGuard aGuard
;
116 mpProgress
->SetDirectory( rStartURL
);
121 css::uno::Reference
< XCommandEnvironment
> xEnv
;
122 Content
aCnt( rStartURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), xEnv
, comphelper::getProcessComponentContext() );
123 Sequence
< OUString
> aProps( 2 );
125 aProps
.getArray()[ 0 ] = "IsFolder";
126 aProps
.getArray()[ 1 ] = "IsDocument";
127 css::uno::Reference
< XResultSet
> xResultSet(
128 aCnt
.createCursor( aProps
) );
130 if( xResultSet
.is() )
132 css::uno::Reference
< XContentAccess
> xContentAccess( xResultSet
, UNO_QUERY_THROW
);
133 css::uno::Reference
< XRow
> xRow( xResultSet
, UNO_QUERY_THROW
);
135 while( xResultSet
->next() && schedule() )
137 INetURLObject
aFoundURL( xContentAccess
->queryContentIdentifierString() );
138 DBG_ASSERT( aFoundURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
140 bool bFolder
= xRow
->getBoolean( 1 ); // property "IsFolder"
141 if ( xRow
->wasNull() )
144 if( bRecursive
&& bFolder
)
145 ImplSearch( aFoundURL
, rFormats
, true );
148 bool bDocument
= xRow
->getBoolean( 2 ); // property "IsDocument"
149 if ( xRow
->wasNull() )
154 GraphicDescriptor
aDesc( aFoundURL
);
156 if( ( aDesc
.Detect() &&
157 std::find( rFormats
.begin(),
159 GraphicDescriptor::GetImportFormatShortName(
160 aDesc
.GetFileFormat() ).toAsciiLowerCase() )
161 != rFormats
.end() ) ||
162 std::find( rFormats
.begin(),
164 aFoundURL
.GetFileExtension().toAsciiLowerCase())
167 SolarMutexGuard aGuard
;
169 mpBrowser
->aFoundList
.push_back(
170 aFoundURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
)
172 mpBrowser
->m_xLbxFound
->insert_text(
173 mpBrowser
->aFoundList
.size() - 1,
174 GetReducedString(aFoundURL
, 50));
181 catch (const ContentCreationException
&)
184 catch (const css::uno::RuntimeException
&)
187 catch (const css::uno::Exception
&)
192 SearchProgress::SearchProgress(weld::Window
* pParent
, TPGalleryThemeProperties
* pTabPage
, INetURLObject aStartURL
)
193 : GenericDialogController(pParent
, "cui/ui/gallerysearchprogress.ui", "GallerySearchProgress")
194 , startUrl_(std::move(aStartURL
))
195 , m_pTabPage(pTabPage
)
196 , m_xFtSearchDir(m_xBuilder
->weld_label("dir"))
197 , m_xFtSearchType(m_xBuilder
->weld_label("file"))
198 , m_xBtnCancel(m_xBuilder
->weld_button("cancel"))
200 m_xFtSearchType
->set_size_request(m_xFtSearchType
->get_preferred_size().Width(), -1);
201 m_xBtnCancel
->connect_clicked(LINK(this, SearchProgress
, ClickCancelBtn
));
204 SearchProgress::~SearchProgress()
208 IMPL_LINK_NOARG(SearchProgress
, ClickCancelBtn
, weld::Button
&, void)
210 if (m_aSearchThread
.is())
211 m_aSearchThread
->terminate();
214 IMPL_LINK_NOARG(SearchProgress
, CleanUpHdl
, void*, void)
216 if (m_aSearchThread
.is())
217 m_aSearchThread
->join();
219 m_xDialog
->response(RET_OK
);
222 void SearchProgress::LaunchThread()
224 assert(!m_aSearchThread
.is());
225 m_aSearchThread
= new SearchThread(this, m_pTabPage
, startUrl_
);
226 m_aSearchThread
->launch();
229 TakeThread::TakeThread(
230 TakeProgress
* pProgress
,
231 TPGalleryThemeProperties
* pBrowser
,
232 TokenList_impl
& rTakenList
234 Thread ( "cuiTakeThread" ),
235 mpProgress ( pProgress
),
236 mpBrowser ( pBrowser
),
237 mrTakenList ( rTakenList
)
242 TakeThread::~TakeThread()
246 void TakeThread::execute()
249 GalleryTheme
* pThm
= mpBrowser
->GetXChgData()->pTheme
;
250 std::unique_ptr
<GalleryProgress
> pStatusProgress
;
252 std::vector
<int> aSelectedRows
;
255 SolarMutexGuard aGuard
;
256 pStatusProgress
.reset(new GalleryProgress
);
257 if (mpBrowser
->bTakeAll
)
258 nEntries
= mpBrowser
->m_xLbxFound
->n_children();
261 aSelectedRows
= mpBrowser
->m_xLbxFound
->get_selected_rows();
262 nEntries
= aSelectedRows
.size();
264 pThm
->LockBroadcaster();
267 for( sal_Int32 i
= 0; i
< nEntries
&& schedule(); ++i
)
269 const sal_Int32 nPos
= mpBrowser
->bTakeAll
? i
: aSelectedRows
[i
];
270 const INetURLObject
aURL( mpBrowser
->aFoundList
[ nPos
]);
272 mrTakenList
.push_back( nPos
);
275 SolarMutexGuard aGuard
;
277 mpProgress
->SetFile( aURL
);
278 pStatusProgress
->Update( i
, nEntries
- 1 );
279 pThm
->InsertURL( aURL
);
284 SolarMutexGuard aGuard
;
286 pThm
->UnlockBroadcaster();
287 pStatusProgress
.reset();
290 Application::PostUserEvent(LINK(mpProgress
, TakeProgress
, CleanUpHdl
));
293 TakeProgress::TakeProgress(weld::Window
* pParent
, TPGalleryThemeProperties
* pTabPage
)
294 : GenericDialogController(pParent
, "cui/ui/galleryapplyprogress.ui",
295 "GalleryApplyProgress")
297 , m_pTabPage(pTabPage
)
298 , m_xFtTakeFile(m_xBuilder
->weld_label("file"))
299 , m_xBtnCancel(m_xBuilder
->weld_button("cancel"))
301 m_xBtnCancel
->connect_clicked(LINK(this, TakeProgress
, ClickCancelBtn
));
304 TakeProgress::~TakeProgress()
308 IMPL_LINK_NOARG(TakeProgress
, ClickCancelBtn
, weld::Button
&, void)
310 if (maTakeThread
.is())
311 maTakeThread
->terminate();
315 IMPL_LINK_NOARG(TakeProgress
, CleanUpHdl
, void*, void)
317 if (maTakeThread
.is())
318 maTakeThread
->join();
320 std::vector
<bool, std::allocator
<bool> > aRemoveEntries(m_pTabPage
->aFoundList
.size(), false);
321 std::vector
< OUString
> aRemainingVector
;
322 sal_uInt32 i
, nCount
;
324 std::unique_ptr
<weld::WaitObject
> xWait(new weld::WaitObject(m_pParent
));
326 m_pTabPage
->m_xLbxFound
->select(-1);
327 m_pTabPage
->m_xLbxFound
->freeze();
329 // mark all taken positions in aRemoveEntries
330 for( i
= 0, nCount
= maTakenList
.size(); i
< nCount
; ++i
)
331 aRemoveEntries
[ maTakenList
[ i
] ] = true;
335 for( i
= 0, nCount
= aRemoveEntries
.size(); i
< nCount
; ++i
)
336 if( !aRemoveEntries
[ i
] )
337 aRemainingVector
.push_back( m_pTabPage
->aFoundList
[i
] );
339 std::swap(m_pTabPage
->aFoundList
, aRemainingVector
);
340 aRemainingVector
.clear();
343 for( i
= 0, nCount
= aRemoveEntries
.size(); i
< nCount
; ++i
)
344 if( !aRemoveEntries
[ i
] )
345 aRemainingVector
.push_back(m_pTabPage
->m_xLbxFound
->get_text(i
));
347 m_pTabPage
->m_xLbxFound
->clear();
348 for( i
= 0, nCount
= aRemainingVector
.size(); i
< nCount
; ++i
)
349 m_pTabPage
->m_xLbxFound
->append_text(aRemainingVector
[i
]);
350 aRemainingVector
.clear();
352 m_pTabPage
->m_xLbxFound
->thaw();
353 m_pTabPage
->SelectFoundHdl( *m_pTabPage
->m_xLbxFound
);
357 m_xDialog
->response(RET_OK
);
360 void TakeProgress::LaunchThread()
362 assert(!maTakeThread
.is());
363 maTakeThread
= new TakeThread(this, m_pTabPage
, maTakenList
);
364 maTakeThread
->launch();
367 ActualizeProgress::ActualizeProgress(weld::Widget
* pWindow
, GalleryTheme
* pThm
)
368 : GenericDialogController(pWindow
, "cui/ui/galleryupdateprogress.ui",
369 "GalleryUpdateProgress")
372 , m_xFtActualizeFile(m_xBuilder
->weld_label("file"))
373 , m_xBtnCancel(m_xBuilder
->weld_button("cancel"))
375 m_xBtnCancel
->connect_clicked(LINK(this, ActualizeProgress
, ClickCancelBtn
));
378 ActualizeProgress::~ActualizeProgress()
382 short ActualizeProgress::run()
384 pIdle
= new Idle("ActualizeProgressTimeout");
385 pIdle
->SetInvokeHandler( LINK( this, ActualizeProgress
, TimeoutHdl
) );
386 pIdle
->SetPriority( TaskPriority::LOWEST
);
389 return GenericDialogController::run();
392 IMPL_LINK_NOARG(ActualizeProgress
, ClickCancelBtn
, weld::Button
&, void)
394 pTheme
->AbortActualize();
395 m_xDialog
->response(RET_OK
);
398 IMPL_LINK( ActualizeProgress
, TimeoutHdl
, Timer
*, _pTimer
, void)
406 pTheme
->Actualize(LINK(this, ActualizeProgress
, ActualizeHdl
), &aStatusProgress
);
407 ClickCancelBtn(*m_xBtnCancel
);
410 IMPL_LINK( ActualizeProgress
, ActualizeHdl
, const INetURLObject
&, rURL
, void )
412 Application::Reschedule(true);
413 m_xFtActualizeFile
->set_label(GetReducedString(rURL
, 30));
416 TitleDialog::TitleDialog(weld::Widget
* pParent
, const OUString
& rOldTitle
)
417 : GenericDialogController(pParent
, "cui/ui/gallerytitledialog.ui", "GalleryTitleDialog")
418 , m_xEdit(m_xBuilder
->weld_entry("entry"))
420 m_xEdit
->set_text(rOldTitle
);
421 m_xEdit
->grab_focus();
424 TitleDialog::~TitleDialog()
428 GalleryIdDialog::GalleryIdDialog(weld::Widget
* pParent
, GalleryTheme
* _pThm
)
429 : GenericDialogController(pParent
, "cui/ui/gallerythemeiddialog.ui", "GalleryThemeIDDialog")
431 , m_xBtnOk(m_xBuilder
->weld_button("ok"))
432 , m_xLbResName(m_xBuilder
->weld_combo_box("entry"))
434 m_xLbResName
->append_text("!!! No Id !!!");
436 GalleryTheme::InsertAllThemes(*m_xLbResName
);
438 m_xLbResName
->set_active(m_pThm
->GetId());
439 m_xLbResName
->grab_focus();
441 m_xBtnOk
->connect_clicked(LINK(this, GalleryIdDialog
, ClickOkHdl
));
444 GalleryIdDialog::~GalleryIdDialog()
448 IMPL_LINK_NOARG(GalleryIdDialog
, ClickOkHdl
, weld::Button
&, void)
450 Gallery
* pGal
= m_pThm
->GetParent();
451 const sal_uInt32 nId
= GetId();
452 bool bDifferentThemeExists
= false;
454 for( size_t i
= 0, nCount
= pGal
->GetThemeCount(); i
< nCount
&& !bDifferentThemeExists
; i
++ )
456 const GalleryThemeEntry
* pInfo
= pGal
->GetThemeInfo( i
);
458 if ((pInfo
->GetId() == nId
) && (pInfo
->GetThemeName() != m_pThm
->GetName()))
460 OUString aStr
= CuiResId( RID_CUISTR_GALLERY_ID_EXISTS
) +
461 " (" + pInfo
->GetThemeName() + ")";
463 std::unique_ptr
<weld::MessageDialog
> xInfoBox(Application::CreateMessageDialog(m_xDialog
.get(),
464 VclMessageType::Info
, VclButtonsType::Ok
,
467 m_xLbResName
->grab_focus();
468 bDifferentThemeExists
= true;
472 if (!bDifferentThemeExists
)
473 m_xDialog
->response(RET_OK
);
476 GalleryThemeProperties::GalleryThemeProperties(weld::Widget
* pParent
,
477 ExchangeData
* _pData
, SfxItemSet
const * pItemSet
)
478 : SfxTabDialogController(pParent
, "cui/ui/gallerythemedialog.ui",
479 "GalleryThemeDialog", pItemSet
)
482 AddTabPage("general", TPGalleryThemeGeneral::Create
, nullptr);
483 AddTabPage("files", TPGalleryThemeProperties::Create
, nullptr);
484 if (pData
->pTheme
->IsReadOnly())
485 RemoveTabPage("files");
487 OUString aText
= m_xDialog
->get_title().replaceFirst( "%1", pData
->pTheme
->GetName() );
489 if (pData
->pTheme
->IsReadOnly())
490 aText
+= " " + CuiResId( RID_CUISTR_GALLERY_READONLY
);
492 m_xDialog
->set_title(aText
);
495 void GalleryThemeProperties::PageCreated(const OUString
& rId
, SfxTabPage
&rPage
)
497 if (rId
== "general")
498 static_cast<TPGalleryThemeGeneral
&>( rPage
).SetXChgData( pData
);
500 static_cast<TPGalleryThemeProperties
&>( rPage
).SetXChgData( pData
);
503 TPGalleryThemeGeneral::TPGalleryThemeGeneral(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
504 : SfxTabPage(pPage
, pController
, "cui/ui/gallerygeneralpage.ui", "GalleryGeneralPage", &rSet
)
506 , m_xFiMSImage(m_xBuilder
->weld_image("image"))
507 , m_xEdtMSName(m_xBuilder
->weld_entry("name"))
508 , m_xFtMSShowType(m_xBuilder
->weld_label("type"))
509 , m_xFtMSShowPath(m_xBuilder
->weld_label("location"))
510 , m_xFtMSShowContent(m_xBuilder
->weld_label("contents"))
511 , m_xFtMSShowChangeDate(m_xBuilder
->weld_label("modified"))
515 void TPGalleryThemeGeneral::SetXChgData( ExchangeData
* _pData
)
519 GalleryTheme
* pThm
= pData
->pTheme
;
520 OUString
aOutStr( OUString::number(pThm
->GetObjectCount()) );
521 OUString
aObjStr( CuiResId( RID_CUISTR_GALLERYPROPS_OBJECT
) );
523 OUString
aType( SvxResId( RID_SVXSTR_GALLERYPROPS_GALTHEME
) );
524 bool bReadOnly
= pThm
->IsReadOnly();
526 m_xEdtMSName
->set_text(pThm
->GetName());
527 m_xEdtMSName
->set_editable(!bReadOnly
);
528 m_xEdtMSName
->set_sensitive(!bReadOnly
);
530 if( pThm
->IsReadOnly() )
531 aType
+= CuiResId( RID_CUISTR_GALLERY_READONLY
);
533 m_xFtMSShowType
->set_label(aType
);
534 m_xFtMSShowPath
->set_label(pThm
->getThemeURL().GetMainURL(INetURLObject::DecodeMechanism::Unambiguous
));
536 // singular or plural?
537 if ( 1 == pThm
->GetObjectCount() )
538 aObjStr
= aObjStr
.getToken( 0, ';' );
540 aObjStr
= aObjStr
.getToken( 1, ';' );
542 aOutStr
+= " " + aObjStr
;
544 m_xFtMSShowContent
->set_label(aOutStr
);
546 // get locale wrapper (singleton)
547 const SvtSysLocale aSysLocale
;
548 const LocaleDataWrapper
& aLocaleData
= aSysLocale
.GetLocaleData();
551 aAccess
= aLocaleData
.getDate( pData
->aThemeChangeDate
) + ", " + aLocaleData
.getTime( pData
->aThemeChangeTime
);
552 m_xFtMSShowChangeDate
->set_label(aAccess
);
557 if( pThm
->IsReadOnly() )
558 sId
= RID_SVXBMP_THEME_READONLY_BIG
;
559 else if( pThm
->IsDefault() )
560 sId
= RID_SVXBMP_THEME_DEFAULT_BIG
;
562 sId
= RID_SVXBMP_THEME_NORMAL_BIG
;
564 m_xFiMSImage
->set_from_icon_name(sId
);
567 bool TPGalleryThemeGeneral::FillItemSet( SfxItemSet
* /*rSet*/ )
569 pData
->aEditedTitle
= m_xEdtMSName
->get_text();
573 std::unique_ptr
<SfxTabPage
> TPGalleryThemeGeneral::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
575 return std::make_unique
<TPGalleryThemeGeneral
>(pPage
, pController
, *rSet
);
578 TPGalleryThemeProperties::TPGalleryThemeProperties(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
579 : SfxTabPage(pPage
, pController
, "cui/ui/galleryfilespage.ui", "GalleryFilesPage", &rSet
)
581 , aPreviewTimer("cui TPGalleryThemeProperties aPreviewTimer")
582 , bEntriesFound(false)
583 , bInputAllowed(true)
585 , bSearchRecursive(false)
586 , xDialogListener(new ::svt::DialogClosedListener())
587 , m_xCbbFileType(m_xBuilder
->weld_combo_box("filetype"))
588 , m_xLbxFound(m_xBuilder
->weld_tree_view("files"))
589 , m_xBtnSearch(m_xBuilder
->weld_button("findfiles"))
590 , m_xBtnTake(m_xBuilder
->weld_button("add"))
591 , m_xBtnTakeAll(m_xBuilder
->weld_button("addall"))
592 , m_xCbxPreview(m_xBuilder
->weld_check_button("preview"))
593 , m_xWndPreview(new weld::CustomWeld(*m_xBuilder
, "image", m_aWndPreview
))
595 m_xLbxFound
->set_size_request(m_xLbxFound
->get_approximate_digit_width() * 35,
596 m_xLbxFound
->get_height_rows(15));
597 m_xLbxFound
->set_selection_mode(SelectionMode::Multiple
);
598 xDialogListener
->SetDialogClosedLink( LINK( this, TPGalleryThemeProperties
, DialogClosedHdl
) );
601 void TPGalleryThemeProperties::SetXChgData( ExchangeData
* _pData
)
605 aPreviewTimer
.SetInvokeHandler( LINK( this, TPGalleryThemeProperties
, PreviewTimerHdl
) );
606 aPreviewTimer
.SetTimeout( 500 );
607 m_xBtnSearch
->connect_clicked(LINK(this, TPGalleryThemeProperties
, ClickSearchHdl
));
608 m_xBtnTake
->connect_clicked(LINK(this, TPGalleryThemeProperties
, ClickTakeHdl
));
609 m_xBtnTakeAll
->connect_clicked(LINK(this, TPGalleryThemeProperties
, ClickTakeAllHdl
));
610 m_xCbxPreview
->connect_toggled(LINK(this, TPGalleryThemeProperties
, ClickPreviewHdl
));
611 m_xCbbFileType
->connect_changed(LINK(this, TPGalleryThemeProperties
, SelectFileTypeHdl
));
612 m_xLbxFound
->connect_row_activated(LINK(this, TPGalleryThemeProperties
, DClickFoundHdl
));
613 m_xLbxFound
->connect_changed(LINK(this, TPGalleryThemeProperties
, SelectFoundHdl
));
614 m_xLbxFound
->append_text(CuiResId(RID_CUISTR_GALLERY_NOFILES
));
619 m_xBtnTake
->set_sensitive(true);
620 m_xBtnTakeAll
->set_sensitive(false);
621 m_xCbxPreview
->set_sensitive(false);
624 void TPGalleryThemeProperties::StartSearchFiles( std::u16string_view _rFolderURL
, short _nDlgResult
)
626 if ( RET_OK
== _nDlgResult
)
628 aURL
= INetURLObject( _rFolderURL
);
629 bSearchRecursive
= true; // UI choice no longer possible, windows file picker allows no user controls
634 TPGalleryThemeProperties::~TPGalleryThemeProperties()
636 xMediaPlayer
.clear();
637 xDialogListener
.clear();
638 aFilterEntryList
.clear();
641 std::unique_ptr
<SfxTabPage
> TPGalleryThemeProperties::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
643 return std::make_unique
<TPGalleryThemeProperties
>(pPage
, pController
, *rSet
);
646 OUString
TPGalleryThemeProperties::addExtension( const OUString
& _rDisplayText
, std::u16string_view _rExtension
)
648 OUString sRet
= _rDisplayText
;
649 if ( sRet
.indexOf( "(*.*)" ) == -1 )
651 sRet
+= OUString::Concat(" (") + _rExtension
+ ")";
656 void TPGalleryThemeProperties::FillFilterList()
658 GraphicFilter
&rFilter
= GraphicFilter::GetGraphicFilter();
661 sal_uInt16 i
, nKeyCount
;
664 for( i
= 0, nKeyCount
= rFilter
.GetImportFormatCount(); i
< nKeyCount
; i
++ )
666 aExt
= rFilter
.GetImportFormatShortName( i
);
667 aName
= rFilter
.GetImportFormatName( i
);
668 size_t entryIndex
= 0;
669 FilterEntry
* pTestEntry
= aFilterEntryList
.empty() ? nullptr : aFilterEntryList
[ entryIndex
].get();
670 bool bInList
= false;
672 OUString aExtensions
;
677 sWildcard
= rFilter
.GetImportWildcard( i
, j
++ );
678 if ( sWildcard
.isEmpty() )
680 if ( aExtensions
.indexOf( sWildcard
) == -1 )
682 if ( !aExtensions
.isEmpty() )
684 aExtensions
+= sWildcard
;
687 aName
= addExtension( aName
, aExtensions
);
691 if ( pTestEntry
->aFilterName
== aExt
)
696 pTestEntry
= ( ++entryIndex
< aFilterEntryList
.size() )
697 ? aFilterEntryList
[ entryIndex
].get() : nullptr;
701 std::unique_ptr
<FilterEntry
> pFilterEntry(new FilterEntry
);
702 pFilterEntry
->aFilterName
= aExt
;
703 m_xCbbFileType
->append_text(aName
);
704 aFilterEntryList
.push_back(std::move(pFilterEntry
));
708 #if HAVE_FEATURE_AVMEDIA
710 static constexpr OUStringLiteral aWildcard
= u
"*.";
711 ::avmedia::FilterNameVector aFilters
= ::avmedia::MediaWindow::getMediaFilters();
713 for(const std::pair
<OUString
,OUString
> & aFilter
: aFilters
)
715 for( sal_Int32 nIndex
= 0; nIndex
>= 0; )
717 OUString
aFilterWildcard( aWildcard
);
719 std::unique_ptr
<FilterEntry
> pFilterEntry(new FilterEntry
);
720 pFilterEntry
->aFilterName
= aFilter
.second
.getToken( 0, ';', nIndex
);
721 aFilterWildcard
+= pFilterEntry
->aFilterName
;
722 m_xCbbFileType
->append_text(addExtension(aFilter
.first
, aFilterWildcard
));
723 aFilterEntryList
.push_back( std::move(pFilterEntry
) );
729 OUString aExtensions
;
732 for ( i
= 0; i
< nKeyCount
; ++i
)
738 sWildcard
= rFilter
.GetImportWildcard( i
, j
++ );
739 if ( sWildcard
.isEmpty() )
741 if ( aExtensions
.indexOf( sWildcard
) == -1 )
743 if ( !aExtensions
.isEmpty() )
746 aExtensions
+= sWildcard
;
751 #if HAVE_FEATURE_AVMEDIA
753 for(const std::pair
<OUString
,OUString
> & aFilter
: aFilters
)
755 for( sal_Int32 nIndex
= 0; nIndex
>= 0; )
757 if ( !aExtensions
.isEmpty() )
759 aExtensions
+= OUString::Concat(aWildcard
) + o3tl::getToken(aFilter
.second
, 0, ';', nIndex
);
765 if (aExtensions
.getLength() > 240)
769 std::unique_ptr
<FilterEntry
> pFilterEntry(new FilterEntry
);
770 pFilterEntry
->aFilterName
= CuiResId(RID_CUISTR_GALLERY_ALLFILES
);
771 pFilterEntry
->aFilterName
= addExtension(pFilterEntry
->aFilterName
, aExtensions
);
772 m_xCbbFileType
->insert_text(0, pFilterEntry
->aFilterName
);
773 m_xCbbFileType
->set_active(0);
774 aFilterEntryList
.insert(aFilterEntryList
.begin(), std::move(pFilterEntry
));
777 IMPL_LINK_NOARG(TPGalleryThemeProperties
, SelectFileTypeHdl
, weld::ComboBox
&, void)
779 OUString
aText(m_xCbbFileType
->get_active_text());
781 if( bInputAllowed
&& ( aLastFilterName
!= aText
) )
783 aLastFilterName
= aText
;
785 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryupdategalleryfilelistdialog.ui"));
786 std::unique_ptr
<weld::MessageDialog
> xQuery(xBuilder
->weld_message_dialog("QueryUpdateFileListDialog"));
787 if (xQuery
->run() == RET_YES
)
792 void TPGalleryThemeProperties::SearchFiles()
794 auto xProgress
= std::make_shared
<SearchProgress
>(GetFrameWeld(), this, aURL
);
797 m_xLbxFound
->clear();
799 xProgress
->SetFileType( m_xCbbFileType
->get_active_text() );
800 xProgress
->SetDirectory( INetURLObject() );
802 xProgress
->LaunchThread();
803 weld::DialogController::runAsync(xProgress
, [this](sal_Int32 nResult
) {
804 EndSearchProgressHdl(nResult
);
808 IMPL_LINK_NOARG(TPGalleryThemeProperties
, ClickSearchHdl
, weld::Button
&, void)
815 // setup folder picker
816 css::uno::Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
817 xFolderPicker
= sfx2::createFolderPicker(xContext
, GetFrameWeld());
819 OUString
aDlgPathName( SvtPathOptions().GetGraphicPath() );
820 xFolderPicker
->setDisplayDirectory(aDlgPathName
);
822 aPreviewTimer
.Stop();
824 css::uno::Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
825 if ( xAsyncDlg
.is() )
826 xAsyncDlg
->startExecuteModal( xDialogListener
);
829 if( xFolderPicker
->execute() == RET_OK
)
831 aURL
= INetURLObject( xFolderPicker
->getDirectory() );
832 bSearchRecursive
= true; // UI choice no longer possible, windows file picker allows no user controls
837 catch (const IllegalArgumentException
&)
839 OSL_FAIL( "Folder picker failed with illegal arguments" );
843 void TPGalleryThemeProperties::TakeFiles()
845 if (m_xLbxFound
->count_selected_rows() || (bTakeAll
&& bEntriesFound
))
847 auto xTakeProgress
= std::make_shared
<TakeProgress
>(GetFrameWeld(), this);
848 xTakeProgress
->LaunchThread();
849 weld::DialogController::runAsync(xTakeProgress
, [](sal_Int32
/*nResult*/) {
850 /* no postprocessing needed, pTakeProgress
851 will be disposed in TakeProgress::CleanupHdl */
857 IMPL_LINK_NOARG(TPGalleryThemeProperties
, ClickPreviewHdl
, weld::Toggleable
&, void)
859 if ( !bInputAllowed
)
862 aPreviewTimer
.Stop();
863 aPreviewString
.clear();
865 if (!m_xCbxPreview
->get_active())
867 xMediaPlayer
.clear();
868 m_aWndPreview
.SetGraphic(Graphic());
869 m_aWndPreview
.Invalidate();
875 void TPGalleryThemeProperties::DoPreview()
877 int nIndex
= m_xLbxFound
->get_selected_index();
878 OUString
aString(m_xLbxFound
->get_text(nIndex
));
880 if (aString
== aPreviewString
)
883 INetURLObject
_aURL(aFoundList
[nIndex
]);
884 bInputAllowed
= false;
886 if (!m_aWndPreview
.SetGraphic(_aURL
))
888 weld::WaitObject
aWaitObject(GetFrameWeld());
889 ErrorHandler::HandleError(ERRCODE_IO_NOTEXISTSPATH
, GetFrameWeld());
891 #if HAVE_FEATURE_AVMEDIA
892 else if( ::avmedia::MediaWindow::isMediaURL( _aURL
.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous
), "" ) )
894 xMediaPlayer
= ::avmedia::MediaWindow::createPlayer( _aURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), "" );
895 if( xMediaPlayer
.is() )
896 xMediaPlayer
->start();
899 bInputAllowed
= true;
900 aPreviewString
= aString
;
903 IMPL_LINK_NOARG(TPGalleryThemeProperties
, ClickTakeHdl
, weld::Button
&, void)
908 aPreviewTimer
.Stop();
910 if (!m_xLbxFound
->count_selected_rows() || !bEntriesFound
)
912 SvxOpenGraphicDialog
aDlg(CuiResId(RID_CUISTR_KEY_GALLERY_DIR
), GetFrameWeld());
913 aDlg
.EnableLink(false);
916 if( !aDlg
.Execute() )
917 pData
->pTheme
->InsertURL( INetURLObject( aDlg
.GetPath() ) );
926 IMPL_LINK_NOARG(TPGalleryThemeProperties
, ClickTakeAllHdl
, weld::Button
&, void)
930 aPreviewTimer
.Stop();
936 IMPL_LINK_NOARG(TPGalleryThemeProperties
, SelectFoundHdl
, weld::TreeView
&, void)
941 bool bPreviewPossible
= false;
943 aPreviewTimer
.Stop();
947 if (m_xLbxFound
->count_selected_rows() == 1)
949 m_xCbxPreview
->set_sensitive(true);
950 bPreviewPossible
= true;
953 m_xCbxPreview
->set_sensitive(false);
955 if( !aFoundList
.empty() )
956 m_xBtnTakeAll
->set_sensitive(true);
958 m_xBtnTakeAll
->set_sensitive(false);
961 if (bPreviewPossible
&& m_xCbxPreview
->get_active())
962 aPreviewTimer
.Start();
965 IMPL_LINK_NOARG(TPGalleryThemeProperties
, DClickFoundHdl
, weld::TreeView
&, bool)
969 aPreviewTimer
.Stop();
971 if (m_xLbxFound
->count_selected_rows() == 1 && bEntriesFound
)
972 ClickTakeHdl(*m_xBtnTake
);
977 IMPL_LINK_NOARG(TPGalleryThemeProperties
, PreviewTimerHdl
, Timer
*, void)
979 aPreviewTimer
.Stop();
983 void TPGalleryThemeProperties::EndSearchProgressHdl(sal_Int32
/*nResult*/)
985 if( !aFoundList
.empty() )
987 m_xLbxFound
->select(0);
988 m_xBtnTakeAll
->set_sensitive(true);
989 m_xCbxPreview
->set_sensitive(true);
990 bEntriesFound
= true;
994 m_xLbxFound
->append_text(CuiResId(RID_CUISTR_GALLERY_NOFILES
));
995 m_xBtnTakeAll
->set_sensitive(false);
996 m_xCbxPreview
->set_sensitive(false);
997 bEntriesFound
= false;
1001 IMPL_LINK( TPGalleryThemeProperties
, DialogClosedHdl
, css::ui::dialogs::DialogClosedEvent
*, pEvt
, void )
1003 DBG_ASSERT( xFolderPicker
.is(), "TPGalleryThemeProperties::DialogClosedHdl(): no folder picker" );
1005 OUString sURL
= xFolderPicker
->getDirectory();
1006 StartSearchFiles( sURL
, pEvt
->DialogResult
);
1009 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */