summaryrefslogtreecommitdiffstats
path: root/svtools
diff options
context:
space:
mode:
authorSven Jacobi <sj@openoffice.org>2001-02-28 12:49:33 +0000
committerSven Jacobi <sj@openoffice.org>2001-02-28 12:49:33 +0000
commitdffc9cb60a4c20aef2e0ead415f1419dbb30dc3d (patch)
tree008bcc06514208ccfc5055e944e377021f5e954e /svtools
parentadded FilterConfigItem (diff)
downloadcore-dffc9cb60a4c20aef2e0ead415f1419dbb30dc3d.tar.gz
core-dffc9cb60a4c20aef2e0ead415f1419dbb30dc3d.zip
added FilterConfigItem - read/write of filter settings
Diffstat (limited to 'svtools')
-rw-r--r--svtools/source/filter.vcl/filter/FilterConfigItem.cxx277
1 files changed, 277 insertions, 0 deletions
diff --git a/svtools/source/filter.vcl/filter/FilterConfigItem.cxx b/svtools/source/filter.vcl/filter/FilterConfigItem.cxx
new file mode 100644
index 000000000000..b83c9c4b236f
--- /dev/null
+++ b/svtools/source/filter.vcl/filter/FilterConfigItem.cxx
@@ -0,0 +1,277 @@
+/*************************************************************************
+ *
+ * $RCSfile: FilterConfigItem.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: sj $ $Date: 2001-02-28 13:49:33 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _FILTER_CONFIG_ITEM_HXX_
+#include "FilterConfigItem.hxx"
+#endif
+#include <tools/debug.hxx>
+#ifndef _UTL_CONFIGMGR_HXX_
+#include <unotools/configmgr.hxx>
+#endif
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX_
+#include <unotools/processfactory.hxx>
+#endif
+#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
+#include <com/sun/star/beans/PropertyValue.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UTIL_XCHANGESBATCH_HPP_
+#include <com/sun/star/util/XChangesBatch.hpp>
+#endif
+#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#endif
+
+using namespace ::rtl;
+using namespace ::utl ; // getProcessServiceFactory
+using namespace ::com::sun::star::lang ; // XMultiServiceFactory
+using namespace ::com::sun::star::beans ; // PropertyValue
+using namespace ::com::sun::star::uno ; // Reference
+using namespace ::com::sun::star::util ; // XChangesBatch
+
+FilterConfigItem::FilterConfigItem( const OUString& rSubTree )
+{
+ OUString sTree( ConfigManager::GetConfigBaseURL() );
+ sTree += rSubTree;
+ Reference< XMultiServiceFactory > xSMGR = getProcessServiceFactory(); // get global uno service manager
+
+ Reference< XMultiServiceFactory > xCfgProv(
+ xSMGR->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ) ),
+ UNO_QUERY );
+
+ if ( xCfgProv.is() )
+ {
+ Any aAny;
+ // creation arguments: nodepath
+ PropertyValue aPathArgument;
+ aAny <<= sTree;
+ aPathArgument.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) );
+ aPathArgument.Value = aAny;
+
+ // creation arguments: commit mode
+ PropertyValue aModeArgument;
+ sal_Bool bAsyncron = sal_True;
+ aAny <<= bAsyncron;
+ aModeArgument.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "lazywrite" ) );
+ aModeArgument.Value = aAny;
+
+ Sequence< Any > aArguments( 2 );
+ aArguments[ 0 ] <<= aPathArgument;
+ aArguments[ 1 ] <<= aModeArgument;
+
+ try
+ {
+ xUpdatableView = xCfgProv->createInstanceWithArguments(
+ OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) ),
+ aArguments );
+ if ( xUpdatableView.is() )
+ xPropSet = Reference< XPropertySet >( xUpdatableView, UNO_QUERY );
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ DBG_ERROR( "FilterConfigItem::FilterConfigItem - Could not access configuration Key" );
+ }
+ }
+};
+
+FilterConfigItem::~FilterConfigItem()
+{
+ if ( xUpdatableView.is() )
+ {
+ if ( xPropSet.is() && bModified )
+ {
+ Reference< XChangesBatch > xUpdateControl( xUpdatableView, UNO_QUERY );
+ if ( xUpdateControl.is() )
+ {
+ try
+ {
+ xUpdateControl->commitChanges();
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ DBG_ERROR( "FilterConfigItem::FilterConfigItem - Could not update configuration data" );
+ }
+ }
+ }
+ }
+}
+
+sal_Bool FilterConfigItem::ImplGetPropertyValue( Any& rAny, const OUString& rString, sal_Bool bTestPropertyAvailability )
+{
+ sal_Bool bRetValue = sal_True;
+
+ if ( xPropSet.is() )
+ {
+ if ( bTestPropertyAvailability )
+ {
+ bRetValue = sal_False;
+ try
+ {
+ Reference< XPropertySetInfo >
+ aXPropSetInfo( xPropSet->getPropertySetInfo() );
+ if ( aXPropSetInfo.is() )
+ bRetValue = aXPropSetInfo->hasPropertyByName( rString );
+ }
+ catch( ::com::sun::star::uno::Exception& )
+ {
+ //
+ }
+ }
+ if ( bRetValue )
+ {
+ try
+ {
+ rAny = xPropSet->getPropertyValue( rString );
+ if ( !rAny.hasValue() )
+ bRetValue = sal_False;
+ }
+ catch( ::com::sun::star::uno::Exception& )
+ {
+ bRetValue = sal_False;
+ }
+ }
+ }
+ else
+ bRetValue = sal_False;
+ return bRetValue;
+}
+
+sal_Bool FilterConfigItem::ReadBool( const OUString& rKey, sal_Bool bDefault )
+{
+ sal_Bool bRetValue = bDefault;
+ Any aAny;
+
+ if ( ImplGetPropertyValue( aAny, rKey, sal_True ) )
+ aAny >>= bRetValue;
+ return bRetValue;
+}
+
+sal_Int32 FilterConfigItem::ReadInt32( const OUString& rKey, sal_Int32 nDefault )
+{
+ sal_Int32 nRetValue = nDefault;
+ Any aAny;
+
+ if ( ImplGetPropertyValue( aAny, rKey, sal_True ) )
+ aAny >>= nRetValue;
+ return nRetValue;
+}
+
+void FilterConfigItem::WriteBool( const OUString& rKey, sal_Bool bNewValue )
+{
+ if ( xPropSet.is() )
+ {
+ Any aAny;
+
+ if ( ImplGetPropertyValue( aAny, rKey, sal_True ) )
+ {
+ sal_Bool bOldValue;
+ if ( aAny >>= bOldValue )
+ {
+ if ( bOldValue != bNewValue )
+ {
+ aAny <<= bNewValue;
+ try
+ {
+ xPropSet->setPropertyValue( rKey, aAny );
+ bModified = sal_True;
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ DBG_ERROR( "FilterConfigItem::WriteBool - could not set PropertyValue" );
+ }
+ }
+ }
+ }
+ }
+}
+
+void FilterConfigItem::WriteInt32( const OUString& rKey, sal_Int32 nNewValue )
+{
+ if ( xPropSet.is() )
+ {
+ Any aAny;
+
+ if ( ImplGetPropertyValue( aAny, rKey, sal_True ) )
+ {
+ sal_Int32 nOldValue;
+ if ( aAny >>= nOldValue )
+ {
+ if ( nOldValue != nNewValue )
+ {
+ aAny <<= nNewValue;
+ try
+ {
+ xPropSet->setPropertyValue( rKey, aAny );
+ bModified = sal_True;
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ DBG_ERROR( "FilterConfigItem::WriteInt32 - could not set PropertyValue" );
+ }
+ }
+ }
+ }
+ }
+}
+
+// ------------------------------------------------------------------------