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/FolderPicker.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 
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  m_pTabPage->aFoundList = std::move(aRemainingVector);
339 
340  // refill list box
341  for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
342  if( !aRemoveEntries[ i ] )
343  aRemainingVector.push_back(m_pTabPage->m_xLbxFound->get_text(i));
344 
345  m_pTabPage->m_xLbxFound->clear();
346 
347  for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
348  m_pTabPage->m_xLbxFound->append_text(aRemainingVector[i]);
349 
350  aRemainingVector.clear();
351 
352  m_pTabPage->m_xLbxFound->thaw();
353  m_pTabPage->SelectFoundHdl( *m_pTabPage->m_xLbxFound );
354 
355  xWait.reset();
356 
357  m_xDialog->response(RET_OK);
358 }
359 
361 {
362  assert(!maTakeThread.is());
364  maTakeThread->launch();
365 }
366 
368  : GenericDialogController(pWindow, "cui/ui/galleryupdateprogress.ui",
369  "GalleryUpdateProgress")
370  , pIdle(nullptr)
371  , pTheme(pThm)
372  , m_xFtActualizeFile(m_xBuilder->weld_label("file"))
373  , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
374 {
375  m_xBtnCancel->connect_clicked(LINK(this, ActualizeProgress, ClickCancelBtn));
376 }
377 
379 {
380 }
381 
383 {
384  pIdle = new Idle("ActualizeProgressTimeout");
385  pIdle->SetInvokeHandler( LINK( this, ActualizeProgress, TimeoutHdl ) );
386  pIdle->SetPriority( TaskPriority::LOWEST );
387  pIdle->Start();
388 
389  return GenericDialogController::run();
390 }
391 
393 {
394  pTheme->AbortActualize();
395  m_xDialog->response(RET_OK);
396 }
397 
398 IMPL_LINK( ActualizeProgress, TimeoutHdl, Timer*, _pTimer, void)
399 {
400  if (_pTimer)
401  {
402  _pTimer->Stop();
403  delete _pTimer;
404  }
405 
406  pTheme->Actualize(LINK(this, ActualizeProgress, ActualizeHdl), &aStatusProgress);
407  ClickCancelBtn(*m_xBtnCancel);
408 }
409 
410 IMPL_LINK( ActualizeProgress, ActualizeHdl, const INetURLObject&, rURL, void )
411 {
413  m_xFtActualizeFile->set_label(GetReducedString(rURL, 30));
414 }
415 
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"))
419 {
420  m_xEdit->set_text(rOldTitle);
421  m_xEdit->grab_focus();
422 }
423 
425 {
426 }
427 
429  : GenericDialogController(pParent, "cui/ui/gallerythemeiddialog.ui", "GalleryThemeIDDialog")
430  , m_pThm(_pThm)
431  , m_xBtnOk(m_xBuilder->weld_button("ok"))
432  , m_xLbResName(m_xBuilder->weld_combo_box("entry"))
433 {
434  m_xLbResName->append_text("!!! No Id !!!");
435 
437 
438  m_xLbResName->set_active(m_pThm->GetId());
439  m_xLbResName->grab_focus();
440 
441  m_xBtnOk->connect_clicked(LINK(this, GalleryIdDialog, ClickOkHdl));
442 }
443 
445 {
446 }
447 
449 {
450  Gallery* pGal = m_pThm->GetParent();
451  const sal_uInt32 nId = GetId();
452  bool bDifferentThemeExists = false;
453 
454  for( size_t i = 0, nCount = pGal->GetThemeCount(); i < nCount && !bDifferentThemeExists; i++ )
455  {
456  const GalleryThemeEntry* pInfo = pGal->GetThemeInfo( i );
457 
458  if ((pInfo->GetId() == nId) && (pInfo->GetThemeName() != m_pThm->GetName()))
459  {
460  OUString aStr = CuiResId( RID_CUISTR_GALLERY_ID_EXISTS ) +
461  " (" + pInfo->GetThemeName() + ")";
462 
463  std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(),
464  VclMessageType::Info, VclButtonsType::Ok,
465  aStr));
466  xInfoBox->run();
467  m_xLbResName->grab_focus();
468  bDifferentThemeExists = true;
469  }
470  }
471 
472  if (!bDifferentThemeExists)
473  m_xDialog->response(RET_OK);
474 }
475 
477  ExchangeData* _pData, SfxItemSet const * pItemSet)
478  : SfxTabDialogController(pParent, "cui/ui/gallerythemedialog.ui",
479  "GalleryThemeDialog", pItemSet)
480  , pData(_pData)
481 {
482  AddTabPage("general", TPGalleryThemeGeneral::Create, nullptr);
483  AddTabPage("files", TPGalleryThemeProperties::Create, nullptr);
484  if (pData->pTheme->IsReadOnly())
485  RemoveTabPage("files");
486 
487  OUString aText = m_xDialog->get_title().replaceFirst( "%1", pData->pTheme->GetName() );
488 
489  if (pData->pTheme->IsReadOnly())
490  aText += " " + CuiResId( RID_CUISTR_GALLERY_READONLY );
491 
492  m_xDialog->set_title(aText);
493 }
494 
495 void GalleryThemeProperties::PageCreated(const OString& rId, SfxTabPage &rPage)
496 {
497  if (rId == "general")
498  static_cast<TPGalleryThemeGeneral&>( rPage ).SetXChgData( pData );
499  else
500  static_cast<TPGalleryThemeProperties&>( rPage ).SetXChgData( pData );
501 }
502 
504  : SfxTabPage(pPage, pController, "cui/ui/gallerygeneralpage.ui", "GalleryGeneralPage", &rSet)
505  , pData(nullptr)
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"))
512 {
513 }
514 
516 {
517  pData = _pData;
518 
519  GalleryTheme* pThm = pData->pTheme;
520  OUString aOutStr( OUString::number(pThm->GetObjectCount()) );
521  OUString aObjStr( CuiResId( RID_CUISTR_GALLERYPROPS_OBJECT ) );
522  OUString aAccess;
523  OUString aType( SvxResId( RID_SVXSTR_GALLERYPROPS_GALTHEME ) );
524  bool bReadOnly = pThm->IsReadOnly();
525 
526  m_xEdtMSName->set_text(pThm->GetName());
527  m_xEdtMSName->set_editable(!bReadOnly);
528  m_xEdtMSName->set_sensitive(!bReadOnly);
529 
530  if( pThm->IsReadOnly() )
531  aType += CuiResId( RID_CUISTR_GALLERY_READONLY );
532 
533  m_xFtMSShowType->set_label(aType);
535 
536  // singular or plural?
537  if ( 1 == pThm->GetObjectCount() )
538  aObjStr = aObjStr.getToken( 0, ';' );
539  else
540  aObjStr = aObjStr.getToken( 1, ';' );
541 
542  aOutStr += " " + aObjStr;
543 
544  m_xFtMSShowContent->set_label(aOutStr);
545 
546  // get locale wrapper (singleton)
547  const SvtSysLocale aSysLocale;
548  const LocaleDataWrapper& aLocaleData = aSysLocale.GetLocaleData();
549 
550  // ChangeDate/Time
551  aAccess = aLocaleData.getDate( pData->aThemeChangeDate ) + ", " + aLocaleData.getTime( pData->aThemeChangeTime );
552  m_xFtMSShowChangeDate->set_label(aAccess);
553 
554  // set image
555  OUString sId;
556 
557  if( pThm->IsReadOnly() )
558  sId = RID_SVXBMP_THEME_READONLY_BIG;
559  else if( pThm->IsDefault() )
560  sId = RID_SVXBMP_THEME_DEFAULT_BIG;
561  else
562  sId = RID_SVXBMP_THEME_NORMAL_BIG;
563 
564  m_xFiMSImage->set_from_icon_name(sId);
565 }
566 
568 {
569  pData->aEditedTitle = m_xEdtMSName->get_text();
570  return true;
571 }
572 
573 std::unique_ptr<SfxTabPage> TPGalleryThemeGeneral::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
574 {
575  return std::make_unique<TPGalleryThemeGeneral>(pPage, pController, *rSet);
576 }
577 
579  : SfxTabPage(pPage, pController, "cui/ui/galleryfilespage.ui", "GalleryFilesPage", &rSet)
580  , pData(nullptr)
581  , aPreviewTimer("cui TPGalleryThemeProperties aPreviewTimer")
582  , bEntriesFound(false)
583  , bInputAllowed(true)
584  , bTakeAll(false)
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))
594 {
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 ) );
599 }
600 
602 {
603  pData = _pData;
604 
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));
615  m_xLbxFound->show();
616 
617  FillFilterList();
618 
619  m_xBtnTake->set_sensitive(true);
620  m_xBtnTakeAll->set_sensitive(false);
621  m_xCbxPreview->set_sensitive(false);
622 }
623 
624 void TPGalleryThemeProperties::StartSearchFiles( const OUString& _rFolderURL, short _nDlgResult )
625 {
626  if ( RET_OK == _nDlgResult )
627  {
628  aURL = INetURLObject( _rFolderURL );
629  bSearchRecursive = true; // UI choice no longer possible, windows file picker allows no user controls
630  SearchFiles();
631  }
632 }
633 
635 {
636  xMediaPlayer.clear();
637  xDialogListener.clear();
638  aFilterEntryList.clear();
639 }
640 
641 std::unique_ptr<SfxTabPage> TPGalleryThemeProperties::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
642 {
643  return std::make_unique<TPGalleryThemeProperties>(pPage, pController, *rSet);
644 }
645 
646 OUString TPGalleryThemeProperties::addExtension( const OUString& _rDisplayText, std::u16string_view _rExtension )
647 {
648  OUString sRet = _rDisplayText;
649  if ( sRet.indexOf( "(*.*)" ) == -1 )
650  {
651  sRet += OUString::Concat(" (") + _rExtension + ")";
652  }
653  return sRet;
654 }
655 
657 {
659  OUString aExt;
660  OUString aName;
661  sal_uInt16 i, nKeyCount;
662 
663  // graphic filters
664  for( i = 0, nKeyCount = rFilter.GetImportFormatCount(); i < nKeyCount; i++ )
665  {
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;
671 
672  OUString aExtensions;
673  int j = 0;
674  OUString sWildcard;
675  while( true )
676  {
677  sWildcard = rFilter.GetImportWildcard( i, j++ );
678  if ( sWildcard.isEmpty() )
679  break;
680  if ( aExtensions.indexOf( sWildcard ) == -1 )
681  {
682  if ( !aExtensions.isEmpty() )
683  aExtensions += ";";
684  aExtensions += sWildcard;
685  }
686  }
687  aName = addExtension( aName, aExtensions );
688 
689  while( pTestEntry )
690  {
691  if ( pTestEntry->aFilterName == aExt )
692  {
693  bInList = true;
694  break;
695  }
696  pTestEntry = ( ++entryIndex < aFilterEntryList.size() )
697  ? aFilterEntryList[ entryIndex ].get() : nullptr;
698  }
699  if ( !bInList )
700  {
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));
705  }
706  }
707 
708 #if HAVE_FEATURE_AVMEDIA
709  // media filters
710  static constexpr OUStringLiteral aWildcard = u"*.";
712 
713  for(const std::pair<OUString,OUString> & aFilter : aFilters)
714  {
715  for( sal_Int32 nIndex = 0; nIndex >= 0; )
716  {
717  OUString aFilterWildcard( aWildcard );
718 
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) );
724  }
725  }
726 #endif
727 
728  // 'All' filters
729  OUString aExtensions;
730 
731  // graphic filters
732  for ( i = 0; i < nKeyCount; ++i )
733  {
734  int j = 0;
735  OUString sWildcard;
736  while( true )
737  {
738  sWildcard = rFilter.GetImportWildcard( i, j++ );
739  if ( sWildcard.isEmpty() )
740  break;
741  if ( aExtensions.indexOf( sWildcard ) == -1 )
742  {
743  if ( !aExtensions.isEmpty() )
744  aExtensions += ";";
745 
746  aExtensions += sWildcard;
747  }
748  }
749  }
750 
751 #if HAVE_FEATURE_AVMEDIA
752  // media filters
753  for(const std::pair<OUString,OUString> & aFilter : aFilters)
754  {
755  for( sal_Int32 nIndex = 0; nIndex >= 0; )
756  {
757  if ( !aExtensions.isEmpty() )
758  aExtensions += ";";
759  aExtensions += aWildcard + aFilter.second.getToken( 0, ';', nIndex );
760  }
761  }
762 #endif
763 
764 #if defined(_WIN32)
765  if (aExtensions.getLength() > 240)
766  aExtensions = "*.*";
767 #endif
768 
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));
775 }
776 
778 {
779  OUString aText(m_xCbbFileType->get_active_text());
780 
781  if( bInputAllowed && ( aLastFilterName != aText ) )
782  {
783  aLastFilterName = aText;
784 
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)
788  SearchFiles();
789  }
790 }
791 
793 {
794  auto xProgress = std::make_shared<SearchProgress>(GetFrameWeld(), this, aURL);
795 
796  aFoundList.clear();
797  m_xLbxFound->clear();
798 
799  xProgress->SetFileType( m_xCbbFileType->get_active_text() );
800  xProgress->SetDirectory( INetURLObject() );
801 
802  xProgress->LaunchThread();
803  weld::DialogController::runAsync(xProgress, [this](sal_Int32 nResult) {
804  EndSearchProgressHdl(nResult);
805  });
806 }
807 
809 {
810  if( !bInputAllowed )
811  return;
812 
813  try
814  {
815  // setup folder picker
816  css::uno::Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
817  xFolderPicker = sfx2::createFolderPicker(xContext, GetFrameWeld());
818 
819  OUString aDlgPathName( SvtPathOptions().GetGraphicPath() );
820  xFolderPicker->setDisplayDirectory(aDlgPathName);
821 
822  aPreviewTimer.Stop();
823 
824  css::uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
825  if ( xAsyncDlg.is() )
826  xAsyncDlg->startExecuteModal( xDialogListener );
827  else
828  {
829  if( xFolderPicker->execute() == RET_OK )
830  {
831  aURL = INetURLObject( xFolderPicker->getDirectory() );
832  bSearchRecursive = true; // UI choice no longer possible, windows file picker allows no user controls
833  SearchFiles();
834  }
835  }
836  }
837  catch (const IllegalArgumentException&)
838  {
839  OSL_FAIL( "Folder picker failed with illegal arguments" );
840  }
841 }
842 
844 {
845  if (m_xLbxFound->count_selected_rows() || (bTakeAll && bEntriesFound))
846  {
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 */
852  });
853 
854  }
855 }
856 
858 {
859  if ( !bInputAllowed )
860  return;
861 
862  aPreviewTimer.Stop();
863  aPreviewString.clear();
864 
865  if (!m_xCbxPreview->get_active())
866  {
867  xMediaPlayer.clear();
868  m_aWndPreview.SetGraphic(Graphic());
869  m_aWndPreview.Invalidate();
870  }
871  else
872  DoPreview();
873 }
874 
876 {
877  int nIndex = m_xLbxFound->get_selected_index();
878  OUString aString(m_xLbxFound->get_text(nIndex));
879 
880  if (aString == aPreviewString)
881  return;
882 
883  INetURLObject _aURL(aFoundList[nIndex]);
884  bInputAllowed = false;
885 
886  if (!m_aWndPreview.SetGraphic(_aURL))
887  {
888  weld::WaitObject aWaitObject(GetFrameWeld());
890  }
891 #if HAVE_FEATURE_AVMEDIA
893  {
895  if( xMediaPlayer.is() )
896  xMediaPlayer->start();
897  }
898 #endif
899  bInputAllowed = true;
900  aPreviewString = aString;
901 }
902 
904 {
905  if( !bInputAllowed )
906  return;
907 
908  aPreviewTimer.Stop();
909 
910  if (!m_xLbxFound->count_selected_rows() || !bEntriesFound)
911  {
912  SvxOpenGraphicDialog aDlg(CuiResId(RID_CUISTR_KEY_GALLERY_DIR), GetFrameWeld());
913  aDlg.EnableLink(false);
914  aDlg.AsLink(false);
915 
916  if( !aDlg.Execute() )
917  pData->pTheme->InsertURL( INetURLObject( aDlg.GetPath() ) );
918  }
919  else
920  {
921  bTakeAll = false;
922  TakeFiles();
923  }
924 }
925 
927 {
928  if( bInputAllowed )
929  {
930  aPreviewTimer.Stop();
931  bTakeAll = true;
932  TakeFiles();
933  }
934 }
935 
937 {
938  if (!bInputAllowed)
939  return;
940 
941  bool bPreviewPossible = false;
942 
943  aPreviewTimer.Stop();
944 
945  if( bEntriesFound )
946  {
947  if (m_xLbxFound->count_selected_rows() == 1)
948  {
949  m_xCbxPreview->set_sensitive(true);
950  bPreviewPossible = true;
951  }
952  else
953  m_xCbxPreview->set_sensitive(false);
954 
955  if( !aFoundList.empty() )
956  m_xBtnTakeAll->set_sensitive(true);
957  else
958  m_xBtnTakeAll->set_sensitive(false);
959  }
960 
961  if (bPreviewPossible && m_xCbxPreview->get_active())
962  aPreviewTimer.Start();
963 }
964 
966 {
967  if( bInputAllowed )
968  {
969  aPreviewTimer.Stop();
970 
971  if (m_xLbxFound->count_selected_rows() == 1 && bEntriesFound)
972  ClickTakeHdl(*m_xBtnTake);
973  }
974  return true;
975 }
976 
978 {
979  aPreviewTimer.Stop();
980  DoPreview();
981 }
982 
984 {
985  if( !aFoundList.empty() )
986  {
987  m_xLbxFound->select(0);
988  m_xBtnTakeAll->set_sensitive(true);
989  m_xCbxPreview->set_sensitive(true);
990  bEntriesFound = true;
991  }
992  else
993  {
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;
998  }
999 }
1000 
1001 IMPL_LINK( TPGalleryThemeProperties, DialogClosedHdl, css::ui::dialogs::DialogClosedEvent*, pEvt, void )
1002 {
1003  DBG_ASSERT( xFolderPicker.is(), "TPGalleryThemeProperties::DialogClosedHdl(): no folder picker" );
1004 
1005  OUString sURL = xFolderPicker->getDirectory();
1006  StartSearchFiles( sURL, pEvt->DialogResult );
1007 }
1008 
1009 /* 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:641
GalleryThemeProperties(weld::Widget *pParent, ExchangeData *pData, SfxItemSet const *pItemSet)
Definition: cuigaldlg.cxx:476
bool IsDefault() const
sal_uInt32 GetId() const
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: cuigaldlg.hxx:79
std::unique_ptr< ContentProperties > pData
css::uno::Reference< css::media::XPlayer > xMediaPlayer
Definition: cuigaldlg.hxx:232
const ExchangeData * GetXChgData() const
Definition: cuigaldlg.hxx:269
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:503
void RemoveTabPage(const OString &rName)
sal_Int16 nId
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:382
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 StartSearchFiles(const OUString &_rFolderURL, short _nDlgResult)
Definition: cuigaldlg.cxx:624
void SetXChgData(ExchangeData *pData)
Definition: cuigaldlg.cxx:515
#define ERRCODE_IO_NOTEXISTSPATH
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:578
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:424
GalleryIdDialog(weld::Widget *pParent, GalleryTheme *pThm)
Definition: cuigaldlg.cxx:428
RET_YES
virtual ~SearchProgress() override
Definition: cuigaldlg.cxx:203
void SetXChgData(ExchangeData *pData)
Definition: cuigaldlg.cxx:601
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:444
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:378
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:573
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
uno::Reference< sdbc::XRow > xRow
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:646
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
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
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:360
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:416
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:398
Reference< XExecutableDialog > m_xDialog
virtual ~TPGalleryThemeProperties() override
Definition: cuigaldlg.cxx:634
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:367
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:983
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:495
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:567
std::unique_ptr< weld::Label > m_xFtMSShowType
Definition: cuigaldlg.hxx:198
std::vector< sal_uLong > TokenList_impl
Definition: cuigaldlg.hxx:40
INetURLObject startUrl_
Definition: cuigaldlg.hxx:74
OUString sId