26#include <osl/diagnose.h>
27#include <com/sun/star/beans/PropertyValue.hpp>
28#include <com/sun/star/configuration/theDefaultProvider.hpp>
29#include <com/sun/star/lang/XMultiServiceFactory.hpp>
30#include <com/sun/star/util/XChangesBatch.hpp>
31#include <com/sun/star/beans/XPropertySetInfo.hpp>
32#include <com/sun/star/beans/XPropertySet.hpp>
33#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
34#include <com/sun/star/awt/Size.hpp>
35#include <com/sun/star/task/XStatusIndicator.hpp>
46static bool ImpIsTreeAvailable( Reference< XMultiServiceFactory >
const & rXCfgProv, std::u16string_view rTree )
48 bool bAvailable = !rTree.empty();
52 if ( rTree[0] ==
'/' )
60 Reference< XInterface > xReadAccess;
63 xReadAccess = rXCfgProv->createInstanceWithArguments(
64 "com.sun.star.configuration.ConfigurationAccess",
67 catch (
const css::uno::Exception&)
71 if ( xReadAccess.is() )
73 const sal_Int32 nEnd = rTree.size();
74 while (bAvailable && nIdx>=0 && nIdx<nEnd)
76 Reference< XHierarchicalNameAccess > xHierarchicalNameAccess
77 ( xReadAccess, UNO_QUERY );
79 if ( !xHierarchicalNameAccess.is() )
84 if ( !xHierarchicalNameAccess->hasByHierarchicalName( aNode ) )
88 Any a( xHierarchicalNameAccess->getByHierarchicalName( aNode ) );
89 bAvailable = (
a >>= xReadAccess);
104 Reference< XMultiServiceFactory > xCfgProv = theDefaultProvider::get( xContext );
106 OUString sTree = OUString::Concat(
"/org.openoffice.") + rSubTree;
111 PropertyValue aPathArgument;
112 aPathArgument.Name =
"nodepath";
113 aPathArgument.Value <<= sTree;
120 "com.sun.star.configuration.ConfigurationUpdateAccess",
125 catch ( css::uno::Exception& )
127 OSL_FAIL(
"FilterConfigItem::FilterConfigItem - Could not access configuration Key" );
144 css::uno::Sequence< css::beans::PropertyValue >
const * pFilterData )
165 Reference< XChangesBatch > xUpdateControl(
xUpdatableView, UNO_QUERY );
166 if ( xUpdateControl.is() )
170 xUpdateControl->commitChanges();
173 catch ( css::uno::Exception& )
175 OSL_FAIL(
"FilterConfigItem::FilterConfigItem - Could not update configuration data" );
182 bool bRetValue =
true;
184 if ( rXPropSet.is() )
189 Reference< XPropertySetInfo >
190 aXPropSetInfo( rXPropSet->getPropertySetInfo() );
191 if ( aXPropSetInfo.is() )
192 bRetValue = aXPropSetInfo->hasPropertyByName( rString );
194 catch( css::uno::Exception& )
201 rAny = rXPropSet->getPropertyValue( rString );
202 if ( !rAny.hasValue() )
205 catch( css::uno::Exception& )
220 auto pProp = std::find_if(rPropSeq.begin(), rPropSeq.end(),
221 [&rName](
const PropertyValue& rProp) { return rProp.Name == rName; });
222 if (pProp != rPropSeq.end())
234 if ( !rPropValue.Name.isEmpty() )
236 auto pProp = std::find_if(std::cbegin(rPropSeq), std::cend(rPropSeq),
237 [&rPropValue](
const PropertyValue& rProp) {
return rProp.Name == rPropValue.Name; });
238 sal_Int32
i = std::distance(std::cbegin(rPropSeq), pProp);
239 sal_Int32
nCount = rPropSeq.getLength();
241 rPropSeq.realloc( ++
nCount );
243 rPropSeq.getArray()[
i ] = rPropValue;
253 bool bRetValue = bDefault;
257 pPropVal->Value >>= bRetValue;
265 aBool.Value <<= bRetValue;
273 sal_Int32 nRetValue = nDefault;
277 pPropVal->Value >>= nRetValue;
283 PropertyValue aInt32;
285 aInt32.Value <<= nRetValue;
293 OUString aRetValue( rDefault );
297 pPropVal->Value >>= aRetValue;
303 PropertyValue aString;
305 aString.Value <<= aRetValue;
314 aBool.Value <<= bNewValue;
324 bool bOldValue(
true);
325 if ( !(aAny >>= bOldValue) )
328 if ( bOldValue != bNewValue )
332 xPropSet->setPropertyValue( rKey,
Any(bNewValue) );
335 catch ( css::uno::Exception& )
337 OSL_FAIL(
"FilterConfigItem::WriteBool - could not set PropertyValue" );
344 PropertyValue aInt32;
346 aInt32.Value <<= nNewValue;
357 sal_Int32 nOldValue = 0;
358 if ( !(aAny >>= nOldValue) )
361 if ( nOldValue != nNewValue )
365 xPropSet->setPropertyValue( rKey,
Any(nNewValue) );
368 catch ( css::uno::Exception& )
370 OSL_FAIL(
"FilterConfigItem::WriteInt32 - could not set PropertyValue" );
378 Reference< XStatusIndicator > xStatusIndicator;
381 [](
const css::beans::PropertyValue& rPropVal) {
382 return rPropVal.Name ==
"StatusIndicator"; });
385 pPropVal->Value >>= xStatusIndicator;
387 return xStatusIndicator;
static bool ImpIsTreeAvailable(Reference< XMultiServiceFactory > const &rXCfgProv, std::u16string_view 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)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)