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