25#include <QtCore/QString>
26#include <QtGui/QFontDatabase>
27#include <QtCore/QStandardPaths>
31#include <kprotocolmanager.h>
33#include <kemailsettings.h>
36#include <com/sun/star/uno/Any.hxx>
37#include <osl/diagnose.h>
39#include <rtl/ustring.hxx>
45namespace uno = css::uno;
50OUString fromQStringToOUString(QString
const& s)
53 return {
reinterpret_cast<char16_t const*
>(s.utf16()), s.size() };
57css::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");
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")
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"ooInetFTPProxyName")
109 switch (KProtocolManager::proxyType())
111 case KProtocolManager::ManualProxy:
112 aFTPProxy = KProtocolManager::proxyFor(QStringLiteral(
"FTP"));
114 case KProtocolManager::PACProxy:
115 case KProtocolManager::WPADProxy:
116 case KProtocolManager::EnvVarProxy:
120 aFTPProxy = KProtocolManager::proxyForUrl(
121 QUrl(QStringLiteral(
"ftp://ftp.libreoffice.org")));
126 if (!aFTPProxy.isEmpty())
128 QUrl aProxy(aFTPProxy);
129 OUString sProxy = fromQStringToOUString(aProxy.host());
130 return css::beans::Optional<css::uno::Any>(
true,
uno::Any(sProxy));
133 else if (
id ==
u"ooInetFTPProxyPort")
136 switch (KProtocolManager::proxyType())
138 case KProtocolManager::ManualProxy:
139 aFTPProxy = KProtocolManager::proxyFor(QStringLiteral(
"FTP"));
141 case KProtocolManager::PACProxy:
142 case KProtocolManager::WPADProxy:
143 case KProtocolManager::EnvVarProxy:
147 aFTPProxy = KProtocolManager::proxyForUrl(
148 QUrl(QStringLiteral(
"ftp://ftp.libreoffice.org")));
153 if (!aFTPProxy.isEmpty())
155 QUrl aProxy(aFTPProxy);
156 sal_Int32 nPort = aProxy.port();
157 return css::beans::Optional<css::uno::Any>(
true,
uno::Any(nPort));
160 else if (
id ==
u"ooInetHTTPProxyName")
163 switch (KProtocolManager::proxyType())
165 case KProtocolManager::ManualProxy:
166 aHTTPProxy = KProtocolManager::proxyFor(QStringLiteral(
"HTTP"));
168 case KProtocolManager::PACProxy:
169 case KProtocolManager::WPADProxy:
170 case KProtocolManager::EnvVarProxy:
174 aHTTPProxy = KProtocolManager::proxyForUrl(
175 QUrl(QStringLiteral(
"http://www.libreoffice.org")));
180 if (!aHTTPProxy.isEmpty())
182 QUrl aProxy(aHTTPProxy);
183 OUString sProxy = fromQStringToOUString(aProxy.host());
184 return css::beans::Optional<css::uno::Any>(
true,
uno::Any(sProxy));
187 else if (
id ==
u"ooInetHTTPProxyPort")
190 switch (KProtocolManager::proxyType())
192 case KProtocolManager::ManualProxy:
193 aHTTPProxy = KProtocolManager::proxyFor(QStringLiteral(
"HTTP"));
195 case KProtocolManager::PACProxy:
196 case KProtocolManager::WPADProxy:
197 case KProtocolManager::EnvVarProxy:
201 aHTTPProxy = KProtocolManager::proxyForUrl(
202 QUrl(QStringLiteral(
"http://www.libreoffice.org")));
207 if (!aHTTPProxy.isEmpty())
209 QUrl aProxy(aHTTPProxy);
210 sal_Int32 nPort = aProxy.port();
211 return css::beans::Optional<css::uno::Any>(
true,
uno::Any(nPort));
214 else if (
id ==
u"ooInetHTTPSProxyName")
217 switch (KProtocolManager::proxyType())
219 case KProtocolManager::ManualProxy:
220 aHTTPSProxy = KProtocolManager::proxyFor(QStringLiteral(
"HTTPS"));
222 case KProtocolManager::PACProxy:
223 case KProtocolManager::WPADProxy:
224 case KProtocolManager::EnvVarProxy:
228 aHTTPSProxy = KProtocolManager::proxyForUrl(
229 QUrl(QStringLiteral(
"https://www.libreoffice.org")));
234 if (!aHTTPSProxy.isEmpty())
236 QUrl aProxy(aHTTPSProxy);
237 OUString sProxy = fromQStringToOUString(aProxy.host());
238 return css::beans::Optional<css::uno::Any>(
true,
uno::Any(sProxy));
241 else if (
id ==
u"ooInetHTTPSProxyPort")
244 switch (KProtocolManager::proxyType())
246 case KProtocolManager::ManualProxy:
247 aHTTPSProxy = KProtocolManager::proxyFor(QStringLiteral(
"HTTPS"));
249 case KProtocolManager::PACProxy:
250 case KProtocolManager::WPADProxy:
251 case KProtocolManager::EnvVarProxy:
255 aHTTPSProxy = KProtocolManager::proxyForUrl(
256 QUrl(QStringLiteral(
"https://www.libreoffice.org")));
261 if (!aHTTPSProxy.isEmpty())
263 QUrl aProxy(aHTTPSProxy);
264 sal_Int32 nPort = aProxy.port();
265 return css::beans::Optional<css::uno::Any>(
true,
uno::Any(nPort));
268 else if (
id ==
u"ooInetNoProxy")
271 switch (KProtocolManager::proxyType())
273 case KProtocolManager::ManualProxy:
274 case KProtocolManager::PACProxy:
275 case KProtocolManager::WPADProxy:
276 case KProtocolManager::EnvVarProxy:
277 aNoProxyFor = KProtocolManager::noProxyFor();
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::Any(sNoProxyFor));
291 else if (
id ==
u"ooInetProxyType")
293 sal_Int32 nProxyType;
294 switch (KProtocolManager::proxyType())
296 case KProtocolManager::ManualProxy:
297 case KProtocolManager::PACProxy:
298 case KProtocolManager::WPADProxy:
299 case KProtocolManager::EnvVarProxy:
305 return css::beans::Optional<css::uno::Any>(
true,
uno::Any(nProxyType));
311 return css::beans::Optional<css::uno::Any>();
css::beans::Optional< css::uno::Any > getValue(std::u16string_view id)