nss: upgrade to release 3.73
[LibreOffice.git] / shell / source / backends / kf5be / kf5access.cxx
blob27d047d640d1e7ae575b95263b89c83b7a75ac09
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 "kf5access.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 <osl/diagnose.h>
38 #include <osl/file.h>
39 #include <rtl/ustring.hxx>
41 namespace kf5access
43 namespace
45 namespace uno = css::uno;
48 namespace
50 OUString fromQStringToOUString(QString const& s)
52 // Conversion from QString size()'s int to OUString's sal_Int32 should be non-narrowing:
53 return { reinterpret_cast<char16_t const*>(s.utf16()), s.size() };
57 css::beans::Optional<css::uno::Any> getValue(OUString const& id)
59 if (id == "ExternalMailer")
61 KEMailSettings aEmailSettings;
62 QString aClientProgram;
63 OUString sClientProgram;
65 aClientProgram = aEmailSettings.getSetting(KEMailSettings::ClientProgram);
66 if (aClientProgram.isEmpty())
67 aClientProgram = QStringLiteral("kmail");
68 else
69 aClientProgram = aClientProgram.section(QLatin1Char(' '), 0, 0);
70 sClientProgram = fromQStringToOUString(aClientProgram);
71 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sClientProgram));
73 else if (id == "SourceViewFontHeight")
75 const QFont aFixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
76 const short nFontHeight = aFixedFont.pointSize();
77 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(nFontHeight));
79 else if (id == "SourceViewFontName")
81 const QFont aFixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
82 const QString aFontName = aFixedFont.family();
83 const OUString sFontName = fromQStringToOUString(aFontName);
84 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sFontName));
86 else if (id == "EnableATToolSupport")
88 /* does not make much sense without an accessibility bridge */
89 bool ATToolSupport = false;
90 return css::beans::Optional<css::uno::Any>(true,
91 uno::makeAny(OUString::boolean(ATToolSupport)));
93 else if (id == "WorkPathVariable")
95 QString aDocumentsDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
96 if (aDocumentsDir.isEmpty())
97 aDocumentsDir = QDir::homePath();
98 OUString sDocumentsDir;
99 OUString sDocumentsURL;
100 if (aDocumentsDir.endsWith(QLatin1Char('/')))
101 aDocumentsDir.truncate(aDocumentsDir.length() - 1);
102 sDocumentsDir = fromQStringToOUString(aDocumentsDir);
103 osl_getFileURLFromSystemPath(sDocumentsDir.pData, &sDocumentsURL.pData);
104 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sDocumentsURL));
106 else if (id == "ooInetFTPProxyName")
108 QString aFTPProxy;
109 switch (KProtocolManager::proxyType())
111 case KProtocolManager::ManualProxy: // Proxies are manually configured
112 aFTPProxy = KProtocolManager::proxyFor(QStringLiteral("FTP"));
113 break;
114 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
115 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
116 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
117 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
118 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
119 // The best we can do here is to ask the current value for a given address.
120 aFTPProxy = KProtocolManager::proxyForUrl(
121 QUrl(QStringLiteral("ftp://ftp.libreoffice.org")));
122 break;
123 default: // No proxy is used
124 break;
126 if (!aFTPProxy.isEmpty())
128 QUrl aProxy(aFTPProxy);
129 OUString sProxy = fromQStringToOUString(aProxy.host());
130 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sProxy));
133 else if (id == "ooInetFTPProxyPort")
135 QString aFTPProxy;
136 switch (KProtocolManager::proxyType())
138 case KProtocolManager::ManualProxy: // Proxies are manually configured
139 aFTPProxy = KProtocolManager::proxyFor(QStringLiteral("FTP"));
140 break;
141 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
142 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
143 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
144 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
145 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
146 // The best we can do here is to ask the current value for a given address.
147 aFTPProxy = KProtocolManager::proxyForUrl(
148 QUrl(QStringLiteral("ftp://ftp.libreoffice.org")));
149 break;
150 default: // No proxy is used
151 break;
153 if (!aFTPProxy.isEmpty())
155 QUrl aProxy(aFTPProxy);
156 sal_Int32 nPort = aProxy.port();
157 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(nPort));
160 else if (id == "ooInetHTTPProxyName")
162 QString aHTTPProxy;
163 switch (KProtocolManager::proxyType())
165 case KProtocolManager::ManualProxy: // Proxies are manually configured
166 aHTTPProxy = KProtocolManager::proxyFor(QStringLiteral("HTTP"));
167 break;
168 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
169 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
170 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
171 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
172 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
173 // The best we can do here is to ask the current value for a given address.
174 aHTTPProxy = KProtocolManager::proxyForUrl(
175 QUrl(QStringLiteral("http://www.libreoffice.org")));
176 break;
177 default: // No proxy is used
178 break;
180 if (!aHTTPProxy.isEmpty())
182 QUrl aProxy(aHTTPProxy);
183 OUString sProxy = fromQStringToOUString(aProxy.host());
184 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sProxy));
187 else if (id == "ooInetHTTPProxyPort")
189 QString aHTTPProxy;
190 switch (KProtocolManager::proxyType())
192 case KProtocolManager::ManualProxy: // Proxies are manually configured
193 aHTTPProxy = KProtocolManager::proxyFor(QStringLiteral("HTTP"));
194 break;
195 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
196 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
197 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
198 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
199 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
200 // The best we can do here is to ask the current value for a given address.
201 aHTTPProxy = KProtocolManager::proxyForUrl(
202 QUrl(QStringLiteral("http://www.libreoffice.org")));
203 break;
204 default: // No proxy is used
205 break;
207 if (!aHTTPProxy.isEmpty())
209 QUrl aProxy(aHTTPProxy);
210 sal_Int32 nPort = aProxy.port();
211 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(nPort));
214 else if (id == "ooInetHTTPSProxyName")
216 QString aHTTPSProxy;
217 switch (KProtocolManager::proxyType())
219 case KProtocolManager::ManualProxy: // Proxies are manually configured
220 aHTTPSProxy = KProtocolManager::proxyFor(QStringLiteral("HTTPS"));
221 break;
222 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
223 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
224 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
225 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
226 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
227 // The best we can do here is to ask the current value for a given address.
228 aHTTPSProxy = KProtocolManager::proxyForUrl(
229 QUrl(QStringLiteral("https://www.libreoffice.org")));
230 break;
231 default: // No proxy is used
232 break;
234 if (!aHTTPSProxy.isEmpty())
236 QUrl aProxy(aHTTPSProxy);
237 OUString sProxy = fromQStringToOUString(aProxy.host());
238 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sProxy));
241 else if (id == "ooInetHTTPSProxyPort")
243 QString aHTTPSProxy;
244 switch (KProtocolManager::proxyType())
246 case KProtocolManager::ManualProxy: // Proxies are manually configured
247 aHTTPSProxy = KProtocolManager::proxyFor(QStringLiteral("HTTPS"));
248 break;
249 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
250 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
251 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
252 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
253 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
254 // The best we can do here is to ask the current value for a given address.
255 aHTTPSProxy = KProtocolManager::proxyForUrl(
256 QUrl(QStringLiteral("https://www.libreoffice.org")));
257 break;
258 default: // No proxy is used
259 break;
261 if (!aHTTPSProxy.isEmpty())
263 QUrl aProxy(aHTTPSProxy);
264 sal_Int32 nPort = aProxy.port();
265 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(nPort));
268 else if (id == "ooInetNoProxy")
270 QString aNoProxyFor;
271 switch (KProtocolManager::proxyType())
273 case KProtocolManager::ManualProxy: // Proxies are manually configured
274 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
275 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
276 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
277 aNoProxyFor = KProtocolManager::noProxyFor();
278 break;
279 default: // No proxy is used
280 break;
282 if (!aNoProxyFor.isEmpty())
284 OUString sNoProxyFor;
286 aNoProxyFor = aNoProxyFor.replace(QLatin1Char(','), QLatin1Char(';'));
287 sNoProxyFor = fromQStringToOUString(aNoProxyFor);
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::EnvVarProxy: // Proxy values set through environment variables
300 nProxyType = 1;
301 break;
302 default: // No proxy is used
303 nProxyType = 0;
305 return css::beans::Optional<css::uno::Any>(true, uno::makeAny(nProxyType));
307 else
309 OSL_ASSERT(false); // this cannot happen
311 return css::beans::Optional<css::uno::Any>();
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */