LibreOffice Module cui (master)  1
cuigaldlg.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <config_features.h>
21 
22 #include <sal/config.h>
23 
24 #include <algorithm>
25 #include <cassert>
26 
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/filedlghelper.hxx>
34 #include <sfx2/opengrf.hxx>
35 #include <vcl/graphicfilter.hxx>
36 #include <svx/gallery1.hxx>
37 #include <svx/galtheme.hxx>
38 #include <cuigaldlg.hxx>
39 #include <bitmaps.hlst>
41 #include <unotools/syslocale.hxx>
42 #include <com/sun/star/uno/Reference.hxx>
43 #include <com/sun/star/lang/IllegalArgumentException.hpp>
45 #include <com/sun/star/sdbc/XResultSet.hpp>
46 #include <com/sun/star/sdbc/XRow.hpp>
47 #include <com/sun/star/ucb/ContentCreationException.hpp>
48 #include <com/sun/star/ucb/XContentAccess.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>
54 #include <osl/diagnose.h>
55 #include <o3tl/string_view.hxx>
56 
57 using namespace ::ucbhelper;
58 using namespace ::cppu;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::sdbc;
61 using namespace ::com::sun::star::ucb;
62 using namespace ::com::sun::star::ui::dialogs;
63 using namespace ::com::sun::star::uno;
64 
65 
67  TPGalleryThemeProperties* pBrowser,
68  const INetURLObject& rStartURL)
69  : Thread("cuiSearchThread")
70  , mpProgress(pProgress)
71  , mpBrowser(pBrowser)
72  , maStartURL(rStartURL)
73 {
74 }
75 
77 {
78 }
79 
81 {
82  const OUString aFileType(mpBrowser->m_xCbbFileType->get_active_text());
83 
84  if (!aFileType.isEmpty())
85  {
86  const int nFileNumber = mpBrowser->m_xCbbFileType->find_text(aFileType);
87  sal_Int32 nBeginFormat, nEndFormat;
88  std::vector< OUString > aFormats;
89 
90  if( !nFileNumber || nFileNumber == -1)
91  {
92  nBeginFormat = 1;
93  nEndFormat = mpBrowser->m_xCbbFileType->get_count() - 1;
94  }
95  else
96  nBeginFormat = nEndFormat = nFileNumber;
97 
98  for (sal_Int32 i = nBeginFormat; i <= nEndFormat; ++i)
99  aFormats.push_back( mpBrowser->aFilterEntryList[ i ]->aFilterName.toAsciiLowerCase() );
100 
102  }
103 
105 }
106 
107 
109  const std::vector< OUString >& rFormats,
110  bool bRecursive )
111 {
112  {
113  SolarMutexGuard aGuard;
114 
115  mpProgress->SetDirectory( rStartURL );
116  }
117 
118  try
119  {
120  css::uno::Reference< XCommandEnvironment > xEnv;
122  Sequence< OUString > aProps( 2 );
123 
124  aProps.getArray()[ 0 ] = "IsFolder";
125  aProps.getArray()[ 1 ] = "IsDocument";
126  css::uno::Reference< XResultSet > xResultSet(
127  aCnt.createCursor( aProps ) );
128 
129  if( xResultSet.is() )
130  {
131  css::uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
132  css::uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
133 
134  while( xResultSet->next() && schedule() )
135  {
136  INetURLObject aFoundURL( xContentAccess->queryContentIdentifierString() );
137  DBG_ASSERT( aFoundURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
138 
139  bool bFolder = xRow->getBoolean( 1 ); // property "IsFolder"
140  if ( xRow->wasNull() )
141  bFolder = false;
142 
143  if( bRecursive && bFolder )
144  ImplSearch( aFoundURL, rFormats, true );
145  else
146  {
147  bool bDocument = xRow->getBoolean( 2 ); // property "IsDocument"
148  if ( xRow->wasNull() )
149  bDocument = false;
150 
151  if( bDocument )
152  {
153  GraphicDescriptor aDesc( aFoundURL );
154 
155  if( ( aDesc.Detect() &&
156  std::find( rFormats.begin(),
157  rFormats.end(),
159  aDesc.GetFileFormat() ).toAsciiLowerCase() )
160  != rFormats.end() ) ||
161  std::find( rFormats.begin(),
162  rFormats.end(),
163  aFoundURL.GetFileExtension().toAsciiLowerCase())
164  != rFormats.end() )
165  {
166  SolarMutexGuard aGuard;
167 
168  mpBrowser->aFoundList.push_back(
169  aFoundURL.GetMainURL( INetURLObject::DecodeMechanism::NONE )
170  );
171  mpBrowser->m_xLbxFound->insert_text(
172  mpBrowser->aFoundList.size() - 1,
173  GetReducedString(aFoundURL, 50));
174  }
175  }
176  }
177  }
178  }
179  }
180  catch (const ContentCreationException&)
181  {
182  }
183  catch (const css::uno::RuntimeException&)
184  {
185  }
186  catch (const css::uno::Exception&)
187  {
188  }
189 }
190 
192  : GenericDialogController(pParent, "cui/ui/gallerysearchprogress.ui", "GallerySearchProgress")
193  , startUrl_(rStartURL)
194  , m_pTabPage(pTabPage)
195  , m_xFtSearchDir(m_xBuilder->weld_label("dir"))
196  , m_xFtSearchType(m_xBuilder->weld_label("file"))
197  , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
198 {
199  m_xFtSearchType->set_size_request(m_xFtSearchType->get_preferred_size().Width(), -1);
200  m_xBtnCancel->connect_clicked(LINK(this, SearchProgress, ClickCancelBtn));
201 }
202 
204 {
205 }
206 
208 {
209  if (m_aSearchThread.is())
210  m_aSearchThread->terminate();
211 }
212 
213 IMPL_LINK_NOARG(SearchProgress, CleanUpHdl, void*, void)
214 {
215  if (m_aSearchThread.is())
216  m_aSearchThread->join();
217 
218  m_xDialog->response(RET_OK);
219 }
220 
222 {
223  assert(!m_aSearchThread.is());
225  m_aSearchThread->launch();
226 }
227 
229  TakeProgress* pProgress,
230  TPGalleryThemeProperties* pBrowser,
231  TokenList_impl& rTakenList
232 ) :
233  Thread ( "cuiTakeThread" ),
234  mpProgress ( pProgress ),
235  mpBrowser ( pBrowser ),
236  mrTakenList ( rTakenList )
237 {
238 }
239 
240 
242 {
243 }
244 
246 {
247  sal_Int32 nEntries;
249  std::unique_ptr<GalleryProgress> pStatusProgress;
250 
251  std::vector<int> aSelectedRows;
252 
253  {
254  SolarMutexGuard aGuard;
255  pStatusProgress.reset(new GalleryProgress);
256  if (mpBrowser->bTakeAll)
257  nEntries = mpBrowser->m_xLbxFound->n_children();
258  else
259  {
260  aSelectedRows = mpBrowser->m_xLbxFound->get_selected_rows();
261  nEntries = aSelectedRows.size();
262  }
263  pThm->LockBroadcaster();
264  }
265 
266  for( sal_Int32 i = 0; i < nEntries && schedule(); ++i )
267  {
268  const sal_Int32 nPos = mpBrowser->bTakeAll ? i : aSelectedRows[i];
269  const INetURLObject aURL( mpBrowser->aFoundList[ nPos ]);
270 
271  mrTakenList.push_back( nPos );
272 
273  {
274  SolarMutexGuard aGuard;
275 
276  mpProgress->SetFile( aURL );
277  pStatusProgress->Update( i, nEntries - 1 );
278  pThm->InsertURL( aURL );
279  }
280  }
281 
282  {
283  SolarMutexGuard aGuard;
284 
285  pThm->UnlockBroadcaster();
286  pStatusProgress.reset();
287  }
288 
290 }
291 
293  : GenericDialogController(pParent, "cui/ui/galleryapplyprogress.ui",
294  "GalleryApplyProgress")
295  , m_pParent(pParent)
296  , m_pTabPage(pTabPage)
297  , m_xFtTakeFile(m_xBuilder->weld_label("file"))
298  , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
299 {
300  m_xBtnCancel->connect_clicked(LINK(this, TakeProgress, ClickCancelBtn));
301 }
302 
304 {
305 }
306 
307 IMPL_LINK_NOARG(TakeProgress, ClickCancelBtn, weld::Button&, void)
308 {
309  if (maTakeThread.is())
310  maTakeThread->terminate();
311 }
312 
313 
314 IMPL_LINK_NOARG(TakeProgress, CleanUpHdl, void*, void)
315 {
316  if (maTakeThread.is())
317  maTakeThread->join();
318 
319  std::vector<bool, std::allocator<bool> > aRemoveEntries(m_pTabPage->aFoundList.size(), false);
320  std::vector< OUString > aRemainingVector;
321  sal_uInt32 i, nCount;
322 
323  std::unique_ptr<weld::WaitObject> xWait(new weld::WaitObject(m_pParent));
324 
325  m_pTabPage->m_xLbxFound->select(-1);
326  m_pTabPage->m_xLbxFound->freeze();
327 
328  // mark all taken positions in aRemoveEntries
329  for( i = 0, nCount = maTakenList.size(); i < nCount; ++i )
330  aRemoveEntries[ maTakenList[ i ] ] = true;
331  maTakenList.clear();
332 
333  // refill found list
334  for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
335  if( !aRemoveEntries[ i ] )
336  aRemainingVector.push_back( m_pTabPage->aFoundList[i] );
337 
338  std::swap(m_pTabPage->aFoundList, aRemainingVector);
339  aRemainingVector.clear();
340 
341  // refill list box
342  for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
343  if( !aRemoveEntries[ i ] )
344  aRemainingVector.push_back(m_pTabPage->m_xLbxFound->get_text(i));
345 
346  m_pTabPage->m_xLbxFound->clear();
347  for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
348  m_pTabPage->m_xLbxFound->append_text(aRemainingVector[i]);
349  aRemainingVector.clear();
350 
351  m_pTabPage->m_xLbxFound->thaw();
352  m_pTabPage->SelectFoundHdl( *m_pTabPage->m_xLbxFound );
353 
354  xWait.reset();
355 
356  m_xDialog->response(RET_OK);
357 }
358 
360 {
361  assert(!maTakeThread.is());
363  maTakeThread->launch();
364 }
365 
367  : GenericDialogController(pWindow, "cui/ui/galleryupdateprogress.ui",
368  "GalleryUpdateProgress")
369  , pIdle(nullptr)
370  , pTheme(pThm)
371  , m_xFtActualizeFile(m_xBuilder->weld_label("file"))
372  , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
373 {
374  m_xBtnCancel->connect_clicked(LINK(this, ActualizeProgress, ClickCancelBtn));
375 }
376 
378 {
379 }
380 
382 {
383  pIdle = new Idle("ActualizeProgressTimeout");
384  pIdle->SetInvokeHandler( LINK( this, ActualizeProgress, TimeoutHdl ) );
385  pIdle->SetPriority( TaskPriority::LOWEST );
386  pIdle->Start();
387 
388  return GenericDialogController::run();
389 }
390 
392 {
393  pTheme->AbortActualize();
394  m_xDialog->response(RET_OK);
395 }
396 
397 IMPL_LINK( ActualizeProgress, TimeoutHdl, Timer*, _pTimer, void)
398 {
399  if (_pTimer)
400  {
401  _pTimer->Stop();
402  delete _pTimer;
403  }
404 
405  pTheme->Actualize(LINK(this, ActualizeProgress, ActualizeHdl), &aStatusProgress);
406  ClickCancelBtn(*m_xBtnCancel);
407 }
408 
409 IMPL_LINK( ActualizeProgress, ActualizeHdl, const INetURLObject&, rURL, void )
410 {
412  m_xFtActualizeFile->set_label(GetReducedString(rURL, 30));
413 }
414 
415 TitleDialog::TitleDialog(weld::Widget* pParent, const OUString& rOldTitle)
416  : GenericDialogController(pParent, "cui/ui/gallerytitledialog.ui", "GalleryTitleDialog")
417  , m_xEdit(m_xBuilder->weld_entry("entry"))
418 {
419  m_xEdit->set_text(rOldTitle);
420  m_xEdit->grab_focus();
421 }
422 
424 {
425 }
426 
428  : GenericDialogController(pParent, "cui/ui/gallerythemeiddialog.ui", "GalleryThemeIDDialog")
429  , m_pThm(_pThm)
430  , m_xBtnOk(m_xBuilder->weld_button("ok"))
431  , m_xLbResName(m_xBuilder->weld_combo_box("entry"))
432 {
433  m_xLbResName->append_text("!!! No Id !!!");
434 
436 
437  m_xLbResName->set_active(m_pThm->GetId());
438  m_xLbResName->grab_focus();
439 
440  m_xBtnOk->connect_clicked(LINK(this, GalleryIdDialog, ClickOkHdl));
441 }
442 
444 {
445 }
446 
448 {
449  Gallery* pGal = m_pThm->GetParent();
450  const sal_uInt32 nId = GetId();
451  bool bDifferentThemeExists = false;
452 
453  for( size_t i = 0, nCount = pGal->GetThemeCount(); i < nCount && !bDifferentThemeExists; i++ )
454  {
455  const GalleryThemeEntry* pInfo = pGal->GetThemeInfo( i );
456 
457  if ((pInfo->GetId() == nId) && (pInfo->GetThemeName() != m_pThm->GetName()))
458  {
459  OUString aStr = CuiResId( RID_CUISTR_GALLERY_ID_EXISTS ) +
460  " (" + pInfo->GetThemeName() + ")";
461 
462  std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
463  VclMessageType::Info, VclButtonsType::Ok,
464  aStr));
465  xInfoBox->run();
466  m_xLbResName->grab_focus();
467  bDifferentThemeExists = true;
468  }
469  }
470 
471  if (!bDifferentThemeExists)
472  m_xDialog->response(RET_OK);
473 }
474 
476  ExchangeData* _pData, SfxItemSet const * pItemSet)
477  : SfxTabDialogController(pParent, "cui/ui/gallerythemedialog.ui",
478  "GalleryThemeDialog", pItemSet)
479  , pData(_pData)
480 {
481  AddTabPage("general", TPGalleryThemeGeneral::Create, nullptr);
482  AddTabPage("files", TPGalleryThemeProperties::Create, nullptr);
483  if (pData->pTheme->IsReadOnly())
484  RemoveTabPage("files");
485 
486  OUString aText = m_xDialog->get_title().replaceFirst( "%1", pData->pTheme->GetName() );
487 
488  if (pData->pTheme->IsReadOnly())
489  aText += " " + CuiResId( RID_CUISTR_GALLERY_READONLY );
490 
491  m_xDialog->set_title(aText);
492 }
493 
494 void GalleryThemeProperties::PageCreated(const OString& rId, SfxTabPage &rPage)
495 {
496  if (rId == "general")
497  static_cast<TPGalleryThemeGeneral&>( rPage ).SetXChgData( pData );
498  else
499  static_cast<TPGalleryThemeProperties&>( rPage ).SetXChgData( pData );
500 }
501 
503  : SfxTabPage(pPage, pController, "cui/ui/gallerygeneralpage.ui", "GalleryGeneralPage", &rSet)
504  , pData(nullptr)
505  , m_xFiMSImage(m_xBuilder->weld_image("image"))
506  , m_xEdtMSName(m_xBuilder->weld_entry("name"))
507  , m_xFtMSShowType(m_xBuilder->weld_label("type"))
508  , m_xFtMSShowPath(m_xBuilder->weld_label("location"))
509  , m_xFtMSShowContent(m_xBuilder->weld_label("contents"))
510  , m_xFtMSShowChangeDate(m_xBuilder->weld_label("modified"))
511 {
512 }
513 
515 {
516  pData = _pData;
517 
518  GalleryTheme* pThm = pData->pTheme;
519  OUString aOutStr( OUString::number(pThm->GetObjectCount()) );
520  OUString aObjStr( CuiResId( RID_CUISTR_GALLERYPROPS_OBJECT ) );
521  OUString aAccess;
522  OUString aType( SvxResId( RID_SVXSTR_GALLERYPROPS_GALTHEME ) );
523  bool bReadOnly = pThm->IsReadOnly();
524 
525  m_xEdtMSName->set_text(pThm->GetName());
526  m_xEdtMSName->set_editable(!bReadOnly);
527  m_xEdtMSName->set_sensitive(!bReadOnly);
528 
529  if( pThm->IsReadOnly() )
530  aType += CuiResId( RID_CUISTR_GALLERY_READONLY );
531 
532  m_xFtMSShowType->set_label(aType);
534 
535  // singular or plural?
536  if ( 1 == pThm->GetObjectCount() )
537  aObjStr = aObjStr.getToken( 0, ';' );
538  else
539  aObjStr = aObjStr.getToken( 1, ';' );
540 
541  aOutStr += " " + aObjStr;
542 
543  m_xFtMSShowContent->set_label(aOutStr);
544 
545  // get locale wrapper (singleton)
546  const SvtSysLocale aSysLocale;
547  const LocaleDataWrapper& aLocaleData = aSysLocale.GetLocaleData();
548 
549  // ChangeDate/Time
550  aAccess = aLocaleData.getDate( pData->aThemeChangeDate ) + ", " + aLocaleData.getTime( pData->aThemeChangeTime );
551  m_xFtMSShowChangeDate->set_label(aAccess);
552 
553  // set image
554  OUString sId;
555 
556  if( pThm->IsReadOnly() )
557  sId = RID_SVXBMP_THEME_READONLY_BIG;
558  else if( pThm->IsDefault() )
559  sId = RID_SVXBMP_THEME_DEFAULT_BIG;
560  else
561  sId = RID_SVXBMP_THEME_NORMAL_BIG;
562 
563  m_xFiMSImage->set_from_icon_name(sId);
564 }
565 
567 {
568  pData->aEditedTitle = m_xEdtMSName->get_text();
569  return true;
570 }
571 
572 std::unique_ptr<SfxTabPage> TPGalleryThemeGeneral::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
573 {
574  return std::make_unique<TPGalleryThemeGeneral>(pPage, pController, *rSet);
575 }
576 
578  : SfxTabPage(pPage, pController, "cui/ui/galleryfilespage.ui", "GalleryFilesPage", &rSet)
579  , pData(nullptr)
580  , aPreviewTimer("cui TPGalleryThemeProperties aPreviewTimer")
581  , bEntriesFound(false)
582  , bInputAllowed(true)
583  , bTakeAll(false)
584  , bSearchRecursive(false)
585  , xDialogListener(new ::svt::DialogClosedListener())
586  , m_xCbbFileType(m_xBuilder->weld_combo_box("filetype"))
587  , m_xLbxFound(m_xBuilder->weld_tree_view("files"))
588  , m_xBtnSearch(m_xBuilder->weld_button("findfiles"))
589  , m_xBtnTake(m_xBuilder->weld_button("add"))
590  , m_xBtnTakeAll(m_xBuilder->weld_button("addall"))
591  , m_xCbxPreview(m_xBuilder->weld_check_button("preview"))
592  , m_xWndPreview(new weld::CustomWeld(*m_xBuilder, "image", m_aWndPreview))
593 {
594  m_xLbxFound->set_size_request(m_xLbxFound->get_approximate_digit_width() * 35,
595  m_xLbxFound->get_height_rows(15));
596  m_xLbxFound->set_selection_mode(SelectionMode::Multiple);
597  xDialogListener->SetDialogClosedLink( LINK( this, TPGalleryThemeProperties, DialogClosedHdl ) );
598 }
599 
601 {
602  pData = _pData;
603 
604  aPreviewTimer.SetInvokeHandler( LINK( this, TPGalleryThemeProperties, PreviewTimerHdl ) );
605  aPreviewTimer.SetTimeout( 500 );
606  m_xBtnSearch->connect_clicked(LINK(this, TPGalleryThemeProperties, ClickSearchHdl));
607  m_xBtnTake->connect_clicked(LINK(this, TPGalleryThemeProperties, ClickTakeHdl));
608  m_xBtnTakeAll->connect_clicked(LINK(this, TPGalleryThemeProperties, ClickTakeAllHdl));
609  m_xCbxPreview->connect_toggled(LINK(this, TPGalleryThemeProperties, ClickPreviewHdl));
610  m_xCbbFileType->connect_changed(LINK(this, TPGalleryThemeProperties, SelectFileTypeHdl));
611  m_xLbxFound->connect_row_activated(LINK(this, TPGalleryThemeProperties, DClickFoundHdl));
612  m_xLbxFound->connect_changed(LINK(this, TPGalleryThemeProperties, SelectFoundHdl));
613  m_xLbxFound->append_text(CuiResId(RID_CUISTR_GALLERY_NOFILES));
614  m_xLbxFound->show();
615 
616  FillFilterList();
617 
618  m_xBtnTake->set_sensitive(true);
619  m_xBtnTakeAll->set_sensitive(false);
620  m_xCbxPreview->set_sensitive(false);
621 }
622 
623 void TPGalleryThemeProperties::StartSearchFiles( std::u16string_view _rFolderURL, short _nDlgResult )
624 {
625  if ( RET_OK == _nDlgResult )
626  {
627  aURL = INetURLObject( _rFolderURL );
628  bSearchRecursive = true; // UI choice no longer possible, windows file picker allows no user controls
629  SearchFiles();
630  }
631 }
632 
634 {
635  xMediaPlayer.clear();
636  xDialogListener.clear();
637  aFilterEntryList.clear();
638 }
639 
640 std::unique_ptr<SfxTabPage> TPGalleryThemeProperties::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
641 {
642  return std::make_unique<TPGalleryThemeProperties>(pPage, pController, *rSet);
643 }
644 
645 OUString TPGalleryThemeProperties::addExtension( const OUString& _rDisplayText, std::u16string_view _rExtension )
646 {
647  OUString sRet = _rDisplayText;
648  if ( sRet.indexOf( "(*.*)" ) == -1 )
649  {
650  sRet += OUString::Concat(" (") + _rExtension + ")";
651  }
652  return sRet;
653 }
654 
656 {
658  OUString aExt;
659  OUString aName;
660  sal_uInt16 i, nKeyCount;
661 
662  // graphic filters
663  for( i = 0, nKeyCount = rFilter.GetImportFormatCount(); i < nKeyCount; i++ )
664  {
665  aExt = rFilter.GetImportFormatShortName( i );
666  aName = rFilter.GetImportFormatName( i );
667  size_t entryIndex = 0;
668  FilterEntry* pTestEntry = aFilterEntryList.empty() ? nullptr : aFilterEntryList[ entryIndex ].get();
669  bool bInList = false;
670 
671  OUString aExtensions;
672  int j = 0;
673  OUString sWildcard;
674  while( true )
675  {
676  sWildcard = rFilter.GetImportWildcard( i, j++ );
677  if ( sWildcard.isEmpty() )
678  break;
679  if ( aExtensions.indexOf( sWildcard ) == -1 )
680  {
681  if ( !aExtensions.isEmpty() )
682  aExtensions += ";";
683  aExtensions += sWildcard;
684  }
685  }
686  aName = addExtension( aName, aExtensions );
687 
688  while( pTestEntry )
689  {
690  if ( pTestEntry->aFilterName == aExt )
691  {
692  bInList = true;
693  break;
694  }
695  pTestEntry = ( ++entryIndex < aFilterEntryList.size() )
696  ? aFilterEntryList[ entryIndex ].get() : nullptr;
697  }
698  if ( !bInList )
699  {
700  std::unique_ptr<FilterEntry> pFilterEntry(new FilterEntry);
701  pFilterEntry->aFilterName = aExt;
702  m_xCbbFileType->append_text(aName);
703  aFilterEntryList.push_back(std::move(pFilterEntry));
704  }
705  }
706 
707 #if HAVE_FEATURE_AVMEDIA
708  // media filters
709  static constexpr OUStringLiteral aWildcard = u"*.";
711 
712  for(const std::pair<OUString,OUString> & aFilter : aFilters)
713  {
714  for( sal_Int32 nIndex = 0; nIndex >= 0; )
715  {
716  OUString aFilterWildcard( aWildcard );
717 
718  std::unique_ptr<FilterEntry> pFilterEntry(new FilterEntry);
719  pFilterEntry->aFilterName = aFilter.second.getToken( 0, ';', nIndex );
720  aFilterWildcard += pFilterEntry->aFilterName;
721  m_xCbbFileType->append_text(addExtension(aFilter.first, aFilterWildcard));
722  aFilterEntryList.push_back( std::move(pFilterEntry) );
723  }
724  }
725 #endif
726 
727  // 'All' filters
728  OUString aExtensions;
729 
730  // graphic filters
731  for ( i = 0; i < nKeyCount; ++i )
732  {
733  int j = 0;
734  OUString sWildcard;
735  while( true )
736  {
737  sWildcard = rFilter.GetImportWildcard( i, j++ );
738  if ( sWildcard.isEmpty() )
739  break;
740  if ( aExtensions.indexOf( sWildcard ) == -1 )
741  {
742  if ( !aExtensions.isEmpty() )
743  aExtensions += ";";
744 
745  aExtensions += sWildcard;
746  }
747  }
748  }
749 
750 #if HAVE_FEATURE_AVMEDIA
751  // media filters
752  for(const std::pair<OUString,OUString> & aFilter : aFilters)
753  {
754  for( sal_Int32 nIndex = 0; nIndex >= 0; )
755  {
756  if ( !aExtensions.isEmpty() )
757  aExtensions += ";";
758  aExtensions += OUString::Concat(aWildcard) + o3tl::getToken(aFilter.second, 0, ';', nIndex );
759  }
760  }
761 #endif
762 
763 #if defined(_WIN32)
764  if (aExtensions.getLength() > 240)
765  aExtensions = "*.*";
766 #endif
767 
768  std::unique_ptr<FilterEntry> pFilterEntry(new FilterEntry);
769  pFilterEntry->aFilterName = CuiResId(RID_CUISTR_GALLERY_ALLFILES);
770  pFilterEntry->aFilterName = addExtension(pFilterEntry->aFilterName, aExtensions);
771  m_xCbbFileType->insert_text(0, pFilterEntry->aFilterName);
772  m_xCbbFileType->set_active(0);
773  aFilterEntryList.insert(aFilterEntryList.begin(), std::move(pFilterEntry));
774 }
775 
777 {
778  OUString aText(m_xCbbFileType->get_active_text());
779 
780  if( bInputAllowed && ( aLastFilterName != aText ) )
781  {
782  aLastFilterName = aText;
783 
784  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryupdategalleryfilelistdialog.ui"));
785  std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("QueryUpdateFileListDialog"));
786  if (xQuery->run() == RET_YES)
787  SearchFiles();
788  }
789 }
790 
792 {
793  auto xProgress = std::make_shared<SearchProgress>(GetFrameWeld(), this, aURL);
794 
795  aFoundList.clear();
796  m_xLbxFound->clear();
797 
798  xProgress->SetFileType( m_xCbbFileType->get_active_text() );
799  xProgress->SetDirectory( INetURLObject() );
800 
801  xProgress->LaunchThread();
802  weld::DialogController::runAsync(xProgress, [this](sal_Int32 nResult) {
803  EndSearchProgressHdl(nResult);
804  });
805 }
806 
808 {
809  if( !bInputAllowed )
810  return;
811 
812  try
813  {
814  // setup folder picker
815  css::uno::Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
816  xFolderPicker = sfx2::createFolderPicker(xContext, GetFrameWeld());
817 
818  OUString aDlgPathName( SvtPathOptions().GetGraphicPath() );
819  xFolderPicker->setDisplayDirectory(aDlgPathName);
820 
821  aPreviewTimer.Stop();
822 
823  css::uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
824  if ( xAsyncDlg.is() )
825  xAsyncDlg->startExecuteModal( xDialogListener );
826  else
827  {
828  if( xFolderPicker->execute() == RET_OK )
829  {
830  aURL = INetURLObject( xFolderPicker->getDirectory() );
831  bSearchRecursive = true; // UI choice no longer possible, windows file picker allows no user controls
832  SearchFiles();
833  }
834  }
835  }
836  catch (const IllegalArgumentException&)
837  {
838  OSL_FAIL( "Folder picker failed with illegal arguments" );
839  }
840 }
841 
843 {
844  if (m_xLbxFound->count_selected_rows() || (bTakeAll && bEntriesFound))
845  {
846  auto xTakeProgress = std::make_shared<TakeProgress>(GetFrameWeld(), this);
847  xTakeProgress->LaunchThread();
848  weld::DialogController::runAsync(xTakeProgress, [](sal_Int32 /*nResult*/) {
849  /* no postprocessing needed, pTakeProgress
850  will be disposed in TakeProgress::CleanupHdl */
851  });
852 
853  }
854 }
855 
857 {
858  if ( !bInputAllowed )
859  return;
860 
861  aPreviewTimer.Stop();
862  aPreviewString.clear();
863 
864  if (!m_xCbxPreview->get_active())
865  {
866  xMediaPlayer.clear();
867  m_aWndPreview.SetGraphic(Graphic());
868  m_aWndPreview.Invalidate();
869  }
870  else
871  DoPreview();
872 }
873 
875 {
876  int nIndex = m_xLbxFound->get_selected_index();
877  OUString aString(m_xLbxFound->get_text(nIndex));
878 
879  if (aString == aPreviewString)
880  return;
881 
882  INetURLObject _aURL(aFoundList[nIndex]);
883  bInputAllowed = false;
884 
885  if (!m_aWndPreview.SetGraphic(_aURL))
886  {
887  weld::WaitObject aWaitObject(GetFrameWeld());
889  }
890 #if HAVE_FEATURE_AVMEDIA
892  {
894  if( xMediaPlayer.is() )
895  xMediaPlayer->start();
896  }
897 #endif
898  bInputAllowed = true;
899  aPreviewString = aString;
900 }
901 
903 {
904  if( !bInputAllowed )
905  return;
906 
907  aPreviewTimer.Stop();
908 
909  if (!m_xLbxFound->count_selected_rows() || !bEntriesFound)
910  {
911  SvxOpenGraphicDialog aDlg(CuiResId(RID_CUISTR_KEY_GALLERY_DIR), GetFrameWeld());
912  aDlg.EnableLink(false);
913  aDlg.AsLink(false);
914 
915  if( !aDlg.Execute() )
916  pData->pTheme->InsertURL( INetURLObject( aDlg.GetPath() ) );
917  }
918  else
919  {
920  bTakeAll = false;
921  TakeFiles();
922  }
923 }
924 
926 {
927  if( bInputAllowed )
928  {
929  aPreviewTimer.Stop();
930  bTakeAll = true;
931  TakeFiles();
932  }
933 }
934 
936 {
937  if (!bInputAllowed)
938  return;
939 
940  bool bPreviewPossible = false;
941 
942  aPreviewTimer.Stop();
943 
944  if( bEntriesFound )
945  {
946  if (m_xLbxFound->count_selected_rows() == 1)
947  {
948  m_xCbxPreview->set_sensitive(true);
949  bPreviewPossible = true;
950  }
951  else
952  m_xCbxPreview->set_sensitive(false);
953 
954  if( !aFoundList.empty() )
955  m_xBtnTakeAll->set_sensitive(true);
956  else
957  m_xBtnTakeAll->set_sensitive(false);
958  }
959 
960  if (bPreviewPossible && m_xCbxPreview->get_active())
961  aPreviewTimer.Start();
962 }
963 
965 {
966  if( bInputAllowed )
967  {
968  aPreviewTimer.Stop();
969 
970  if (m_xLbxFound->count_selected_rows() == 1 && bEntriesFound)
971  ClickTakeHdl(*m_xBtnTake);
972  }
973  return true;
974 }
975 
977 {
978  aPreviewTimer.Stop();
979  DoPreview();
980 }
981 
983 {
984  if( !aFoundList.empty() )
985  {
986  m_xLbxFound->select(0);
987  m_xBtnTakeAll->set_sensitive(true);
988  m_xCbxPreview->set_sensitive(true);
989  bEntriesFound = true;
990  }
991  else
992  {
993  m_xLbxFound->append_text(CuiResId(RID_CUISTR_GALLERY_NOFILES));
994  m_xBtnTakeAll->set_sensitive(false);
995  m_xCbxPreview->set_sensitive(false);
996  bEntriesFound = false;
997  }
998 }
999 
1000 IMPL_LINK( TPGalleryThemeProperties, DialogClosedHdl, css::ui::dialogs::DialogClosedEvent*, pEvt, void )
1001 {
1002  DBG_ASSERT( xFolderPicker.is(), "TPGalleryThemeProperties::DialogClosedHdl(): no folder picker" );
1003 
1004  OUString sURL = xFolderPicker->getDirectory();
1005  StartSearchFiles( sURL, pEvt->DialogResult );
1006 }
1007 
1008 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::ComboBox > m_xCbbFileType
Definition: cuigaldlg.hxx:236
ExchangeData * pData
Definition: cuigaldlg.hxx:183
const INetURLObject & getThemeURL() const
std::unique_ptr< weld::Button > m_xBtnOk
Definition: cuigaldlg.hxx:171
OUString GetReducedString(const INetURLObject &rURL, sal_Int32 nMaxLen)
URL aURL
sal_Int32 nIndex
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: cuigaldlg.cxx:640
GalleryThemeProperties(weld::Widget *pParent, ExchangeData *pData, SfxItemSet const *pItemSet)
Definition: cuigaldlg.cxx:475
bool IsDefault() const
sal_uInt32 GetId() const
Reference< XRow > xRow
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: cuigaldlg.hxx:79
void StartSearchFiles(std::u16string_view _rFolderURL, short _nDlgResult)
Definition: cuigaldlg.cxx:623
css::uno::Reference< css::media::XPlayer > xMediaPlayer
Definition: cuigaldlg.hxx:232
const ExchangeData * GetXChgData() const
Definition: cuigaldlg.hxx:269
std::unique_ptr< sal_Int32[]> pData
std::unique_ptr< weld::CheckButton > m_xCbxPreview
Definition: cuigaldlg.hxx:241
SearchProgress(weld::Window *pParent, TPGalleryThemeProperties *pTabPage, const INetURLObject &rStartURL)
Definition: cuigaldlg.cxx:191
OUString GetImportFormatName(sal_uInt16 nFormat)
TPGalleryThemeGeneral(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: cuigaldlg.cxx:502
void RemoveTabPage(const OString &rName)
sal_Int16 nId
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static FilterNameVector getMediaFilters()
static void InsertAllThemes(weld::ComboBox &rListBox)
std::unique_ptr< weld::Image > m_xFiMSImage
Definition: cuigaldlg.hxx:196
OUString GetPath() const
bool bReadOnly
TPGalleryThemeProperties * mpBrowser
Definition: cuigaldlg.hxx:99
virtual short run() override
Definition: cuigaldlg.cxx:381
TakeProgress(weld::Window *pParent, TPGalleryThemeProperties *pTabPage)
Definition: cuigaldlg.cxx:292
DialogGalleryPreview m_aWndPreview
Definition: cuigaldlg.hxx:235
TakeThread(TakeProgress *pProgress, TPGalleryThemeProperties *pBrowser, TokenList_impl &rTakenList)
Definition: cuigaldlg.cxx:228
void SetXChgData(ExchangeData *pData)
Definition: cuigaldlg.cxx:514
#define ERRCODE_IO_NOTEXISTSPATH
static bool isMediaURL(std::u16string_view rURL, const OUString &rReferer, bool bDeep=false, rtl::Reference< PlayerListener > xPreferredPixelSizeListener=nullptr)
std::unique_ptr< weld::Label > m_xFtMSShowContent
Definition: cuigaldlg.hxx:200
rtl::Reference< ::svt::DialogClosedListener > xDialogListener
Definition: cuigaldlg.hxx:231
virtual sal_uInt32 GetId() const override
TPGalleryThemeProperties(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: cuigaldlg.cxx:577
OUString GetImportWildcard(sal_uInt16 nFormat, sal_Int32 nEntry)
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
const LocaleDataWrapper & GetLocaleData() const
size_t GetThemeCount() const
virtual ~TitleDialog() override
Definition: cuigaldlg.cxx:423
GalleryIdDialog(weld::Widget *pParent, GalleryTheme *pThm)
Definition: cuigaldlg.cxx:427
RET_YES
virtual ~SearchProgress() override
Definition: cuigaldlg.cxx:203
void SetXChgData(ExchangeData *pData)
Definition: cuigaldlg.cxx:600
std::unique_ptr< weld::Label > m_xFtMSShowChangeDate
Definition: cuigaldlg.hxx:201
int nCount
OUString SvxResId(TranslateId aId)
static css::uno::Reference< css::media::XPlayer > createPlayer(const OUString &rURL, const OUString &rReferer, const OUString *pMimeType=nullptr)
ExchangeData * pData
Definition: cuigaldlg.hxx:218
void SetGraphic(const Graphic &rGraphic)
ExchangeData * pData
Definition: cuigaldlg.hxx:194
rtl::Reference< TakeThread > maTakeThread
Definition: cuigaldlg.hxx:119
TokenList_impl & mrTakenList
Definition: cuigaldlg.hxx:100
virtual ~GalleryIdDialog() override
Definition: cuigaldlg.cxx:443
SAL_DLLPRIVATE void LockBroadcaster()
::std::vector< ::std::pair< OUString, OUString > > FilterNameVector
std::unique_ptr< weld::Label > m_xFtMSShowPath
Definition: cuigaldlg.hxx:199
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
static OUString GetImportFormatShortName(GraphicFileFormat nFormat)
virtual ~ActualizeProgress() override
Definition: cuigaldlg.cxx:377
sal_uInt32 GetId() const
std::vector< OUString > aFoundList
Definition: cuigaldlg.hxx:219
INetURLObject maStartURL
Definition: cuigaldlg.hxx:55
static bool Reschedule(bool bHandleAllCurrentEvents=false)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: cuigaldlg.cxx:572
TPGalleryThemeProperties * mpBrowser
Definition: cuigaldlg.hxx:54
#define DBG_ASSERT(sCon, aError)
int i
bool InsertURL(const INetURLObject &rURL, sal_uInt32 nInsertPos=SAL_MAX_UINT32)
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: cuigaldlg.hxx:144
void SetDirectory(const INetURLObject &rURL)
Definition: cuigaldlg.hxx:91
TokenList_impl maTakenList
Definition: cuigaldlg.hxx:120
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
GalleryTheme * pTheme
virtual void execute() override
Definition: cuigaldlg.cxx:80
float u
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: cuigaldlg.hxx:122
void SetFile(const INetURLObject &rURL)
Definition: cuigaldlg.hxx:134
static OUString addExtension(const OUString &, std::u16string_view)
Definition: cuigaldlg.cxx:645
SAL_DLLPRIVATE sal_uInt32 GetObjectCount() const
std::unique_ptr< weld::TreeView > m_xLbxFound
Definition: cuigaldlg.hxx:237
std::unique_ptr< weld::Button > m_xBtnTakeAll
Definition: cuigaldlg.hxx:240
TPGalleryThemeProperties * m_pTabPage
Definition: cuigaldlg.hxx:75
void SetTimeout(sal_uInt64 nTimeoutMs)
void UnlockBroadcaster()
std::unique_ptr< weld::Entry > m_xEdit
Definition: cuigaldlg.hxx:160
void LaunchThread()
Definition: cuigaldlg.cxx:221
std::unique_ptr< weld::ComboBox > m_xLbResName
Definition: cuigaldlg.hxx:172
void LaunchThread()
Definition: cuigaldlg.cxx:359
tools::Time aThemeChangeTime
OUString GetImportFormatShortName(sal_uInt16 nFormat)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString getDate(const Date &rDate) const
std::vector< std::unique_ptr< FilterEntry > > aFilterEntryList
Definition: cuigaldlg.hxx:221
virtual void execute() override
Definition: cuigaldlg.cxx:245
weld::Window * GetFrameWeld() const
virtual ~TakeThread() override
Definition: cuigaldlg.cxx:241
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
Date aThemeChangeDate
TakeProgress * mpProgress
Definition: cuigaldlg.hxx:98
TPGalleryThemeProperties * m_pTabPage
Definition: cuigaldlg.hxx:118
TitleDialog(weld::Widget *pParent, const OUString &rOldText)
Definition: cuigaldlg.cxx:415
std::unique_ptr< weld::Button > m_xBtnSearch
Definition: cuigaldlg.hxx:238
sal_uInt16 GetImportFormatCount() const
OUString aName
SAL_DLLPRIVATE const GalleryThemeEntry * GetThemeInfo(size_t nPos)
RET_OK
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
IMPL_LINK(ActualizeProgress, TimeoutHdl, Timer *, _pTimer, void)
Definition: cuigaldlg.cxx:397
Reference< XExecutableDialog > m_xDialog
virtual ~TPGalleryThemeProperties() override
Definition: cuigaldlg.cxx:633
Reference< XComponentContext > getProcessComponentContext()
void SetInvokeHandler(const Link< Timer *, void > &rLink)
std::unique_ptr< weld::Label > m_xFtSearchType
Definition: cuigaldlg.hxx:78
OUString aWildcard
ActualizeProgress(weld::Widget *pWindow, GalleryTheme *pThm)
Definition: cuigaldlg.cxx:366
std::unique_ptr< weld::Entry > m_xEdtMSName
Definition: cuigaldlg.hxx:197
virtual ~TakeProgress() override
Definition: cuigaldlg.cxx:303
IMPL_LINK_NOARG(SearchProgress, ClickCancelBtn, weld::Button &, void)
Definition: cuigaldlg.cxx:207
virtual void Start(bool bStartTimer=true) override
void EndSearchProgressHdl(sal_Int32 nResult)
Definition: cuigaldlg.cxx:982
static GraphicFilter & GetGraphicFilter()
GraphicFileFormat GetFileFormat() const
std::unique_ptr< weld::Button > m_xBtnTake
Definition: cuigaldlg.hxx:239
void ImplSearch(const INetURLObject &rStartURL, const std::vector< OUString > &rFormats, bool bRecursive)
Definition: cuigaldlg.cxx:108
rtl::Reference< SearchThread > m_aSearchThread
Definition: cuigaldlg.hxx:76
void SetPriority(TaskPriority ePriority)
const OUString & GetName() const
virtual void PageCreated(const OString &rId, SfxTabPage &rPage) override
Definition: cuigaldlg.cxx:494
SearchProgress * mpProgress
Definition: cuigaldlg.hxx:53
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
SearchThread(SearchProgress *pProgress, TPGalleryThemeProperties *pBrowser, const INetURLObject &rStartURL)
Definition: cuigaldlg.cxx:66
bool IsReadOnly() const
bool Detect(bool bExtendedInfo=false)
virtual ~SearchThread() override
Definition: cuigaldlg.cxx:76
GalleryTheme * m_pThm
Definition: cuigaldlg.hxx:170
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
aStr
const OUString & GetThemeName() const
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
sal_uInt16 nPos
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
OUString aEditedTitle
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: cuigaldlg.cxx:566
std::unique_ptr< weld::Label > m_xFtMSShowType
Definition: cuigaldlg.hxx:198
std::vector< sal_uLong > TokenList_impl
Definition: cuigaldlg.hxx:40
bool m_bDetectedRangeSegmentation false
INetURLObject startUrl_
Definition: cuigaldlg.hxx:74
OUString sId