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