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>
22 #include "kde5access.hxx"
24 #include <QtGui/QFont>
25 #include <QtCore/QString>
26 #include <QtGui/QFontDatabase>
27 #include <QtCore/QStandardPaths>
28 #include <QtCore/QDir>
29 #include <QtCore/QUrl>
31 #include <kprotocolmanager.h>
33 #include <kemailsettings.h>
34 // #include <kglobalsettings.h>
36 #include <com/sun/star/uno/Any.hxx>
37 #include <cppu/unotype.hxx>
38 #include <osl/diagnose.h>
40 #include <rtl/string.h>
41 #include <rtl/ustring.hxx>
47 namespace uno
= css::uno
;
50 css::beans::Optional
<css::uno::Any
> getValue(OUString
const& id
)
52 if (id
== "ExternalMailer")
54 KEMailSettings aEmailSettings
;
55 QString aClientProgram
;
56 OUString sClientProgram
;
58 aClientProgram
= aEmailSettings
.getSetting(KEMailSettings::ClientProgram
);
59 if (aClientProgram
.isEmpty())
60 aClientProgram
= QStringLiteral("kmail");
62 aClientProgram
= aClientProgram
.section(QLatin1Char(' '), 0, 0);
63 sClientProgram
= reinterpret_cast<const sal_Unicode
*>(aClientProgram
.utf16());
64 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(sClientProgram
));
66 else if (id
== "SourceViewFontHeight")
68 const QFont aFixedFont
= QFontDatabase::systemFont(QFontDatabase::FixedFont
);
69 const short nFontHeight
= aFixedFont
.pointSize();
70 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(nFontHeight
));
72 else if (id
== "SourceViewFontName")
74 const QFont aFixedFont
= QFontDatabase::systemFont(QFontDatabase::FixedFont
);
75 const QString aFontName
= aFixedFont
.family();
76 const OUString sFontName
= reinterpret_cast<const sal_Unicode
*>(aFontName
.utf16());
77 return css::beans::Optional
<css::uno::Any
>(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
>(true,
84 uno::makeAny(OUString::boolean(ATToolSupport
)));
86 else if (id
== "WorkPathVariable")
88 QString
aDocumentsDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation
));
89 if (aDocumentsDir
.isEmpty())
90 aDocumentsDir
= QDir::homePath();
91 OUString sDocumentsDir
;
92 OUString sDocumentsURL
;
93 if (aDocumentsDir
.endsWith(QLatin1Char('/')))
94 aDocumentsDir
.truncate(aDocumentsDir
.length() - 1);
95 sDocumentsDir
= reinterpret_cast<const sal_Unicode
*>(aDocumentsDir
.utf16());
96 osl_getFileURLFromSystemPath(sDocumentsDir
.pData
, &sDocumentsURL
.pData
);
97 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(sDocumentsURL
));
99 else if (id
== "ooInetFTPProxyName")
102 switch (KProtocolManager::proxyType())
104 case KProtocolManager::ManualProxy
: // Proxies are manually configured
105 aFTPProxy
= KProtocolManager::proxyFor(QStringLiteral("FTP"));
107 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
108 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
109 case KProtocolManager::
110 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(
115 QUrl(QStringLiteral("ftp://ftp.libreoffice.org")));
117 default: // No proxy is used
120 if (!aFTPProxy
.isEmpty())
122 QUrl
aProxy(aFTPProxy
);
123 OUString sProxy
= reinterpret_cast<const sal_Unicode
*>(aProxy
.host().utf16());
124 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(sProxy
));
127 else if (id
== "ooInetFTPProxyPort")
130 switch (KProtocolManager::proxyType())
132 case KProtocolManager::ManualProxy
: // Proxies are manually configured
133 aFTPProxy
= KProtocolManager::proxyFor(QStringLiteral("FTP"));
135 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
136 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
137 case KProtocolManager::
138 EnvVarProxy
: // Use the proxy values set through environment variables
139 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
140 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
141 // The best we can do here is to ask the current value for a given address.
142 aFTPProxy
= KProtocolManager::proxyForUrl(
143 QUrl(QStringLiteral("ftp://ftp.libreoffice.org")));
145 default: // No proxy is used
148 if (!aFTPProxy
.isEmpty())
150 QUrl
aProxy(aFTPProxy
);
151 sal_Int32 nPort
= aProxy
.port();
152 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(nPort
));
155 else if (id
== "ooInetHTTPProxyName")
158 switch (KProtocolManager::proxyType())
160 case KProtocolManager::ManualProxy
: // Proxies are manually configured
161 aHTTPProxy
= KProtocolManager::proxyFor(QStringLiteral("HTTP"));
163 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
164 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
165 case KProtocolManager::
166 EnvVarProxy
: // Use the proxy values set through environment variables
167 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
168 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
169 // The best we can do here is to ask the current value for a given address.
170 aHTTPProxy
= KProtocolManager::proxyForUrl(
171 QUrl(QStringLiteral("ftp://ftp.libreoffice.org")));
173 default: // No proxy is used
176 if (!aHTTPProxy
.isEmpty())
178 QUrl
aProxy(aHTTPProxy
);
179 OUString sProxy
= reinterpret_cast<const sal_Unicode
*>(aProxy
.host().utf16());
180 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(sProxy
));
183 else if (id
== "ooInetHTTPProxyPort")
186 switch (KProtocolManager::proxyType())
188 case KProtocolManager::ManualProxy
: // Proxies are manually configured
189 aHTTPProxy
= KProtocolManager::proxyFor(QStringLiteral("HTTP"));
191 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
192 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
193 case KProtocolManager::
194 EnvVarProxy
: // Use the proxy values set through environment variables
195 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
196 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
197 // The best we can do here is to ask the current value for a given address.
198 aHTTPProxy
= KProtocolManager::proxyForUrl(
199 QUrl(QStringLiteral("ftp://ftp.libreoffice.org")));
201 default: // No proxy is used
204 if (!aHTTPProxy
.isEmpty())
206 QUrl
aProxy(aHTTPProxy
);
207 sal_Int32 nPort
= aProxy
.port();
208 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(nPort
));
211 else if (id
== "ooInetHTTPSProxyName")
214 switch (KProtocolManager::proxyType())
216 case KProtocolManager::ManualProxy
: // Proxies are manually configured
217 aHTTPSProxy
= KProtocolManager::proxyFor(QStringLiteral("HTTPS"));
219 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
220 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
221 case KProtocolManager::
222 EnvVarProxy
: // Use the proxy values set through environment variables
223 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
224 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
225 // The best we can do here is to ask the current value for a given address.
226 aHTTPSProxy
= KProtocolManager::proxyForUrl(
227 QUrl(QStringLiteral("ftp://ftp.libreoffice.org")));
229 default: // No proxy is used
232 if (!aHTTPSProxy
.isEmpty())
234 QUrl
aProxy(aHTTPSProxy
);
235 OUString sProxy
= reinterpret_cast<const sal_Unicode
*>(aProxy
.host().utf16());
236 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(sProxy
));
239 else if (id
== "ooInetHTTPSProxyPort")
242 switch (KProtocolManager::proxyType())
244 case KProtocolManager::ManualProxy
: // Proxies are manually configured
245 aHTTPSProxy
= KProtocolManager::proxyFor(QStringLiteral("HTTPS"));
247 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
248 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
249 case KProtocolManager::
250 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(
255 QUrl(QStringLiteral("ftp://ftp.libreoffice.org")));
257 default: // No proxy is used
260 if (!aHTTPSProxy
.isEmpty())
262 QUrl
aProxy(aHTTPSProxy
);
263 sal_Int32 nPort
= aProxy
.port();
264 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(nPort
));
267 else if (id
== "ooInetNoProxy")
270 switch (KProtocolManager::proxyType())
272 case KProtocolManager::ManualProxy
: // Proxies are manually configured
273 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
274 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
275 case KProtocolManager::
276 EnvVarProxy
: // Use the proxy values set through environment variables
277 aNoProxyFor
= KProtocolManager::noProxyFor();
279 default: // No proxy is used
282 if (!aNoProxyFor
.isEmpty())
284 OUString sNoProxyFor
;
286 aNoProxyFor
= aNoProxyFor
.replace(QLatin1Char(','), QLatin1Char(';'));
287 sNoProxyFor
= reinterpret_cast<const sal_Unicode
*>(aNoProxyFor
.utf16());
288 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(sNoProxyFor
));
291 else if (id
== "ooInetProxyType")
293 sal_Int32 nProxyType
;
294 switch (KProtocolManager::proxyType())
296 case KProtocolManager::ManualProxy
: // Proxies are manually configured
297 case KProtocolManager::PACProxy
: // A proxy configuration URL has been given
298 case KProtocolManager::WPADProxy
: // A proxy should be automatically discovered
299 case KProtocolManager::
300 EnvVarProxy
: // Use the proxy values set through environment variables
303 default: // No proxy is used
306 return css::beans::Optional
<css::uno::Any
>(true, uno::makeAny(nProxyType
));
310 OSL_ASSERT(false); // this cannot happen
312 return css::beans::Optional
<css::uno::Any
>();
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */