1*b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b5088357SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b5088357SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b5088357SAndrew Rist  * distributed with this work for additional information
6*b5088357SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b5088357SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b5088357SAndrew Rist  * "License"); you may not use this file except in compliance
9*b5088357SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b5088357SAndrew Rist  *
11*b5088357SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b5088357SAndrew Rist  *
13*b5088357SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b5088357SAndrew Rist  * software distributed under the License is distributed on an
15*b5088357SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b5088357SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b5088357SAndrew Rist  * specific language governing permissions and limitations
18*b5088357SAndrew Rist  * under the License.
19*b5088357SAndrew Rist  *
20*b5088357SAndrew Rist  *************************************************************/
21*b5088357SAndrew Rist 
22*b5088357SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "itemholder1.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //-----------------------------------------------
30cdf0e10cSrcweir // includes
31cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
32cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <unotools/misccfg.hxx>
35cdf0e10cSrcweir #include <unotools/undoopt.hxx>
36cdf0e10cSrcweir #include <unotools/useroptions.hxx>
37cdf0e10cSrcweir #include <unotools/accelcfg.hxx>
38cdf0e10cSrcweir #include <unotools/cacheoptions.hxx>
39cdf0e10cSrcweir #include <unotools/cmdoptions.hxx>
40cdf0e10cSrcweir #include <unotools/compatibility.hxx>
41cdf0e10cSrcweir #include <unotools/defaultoptions.hxx>
42cdf0e10cSrcweir #include <unotools/dynamicmenuoptions.hxx>
43cdf0e10cSrcweir #include <unotools/eventcfg.hxx>
44cdf0e10cSrcweir #include <unotools/extendedsecurityoptions.hxx>
45cdf0e10cSrcweir #include <unotools/fltrcfg.hxx>
46cdf0e10cSrcweir #include <unotools/fontoptions.hxx>
47cdf0e10cSrcweir #include <unotools/historyoptions.hxx>
48cdf0e10cSrcweir #include <unotools/inetoptions.hxx>
49cdf0e10cSrcweir #include <unotools/internaloptions.hxx>
50cdf0e10cSrcweir #include <unotools/javaoptions.hxx>
51cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
52cdf0e10cSrcweir #include <unotools/localisationoptions.hxx>
53cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
54cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
55cdf0e10cSrcweir #include <unotools/printwarningoptions.hxx>
56cdf0e10cSrcweir #include <unotools/regoptions.hxx>
57cdf0e10cSrcweir #include <unotools/optionsdlg.hxx>
58cdf0e10cSrcweir #include <unotools/saveopt.hxx>
59cdf0e10cSrcweir #include <unotools/searchopt.hxx>
60cdf0e10cSrcweir #include <unotools/securityoptions.hxx>
61cdf0e10cSrcweir #include <unotools/sourceviewconfig.hxx>
62cdf0e10cSrcweir #include <unotools/startoptions.hxx>
63cdf0e10cSrcweir #include <unotools/viewoptions.hxx>
64cdf0e10cSrcweir #include <unotools/workingsetoptions.hxx>
65cdf0e10cSrcweir #include <unotools/xmlaccelcfg.hxx>
66cdf0e10cSrcweir #include <unotools/options.hxx>
67cdf0e10cSrcweir #include <unotools/syslocaleoptions.hxx>
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //-----------------------------------------------
70cdf0e10cSrcweir // namespaces
71cdf0e10cSrcweir 
72cdf0e10cSrcweir namespace css = ::com::sun::star;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir //-----------------------------------------------
75cdf0e10cSrcweir // declarations
76cdf0e10cSrcweir 
77cdf0e10cSrcweir //-----------------------------------------------
78cdf0e10cSrcweir ItemHolder1::ItemHolder1()
79cdf0e10cSrcweir     : ItemHolderMutexBase()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     try
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
84cdf0e10cSrcweir         css::uno::Reference< css::lang::XComponent > xCfg(
85cdf0e10cSrcweir             xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")),
86cdf0e10cSrcweir             css::uno::UNO_QUERY);
87cdf0e10cSrcweir         if (xCfg.is())
88cdf0e10cSrcweir             xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir // #i37892  got errorhandling from   ConfigManager::GetConfigurationProvider()
91cdf0e10cSrcweir #ifdef DBG_UTIL
92cdf0e10cSrcweir     catch(css::uno::Exception& rEx)
93cdf0e10cSrcweir 	{
94cdf0e10cSrcweir         static sal_Bool bMessage = sal_True;
95cdf0e10cSrcweir         if(bMessage)
96cdf0e10cSrcweir         {
97cdf0e10cSrcweir             bMessage = sal_False;
98cdf0e10cSrcweir             ::rtl::OString sMsg("CreateInstance with arguments exception: ");
99cdf0e10cSrcweir             sMsg += ::rtl::OString(rEx.Message.getStr(),
100cdf0e10cSrcweir                         rEx.Message.getLength(),
101cdf0e10cSrcweir                         RTL_TEXTENCODING_ASCII_US);
102cdf0e10cSrcweir             OSL_ENSURE(sal_False, sMsg.getStr());
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir #else
106cdf0e10cSrcweir 	catch(css::uno::Exception&){}
107cdf0e10cSrcweir #endif
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //-----------------------------------------------
111cdf0e10cSrcweir ItemHolder1::~ItemHolder1()
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     impl_releaseAllItems();
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir //-----------------------------------------------
117cdf0e10cSrcweir void ItemHolder1::holdConfigItem(EItem eItem)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     static ItemHolder1* pHolder = new ItemHolder1();
120cdf0e10cSrcweir     pHolder->impl_addItem(eItem);
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //-----------------------------------------------
124cdf0e10cSrcweir void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&)
125cdf0e10cSrcweir     throw(css::uno::RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY);
128cdf0e10cSrcweir     impl_releaseAllItems();
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir //-----------------------------------------------
132cdf0e10cSrcweir void ItemHolder1::impl_addItem(EItem eItem)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aLock);
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     TItems::const_iterator pIt;
137cdf0e10cSrcweir     for (  pIt  = m_lItems.begin();
138cdf0e10cSrcweir            pIt != m_lItems.end()  ;
139cdf0e10cSrcweir          ++pIt                    )
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         const TItemInfo& rInfo = *pIt;
142cdf0e10cSrcweir         if (rInfo.eItem == eItem)
143cdf0e10cSrcweir             return;
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     TItemInfo aNewItem;
147cdf0e10cSrcweir     aNewItem.eItem = eItem;
148cdf0e10cSrcweir     impl_newItem(aNewItem);
149cdf0e10cSrcweir     if (aNewItem.pItem)
150cdf0e10cSrcweir         m_lItems.push_back(aNewItem);
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir //-----------------------------------------------
154cdf0e10cSrcweir void ItemHolder1::impl_releaseAllItems()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aLock);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     TItems::iterator pIt;
159cdf0e10cSrcweir     for (  pIt  = m_lItems.begin();
160cdf0e10cSrcweir            pIt != m_lItems.end()  ;
161cdf0e10cSrcweir          ++pIt                    )
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         TItemInfo& rInfo = *pIt;
164cdf0e10cSrcweir         impl_deleteItem(rInfo);
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir     m_lItems.clear();
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir //-----------------------------------------------
170cdf0e10cSrcweir void ItemHolder1::impl_newItem(TItemInfo& rItem)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir     switch(rItem.eItem)
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         case E_ACCELCFG :
175cdf0e10cSrcweir             rItem.pItem = new SvtAcceleratorConfiguration();
176cdf0e10cSrcweir             break;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         case E_CMDOPTIONS :
179cdf0e10cSrcweir             rItem.pItem = new SvtCommandOptions();
180cdf0e10cSrcweir             break;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         case E_COMPATIBILITY :
183cdf0e10cSrcweir             rItem.pItem = new SvtCompatibilityOptions();
184cdf0e10cSrcweir             break;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         case E_DEFAULTOPTIONS :
187cdf0e10cSrcweir             rItem.pItem = new SvtDefaultOptions();
188cdf0e10cSrcweir             break;
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         case E_DYNAMICMENUOPTIONS :
191cdf0e10cSrcweir             rItem.pItem = new SvtDynamicMenuOptions();
192cdf0e10cSrcweir             break;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         case E_EVENTCFG :
195cdf0e10cSrcweir             //rItem.pItem = new GlobalEventConfig();
196cdf0e10cSrcweir             break;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         case E_EXTENDEDSECURITYOPTIONS :
199cdf0e10cSrcweir             rItem.pItem = new SvtExtendedSecurityOptions();
200cdf0e10cSrcweir             break;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         case E_FLTRCFG :
203cdf0e10cSrcweir // no ref count            rItem.pItem = new SvtFilterOptions();
204cdf0e10cSrcweir             break;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         case E_FONTOPTIONS :
207cdf0e10cSrcweir             rItem.pItem = new SvtFontOptions();
208cdf0e10cSrcweir             break;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         case E_HISTORYOPTIONS :
211cdf0e10cSrcweir             rItem.pItem = new SvtHistoryOptions();
212cdf0e10cSrcweir             break;
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         case E_INETOPTIONS :
215cdf0e10cSrcweir             rItem.pItem = new SvtInetOptions();
216cdf0e10cSrcweir             break;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         case E_INTERNALOPTIONS :
219cdf0e10cSrcweir             rItem.pItem = new SvtInternalOptions();
220cdf0e10cSrcweir             break;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         case E_JAVAOPTIONS :
223cdf0e10cSrcweir // no ref count            rItem.pItem = new SvtJavaOptions();
224cdf0e10cSrcweir             break;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir         case E_LINGUCFG :
227cdf0e10cSrcweir             rItem.pItem = new SvtLinguConfig();
228cdf0e10cSrcweir             break;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         case E_LOCALISATIONOPTIONS :
231cdf0e10cSrcweir             rItem.pItem = new SvtLocalisationOptions();
232cdf0e10cSrcweir             break;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         case E_MODULEOPTIONS :
235cdf0e10cSrcweir             rItem.pItem = new SvtModuleOptions();
236cdf0e10cSrcweir             break;
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         case E_OPTIONSDLGOPTIONS :
239cdf0e10cSrcweir             rItem.pItem = new SvtOptionsDialogOptions();
240cdf0e10cSrcweir             break;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         case E_PATHOPTIONS :
243cdf0e10cSrcweir             rItem.pItem = new SvtPathOptions();
244cdf0e10cSrcweir             break;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir         case E_PRINTWARNINGOPTIONS :
247cdf0e10cSrcweir             rItem.pItem = new SvtPrintWarningOptions();
248cdf0e10cSrcweir             break;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         case E_MISCCFG :
251cdf0e10cSrcweir 			rItem.pItem = new ::utl::MiscCfg();
252cdf0e10cSrcweir             break;
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         case E_SAVEOPTIONS :
255cdf0e10cSrcweir             rItem.pItem = new SvtSaveOptions();
256cdf0e10cSrcweir             break;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         case E_SEARCHOPT :
259cdf0e10cSrcweir // no ref count            rItem.pItem = new SvtSearchOptions();
260cdf0e10cSrcweir             break;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir         case E_SECURITYOPTIONS :
263cdf0e10cSrcweir             rItem.pItem = new SvtSecurityOptions();
264cdf0e10cSrcweir             break;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         case E_SOURCEVIEWCONFIG :
267cdf0e10cSrcweir             rItem.pItem = new ::utl::SourceViewConfig();
268cdf0e10cSrcweir             break;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir         case E_STARTOPTIONS :
271cdf0e10cSrcweir             rItem.pItem = new SvtStartOptions();
272cdf0e10cSrcweir             break;
273cdf0e10cSrcweir 
274cdf0e10cSrcweir         case E_VIEWOPTIONS_DIALOG :
275cdf0e10cSrcweir             rItem.pItem = new SvtViewOptions(E_DIALOG, ::rtl::OUString());
276cdf0e10cSrcweir             break;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir         case E_VIEWOPTIONS_TABDIALOG :
279cdf0e10cSrcweir             rItem.pItem = new SvtViewOptions(E_TABDIALOG, ::rtl::OUString());
280cdf0e10cSrcweir             break;
281cdf0e10cSrcweir 
282cdf0e10cSrcweir         case E_VIEWOPTIONS_TABPAGE :
283cdf0e10cSrcweir             rItem.pItem = new SvtViewOptions(E_TABPAGE, ::rtl::OUString());
284cdf0e10cSrcweir             break;
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         case E_VIEWOPTIONS_WINDOW :
287cdf0e10cSrcweir             rItem.pItem = new SvtViewOptions(E_WINDOW, ::rtl::OUString());
288cdf0e10cSrcweir             break;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         case E_WORKINGSETOPTIONS :
291cdf0e10cSrcweir             rItem.pItem = new SvtWorkingSetOptions();
292cdf0e10cSrcweir             break;
293cdf0e10cSrcweir 
294cdf0e10cSrcweir         case E_XMLACCELCFG :
295cdf0e10cSrcweir             // ??? TODO
296cdf0e10cSrcweir             break;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir         case E_UNDOOPTIONS :
299cdf0e10cSrcweir             rItem.pItem = new SvtUndoOptions();
300cdf0e10cSrcweir             break;
301cdf0e10cSrcweir 
302cdf0e10cSrcweir         case E_USEROPTIONS :
303cdf0e10cSrcweir             rItem.pItem = new SvtUserOptions();
304cdf0e10cSrcweir             break;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir         case E_SYSLOCALEOPTIONS :
307cdf0e10cSrcweir             rItem.pItem = new SvtSysLocaleOptions();
308cdf0e10cSrcweir             break;
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 		default:
311cdf0e10cSrcweir             OSL_ASSERT( "unknown item type" );
312cdf0e10cSrcweir             break;
313cdf0e10cSrcweir     }
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir //-----------------------------------------------
317cdf0e10cSrcweir void ItemHolder1::impl_deleteItem(TItemInfo& rItem)
318cdf0e10cSrcweir {
319cdf0e10cSrcweir     if (rItem.pItem)
320cdf0e10cSrcweir     {
321cdf0e10cSrcweir         delete rItem.pItem;
322cdf0e10cSrcweir         rItem.pItem = 0;
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326