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