1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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"
32 #include "rtl/string.h"
33 #include "rtl/ustring.hxx"
35 #include "kde4access.hxx"
39 #define SEMI_COLON ';'
41 namespace kde4access
{
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";
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
== "SourceViewFontHeight")
68 aFixedFont
= KGlobalSettings::fixedFont();
69 nFontHeight
= aFixedFont
.pointSize();
70 return css::beans::Optional
< css::uno::Any
>(
71 true, uno::makeAny( nFontHeight
) );
72 } else if (id
== "SourceViewFontName")
76 :: OUString sFontName
;
78 aFixedFont
= KGlobalSettings::fixedFont();
79 aFontName
= aFixedFont
.family();
80 sFontName
= (const sal_Unicode
*) aFontName
.utf16();
81 return css::beans::Optional
< css::uno::Any
>(
82 true, uno::makeAny( sFontName
) );
83 } else if (id
== "EnableATToolSupport")
85 /* does not make much sense without an accessibility bridge */
86 bool ATToolSupport
= false;
87 return css::beans::Optional
< css::uno::Any
>(
88 true, uno::makeAny( OUString::boolean( ATToolSupport
) ) );
89 } else if (id
== "WorkPathVariable")
91 QString
aDocumentsDir( KGlobalSettings::documentPath() );
92 OUString sDocumentsDir
;
93 OUString sDocumentsURL
;
94 if ( aDocumentsDir
.endsWith(QChar('/')) )
95 aDocumentsDir
.truncate ( aDocumentsDir
.length() - 1 );
96 sDocumentsDir
= (const sal_Unicode
*) aDocumentsDir
.utf16();
97 osl_getFileURLFromSystemPath( sDocumentsDir
.pData
, &sDocumentsURL
.pData
);
98 return css::beans::Optional
< css::uno::Any
>(
99 true, uno::makeAny( sDocumentsURL
) );
100 } else if (id
== "ooInetFTPProxyName")
103 switch ( KProtocolManager::proxyType() )
105 case KProtocolManager::ManualProxy
: // Proxies are manually configured
106 aFTPProxy
= KProtocolManager::proxyFor( "FTP" );
108 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
109 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
110 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
111 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
112 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
113 // The best we can do here is to ask the current value for a given address.
114 aFTPProxy
= KProtocolManager::proxyForUrl( KUrl("ftp://ftp.libreoffice.org") );
116 default: // No proxy is used
119 if ( !aFTPProxy
.isEmpty() )
121 KUrl
aProxy(aFTPProxy
);
122 OUString sProxy
= (const sal_Unicode
*) aProxy
.host().utf16();
123 return css::beans::Optional
< css::uno::Any
>(
124 true, uno::makeAny( sProxy
) );
126 } else if (id
== "ooInetFTPProxyPort")
129 switch ( KProtocolManager::proxyType() )
131 case KProtocolManager::ManualProxy
: // Proxies are manually configured
132 aFTPProxy
= KProtocolManager::proxyFor( "FTP" );
134 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
135 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
136 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
137 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
138 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
139 // The best we can do here is to ask the current value for a given address.
140 aFTPProxy
= KProtocolManager::proxyForUrl( KUrl("ftp://ftp.libreoffice.org") );
142 default: // No proxy is used
145 if ( !aFTPProxy
.isEmpty() )
147 KUrl
aProxy(aFTPProxy
);
148 sal_Int32 nPort
= aProxy
.port();
149 return css::beans::Optional
< css::uno::Any
>(
150 true, uno::makeAny( nPort
) );
152 } else if (id
== "ooInetHTTPProxyName")
155 switch ( KProtocolManager::proxyType() )
157 case KProtocolManager::ManualProxy
: // Proxies are manually configured
158 aHTTPProxy
= KProtocolManager::proxyFor( "HTTP" );
160 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
161 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
162 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
163 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
164 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
165 // The best we can do here is to ask the current value for a given address.
166 aHTTPProxy
= KProtocolManager::proxyForUrl( KUrl("http://http.libreoffice.org") );
168 default: // No proxy is used
171 if ( !aHTTPProxy
.isEmpty() )
173 KUrl
aProxy(aHTTPProxy
);
174 OUString sProxy
= (const sal_Unicode
*) aProxy
.host().utf16();
175 return css::beans::Optional
< css::uno::Any
>(
176 true, uno::makeAny( sProxy
) );
178 } else if (id
== "ooInetHTTPProxyPort")
181 switch ( KProtocolManager::proxyType() )
183 case KProtocolManager::ManualProxy
: // Proxies are manually configured
184 aHTTPProxy
= KProtocolManager::proxyFor( "HTTP" );
186 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
187 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
188 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
189 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
190 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
191 // The best we can do here is to ask the current value for a given address.
192 aHTTPProxy
= KProtocolManager::proxyForUrl( KUrl("http://http.libreoffice.org") );
194 default: // No proxy is used
197 if ( !aHTTPProxy
.isEmpty() )
199 KUrl
aProxy(aHTTPProxy
);
200 sal_Int32 nPort
= aProxy
.port();
201 return css::beans::Optional
< css::uno::Any
>(
202 true, uno::makeAny( nPort
) );
204 } else if (id
== "ooInetHTTPSProxyName")
207 switch ( KProtocolManager::proxyType() )
209 case KProtocolManager::ManualProxy
: // Proxies are manually configured
210 aHTTPSProxy
= KProtocolManager::proxyFor( "HTTPS" );
212 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
213 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
214 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
215 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
216 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
217 // The best we can do here is to ask the current value for a given address.
218 aHTTPSProxy
= KProtocolManager::proxyForUrl( KUrl("https://https.libreoffice.org") );
220 default: // No proxy is used
223 if ( !aHTTPSProxy
.isEmpty() )
225 KUrl
aProxy(aHTTPSProxy
);
226 OUString sProxy
= (const sal_Unicode
*) aProxy
.host().utf16();
227 return css::beans::Optional
< css::uno::Any
>(
228 true, uno::makeAny( sProxy
) );
230 } else if (id
== "ooInetHTTPSProxyPort")
233 switch ( KProtocolManager::proxyType() )
235 case KProtocolManager::ManualProxy
: // Proxies are manually configured
236 aHTTPSProxy
= KProtocolManager::proxyFor( "HTTPS" );
238 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
239 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
240 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
241 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
242 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
243 // The best we can do here is to ask the current value for a given address.
244 aHTTPSProxy
= KProtocolManager::proxyForUrl( KUrl("https://https.libreoffice.org") );
246 default: // No proxy is used
249 if ( !aHTTPSProxy
.isEmpty() )
251 KUrl
aProxy(aHTTPSProxy
);
252 sal_Int32 nPort
= aProxy
.port();
253 return css::beans::Optional
< css::uno::Any
>(
254 true, uno::makeAny( nPort
) );
256 } else if ( id
== "ooInetNoProxy" ) {
258 switch ( KProtocolManager::proxyType() )
260 case KProtocolManager::ManualProxy
: // Proxies are manually configured
261 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
262 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
263 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
264 aNoProxyFor
= KProtocolManager::noProxyFor();
266 default: // No proxy is used
269 if ( !aNoProxyFor
.isEmpty() )
271 OUString sNoProxyFor
;
273 aNoProxyFor
= aNoProxyFor
.replace( COMMA
, SEMI_COLON
);
274 sNoProxyFor
= (const sal_Unicode
*) aNoProxyFor
.utf16();
275 return css::beans::Optional
< css::uno::Any
>(
276 true, uno::makeAny( sNoProxyFor
) );
278 } else if ( id
== "ooInetProxyType" ) {
280 switch ( KProtocolManager::proxyType() )
282 case KProtocolManager::ManualProxy
: // Proxies are manually configured
283 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
284 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
285 case KProtocolManager::EnvVarProxy
: // Use the proxy values set through environment variables
288 default: // No proxy is used
291 return css::beans::Optional
< css::uno::Any
>(
292 true, uno::makeAny( (sal_Int32
) nProxyType
) );
294 OSL_ASSERT(false); // this cannot happen
296 return css::beans::Optional
< css::uno::Any
>();
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */