24#include <unordered_map>
29#include <com/sun/star/beans/Property.hpp>
30#include <com/sun/star/beans/XProperty.hpp>
31#include <com/sun/star/beans/PropertyAttribute.hpp>
32#include <com/sun/star/beans/XPropertySet.hpp>
33#include <com/sun/star/util/XChangesNotifier.hpp>
34#include <com/sun/star/util/PathSubstitution.hpp>
35#include <com/sun/star/container/XNameAccess.hpp>
36#include <com/sun/star/lang/XServiceInfo.hpp>
37#include <com/sun/star/util/XStringSubstitution.hpp>
38#include <com/sun/star/util/XChangesListener.hpp>
39#include <com/sun/star/util/XPathSettings.hpp>
42#include <rtl/ustrbuf.hxx>
73const sal_Int32 IDGROUP_OLDSTYLE = 0;
74const sal_Int32 IDGROUP_INTERNAL_PATHS = 1;
75const sal_Int32 IDGROUP_USER_PATHS = 2;
76const sal_Int32 IDGROUP_WRITE_PATH = 3;
78const sal_Int32 IDGROUP_COUNT = 4;
80sal_Int32 impl_getPropGroup(sal_Int32 nID)
82 return (nID % IDGROUP_COUNT);
89typedef ::cppu::WeakComponentImplHelper<
90 css::lang::XServiceInfo,
91 css::util::XChangesListener,
92 css::util::XPathSettings>
96 ,
public PathSettings_BASE
104 : bIsSinglePath (
false)
105 , bIsReadonly (
false)
112 std::vector<OUString> lInternalPaths;
115 std::vector<OUString> lUserPaths;
127 typedef std::unordered_map<OUString, PathSettings::PathInfo> PathHash;
140 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
143 PathSettings::PathHash m_lPaths;
147 css::uno::Sequence< css::beans::Property > m_lPropDesc;
150 css::uno::Reference< css::util::XStringSubstitution > m_xSubstitution;
153 css::uno::Reference< css::container::XNameAccess > m_xCfgOld;
156 css::uno::Reference< css::container::XNameAccess > m_xCfgNew;
159 css::uno::Reference< css::util::XChangesListener > m_xCfgNewListener;
161 std::unique_ptr<::cppu::OPropertyArrayHelper> m_pPropHelp;
169 explicit PathSettings(css::uno::Reference< css::uno::XComponentContext > xContext);
172 virtual ~PathSettings()
override;
176 return "com.sun.star.comp.framework.PathSettings";
186 return {
"com.sun.star.util.PathSettings"};
191 virtual void SAL_CALL acquire()
noexcept override
193 virtual void SAL_CALL release()
noexcept override
197 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
getTypes( )
override;
200 virtual void SAL_CALL changesOccurred(
const css::util::ChangesEvent&
aEvent)
override;
203 virtual void SAL_CALL
disposing(
const css::lang::EventObject& aSource)
override;
208 virtual OUString SAL_CALL getAddin()
override
209 {
return getStringProperty(
"Addin"); }
210 virtual void SAL_CALL setAddin(
const OUString& p1)
override
211 { setStringProperty(
"Addin", p1); }
212 virtual OUString SAL_CALL getAutoCorrect()
override
213 {
return getStringProperty(
"AutoCorrect"); }
214 virtual void SAL_CALL setAutoCorrect(
const OUString& p1)
override
215 { setStringProperty(
"AutoCorrect", p1); }
216 virtual OUString SAL_CALL getAutoText()
override
217 {
return getStringProperty(
"AutoText"); }
218 virtual void SAL_CALL setAutoText(
const OUString& p1)
override
219 { setStringProperty(
"AutoText", p1); }
220 virtual OUString SAL_CALL getBackup()
override
221 {
return getStringProperty(
"Backup"); }
222 virtual void SAL_CALL setBackup(
const OUString& p1)
override
223 { setStringProperty(
"Backup", p1); }
224 virtual OUString SAL_CALL getBasic()
override
225 {
return getStringProperty(
"Basic"); }
226 virtual void SAL_CALL setBasic(
const OUString& p1)
override
227 { setStringProperty(
"Basic", p1); }
228 virtual OUString SAL_CALL getBitmap()
override
229 {
return getStringProperty(
"Bitmap"); }
230 virtual void SAL_CALL setBitmap(
const OUString& p1)
override
231 { setStringProperty(
"Bitmap", p1); }
232 virtual OUString SAL_CALL getConfig()
override
233 {
return getStringProperty(
"Config"); }
234 virtual void SAL_CALL setConfig(
const OUString& p1)
override
235 { setStringProperty(
"Config", p1); }
236 virtual OUString SAL_CALL getDictionary()
override
237 {
return getStringProperty(
"Dictionary"); }
238 virtual void SAL_CALL setDictionary(
const OUString& p1)
override
239 { setStringProperty(
"Dictionary", p1); }
240 virtual OUString SAL_CALL getFavorite()
override
241 {
return getStringProperty(
"Favorite"); }
242 virtual void SAL_CALL setFavorite(
const OUString& p1)
override
243 { setStringProperty(
"Favorite", p1); }
244 virtual OUString SAL_CALL getFilter()
override
245 {
return getStringProperty(
"Filter"); }
246 virtual void SAL_CALL setFilter(
const OUString& p1)
override
247 { setStringProperty(
"Filter", p1); }
248 virtual OUString SAL_CALL getGallery()
override
249 {
return getStringProperty(
"Gallery"); }
250 virtual void SAL_CALL setGallery(
const OUString& p1)
override
251 { setStringProperty(
"Gallery", p1); }
252 virtual OUString SAL_CALL getGraphic()
override
253 {
return getStringProperty(
"Graphic"); }
254 virtual void SAL_CALL setGraphic(
const OUString& p1)
override
255 { setStringProperty(
"Graphic", p1); }
256 virtual OUString SAL_CALL getHelp()
override
257 {
return getStringProperty(
"Help"); }
258 virtual void SAL_CALL setHelp(
const OUString& p1)
override
259 { setStringProperty(
"Help", p1); }
260 virtual OUString SAL_CALL getLinguistic()
override
261 {
return getStringProperty(
"Linguistic"); }
262 virtual void SAL_CALL setLinguistic(
const OUString& p1)
override
263 { setStringProperty(
"Linguistic", p1); }
264 virtual OUString SAL_CALL getModule()
override
265 {
return getStringProperty(
"Module"); }
266 virtual void SAL_CALL setModule(
const OUString& p1)
override
267 { setStringProperty(
"Module", p1); }
268 virtual OUString SAL_CALL getPalette()
override
269 {
return getStringProperty(
"Palette"); }
270 virtual void SAL_CALL setPalette(
const OUString& p1)
override
271 { setStringProperty(
"Palette", p1); }
272 virtual OUString SAL_CALL getPlugin()
override
273 {
return getStringProperty(
"Plugin"); }
274 virtual void SAL_CALL setPlugin(
const OUString& p1)
override
275 { setStringProperty(
"Plugin", p1); }
276 virtual OUString SAL_CALL getStorage()
override
277 {
return getStringProperty(
"Storage"); }
278 virtual void SAL_CALL setStorage(
const OUString& p1)
override
279 { setStringProperty(
"Storage", p1); }
280 virtual OUString SAL_CALL getTemp()
override
281 {
return getStringProperty(
"Temp"); }
282 virtual void SAL_CALL setTemp(
const OUString& p1)
override
283 { setStringProperty(
"Temp", p1); }
284 virtual OUString SAL_CALL getTemplate()
override
285 {
return getStringProperty(
"Template"); }
286 virtual void SAL_CALL setTemplate(
const OUString& p1)
override
287 { setStringProperty(
"Template", p1); }
288 virtual OUString SAL_CALL getUIConfig()
override
289 {
return getStringProperty(
"UIConfig"); }
290 virtual void SAL_CALL setUIConfig(
const OUString& p1)
override
291 { setStringProperty(
"UIConfig", p1); }
292 virtual OUString SAL_CALL getUserConfig()
override
293 {
return getStringProperty(
"UserConfig"); }
294 virtual void SAL_CALL setUserConfig(
const OUString& p1)
override
295 { setStringProperty(
"UserConfig", p1); }
296 virtual OUString SAL_CALL getUserDictionary()
override
297 {
return getStringProperty(
"UserDictionary"); }
298 virtual void SAL_CALL setUserDictionary(
const OUString& p1)
override
299 { setStringProperty(
"UserDictionary", p1); }
300 virtual OUString SAL_CALL getWork()
override
301 {
return getStringProperty(
"Work"); }
302 virtual void SAL_CALL setWork(
const OUString& p1)
override
303 { setStringProperty(
"Work", p1); }
304 virtual OUString SAL_CALL getBasePathShareLayer()
override
305 {
return getStringProperty(
"UIConfig"); }
306 virtual void SAL_CALL setBasePathShareLayer(
const OUString& p1)
override
307 { setStringProperty(
"UIConfig", p1); }
308 virtual OUString SAL_CALL getBasePathUserLayer()
override
309 {
return getStringProperty(
"UserConfig"); }
310 virtual void SAL_CALL setBasePathUserLayer(
const OUString& p1)
override
311 { setStringProperty(
"UserConfig", p1); }
316 virtual void SAL_CALL
setPropertyValue(
const OUString& p1,
const css::uno::Any& p2)
override
318 virtual css::uno::Any SAL_CALL
getPropertyValue(
const OUString& p1)
override
319 { return ::cppu::OPropertySetHelper::getPropertyValue(p1); }
320 virtual void SAL_CALL
addPropertyChangeListener(
const OUString& p1,
const css::uno::Reference<css::beans::XPropertyChangeListener>& p2)
override
322 virtual void SAL_CALL
removePropertyChangeListener(
const OUString& p1,
const css::uno::Reference<css::beans::XPropertyChangeListener>& p2)
override
324 virtual void SAL_CALL
addVetoableChangeListener(
const OUString& p1,
const css::uno::Reference<css::beans::XVetoableChangeListener>& p2)
override
326 virtual void SAL_CALL
removeVetoableChangeListener(
const OUString& p1,
const css::uno::Reference<css::beans::XVetoableChangeListener>& p2)
override
332 virtual void SAL_CALL
disposing()
final override;
335 OUString getStringProperty(
const OUString& p1);
338 void setStringProperty(
const OUString& p1,
const OUString& p2);
343 std::vector<OUString> impl_readOldFormat(
const OUString& sPath);
346 PathSettings::PathInfo impl_readNewFormat(
const OUString& sPath);
352 void impl_mergeOldUserPaths( PathSettings::PathInfo& rPath,
353 const std::vector<OUString>& lOld );
357 PathSettings::EChangeOp impl_updatePath(
const OUString& sPath ,
358 bool bNotifyListener);
364 void impl_subst(std::vector<OUString>& lVals ,
365 const css::uno::Reference< css::util::XStringSubstitution >& xSubst ,
368 void impl_subst(PathSettings::PathInfo& aPath ,
372 OUString impl_convertPath2OldStyle(
const PathSettings::PathInfo& rPath )
const;
373 std::vector<OUString> impl_convertOldStyle2Path(std::u16string_view sOldStylePath)
const;
379 void impl_purgeKnownPaths(PathSettings::PathInfo& rPath,
380 std::vector<OUString>& lList);
383 void impl_rebuildPropertyDescriptor();
388 css::uno::Any impl_getPathValue( sal_Int32 nID )
const;
389 void impl_setPathValue( sal_Int32 nID ,
390 const css::uno::Any& aVal);
394 PathSettings::PathInfo* impl_getPathAccess (sal_Int32
nHandle);
395 const PathSettings::PathInfo* impl_getPathAccessConst(sal_Int32
nHandle)
const;
398 bool impl_isValidPath(std::u16string_view sPath)
const;
399 bool impl_isValidPath(
const std::vector<OUString>& lPath)
const;
401 void impl_storePath(
const PathSettings::PathInfo& aPath);
403 css::uno::Sequence< sal_Int32 > impl_mapPathName2IDList(std::u16string_view sPath);
405 void impl_notifyPropListener( std::u16string_view sPath ,
406 const PathSettings::PathInfo* pPathOld,
407 const PathSettings::PathInfo* pPathNew);
411 css::uno::Any& aOldValue,
413 const css::uno::Any& aValue )
override;
415 const css::uno::Any& aValue )
override;
417 sal_Int32
nHandle )
const override;
422 virtual ::cppu::IPropertyArrayHelper& SAL_CALL
getInfoHelper()
override;
423 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
override;
426 css::uno::Reference< css::util::XStringSubstitution > fa_getSubstitution();
427 css::uno::Reference< css::container::XNameAccess > fa_getCfgOld();
428 css::uno::Reference< css::container::XNameAccess > fa_getCfgNew();
431PathSettings::PathSettings( css::uno::Reference< css::uno::XComponentContext > xContext )
438PathSettings::~PathSettings()
443void SAL_CALL PathSettings::disposing()
445 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
447 css::uno::Reference< css::util::XChangesNotifier >
448 xBroadcaster(m_xCfgNew, css::uno::UNO_QUERY);
449 if (xBroadcaster.is())
450 xBroadcaster->removeChangesListener(m_xCfgNewListener);
452 m_xSubstitution.clear();
455 m_xCfgNewListener.clear();
460css::uno::Any SAL_CALL PathSettings::queryInterface(
const css::uno::Type& _rType )
462 css::uno::Any aRet = PathSettings_BASE::queryInterface( _rType );
463 if ( !aRet.hasValue() )
468css::uno::Sequence< css::uno::Type > SAL_CALL PathSettings::getTypes( )
471 PathSettings_BASE::getTypes(),
476void SAL_CALL PathSettings::changesOccurred(
const css::util::ChangesEvent&
aEvent)
478 sal_Int32 c =
aEvent.Changes.getLength();
480 bool bUpdateDescriptor =
false;
484 const css::util::ElementChange& aChange =
aEvent.Changes[
i];
487 aChange.Accessor >>= sChanged;
489 OUString sPath = ::utl::extractFirstFromConfigurationPath(sChanged);
490 if (!sPath.isEmpty())
492 PathSettings::EChangeOp eOp = impl_updatePath(sPath,
true);
494 (eOp == PathSettings::E_ADDED ) ||
495 (eOp == PathSettings::E_REMOVED)
497 bUpdateDescriptor =
true;
501 if (bUpdateDescriptor)
502 impl_rebuildPropertyDescriptor();
505void SAL_CALL PathSettings::disposing(
const css::lang::EventObject& aSource)
507 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
509 if (aSource.Source == m_xCfgNew)
513OUString PathSettings::getStringProperty(
const OUString& p1)
521void PathSettings::setStringProperty(
const OUString& p1,
const OUString& p2)
526void PathSettings::impl_readAll()
531 css::uno::Reference< css::container::XNameAccess > xCfg = fa_getCfgNew();
532 css::uno::Sequence< OUString > lPaths = xCfg->getElementNames();
534 sal_Int32 c = lPaths.getLength();
535 for (sal_Int32
i = 0;
i < c; ++
i)
537 const OUString& sPath = lPaths[
i];
538 impl_updatePath(sPath,
false);
541 catch(
const css::uno::RuntimeException& )
545 impl_rebuildPropertyDescriptor();
549std::vector<OUString> PathSettings::impl_readOldFormat(
const OUString& sPath)
551 css::uno::Reference< css::container::XNameAccess > xCfg( fa_getCfgOld() );
552 std::vector<OUString> aPathVal;
554 if( xCfg->hasByName(sPath) )
556 css::uno::Any aVal( xCfg->getByName(sPath) );
559 css::uno::Sequence< OUString > lStringListVal;
561 if (aVal >>= sStringVal)
563 aPathVal.push_back(sStringVal);
565 else if (aVal >>= lStringListVal)
567 aPathVal = comphelper::sequenceToContainer<std::vector<OUString>>(lStringListVal);
575PathSettings::PathInfo PathSettings::impl_readNewFormat(
const OUString& sPath)
577 css::uno::Reference< css::container::XNameAccess > xCfg = fa_getCfgNew();
580 css::uno::Reference< css::container::XNameAccess > xPath;
581 xCfg->getByName(sPath) >>= xPath;
583 PathSettings::PathInfo aPathVal;
586 css::uno::Reference< css::container::XNameAccess > xIPath;
587 xPath->getByName(
"InternalPaths") >>= xIPath;
588 aPathVal.lInternalPaths = comphelper::sequenceToContainer<std::vector<OUString>>(xIPath->getElementNames());
591 css::uno::Sequence<OUString> vTmpUserPathsSeq;
593 aPathVal.lUserPaths = comphelper::sequenceToContainer<std::vector<OUString>>(vTmpUserPathsSeq);
600 std::vector<OUString>::iterator aI = std::find(aPathVal.lUserPaths.begin(), aPathVal.lUserPaths.end(), aPathVal.sWritePath);
601 if (aI != aPathVal.lUserPaths.end())
602 aPathVal.lUserPaths.erase(aI);
605 xPath->getByName(
"IsSinglePath") >>= aPathVal.bIsSinglePath;
608 aPathVal.bIsReadonly =
false;
609 css::uno::Reference< css::beans::XProperty > xInfo(xPath, css::uno::UNO_QUERY);
612 css::beans::Property aInfo = xInfo->getAsProperty();
613 bool bFinalized = ((aInfo.Attributes & css::beans::PropertyAttribute::READONLY ) == css::beans::PropertyAttribute::READONLY );
618 aPathVal.bIsReadonly = bFinalized;
624void PathSettings::impl_storePath(
const PathSettings::PathInfo& aPath)
626 css::uno::Reference< css::container::XNameAccess > xCfgNew = fa_getCfgNew();
627 css::uno::Reference< css::container::XNameAccess > xCfgOld = fa_getCfgOld();
632 PathInfo aResubstPath(aPath);
633 impl_subst(aResubstPath,
true);
636 if (! aResubstPath.bIsSinglePath)
639 aResubstPath.sPathName,
645 aResubstPath.sPathName,
647 css::uno::Any(aResubstPath.sWritePath));
657 if (xCfgOld->hasByName(aResubstPath.sPathName))
659 css::uno::Reference< css::beans::XPropertySet > xProps(xCfgOld, css::uno::UNO_QUERY_THROW);
660 xProps->setPropertyValue(aResubstPath.sPathName, css::uno::Any());
665void PathSettings::impl_mergeOldUserPaths( PathSettings::PathInfo& rPath,
666 const std::vector<OUString>& lOld )
668 for (
auto const& old : lOld)
670 if (rPath.bIsSinglePath)
672 SAL_WARN_IF(lOld.size()>1,
"fwk",
"PathSettings::impl_mergeOldUserPaths(): Single path has more than one path value inside old configuration (Common.xcu)!");
673 if ( rPath.sWritePath != old )
674 rPath.sWritePath = old;
679 ( std::find(rPath.lInternalPaths.begin(), rPath.lInternalPaths.end(), old) == rPath.lInternalPaths.end()) &&
680 ( std::find(rPath.lUserPaths.begin(), rPath.lUserPaths.end(), old) == rPath.lUserPaths.end() ) &&
681 ( rPath.sWritePath != old )
683 rPath.lUserPaths.push_back(old);
688PathSettings::EChangeOp PathSettings::impl_updatePath(
const OUString& sPath ,
689 bool bNotifyListener)
692 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
694 PathSettings::PathInfo* pPathOld =
nullptr;
695 PathSettings::PathInfo* pPathNew =
nullptr;
696 PathSettings::EChangeOp eOp = PathSettings::E_UNDEFINED;
697 PathSettings::PathInfo aPath;
701 aPath = impl_readNewFormat(sPath);
702 aPath.sPathName = sPath;
707 impl_subst(aPath,
false);
709 catch(
const css::uno::RuntimeException&)
711 catch(
const css::container::NoSuchElementException&)
712 { eOp = PathSettings::E_REMOVED; }
713 catch(
const css::uno::Exception&)
720 std::vector<OUString> lOldVals = impl_readOldFormat(sPath);
725 impl_subst(lOldVals, fa_getSubstitution(),
false);
726 impl_mergeOldUserPaths(aPath, lOldVals);
728 catch(
const css::uno::RuntimeException&)
734 catch(
const css::uno::Exception&)
737 PathSettings::PathHash::iterator pPath = m_lPaths.find(sPath);
738 if (eOp == PathSettings::E_UNDEFINED)
740 if (pPath != m_lPaths.end())
741 eOp = PathSettings::E_CHANGED;
743 eOp = PathSettings::E_ADDED;
748 case PathSettings::E_ADDED :
754 impl_notifyPropListener(sPath, pPathOld, pPathNew);
756 m_lPaths[sPath] = aPath;
760 case PathSettings::E_CHANGED :
764 pPathOld = &(pPath->second);
766 impl_notifyPropListener(sPath, pPathOld, pPathNew);
768 m_lPaths[sPath] = aPath;
772 case PathSettings::E_REMOVED :
774 if (pPath != m_lPaths.end())
778 pPathOld = &(pPath->second);
780 impl_notifyPropListener(sPath, pPathOld, pPathNew);
782 m_lPaths.erase(pPath);
794css::uno::Sequence< sal_Int32 > PathSettings::impl_mapPathName2IDList(std::u16string_view sPath)
808 css::uno::Sequence<sal_Int32> lIDs{ IDGROUP_OLDSTYLE, IDGROUP_INTERNAL_PATHS,
809 IDGROUP_USER_PATHS, IDGROUP_WRITE_PATH };
810 assert(lIDs.getLength() == IDGROUP_COUNT);
811 auto plIDs = lIDs.getArray();
813 sal_Int32 c = m_lPropDesc.getLength();
817 const css::beans::Property& rProp = m_lPropDesc[
i];
819 if (rProp.Name == sPath)
820 plIDs[IDGROUP_OLDSTYLE] = rProp.Handle;
822 if (rProp.Name == sInternalProp)
823 plIDs[IDGROUP_INTERNAL_PATHS] = rProp.Handle;
825 if (rProp.Name == sUserProp)
826 plIDs[IDGROUP_USER_PATHS] = rProp.Handle;
828 if (rProp.Name == sWriteProp)
829 plIDs[IDGROUP_WRITE_PATH] = rProp.Handle;
835void PathSettings::impl_notifyPropListener( std::u16string_view sPath,
836 const PathSettings::PathInfo* pPathOld,
837 const PathSettings::PathInfo* pPathNew)
839 css::uno::Sequence< sal_Int32 > lHandles(1);
840 auto plHandles = lHandles.getArray();
841 css::uno::Sequence< css::uno::Any > lOldVals(1);
842 auto plOldVals = lOldVals.getArray();
843 css::uno::Sequence< css::uno::Any > lNewVals(1);
844 auto plNewVals = lNewVals.getArray();
846 css::uno::Sequence< sal_Int32 > lIDs = impl_mapPathName2IDList(sPath);
847 sal_Int32 c = lIDs.getLength();
849 sal_Int32 nMaxID = m_lPropDesc.getLength()-1;
852 sal_Int32 nID = lIDs[
i];
861 switch(impl_getPropGroup(nID))
863 case IDGROUP_OLDSTYLE :
867 OUString sVal = impl_convertPath2OldStyle(*pPathOld);
868 plOldVals[0] <<= sVal;
872 OUString sVal = impl_convertPath2OldStyle(*pPathNew);
873 plNewVals[0] <<= sVal;
878 case IDGROUP_INTERNAL_PATHS :
887 case IDGROUP_USER_PATHS :
896 case IDGROUP_WRITE_PATH :
899 plOldVals[0] <<= pPathOld->sWritePath;
901 plNewVals[0] <<= pPathNew->sWritePath;
914void PathSettings::impl_subst(std::vector<OUString>& lVals ,
915 const css::uno::Reference< css::util::XStringSubstitution >& xSubst ,
918 for (
auto & old : lVals)
922 sNew = xSubst->reSubstituteVariables(old);
924 sNew = xSubst->substituteVariables(old,
false);
930void PathSettings::impl_subst(PathSettings::PathInfo& aPath ,
933 css::uno::Reference< css::util::XStringSubstitution > xSubst = fa_getSubstitution();
935 impl_subst(aPath.lInternalPaths, xSubst, bReSubst);
936 impl_subst(aPath.lUserPaths , xSubst, bReSubst);
938 aPath.sWritePath = xSubst->reSubstituteVariables(aPath.sWritePath);
940 aPath.sWritePath = xSubst->substituteVariables(aPath.sWritePath,
false);
943OUString PathSettings::impl_convertPath2OldStyle(
const PathSettings::PathInfo& rPath)
const
945 OUStringBuffer sPathVal(256);
947 for (
auto const& internalPath : rPath.lInternalPaths)
949 if (sPathVal.getLength())
950 sPathVal.append(
";");
951 sPathVal.append(internalPath);
953 for (
auto const& userPath : rPath.lUserPaths)
955 if (sPathVal.getLength())
956 sPathVal.append(
";");
957 sPathVal.append(userPath);
959 if (!rPath.sWritePath.isEmpty())
961 if (sPathVal.getLength())
962 sPathVal.append(
";");
963 sPathVal.append(rPath.sWritePath);
966 return sPathVal.makeStringAndClear();
969std::vector<OUString> PathSettings::impl_convertOldStyle2Path(std::u16string_view sOldStylePath)
const
971 std::vector<OUString> lList;
976 if (!sToken.isEmpty())
977 lList.push_back(sToken);
984void PathSettings::impl_purgeKnownPaths(PathSettings::PathInfo& rPath,
985 std::vector<OUString>& lList)
989 for (
auto const& internalPath : rPath.lInternalPaths)
991 std::vector<OUString>::iterator pItem = std::find(lList.begin(), lList.end(), internalPath);
992 if (pItem != lList.end())
994 pItem = std::find(rPath.lUserPaths.begin(), rPath.lUserPaths.end(), internalPath);
995 if (pItem != rPath.lUserPaths.end())
996 rPath.lUserPaths.erase(pItem);
1000 rPath.lUserPaths.erase(std::remove_if(rPath.lUserPaths.begin(), rPath.lUserPaths.end(),
1001 [&lList](
const OUString& rItem) {
1002 return std::find(lList.begin(), lList.end(), rItem) == lList.end();
1004 rPath.lUserPaths.end());
1007 for (
auto const& userPath : rPath.lUserPaths)
1009 std::vector<OUString>::iterator pItem = std::find(lList.begin(), lList.end(), userPath);
1010 if (pItem != lList.end())
1015 std::vector<OUString>::iterator pItem = std::find(lList.begin(), lList.end(), rPath.sWritePath);
1016 if (pItem != lList.end())
1020void PathSettings::impl_rebuildPropertyDescriptor()
1023 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
1025 sal_Int32 c =
static_cast<sal_Int32
>(m_lPaths.size());
1027 m_lPropDesc.realloc(c*IDGROUP_COUNT);
1028 auto plPropDesc = m_lPropDesc.getArray();
1030 for (
auto const& path : m_lPaths)
1032 const PathSettings::PathInfo& rPath = path.second;
1033 css::beans::Property* pProp =
nullptr;
1035 pProp = &(plPropDesc[
i]);
1036 pProp->Name = rPath.sPathName;
1039 pProp->Attributes = css::beans::PropertyAttribute::BOUND;
1040 if (rPath.bIsReadonly)
1041 pProp->Attributes |= css::beans::PropertyAttribute::READONLY;
1044 pProp = &(plPropDesc[
i]);
1048 pProp->Attributes = css::beans::PropertyAttribute::BOUND |
1049 css::beans::PropertyAttribute::READONLY;
1052 pProp = &(plPropDesc[
i]);
1056 pProp->Attributes = css::beans::PropertyAttribute::BOUND;
1057 if (rPath.bIsReadonly)
1058 pProp->Attributes |= css::beans::PropertyAttribute::READONLY;
1061 pProp = &(plPropDesc[
i]);
1065 pProp->Attributes = css::beans::PropertyAttribute::BOUND;
1066 if (rPath.bIsReadonly)
1067 pProp->Attributes |= css::beans::PropertyAttribute::READONLY;
1071 m_pPropHelp.reset(new ::cppu::OPropertyArrayHelper(m_lPropDesc,
false));
1076css::uno::Any PathSettings::impl_getPathValue(sal_Int32 nID)
const
1078 const PathSettings::PathInfo* pPath = impl_getPathAccessConst(nID);
1080 throw css::lang::IllegalArgumentException();
1083 switch(impl_getPropGroup(nID))
1085 case IDGROUP_OLDSTYLE :
1087 OUString sVal = impl_convertPath2OldStyle(*pPath);
1092 case IDGROUP_INTERNAL_PATHS :
1098 case IDGROUP_USER_PATHS :
1104 case IDGROUP_WRITE_PATH :
1106 aVal <<= pPath->sWritePath;
1114void PathSettings::impl_setPathValue( sal_Int32 nID ,
1115 const css::uno::Any& aVal)
1117 PathSettings::PathInfo* pOrgPath = impl_getPathAccess(nID);
1119 throw css::container::NoSuchElementException();
1123 PathSettings::PathInfo aChangePath(*pOrgPath);
1125 switch(impl_getPropGroup(nID))
1127 case IDGROUP_OLDSTYLE :
1131 std::vector<OUString> lList = impl_convertOldStyle2Path(sVal);
1132 impl_subst(lList, fa_getSubstitution(),
false);
1133 impl_purgeKnownPaths(aChangePath, lList);
1134 if (! impl_isValidPath(lList))
1135 throw css::lang::IllegalArgumentException();
1137 if (aChangePath.bIsSinglePath)
1139 SAL_WARN_IF(lList.size()>1,
"fwk",
"PathSettings::impl_setPathValue(): You try to set more than path value for a defined SINGLE_PATH!");
1140 if ( !lList.empty() )
1141 aChangePath.sWritePath = *(lList.begin());
1143 aChangePath.sWritePath.clear();
1147 for (
auto const& elem : lList)
1149 aChangePath.lUserPaths.push_back(elem);
1155 case IDGROUP_INTERNAL_PATHS :
1157 if (aChangePath.bIsSinglePath)
1159 throw css::uno::Exception(
1160 "The path '" + aChangePath.sPathName
1161 +
"' is defined as SINGLE_PATH. It's sub set of internal paths can't be set.",
1165 css::uno::Sequence<OUString> lTmpList;
1167 std::vector<OUString> lList = comphelper::sequenceToContainer<std::vector<OUString>>(lTmpList);
1168 if (! impl_isValidPath(lList))
1169 throw css::lang::IllegalArgumentException();
1170 aChangePath.lInternalPaths = lList;
1174 case IDGROUP_USER_PATHS :
1176 if (aChangePath.bIsSinglePath)
1178 throw css::uno::Exception(
1179 "The path '" + aChangePath.sPathName
1180 +
"' is defined as SINGLE_PATH. It's sub set of internal paths can't be set.",
1184 css::uno::Sequence<OUString> lTmpList;
1186 std::vector<OUString> lList = comphelper::sequenceToContainer<std::vector<OUString>>(lTmpList);
1187 if (! impl_isValidPath(lList))
1188 throw css::lang::IllegalArgumentException();
1189 aChangePath.lUserPaths = lList;
1193 case IDGROUP_WRITE_PATH :
1197 if (! impl_isValidPath(sVal))
1198 throw css::lang::IllegalArgumentException();
1199 aChangePath.sWritePath = sVal;
1211 impl_storePath(aChangePath);
1212 *pOrgPath = std::move(aChangePath);
1215bool PathSettings::impl_isValidPath(
const std::vector<OUString>& lPath)
const
1217 for (
auto const& path : lPath)
1219 if (! impl_isValidPath(path))
1226bool PathSettings::impl_isValidPath(std::u16string_view sPath)
const
1238OUString impl_extractBaseFromPropName(
const OUString& sPropName)
1242 return sPropName.copy(0,
i);
1245 return sPropName.copy(0,
i);
1248 return sPropName.copy(0,
i);
1253PathSettings::PathInfo* PathSettings::impl_getPathAccess(sal_Int32
nHandle)
1256 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
1258 if (
nHandle > (m_lPropDesc.getLength()-1))
1261 const css::beans::Property& rProp = m_lPropDesc[
nHandle];
1262 OUString sProp = impl_extractBaseFromPropName(rProp.Name);
1263 PathSettings::PathHash::iterator rPath = m_lPaths.find(sProp);
1265 if (rPath != m_lPaths.end())
1266 return &(rPath->second);
1272const PathSettings::PathInfo* PathSettings::impl_getPathAccessConst(sal_Int32
nHandle)
const
1275 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
1277 if (
nHandle > (m_lPropDesc.getLength()-1))
1280 const css::beans::Property& rProp = m_lPropDesc[
nHandle];
1281 OUString sProp = impl_extractBaseFromPropName(rProp.Name);
1282 PathSettings::PathHash::const_iterator rPath = m_lPaths.find(sProp);
1284 if (rPath != m_lPaths.end())
1285 return &(rPath->second);
1291sal_Bool SAL_CALL PathSettings::convertFastPropertyValue( css::uno::Any& aConvertedValue,
1292 css::uno::Any& aOldValue ,
1294 const css::uno::Any& aValue )
1297 css::uno::Any aCurrentVal = impl_getPathValue(
nHandle);
1299 return PropHelper::willPropertyBeChanged(
1306void SAL_CALL PathSettings::setFastPropertyValue_NoBroadcast( sal_Int32
nHandle,
1307 const css::uno::Any& aValue )
1310 impl_setPathValue(
nHandle, aValue);
1313void SAL_CALL PathSettings::getFastPropertyValue(css::uno::Any& aValue ,
1316 aValue = impl_getPathValue(
nHandle);
1321 return *m_pPropHelp;
1324css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL PathSettings::getPropertySetInfo()
1326 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1329css::uno::Reference< css::util::XStringSubstitution > PathSettings::fa_getSubstitution()
1331 css::uno::Reference< css::util::XStringSubstitution > xSubst;
1333 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
1334 xSubst = m_xSubstitution;
1343 xSubst = css::util::PathSubstitution::create(
m_xContext);
1346 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
1347 m_xSubstitution = xSubst;
1354css::uno::Reference< css::container::XNameAccess > PathSettings::fa_getCfgOld()
1356 css::uno::Reference< css::container::XNameAccess > xCfg;
1358 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
1366 "org.openoffice.Office.Common/Path/Current",
1368 css::uno::UNO_QUERY_THROW);
1371 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
1379css::uno::Reference< css::container::XNameAccess > PathSettings::fa_getCfgNew()
1381 css::uno::Reference< css::container::XNameAccess > xCfg;
1383 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
1391 "org.openoffice.Office.Paths/Paths",
1393 css::uno::UNO_QUERY_THROW);
1396 osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex);
1401 css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(xCfg, css::uno::UNO_QUERY_THROW);
1402 xBroadcaster->addChangesListener(m_xCfgNewListener);
1410extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1412 css::uno::XComponentContext *context,
1413 css::uno::Sequence<css::uno::Any>
const &)
1417 xPathSettings->impl_readAll();
1419 return cppu::acquire(xPathSettings.get());
static css::uno::Reference< css::uno::XInterface > openConfig(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &sPackage, EConfigurationModes eMode)
static void flush(const css::uno::Reference< css::uno::XInterface > &xCFG)
static void writeRelativeKey(const css::uno::Reference< css::uno::XInterface > &xCFG, const OUString &sRelPath, const OUString &sKey, const css::uno::Any &aValue)
virtual css::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) SAL_OVERRIDE
virtual void SAL_CALL addVetoableChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) SAL_OVERRIDE
virtual IPropertyArrayHelper &SAL_CALL getInfoHelper()=0
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue)=0
void SAL_CALL disposing()
virtual void SAL_CALL removePropertyChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) SAL_OVERRIDE
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue)=0
virtual void SAL_CALL removeVetoableChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) SAL_OVERRIDE
virtual css::uno::Any SAL_CALL getPropertyValue(const ::rtl::OUString &aPropertyName) SAL_OVERRIDE
virtual void SAL_CALL setPropertyValue(const ::rtl::OUString &rPropertyName, const css::uno::Any &aValue) SAL_OVERRIDE
virtual void SAL_CALL addPropertyChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) SAL_OVERRIDE
css::uno::Sequence< css::uno::Type > getTypes()
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
css::uno::Type const & get()
css::uno::Reference< css::uno::XComponentContext > m_xContext
#define SAL_WARN_IF(condition, area, stream)
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
constexpr OUStringLiteral CFGPROP_USERPATHS
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_PathSettings_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral POSTFIX_WRITE_PATH
constexpr OUStringLiteral POSTFIX_INTERNAL_PATHS
constexpr OUStringLiteral POSTFIX_USER_PATHS
constexpr OUStringLiteral CFGPROP_WRITEPATH