LibreOffice Module cui (master)  1
optpath.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 <svx/svxdlg.hxx>
21 #include <sfx2/filedlghelper.hxx>
22 #include <sfx2/app.hxx>
23 #include <tools/urlobj.hxx>
25 #include <unotools/pathoptions.hxx>
27 #include <unotools/viewoptions.hxx>
28 
29 #include <bitmaps.hlst>
30 #include <dialmgr.hxx>
31 #include <optpath.hxx>
32 #include <strings.hrc>
34 #include <comphelper/string.hxx>
35 #include <com/sun/star/uno/Exception.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
38 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
39 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
40 #include <com/sun/star/ui/dialogs/FilePicker.hpp>
41 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
42 #include <com/sun/star/util/thePathSettings.hpp>
43 #include <tools/diagnose_ex.h>
44 #include <sal/log.hxx>
45 
46 using namespace css;
47 using namespace css::beans;
48 using namespace css::lang;
49 using namespace css::ui::dialogs;
50 using namespace css::uno;
51 using namespace svx;
52 
53 // define ----------------------------------------------------------------
54 
55 #define POSTFIX_INTERNAL "_internal"
56 #define POSTFIX_USER "_user"
57 #define POSTFIX_WRITABLE "_writable"
58 #define VAR_ONE "%1"
59 #define IODLG_CONFIGNAME "FilePicker_Save"
60 
61 // struct OptPath_Impl ---------------------------------------------------
62 
64 {
66  OUString m_sMultiPathDlg;
67  Reference< css::util::XPathSettings > m_xPathSettings;
68 
70  : m_sMultiPathDlg(CuiResId(RID_SVXSTR_EDIT_PATHS))
71  {
72  }
73 };
74 
75 namespace {
76 
77 struct PathUserData_Impl
78 {
79  SvtPathOptions::Paths nRealId;
80  bool bItemStateSet;
81  OUString sUserPath;
82  OUString sWritablePath;
83  bool bReadOnly;
84 
85  explicit PathUserData_Impl(SvtPathOptions::Paths nId)
86  : nRealId(nId)
87  , bItemStateSet(false)
88  , bReadOnly(false)
89  {
90  }
91 };
92 
93 struct Handle2CfgNameMapping_Impl
94 {
96  const char* m_pCfgName;
97 };
98 
99 }
100 
101 Handle2CfgNameMapping_Impl const Hdl2CfgMap_Impl[] =
102 {
103  { SvtPathOptions::Paths::AutoCorrect, "AutoCorrect" },
104  { SvtPathOptions::Paths::AutoText, "AutoText" },
105  { SvtPathOptions::Paths::Backup, "Backup" },
106  { SvtPathOptions::Paths::Gallery, "Gallery" },
107  { SvtPathOptions::Paths::Graphic, "Graphic" },
108  { SvtPathOptions::Paths::Temp, "Temp" },
109  { SvtPathOptions::Paths::Template, "Template" },
110  { SvtPathOptions::Paths::Work, "Work" },
111  { SvtPathOptions::Paths::Dictionary, "Dictionary" },
112  { SvtPathOptions::Paths::Classification, "Classification" },
113 #if OSL_DEBUG_LEVEL > 1
114  { SvtPathOptions::Paths::Linguistic, "Linguistic" },
115 #endif
116  { SvtPathOptions::Paths::LAST, nullptr }
117 };
118 
119 static OUString getCfgName_Impl( SvtPathOptions::Paths _nHandle )
120 {
121  OUString sCfgName;
122  sal_uInt16 nIndex = 0;
123  while ( Hdl2CfgMap_Impl[ nIndex ].m_nHandle != SvtPathOptions::Paths::LAST )
124  {
125  if ( Hdl2CfgMap_Impl[ nIndex ].m_nHandle == _nHandle )
126  {
127  // config name found
128  sCfgName = OUString::createFromAscii( Hdl2CfgMap_Impl[ nIndex ].m_pCfgName );
129  break;
130  }
131  ++nIndex;
132  }
133 
134  return sCfgName;
135 }
136 
137 #define MULTIPATH_DELIMITER ';'
138 
139 static OUString Convert_Impl( const OUString& rValue )
140 {
141  if (rValue.isEmpty())
142  return OUString();
143 
144  sal_Int32 nPos = 0;
145  OUStringBuffer aReturn;
146  for (;;)
147  {
148  OUString aValue = rValue.getToken( 0, MULTIPATH_DELIMITER, nPos );
149  INetURLObject aObj( aValue );
150  if ( aObj.GetProtocol() == INetProtocol::File )
151  aReturn.append(aObj.PathToFileName());
152  if ( nPos < 0 )
153  break;
154  aReturn.append(MULTIPATH_DELIMITER);
155  }
156 
157  return aReturn.makeStringAndClear();
158 }
159 
160 // functions -------------------------------------------------------------
161 
162 static bool IsMultiPath_Impl( const SvtPathOptions::Paths nIndex )
163 {
164 #if OSL_DEBUG_LEVEL > 1
165  return ( SvtPathOptions::Paths::AutoCorrect == nIndex ||
167  SvtPathOptions::Paths::Basic == nIndex ||
168  SvtPathOptions::Paths::Gallery == nIndex ||
170 #else
171  return ( SvtPathOptions::Paths::AutoCorrect == nIndex ||
173  SvtPathOptions::Paths::Basic == nIndex ||
174  SvtPathOptions::Paths::Gallery == nIndex ||
178 #endif
179 }
180 
181 // class SvxPathTabPage --------------------------------------------------
182 
184  : SfxTabPage( pPage, pController, "cui/ui/optpathspage.ui", "OptPathsPage", &rSet)
185  , pImpl(new OptPath_Impl)
186  , xDialogListener ( new ::svt::DialogClosedListener() )
187  , m_xStandardBtn(m_xBuilder->weld_button("default"))
188  , m_xPathBtn(m_xBuilder->weld_button("edit"))
189  , m_xPathBox(m_xBuilder->weld_tree_view("paths"))
190 {
191  m_xStandardBtn->connect_clicked(LINK(this, SvxPathTabPage, StandardHdl_Impl));
192  m_xPathBtn->connect_clicked( LINK( this, SvxPathTabPage, PathHdl_Impl ) );
193 
194  m_xPathBox->set_size_request(m_xPathBox->get_approximate_digit_width() * 60,
195  m_xPathBox->get_height_rows(20));
196 
197  m_xPathBox->connect_row_activated( LINK( this, SvxPathTabPage, DoubleClickPathHdl_Impl ) );
198  m_xPathBox->connect_column_clicked(LINK(this, SvxPathTabPage, HeaderBarClick));
199  m_xPathBox->connect_changed( LINK( this, SvxPathTabPage, PathSelect_Impl ) );
200  m_xPathBox->set_selection_mode(SelectionMode::Multiple);
201 
202  xDialogListener->SetDialogClosedLink( LINK( this, SvxPathTabPage, DialogClosedHdl ) );
203 }
204 
205 IMPL_LINK(SvxPathTabPage, HeaderBarClick, int, nColumn, void)
206 {
207  bool bSortAtoZ = !m_xPathBox->get_sort_order();
208  m_xPathBox->set_sort_order(bSortAtoZ);
209  m_xPathBox->set_sort_indicator(bSortAtoZ ? TRISTATE_TRUE : TRISTATE_FALSE, nColumn);
210 }
211 
213 {
214  for (int i = 0, nEntryCount = m_xPathBox->n_children(); i < nEntryCount; ++i)
215  delete reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(i).toInt64());
216 }
217 
218 std::unique_ptr<SfxTabPage> SvxPathTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
219  const SfxItemSet* rAttrSet )
220 {
221  return std::make_unique<SvxPathTabPage>( pPage, pController, *rAttrSet );
222 }
223 
225 {
226  for (int i = 0, nEntryCount = m_xPathBox->n_children(); i < nEntryCount; ++i)
227  {
228  PathUserData_Impl* pPathImpl = reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(i).toInt64());
229  SvtPathOptions::Paths nRealId = pPathImpl->nRealId;
230  if (pPathImpl->bItemStateSet )
231  SetPathList( nRealId, pPathImpl->sUserPath, pPathImpl->sWritablePath );
232  }
233  return true;
234 }
235 
237 {
238  m_xPathBox->clear();
239  m_xPathBox->make_unsorted();
240 
241  std::unique_ptr<weld::TreeIter> xIter = m_xPathBox->make_iterator();
242  for( sal_uInt16 i = 0; i <= sal_uInt16(SvtPathOptions::Paths::Classification); ++i )
243  {
244  // only writer uses autotext
245  if ( static_cast<SvtPathOptions::Paths>(i) == SvtPathOptions::Paths::AutoText
247  continue;
248 
249  const char* pId = nullptr;
250 
251  switch (static_cast<SvtPathOptions::Paths>(i))
252  {
254  pId = RID_SVXSTR_KEY_AUTOCORRECT_DIR;
255  break;
257  pId = RID_SVXSTR_KEY_GLOSSARY_PATH;
258  break;
260  pId = RID_SVXSTR_KEY_BACKUP_PATH;
261  break;
263  pId = RID_SVXSTR_KEY_GALLERY_DIR;
264  break;
266  pId = RID_SVXSTR_KEY_GRAPHICS_PATH;
267  break;
269  pId = RID_SVXSTR_KEY_TEMP_PATH;
270  break;
272  pId = RID_SVXSTR_KEY_TEMPLATE_PATH;
273  break;
275  pId = RID_SVXSTR_KEY_DICTIONARY_PATH;
276  break;
278  pId = RID_SVXSTR_KEY_CLASSIFICATION_PATH;
279  break;
280 #if OSL_DEBUG_LEVEL > 1
282  pId = RID_SVXSTR_KEY_LINGUISTIC_DIR;
283  break;
284 #endif
286  pId = RID_SVXSTR_KEY_WORK_PATH;
287  break;
288  default: break;
289  }
290 
291  if (pId)
292  {
293  m_xPathBox->append(xIter.get());
294 
295  OUString aStr(CuiResId(pId));
296  m_xPathBox->set_text(*xIter, aStr, 0);
297 
298  OUString sInternal, sUser, sWritable;
299  bool bReadOnly = false;
300  GetPathList( static_cast<SvtPathOptions::Paths>(i), sInternal, sUser, sWritable, bReadOnly );
301 
302  if (bReadOnly)
303  m_xPathBox->set_image(*xIter, RID_SVXBMP_LOCK);
304 
305  OUString sTmpPath = sUser;
306  if ( !sTmpPath.isEmpty() && !sWritable.isEmpty() )
307  sTmpPath += OUStringChar(MULTIPATH_DELIMITER);
308  sTmpPath += sWritable;
309  const OUString aValue = Convert_Impl( sTmpPath );
310 
311  m_xPathBox->set_text(*xIter, aValue, 1);
312 
313  const OUString aValueInternal = Convert_Impl( sInternal );
314 
315  m_xPathBox->set_text(*xIter, aValueInternal, 2);
316 
317  m_xPathBox->set_sensitive(*xIter, !bReadOnly, 0);
318  m_xPathBox->set_sensitive(*xIter, !bReadOnly, 1);
319  m_xPathBox->set_sensitive(*xIter, !bReadOnly, 2);
320 
321  PathUserData_Impl* pPathImpl = new PathUserData_Impl(static_cast<SvtPathOptions::Paths>(i));
322  pPathImpl->sUserPath = sUser;
323  pPathImpl->sWritablePath = sWritable;
324  pPathImpl->bReadOnly = bReadOnly;
325 
326  OUString sId = OUString::number(reinterpret_cast<sal_Int64>(pPathImpl));
327  m_xPathBox->set_id(*xIter, sId);
328  }
329  }
330 
331  m_xPathBox->columns_autosize();
332  m_xPathBox->make_sorted();
333  PathSelect_Impl(*m_xPathBox);
334 }
335 
337 {
338  bool bEnable = false;
339  int nEntry = m_xPathBox->get_selected_index();
340  if (nEntry != -1)
341  {
342  PathUserData_Impl* pPathImpl = reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(nEntry).toInt64());
343  bEnable = !pPathImpl->bReadOnly;
344  }
345  sal_uInt16 nSelCount = m_xPathBox->count_selected_rows();
346  m_xPathBtn->set_sensitive(1 == nSelCount && bEnable);
347  m_xStandardBtn->set_sensitive(nSelCount > 0 && bEnable);
348 }
349 
350 IMPL_LINK_NOARG(SvxPathTabPage, StandardHdl_Impl, weld::Button&, void)
351 {
352  m_xPathBox->selected_foreach([this](weld::TreeIter& rEntry){
353  PathUserData_Impl* pPathImpl = reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(rEntry).toInt64());
354  OUString aOldPath = pImpl->m_aDefOpt.GetDefaultPath( pPathImpl->nRealId );
355 
356  if ( !aOldPath.isEmpty() )
357  {
358  OUString sInternal, sUser, sWritable, sTemp;
359  bool bReadOnly = false;
360  GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
361 
362  sal_Int32 nOldPos = 0;
363  do
364  {
365  bool bFound = false;
366  const OUString sOnePath = aOldPath.getToken( 0, MULTIPATH_DELIMITER, nOldPos );
367  if ( !sInternal.isEmpty() )
368  {
369  sal_Int32 nInternalPos = 0;
370  do
371  {
372  if ( sInternal.getToken( 0, MULTIPATH_DELIMITER, nInternalPos ) == sOnePath )
373  bFound = true;
374  }
375  while ( !bFound && nInternalPos >= 0 );
376  }
377  if ( !bFound )
378  {
379  if ( !sTemp.isEmpty() )
380  sTemp += OUStringChar(MULTIPATH_DELIMITER);
381  sTemp += sOnePath;
382  }
383  }
384  while ( nOldPos >= 0 );
385 
386  OUString sWritablePath;
387  OUStringBuffer sUserPath;
388  if ( !sTemp.isEmpty() )
389  {
390  sal_Int32 nNextPos = 0;
391  for (;;)
392  {
393  const OUString sToken = sTemp.getToken( 0, MULTIPATH_DELIMITER, nNextPos );
394  if ( nNextPos<0 )
395  {
396  // Last token need a different handling
397  sWritablePath = sToken;
398  break;
399  }
400  if ( !sUserPath.isEmpty() )
401  sUserPath.append(MULTIPATH_DELIMITER);
402  sUserPath.append(sToken);
403  }
404  }
405  m_xPathBox->set_text(rEntry, Convert_Impl(sTemp), 1);
406  pPathImpl->bItemStateSet = true;
407  pPathImpl->sUserPath = sUserPath.makeStringAndClear();
408  pPathImpl->sWritablePath = sWritablePath;
409  }
410  return false;
411  });
412 }
413 
414 void SvxPathTabPage::ChangeCurrentEntry( const OUString& _rFolder )
415 {
416  int nEntry = m_xPathBox->get_cursor_index();
417  if (nEntry == -1)
418  {
419  SAL_WARN( "cui.options", "SvxPathTabPage::ChangeCurrentEntry(): no entry" );
420  return;
421  }
422 
423  OUString sInternal, sUser, sWritable;
424  PathUserData_Impl* pPathImpl = reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(nEntry).toInt64());
425  bool bReadOnly = false;
426  GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
427  sUser = pPathImpl->sUserPath;
428  sWritable = pPathImpl->sWritablePath;
429 
430  // old path is a URL?
431  INetURLObject aObj( sWritable );
432  bool bURL = ( aObj.GetProtocol() != INetProtocol::NotValid );
433  INetURLObject aNewObj( _rFolder );
434  aNewObj.removeFinalSlash();
435 
436  // then the new path also a URL else system path
437  OUString sNewPathStr = bURL ? _rFolder : aNewObj.getFSysPath( FSysStyle::Detect );
438 
439  bool bChanged =
440 #ifdef UNX
441 // Unix is case sensitive
442  ( sNewPathStr != sWritable );
443 #else
444  !sNewPathStr.equalsIgnoreAsciiCase( sWritable );
445 #endif
446 
447  if ( !bChanged )
448  return;
449 
450  m_xPathBox->set_text(nEntry, Convert_Impl(sNewPathStr), 1);
451  pPathImpl->bItemStateSet = true;
452  pPathImpl->sWritablePath = sNewPathStr;
453  if ( SvtPathOptions::Paths::Work == pPathImpl->nRealId )
454  {
455  // Remove view options entry so the new work path
456  // will be used for the next open dialog.
457  SvtViewOptions aDlgOpt( EViewType::Dialog, IODLG_CONFIGNAME );
458  aDlgOpt.Delete();
459  // Reset also last used dir in the sfx application instance
460  SfxApplication *pSfxApp = SfxGetpApp();
461  pSfxApp->ResetLastDir();
462  }
463 }
464 
465 IMPL_LINK_NOARG(SvxPathTabPage, DoubleClickPathHdl_Impl, weld::TreeView&, bool)
466 {
467  PathHdl_Impl(*m_xPathBtn);
468  return true;
469 }
470 
472 {
473  int nEntry = m_xPathBox->get_cursor_index();
474  PathUserData_Impl* pPathImpl = nEntry != -1 ? reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(nEntry).toInt64()) : nullptr;
475  if (!pPathImpl || pPathImpl->bReadOnly)
476  return;
477 
478  SvtPathOptions::Paths nPos = pPathImpl->nRealId;
479  OUString sInternal, sUser, sWritable;
480  bool bPickFile = false;
481  bool bReadOnly = false;
482  GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
483  sUser = pPathImpl->sUserPath;
484  sWritable = pPathImpl->sWritablePath;
485  bPickFile = pPathImpl->nRealId == SvtPathOptions::Paths::Classification;
486 
487  if (IsMultiPath_Impl(nPos))
488  {
492 
493  OUString sPath( sUser );
494  if ( !sPath.isEmpty() )
495  sPath += OUStringChar(MULTIPATH_DELIMITER);
496  sPath += sWritable;
497  pMultiDlg->SetPath( sPath );
498 
499  const OUString sPathName = m_xPathBox->get_text(nEntry, 0);
500  const OUString sNewTitle = pImpl->m_sMultiPathDlg.replaceFirst( VAR_ONE, sPathName );
501  pMultiDlg->SetTitle( sNewTitle );
502 
503  if (pMultiDlg->Execute() == RET_OK)
504  {
505  sUser.clear();
506  sWritable.clear();
507  OUString sFullPath;
508  OUString sNewPath = pMultiDlg->GetPath();
509  if ( !sNewPath.isEmpty() )
510  {
511  sal_Int32 nNextPos = 0;
512  for (;;)
513  {
514  const OUString sToken(sNewPath.getToken( 0, MULTIPATH_DELIMITER, nNextPos ));
515  if ( nNextPos<0 )
516  {
517  // Last token need a different handling
518  sWritable = sToken;
519  break;
520  }
521  if ( !sUser.isEmpty() )
522  sUser += OUStringChar(MULTIPATH_DELIMITER);
523  sUser += sToken;
524  }
525  sFullPath = sUser;
526  if ( !sFullPath.isEmpty() )
527  sFullPath += OUStringChar(MULTIPATH_DELIMITER);
528  sFullPath += sWritable;
529  }
530 
531  m_xPathBox->set_text(nEntry, Convert_Impl(sFullPath), 1);
532  // save modified flag
533  pPathImpl->bItemStateSet = true;
534  pPathImpl->sUserPath = sUser;
535  pPathImpl->sWritablePath = sWritable;
536  }
537  }
538  else if (!bPickFile)
539  {
540  try
541  {
543  xFolderPicker = FolderPicker::create(xContext);
544 
545  INetURLObject aURL( sWritable, INetProtocol::File );
546  xFolderPicker->setDisplayDirectory( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
547 
548  Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
549  if ( xAsyncDlg.is() )
550  xAsyncDlg->startExecuteModal( xDialogListener );
551  else
552  {
553  short nRet = xFolderPicker->execute();
554  if (ExecutableDialogResults::OK != nRet)
555  return;
556 
557  OUString sFolder(xFolderPicker->getDirectory());
558  ChangeCurrentEntry(sFolder);
559  }
560  }
561  catch( Exception const & )
562  {
563  TOOLS_WARN_EXCEPTION( "cui.options", "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
564  }
565  }
566  else
567  {
568  try
569  {
570  uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
571  uno::Reference<ui::dialogs::XFilePicker3> xFilePicker = ui::dialogs::FilePicker::createWithMode(xComponentContext, ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE);
572  xFilePicker->appendFilter(OUString(), "*.xml");
573  if (xFilePicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
574  {
575  uno::Sequence<OUString> aPathSeq(xFilePicker->getSelectedFiles());
576  ChangeCurrentEntry(aPathSeq[0]);
577  }
578  }
579  catch (const uno::Exception&)
580  {
581  DBG_UNHANDLED_EXCEPTION("cui.options", "exception from file picker");
582  }
583  }
584 }
585 
586 IMPL_LINK( SvxPathTabPage, DialogClosedHdl, DialogClosedEvent*, pEvt, void )
587 {
588  if (RET_OK == pEvt->DialogResult)
589  {
590  assert(xFolderPicker.is() && "SvxPathTabPage::DialogClosedHdl(): no folder picker");
591  OUString sURL = xFolderPicker->getDirectory();
592  ChangeCurrentEntry( sURL );
593  }
594 }
595 
597  SvtPathOptions::Paths _nPathHandle, OUString& _rInternalPath,
598  OUString& _rUserPath, OUString& _rWritablePath, bool& _rReadOnly )
599 {
600  OUString sCfgName = getCfgName_Impl( _nPathHandle );
601 
602  try
603  {
604  // load PathSettings service if necessary
605  if ( !pImpl->m_xPathSettings.is() )
606  {
608  pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
609  }
610 
611  // load internal paths
612  Any aAny = pImpl->m_xPathSettings->getPropertyValue(
613  sCfgName + POSTFIX_INTERNAL);
614  Sequence< OUString > aPathSeq;
615  if ( aAny >>= aPathSeq )
616  {
617  tools::Long i, nCount = aPathSeq.getLength();
618  const OUString* pPaths = aPathSeq.getConstArray();
619 
620  for ( i = 0; i < nCount; ++i )
621  {
622  if ( !_rInternalPath.isEmpty() )
623  _rInternalPath += ";";
624  _rInternalPath += pPaths[i];
625  }
626  }
627  // load user paths
628  aAny = pImpl->m_xPathSettings->getPropertyValue(
629  sCfgName + POSTFIX_USER);
630  if ( aAny >>= aPathSeq )
631  {
632  tools::Long i, nCount = aPathSeq.getLength();
633  const OUString* pPaths = aPathSeq.getConstArray();
634 
635  for ( i = 0; i < nCount; ++i )
636  {
637  if ( !_rUserPath.isEmpty() )
638  _rUserPath += ";";
639  _rUserPath += pPaths[i];
640  }
641  }
642  // then the writable path
643  aAny = pImpl->m_xPathSettings->getPropertyValue(
644  sCfgName + POSTFIX_WRITABLE);
645  OUString sWritablePath;
646  if ( aAny >>= sWritablePath )
647  _rWritablePath = sWritablePath;
648 
649  // and the readonly flag
650  Reference< XPropertySetInfo > xInfo = pImpl->m_xPathSettings->getPropertySetInfo();
651  Property aProp = xInfo->getPropertyByName(sCfgName);
652  _rReadOnly = ( ( aProp.Attributes & PropertyAttribute::READONLY ) == PropertyAttribute::READONLY );
653  }
654  catch( const Exception& )
655  {
656  TOOLS_WARN_EXCEPTION( "cui.options", "SvxPathTabPage::GetPathList()" );
657  }
658 }
659 
660 
662  SvtPathOptions::Paths _nPathHandle, const OUString& _rUserPath, const OUString& _rWritablePath )
663 {
664  OUString sCfgName = getCfgName_Impl( _nPathHandle );
665 
666  try
667  {
668  // load PathSettings service if necessary
669  if ( !pImpl->m_xPathSettings.is() )
670  {
672  pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
673  }
674 
675  // save user paths
676  const sal_Int32 nCount = comphelper::string::getTokenCount(_rUserPath, MULTIPATH_DELIMITER);
677  Sequence< OUString > aPathSeq( nCount );
678  OUString* pArray = aPathSeq.getArray();
679  sal_Int32 nPos = 0;
680  for ( sal_Int32 i = 0; i < nCount; ++i )
681  pArray[i] = _rUserPath.getToken( 0, MULTIPATH_DELIMITER, nPos );
682  Any aValue( aPathSeq );
683  pImpl->m_xPathSettings->setPropertyValue(
684  sCfgName + POSTFIX_USER, aValue);
685 
686  // then the writable path
687  aValue <<= _rWritablePath;
688  pImpl->m_xPathSettings->setPropertyValue(
689  sCfgName + POSTFIX_WRITABLE, aValue);
690  }
691  catch( const Exception& )
692  {
693  TOOLS_WARN_EXCEPTION("cui.options", "");
694  }
695 }
696 
697 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
URL aURL
sal_Int32 nIndex
IMPL_LINK(SvxPathTabPage, HeaderBarClick, int, nColumn, void)
Definition: optpath.cxx:205
#define VAR_ONE
Definition: optpath.cxx:58
static SvxAbstractDialogFactory * Create()
bool IsModuleInstalled(EModule eModule) const
long Long
static OUString Convert_Impl(const OUString &rValue)
Definition: optpath.cxx:139
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optpath.cxx:224
virtual VclPtr< AbstractSvxMultiPathDialog > CreateSvxMultiPathDialog(weld::Window *pParent)=0
bool bReadOnly
void GetPathList(SvtPathOptions::Paths _nPathHandle, OUString &_rInternalPath, OUString &_rUserPath, OUString &_rWritablePath, bool &_rReadOnly)
Definition: optpath.cxx:596
TRISTATE_TRUE
SvxPathTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optpath.cxx:183
SfxApplication * SfxGetpApp()
OUString PathToFileName() const
Reference< css::util::XPathSettings > m_xPathSettings
Definition: optpath.cxx:67
std::unique_ptr< weld::TreeView > m_xPathBox
Definition: optpath.hxx:43
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
std::unique_ptr< weld::Button > m_xStandardBtn
Definition: optpath.hxx:41
IMPL_LINK_NOARG(SvxPathTabPage, PathSelect_Impl, weld::TreeView &, void)
Definition: optpath.cxx:336
int nCount
#define POSTFIX_WRITABLE
Definition: optpath.cxx:57
#define MULTIPATH_DELIMITER
Definition: optpath.cxx:137
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
#define DBG_UNHANDLED_EXCEPTION(...)
OUString getFSysPath(FSysStyle eStyle, sal_Unicode *pDelimiter=nullptr) const
#define TOOLS_WARN_EXCEPTION(area, stream)
void SetPathList(SvtPathOptions::Paths _nPathHandle, const OUString &_rUserPath, const OUString &_rWritablePath)
Definition: optpath.cxx:661
int i
void ResetLastDir()
virtual ~SvxPathTabPage() override
Definition: optpath.cxx:212
#define IODLG_CONFIGNAME
Definition: optpath.cxx:59
static OUString getCfgName_Impl(SvtPathOptions::Paths _nHandle)
Definition: optpath.cxx:119
TRISTATE_FALSE
OUString m_sMultiPathDlg
Definition: optpath.cxx:66
bool removeFinalSlash()
static bool IsMultiPath_Impl(const SvtPathOptions::Paths nIndex)
Definition: optpath.cxx:162
#define POSTFIX_USER
Definition: optpath.cxx:56
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
virtual void Reset(const SfxItemSet *rSet) override
Definition: optpath.cxx:236
rtl::Reference< ::svt::DialogClosedListener > xDialogListener
Definition: optpath.hxx:38
virtual void SetPath(const OUString &rPath)=0
INetProtocol GetProtocol() const
RET_OK
void ChangeCurrentEntry(const OUString &_rFolder)
Definition: optpath.cxx:414
const sal_Int32 m_nHandle
Reference< XComponentContext > getProcessComponentContext()
Handle2CfgNameMapping_Impl const Hdl2CfgMap_Impl[]
Definition: optpath.cxx:101
#define POSTFIX_INTERNAL
Definition: optpath.cxx:55
OUString sId
#define SAL_WARN(area, stream)
SvtDefaultOptions m_aDefOpt
Definition: optpath.cxx:65
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: optpath.cxx:218
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
aStr
std::unique_ptr< OptPath_Impl > pImpl
Definition: optpath.hxx:36
std::unique_ptr< weld::Button > m_xPathBtn
Definition: optpath.hxx:42
sal_uInt16 nPos