look for java, javac and javadoc with the .exe suffix on windows
[LibreOffice.git] / shell / source / backends / kf5be / kf5access.cxx
blobd266f147d68adfac685fd2b9b435cf3217fbcb10
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(std::u16string_view id)
59 if (id == u"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::Any(sClientProgram));
73 else if (id == u"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::Any(nFontHeight));
79 else if (id == u"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::Any(sFontName));
86 else if (id == u"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::Any(OUString::boolean(ATToolSupport)));
93 else if (id == u"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::Any(sDocumentsURL));
106 else if (id == u"ooInetHTTPProxyName")
108 QString aHTTPProxy;
109 switch (KProtocolManager::proxyType())
111 case KProtocolManager::ManualProxy: // Proxies are manually configured
112 aHTTPProxy = KProtocolManager::proxyFor(QStringLiteral("HTTP"));
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 aHTTPProxy = KProtocolManager::proxyForUrl(
121 QUrl(QStringLiteral("http://www.libreoffice.org")));
122 break;
123 default: // No proxy is used
124 break;
126 if (!aHTTPProxy.isEmpty())
128 QUrl aProxy(aHTTPProxy);
129 OUString sProxy = fromQStringToOUString(aProxy.host());
130 return css::beans::Optional<css::uno::Any>(true, uno::Any(sProxy));
133 else if (id == u"ooInetHTTPProxyPort")
135 QString aHTTPProxy;
136 switch (KProtocolManager::proxyType())
138 case KProtocolManager::ManualProxy: // Proxies are manually configured
139 aHTTPProxy = KProtocolManager::proxyFor(QStringLiteral("HTTP"));
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 aHTTPProxy = KProtocolManager::proxyForUrl(
148 QUrl(QStringLiteral("http://www.libreoffice.org")));
149 break;
150 default: // No proxy is used
151 break;
153 if (!aHTTPProxy.isEmpty())
155 QUrl aProxy(aHTTPProxy);
156 sal_Int32 nPort = aProxy.port();
157 return css::beans::Optional<css::uno::Any>(true, uno::Any(nPort));
160 else if (id == u"ooInetHTTPSProxyName")
162 QString aHTTPSProxy;
163 switch (KProtocolManager::proxyType())
165 case KProtocolManager::ManualProxy: // Proxies are manually configured
166 aHTTPSProxy = KProtocolManager::proxyFor(QStringLiteral("HTTPS"));
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 aHTTPSProxy = KProtocolManager::proxyForUrl(
175 QUrl(QStringLiteral("https://www.libreoffice.org")));
176 break;
177 default: // No proxy is used
178 break;
180 if (!aHTTPSProxy.isEmpty())
182 QUrl aProxy(aHTTPSProxy);
183 OUString sProxy = fromQStringToOUString(aProxy.host());
184 return css::beans::Optional<css::uno::Any>(true, uno::Any(sProxy));
187 else if (id == u"ooInetHTTPSProxyPort")
189 QString aHTTPSProxy;
190 switch (KProtocolManager::proxyType())
192 case KProtocolManager::ManualProxy: // Proxies are manually configured
193 aHTTPSProxy = KProtocolManager::proxyFor(QStringLiteral("HTTPS"));
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 aHTTPSProxy = KProtocolManager::proxyForUrl(
202 QUrl(QStringLiteral("https://www.libreoffice.org")));
203 break;
204 default: // No proxy is used
205 break;
207 if (!aHTTPSProxy.isEmpty())
209 QUrl aProxy(aHTTPSProxy);
210 sal_Int32 nPort = aProxy.port();
211 return css::beans::Optional<css::uno::Any>(true, uno::Any(nPort));
214 else if (id == u"ooInetNoProxy")
216 QString aNoProxyFor;
217 switch (KProtocolManager::proxyType())
219 case KProtocolManager::ManualProxy: // Proxies are manually configured
220 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
221 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
222 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
223 aNoProxyFor = KProtocolManager::noProxyFor();
224 break;
225 default: // No proxy is used
226 break;
228 if (!aNoProxyFor.isEmpty())
230 OUString sNoProxyFor;
232 aNoProxyFor = aNoProxyFor.replace(QLatin1Char(','), QLatin1Char(';'));
233 sNoProxyFor = fromQStringToOUString(aNoProxyFor);
234 return css::beans::Optional<css::uno::Any>(true, uno::Any(sNoProxyFor));
237 else if (id == u"ooInetProxyType")
239 sal_Int32 nProxyType;
240 switch (KProtocolManager::proxyType())
242 case KProtocolManager::ManualProxy: // Proxies are manually configured
243 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
244 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
245 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
246 nProxyType = 1;
247 break;
248 default: // No proxy is used
249 nProxyType = 0;
251 return css::beans::Optional<css::uno::Any>(true, uno::Any(nProxyType));
253 else
255 OSL_ASSERT(false); // this cannot happen
257 return css::beans::Optional<css::uno::Any>();
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */