Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / unotools / source / config / itemholder1.cxx
blob0bac77328ccbd5f2eb3fe054cbdef4196e1d3767
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "itemholder1.hxx"
23 #include <comphelper/processfactory.hxx>
24 #include <com/sun/star/lang/XComponent.hpp>
25 #include <com/sun/star/configuration/theDefaultProvider.hpp>
27 #include <unotools/misccfg.hxx>
28 #include <unotools/useroptions.hxx>
29 #include <unotools/accelcfg.hxx>
30 #include <unotools/cmdoptions.hxx>
31 #include <unotools/compatibility.hxx>
32 #include <unotools/defaultoptions.hxx>
33 #include <unotools/dynamicmenuoptions.hxx>
34 #include <unotools/eventcfg.hxx>
35 #include <unotools/extendedsecurityoptions.hxx>
36 #include <unotools/fltrcfg.hxx>
37 #include <unotools/fontoptions.hxx>
38 #include <unotools/historyoptions.hxx>
39 #include <unotools/internaloptions.hxx>
40 #include <unotools/lingucfg.hxx>
41 #include <unotools/localisationoptions.hxx>
42 #include <unotools/moduleoptions.hxx>
43 #include <unotools/pathoptions.hxx>
44 #include <unotools/printwarningoptions.hxx>
45 #include <unotools/optionsdlg.hxx>
46 #include <unotools/saveopt.hxx>
47 #include <unotools/searchopt.hxx>
48 #include <unotools/securityoptions.hxx>
49 #include <unotools/viewoptions.hxx>
50 #include <unotools/workingsetoptions.hxx>
51 #include <unotools/xmlaccelcfg.hxx>
52 #include <unotools/options.hxx>
53 #include <unotools/syslocaleoptions.hxx>
55 //-----------------------------------------------
56 ItemHolder1::ItemHolder1()
57 : ItemHolderMutexBase()
59 try
61 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
62 css::uno::Reference< css::lang::XComponent > xCfg(
63 css::configuration::theDefaultProvider::get( xContext ),
64 css::uno::UNO_QUERY_THROW );
65 xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
67 #ifdef DBG_UTIL
68 catch(const css::uno::Exception& rEx)
70 static sal_Bool bMessage = sal_True;
71 if(bMessage)
73 bMessage = sal_False;
74 ::rtl::OString sMsg("CreateInstance with arguments exception: ");
75 sMsg += ::rtl::OString(rEx.Message.getStr(),
76 rEx.Message.getLength(),
77 RTL_TEXTENCODING_ASCII_US);
78 OSL_FAIL(sMsg.getStr());
81 #else
82 catch(css::uno::Exception&){}
83 #endif
86 //-----------------------------------------------
87 ItemHolder1::~ItemHolder1()
89 impl_releaseAllItems();
92 //-----------------------------------------------
93 void ItemHolder1::holdConfigItem(EItem eItem)
95 static ItemHolder1* pHolder = new ItemHolder1();
96 pHolder->impl_addItem(eItem);
99 //-----------------------------------------------
100 void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&)
101 throw(css::uno::RuntimeException)
103 css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY);
104 impl_releaseAllItems();
107 //-----------------------------------------------
108 void ItemHolder1::impl_addItem(EItem eItem)
110 ::osl::ResettableMutexGuard aLock(m_aLock);
112 TItems::const_iterator pIt;
113 for ( pIt = m_lItems.begin();
114 pIt != m_lItems.end() ;
115 ++pIt )
117 const TItemInfo& rInfo = *pIt;
118 if (rInfo.eItem == eItem)
119 return;
122 TItemInfo aNewItem;
123 aNewItem.eItem = eItem;
124 impl_newItem(aNewItem);
125 if (aNewItem.pItem)
126 m_lItems.push_back(aNewItem);
129 //-----------------------------------------------
130 void ItemHolder1::impl_releaseAllItems()
132 ::osl::ResettableMutexGuard aLock(m_aLock);
134 TItems::iterator pIt;
135 for ( pIt = m_lItems.begin();
136 pIt != m_lItems.end() ;
137 ++pIt )
139 TItemInfo& rInfo = *pIt;
140 impl_deleteItem(rInfo);
142 m_lItems.clear();
145 //-----------------------------------------------
146 void ItemHolder1::impl_newItem(TItemInfo& rItem)
148 switch(rItem.eItem)
150 case E_ACCELCFG :
151 rItem.pItem = new SvtAcceleratorConfiguration();
152 break;
154 case E_CMDOPTIONS :
155 rItem.pItem = new SvtCommandOptions();
156 break;
158 case E_COMPATIBILITY :
159 rItem.pItem = new SvtCompatibilityOptions();
160 break;
162 case E_DEFAULTOPTIONS :
163 rItem.pItem = new SvtDefaultOptions();
164 break;
166 case E_DYNAMICMENUOPTIONS :
167 rItem.pItem = new SvtDynamicMenuOptions();
168 break;
170 case E_EVENTCFG :
171 //rItem.pItem = new GlobalEventConfig();
172 break;
174 case E_EXTENDEDSECURITYOPTIONS :
175 rItem.pItem = new SvtExtendedSecurityOptions();
176 break;
178 case E_FLTRCFG :
179 // no ref count rItem.pItem = new SvtFilterOptions();
180 break;
182 case E_FONTOPTIONS :
183 rItem.pItem = new SvtFontOptions();
184 break;
186 case E_HISTORYOPTIONS :
187 rItem.pItem = new SvtHistoryOptions();
188 break;
190 case E_INTERNALOPTIONS :
191 rItem.pItem = new SvtInternalOptions();
192 break;
194 case E_JAVAOPTIONS :
195 // no ref count rItem.pItem = new SvtJavaOptions();
196 break;
198 case E_LINGUCFG :
199 rItem.pItem = new SvtLinguConfig();
200 break;
202 case E_LOCALISATIONOPTIONS :
203 rItem.pItem = new SvtLocalisationOptions();
204 break;
206 case E_MODULEOPTIONS :
207 rItem.pItem = new SvtModuleOptions();
208 break;
210 case E_OPTIONSDLGOPTIONS :
211 rItem.pItem = new SvtOptionsDialogOptions();
212 break;
214 case E_PATHOPTIONS :
215 rItem.pItem = new SvtPathOptions();
216 break;
218 case E_PRINTWARNINGOPTIONS :
219 rItem.pItem = new SvtPrintWarningOptions();
220 break;
222 case E_MISCCFG :
223 rItem.pItem = new ::utl::MiscCfg();
224 break;
226 case E_SAVEOPTIONS :
227 rItem.pItem = new SvtSaveOptions();
228 break;
230 case E_SEARCHOPT :
231 // no ref count rItem.pItem = new SvtSearchOptions();
232 break;
234 case E_SECURITYOPTIONS :
235 rItem.pItem = new SvtSecurityOptions();
236 break;
238 case E_VIEWOPTIONS_DIALOG :
239 rItem.pItem = new SvtViewOptions(E_DIALOG, ::rtl::OUString());
240 break;
242 case E_VIEWOPTIONS_TABDIALOG :
243 rItem.pItem = new SvtViewOptions(E_TABDIALOG, ::rtl::OUString());
244 break;
246 case E_VIEWOPTIONS_TABPAGE :
247 rItem.pItem = new SvtViewOptions(E_TABPAGE, ::rtl::OUString());
248 break;
250 case E_VIEWOPTIONS_WINDOW :
251 rItem.pItem = new SvtViewOptions(E_WINDOW, ::rtl::OUString());
252 break;
254 case E_WORKINGSETOPTIONS :
255 rItem.pItem = new SvtWorkingSetOptions();
256 break;
258 case E_XMLACCELCFG :
259 // ??? TODO
260 break;
262 case E_USEROPTIONS :
263 rItem.pItem = new SvtUserOptions();
264 break;
266 case E_SYSLOCALEOPTIONS :
267 rItem.pItem = new SvtSysLocaleOptions();
268 break;
270 default:
271 OSL_FAIL( "unknown item type" );
272 break;
276 //-----------------------------------------------
277 void ItemHolder1::impl_deleteItem(TItemInfo& rItem)
279 if (rItem.pItem)
281 delete rItem.pItem;
282 rItem.pItem = 0;
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */