Debian Codegraph @

shell/source/backends/kf5be/kfaccess.cxx

raw
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 "kfaccess.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 #include <vcl/qt/QtUtils.hxx>
41
42 namespace kfaccess
43 {
44 namespace
45 {
46 namespace uno = css::uno;
47 }
48
49 css::beans::Optional<css::uno::Any> getValue(std::u16string_view id)
50 {
51 if (id == u"ExternalMailer")
52 {
53 KEMailSettings aEmailSettings;
54 QString aClientProgram;
55 OUString sClientProgram;
56
57 aClientProgram = aEmailSettings.getSetting(KEMailSettings::ClientProgram);
58 if (aClientProgram.isEmpty())
59 aClientProgram = QStringLiteral("kmail");
60 else
61 aClientProgram = aClientProgram.section(QLatin1Char(' '), 0, 0);
62 sClientProgram = toOUString(aClientProgram);
63 return css::beans::Optional<css::uno::Any>(true, uno::Any(sClientProgram));
64 }
65 else if (id == u"SourceViewFontHeight")
66 {
67 const QFont aFixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
68 const short nFontHeight = aFixedFont.pointSize();
69 return css::beans::Optional<css::uno::Any>(true, uno::Any(nFontHeight));
70 }
71 else if (id == u"SourceViewFontName")
72 {
73 const QFont aFixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
74 const QString aFontName = aFixedFont.family();
75 const OUString sFontName = toOUString(aFontName);
76 return css::beans::Optional<css::uno::Any>(true, uno::Any(sFontName));
77 }
78 else if (id == u"WorkPathVariable")
79 {
80 QString aDocumentsDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
81 if (aDocumentsDir.isEmpty())
82 aDocumentsDir = QDir::homePath();
83 OUString sDocumentsDir;
84 OUString sDocumentsURL;
85 if (aDocumentsDir.endsWith(QLatin1Char('/')))
86 aDocumentsDir.truncate(aDocumentsDir.length() - 1);
87 sDocumentsDir = toOUString(aDocumentsDir);
88 osl_getFileURLFromSystemPath(sDocumentsDir.pData, &sDocumentsURL.pData);
89 return css::beans::Optional<css::uno::Any>(true, uno::Any(sDocumentsURL));
90 }
91 else if (id == u"ooInetHTTPProxyName")
92 {
93 QString aHTTPProxy;
94 switch (KProtocolManager::proxyType())
95 {
96 case KProtocolManager::ManualProxy: // Proxies are manually configured
97 aHTTPProxy = KProtocolManager::proxyFor(QStringLiteral("HTTP"));
98 break;
99 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
100 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
101 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
102 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
103 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
104 // The best we can do here is to ask the current value for a given address.
105 aHTTPProxy = KProtocolManager::proxyForUrl(
106 QUrl(QStringLiteral("http://www.libreoffice.org")));
107 break;
108 default: // No proxy is used
109 break;
110 }
111 if (!aHTTPProxy.isEmpty())
112 {
113 QUrl aProxy(aHTTPProxy);
114 OUString sProxy = toOUString(aProxy.host());
115 return css::beans::Optional<css::uno::Any>(true, uno::Any(sProxy));
116 }
117 }
118 else if (id == u"ooInetHTTPProxyPort")
119 {
120 QString aHTTPProxy;
121 switch (KProtocolManager::proxyType())
122 {
123 case KProtocolManager::ManualProxy: // Proxies are manually configured
124 aHTTPProxy = KProtocolManager::proxyFor(QStringLiteral("HTTP"));
125 break;
126 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
127 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
128 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
129 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
130 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
131 // The best we can do here is to ask the current value for a given address.
132 aHTTPProxy = KProtocolManager::proxyForUrl(
133 QUrl(QStringLiteral("http://www.libreoffice.org")));
134 break;
135 default: // No proxy is used
136 break;
137 }
138 if (!aHTTPProxy.isEmpty())
139 {
140 QUrl aProxy(aHTTPProxy);
141 sal_Int32 nPort = aProxy.port();
142 return css::beans::Optional<css::uno::Any>(true, uno::Any(nPort));
143 }
144 }
145 else if (id == u"ooInetHTTPSProxyName")
146 {
147 QString aHTTPSProxy;
148 switch (KProtocolManager::proxyType())
149 {
150 case KProtocolManager::ManualProxy: // Proxies are manually configured
151 aHTTPSProxy = KProtocolManager::proxyFor(QStringLiteral("HTTPS"));
152 break;
153 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
154 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
155 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
156 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
157 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
158 // The best we can do here is to ask the current value for a given address.
159 aHTTPSProxy = KProtocolManager::proxyForUrl(
160 QUrl(QStringLiteral("https://www.libreoffice.org")));
161 break;
162 default: // No proxy is used
163 break;
164 }
165 if (!aHTTPSProxy.isEmpty())
166 {
167 QUrl aProxy(aHTTPSProxy);
168 OUString sProxy = toOUString(aProxy.host());
169 return css::beans::Optional<css::uno::Any>(true, uno::Any(sProxy));
170 }
171 }
172 else if (id == u"ooInetHTTPSProxyPort")
173 {
174 QString aHTTPSProxy;
175 switch (KProtocolManager::proxyType())
176 {
177 case KProtocolManager::ManualProxy: // Proxies are manually configured
178 aHTTPSProxy = KProtocolManager::proxyFor(QStringLiteral("HTTPS"));
179 break;
180 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
181 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
182 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
183 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
184 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
185 // The best we can do here is to ask the current value for a given address.
186 aHTTPSProxy = KProtocolManager::proxyForUrl(
187 QUrl(QStringLiteral("https://www.libreoffice.org")));
188 break;
189 default: // No proxy is used
190 break;
191 }
192 if (!aHTTPSProxy.isEmpty())
193 {
194 QUrl aProxy(aHTTPSProxy);
195 sal_Int32 nPort = aProxy.port();
196 return css::beans::Optional<css::uno::Any>(true, uno::Any(nPort));
197 }
198 }
199 else if (id == u"ooInetNoProxy")
200 {
201 QString aNoProxyFor;
202 switch (KProtocolManager::proxyType())
203 {
204 case KProtocolManager::ManualProxy: // Proxies are manually configured
205 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
206 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
207 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
208 aNoProxyFor = KProtocolManager::noProxyFor();
209 break;
210 default: // No proxy is used
211 break;
212 }
213 if (!aNoProxyFor.isEmpty())
214 {
215 OUString sNoProxyFor;
216
217 aNoProxyFor = aNoProxyFor.replace(QLatin1Char(','), QLatin1Char(';'));
218 sNoProxyFor = toOUString(aNoProxyFor);
219 return css::beans::Optional<css::uno::Any>(true, uno::Any(sNoProxyFor));
220 }
221 }
222 else if (id == u"ooInetProxyType")
223 {
224 sal_Int32 nProxyType;
225 switch (KProtocolManager::proxyType())
226 {
227 case KProtocolManager::ManualProxy: // Proxies are manually configured
228 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
229 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
230 case KProtocolManager::EnvVarProxy: // Proxy values set through environment variables
231 nProxyType = 1;
232 break;
233 default: // No proxy is used
234 nProxyType = 0;
235 }
236 return css::beans::Optional<css::uno::Any>(true, uno::Any(nProxyType));
237 }
238 else
239 {
240 OSL_ASSERT(false); // this cannot happen
241 }
242 return css::beans::Optional<css::uno::Any>();
243 }
244 }
245
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */