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 "com/sun/star/uno/Any.hxx" 32 #include "cppu/unotype.hxx" 33 #include "osl/diagnose.h" 34 #include "osl/file.h" 35 #include "rtl/string.h" 36 #include "rtl/ustring.hxx" 37 38 #include "kde_headers.h" 39 40 #include "kdeaccess.hxx" 41 42 #define SPACE ' ' 43 #define COMMA ',' 44 #define SEMI_COLON ';' 45 46 namespace kdeaccess { 47 48 namespace { 49 50 namespace css = com::sun::star ; 51 namespace uno = css::uno ; 52 53 } 54 55 css::beans::Optional< css::uno::Any > getValue(rtl::OUString const & id) { 56 if (id.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ExternalMailer"))) { 57 KEMailSettings aEmailSettings; 58 QString aClientProgram; 59 ::rtl::OUString sClientProgram; 60 61 aClientProgram = aEmailSettings.getSetting( KEMailSettings::ClientProgram ); 62 if ( aClientProgram.isEmpty() ) 63 aClientProgram = "kmail"; 64 else 65 aClientProgram = aClientProgram.section(SPACE, 0, 0); 66 sClientProgram = (const sal_Unicode *) aClientProgram.ucs2(); 67 return css::beans::Optional< css::uno::Any >( 68 true, uno::makeAny( sClientProgram ) ); 69 } else if (id.equalsAsciiL( 70 RTL_CONSTASCII_STRINGPARAM("SourceViewFontHeight"))) 71 { 72 QFont aFixedFont; 73 short nFontHeight; 74 75 aFixedFont = KGlobalSettings::fixedFont(); 76 nFontHeight = aFixedFont.pointSize(); 77 return css::beans::Optional< css::uno::Any >( 78 true, uno::makeAny( nFontHeight ) ); 79 } else if (id.equalsAsciiL( 80 RTL_CONSTASCII_STRINGPARAM("SourceViewFontName"))) 81 { 82 QFont aFixedFont; 83 QString aFontName; 84 :: rtl::OUString sFontName; 85 86 aFixedFont = KGlobalSettings::fixedFont(); 87 aFontName = aFixedFont.family(); 88 sFontName = (const sal_Unicode *) aFontName.ucs2(); 89 return css::beans::Optional< css::uno::Any >( 90 true, uno::makeAny( sFontName ) ); 91 } else if (id.equalsAsciiL( 92 RTL_CONSTASCII_STRINGPARAM("EnableATToolSupport"))) 93 { 94 /* does not make much sense without an accessibility bridge */ 95 sal_Bool ATToolSupport = sal_False; 96 return css::beans::Optional< css::uno::Any >( 97 true, uno::makeAny( rtl::OUString::valueOf( ATToolSupport ) ) ); 98 } else if (id.equalsAsciiL( 99 RTL_CONSTASCII_STRINGPARAM("WorkPathVariable"))) 100 { 101 QString aDocumentsDir( KGlobalSettings::documentPath() ); 102 rtl::OUString sDocumentsDir; 103 rtl::OUString sDocumentsURL; 104 if ( aDocumentsDir.endsWith(QChar('/')) ) 105 aDocumentsDir.truncate ( aDocumentsDir.length() - 1 ); 106 sDocumentsDir = (const sal_Unicode *) aDocumentsDir.ucs2(); 107 osl_getFileURLFromSystemPath( sDocumentsDir.pData, &sDocumentsURL.pData ); 108 return css::beans::Optional< css::uno::Any >( 109 true, uno::makeAny( sDocumentsURL ) ); 110 } else if (id.equalsAsciiL( 111 RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName"))) 112 { 113 QString aFTPProxy; 114 switch ( KProtocolManager::proxyType() ) 115 { 116 case KProtocolManager::ManualProxy: // Proxies are manually configured 117 aFTPProxy = KProtocolManager::proxyFor( "FTP" ); 118 break; 119 case KProtocolManager::PACProxy: // A proxy configuration URL has been given 120 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered 121 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables 122 // In such cases, the proxy address is not stored in KDE, but determined dynamically. 123 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind... 124 // The best we can do here is to ask the current value for a given address. 125 aFTPProxy = KProtocolManager::proxyForURL( "ftp://ftp.openoffice.org" ); 126 break; 127 default: // No proxy is used 128 break; 129 } 130 if ( !aFTPProxy.isEmpty() ) 131 { 132 KURL aProxy(aFTPProxy); 133 ::rtl::OUString sProxy = (const sal_Unicode *) aProxy.host().ucs2(); 134 return css::beans::Optional< css::uno::Any >( 135 true, uno::makeAny( sProxy ) ); 136 } 137 } else if (id.equalsAsciiL( 138 RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort"))) 139 { 140 QString aFTPProxy; 141 switch ( KProtocolManager::proxyType() ) 142 { 143 case KProtocolManager::ManualProxy: // Proxies are manually configured 144 aFTPProxy = KProtocolManager::proxyFor( "FTP" ); 145 break; 146 case KProtocolManager::PACProxy: // A proxy configuration URL has been given 147 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered 148 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables 149 // In such cases, the proxy address is not stored in KDE, but determined dynamically. 150 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind... 151 // The best we can do here is to ask the current value for a given address. 152 aFTPProxy = KProtocolManager::proxyForURL( "ftp://ftp.openoffice.org" ); 153 break; 154 default: // No proxy is used 155 break; 156 } 157 if ( !aFTPProxy.isEmpty() ) 158 { 159 KURL aProxy(aFTPProxy); 160 sal_Int32 nPort = aProxy.port(); 161 return css::beans::Optional< css::uno::Any >( 162 true, uno::makeAny( nPort ) ); 163 } 164 } else if (id.equalsAsciiL( 165 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName"))) 166 { 167 QString aHTTPProxy; 168 switch ( KProtocolManager::proxyType() ) 169 { 170 case KProtocolManager::ManualProxy: // Proxies are manually configured 171 aHTTPProxy = KProtocolManager::proxyFor( "HTTP" ); 172 break; 173 case KProtocolManager::PACProxy: // A proxy configuration URL has been given 174 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered 175 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables 176 // In such cases, the proxy address is not stored in KDE, but determined dynamically. 177 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind... 178 // The best we can do here is to ask the current value for a given address. 179 aHTTPProxy = KProtocolManager::proxyForURL( "http://http.openoffice.org" ); 180 break; 181 default: // No proxy is used 182 break; 183 } 184 if ( !aHTTPProxy.isEmpty() ) 185 { 186 KURL aProxy(aHTTPProxy); 187 ::rtl::OUString sProxy = (const sal_Unicode *) aProxy.host().ucs2(); 188 return css::beans::Optional< css::uno::Any >( 189 true, uno::makeAny( sProxy ) ); 190 } 191 } else if (id.equalsAsciiL( 192 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort"))) 193 { 194 QString aHTTPProxy; 195 switch ( KProtocolManager::proxyType() ) 196 { 197 case KProtocolManager::ManualProxy: // Proxies are manually configured 198 aHTTPProxy = KProtocolManager::proxyFor( "HTTP" ); 199 break; 200 case KProtocolManager::PACProxy: // A proxy configuration URL has been given 201 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered 202 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables 203 // In such cases, the proxy address is not stored in KDE, but determined dynamically. 204 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind... 205 // The best we can do here is to ask the current value for a given address. 206 aHTTPProxy = KProtocolManager::proxyForURL( "http://http.openoffice.org" ); 207 break; 208 default: // No proxy is used 209 break; 210 } 211 if ( !aHTTPProxy.isEmpty() ) 212 { 213 KURL aProxy(aHTTPProxy); 214 sal_Int32 nPort = aProxy.port(); 215 return css::beans::Optional< css::uno::Any >( 216 true, uno::makeAny( nPort ) ); 217 } 218 } else if (id.equalsAsciiL( 219 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName"))) 220 { 221 QString aHTTPSProxy; 222 switch ( KProtocolManager::proxyType() ) 223 { 224 case KProtocolManager::ManualProxy: // Proxies are manually configured 225 aHTTPSProxy = KProtocolManager::proxyFor( "HTTPS" ); 226 break; 227 case KProtocolManager::PACProxy: // A proxy configuration URL has been given 228 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered 229 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables 230 // In such cases, the proxy address is not stored in KDE, but determined dynamically. 231 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind... 232 // The best we can do here is to ask the current value for a given address. 233 aHTTPSProxy = KProtocolManager::proxyForURL( "https://https.openoffice.org" ); 234 break; 235 default: // No proxy is used 236 break; 237 } 238 if ( !aHTTPSProxy.isEmpty() ) 239 { 240 KURL aProxy(aHTTPSProxy); 241 ::rtl::OUString sProxy = (const sal_Unicode *) aProxy.host().ucs2(); 242 return css::beans::Optional< css::uno::Any >( 243 true, uno::makeAny( sProxy ) ); 244 } 245 } else if (id.equalsAsciiL( 246 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort"))) 247 { 248 QString aHTTPSProxy; 249 switch ( KProtocolManager::proxyType() ) 250 { 251 case KProtocolManager::ManualProxy: // Proxies are manually configured 252 aHTTPSProxy = KProtocolManager::proxyFor( "HTTPS" ); 253 break; 254 case KProtocolManager::PACProxy: // A proxy configuration URL has been given 255 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered 256 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables 257 // In such cases, the proxy address is not stored in KDE, but determined dynamically. 258 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind... 259 // The best we can do here is to ask the current value for a given address. 260 aHTTPSProxy = KProtocolManager::proxyForURL( "https://https.openoffice.org" ); 261 break; 262 default: // No proxy is used 263 break; 264 } 265 if ( !aHTTPSProxy.isEmpty() ) 266 { 267 KURL aProxy(aHTTPSProxy); 268 sal_Int32 nPort = aProxy.port(); 269 return css::beans::Optional< css::uno::Any >( 270 true, uno::makeAny( nPort ) ); 271 } 272 } else if (id.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy"))) { 273 QString aNoProxyFor; 274 switch ( KProtocolManager::proxyType() ) 275 { 276 case KProtocolManager::ManualProxy: // Proxies are manually configured 277 case KProtocolManager::PACProxy: // A proxy configuration URL has been given 278 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered 279 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables 280 aNoProxyFor = KProtocolManager::noProxyFor(); 281 break; 282 default: // No proxy is used 283 break; 284 } 285 if ( !aNoProxyFor.isEmpty() ) 286 { 287 ::rtl::OUString sNoProxyFor; 288 289 aNoProxyFor = aNoProxyFor.replace( COMMA, SEMI_COLON ); 290 sNoProxyFor = (const sal_Unicode *) aNoProxyFor.ucs2(); 291 return css::beans::Optional< css::uno::Any >( 292 true, uno::makeAny( sNoProxyFor ) ); 293 } 294 } else if (id.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetProxyType"))) { 295 int nProxyType; 296 switch ( KProtocolManager::proxyType() ) 297 { 298 case KProtocolManager::ManualProxy: // Proxies are manually configured 299 case KProtocolManager::PACProxy: // A proxy configuration URL has been given 300 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered 301 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables 302 nProxyType = 1; 303 break; 304 default: // No proxy is used 305 nProxyType = 0; 306 } 307 return css::beans::Optional< css::uno::Any >( 308 true, uno::makeAny( (sal_Int32) nProxyType ) ); 309 } else { 310 OSL_ASSERT(false); // this cannot happen 311 } 312 return css::beans::Optional< css::uno::Any >(); 313 } 314 315 } 316