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/optionsdlg.hxx>
57cdf0e10cSrcweir #include <unotools/saveopt.hxx>
58cdf0e10cSrcweir #include <unotools/searchopt.hxx>
59cdf0e10cSrcweir #include <unotools/securityoptions.hxx>
60cdf0e10cSrcweir #include <unotools/sourceviewconfig.hxx>
61cdf0e10cSrcweir #include <unotools/startoptions.hxx>
62cdf0e10cSrcweir #include <unotools/viewoptions.hxx>
63cdf0e10cSrcweir #include <unotools/workingsetoptions.hxx>
64cdf0e10cSrcweir #include <unotools/xmlaccelcfg.hxx>
65cdf0e10cSrcweir #include <unotools/options.hxx>
66cdf0e10cSrcweir #include <unotools/syslocaleoptions.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir //-----------------------------------------------
69cdf0e10cSrcweir // namespaces
70cdf0e10cSrcweir 
71cdf0e10cSrcweir namespace css = ::com::sun::star;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //-----------------------------------------------
74cdf0e10cSrcweir // declarations
75cdf0e10cSrcweir 
76cdf0e10cSrcweir //-----------------------------------------------
ItemHolder1()77cdf0e10cSrcweir ItemHolder1::ItemHolder1()
78cdf0e10cSrcweir     : ItemHolderMutexBase()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     try
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
83cdf0e10cSrcweir         css::uno::Reference< css::lang::XComponent > xCfg(
84cdf0e10cSrcweir             xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")),
85cdf0e10cSrcweir             css::uno::UNO_QUERY);
86cdf0e10cSrcweir         if (xCfg.is())
87cdf0e10cSrcweir             xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir // #i37892  got errorhandling from   ConfigManager::GetConfigurationProvider()
90cdf0e10cSrcweir #ifdef DBG_UTIL
91cdf0e10cSrcweir     catch(css::uno::Exception& rEx)
92cdf0e10cSrcweir 	{
93cdf0e10cSrcweir         static sal_Bool bMessage = sal_True;
94cdf0e10cSrcweir         if(bMessage)
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             bMessage = sal_False;
97cdf0e10cSrcweir             ::rtl::OString sMsg("CreateInstance with arguments exception: ");
98cdf0e10cSrcweir             sMsg += ::rtl::OString(rEx.Message.getStr(),
99cdf0e10cSrcweir                         rEx.Message.getLength(),
100cdf0e10cSrcweir                         RTL_TEXTENCODING_ASCII_US);
101cdf0e10cSrcweir             OSL_ENSURE(sal_False, sMsg.getStr());
102cdf0e10cSrcweir         }
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir #else
105cdf0e10cSrcweir 	catch(css::uno::Exception&){}
106cdf0e10cSrcweir #endif
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir //-----------------------------------------------
~ItemHolder1()110cdf0e10cSrcweir ItemHolder1::~ItemHolder1()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     impl_releaseAllItems();
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir //-----------------------------------------------
holdConfigItem(EItem eItem)116cdf0e10cSrcweir void ItemHolder1::holdConfigItem(EItem eItem)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     static ItemHolder1* pHolder = new ItemHolder1();
119cdf0e10cSrcweir     pHolder->impl_addItem(eItem);
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir //-----------------------------------------------
disposing(const css::lang::EventObject &)123cdf0e10cSrcweir void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&)
124cdf0e10cSrcweir     throw(css::uno::RuntimeException)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY);
127cdf0e10cSrcweir     impl_releaseAllItems();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir //-----------------------------------------------
impl_addItem(EItem eItem)131cdf0e10cSrcweir void ItemHolder1::impl_addItem(EItem eItem)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aLock);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     TItems::const_iterator pIt;
136cdf0e10cSrcweir     for (  pIt  = m_lItems.begin();
137cdf0e10cSrcweir            pIt != m_lItems.end()  ;
138cdf0e10cSrcweir          ++pIt                    )
139cdf0e10cSrcweir     {
140cdf0e10cSrcweir         const TItemInfo& rInfo = *pIt;
141cdf0e10cSrcweir         if (rInfo.eItem == eItem)
142cdf0e10cSrcweir             return;
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     TItemInfo aNewItem;
146cdf0e10cSrcweir     aNewItem.eItem = eItem;
147cdf0e10cSrcweir     impl_newItem(aNewItem);
148cdf0e10cSrcweir     if (aNewItem.pItem)
149cdf0e10cSrcweir         m_lItems.push_back(aNewItem);
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir //-----------------------------------------------
impl_releaseAllItems()153cdf0e10cSrcweir void ItemHolder1::impl_releaseAllItems()
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aLock);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     TItems::iterator pIt;
158cdf0e10cSrcweir     for (  pIt  = m_lItems.begin();
159cdf0e10cSrcweir            pIt != m_lItems.end()  ;
160cdf0e10cSrcweir          ++pIt                    )
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir         TItemInfo& rInfo = *pIt;
163cdf0e10cSrcweir         impl_deleteItem(rInfo);
164cdf0e10cSrcweir     }
165cdf0e10cSrcweir     m_lItems.clear();
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir //-----------------------------------------------
impl_newItem(TItemInfo & rItem)169cdf0e10cSrcweir void ItemHolder1::impl_newItem(TItemInfo& rItem)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     switch(rItem.eItem)
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         case E_ACCELCFG :
174cdf0e10cSrcweir             rItem.pItem = new SvtAcceleratorConfiguration();
175cdf0e10cSrcweir             break;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         case E_CMDOPTIONS :
178cdf0e10cSrcweir             rItem.pItem = new SvtCommandOptions();
179cdf0e10cSrcweir             break;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         case E_COMPATIBILITY :
182cdf0e10cSrcweir             rItem.pItem = new SvtCompatibilityOptions();
183cdf0e10cSrcweir             break;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         case E_DEFAULTOPTIONS :
186cdf0e10cSrcweir             rItem.pItem = new SvtDefaultOptions();
187cdf0e10cSrcweir             break;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         case E_DYNAMICMENUOPTIONS :
190cdf0e10cSrcweir             rItem.pItem = new SvtDynamicMenuOptions();
191cdf0e10cSrcweir             break;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         case E_EVENTCFG :
194cdf0e10cSrcweir             //rItem.pItem = new GlobalEventConfig();
195cdf0e10cSrcweir             break;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         case E_EXTENDEDSECURITYOPTIONS :
198cdf0e10cSrcweir             rItem.pItem = new SvtExtendedSecurityOptions();
199cdf0e10cSrcweir             break;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         case E_FLTRCFG :
202cdf0e10cSrcweir // no ref count            rItem.pItem = new SvtFilterOptions();
203cdf0e10cSrcweir             break;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         case E_FONTOPTIONS :
206cdf0e10cSrcweir             rItem.pItem = new SvtFontOptions();
207cdf0e10cSrcweir             break;
208cdf0e10cSrcweir 
209cdf0e10cSrcweir         case E_HISTORYOPTIONS :
210cdf0e10cSrcweir             rItem.pItem = new SvtHistoryOptions();
211cdf0e10cSrcweir             break;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         case E_INETOPTIONS :
214cdf0e10cSrcweir             rItem.pItem = new SvtInetOptions();
215cdf0e10cSrcweir             break;
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         case E_INTERNALOPTIONS :
218cdf0e10cSrcweir             rItem.pItem = new SvtInternalOptions();
219cdf0e10cSrcweir             break;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         case E_JAVAOPTIONS :
222cdf0e10cSrcweir // no ref count            rItem.pItem = new SvtJavaOptions();
223cdf0e10cSrcweir             break;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         case E_LINGUCFG :
226cdf0e10cSrcweir             rItem.pItem = new SvtLinguConfig();
227cdf0e10cSrcweir             break;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         case E_LOCALISATIONOPTIONS :
230cdf0e10cSrcweir             rItem.pItem = new SvtLocalisationOptions();
231cdf0e10cSrcweir             break;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         case E_MODULEOPTIONS :
234cdf0e10cSrcweir             rItem.pItem = new SvtModuleOptions();
235cdf0e10cSrcweir             break;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         case E_OPTIONSDLGOPTIONS :
238cdf0e10cSrcweir             rItem.pItem = new SvtOptionsDialogOptions();
239cdf0e10cSrcweir             break;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         case E_PATHOPTIONS :
242cdf0e10cSrcweir             rItem.pItem = new SvtPathOptions();
243cdf0e10cSrcweir             break;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir         case E_PRINTWARNINGOPTIONS :
246cdf0e10cSrcweir             rItem.pItem = new SvtPrintWarningOptions();
247cdf0e10cSrcweir             break;
248cdf0e10cSrcweir 
249cdf0e10cSrcweir         case E_MISCCFG :
250cdf0e10cSrcweir 			rItem.pItem = new ::utl::MiscCfg();
251cdf0e10cSrcweir             break;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir         case E_SAVEOPTIONS :
254cdf0e10cSrcweir             rItem.pItem = new SvtSaveOptions();
255cdf0e10cSrcweir             break;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         case E_SEARCHOPT :
258cdf0e10cSrcweir // no ref count            rItem.pItem = new SvtSearchOptions();
259cdf0e10cSrcweir             break;
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         case E_SECURITYOPTIONS :
262cdf0e10cSrcweir             rItem.pItem = new SvtSecurityOptions();
263cdf0e10cSrcweir             break;
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         case E_SOURCEVIEWCONFIG :
266cdf0e10cSrcweir             rItem.pItem = new ::utl::SourceViewConfig();
267cdf0e10cSrcweir             break;
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         case E_STARTOPTIONS :
270cdf0e10cSrcweir             rItem.pItem = new SvtStartOptions();
271cdf0e10cSrcweir             break;
272cdf0e10cSrcweir 
273cdf0e10cSrcweir         case E_VIEWOPTIONS_DIALOG :
274cdf0e10cSrcweir             rItem.pItem = new SvtViewOptions(E_DIALOG, ::rtl::OUString());
275cdf0e10cSrcweir             break;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir         case E_VIEWOPTIONS_TABDIALOG :
278cdf0e10cSrcweir             rItem.pItem = new SvtViewOptions(E_TABDIALOG, ::rtl::OUString());
279cdf0e10cSrcweir             break;
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         case E_VIEWOPTIONS_TABPAGE :
282cdf0e10cSrcweir             rItem.pItem = new SvtViewOptions(E_TABPAGE, ::rtl::OUString());
283cdf0e10cSrcweir             break;
284cdf0e10cSrcweir 
285cdf0e10cSrcweir         case E_VIEWOPTIONS_WINDOW :
286cdf0e10cSrcweir             rItem.pItem = new SvtViewOptions(E_WINDOW, ::rtl::OUString());
287cdf0e10cSrcweir             break;
288cdf0e10cSrcweir 
289cdf0e10cSrcweir         case E_WORKINGSETOPTIONS :
290cdf0e10cSrcweir             rItem.pItem = new SvtWorkingSetOptions();
291cdf0e10cSrcweir             break;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         case E_XMLACCELCFG :
294cdf0e10cSrcweir             // ??? TODO
295cdf0e10cSrcweir             break;
296cdf0e10cSrcweir 
297cdf0e10cSrcweir         case E_UNDOOPTIONS :
298cdf0e10cSrcweir             rItem.pItem = new SvtUndoOptions();
299cdf0e10cSrcweir             break;
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         case E_USEROPTIONS :
302cdf0e10cSrcweir             rItem.pItem = new SvtUserOptions();
303cdf0e10cSrcweir             break;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir         case E_SYSLOCALEOPTIONS :
306cdf0e10cSrcweir             rItem.pItem = new SvtSysLocaleOptions();
307cdf0e10cSrcweir             break;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 		default:
310cdf0e10cSrcweir             OSL_ASSERT( "unknown item type" );
311cdf0e10cSrcweir             break;
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir //-----------------------------------------------
impl_deleteItem(TItemInfo & rItem)316cdf0e10cSrcweir void ItemHolder1::impl_deleteItem(TItemInfo& rItem)
317cdf0e10cSrcweir {
318cdf0e10cSrcweir     if (rItem.pItem)
319cdf0e10cSrcweir     {
320cdf0e10cSrcweir         delete rItem.pItem;
321cdf0e10cSrcweir         rItem.pItem = 0;
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325