1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_shell.hxx" 29 #include "sal/config.h" 30 31 #include "boost/noncopyable.hpp" 32 #include "com/sun/star/beans/Optional.hpp" 33 #include "com/sun/star/beans/PropertyVetoException.hpp" 34 #include "com/sun/star/beans/UnknownPropertyException.hpp" 35 #include "com/sun/star/beans/XPropertyChangeListener.hpp" 36 #include "com/sun/star/beans/XPropertySet.hpp" 37 #include "com/sun/star/beans/XPropertySetInfo.hpp" 38 #include "com/sun/star/beans/XVetoableChangeListener.hpp" 39 #include "com/sun/star/lang/IllegalArgumentException.hpp" 40 #include "com/sun/star/lang/WrappedTargetException.hpp" 41 #include "com/sun/star/lang/XMultiComponentFactory.hpp" 42 #include "com/sun/star/lang/XServiceInfo.hpp" 43 #include "com/sun/star/lang/WrappedTargetException.hpp" 44 #include "com/sun/star/uno/Any.hxx" 45 #include "com/sun/star/uno/Exception.hpp" 46 #include "com/sun/star/uno/Reference.hxx" 47 #include "com/sun/star/uno/RuntimeException.hpp" 48 #include "com/sun/star/uno/Sequence.hxx" 49 #include "com/sun/star/uno/XComponentContext.hpp" 50 #include "com/sun/star/uno/XCurrentContext.hpp" 51 #include "cppuhelper/factory.hxx" 52 #include "cppuhelper/implbase2.hxx" 53 #include "cppuhelper/implementationentry.hxx" 54 #include "cppuhelper/weak.hxx" 55 #include "osl/diagnose.h" 56 #include "rtl/string.h" 57 #include "rtl/textenc.h" 58 #include "rtl/ustring.h" 59 #include "rtl/ustring.hxx" 60 #include "sal/types.h" 61 #include "uno/current_context.hxx" 62 #include "uno/lbnames.h" 63 64 namespace { 65 66 namespace css = com::sun::star; 67 68 rtl::OUString SAL_CALL getDefaultImplementationName() { 69 return rtl::OUString( 70 RTL_CONSTASCII_USTRINGPARAM( 71 "com.sun.star.comp.configuration.backend.DesktopBackend")); 72 } 73 74 css::uno::Sequence< rtl::OUString > SAL_CALL getDefaultSupportedServiceNames() { 75 rtl::OUString name( 76 RTL_CONSTASCII_USTRINGPARAM( 77 "com.sun.star.configuration.backend.DesktopBackend")); 78 return css::uno::Sequence< rtl::OUString >(&name, 1); 79 } 80 81 class Default: 82 public cppu::WeakImplHelper2< 83 css::lang::XServiceInfo, css::beans::XPropertySet >, 84 private boost::noncopyable 85 { 86 public: 87 Default() {} 88 89 private: 90 virtual ~Default() {} 91 92 virtual rtl::OUString SAL_CALL getImplementationName() 93 throw (css::uno::RuntimeException) 94 { return getDefaultImplementationName(); } 95 96 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName) 97 throw (css::uno::RuntimeException) 98 { return ServiceName == getSupportedServiceNames()[0]; } 99 100 virtual css::uno::Sequence< rtl::OUString > SAL_CALL 101 getSupportedServiceNames() throw (css::uno::RuntimeException) 102 { return getDefaultSupportedServiceNames(); } 103 104 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL 105 getPropertySetInfo() throw (css::uno::RuntimeException) 106 { return css::uno::Reference< css::beans::XPropertySetInfo >(); } 107 108 virtual void SAL_CALL setPropertyValue( 109 rtl::OUString const &, css::uno::Any const &) 110 throw ( 111 css::beans::UnknownPropertyException, 112 css::beans::PropertyVetoException, 113 css::lang::IllegalArgumentException, 114 css::lang::WrappedTargetException, css::uno::RuntimeException); 115 116 virtual css::uno::Any SAL_CALL getPropertyValue( 117 rtl::OUString const & PropertyName) 118 throw ( 119 css::beans::UnknownPropertyException, 120 css::lang::WrappedTargetException, css::uno::RuntimeException); 121 122 virtual void SAL_CALL addPropertyChangeListener( 123 rtl::OUString const &, 124 css::uno::Reference< css::beans::XPropertyChangeListener > const &) 125 throw ( 126 css::beans::UnknownPropertyException, 127 css::lang::WrappedTargetException, css::uno::RuntimeException) 128 {} 129 130 virtual void SAL_CALL removePropertyChangeListener( 131 rtl::OUString const &, 132 css::uno::Reference< css::beans::XPropertyChangeListener > const &) 133 throw ( 134 css::beans::UnknownPropertyException, 135 css::lang::WrappedTargetException, css::uno::RuntimeException) 136 {} 137 138 virtual void SAL_CALL addVetoableChangeListener( 139 rtl::OUString const &, 140 css::uno::Reference< css::beans::XVetoableChangeListener > const &) 141 throw ( 142 css::beans::UnknownPropertyException, 143 css::lang::WrappedTargetException, css::uno::RuntimeException) 144 {} 145 146 virtual void SAL_CALL removeVetoableChangeListener( 147 rtl::OUString const &, 148 css::uno::Reference< css::beans::XVetoableChangeListener > const &) 149 throw ( 150 css::beans::UnknownPropertyException, 151 css::lang::WrappedTargetException, css::uno::RuntimeException) 152 {} 153 }; 154 155 void Default::setPropertyValue(rtl::OUString const &, css::uno::Any const &) 156 throw ( 157 css::beans::UnknownPropertyException, css::beans::PropertyVetoException, 158 css::lang::IllegalArgumentException, css::lang::WrappedTargetException, 159 css::uno::RuntimeException) 160 { 161 throw css::lang::IllegalArgumentException( 162 rtl::OUString( 163 RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")), 164 static_cast< cppu::OWeakObject * >(this), -1); 165 } 166 167 css::uno::Any Default::getPropertyValue(rtl::OUString const & PropertyName) 168 throw ( 169 css::beans::UnknownPropertyException, css::lang::WrappedTargetException, 170 css::uno::RuntimeException) 171 { 172 if (PropertyName.equalsAsciiL( 173 RTL_CONSTASCII_STRINGPARAM("EnableATToolSupport")) || 174 PropertyName.equalsAsciiL( 175 RTL_CONSTASCII_STRINGPARAM("ExternalMailer")) || 176 PropertyName.equalsAsciiL( 177 RTL_CONSTASCII_STRINGPARAM("SourceViewFontHeight")) || 178 PropertyName.equalsAsciiL( 179 RTL_CONSTASCII_STRINGPARAM("SourceViewFontName")) || 180 PropertyName.equalsAsciiL( 181 RTL_CONSTASCII_STRINGPARAM("WorkPathVariable")) || 182 PropertyName.equalsAsciiL( 183 RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName")) || 184 PropertyName.equalsAsciiL( 185 RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")) || 186 PropertyName.equalsAsciiL( 187 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")) || 188 PropertyName.equalsAsciiL( 189 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")) || 190 PropertyName.equalsAsciiL( 191 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")) || 192 PropertyName.equalsAsciiL( 193 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")) || 194 PropertyName.equalsAsciiL( 195 RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy")) || 196 PropertyName.equalsAsciiL( 197 RTL_CONSTASCII_STRINGPARAM("ooInetProxyType"))) 198 { 199 return css::uno::makeAny(css::beans::Optional< css::uno::Any >()); 200 } 201 throw css::beans::UnknownPropertyException( 202 PropertyName, static_cast< cppu::OWeakObject * >(this)); 203 } 204 205 css::uno::Reference< css::uno::XInterface > createBackend( 206 css::uno::Reference< css::uno::XComponentContext > const & context, 207 rtl::OUString const & name) 208 { 209 try { 210 return css::uno::Reference< css::lang::XMultiComponentFactory >( 211 context->getServiceManager(), css::uno::UNO_SET_THROW)-> 212 createInstanceWithContext(name, context); 213 } catch (css::uno::RuntimeException &) { 214 // Assuming these exceptions are real errors: 215 throw; 216 } catch (css::uno::Exception & e) { 217 // Assuming these exceptions indicate that the service is not installed: 218 OSL_TRACE( 219 "createInstance(%s) failed with %s", 220 rtl::OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr(), 221 rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr()); 222 return css::uno::Reference< css::uno::XInterface >(); 223 } 224 } 225 226 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( 227 css::uno::Reference< css::uno::XComponentContext > const & context) 228 { 229 rtl::OUString desktop; 230 css::uno::Reference< css::uno::XCurrentContext > current( 231 css::uno::getCurrentContext()); 232 if (current.is()) { 233 current->getValueByName( 234 rtl::OUString( 235 RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>= 236 desktop; 237 } 238 // Fall back to the default if the specific backend is not available: 239 css::uno::Reference< css::uno::XInterface > backend; 240 if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("GNOME"))) { 241 backend = createBackend( 242 context, 243 rtl::OUString( 244 RTL_CONSTASCII_USTRINGPARAM( 245 "com.sun.star.configuration.backend.GconfBackend"))); 246 } else if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE"))) { 247 backend = createBackend( 248 context, 249 rtl::OUString( 250 RTL_CONSTASCII_USTRINGPARAM( 251 "com.sun.star.configuration.backend.KDEBackend"))); 252 } else if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE4"))) { 253 backend = createBackend( 254 context, 255 rtl::OUString( 256 RTL_CONSTASCII_USTRINGPARAM( 257 "com.sun.star.configuration.backend.KDE4Backend"))); 258 } 259 return backend.is() 260 ? backend : static_cast< cppu::OWeakObject * >(new Default); 261 } 262 263 static cppu::ImplementationEntry const services[] = { 264 { &createInstance, &getDefaultImplementationName, 265 &getDefaultSupportedServiceNames, &cppu::createSingleComponentFactory, 0, 266 0 }, 267 { 0, 0, 0, 0, 0, 0 } 268 }; 269 270 } 271 272 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( 273 char const * pImplName, void * pServiceManager, void * pRegistryKey) 274 { 275 return cppu::component_getFactoryHelper( 276 pImplName, pServiceManager, pRegistryKey, services); 277 } 278 279 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL 280 component_getImplementationEnvironment( 281 char const ** ppEnvTypeName, uno_Environment **) 282 { 283 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 284 } 285