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  sal_uInt16 nRealId;
80  SfxItemState eState;
81  OUString sUserPath;
82  OUString sWritablePath;
83  bool bReadOnly;
84 
85  explicit PathUserData_Impl(sal_uInt16 nId)
86  : nRealId(nId)
87  , eState(SfxItemState::UNKNOWN)
88  , bReadOnly(false)
89  {
90  }
91 };
92 
93 struct Handle2CfgNameMapping_Impl
94 {
95  sal_uInt16 m_nHandle;
96  const char* m_pCfgName;
97 };
98 
99 }
100 
101 Handle2CfgNameMapping_Impl const Hdl2CfgMap_Impl[] =
102 {
103  { SvtPathOptions::PATH_AUTOCORRECT, "AutoCorrect" },
104  { SvtPathOptions::PATH_AUTOTEXT, "AutoText" },
105  { SvtPathOptions::PATH_BACKUP, "Backup" },
106  { SvtPathOptions::PATH_GALLERY, "Gallery" },
107  { SvtPathOptions::PATH_GRAPHIC, "Graphic" },
108  { SvtPathOptions::PATH_TEMP, "Temp" },
109  { SvtPathOptions::PATH_TEMPLATE, "Template" },
110  { SvtPathOptions::PATH_WORK, "Work" },
111  { SvtPathOptions::PATH_DICTIONARY, "Dictionary" },
112  { SvtPathOptions::PATH_CLASSIFICATION, "Classification" },
113 #if OSL_DEBUG_LEVEL > 1
114  { SvtPathOptions::PATH_LINGUISTIC, "Linguistic" },
115 #endif
116  { USHRT_MAX, nullptr }
117 };
118 
119 static OUString getCfgName_Impl( sal_uInt16 _nHandle )
120 {
121  OUString sCfgName;
122  sal_uInt16 nIndex = 0;
123  while ( Hdl2CfgMap_Impl[ nIndex ].m_nHandle != USHRT_MAX )
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 sal_uInt16 nIndex )
163 {
164 #if OSL_DEBUG_LEVEL > 1
165  return ( SvtPathOptions::PATH_AUTOCORRECT == nIndex ||
166  SvtPathOptions::PATH_AUTOTEXT == nIndex ||
167  SvtPathOptions::PATH_BASIC == nIndex ||
168  SvtPathOptions::PATH_GALLERY == nIndex ||
169  SvtPathOptions::PATH_TEMPLATE == nIndex );
170 #else
171  return ( SvtPathOptions::PATH_AUTOCORRECT == nIndex ||
172  SvtPathOptions::PATH_AUTOTEXT == nIndex ||
173  SvtPathOptions::PATH_BASIC == nIndex ||
174  SvtPathOptions::PATH_GALLERY == nIndex ||
175  SvtPathOptions::PATH_TEMPLATE == 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_changed( LINK( this, SvxPathTabPage, PathSelect_Impl ) );
199  m_xPathBox->set_selection_mode(SelectionMode::Multiple);
200 
201  xDialogListener->SetDialogClosedLink( LINK( this, SvxPathTabPage, DialogClosedHdl ) );
202 }
203 
205 {
206  for (int i = 0, nEntryCount = m_xPathBox->n_children(); i < nEntryCount; ++i)
207  delete reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(i).toInt64());
208 }
209 
210 std::unique_ptr<SfxTabPage> SvxPathTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
211  const SfxItemSet* rAttrSet )
212 {
213  return std::make_unique<SvxPathTabPage>( pPage, pController, *rAttrSet );
214 }
215 
217 {
218  for (int i = 0, nEntryCount = m_xPathBox->n_children(); i < nEntryCount; ++i)
219  {
220  PathUserData_Impl* pPathImpl = reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(i).toInt64());
221  sal_uInt16 nRealId = pPathImpl->nRealId;
222  if (pPathImpl->eState == SfxItemState::SET)
223  SetPathList( nRealId, pPathImpl->sUserPath, pPathImpl->sWritablePath );
224  }
225  return true;
226 }
227 
229 {
230  m_xPathBox->clear();
231 
232  std::unique_ptr<weld::TreeIter> xIter = m_xPathBox->make_iterator();
233  for( sal_uInt16 i = 0; i <= sal_uInt16(SvtPathOptions::PATH_CLASSIFICATION); ++i )
234  {
235  // only writer uses autotext
238  continue;
239 
240  const char* pId = nullptr;
241 
242  switch (i)
243  {
245  pId = RID_SVXSTR_KEY_AUTOCORRECT_DIR;
246  break;
248  pId = RID_SVXSTR_KEY_GLOSSARY_PATH;
249  break;
251  pId = RID_SVXSTR_KEY_BACKUP_PATH;
252  break;
254  pId = RID_SVXSTR_KEY_GALLERY_DIR;
255  break;
257  pId = RID_SVXSTR_KEY_GRAPHICS_PATH;
258  break;
260  pId = RID_SVXSTR_KEY_TEMP_PATH;
261  break;
263  pId = RID_SVXSTR_KEY_TEMPLATE_PATH;
264  break;
266  pId = RID_SVXSTR_KEY_DICTIONARY_PATH;
267  break;
269  pId = RID_SVXSTR_KEY_CLASSIFICATION_PATH;
270  break;
271 #if OSL_DEBUG_LEVEL > 1
273  pId = RID_SVXSTR_KEY_LINGUISTIC_DIR;
274  break;
275 #endif
277  pId = RID_SVXSTR_KEY_WORK_PATH;
278  break;
279  }
280 
281  if (pId)
282  {
283  m_xPathBox->append(xIter.get());
284 
285  OUString aStr(CuiResId(pId));
286  m_xPathBox->set_text(*xIter, aStr, 0);
287 
288  OUString sInternal, sUser, sWritable;
289  bool bReadOnly = false;
290  GetPathList( i, sInternal, sUser, sWritable, bReadOnly );
291 
292  if (bReadOnly)
293  m_xPathBox->set_image(*xIter, RID_SVXBMP_LOCK);
294 
295  OUString sTmpPath = sUser;
296  if ( !sTmpPath.isEmpty() && !sWritable.isEmpty() )
297  sTmpPath += OUStringChar(MULTIPATH_DELIMITER);
298  sTmpPath += sWritable;
299  const OUString aValue = Convert_Impl( sTmpPath );
300 
301  m_xPathBox->set_text(*xIter, aValue, 1);
302 
303  const OUString aValueInternal = Convert_Impl( sInternal );
304 
305  m_xPathBox->set_text(*xIter, aValueInternal, 2);
306 
307  m_xPathBox->set_sensitive(*xIter, !bReadOnly, 0);
308  m_xPathBox->set_sensitive(*xIter, !bReadOnly, 1);
309  m_xPathBox->set_sensitive(*xIter, !bReadOnly, 2);
310 
311  PathUserData_Impl* pPathImpl = new PathUserData_Impl(i);
312  pPathImpl->sUserPath = sUser;
313  pPathImpl->sWritablePath = sWritable;
314  pPathImpl->bReadOnly = bReadOnly;
315 
316  OUString sId = OUString::number(reinterpret_cast<sal_Int64>(pPathImpl));
317  m_xPathBox->set_id(*xIter, sId);
318  }
319  }
320 
321  m_xPathBox->columns_autosize();
322  PathSelect_Impl(*m_xPathBox);
323 }
324 
326 {
327  bool bEnable = false;
328  int nEntry = m_xPathBox->get_selected_index();
329  if (nEntry != -1)
330  {
331  PathUserData_Impl* pPathImpl = reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(nEntry).toInt64());
332  bEnable = !pPathImpl->bReadOnly;
333  }
334  sal_uInt16 nSelCount = m_xPathBox->count_selected_rows();
335  m_xPathBtn->set_sensitive(1 == nSelCount && bEnable);
336  m_xStandardBtn->set_sensitive(nSelCount > 0 && bEnable);
337 }
338 
339 IMPL_LINK_NOARG(SvxPathTabPage, StandardHdl_Impl, weld::Button&, void)
340 {
341  m_xPathBox->selected_foreach([this](weld::TreeIter& rEntry){
342  PathUserData_Impl* pPathImpl = reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(rEntry).toInt64());
343  OUString aOldPath = pImpl->m_aDefOpt.GetDefaultPath( pPathImpl->nRealId );
344 
345  if ( !aOldPath.isEmpty() )
346  {
347  OUString sInternal, sUser, sWritable, sTemp;
348  bool bReadOnly = false;
349  GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
350 
351  sal_Int32 nOldPos = 0;
352  do
353  {
354  bool bFound = false;
355  const OUString sOnePath = aOldPath.getToken( 0, MULTIPATH_DELIMITER, nOldPos );
356  if ( !sInternal.isEmpty() )
357  {
358  sal_Int32 nInternalPos = 0;
359  do
360  {
361  if ( sInternal.getToken( 0, MULTIPATH_DELIMITER, nInternalPos ) == sOnePath )
362  bFound = true;
363  }
364  while ( !bFound && nInternalPos >= 0 );
365  }
366  if ( !bFound )
367  {
368  if ( !sTemp.isEmpty() )
369  sTemp += OUStringChar(MULTIPATH_DELIMITER);
370  sTemp += sOnePath;
371  }
372  }
373  while ( nOldPos >= 0 );
374 
375  OUString sWritablePath;
376  OUStringBuffer sUserPath;
377  if ( !sTemp.isEmpty() )
378  {
379  sal_Int32 nNextPos = 0;
380  for (;;)
381  {
382  const OUString sToken = sTemp.getToken( 0, MULTIPATH_DELIMITER, nNextPos );
383  if ( nNextPos<0 )
384  {
385  // Last token need a different handling
386  sWritablePath = sToken;
387  break;
388  }
389  if ( !sUserPath.isEmpty() )
390  sUserPath.append(MULTIPATH_DELIMITER);
391  sUserPath.append(sToken);
392  }
393  }
394  m_xPathBox->set_text(rEntry, Convert_Impl(sTemp), 1);
395  pPathImpl->eState = SfxItemState::SET;
396  pPathImpl->sUserPath = sUserPath.makeStringAndClear();
397  pPathImpl->sWritablePath = sWritablePath;
398  }
399  return false;
400  });
401 }
402 
403 void SvxPathTabPage::ChangeCurrentEntry( const OUString& _rFolder )
404 {
405  int nEntry = m_xPathBox->get_cursor_index();
406  if (nEntry == -1)
407  {
408  SAL_WARN( "cui.options", "SvxPathTabPage::ChangeCurrentEntry(): no entry" );
409  return;
410  }
411 
412  OUString sInternal, sUser, sWritable;
413  PathUserData_Impl* pPathImpl = reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(nEntry).toInt64());
414  bool bReadOnly = false;
415  GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
416  sUser = pPathImpl->sUserPath;
417  sWritable = pPathImpl->sWritablePath;
418 
419  // old path is a URL?
420  INetURLObject aObj( sWritable );
421  bool bURL = ( aObj.GetProtocol() != INetProtocol::NotValid );
422  INetURLObject aNewObj( _rFolder );
423  aNewObj.removeFinalSlash();
424 
425  // then the new path also a URL else system path
426  OUString sNewPathStr = bURL ? _rFolder : aNewObj.getFSysPath( FSysStyle::Detect );
427 
428  bool bChanged =
429 #ifdef UNX
430 // Unix is case sensitive
431  ( sNewPathStr != sWritable );
432 #else
433  !sNewPathStr.equalsIgnoreAsciiCase( sWritable );
434 #endif
435 
436  if ( !bChanged )
437  return;
438 
439  m_xPathBox->set_text(nEntry, Convert_Impl(sNewPathStr), 1);
440  pPathImpl->eState = SfxItemState::SET;
441  pPathImpl->sWritablePath = sNewPathStr;
442  if ( SvtPathOptions::PATH_WORK == pPathImpl->nRealId )
443  {
444  // Remove view options entry so the new work path
445  // will be used for the next open dialog.
446  SvtViewOptions aDlgOpt( EViewType::Dialog, IODLG_CONFIGNAME );
447  aDlgOpt.Delete();
448  // Reset also last used dir in the sfx application instance
449  SfxApplication *pSfxApp = SfxGetpApp();
450  pSfxApp->ResetLastDir();
451  }
452 }
453 
454 IMPL_LINK_NOARG(SvxPathTabPage, DoubleClickPathHdl_Impl, weld::TreeView&, bool)
455 {
456  PathHdl_Impl(*m_xPathBtn);
457  return true;
458 }
459 
461 {
462  int nEntry = m_xPathBox->get_cursor_index();
463  PathUserData_Impl* pPathImpl = nEntry != -1 ? reinterpret_cast<PathUserData_Impl*>(m_xPathBox->get_id(nEntry).toInt64()) : nullptr;
464  if (!pPathImpl || pPathImpl->bReadOnly)
465  return;
466 
467  sal_uInt16 nPos = pPathImpl->nRealId;
468  OUString sInternal, sUser, sWritable;
469  bool bPickFile = false;
470  bool bReadOnly = false;
471  GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
472  sUser = pPathImpl->sUserPath;
473  sWritable = pPathImpl->sWritablePath;
474  bPickFile = pPathImpl->nRealId == SvtPathOptions::PATH_CLASSIFICATION;
475 
476  if (IsMultiPath_Impl(nPos))
477  {
481 
482  OUString sPath( sUser );
483  if ( !sPath.isEmpty() )
484  sPath += OUStringChar(MULTIPATH_DELIMITER);
485  sPath += sWritable;
486  pMultiDlg->SetPath( sPath );
487 
488  const OUString sPathName = m_xPathBox->get_text(nEntry, 0);
489  const OUString sNewTitle = pImpl->m_sMultiPathDlg.replaceFirst( VAR_ONE, sPathName );
490  pMultiDlg->SetTitle( sNewTitle );
491 
492  if (pMultiDlg->Execute() == RET_OK)
493  {
494  sUser.clear();
495  sWritable.clear();
496  OUString sFullPath;
497  OUString sNewPath = pMultiDlg->GetPath();
498  if ( !sNewPath.isEmpty() )
499  {
500  sal_Int32 nNextPos = 0;
501  for (;;)
502  {
503  const OUString sToken(sNewPath.getToken( 0, MULTIPATH_DELIMITER, nNextPos ));
504  if ( nNextPos<0 )
505  {
506  // Last token need a different handling
507  sWritable = sToken;
508  break;
509  }
510  if ( !sUser.isEmpty() )
511  sUser += OUStringChar(MULTIPATH_DELIMITER);
512  sUser += sToken;
513  }
514  sFullPath = sUser;
515  if ( !sFullPath.isEmpty() )
516  sFullPath += OUStringChar(MULTIPATH_DELIMITER);
517  sFullPath += sWritable;
518  }
519 
520  m_xPathBox->set_text(nEntry, Convert_Impl(sFullPath), 1);
521  // save modified flag
522  pPathImpl->eState = SfxItemState::SET;
523  pPathImpl->sUserPath = sUser;
524  pPathImpl->sWritablePath = sWritable;
525  }
526  }
527  else if (!bPickFile)
528  {
529  try
530  {
532  xFolderPicker = FolderPicker::create(xContext);
533 
534  INetURLObject aURL( sWritable, INetProtocol::File );
535  xFolderPicker->setDisplayDirectory( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
536 
537  Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
538  if ( xAsyncDlg.is() )
539  xAsyncDlg->startExecuteModal( xDialogListener.get() );
540  else
541  {
542  short nRet = xFolderPicker->execute();
543  if (ExecutableDialogResults::OK != nRet)
544  return;
545 
546  OUString sFolder(xFolderPicker->getDirectory());
547  ChangeCurrentEntry(sFolder);
548  }
549  }
550  catch( Exception const & )
551  {
552  TOOLS_WARN_EXCEPTION( "cui.options", "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
553  }
554  }
555  else
556  {
557  try
558  {
559  uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
560  uno::Reference<ui::dialogs::XFilePicker3> xFilePicker = ui::dialogs::FilePicker::createWithMode(xComponentContext, ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE);
561  xFilePicker->appendFilter(OUString(), "*.xml");
562  if (xFilePicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
563  {
564  uno::Sequence<OUString> aPathSeq(xFilePicker->getSelectedFiles());
565  ChangeCurrentEntry(aPathSeq[0]);
566  }
567  }
568  catch (const uno::Exception&)
569  {
570  DBG_UNHANDLED_EXCEPTION("cui.options", "exception from file picker");
571  }
572  }
573 }
574 
575 IMPL_LINK( SvxPathTabPage, DialogClosedHdl, DialogClosedEvent*, pEvt, void )
576 {
577  if (RET_OK == pEvt->DialogResult)
578  {
579  assert(xFolderPicker.is() && "SvxPathTabPage::DialogClosedHdl(): no folder picker");
580  OUString sURL = xFolderPicker->getDirectory();
581  ChangeCurrentEntry( sURL );
582  }
583 }
584 
586  sal_uInt16 _nPathHandle, OUString& _rInternalPath,
587  OUString& _rUserPath, OUString& _rWritablePath, bool& _rReadOnly )
588 {
589  OUString sCfgName = getCfgName_Impl( _nPathHandle );
590 
591  try
592  {
593  // load PathSettings service if necessary
594  if ( !pImpl->m_xPathSettings.is() )
595  {
597  pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
598  }
599 
600  // load internal paths
601  Any aAny = pImpl->m_xPathSettings->getPropertyValue(
602  sCfgName + POSTFIX_INTERNAL);
603  Sequence< OUString > aPathSeq;
604  if ( aAny >>= aPathSeq )
605  {
606  long i, nCount = aPathSeq.getLength();
607  const OUString* pPaths = aPathSeq.getConstArray();
608 
609  for ( i = 0; i < nCount; ++i )
610  {
611  if ( !_rInternalPath.isEmpty() )
612  _rInternalPath += ";";
613  _rInternalPath += pPaths[i];
614  }
615  }
616  // load user paths
617  aAny = pImpl->m_xPathSettings->getPropertyValue(
618  sCfgName + POSTFIX_USER);
619  if ( aAny >>= aPathSeq )
620  {
621  long i, nCount = aPathSeq.getLength();
622  const OUString* pPaths = aPathSeq.getConstArray();
623 
624  for ( i = 0; i < nCount; ++i )
625  {
626  if ( !_rUserPath.isEmpty() )
627  _rUserPath += ";";
628  _rUserPath += pPaths[i];
629  }
630  }
631  // then the writable path
632  aAny = pImpl->m_xPathSettings->getPropertyValue(
633  sCfgName + POSTFIX_WRITABLE);
634  OUString sWritablePath;
635  if ( aAny >>= sWritablePath )
636  _rWritablePath = sWritablePath;
637 
638  // and the readonly flag
639  Reference< XPropertySetInfo > xInfo = pImpl->m_xPathSettings->getPropertySetInfo();
640  Property aProp = xInfo->getPropertyByName(sCfgName);
641  _rReadOnly = ( ( aProp.Attributes & PropertyAttribute::READONLY ) == PropertyAttribute::READONLY );
642  }
643  catch( const Exception& )
644  {
645  TOOLS_WARN_EXCEPTION( "cui.options", "SvxPathTabPage::GetPathList()" );
646  }
647 }
648 
649 
651  sal_uInt16 _nPathHandle, const OUString& _rUserPath, const OUString& _rWritablePath )
652 {
653  OUString sCfgName = getCfgName_Impl( _nPathHandle );
654 
655  try
656  {
657  // load PathSettings service if necessary
658  if ( !pImpl->m_xPathSettings.is() )
659  {
661  pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
662  }
663 
664  // save user paths
665  const sal_Int32 nCount = comphelper::string::getTokenCount(_rUserPath, MULTIPATH_DELIMITER);
666  Sequence< OUString > aPathSeq( nCount );
667  OUString* pArray = aPathSeq.getArray();
668  sal_Int32 nPos = 0;
669  for ( sal_Int32 i = 0; i < nCount; ++i )
670  pArray[i] = _rUserPath.getToken( 0, MULTIPATH_DELIMITER, nPos );
671  Any aValue( aPathSeq );
672  pImpl->m_xPathSettings->setPropertyValue(
673  sCfgName + POSTFIX_USER, aValue);
674 
675  // then the writable path
676  aValue <<= _rWritablePath;
677  pImpl->m_xPathSettings->setPropertyValue(
678  sCfgName + POSTFIX_WRITABLE, aValue);
679  }
680  catch( const Exception& )
681  {
682  TOOLS_WARN_EXCEPTION("cui.options", "");
683  }
684 }
685 
686 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
URL aURL
sal_Int32 nIndex
#define VAR_ONE
Definition: optpath.cxx:58
static SvxAbstractDialogFactory * Create()
bool IsModuleInstalled(EModule eModule) const
static OUString Convert_Impl(const OUString &rValue)
Definition: optpath.cxx:139
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optpath.cxx:216
virtual VclPtr< AbstractSvxMultiPathDialog > CreateSvxMultiPathDialog(weld::Window *pParent)=0
bool bReadOnly
SvxPathTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optpath.cxx:183
sal_Int32 getTokenCount(const OString &rIn, char cTok)
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:325
IMPL_LINK(SvxPathTabPage, DialogClosedHdl, DialogClosedEvent *, pEvt, void)
Definition: optpath.cxx:575
int nCount
#define POSTFIX_WRITABLE
Definition: optpath.cxx:57
#define MULTIPATH_DELIMITER
Definition: optpath.cxx:137
UNKNOWN
#define DBG_UNHANDLED_EXCEPTION(...)
OUString getFSysPath(FSysStyle eStyle, sal_Unicode *pDelimiter=nullptr) const
#define TOOLS_WARN_EXCEPTION(area, stream)
int i
void ResetLastDir()
virtual ~SvxPathTabPage() override
Definition: optpath.cxx:204
#define IODLG_CONFIGNAME
Definition: optpath.cxx:59
OUString m_sMultiPathDlg
Definition: optpath.cxx:66
void GetPathList(sal_uInt16 _nPathHandle, OUString &_rInternalPath, OUString &_rUserPath, OUString &_rWritablePath, bool &_rReadOnly)
Definition: optpath.cxx:585
bool removeFinalSlash()
#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:228
SfxItemState
rtl::Reference< ::svt::DialogClosedListener > xDialogListener
Definition: optpath.hxx:38
virtual void SetPath(const OUString &rPath)=0
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
INetProtocol GetProtocol() const
RET_OK
void ChangeCurrentEntry(const OUString &_rFolder)
Definition: optpath.cxx:403
void SetPathList(sal_uInt16 _nPathHandle, const OUString &_rUserPath, const OUString &_rWritablePath)
Definition: optpath.cxx:650
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 bool IsMultiPath_Impl(const sal_uInt16 nIndex)
Definition: optpath.cxx:162
static OUString getCfgName_Impl(sal_uInt16 _nHandle)
Definition: optpath.cxx:119
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: optpath.cxx:210
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