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