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