24 #include <osl/diagnose.h>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/configuration/theDefaultProvider.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/util/XChangesBatch.hpp>
29 #include <com/sun/star/beans/XPropertySetInfo.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
32 #include <com/sun/star/awt/Size.hpp>
33 #include <com/sun/star/task/XStatusIndicator.hpp>
44 static bool ImpIsTreeAvailable( Reference< XMultiServiceFactory >
const & rXCfgProv,
const OUString& rTree )
46 bool bAvailable = !rTree.isEmpty();
50 if ( rTree[0] ==
'/' )
54 PropertyValue aPathArgument;
55 aPathArgument.Name =
"nodepath";
56 aPathArgument.Value <<= rTree.getToken(0,
'/', nIdx);
59 aArguments[ 0 ] <<= aPathArgument;
61 Reference< XInterface > xReadAccess;
64 xReadAccess = rXCfgProv->createInstanceWithArguments(
65 "com.sun.star.configuration.ConfigurationAccess",
68 catch (
const css::uno::Exception&)
72 if ( xReadAccess.is() )
74 const sal_Int32 nEnd {rTree.getLength()};
75 while (bAvailable && nIdx>=0 && nIdx<nEnd)
78 ( xReadAccess, UNO_QUERY );
80 if ( !xHierarchicalNameAccess.is() )
84 const OUString aNode( rTree.getToken(0,
'/', nIdx) );
85 if ( !xHierarchicalNameAccess->hasByHierarchicalName( aNode ) )
89 Any a( xHierarchicalNameAccess->getByHierarchicalName( aNode ) );
90 bAvailable = (
a >>= xReadAccess);
105 Reference< XMultiServiceFactory > xCfgProv = theDefaultProvider::get( xContext );
107 OUString sTree = OUString::Concat(
"/org.openoffice.") + rSubTree;
112 PropertyValue aPathArgument;
113 aPathArgument.Name =
"nodepath";
114 aPathArgument.Value <<= sTree;
117 aArguments[ 0 ] <<= aPathArgument;
122 "com.sun.star.configuration.ConfigurationUpdateAccess",
127 catch ( css::uno::Exception& )
129 OSL_FAIL(
"FilterConfigItem::FilterConfigItem - Could not access configuration Key" );
146 css::uno::Sequence< css::beans::PropertyValue >
const * pFilterData )
167 Reference< XChangesBatch > xUpdateControl(
xUpdatableView, UNO_QUERY );
168 if ( xUpdateControl.is() )
172 xUpdateControl->commitChanges();
175 catch ( css::uno::Exception& )
177 OSL_FAIL(
"FilterConfigItem::FilterConfigItem - Could not update configuration data" );
184 bool bRetValue =
true;
186 if ( rXPropSet.is() )
191 Reference< XPropertySetInfo >
192 aXPropSetInfo( rXPropSet->getPropertySetInfo() );
193 if ( aXPropSetInfo.is() )
194 bRetValue = aXPropSetInfo->hasPropertyByName( rString );
196 catch( css::uno::Exception& )
203 rAny = rXPropSet->getPropertyValue( rString );
204 if ( !rAny.hasValue() )
207 catch( css::uno::Exception& )
222 auto pProp = std::find_if(rPropSeq.begin(), rPropSeq.end(),
223 [&rName](
const PropertyValue& rProp) {
return rProp.Name == rName; });
224 if (pProp != rPropSeq.end())
236 if ( !rPropValue.Name.isEmpty() )
238 auto pProp = std::find_if(rPropSeq.begin(), rPropSeq.end(),
239 [&rPropValue](
const PropertyValue& rProp) {
return rProp.Name == rPropValue.Name; });
240 sal_Int32
i = std::distance(rPropSeq.begin(), pProp);
241 sal_Int32
nCount = rPropSeq.getLength();
243 rPropSeq.realloc( ++nCount );
245 rPropSeq[ i ] = rPropValue;
255 bool bRetValue = bDefault;
259 pPropVal->Value >>= bRetValue;
267 aBool.Value <<= bRetValue;
275 sal_Int32 nRetValue = nDefault;
279 pPropVal->Value >>= nRetValue;
285 PropertyValue aInt32;
287 aInt32.Value <<= nRetValue;
295 OUString aRetValue( rDefault );
299 pPropVal->Value >>= aRetValue;
305 PropertyValue aString;
307 aString.Value <<= aRetValue;
316 aBool.Value <<= bNewValue;
326 bool bOldValue(
true);
327 if ( !(aAny >>= bOldValue) )
330 if ( bOldValue != bNewValue )
334 xPropSet->setPropertyValue( rKey,
Any(bNewValue) );
337 catch ( css::uno::Exception& )
339 OSL_FAIL(
"FilterConfigItem::WriteBool - could not set PropertyValue" );
346 PropertyValue aInt32;
348 aInt32.Value <<= nNewValue;
359 sal_Int32 nOldValue = 0;
360 if ( !(aAny >>= nOldValue) )
363 if ( nOldValue != nNewValue )
367 xPropSet->setPropertyValue( rKey,
Any(nNewValue) );
370 catch ( css::uno::Exception& )
372 OSL_FAIL(
"FilterConfigItem::WriteInt32 - could not set PropertyValue" );
380 Reference< XStatusIndicator > xStatusIndicator;
381 const OUString sStatusIndicator(
"StatusIndicator" );
384 [&sStatusIndicator](
const css::beans::PropertyValue& rPropVal) {
385 return rPropVal.Name == sStatusIndicator; });
388 pPropVal->Value >>= xStatusIndicator;
390 return xStatusIndicator;
css::uno::Reference< css::uno::XInterface > xUpdatableView
static bool ImpIsTreeAvailable(Reference< XMultiServiceFactory > const &rXCfgProv, const OUString &rTree)
static bool ImplGetPropertyValue(css::uno::Any &rAny, const css::uno::Reference< css::beans::XPropertySet > &rXPropSet, const OUString &rPropName)
css::uno::Sequence< css::beans::PropertyValue > aFilterData
OUString ReadString(const OUString &rKey, const OUString &rDefault)
void WriteModifiedConfig()
Writes config and sets unmodified state again.
sal_Int32 ReadInt32(const OUString &rKey, sal_Int32 nDefault)
void WriteBool(const OUString &rKey, bool bValue)
Sequence< PropertyValue > aArguments
css::uno::Reference< css::beans::XPropertySet > xPropSet
bool ReadBool(const OUString &rKey, bool bDefault)
~FilterConfigItem()
Writes config in destructor.
static bool WritePropertyValue(css::uno::Sequence< css::beans::PropertyValue > &rPropSeq, const css::beans::PropertyValue &rPropValue)
void ImpInitTree(std::u16string_view rTree)
Reference< XComponentContext > getProcessComponentContext()
void WriteInt32(const OUString &rKey, sal_Int32 nValue)
css::uno::Reference< css::task::XStatusIndicator > GetStatusIndicator() const
static css::beans::PropertyValue * GetPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &rPropSeq, const OUString &rName)
FilterConfigItem(std::u16string_view rSubTree)