LibreOffice Module shell (master) 1
kf5access.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include "kf5access.hxx"
23
24#include <QtGui/QFont>
25#include <QtCore/QString>
26#include <QtGui/QFontDatabase>
27#include <QtCore/QStandardPaths>
28#include <QtCore/QDir>
29#include <QtCore/QUrl>
30
31#include <kprotocolmanager.h>
32
33#include <kemailsettings.h>
34// #include <kglobalsettings.h>
35
36#include <com/sun/star/uno/Any.hxx>
37#include <osl/diagnose.h>
38#include <osl/file.h>
39#include <rtl/ustring.hxx>
40
41namespace kf5access
42{
43namespace
44{
45namespace uno = css::uno;
46}
47
48namespace
49{
50OUString fromQStringToOUString(QString const& s)
51{
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() };
54}
55}
56
57css::beans::Optional<css::uno::Any> getValue(std::u16string_view id)
58{
59 if (id == u"ExternalMailer")
60 {
61 KEMailSettings aEmailSettings;
62 QString aClientProgram;
63 OUString sClientProgram;
64
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::Any(sClientProgram));
72 }
73 else if (id == u"SourceViewFontHeight")
74 {
75 const QFont aFixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
76 const short nFontHeight = aFixedFont.pointSize();
77 return css::beans::Optional<css::uno::Any>(true, uno::Any(nFontHeight));
78 }
79 else if (id == u"SourceViewFontName")
80 {
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::Any(sFontName));
85 }
86 else if (id == u"EnableATToolSupport")
87 {
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::Any(OUString::boolean(ATToolSupport)));
92 }
93 else if (id == u"WorkPathVariable")
94 {
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::Any(sDocumentsURL));
105 }
106 else if (id == u"ooInetFTPProxyName")
107 {
108 QString aFTPProxy;
109 switch (KProtocolManager::proxyType())
110 {
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;
125 }
126 if (!aFTPProxy.isEmpty())
127 {
128 QUrl aProxy(aFTPProxy);
129 OUString sProxy = fromQStringToOUString(aProxy.host());
130 return css::beans::Optional<css::uno::Any>(true, uno::Any(sProxy));
131 }
132 }
133 else if (id == u"ooInetFTPProxyPort")
134 {
135 QString aFTPProxy;
136 switch (KProtocolManager::proxyType())
137 {
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;
152 }
153 if (!aFTPProxy.isEmpty())
154 {
155 QUrl aProxy(aFTPProxy);
156 sal_Int32 nPort = aProxy.port();
157 return css::beans::Optional<css::uno::Any>(true, uno::Any(nPort));
158 }
159 }
160 else if (id == u"ooInetHTTPProxyName")
161 {
162 QString aHTTPProxy;
163 switch (KProtocolManager::proxyType())
164 {
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;
179 }
180 if (!aHTTPProxy.isEmpty())
181 {
182 QUrl aProxy(aHTTPProxy);
183 OUString sProxy = fromQStringToOUString(aProxy.host());
184 return css::beans::Optional<css::uno::Any>(true, uno::Any(sProxy));
185 }
186 }
187 else if (id == u"ooInetHTTPProxyPort")
188 {
189 QString aHTTPProxy;
190 switch (KProtocolManager::proxyType())
191 {
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;
206 }
207 if (!aHTTPProxy.isEmpty())
208 {
209 QUrl aProxy(aHTTPProxy);
210 sal_Int32 nPort = aProxy.port();
211 return css::beans::Optional<css::uno::Any>(true, uno::Any(nPort));
212 }
213 }
214 else if (id == u"ooInetHTTPSProxyName")
215 {
216 QString aHTTPSProxy;
217 switch (KProtocolManager::proxyType())
218 {
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;
233 }
234 if (!aHTTPSProxy.isEmpty())
235 {
236 QUrl aProxy(aHTTPSProxy);
237 OUString sProxy = fromQStringToOUString(aProxy.host());
238 return css::beans::Optional<css::uno::Any>(true, uno::Any(sProxy));
239 }
240 }
241 else if (id == u"ooInetHTTPSProxyPort")
242 {
243 QString aHTTPSProxy;
244 switch (KProtocolManager::proxyType())
245 {
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;
260 }
261 if (!aHTTPSProxy.isEmpty())
262 {
263 QUrl aProxy(aHTTPSProxy);
264 sal_Int32 nPort = aProxy.port();
265 return css::beans::Optional<css::uno::Any>(true, uno::Any(nPort));
266 }
267 }
268 else if (id == u"ooInetNoProxy")
269 {
270 QString aNoProxyFor;
271 switch (KProtocolManager::proxyType())
272 {
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;
281 }
282 if (!aNoProxyFor.isEmpty())
283 {
284 OUString sNoProxyFor;
285
286 aNoProxyFor = aNoProxyFor.replace(QLatin1Char(','), QLatin1Char(';'));
287 sNoProxyFor = fromQStringToOUString(aNoProxyFor);
288 return css::beans::Optional<css::uno::Any>(true, uno::Any(sNoProxyFor));
289 }
290 }
291 else if (id == u"ooInetProxyType")
292 {
293 sal_Int32 nProxyType;
294 switch (KProtocolManager::proxyType())
295 {
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;
304 }
305 return css::beans::Optional<css::uno::Any>(true, uno::Any(nProxyType));
306 }
307 else
308 {
309 OSL_ASSERT(false); // this cannot happen
310 }
311 return css::beans::Optional<css::uno::Any>();
312}
313}
314
315/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
float u
css::beans::Optional< css::uno::Any > getValue(std::u16string_view id)
Definition: kf5access.cxx:57