bump product version to 5.0.4.1
[LibreOffice.git] / shell / source / backends / kdebe / kdeaccess.cxx
blobb7de82a312bee9f95a8d24f3013b597959d02019
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 "com/sun/star/uno/Any.hxx"
23 #include "cppu/unotype.hxx"
24 #include "osl/diagnose.h"
25 #include "osl/file.h"
26 #include "rtl/string.h"
27 #include "rtl/ustring.hxx"
29 #include "shell/kde_headers.h"
31 #include "kdeaccess.hxx"
33 #define SPACE ' '
34 #define COMMA ','
35 #define SEMI_COLON ';'
37 namespace kdeaccess {
39 namespace {
41 namespace uno = css::uno ;
45 css::beans::Optional< css::uno::Any > getValue(OUString const & id) {
46 if ( id == "ExternalMailer" ) {
47 KEMailSettings aEmailSettings;
48 QString aClientProgram;
49 OUString sClientProgram;
51 aClientProgram = aEmailSettings.getSetting( KEMailSettings::ClientProgram );
52 if ( aClientProgram.isEmpty() )
53 aClientProgram = "kmail";
54 else
55 aClientProgram = aClientProgram.section(SPACE, 0, 0);
56 sClientProgram = (const sal_Unicode *) aClientProgram.ucs2();
57 return css::beans::Optional< css::uno::Any >(
58 true, uno::makeAny( sClientProgram ) );
59 } else if (id == "SourceViewFontHeight")
61 QFont aFixedFont;
62 short nFontHeight;
64 aFixedFont = KGlobalSettings::fixedFont();
65 nFontHeight = aFixedFont.pointSize();
66 return css::beans::Optional< css::uno::Any >(
67 true, uno::makeAny( nFontHeight ) );
68 } else if (id == "SourceViewFontName")
70 QFont aFixedFont;
71 QString aFontName;
72 :: OUString sFontName;
74 aFixedFont = KGlobalSettings::fixedFont();
75 aFontName = aFixedFont.family();
76 sFontName = (const sal_Unicode *) aFontName.ucs2();
77 return css::beans::Optional< css::uno::Any >(
78 true, uno::makeAny( sFontName ) );
79 } else if (id == "EnableATToolSupport")
81 /* does not make much sense without an accessibility bridge */
82 bool ATToolSupport = false;
83 return css::beans::Optional< css::uno::Any >(
84 true, uno::makeAny( OUString::boolean( ATToolSupport ) ) );
85 } else if (id == "WorkPathVariable")
87 QString aDocumentsDir( KGlobalSettings::documentPath() );
88 OUString sDocumentsDir;
89 OUString sDocumentsURL;
90 if ( aDocumentsDir.endsWith(QChar('/')) )
91 aDocumentsDir.truncate ( aDocumentsDir.length() - 1 );
92 sDocumentsDir = (const sal_Unicode *) aDocumentsDir.ucs2();
93 osl_getFileURLFromSystemPath( sDocumentsDir.pData, &sDocumentsURL.pData );
94 return css::beans::Optional< css::uno::Any >(
95 true, uno::makeAny( sDocumentsURL ) );
96 } else if (id == "ooInetFTPProxyName")
98 QString aFTPProxy;
99 switch ( KProtocolManager::proxyType() )
101 case KProtocolManager::ManualProxy: // Proxies are manually configured
102 aFTPProxy = KProtocolManager::proxyFor( "FTP" );
103 break;
104 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
105 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
106 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
107 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
108 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
109 // The best we can do here is to ask the current value for a given address.
110 aFTPProxy = KProtocolManager::proxyForURL( "ftp://ftp.openoffice.org" );
111 break;
112 default: // No proxy is used
113 break;
115 if ( !aFTPProxy.isEmpty() )
117 KURL aProxy(aFTPProxy);
118 OUString sProxy = (const sal_Unicode *) aProxy.host().ucs2();
119 return css::beans::Optional< css::uno::Any >(
120 true, uno::makeAny( sProxy ) );
122 } else if (id == "ooInetFTPProxyPort")
124 QString aFTPProxy;
125 switch ( KProtocolManager::proxyType() )
127 case KProtocolManager::ManualProxy: // Proxies are manually configured
128 aFTPProxy = KProtocolManager::proxyFor( "FTP" );
129 break;
130 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
131 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
132 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
133 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
134 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
135 // The best we can do here is to ask the current value for a given address.
136 aFTPProxy = KProtocolManager::proxyForURL( "ftp://ftp.openoffice.org" );
137 break;
138 default: // No proxy is used
139 break;
141 if ( !aFTPProxy.isEmpty() )
143 KURL aProxy(aFTPProxy);
144 sal_Int32 nPort = aProxy.port();
145 return css::beans::Optional< css::uno::Any >(
146 true, uno::makeAny( nPort ) );
148 } else if (id == "ooInetHTTPProxyName")
150 QString aHTTPProxy;
151 switch ( KProtocolManager::proxyType() )
153 case KProtocolManager::ManualProxy: // Proxies are manually configured
154 aHTTPProxy = KProtocolManager::proxyFor( "HTTP" );
155 break;
156 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
157 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
158 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
159 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
160 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
161 // The best we can do here is to ask the current value for a given address.
162 aHTTPProxy = KProtocolManager::proxyForURL( "http://http.openoffice.org" );
163 break;
164 default: // No proxy is used
165 break;
167 if ( !aHTTPProxy.isEmpty() )
169 KURL aProxy(aHTTPProxy);
170 OUString sProxy = (const sal_Unicode *) aProxy.host().ucs2();
171 return css::beans::Optional< css::uno::Any >(
172 true, uno::makeAny( sProxy ) );
174 } else if (id == "ooInetHTTPProxyPort")
176 QString aHTTPProxy;
177 switch ( KProtocolManager::proxyType() )
179 case KProtocolManager::ManualProxy: // Proxies are manually configured
180 aHTTPProxy = KProtocolManager::proxyFor( "HTTP" );
181 break;
182 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
183 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
184 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
185 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
186 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
187 // The best we can do here is to ask the current value for a given address.
188 aHTTPProxy = KProtocolManager::proxyForURL( "http://http.openoffice.org" );
189 break;
190 default: // No proxy is used
191 break;
193 if ( !aHTTPProxy.isEmpty() )
195 KURL aProxy(aHTTPProxy);
196 sal_Int32 nPort = aProxy.port();
197 return css::beans::Optional< css::uno::Any >(
198 true, uno::makeAny( nPort ) );
200 } else if (id == "ooInetHTTPSProxyName")
202 QString aHTTPSProxy;
203 switch ( KProtocolManager::proxyType() )
205 case KProtocolManager::ManualProxy: // Proxies are manually configured
206 aHTTPSProxy = KProtocolManager::proxyFor( "HTTPS" );
207 break;
208 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
209 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
210 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
211 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
212 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
213 // The best we can do here is to ask the current value for a given address.
214 aHTTPSProxy = KProtocolManager::proxyForURL( "https://https.openoffice.org" );
215 break;
216 default: // No proxy is used
217 break;
219 if ( !aHTTPSProxy.isEmpty() )
221 KURL aProxy(aHTTPSProxy);
222 OUString sProxy = (const sal_Unicode *) aProxy.host().ucs2();
223 return css::beans::Optional< css::uno::Any >(
224 true, uno::makeAny( sProxy ) );
226 } else if (id == "ooInetHTTPSProxyPort")
228 QString aHTTPSProxy;
229 switch ( KProtocolManager::proxyType() )
231 case KProtocolManager::ManualProxy: // Proxies are manually configured
232 aHTTPSProxy = KProtocolManager::proxyFor( "HTTPS" );
233 break;
234 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
235 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
236 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
237 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
238 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
239 // The best we can do here is to ask the current value for a given address.
240 aHTTPSProxy = KProtocolManager::proxyForURL( "https://https.openoffice.org" );
241 break;
242 default: // No proxy is used
243 break;
245 if ( !aHTTPSProxy.isEmpty() )
247 KURL aProxy(aHTTPSProxy);
248 sal_Int32 nPort = aProxy.port();
249 return css::beans::Optional< css::uno::Any >(
250 true, uno::makeAny( nPort ) );
252 } else if ( id == "ooInetNoProxy" ) {
253 QString aNoProxyFor;
254 switch ( KProtocolManager::proxyType() )
256 case KProtocolManager::ManualProxy: // Proxies are manually configured
257 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
258 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
259 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
260 aNoProxyFor = KProtocolManager::noProxyFor();
261 break;
262 default: // No proxy is used
263 break;
265 if ( !aNoProxyFor.isEmpty() )
267 OUString sNoProxyFor;
269 aNoProxyFor = aNoProxyFor.replace( COMMA, SEMI_COLON );
270 sNoProxyFor = (const sal_Unicode *) aNoProxyFor.ucs2();
271 return css::beans::Optional< css::uno::Any >(
272 true, uno::makeAny( sNoProxyFor ) );
274 } else if ( id == "ooInetProxyType" ) {
275 int nProxyType;
276 switch ( KProtocolManager::proxyType() )
278 case KProtocolManager::ManualProxy: // Proxies are manually configured
279 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
280 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
281 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
282 nProxyType = 1;
283 break;
284 default: // No proxy is used
285 nProxyType = 0;
287 return css::beans::Optional< css::uno::Any >(
288 true, uno::makeAny( (sal_Int32) nProxyType ) );
289 } else {
290 OSL_ASSERT(false); // this cannot happen
292 return css::beans::Optional< css::uno::Any >();
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */