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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_unotools.hxx"
30*cdf0e10cSrcweir #include <unotools/inetoptions.hxx>
31*cdf0e10cSrcweir #include "rtl/instance.hxx"
32*cdf0e10cSrcweir #include <tools/urlobj.hxx>
33*cdf0e10cSrcweir #ifndef _WILDCARD_HXX
34*cdf0e10cSrcweir #include <tools/wldcrd.hxx>
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <algorithm>
38*cdf0e10cSrcweir #include <map>
39*cdf0e10cSrcweir #include <set>
40*cdf0e10cSrcweir #include <vector>
41*cdf0e10cSrcweir #include <utility>
42*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyChangeEvent.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/system/XProxySettings.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
47*cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
49*cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp>
50*cdf0e10cSrcweir #include <osl/mutex.hxx>
51*cdf0e10cSrcweir #include <rtl/ustring.h>
52*cdf0e10cSrcweir #include <rtl/ustring.hxx>
53*cdf0e10cSrcweir #include <sal/types.h>
54*cdf0e10cSrcweir #include <unotools/configitem.hxx>
55*cdf0e10cSrcweir #include <unotools/processfactory.hxx>
56*cdf0e10cSrcweir #include <osl/diagnose.h>
57*cdf0e10cSrcweir #include <salhelper/refobj.hxx>
58*cdf0e10cSrcweir #include <rtl/logfile.hxx>
59*cdf0e10cSrcweir #include "itemholder1.hxx"
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir using namespace com::sun;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir //============================================================================
64*cdf0e10cSrcweir //
65*cdf0e10cSrcweir //  takeAny
66*cdf0e10cSrcweir //
67*cdf0e10cSrcweir //============================================================================
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir namespace {
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir template< typename T > inline T takeAny(star::uno::Any const & rAny)
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir 	T aValue = T();
74*cdf0e10cSrcweir 	rAny >>= aValue;
75*cdf0e10cSrcweir 	return aValue;
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir //============================================================================
81*cdf0e10cSrcweir //
82*cdf0e10cSrcweir //  SvtInetOptions::Impl
83*cdf0e10cSrcweir //
84*cdf0e10cSrcweir //============================================================================
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir class SvtInetOptions::Impl: public salhelper::ReferenceObject,
87*cdf0e10cSrcweir                             public utl::ConfigItem
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir public:
90*cdf0e10cSrcweir 	enum Index
91*cdf0e10cSrcweir 	{
92*cdf0e10cSrcweir 		INDEX_NO_PROXY,
93*cdf0e10cSrcweir 		INDEX_PROXY_TYPE,
94*cdf0e10cSrcweir 		INDEX_FTP_PROXY_NAME,
95*cdf0e10cSrcweir 		INDEX_FTP_PROXY_PORT,
96*cdf0e10cSrcweir 		INDEX_HTTP_PROXY_NAME,
97*cdf0e10cSrcweir 		INDEX_HTTP_PROXY_PORT
98*cdf0e10cSrcweir 	};
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	Impl();
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	star::uno::Any getProperty(Index nIndex);
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	void
105*cdf0e10cSrcweir     setProperty(Index nIndex, star::uno::Any const & rValue, bool bFlush);
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	inline void flush() { Commit(); }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 	void
110*cdf0e10cSrcweir 	addPropertiesChangeListener(
111*cdf0e10cSrcweir 		star::uno::Sequence< rtl::OUString > const & rPropertyNames,
112*cdf0e10cSrcweir 		star::uno::Reference< star::beans::XPropertiesChangeListener > const &
113*cdf0e10cSrcweir             rListener);
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	void
116*cdf0e10cSrcweir 	removePropertiesChangeListener(
117*cdf0e10cSrcweir 		star::uno::Sequence< rtl::OUString > const & rPropertyNames,
118*cdf0e10cSrcweir 		star::uno::Reference< star::beans::XPropertiesChangeListener > const &
119*cdf0e10cSrcweir             rListener);
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir private:
122*cdf0e10cSrcweir 	enum { ENTRY_COUNT = INDEX_HTTP_PROXY_PORT + 1 };
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	struct Entry
125*cdf0e10cSrcweir 	{
126*cdf0e10cSrcweir 		enum State { UNKNOWN, KNOWN, MODIFIED };
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 		inline Entry(): m_eState(UNKNOWN) {}
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 		rtl::OUString m_aName;
131*cdf0e10cSrcweir 		star::uno::Any m_aValue;
132*cdf0e10cSrcweir 		State m_eState;
133*cdf0e10cSrcweir 	};
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	// MSVC has problems with the below Map type when
136*cdf0e10cSrcweir 	// star::uno::Reference< star::beans::XPropertiesChangeListener > is not
137*cdf0e10cSrcweir     // wrapped in class Listener:
138*cdf0e10cSrcweir 	class Listener:
139*cdf0e10cSrcweir         public star::uno::Reference< star::beans::XPropertiesChangeListener >
140*cdf0e10cSrcweir 	{
141*cdf0e10cSrcweir 	public:
142*cdf0e10cSrcweir 		Listener(star::uno::Reference<
143*cdf0e10cSrcweir                          star::beans::XPropertiesChangeListener > const &
144*cdf0e10cSrcweir 				     rListener):
145*cdf0e10cSrcweir 			star::uno::Reference< star::beans::XPropertiesChangeListener >(
146*cdf0e10cSrcweir                 rListener)
147*cdf0e10cSrcweir         {}
148*cdf0e10cSrcweir 	};
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	typedef std::map< Listener, std::set< rtl::OUString > > Map;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	osl::Mutex m_aMutex;
153*cdf0e10cSrcweir 	Entry m_aEntries[ENTRY_COUNT];
154*cdf0e10cSrcweir 	Map m_aListeners;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	virtual inline ~Impl() { Commit(); }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	virtual void Notify(star::uno::Sequence< rtl::OUString > const & rKeys);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	virtual void Commit();
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	void notifyListeners(star::uno::Sequence< rtl::OUString > const & rKeys);
163*cdf0e10cSrcweir };
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir //============================================================================
166*cdf0e10cSrcweir // virtual
167*cdf0e10cSrcweir void
168*cdf0e10cSrcweir SvtInetOptions::Impl::Notify(star::uno::Sequence< rtl::OUString > const &
169*cdf0e10cSrcweir                                  rKeys)
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir 	{
172*cdf0e10cSrcweir 		osl::MutexGuard aGuard(m_aMutex);
173*cdf0e10cSrcweir 		for (sal_Int32 i = 0; i < rKeys.getLength(); ++i)
174*cdf0e10cSrcweir 			for (sal_Int32 j = 0; j < ENTRY_COUNT; ++j)
175*cdf0e10cSrcweir 				if (rKeys[i] == m_aEntries[j].m_aName)
176*cdf0e10cSrcweir 				{
177*cdf0e10cSrcweir 					m_aEntries[j].m_eState = Entry::UNKNOWN;
178*cdf0e10cSrcweir 					break;
179*cdf0e10cSrcweir 				}
180*cdf0e10cSrcweir 	}
181*cdf0e10cSrcweir 	notifyListeners(rKeys);
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir //============================================================================
185*cdf0e10cSrcweir // virtual
186*cdf0e10cSrcweir void SvtInetOptions::Impl::Commit()
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir 	star::uno::Sequence< rtl::OUString > aKeys(ENTRY_COUNT);
189*cdf0e10cSrcweir 	star::uno::Sequence< star::uno::Any > aValues(ENTRY_COUNT);
190*cdf0e10cSrcweir 	sal_Int32 nCount = 0;
191*cdf0e10cSrcweir 	{
192*cdf0e10cSrcweir 		osl::MutexGuard aGuard(m_aMutex);
193*cdf0e10cSrcweir 		for (sal_Int32 i = 0; i < ENTRY_COUNT; ++i)
194*cdf0e10cSrcweir 			if (m_aEntries[i].m_eState == Entry::MODIFIED)
195*cdf0e10cSrcweir 			{
196*cdf0e10cSrcweir 				aKeys[nCount] = m_aEntries[i].m_aName;
197*cdf0e10cSrcweir 				aValues[nCount] = m_aEntries[i].m_aValue;
198*cdf0e10cSrcweir 				++nCount;
199*cdf0e10cSrcweir 				m_aEntries[i].m_eState = Entry::KNOWN;
200*cdf0e10cSrcweir 			}
201*cdf0e10cSrcweir 	}
202*cdf0e10cSrcweir 	if (nCount > 0)
203*cdf0e10cSrcweir 	{
204*cdf0e10cSrcweir 		aKeys.realloc(nCount);
205*cdf0e10cSrcweir 		aValues.realloc(nCount);
206*cdf0e10cSrcweir 		PutProperties(aKeys, aValues);
207*cdf0e10cSrcweir 	}
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir //============================================================================
211*cdf0e10cSrcweir void
212*cdf0e10cSrcweir SvtInetOptions::Impl::notifyListeners(
213*cdf0e10cSrcweir     star::uno::Sequence< rtl::OUString > const & rKeys)
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir 	typedef
216*cdf0e10cSrcweir         std::vector< std::pair< star::uno::Reference<
217*cdf0e10cSrcweir                                     star::beans::XPropertiesChangeListener >,
218*cdf0e10cSrcweir                                 star::uno::Sequence<
219*cdf0e10cSrcweir                                     star::beans::PropertyChangeEvent > > >
220*cdf0e10cSrcweir     List;
221*cdf0e10cSrcweir 	List aNotifications;
222*cdf0e10cSrcweir 	{
223*cdf0e10cSrcweir 		osl::MutexGuard aGuard(m_aMutex);
224*cdf0e10cSrcweir 		aNotifications.reserve(m_aListeners.size());
225*cdf0e10cSrcweir 		Map::const_iterator aMapEnd(m_aListeners.end());
226*cdf0e10cSrcweir 		for (Map::const_iterator aIt(m_aListeners.begin()); aIt != aMapEnd;
227*cdf0e10cSrcweir 			 ++aIt)
228*cdf0e10cSrcweir 		{
229*cdf0e10cSrcweir 			const Map::mapped_type &rSet = aIt->second;
230*cdf0e10cSrcweir 			Map::mapped_type::const_iterator aSetEnd(rSet.end());
231*cdf0e10cSrcweir 			star::uno::Sequence< star::beans::PropertyChangeEvent >
232*cdf0e10cSrcweir 				aEvents(rKeys.getLength());
233*cdf0e10cSrcweir 			sal_Int32 nCount = 0;
234*cdf0e10cSrcweir 			for (sal_Int32 i = 0; i < rKeys.getLength(); ++i)
235*cdf0e10cSrcweir 			{
236*cdf0e10cSrcweir 				rtl::OUString
237*cdf0e10cSrcweir 					aTheKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
238*cdf0e10cSrcweir 						                      "Inet/")));
239*cdf0e10cSrcweir 				aTheKey += rKeys[i];
240*cdf0e10cSrcweir 				if (rSet.find(aTheKey) != aSetEnd)
241*cdf0e10cSrcweir 				{
242*cdf0e10cSrcweir 					aEvents[nCount].PropertyName = aTheKey;
243*cdf0e10cSrcweir 					aEvents[nCount].PropertyHandle = -1;
244*cdf0e10cSrcweir 					++nCount;
245*cdf0e10cSrcweir 				}
246*cdf0e10cSrcweir 			}
247*cdf0e10cSrcweir 			if (nCount > 0)
248*cdf0e10cSrcweir 			{
249*cdf0e10cSrcweir 				aEvents.realloc(nCount);
250*cdf0e10cSrcweir 				aNotifications.
251*cdf0e10cSrcweir 					push_back(std::make_pair< List::value_type::first_type,
252*cdf0e10cSrcweir 							                  List::value_type::second_type >(
253*cdf0e10cSrcweir 								  aIt->first, aEvents));
254*cdf0e10cSrcweir 			}
255*cdf0e10cSrcweir 		}
256*cdf0e10cSrcweir 	}
257*cdf0e10cSrcweir 	for (List::size_type i = 0; i < aNotifications.size(); ++i)
258*cdf0e10cSrcweir 		if (aNotifications[i].first.is())
259*cdf0e10cSrcweir 			aNotifications[i].first->
260*cdf0e10cSrcweir 				propertiesChange(aNotifications[i].second);
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir //============================================================================
264*cdf0e10cSrcweir SvtInetOptions::Impl::Impl():
265*cdf0e10cSrcweir 	ConfigItem(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Inet/Settings")))
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir 	m_aEntries[INDEX_NO_PROXY].m_aName
268*cdf0e10cSrcweir 		= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetNoProxy"));
269*cdf0e10cSrcweir 	m_aEntries[INDEX_PROXY_TYPE].m_aName
270*cdf0e10cSrcweir 		= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetProxyType"));
271*cdf0e10cSrcweir 	m_aEntries[INDEX_FTP_PROXY_NAME].m_aName
272*cdf0e10cSrcweir 		= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetFTPProxyName"));
273*cdf0e10cSrcweir 	m_aEntries[INDEX_FTP_PROXY_PORT].m_aName
274*cdf0e10cSrcweir 		= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetFTPProxyPort"));
275*cdf0e10cSrcweir 	m_aEntries[INDEX_HTTP_PROXY_NAME].m_aName
276*cdf0e10cSrcweir 		= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPProxyName"));
277*cdf0e10cSrcweir 	m_aEntries[INDEX_HTTP_PROXY_PORT].m_aName
278*cdf0e10cSrcweir 		= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPProxyPort"));
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	star::uno::Sequence< rtl::OUString > aKeys(ENTRY_COUNT);
281*cdf0e10cSrcweir 	for (sal_Int32 i = 0; i < ENTRY_COUNT; ++i)
282*cdf0e10cSrcweir 		aKeys[i] = m_aEntries[i].m_aName;
283*cdf0e10cSrcweir 	if (!EnableNotification(aKeys))
284*cdf0e10cSrcweir 		OSL_ENSURE(false,
285*cdf0e10cSrcweir 				   "SvtInetOptions::Impl::Impl(): Bad EnableNotifications()");
286*cdf0e10cSrcweir }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir //============================================================================
289*cdf0e10cSrcweir star::uno::Any SvtInetOptions::Impl::getProperty(Index nPropIndex)
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir 	for (int nTryCount = 0; nTryCount < 10; ++nTryCount)
292*cdf0e10cSrcweir 	{
293*cdf0e10cSrcweir 		{
294*cdf0e10cSrcweir 			osl::MutexGuard aGuard(m_aMutex);
295*cdf0e10cSrcweir 			if (m_aEntries[nPropIndex].m_eState != Entry::UNKNOWN)
296*cdf0e10cSrcweir 				return m_aEntries[nPropIndex].m_aValue;
297*cdf0e10cSrcweir 		}
298*cdf0e10cSrcweir 		star::uno::Sequence< rtl::OUString > aKeys(ENTRY_COUNT);
299*cdf0e10cSrcweir 		int nIndices[ENTRY_COUNT];
300*cdf0e10cSrcweir 		sal_Int32 nCount = 0;
301*cdf0e10cSrcweir 		{
302*cdf0e10cSrcweir 			osl::MutexGuard aGuard(m_aMutex);
303*cdf0e10cSrcweir 			for (int i = 0; i < ENTRY_COUNT; ++i)
304*cdf0e10cSrcweir 				if (m_aEntries[i].m_eState == Entry::UNKNOWN)
305*cdf0e10cSrcweir 				{
306*cdf0e10cSrcweir 					aKeys[nCount] = m_aEntries[i].m_aName;
307*cdf0e10cSrcweir 					nIndices[nCount] = i;
308*cdf0e10cSrcweir 					++nCount;
309*cdf0e10cSrcweir 				}
310*cdf0e10cSrcweir 		}
311*cdf0e10cSrcweir 		if (nCount > 0)
312*cdf0e10cSrcweir 		{
313*cdf0e10cSrcweir 			aKeys.realloc(nCount);
314*cdf0e10cSrcweir 			star::uno::Sequence< star::uno::Any >
315*cdf0e10cSrcweir                 aValues(GetProperties(aKeys));
316*cdf0e10cSrcweir 			OSL_ENSURE(aValues.getLength() == nCount,
317*cdf0e10cSrcweir 					   "SvtInetOptions::Impl::getProperty():"
318*cdf0e10cSrcweir 					       " Bad GetProperties() result");
319*cdf0e10cSrcweir 			nCount = std::min(nCount, aValues.getLength());
320*cdf0e10cSrcweir 			{
321*cdf0e10cSrcweir 				osl::MutexGuard aGuard(m_aMutex);
322*cdf0e10cSrcweir 				for (sal_Int32 i = 0; i < nCount; ++i)
323*cdf0e10cSrcweir 				{
324*cdf0e10cSrcweir 					int nIndex = nIndices[i];
325*cdf0e10cSrcweir 					if (m_aEntries[nIndex].m_eState == Entry::UNKNOWN)
326*cdf0e10cSrcweir 					{
327*cdf0e10cSrcweir 						m_aEntries[nIndices[i]].m_aValue = aValues[i];
328*cdf0e10cSrcweir 						m_aEntries[nIndices[i]].m_eState = Entry::KNOWN;
329*cdf0e10cSrcweir 					}
330*cdf0e10cSrcweir 				}
331*cdf0e10cSrcweir 			}
332*cdf0e10cSrcweir 		}
333*cdf0e10cSrcweir 	}
334*cdf0e10cSrcweir 	OSL_ENSURE(false,
335*cdf0e10cSrcweir 			   "SvtInetOptions::Impl::getProperty(): Possible life lock");
336*cdf0e10cSrcweir 	{
337*cdf0e10cSrcweir 		osl::MutexGuard aGuard(m_aMutex);
338*cdf0e10cSrcweir 		return m_aEntries[nPropIndex].m_aValue;
339*cdf0e10cSrcweir 	}
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir //============================================================================
343*cdf0e10cSrcweir void SvtInetOptions::Impl::setProperty(Index nIndex,
344*cdf0e10cSrcweir                                        star::uno::Any const & rValue,
345*cdf0e10cSrcweir 									   bool bFlush)
346*cdf0e10cSrcweir {
347*cdf0e10cSrcweir 	SetModified();
348*cdf0e10cSrcweir 	{
349*cdf0e10cSrcweir 		osl::MutexGuard aGuard(m_aMutex);
350*cdf0e10cSrcweir 		m_aEntries[nIndex].m_aValue = rValue;
351*cdf0e10cSrcweir 		m_aEntries[nIndex].m_eState = bFlush ? Entry::KNOWN : Entry::MODIFIED;
352*cdf0e10cSrcweir 	}
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 	star::uno::Sequence< rtl::OUString > aKeys(1);
355*cdf0e10cSrcweir 	aKeys[0] = m_aEntries[nIndex].m_aName;
356*cdf0e10cSrcweir 	if (bFlush)
357*cdf0e10cSrcweir 	{
358*cdf0e10cSrcweir 		star::uno::Sequence< star::uno::Any > aValues(1);
359*cdf0e10cSrcweir 		aValues[0] = rValue;
360*cdf0e10cSrcweir 		PutProperties(aKeys, aValues);
361*cdf0e10cSrcweir 	}
362*cdf0e10cSrcweir 	else
363*cdf0e10cSrcweir 		notifyListeners(aKeys);
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir //============================================================================
367*cdf0e10cSrcweir void
368*cdf0e10cSrcweir SvtInetOptions::Impl::addPropertiesChangeListener(
369*cdf0e10cSrcweir 	star::uno::Sequence< rtl::OUString > const & rPropertyNames,
370*cdf0e10cSrcweir 	star::uno::Reference< star::beans::XPropertiesChangeListener > const &
371*cdf0e10cSrcweir         rListener)
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
374*cdf0e10cSrcweir 	Map::mapped_type & rEntry = m_aListeners[rListener];
375*cdf0e10cSrcweir 	for (sal_Int32 i = 0; i < rPropertyNames.getLength(); ++i)
376*cdf0e10cSrcweir 		rEntry.insert(rPropertyNames[i]);
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir //============================================================================
380*cdf0e10cSrcweir void
381*cdf0e10cSrcweir SvtInetOptions::Impl::removePropertiesChangeListener(
382*cdf0e10cSrcweir 	star::uno::Sequence< rtl::OUString > const & rPropertyNames,
383*cdf0e10cSrcweir 	star::uno::Reference< star::beans::XPropertiesChangeListener > const &
384*cdf0e10cSrcweir         rListener)
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
387*cdf0e10cSrcweir 	Map::iterator aIt(m_aListeners.find(rListener));
388*cdf0e10cSrcweir 	if (aIt != m_aListeners.end())
389*cdf0e10cSrcweir 	{
390*cdf0e10cSrcweir 		for (sal_Int32 i = 0; i < rPropertyNames.getLength(); ++i)
391*cdf0e10cSrcweir 			aIt->second.erase(rPropertyNames[i]);
392*cdf0e10cSrcweir 		if (aIt->second.empty())
393*cdf0e10cSrcweir 			m_aListeners.erase(aIt);
394*cdf0e10cSrcweir 	}
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir //============================================================================
398*cdf0e10cSrcweir //
399*cdf0e10cSrcweir //  SvtInetOptions
400*cdf0e10cSrcweir //
401*cdf0e10cSrcweir //============================================================================
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir namespace
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir     class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
406*cdf0e10cSrcweir     {
407*cdf0e10cSrcweir     };
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir // static
411*cdf0e10cSrcweir SvtInetOptions::Impl * SvtInetOptions::m_pImpl = 0;
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir //============================================================================
414*cdf0e10cSrcweir SvtInetOptions::SvtInetOptions()
415*cdf0e10cSrcweir {
416*cdf0e10cSrcweir     osl::MutexGuard aGuard(LocalSingleton::get());
417*cdf0e10cSrcweir 	if (!m_pImpl)
418*cdf0e10cSrcweir     {
419*cdf0e10cSrcweir         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtInetOptions_Impl::ctor()");
420*cdf0e10cSrcweir 		m_pImpl = new Impl;
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir         ItemHolder1::holdConfigItem(E_INETOPTIONS);
423*cdf0e10cSrcweir     }
424*cdf0e10cSrcweir 	m_pImpl->acquire();
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir //============================================================================
428*cdf0e10cSrcweir SvtInetOptions::~SvtInetOptions()
429*cdf0e10cSrcweir {
430*cdf0e10cSrcweir     osl::MutexGuard aGuard(LocalSingleton::get());
431*cdf0e10cSrcweir 	if (m_pImpl->release() == 0)
432*cdf0e10cSrcweir 		m_pImpl = 0;
433*cdf0e10cSrcweir }
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir //============================================================================
436*cdf0e10cSrcweir rtl::OUString SvtInetOptions::GetProxyNoProxy() const
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir 	return takeAny< rtl::OUString >(m_pImpl->
439*cdf0e10cSrcweir 									    getProperty(Impl::INDEX_NO_PROXY));
440*cdf0e10cSrcweir }
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir //============================================================================
443*cdf0e10cSrcweir sal_Int32 SvtInetOptions::GetProxyType() const
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir 	return takeAny< sal_Int32 >(m_pImpl->
446*cdf0e10cSrcweir 								    getProperty(Impl::INDEX_PROXY_TYPE));
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir //============================================================================
450*cdf0e10cSrcweir rtl::OUString SvtInetOptions::GetProxyFtpName() const
451*cdf0e10cSrcweir {
452*cdf0e10cSrcweir 	return takeAny< rtl::OUString >(m_pImpl->
453*cdf0e10cSrcweir 									    getProperty(
454*cdf0e10cSrcweir 											Impl::INDEX_FTP_PROXY_NAME));
455*cdf0e10cSrcweir }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir //============================================================================
458*cdf0e10cSrcweir sal_Int32 SvtInetOptions::GetProxyFtpPort() const
459*cdf0e10cSrcweir {
460*cdf0e10cSrcweir 	return takeAny< sal_Int32 >(m_pImpl->
461*cdf0e10cSrcweir 								    getProperty(Impl::INDEX_FTP_PROXY_PORT));
462*cdf0e10cSrcweir }
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir //============================================================================
465*cdf0e10cSrcweir rtl::OUString SvtInetOptions::GetProxyHttpName() const
466*cdf0e10cSrcweir {
467*cdf0e10cSrcweir 	return takeAny< rtl::OUString >(m_pImpl->
468*cdf0e10cSrcweir 									    getProperty(
469*cdf0e10cSrcweir 											Impl::INDEX_HTTP_PROXY_NAME));
470*cdf0e10cSrcweir }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir //============================================================================
473*cdf0e10cSrcweir sal_Int32 SvtInetOptions::GetProxyHttpPort() const
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir 	return takeAny< sal_Int32 >(m_pImpl->
476*cdf0e10cSrcweir 								    getProperty(Impl::INDEX_HTTP_PROXY_PORT));
477*cdf0e10cSrcweir }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir //============================================================================
480*cdf0e10cSrcweir void SvtInetOptions::SetProxyNoProxy(rtl::OUString const & rValue,
481*cdf0e10cSrcweir 									 bool bFlush)
482*cdf0e10cSrcweir {
483*cdf0e10cSrcweir 	m_pImpl->setProperty(Impl::INDEX_NO_PROXY,
484*cdf0e10cSrcweir 						 star::uno::makeAny(rValue),
485*cdf0e10cSrcweir 						 bFlush);
486*cdf0e10cSrcweir }
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir //============================================================================
489*cdf0e10cSrcweir void SvtInetOptions::SetProxyType(ProxyType eValue, bool bFlush)
490*cdf0e10cSrcweir {
491*cdf0e10cSrcweir 	m_pImpl->setProperty(Impl::INDEX_PROXY_TYPE,
492*cdf0e10cSrcweir 						 star::uno::makeAny(sal_Int32(eValue)),
493*cdf0e10cSrcweir 						 bFlush);
494*cdf0e10cSrcweir }
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir //============================================================================
497*cdf0e10cSrcweir void SvtInetOptions::SetProxyFtpName(rtl::OUString const & rValue,
498*cdf0e10cSrcweir 									 bool bFlush)
499*cdf0e10cSrcweir {
500*cdf0e10cSrcweir 	m_pImpl->setProperty(Impl::INDEX_FTP_PROXY_NAME,
501*cdf0e10cSrcweir 						 star::uno::makeAny(rValue),
502*cdf0e10cSrcweir 						 bFlush);
503*cdf0e10cSrcweir }
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir //============================================================================
506*cdf0e10cSrcweir void SvtInetOptions::SetProxyFtpPort(sal_Int32 nValue, bool bFlush)
507*cdf0e10cSrcweir {
508*cdf0e10cSrcweir 	m_pImpl->setProperty(Impl::INDEX_FTP_PROXY_PORT,
509*cdf0e10cSrcweir 						 star::uno::makeAny(nValue),
510*cdf0e10cSrcweir 						 bFlush);
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir //============================================================================
514*cdf0e10cSrcweir void SvtInetOptions::SetProxyHttpName(rtl::OUString const & rValue,
515*cdf0e10cSrcweir 									  bool bFlush)
516*cdf0e10cSrcweir {
517*cdf0e10cSrcweir 	m_pImpl->setProperty(Impl::INDEX_HTTP_PROXY_NAME,
518*cdf0e10cSrcweir 						 star::uno::makeAny(rValue),
519*cdf0e10cSrcweir 						 bFlush);
520*cdf0e10cSrcweir }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir //============================================================================
523*cdf0e10cSrcweir void SvtInetOptions::SetProxyHttpPort(sal_Int32 nValue, bool bFlush)
524*cdf0e10cSrcweir {
525*cdf0e10cSrcweir 	m_pImpl->setProperty(Impl::INDEX_HTTP_PROXY_PORT,
526*cdf0e10cSrcweir 						 star::uno::makeAny(nValue),
527*cdf0e10cSrcweir 						 bFlush);
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir //============================================================================
531*cdf0e10cSrcweir void SvtInetOptions::flush()
532*cdf0e10cSrcweir {
533*cdf0e10cSrcweir 	m_pImpl->flush();
534*cdf0e10cSrcweir }
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir //============================================================================
537*cdf0e10cSrcweir void
538*cdf0e10cSrcweir SvtInetOptions::addPropertiesChangeListener(
539*cdf0e10cSrcweir 	star::uno::Sequence< rtl::OUString > const & rPropertyNames,
540*cdf0e10cSrcweir 	star::uno::Reference< star::beans::XPropertiesChangeListener > const &
541*cdf0e10cSrcweir         rListener)
542*cdf0e10cSrcweir {
543*cdf0e10cSrcweir 	m_pImpl->addPropertiesChangeListener(rPropertyNames, rListener);
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir //============================================================================
547*cdf0e10cSrcweir void
548*cdf0e10cSrcweir SvtInetOptions::removePropertiesChangeListener(
549*cdf0e10cSrcweir 	star::uno::Sequence< rtl::OUString > const & rPropertyNames,
550*cdf0e10cSrcweir 	star::uno::Reference< star::beans::XPropertiesChangeListener > const &
551*cdf0e10cSrcweir         rListener)
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir 	m_pImpl->removePropertiesChangeListener(rPropertyNames, rListener);
554*cdf0e10cSrcweir }
555