25#include <osl/diagnose.h>
26#include <com/sun/star/beans/PropertyValue.hpp>
27#include <com/sun/star/configuration/theDefaultProvider.hpp>
28#include <com/sun/star/lang/XMultiServiceFactory.hpp>
29#include <com/sun/star/util/XChangesBatch.hpp>
30#include <com/sun/star/beans/XPropertySetInfo.hpp>
31#include <com/sun/star/beans/XPropertySet.hpp>
32#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
33#include <com/sun/star/awt/Size.hpp>
34#include <com/sun/star/task/XStatusIndicator.hpp>
45static bool ImpIsTreeAvailable( Reference< XMultiServiceFactory >
const & rXCfgProv,
const OUString& rTree )
47 bool bAvailable = !rTree.isEmpty();
51 if ( rTree[0] ==
'/' )
56 rTree.getToken(0,
'/', nIdx));
59 Reference< XInterface > xReadAccess;
62 xReadAccess = rXCfgProv->createInstanceWithArguments(
63 "com.sun.star.configuration.ConfigurationAccess",
66 catch (
const css::uno::Exception&)
70 if ( xReadAccess.is() )
72 const sal_Int32 nEnd {rTree.getLength()};
73 while (bAvailable && nIdx>=0 && nIdx<nEnd)
75 Reference< XHierarchicalNameAccess > xHierarchicalNameAccess
76 ( xReadAccess, UNO_QUERY );
78 if ( !xHierarchicalNameAccess.is() )
82 const OUString aNode( rTree.getToken(0,
'/', nIdx) );
83 if ( !xHierarchicalNameAccess->hasByHierarchicalName( aNode ) )
87 Any a( xHierarchicalNameAccess->getByHierarchicalName( aNode ) );
88 bAvailable = (
a >>= xReadAccess);
103 Reference< XMultiServiceFactory > xCfgProv = theDefaultProvider::get( xContext );
105 OUString sTree = OUString::Concat(
"/org.openoffice.") + rSubTree;
110 PropertyValue aPathArgument;
111 aPathArgument.Name =
"nodepath";
112 aPathArgument.Value <<= sTree;
119 "com.sun.star.configuration.ConfigurationUpdateAccess",
124 catch ( css::uno::Exception& )
126 OSL_FAIL(
"FilterConfigItem::FilterConfigItem - Could not access configuration Key" );
143 css::uno::Sequence< css::beans::PropertyValue >
const * pFilterData )
164 Reference< XChangesBatch > xUpdateControl(
xUpdatableView, UNO_QUERY );
165 if ( xUpdateControl.is() )
169 xUpdateControl->commitChanges();
172 catch ( css::uno::Exception& )
174 OSL_FAIL(
"FilterConfigItem::FilterConfigItem - Could not update configuration data" );
181 bool bRetValue =
true;
183 if ( rXPropSet.is() )
188 Reference< XPropertySetInfo >
189 aXPropSetInfo( rXPropSet->getPropertySetInfo() );
190 if ( aXPropSetInfo.is() )
191 bRetValue = aXPropSetInfo->hasPropertyByName( rString );
193 catch( css::uno::Exception& )
200 rAny = rXPropSet->getPropertyValue( rString );
201 if ( !rAny.hasValue() )
204 catch( css::uno::Exception& )
219 auto pProp = std::find_if(rPropSeq.begin(), rPropSeq.end(),
220 [&rName](
const PropertyValue& rProp) { return rProp.Name == rName; });
221 if (pProp != rPropSeq.end())
233 if ( !rPropValue.Name.isEmpty() )
235 auto pProp = std::find_if(std::cbegin(rPropSeq), std::cend(rPropSeq),
236 [&rPropValue](
const PropertyValue& rProp) {
return rProp.Name == rPropValue.Name; });
237 sal_Int32
i = std::distance(std::cbegin(rPropSeq), pProp);
238 sal_Int32
nCount = rPropSeq.getLength();
240 rPropSeq.realloc( ++
nCount );
242 rPropSeq.getArray()[
i ] = rPropValue;
252 bool bRetValue = bDefault;
256 pPropVal->Value >>= bRetValue;
264 aBool.Value <<= bRetValue;
272 sal_Int32 nRetValue = nDefault;
276 pPropVal->Value >>= nRetValue;
282 PropertyValue aInt32;
284 aInt32.Value <<= nRetValue;
292 OUString aRetValue( rDefault );
296 pPropVal->Value >>= aRetValue;
302 PropertyValue aString;
304 aString.Value <<= aRetValue;
313 aBool.Value <<= bNewValue;
323 bool bOldValue(
true);
324 if ( !(aAny >>= bOldValue) )
327 if ( bOldValue != bNewValue )
331 xPropSet->setPropertyValue( rKey,
Any(bNewValue) );
334 catch ( css::uno::Exception& )
336 OSL_FAIL(
"FilterConfigItem::WriteBool - could not set PropertyValue" );
343 PropertyValue aInt32;
345 aInt32.Value <<= nNewValue;
356 sal_Int32 nOldValue = 0;
357 if ( !(aAny >>= nOldValue) )
360 if ( nOldValue != nNewValue )
364 xPropSet->setPropertyValue( rKey,
Any(nNewValue) );
367 catch ( css::uno::Exception& )
369 OSL_FAIL(
"FilterConfigItem::WriteInt32 - could not set PropertyValue" );
377 Reference< XStatusIndicator > xStatusIndicator;
380 [](
const css::beans::PropertyValue& rPropVal) {
381 return rPropVal.Name ==
"StatusIndicator"; });
384 pPropVal->Value >>= xStatusIndicator;
386 return xStatusIndicator;
static bool ImpIsTreeAvailable(Reference< XMultiServiceFactory > const &rXCfgProv, const OUString &rTree)
FilterConfigItem(std::u16string_view rSubTree)
static const css::beans::PropertyValue * GetPropertyValue(const css::uno::Sequence< css::beans::PropertyValue > &rPropSeq, const OUString &rName)
css::uno::Sequence< css::beans::PropertyValue > aFilterData
css::uno::Reference< css::beans::XPropertySet > xPropSet
css::uno::Reference< css::uno::XInterface > xUpdatableView
css::uno::Reference< css::task::XStatusIndicator > GetStatusIndicator() const
OUString ReadString(const OUString &rKey, const OUString &rDefault)
bool ReadBool(const OUString &rKey, bool bDefault)
void WriteBool(const OUString &rKey, bool bValue)
~FilterConfigItem()
Writes config in destructor.
static bool ImplGetPropertyValue(css::uno::Any &rAny, const css::uno::Reference< css::beans::XPropertySet > &rXPropSet, const OUString &rPropName)
static bool WritePropertyValue(css::uno::Sequence< css::beans::PropertyValue > &rPropSeq, const css::beans::PropertyValue &rPropValue)
void WriteModifiedConfig()
Writes config and sets unmodified state again.
void WriteInt32(const OUString &rKey, sal_Int32 nValue)
void ImpInitTree(std::u16string_view rTree)
sal_Int32 ReadInt32(const OUString &rKey, sal_Int32 nDefault)
Sequence< PropertyValue > aArguments
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)