bump product version to 4.1.6.2
[LibreOffice.git] / shell / source / backends / kde4be / kde4access.cxx
blob6bd8f4a45bd0e5a76759e178ca34725bcd036617
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/config.h"
22 #include "QFont"
23 #include "QString"
24 #include "kemailsettings.h"
25 #include "kglobalsettings.h"
26 #include "kprotocolmanager.h"
28 #include "com/sun/star/uno/Any.hxx"
29 #include "cppu/unotype.hxx"
30 #include "osl/diagnose.h"
31 #include "osl/file.h"
32 #include "rtl/string.h"
33 #include "rtl/ustring.hxx"
35 #include "kde4access.hxx"
37 #define SPACE ' '
38 #define COMMA ','
39 #define SEMI_COLON ';'
41 namespace kde4access {
43 namespace {
45 namespace uno = css::uno ;
49 css::beans::Optional< css::uno::Any > getValue(OUString const & id) {
50 if ( id == "ExternalMailer" ) {
51 KEMailSettings aEmailSettings;
52 QString aClientProgram;
53 OUString sClientProgram;
55 aClientProgram = aEmailSettings.getSetting( KEMailSettings::ClientProgram );
56 if ( aClientProgram.isEmpty() )
57 aClientProgram = "kmail";
58 else
59 aClientProgram = aClientProgram.section(SPACE, 0, 0);
60 sClientProgram = (const sal_Unicode *) aClientProgram.utf16();
61 return css::beans::Optional< css::uno::Any >(
62 true, uno::makeAny( sClientProgram ) );
63 } else if (id.equalsAsciiL(
64 RTL_CONSTASCII_STRINGPARAM("SourceViewFontHeight")))
66 QFont aFixedFont;
67 short nFontHeight;
69 aFixedFont = KGlobalSettings::fixedFont();
70 nFontHeight = aFixedFont.pointSize();
71 return css::beans::Optional< css::uno::Any >(
72 true, uno::makeAny( nFontHeight ) );
73 } else if (id.equalsAsciiL(
74 RTL_CONSTASCII_STRINGPARAM("SourceViewFontName")))
76 QFont aFixedFont;
77 QString aFontName;
78 :: OUString sFontName;
80 aFixedFont = KGlobalSettings::fixedFont();
81 aFontName = aFixedFont.family();
82 sFontName = (const sal_Unicode *) aFontName.utf16();
83 return css::beans::Optional< css::uno::Any >(
84 true, uno::makeAny( sFontName ) );
85 } else if (id.equalsAsciiL(
86 RTL_CONSTASCII_STRINGPARAM("EnableATToolSupport")))
88 /* does not make much sense without an accessibility bridge */
89 sal_Bool ATToolSupport = sal_False;
90 return css::beans::Optional< css::uno::Any >(
91 true, uno::makeAny( OUString::valueOf( ATToolSupport ) ) );
92 } else if (id.equalsAsciiL(
93 RTL_CONSTASCII_STRINGPARAM("WorkPathVariable")))
95 QString aDocumentsDir( KGlobalSettings::documentPath() );
96 OUString sDocumentsDir;
97 OUString sDocumentsURL;
98 if ( aDocumentsDir.endsWith(QChar('/')) )
99 aDocumentsDir.truncate ( aDocumentsDir.length() - 1 );
100 sDocumentsDir = (const sal_Unicode *) aDocumentsDir.utf16();
101 osl_getFileURLFromSystemPath( sDocumentsDir.pData, &sDocumentsURL.pData );
102 return css::beans::Optional< css::uno::Any >(
103 true, uno::makeAny( sDocumentsURL ) );
104 } else if (id.equalsAsciiL(
105 RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName")))
107 QString aFTPProxy;
108 switch ( KProtocolManager::proxyType() )
110 case KProtocolManager::ManualProxy: // Proxies are manually configured
111 aFTPProxy = KProtocolManager::proxyFor( "FTP" );
112 break;
113 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
114 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
115 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
116 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
117 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
118 // The best we can do here is to ask the current value for a given address.
119 aFTPProxy = KProtocolManager::proxyForUrl( KUrl("ftp://ftp.libreoffice.org") );
120 break;
121 default: // No proxy is used
122 break;
124 if ( !aFTPProxy.isEmpty() )
126 KUrl aProxy(aFTPProxy);
127 OUString sProxy = (const sal_Unicode *) aProxy.host().utf16();
128 return css::beans::Optional< css::uno::Any >(
129 true, uno::makeAny( sProxy ) );
131 } else if (id.equalsAsciiL(
132 RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")))
134 QString aFTPProxy;
135 switch ( KProtocolManager::proxyType() )
137 case KProtocolManager::ManualProxy: // Proxies are manually configured
138 aFTPProxy = KProtocolManager::proxyFor( "FTP" );
139 break;
140 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
141 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
142 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
143 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
144 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
145 // The best we can do here is to ask the current value for a given address.
146 aFTPProxy = KProtocolManager::proxyForUrl( KUrl("ftp://ftp.libreoffice.org") );
147 break;
148 default: // No proxy is used
149 break;
151 if ( !aFTPProxy.isEmpty() )
153 KUrl aProxy(aFTPProxy);
154 sal_Int32 nPort = aProxy.port();
155 return css::beans::Optional< css::uno::Any >(
156 true, uno::makeAny( nPort ) );
158 } else if (id.equalsAsciiL(
159 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")))
161 QString aHTTPProxy;
162 switch ( KProtocolManager::proxyType() )
164 case KProtocolManager::ManualProxy: // Proxies are manually configured
165 aHTTPProxy = KProtocolManager::proxyFor( "HTTP" );
166 break;
167 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
168 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
169 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
170 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
171 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
172 // The best we can do here is to ask the current value for a given address.
173 aHTTPProxy = KProtocolManager::proxyForUrl( KUrl("http://http.libreoffice.org") );
174 break;
175 default: // No proxy is used
176 break;
178 if ( !aHTTPProxy.isEmpty() )
180 KUrl aProxy(aHTTPProxy);
181 OUString sProxy = (const sal_Unicode *) aProxy.host().utf16();
182 return css::beans::Optional< css::uno::Any >(
183 true, uno::makeAny( sProxy ) );
185 } else if (id.equalsAsciiL(
186 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")))
188 QString aHTTPProxy;
189 switch ( KProtocolManager::proxyType() )
191 case KProtocolManager::ManualProxy: // Proxies are manually configured
192 aHTTPProxy = KProtocolManager::proxyFor( "HTTP" );
193 break;
194 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
195 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
196 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
197 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
198 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
199 // The best we can do here is to ask the current value for a given address.
200 aHTTPProxy = KProtocolManager::proxyForUrl( KUrl("http://http.libreoffice.org") );
201 break;
202 default: // No proxy is used
203 break;
205 if ( !aHTTPProxy.isEmpty() )
207 KUrl aProxy(aHTTPProxy);
208 sal_Int32 nPort = aProxy.port();
209 return css::beans::Optional< css::uno::Any >(
210 true, uno::makeAny( nPort ) );
212 } else if (id.equalsAsciiL(
213 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")))
215 QString aHTTPSProxy;
216 switch ( KProtocolManager::proxyType() )
218 case KProtocolManager::ManualProxy: // Proxies are manually configured
219 aHTTPSProxy = KProtocolManager::proxyFor( "HTTPS" );
220 break;
221 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
222 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
223 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
224 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
225 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
226 // The best we can do here is to ask the current value for a given address.
227 aHTTPSProxy = KProtocolManager::proxyForUrl( KUrl("https://https.libreoffice.org") );
228 break;
229 default: // No proxy is used
230 break;
232 if ( !aHTTPSProxy.isEmpty() )
234 KUrl aProxy(aHTTPSProxy);
235 OUString sProxy = (const sal_Unicode *) aProxy.host().utf16();
236 return css::beans::Optional< css::uno::Any >(
237 true, uno::makeAny( sProxy ) );
239 } else if (id.equalsAsciiL(
240 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")))
242 QString aHTTPSProxy;
243 switch ( KProtocolManager::proxyType() )
245 case KProtocolManager::ManualProxy: // Proxies are manually configured
246 aHTTPSProxy = KProtocolManager::proxyFor( "HTTPS" );
247 break;
248 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
249 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
250 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
251 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
252 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
253 // The best we can do here is to ask the current value for a given address.
254 aHTTPSProxy = KProtocolManager::proxyForUrl( KUrl("https://https.libreoffice.org") );
255 break;
256 default: // No proxy is used
257 break;
259 if ( !aHTTPSProxy.isEmpty() )
261 KUrl aProxy(aHTTPSProxy);
262 sal_Int32 nPort = aProxy.port();
263 return css::beans::Optional< css::uno::Any >(
264 true, uno::makeAny( nPort ) );
266 } else if ( id == "ooInetNoProxy" ) {
267 QString aNoProxyFor;
268 switch ( KProtocolManager::proxyType() )
270 case KProtocolManager::ManualProxy: // Proxies are manually configured
271 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
272 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
273 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
274 aNoProxyFor = KProtocolManager::noProxyFor();
275 break;
276 default: // No proxy is used
277 break;
279 if ( !aNoProxyFor.isEmpty() )
281 OUString sNoProxyFor;
283 aNoProxyFor = aNoProxyFor.replace( COMMA, SEMI_COLON );
284 sNoProxyFor = (const sal_Unicode *) aNoProxyFor.utf16();
285 return css::beans::Optional< css::uno::Any >(
286 true, uno::makeAny( sNoProxyFor ) );
288 } else if ( id == "ooInetProxyType" ) {
289 int nProxyType;
290 switch ( KProtocolManager::proxyType() )
292 case KProtocolManager::ManualProxy: // Proxies are manually configured
293 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
294 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
295 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
296 nProxyType = 1;
297 break;
298 default: // No proxy is used
299 nProxyType = 0;
301 return css::beans::Optional< css::uno::Any >(
302 true, uno::makeAny( (sal_Int32) nProxyType ) );
303 } else {
304 OSL_ASSERT(false); // this cannot happen
306 return css::beans::Optional< css::uno::Any >();
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */