1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "precompiled_shell.hxx"
25 #include "sal/config.h"
26
27 #include "QFont"
28 #include "QString"
29 #include "kemailsettings.h"
30 #include "kglobalsettings.h"
31 #include "kprotocolmanager.h"
32
33 #include "com/sun/star/uno/Any.hxx"
34 #include "cppu/unotype.hxx"
35 #include "osl/diagnose.h"
36 #include "osl/file.h"
37 #include "rtl/string.h"
38 #include "rtl/ustring.hxx"
39
40 #include "kde4access.hxx"
41
42 #define SPACE ' '
43 #define COMMA ','
44 #define SEMI_COLON ';'
45
46 namespace kde4access {
47
48 namespace {
49
50 namespace css = com::sun::star ;
51 namespace uno = css::uno ;
52
53 }
54
getValue(rtl::OUString const & id)55 css::beans::Optional< css::uno::Any > getValue(rtl::OUString const & id) {
56 if (id.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ExternalMailer"))) {
57 KEMailSettings aEmailSettings;
58 QString aClientProgram;
59 ::rtl::OUString sClientProgram;
60
61 aClientProgram = aEmailSettings.getSetting( KEMailSettings::ClientProgram );
62 if ( aClientProgram.isEmpty() )
63 aClientProgram = "kmail";
64 else
65 aClientProgram = aClientProgram.section(SPACE, 0, 0);
66 sClientProgram = (const sal_Unicode *) aClientProgram.utf16();
67 return css::beans::Optional< css::uno::Any >(
68 true, uno::makeAny( sClientProgram ) );
69 } else if (id.equalsAsciiL(
70 RTL_CONSTASCII_STRINGPARAM("SourceViewFontHeight")))
71 {
72 QFont aFixedFont;
73 short nFontHeight;
74
75 aFixedFont = KGlobalSettings::fixedFont();
76 nFontHeight = aFixedFont.pointSize();
77 return css::beans::Optional< css::uno::Any >(
78 true, uno::makeAny( nFontHeight ) );
79 } else if (id.equalsAsciiL(
80 RTL_CONSTASCII_STRINGPARAM("SourceViewFontName")))
81 {
82 QFont aFixedFont;
83 QString aFontName;
84 :: rtl::OUString sFontName;
85
86 aFixedFont = KGlobalSettings::fixedFont();
87 aFontName = aFixedFont.family();
88 sFontName = (const sal_Unicode *) aFontName.utf16();
89 return css::beans::Optional< css::uno::Any >(
90 true, uno::makeAny( sFontName ) );
91 } else if (id.equalsAsciiL(
92 RTL_CONSTASCII_STRINGPARAM("EnableATToolSupport")))
93 {
94 /* does not make much sense without an accessibility bridge */
95 sal_Bool ATToolSupport = sal_False;
96 return css::beans::Optional< css::uno::Any >(
97 true, uno::makeAny( rtl::OUString::valueOf( ATToolSupport ) ) );
98 } else if (id.equalsAsciiL(
99 RTL_CONSTASCII_STRINGPARAM("WorkPathVariable")))
100 {
101 QString aDocumentsDir( KGlobalSettings::documentPath() );
102 rtl::OUString sDocumentsDir;
103 rtl::OUString sDocumentsURL;
104 if ( aDocumentsDir.endsWith(QChar('/')) )
105 aDocumentsDir.truncate ( aDocumentsDir.length() - 1 );
106 sDocumentsDir = (const sal_Unicode *) aDocumentsDir.utf16();
107 osl_getFileURLFromSystemPath( sDocumentsDir.pData, &sDocumentsURL.pData );
108 return css::beans::Optional< css::uno::Any >(
109 true, uno::makeAny( sDocumentsURL ) );
110 } else if (id.equalsAsciiL(
111 RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName")))
112 {
113 QString aFTPProxy;
114 switch ( KProtocolManager::proxyType() )
115 {
116 case KProtocolManager::ManualProxy: // Proxies are manually configured
117 aFTPProxy = KProtocolManager::proxyFor( "FTP" );
118 break;
119 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
120 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
121 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
122 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
123 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
124 // The best we can do here is to ask the current value for a given address.
125 aFTPProxy = KProtocolManager::proxyForUrl( KUrl("ftp://ftp.openoffice.org") );
126 break;
127 default: // No proxy is used
128 break;
129 }
130 if ( !aFTPProxy.isEmpty() )
131 {
132 KUrl aProxy(aFTPProxy);
133 ::rtl::OUString sProxy = (const sal_Unicode *) aProxy.host().utf16();
134 return css::beans::Optional< css::uno::Any >(
135 true, uno::makeAny( sProxy ) );
136 }
137 } else if (id.equalsAsciiL(
138 RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")))
139 {
140 QString aFTPProxy;
141 switch ( KProtocolManager::proxyType() )
142 {
143 case KProtocolManager::ManualProxy: // Proxies are manually configured
144 aFTPProxy = KProtocolManager::proxyFor( "FTP" );
145 break;
146 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
147 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
148 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
149 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
150 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
151 // The best we can do here is to ask the current value for a given address.
152 aFTPProxy = KProtocolManager::proxyForUrl( KUrl("ftp://ftp.openoffice.org") );
153 break;
154 default: // No proxy is used
155 break;
156 }
157 if ( !aFTPProxy.isEmpty() )
158 {
159 KUrl aProxy(aFTPProxy);
160 sal_Int32 nPort = aProxy.port();
161 return css::beans::Optional< css::uno::Any >(
162 true, uno::makeAny( nPort ) );
163 }
164 } else if (id.equalsAsciiL(
165 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")))
166 {
167 QString aHTTPProxy;
168 switch ( KProtocolManager::proxyType() )
169 {
170 case KProtocolManager::ManualProxy: // Proxies are manually configured
171 aHTTPProxy = KProtocolManager::proxyFor( "HTTP" );
172 break;
173 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
174 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
175 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
176 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
177 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
178 // The best we can do here is to ask the current value for a given address.
179 aHTTPProxy = KProtocolManager::proxyForUrl( KUrl("http://http.openoffice.org") );
180 break;
181 default: // No proxy is used
182 break;
183 }
184 if ( !aHTTPProxy.isEmpty() )
185 {
186 KUrl aProxy(aHTTPProxy);
187 ::rtl::OUString sProxy = (const sal_Unicode *) aProxy.host().utf16();
188 return css::beans::Optional< css::uno::Any >(
189 true, uno::makeAny( sProxy ) );
190 }
191 } else if (id.equalsAsciiL(
192 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")))
193 {
194 QString aHTTPProxy;
195 switch ( KProtocolManager::proxyType() )
196 {
197 case KProtocolManager::ManualProxy: // Proxies are manually configured
198 aHTTPProxy = KProtocolManager::proxyFor( "HTTP" );
199 break;
200 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
201 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
202 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
203 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
204 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
205 // The best we can do here is to ask the current value for a given address.
206 aHTTPProxy = KProtocolManager::proxyForUrl( KUrl("http://http.openoffice.org") );
207 break;
208 default: // No proxy is used
209 break;
210 }
211 if ( !aHTTPProxy.isEmpty() )
212 {
213 KUrl aProxy(aHTTPProxy);
214 sal_Int32 nPort = aProxy.port();
215 return css::beans::Optional< css::uno::Any >(
216 true, uno::makeAny( nPort ) );
217 }
218 } else if (id.equalsAsciiL(
219 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")))
220 {
221 QString aHTTPSProxy;
222 switch ( KProtocolManager::proxyType() )
223 {
224 case KProtocolManager::ManualProxy: // Proxies are manually configured
225 aHTTPSProxy = KProtocolManager::proxyFor( "HTTPS" );
226 break;
227 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
228 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
229 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
230 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
231 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
232 // The best we can do here is to ask the current value for a given address.
233 aHTTPSProxy = KProtocolManager::proxyForUrl( KUrl("https://https.openoffice.org") );
234 break;
235 default: // No proxy is used
236 break;
237 }
238 if ( !aHTTPSProxy.isEmpty() )
239 {
240 KUrl aProxy(aHTTPSProxy);
241 ::rtl::OUString sProxy = (const sal_Unicode *) aProxy.host().utf16();
242 return css::beans::Optional< css::uno::Any >(
243 true, uno::makeAny( sProxy ) );
244 }
245 } else if (id.equalsAsciiL(
246 RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")))
247 {
248 QString aHTTPSProxy;
249 switch ( KProtocolManager::proxyType() )
250 {
251 case KProtocolManager::ManualProxy: // Proxies are manually configured
252 aHTTPSProxy = KProtocolManager::proxyFor( "HTTPS" );
253 break;
254 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
255 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
256 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
257 // In such cases, the proxy address is not stored in KDE, but determined dynamically.
258 // The proxy address may depend on the requested address, on the time of the day, on the speed of the wind...
259 // The best we can do here is to ask the current value for a given address.
260 aHTTPSProxy = KProtocolManager::proxyForUrl( KUrl("https://https.openoffice.org") );
261 break;
262 default: // No proxy is used
263 break;
264 }
265 if ( !aHTTPSProxy.isEmpty() )
266 {
267 KUrl aProxy(aHTTPSProxy);
268 sal_Int32 nPort = aProxy.port();
269 return css::beans::Optional< css::uno::Any >(
270 true, uno::makeAny( nPort ) );
271 }
272 } else if (id.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy"))) {
273 QString aNoProxyFor;
274 switch ( KProtocolManager::proxyType() )
275 {
276 case KProtocolManager::ManualProxy: // Proxies are manually configured
277 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
278 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
279 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
280 aNoProxyFor = KProtocolManager::noProxyFor();
281 break;
282 default: // No proxy is used
283 break;
284 }
285 if ( !aNoProxyFor.isEmpty() )
286 {
287 ::rtl::OUString sNoProxyFor;
288
289 aNoProxyFor = aNoProxyFor.replace( COMMA, SEMI_COLON );
290 sNoProxyFor = (const sal_Unicode *) aNoProxyFor.utf16();
291 return css::beans::Optional< css::uno::Any >(
292 true, uno::makeAny( sNoProxyFor ) );
293 }
294 } else if (id.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ooInetProxyType"))) {
295 int nProxyType;
296 switch ( KProtocolManager::proxyType() )
297 {
298 case KProtocolManager::ManualProxy: // Proxies are manually configured
299 case KProtocolManager::PACProxy: // A proxy configuration URL has been given
300 case KProtocolManager::WPADProxy: // A proxy should be automatically discovered
301 case KProtocolManager::EnvVarProxy: // Use the proxy values set through environment variables
302 nProxyType = 1;
303 break;
304 default: // No proxy is used
305 nProxyType = 0;
306 }
307 return css::beans::Optional< css::uno::Any >(
308 true, uno::makeAny( (sal_Int32) nProxyType ) );
309 } else {
310 OSL_ASSERT(false); // this cannot happen
311 }
312 return css::beans::Optional< css::uno::Any >();
313 }
314
315 }
316