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