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