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 
55 using namespace ::ucbhelper;
56 using namespace ::cppu;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::sdbc;
59 using namespace ::com::sun::star::ucb;
60 using namespace ::com::sun::star::ui::dialogs;
61 using namespace ::com::sun::star::uno;
62 
63 
65  TPGalleryThemeProperties* pBrowser,
66  const INetURLObject& rStartURL)
67  : Thread("cuiSearchThread")
68  , mpProgress(pProgress)
69  , mpBrowser(pBrowser)
70  , maStartURL(rStartURL)
71 {
72 }
73 
75 {
76 }
77 
79 {
80  const OUString aFileType(mpBrowser->m_xCbbFileType->get_active_text());
81 
82  if (!aFileType.isEmpty())
83  {
84  const int nFileNumber = mpBrowser->m_xCbbFileType->find_text(aFileType);
85  sal_Int32 nBeginFormat, nEndFormat;
86  std::vector< OUString > aFormats;
87 
88  if( !nFileNumber || nFileNumber == -1)
89  {
90  nBeginFormat = 1;
91  nEndFormat = mpBrowser->m_xCbbFileType->get_count() - 1;
92  }
93  else
94  nBeginFormat = nEndFormat = nFileNumber;
95 
96  for (sal_Int32 i = nBeginFormat; i <= nEndFormat; ++i)
97  aFormats.push_back( mpBrowser->aFilterEntryList[ i ]->aFilterName.toAsciiLowerCase() );
98 
100  }
101 
103 }
104 
105 
107  const std::vector< OUString >& rFormats,
108  bool bRecursive )
109 {
110  {
111  SolarMutexGuard aGuard;
112 
113  mpProgress->SetDirectory( rStartURL );
114  }
115 
116  try
117  {
118  css::uno::Reference< XCommandEnvironment > xEnv;
120  Sequence< OUString > aProps( 2 );
121 
122  aProps.getArray()[ 0 ] = "IsFolder";
123  aProps.getArray()[ 1 ] = "IsDocument";
124  css::uno::Reference< XResultSet > xResultSet(
125  aCnt.createCursor( aProps ) );
126 
127  if( xResultSet.is() )
128  {
129  css::uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
130  css::uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
131 
132  while( xResultSet->next() && schedule() )
133  {
134  INetURLObject aFoundURL( xContentAccess->queryContentIdentifierString() );
135  DBG_ASSERT( aFoundURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
136 
137  bool bFolder = xRow->getBoolean( 1 ); // property "IsFolder"
138  if ( xRow->wasNull() )
139  bFolder = false;
140 
141  if( bRecursive && bFolder )
142  ImplSearch( aFoundURL, rFormats, true );
143  else
144  {
145  bool bDocument = xRow->getBoolean( 2 ); // property "IsDocument"
146  if ( xRow->wasNull() )
147  bDocument = false;
148 
149  if( bDocument )
150  {
151  GraphicDescriptor aDesc( aFoundURL );
152 
153  if( ( aDesc.Detect() &&
154  std::find( rFormats.begin(),
155  rFormats.end(),
157  aDesc.GetFileFormat() ).toAsciiLowerCase() )
158  != rFormats.end() ) ||
159  std::find( rFormats.begin(),
160  rFormats.end(),
161  aFoundURL.GetFileExtension().toAsciiLowerCase())
162  != rFormats.end() )
163  {
164  SolarMutexGuard aGuard;
165 
166  mpBrowser->aFoundList.push_back(
167  aFoundURL.GetMainURL( INetURLObject::DecodeMechanism::NONE )
168  );
169  mpBrowser->m_xLbxFound->insert_text(
170  mpBrowser->aFoundList.size() - 1,
171  GetReducedString(aFoundURL, 50));
172  }
173  }
174  }
175  }
176  }
177  }
178  catch (const ContentCreationException&)
179  {
180  }
181  catch (const css::uno::RuntimeException&)
182  {
183  }
184  catch (const css::uno::Exception&)
185  {
186  }
187 }
188 
190  : GenericDialogController(pParent, "cui/ui/gallerysearchprogress.ui", "GallerySearchProgress")
191  , startUrl_(rStartURL)
192  , m_xTabPage(pTabPage)
193  , m_xFtSearchDir(m_xBuilder->weld_label("dir"))
194  , m_xFtSearchType(m_xBuilder->weld_label("file"))
195  , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
196 {
197  m_xFtSearchType->set_size_request(m_xFtSearchType->get_preferred_size().Width(), -1);
198  m_xBtnCancel->connect_clicked(LINK(this, SearchProgress, ClickCancelBtn));
199 }
200 
202 {
203 }
204 
206 {
207  if (m_aSearchThread.is())
208  m_aSearchThread->terminate();
209 }
210 
211 IMPL_LINK_NOARG(SearchProgress, CleanUpHdl, void*, void)
212 {
213  if (m_aSearchThread.is())
214  m_aSearchThread->join();
215 
216  m_xDialog->response(RET_OK);
217 }
218 
220 {
221  assert(!m_aSearchThread.is());
223  m_aSearchThread->launch();
224 }
225 
227  TakeProgress* pProgress,
228  TPGalleryThemeProperties* pBrowser,
229  TokenList_impl& rTakenList
230 ) :
231  Thread ( "cuiTakeThread" ),
232  mpProgress ( pProgress ),
233  mpBrowser ( pBrowser ),
234  mrTakenList ( rTakenList )
235 {
236 }
237 
238 
240 {
241 }
242 
244 {
245  sal_Int32 nEntries;
247  std::unique_ptr<GalleryProgress> pStatusProgress;
248 
249  std::vector<int> aSelectedRows;
250 
251  {
252  SolarMutexGuard aGuard;
253  pStatusProgress.reset(new GalleryProgress);
254  if (mpBrowser->bTakeAll)
255  nEntries = mpBrowser->m_xLbxFound->n_children();
256  else
257  {
258  aSelectedRows = mpBrowser->m_xLbxFound->get_selected_rows();
259  nEntries = aSelectedRows.size();
260  }
261  pThm->LockBroadcaster();
262  }
263 
264  for( sal_Int32 i = 0; i < nEntries && schedule(); ++i )
265  {
266  const sal_Int32 nPos = mpBrowser->bTakeAll ? i : aSelectedRows[i];
267  const INetURLObject aURL( mpBrowser->aFoundList[ nPos ]);
268 
269  mrTakenList.push_back( static_cast<sal_uLong>(nPos) );
270 
271  {
272  SolarMutexGuard aGuard;
273 
274  mpProgress->SetFile( aURL );
275  pStatusProgress->Update( i, nEntries - 1 );
276  pThm->InsertURL( aURL );
277  }
278  }
279 
280  {
281  SolarMutexGuard aGuard;
282 
283  pThm->UnlockBroadcaster();
284  pStatusProgress.reset();
285  }
286 
288 }
289 
291  : GenericDialogController(pParent, "cui/ui/galleryapplyprogress.ui",
292  "GalleryApplyProgress")
293  , m_pParent(pParent)
294  , m_xTabPage(pTabPage)
295  , m_xFtTakeFile(m_xBuilder->weld_label("file"))
296  , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
297 {
298  m_xBtnCancel->connect_clicked(LINK(this, TakeProgress, ClickCancelBtn));
299 }
300 
302 {
303 }
304 
305 IMPL_LINK_NOARG(TakeProgress, ClickCancelBtn, weld::Button&, void)
306 {
307  if (maTakeThread.is())
308  maTakeThread->terminate();
309 }
310 
311 
312 IMPL_LINK_NOARG(TakeProgress, CleanUpHdl, void*, void)
313 {
314  if (maTakeThread.is())
315  maTakeThread->join();
316 
317  std::vector<bool, std::allocator<bool> > aRemoveEntries(m_xTabPage->aFoundList.size(), false);
318  std::vector< OUString > aRemainingVector;
319  sal_uInt32 i, nCount;
320 
321  std::unique_ptr<weld::WaitObject> xWait(new weld::WaitObject(m_pParent));
322 
323  m_xTabPage->m_xLbxFound->select(-1);
324  m_xTabPage->m_xLbxFound->freeze();
325 
326  // mark all taken positions in aRemoveEntries
327  for( i = 0, nCount = maTakenList.size(); i < nCount; ++i )
328  aRemoveEntries[ maTakenList[ i ] ] = true;
329  maTakenList.clear();
330 
331  // refill found list
332  for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
333  if( !aRemoveEntries[ i ] )
334  aRemainingVector.push_back( m_xTabPage->aFoundList[i] );
335 
336  m_xTabPage->aFoundList.clear();
337 
338  for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
339  m_xTabPage->aFoundList.push_back( aRemainingVector[ i ] );
340 
341  aRemainingVector.clear();
342 
343  // refill list box
344  for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
345  if( !aRemoveEntries[ i ] )
346  aRemainingVector.push_back(m_xTabPage->m_xLbxFound->get_text(i));
347 
348  m_xTabPage->m_xLbxFound->clear();
349 
350  for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
351  m_xTabPage->m_xLbxFound->append_text(aRemainingVector[i]);
352 
353  aRemainingVector.clear();
354 
355  m_xTabPage->m_xLbxFound->thaw();
356  m_xTabPage->SelectFoundHdl( *m_xTabPage->m_xLbxFound );
357 
358  xWait.reset();
359 
360  m_xDialog->response(RET_OK);
361 }
362 
364 {
365  assert(!maTakeThread.is());
367  maTakeThread->launch();
368 }
369 
371  : GenericDialogController(pWindow, "cui/ui/galleryupdateprogress.ui",
372  "GalleryUpdateProgress")
373  , pIdle(nullptr)
374  , pTheme(pThm)
375  , m_xFtActualizeFile(m_xBuilder->weld_label("file"))
376  , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
377 {
378  m_xBtnCancel->connect_clicked(LINK(this, ActualizeProgress, ClickCancelBtn));
379 }
380 
382 {
383 }
384 
386 {
387  pIdle = new Idle("ActualizeProgressTimeout");
388  pIdle->SetInvokeHandler( LINK( this, ActualizeProgress, TimeoutHdl ) );
389  pIdle->SetPriority( TaskPriority::LOWEST );
390  pIdle->Start();
391 
392  return GenericDialogController::run();
393 }
394 
396 {
397  pTheme->AbortActualize();
398  m_xDialog->response(RET_OK);
399 }
400 
401 IMPL_LINK( ActualizeProgress, TimeoutHdl, Timer*, _pTimer, void)
402 {
403  if (_pTimer)
404  {
405  _pTimer->Stop();
406  delete _pTimer;
407  }
408 
409  pTheme->Actualize(LINK(this, ActualizeProgress, ActualizeHdl), &aStatusProgress);
410  ClickCancelBtn(*m_xBtnCancel);
411 }
412 
413 IMPL_LINK( ActualizeProgress, ActualizeHdl, const INetURLObject&, rURL, void )
414 {
416  m_xFtActualizeFile->set_label(GetReducedString(rURL, 30));
417 }
418 
419 TitleDialog::TitleDialog(weld::Window* pParent, const OUString& rOldTitle)
420  : GenericDialogController(pParent, "cui/ui/gallerytitledialog.ui", "GalleryTitleDialog")
421  , m_xEdit(m_xBuilder->weld_entry("entry"))
422 {
423  m_xEdit->set_text(rOldTitle);
424  m_xEdit->grab_focus();
425 }
426 
428 {
429 }
430 
432  : GenericDialogController(pParent, "cui/ui/gallerythemeiddialog.ui", "GalleryThemeIDDialog")
433  , m_pThm(_pThm)
434  , m_xBtnOk(m_xBuilder->weld_button("ok"))
435  , m_xLbResName(m_xBuilder->weld_combo_box("entry"))
436 {
437  m_xLbResName->append_text("!!! No Id !!!");
438 
440 
441  m_xLbResName->set_active(m_pThm->GetId());
442  m_xLbResName->grab_focus();
443 
444  m_xBtnOk->connect_clicked(LINK(this, GalleryIdDialog, ClickOkHdl));
445 }
446 
448 {
449 }
450 
452 {
453  Gallery* pGal = m_pThm->GetParent();
454  const sal_uLong nId = GetId();
455  bool bDifferentThemeExists = false;
456 
457  for( sal_uLong i = 0, nCount = pGal->GetThemeCount(); i < nCount && !bDifferentThemeExists; i++ )
458  {
459  const GalleryThemeEntry* pInfo = pGal->GetThemeInfo( i );
460 
461  if ((pInfo->GetId() == nId) && (pInfo->GetThemeName() != m_pThm->GetName()))
462  {
463  OUString aStr( CuiResId( RID_SVXSTR_GALLERY_ID_EXISTS ) );
464 
465  aStr += " (" + 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(pParent, "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 
578 {
579  return VclPtr<TPGalleryThemeGeneral>::Create(pParent, *rSet);
580 }
581 
583  : SfxTabPage(pWindow, "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  disposeOnce();
640 }
641 
643 {
644  xMediaPlayer.clear();
645  xDialogListener.clear();
646  aFilterEntryList.clear();
648 }
649 
651 {
652  return VclPtr<TPGalleryThemeProperties>::Create(pParent, *rSet);
653 }
654 
655 OUString TPGalleryThemeProperties::addExtension( const OUString& _rDisplayText, const OUString& _rExtension )
656 {
657  OUString sRet = _rDisplayText;
658  if ( sRet.indexOf( "(*.*)" ) == -1 )
659  {
660  sRet += " (" + _rExtension + ")";
661  }
662  return sRet;
663 }
664 
666 {
668  OUString aExt;
669  OUString aName;
670  sal_uInt16 i, nKeyCount;
671 
672  // graphic filters
673  for( i = 0, nKeyCount = rFilter.GetImportFormatCount(); i < nKeyCount; i++ )
674  {
675  aExt = rFilter.GetImportFormatShortName( i );
676  aName = rFilter.GetImportFormatName( i );
677  size_t entryIndex = 0;
678  FilterEntry* pTestEntry = aFilterEntryList.empty() ? nullptr : aFilterEntryList[ entryIndex ].get();
679  bool bInList = false;
680 
681  OUString aExtensions;
682  int j = 0;
683  OUString sWildcard;
684  while( true )
685  {
686  sWildcard = rFilter.GetImportWildcard( i, j++ );
687  if ( sWildcard.isEmpty() )
688  break;
689  if ( aExtensions.indexOf( sWildcard ) == -1 )
690  {
691  if ( !aExtensions.isEmpty() )
692  aExtensions += ";";
693  aExtensions += sWildcard;
694  }
695  }
696  aName = addExtension( aName, aExtensions );
697 
698  while( pTestEntry )
699  {
700  if ( pTestEntry->aFilterName == aExt )
701  {
702  bInList = true;
703  break;
704  }
705  pTestEntry = ( ++entryIndex < aFilterEntryList.size() )
706  ? aFilterEntryList[ entryIndex ].get() : nullptr;
707  }
708  if ( !bInList )
709  {
710  std::unique_ptr<FilterEntry> pFilterEntry(new FilterEntry);
711  pFilterEntry->aFilterName = aExt;
712  m_xCbbFileType->append_text(aName);
713  aFilterEntryList.push_back(std::move(pFilterEntry));
714  }
715  }
716 
717 #if HAVE_FEATURE_AVMEDIA
718  // media filters
719  static const char aWildcard[] = "*.";
722 
723  for(std::pair<OUString,OUString> & aFilter : aFilters)
724  {
725  for( sal_Int32 nIndex = 0; nIndex >= 0; )
726  {
727  OUString aFilterWildcard( aWildcard );
728 
729  std::unique_ptr<FilterEntry> pFilterEntry(new FilterEntry);
730  pFilterEntry->aFilterName = aFilter.second.getToken( 0, ';', nIndex );
731  aFilterWildcard += pFilterEntry->aFilterName;
732  m_xCbbFileType->append_text(addExtension(aFilter.first, aFilterWildcard));
733  aFilterEntryList.push_back( std::move(pFilterEntry) );
734  }
735  }
736 #endif
737 
738  // 'All' filters
739  OUString aExtensions;
740 
741  // graphic filters
742  for ( i = 0; i < nKeyCount; ++i )
743  {
744  int j = 0;
745  OUString sWildcard;
746  while( true )
747  {
748  sWildcard = rFilter.GetImportWildcard( i, j++ );
749  if ( sWildcard.isEmpty() )
750  break;
751  if ( aExtensions.indexOf( sWildcard ) == -1 )
752  {
753  if ( !aExtensions.isEmpty() )
754  aExtensions += ";";
755 
756  aExtensions += sWildcard;
757  }
758  }
759  }
760 
761 #if HAVE_FEATURE_AVMEDIA
762  // media filters
763  for(std::pair<OUString,OUString> & aFilter : aFilters)
764  {
765  for( sal_Int32 nIndex = 0; nIndex >= 0; )
766  {
767  if ( !aExtensions.isEmpty() )
768  aExtensions += ";";
769  aExtensions += aWildcard + aFilter.second.getToken( 0, ';', nIndex );
770  }
771  }
772 #endif
773 
774 #if defined(_WIN32)
775  if (aExtensions.getLength() > 240)
776  aExtensions = "*.*";
777 #endif
778 
779  std::unique_ptr<FilterEntry> pFilterEntry(new FilterEntry);
780  pFilterEntry->aFilterName = CuiResId(RID_SVXSTR_GALLERY_ALLFILES);
781  pFilterEntry->aFilterName = addExtension(pFilterEntry->aFilterName, aExtensions);
782  m_xCbbFileType->insert_text(0, pFilterEntry->aFilterName);
783  m_xCbbFileType->set_active(0);
784  aFilterEntryList.insert(aFilterEntryList.begin(), std::move(pFilterEntry));
785 }
786 
788 {
789  OUString aText(m_xCbbFileType->get_active_text());
790 
791  if( bInputAllowed && ( aLastFilterName != aText ) )
792  {
793  aLastFilterName = aText;
794 
795  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/queryupdategalleryfilelistdialog.ui"));
796  std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("QueryUpdateFileListDialog"));
797  if (xQuery->run() == RET_YES)
798  SearchFiles();
799  }
800 }
801 
803 {
804  std::shared_ptr<SearchProgress> xProgress(new SearchProgress(GetDialogFrameWeld(), this, aURL));
805 
806  aFoundList.clear();
807  m_xLbxFound->clear();
808 
809  xProgress->SetFileType( m_xCbbFileType->get_active_text() );
810  xProgress->SetDirectory( INetURLObject() );
811 
812  xProgress->LaunchThread();
813  weld::DialogController::runAsync(xProgress, [this](sal_Int32 nResult) {
814  EndSearchProgressHdl(nResult);
815  });
816 }
817 
819 {
820  if( bInputAllowed )
821  {
822  try
823  {
824  // setup folder picker
825  css::uno::Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
826  xFolderPicker = FolderPicker::create(xContext);
827 
828  OUString aDlgPathName( SvtPathOptions().GetGraphicPath() );
829  xFolderPicker->setDisplayDirectory(aDlgPathName);
830 
831  aPreviewTimer.Stop();
832 
833  css::uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
834  if ( xAsyncDlg.is() )
835  xAsyncDlg->startExecuteModal( xDialogListener.get() );
836  else
837  {
838  if( xFolderPicker->execute() == RET_OK )
839  {
840  aURL = INetURLObject( xFolderPicker->getDirectory() );
841  bSearchRecursive = true; // UI choice no longer possible, windows file picker allows no user controls
842  SearchFiles();
843  }
844  }
845  }
846  catch (const IllegalArgumentException&)
847  {
848  OSL_FAIL( "Folder picker failed with illegal arguments" );
849  }
850  }
851 }
852 
854 {
855  if (m_xLbxFound->count_selected_rows() || (bTakeAll && bEntriesFound))
856  {
857  std::shared_ptr<TakeProgress> xTakeProgress(new TakeProgress(GetDialogFrameWeld(), this));
858  xTakeProgress->LaunchThread();
859  weld::DialogController::runAsync(xTakeProgress, [=](sal_Int32 /*nResult*/) {
860  /* no postprocessing needed, pTakeProgress
861  will be disposed in TakeProgress::CleanupHdl */
862  });
863 
864  }
865 }
866 
868 {
869  if ( bInputAllowed )
870  {
871  aPreviewTimer.Stop();
872  aPreviewString.clear();
873 
874  if (!m_xCbxPreview->get_active())
875  {
876  xMediaPlayer.clear();
877  m_aWndPreview.SetGraphic(Graphic());
878  m_aWndPreview.Invalidate();
879  }
880  else
881  DoPreview();
882  }
883 }
884 
886 {
887  int nIndex = m_xLbxFound->get_selected_index();
888  OUString aString(m_xLbxFound->get_text(nIndex));
889 
890  if (aString != aPreviewString)
891  {
892  INetURLObject _aURL(aFoundList[nIndex]);
893  bInputAllowed = false;
894 
895  if (!m_aWndPreview.SetGraphic(_aURL))
896  {
897  GetParent()->LeaveWait();
899  GetParent()->EnterWait();
900  }
901 #if HAVE_FEATURE_AVMEDIA
903  {
905  if( xMediaPlayer.is() )
906  xMediaPlayer->start();
907  }
908 #endif
909  bInputAllowed = true;
910  aPreviewString = aString;
911  }
912 }
913 
915 {
916  if( bInputAllowed )
917  {
918  aPreviewTimer.Stop();
919 
920  if (!m_xLbxFound->count_selected_rows() || !bEntriesFound)
921  {
922  SvxOpenGraphicDialog aDlg(CuiResId(RID_SVXSTR_KEY_GALLERY_DIR), GetDialogFrameWeld());
923  aDlg.EnableLink(false);
924  aDlg.AsLink(false);
925 
926  if( !aDlg.Execute() )
927  pData->pTheme->InsertURL( INetURLObject( aDlg.GetPath() ) );
928  }
929  else
930  {
931  bTakeAll = false;
932  TakeFiles();
933  }
934  }
935 }
936 
938 {
939  if( bInputAllowed )
940  {
941  aPreviewTimer.Stop();
942  bTakeAll = true;
943  TakeFiles();
944  }
945 }
946 
948 {
949  if (bInputAllowed)
950  {
951  bool bPreviewPossible = false;
952 
953  aPreviewTimer.Stop();
954 
955  if( bEntriesFound )
956  {
957  if (m_xLbxFound->count_selected_rows() == 1)
958  {
959  m_xCbxPreview->set_sensitive(true);
960  bPreviewPossible = true;
961  }
962  else
963  m_xCbxPreview->set_sensitive(false);
964 
965  if( !aFoundList.empty() )
966  m_xBtnTakeAll->set_sensitive(true);
967  else
968  m_xBtnTakeAll->set_sensitive(false);
969  }
970 
971  if (bPreviewPossible && m_xCbxPreview->get_active())
972  aPreviewTimer.Start();
973  }
974 }
975 
977 {
978  if( bInputAllowed )
979  {
980  aPreviewTimer.Stop();
981 
982  if (m_xLbxFound->count_selected_rows() == 1 && bEntriesFound)
983  ClickTakeHdl(*m_xBtnTake);
984  }
985 }
986 
988 {
989  aPreviewTimer.Stop();
990  DoPreview();
991 }
992 
994 {
995  if( !aFoundList.empty() )
996  {
997  m_xLbxFound->select(0);
998  m_xBtnTakeAll->set_sensitive(true);
999  m_xCbxPreview->set_sensitive(true);
1000  bEntriesFound = true;
1001  }
1002  else
1003  {
1004  m_xLbxFound->append_text(CuiResId(RID_SVXSTR_GALLERY_NOFILES));
1005  m_xBtnTakeAll->set_sensitive(false);
1006  m_xCbxPreview->set_sensitive(false);
1007  bEntriesFound = false;
1008  }
1009 }
1010 
1011 IMPL_LINK( TPGalleryThemeProperties, DialogClosedHdl, css::ui::dialogs::DialogClosedEvent*, pEvt, void )
1012 {
1013  DBG_ASSERT( xFolderPicker.is(), "TPGalleryThemeProperties::DialogClosedHdl(): no folder picker" );
1014 
1015  OUString sURL = xFolderPicker->getDirectory();
1016  StartSearchFiles( sURL, pEvt->DialogResult );
1017 }
1018 
1019 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::ComboBox > m_xCbbFileType
Definition: cuigaldlg.hxx:235
ExchangeData * pData
Definition: cuigaldlg.hxx:182
std::unique_ptr< weld::Button > m_xBtnOk
Definition: cuigaldlg.hxx:170
OUString GetReducedString(const INetURLObject &rURL, sal_Int32 nMaxLen)
bool IsDefault() const
sal_uInt32 GetId() const
TitleDialog(weld::Window *pParent, const OUString &rOldText)
Definition: cuigaldlg.cxx:419
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: cuigaldlg.hxx:78
css::uno::Reference< css::media::XPlayer > xMediaPlayer
Definition: cuigaldlg.hxx:231
const ExchangeData * GetXChgData() const
Definition: cuigaldlg.hxx:269
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: cuigaldlg.cxx:650
const INetURLObject & GetSdgURL() const
std::unique_ptr< weld::CheckButton > m_xCbxPreview
Definition: cuigaldlg.hxx:240
SearchProgress(weld::Window *pParent, TPGalleryThemeProperties *pTabPage, const INetURLObject &rStartURL)
Definition: cuigaldlg.cxx:189
sal_uIntPtr sal_uLong
SvxGalleryPreview m_aWndPreview
Definition: cuigaldlg.hxx:234
OUString GetImportFormatName(sal_uInt16 nFormat)
void RemoveTabPage(const OString &rName)
sal_Int16 nId
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
VclPtr< TPGalleryThemeProperties > m_xTabPage
Definition: cuigaldlg.hxx:117
static void InsertAllThemes(weld::ComboBox &rListBox)
std::unique_ptr< weld::Image > m_xFiMSImage
Definition: cuigaldlg.hxx:195
OUString GetPath() const
virtual short run() override
Definition: cuigaldlg.cxx:385
TakeProgress(weld::Window *pParent, TPGalleryThemeProperties *pTabPage)
Definition: cuigaldlg.cxx:290
TakeThread(TakeProgress *pProgress, TPGalleryThemeProperties *pBrowser, TokenList_impl &rTakenList)
Definition: cuigaldlg.cxx:226
void StartSearchFiles(const OUString &_rFolderURL, short _nDlgResult)
Definition: cuigaldlg.cxx:627
TPGalleryThemeProperties(TabPageParent pWindow, const SfxItemSet &rSet)
Definition: cuigaldlg.cxx:582
void SetXChgData(ExchangeData *pData)
Definition: cuigaldlg.cxx:519
#define ERRCODE_IO_NOTEXISTSPATH
std::unique_ptr< weld::Label > m_xFtMSShowContent
Definition: cuigaldlg.hxx:199
rtl::Reference< ::svt::DialogClosedListener > xDialogListener
Definition: cuigaldlg.hxx:230
OUString GetImportWildcard(sal_uInt16 nFormat, sal_Int32 nEntry)
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
TPGalleryThemeGeneral(TabPageParent pParent, const SfxItemSet &rSet)
Definition: cuigaldlg.cxx:507
const LocaleDataWrapper & GetLocaleData() const
virtual ~TitleDialog() override
Definition: cuigaldlg.cxx:427
RET_YES
virtual ~SearchProgress() override
Definition: cuigaldlg.cxx:201
OUString SvxResId(const char *pId)
void SetXChgData(ExchangeData *pData)
Definition: cuigaldlg.cxx:604
std::unique_ptr< weld::Label > m_xFtMSShowChangeDate
Definition: cuigaldlg.hxx:200
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:217
ExchangeData * pData
Definition: cuigaldlg.hxx:193
virtual void dispose() override
rtl::Reference< TakeThread > maTakeThread
Definition: cuigaldlg.hxx:118
TokenList_impl & mrTakenList
Definition: cuigaldlg.hxx:99
virtual ~GalleryIdDialog() override
Definition: cuigaldlg.cxx:447
SAL_DLLPRIVATE void LockBroadcaster()
::std::vector< ::std::pair< OUString, OUString > > FilterNameVector
sal_uInt16 GetImportFormatCount()
std::unique_ptr< weld::Label > m_xFtMSShowPath
Definition: cuigaldlg.hxx:198
static OUString addExtension(const OUString &, const OUString &)
Definition: cuigaldlg.cxx:655
static OUString GetImportFormatShortName(GraphicFileFormat nFormat)
virtual ~ActualizeProgress() override
Definition: cuigaldlg.cxx:381
sal_uInt32 GetId() const
std::vector< OUString > aFoundList
Definition: cuigaldlg.hxx:218
INetURLObject maStartURL
Definition: cuigaldlg.hxx:54
static bool Reschedule(bool bHandleAllCurrentEvents=false)
weld::Window * GetDialogFrameWeld() const
#define DBG_ASSERT(sCon, aError)
bool InsertURL(const INetURLObject &rURL, sal_uInt32 nInsertPos=SAL_MAX_UINT32)
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: cuigaldlg.hxx:143
void SetDirectory(const INetURLObject &rURL)
Definition: cuigaldlg.hxx:90
TokenList_impl maTakenList
Definition: cuigaldlg.hxx:119
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
int i
GalleryTheme * pTheme
void SetGraphic(const Graphic &rGraphic)
VclPtr< TPGalleryThemeProperties > m_xTabPage
Definition: cuigaldlg.hxx:74
virtual void execute() override
Definition: cuigaldlg.cxx:78
static void getMediaFilters(FilterNameVector &rFilterNameVector)
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: cuigaldlg.hxx:121
void SetFile(const INetURLObject &rURL)
Definition: cuigaldlg.hxx:133
VclPtr< TPGalleryThemeProperties > mpBrowser
Definition: cuigaldlg.hxx:53
SAL_DLLPRIVATE sal_uInt32 GetObjectCount() const
std::unique_ptr< weld::TreeView > m_xLbxFound
Definition: cuigaldlg.hxx:236
std::unique_ptr< weld::Button > m_xBtnTakeAll
Definition: cuigaldlg.hxx:239
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
void SetTimeout(sal_uInt64 nTimeoutMs)
void UnlockBroadcaster()
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
std::unique_ptr< weld::Entry > m_xEdit
Definition: cuigaldlg.hxx:159
ActualizeProgress(weld::Window *pWindow, GalleryTheme *pThm)
Definition: cuigaldlg.cxx:370
void LaunchThread()
Definition: cuigaldlg.cxx:219
std::unique_ptr< weld::ComboBox > m_xLbResName
Definition: cuigaldlg.hxx:171
void LaunchThread()
Definition: cuigaldlg.cxx:363
tools::Time aThemeChangeTime
OUString GetImportFormatShortName(sal_uInt16 nFormat)
SAL_DLLPRIVATE size_t GetThemeCount() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
friend class TakeProgress
Definition: cuigaldlg.hxx:214
OUString getDate(const Date &rDate) const
std::vector< std::unique_ptr< FilterEntry > > aFilterEntryList
Definition: cuigaldlg.hxx:220
virtual void execute() override
Definition: cuigaldlg.cxx:243
virtual ~TakeThread() override
Definition: cuigaldlg.cxx:239
Date aThemeChangeDate
TakeProgress * mpProgress
Definition: cuigaldlg.hxx:97
std::unique_ptr< weld::Button > m_xBtnSearch
Definition: cuigaldlg.hxx:237
GalleryThemeProperties(weld::Window *pParent, ExchangeData *pData, SfxItemSet const *pItemSet)
Definition: cuigaldlg.cxx:480
SAL_DLLPRIVATE const GalleryThemeEntry * GetThemeInfo(size_t nPos)
RET_OK
virtual void dispose() override
Definition: cuigaldlg.cxx:642
static VclPtr< reference_type > Create(Arg &&...arg)
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
IMPL_LINK(ActualizeProgress, TimeoutHdl, Timer *, _pTimer, void)
Definition: cuigaldlg.cxx:401
virtual ~TPGalleryThemeProperties() override
Definition: cuigaldlg.cxx:637
Reference< XComponentContext > getProcessComponentContext()
GalleryIdDialog(weld::Window *pParent, GalleryTheme *pThm)
Definition: cuigaldlg.cxx:431
void SetInvokeHandler(const Link< Timer *, void > &rLink)
std::unique_ptr< weld::Label > m_xFtSearchType
Definition: cuigaldlg.hxx:77
std::unique_ptr< weld::Entry > m_xEdtMSName
Definition: cuigaldlg.hxx:196
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
virtual ~TakeProgress() override
Definition: cuigaldlg.cxx:301
IMPL_LINK_NOARG(SearchProgress, ClickCancelBtn, weld::Button &, void)
Definition: cuigaldlg.cxx:205
OString const aName
void EndSearchProgressHdl(sal_Int32 nResult)
Definition: cuigaldlg.cxx:993
static GraphicFilter & GetGraphicFilter()
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
GraphicFileFormat GetFileFormat() const
std::unique_ptr< weld::Button > m_xBtnTake
Definition: cuigaldlg.hxx:238
void ImplSearch(const INetURLObject &rStartURL, const std::vector< OUString > &rFormats, bool bRecursive)
Definition: cuigaldlg.cxx:106
rtl::Reference< SearchThread > m_aSearchThread
Definition: cuigaldlg.hxx:75
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:52
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
SearchThread(SearchProgress *pProgress, TPGalleryThemeProperties *pBrowser, const INetURLObject &rStartURL)
Definition: cuigaldlg.cxx:64
bool IsReadOnly() const
bool Detect(bool bExtendedInfo=false)
virtual ~SearchThread() override
Definition: cuigaldlg.cxx:74
sal_Int32 nPos
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: cuigaldlg.cxx:577
GalleryTheme * m_pThm
Definition: cuigaldlg.hxx:169
aStr
const OUString & GetThemeName() const
VclPtr< TPGalleryThemeProperties > mpBrowser
Definition: cuigaldlg.hxx:98
OUString aEditedTitle
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: cuigaldlg.cxx:571
std::unique_ptr< weld::Label > m_xFtMSShowType
Definition: cuigaldlg.hxx:197
std::vector< sal_uLong > TokenList_impl
Definition: cuigaldlg.hxx:39
INetURLObject startUrl_
Definition: cuigaldlg.hxx:73
OUString sId