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