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