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