Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "itemholder1.hxx"
22 :
23 : #include <comphelper/processfactory.hxx>
24 : #include <com/sun/star/lang/XComponent.hpp>
25 : #include <com/sun/star/configuration/theDefaultProvider.hpp>
26 :
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>
54 :
55 : //-----------------------------------------------
56 98 : ItemHolder1::ItemHolder1()
57 98 : : ItemHolderMutexBase()
58 : {
59 : try
60 : {
61 98 : css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
62 : css::uno::Reference< css::lang::XComponent > xCfg(
63 : css::configuration::theDefaultProvider::get( xContext ),
64 98 : css::uno::UNO_QUERY_THROW );
65 98 : xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
66 : }
67 : #ifdef DBG_UTIL
68 : catch(const css::uno::Exception& rEx)
69 : {
70 : static sal_Bool bMessage = sal_True;
71 : if(bMessage)
72 : {
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());
79 : }
80 : }
81 : #else
82 0 : catch(css::uno::Exception&){}
83 : #endif
84 98 : }
85 :
86 : //-----------------------------------------------
87 294 : ItemHolder1::~ItemHolder1()
88 : {
89 98 : impl_releaseAllItems();
90 196 : }
91 :
92 : //-----------------------------------------------
93 1202 : void ItemHolder1::holdConfigItem(EItem eItem)
94 : {
95 1202 : static ItemHolder1* pHolder = new ItemHolder1();
96 1202 : pHolder->impl_addItem(eItem);
97 1202 : }
98 :
99 : //-----------------------------------------------
100 98 : void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&)
101 : throw(css::uno::RuntimeException)
102 : {
103 98 : css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY);
104 98 : impl_releaseAllItems();
105 98 : }
106 :
107 : //-----------------------------------------------
108 1202 : void ItemHolder1::impl_addItem(EItem eItem)
109 : {
110 1202 : ::osl::ResettableMutexGuard aLock(m_aLock);
111 :
112 1202 : TItems::const_iterator pIt;
113 29886 : for ( pIt = m_lItems.begin();
114 19924 : pIt != m_lItems.end() ;
115 : ++pIt )
116 : {
117 8760 : const TItemInfo& rInfo = *pIt;
118 8760 : if (rInfo.eItem == eItem)
119 1202 : return;
120 : }
121 :
122 1202 : TItemInfo aNewItem;
123 1202 : aNewItem.eItem = eItem;
124 1202 : impl_newItem(aNewItem);
125 1202 : if (aNewItem.pItem)
126 1090 : m_lItems.push_back(aNewItem);
127 : }
128 :
129 : //-----------------------------------------------
130 196 : void ItemHolder1::impl_releaseAllItems()
131 : {
132 196 : ::osl::ResettableMutexGuard aLock(m_aLock);
133 :
134 196 : TItems::iterator pIt;
135 3858 : for ( pIt = m_lItems.begin();
136 2572 : pIt != m_lItems.end() ;
137 : ++pIt )
138 : {
139 1090 : TItemInfo& rInfo = *pIt;
140 1090 : impl_deleteItem(rInfo);
141 : }
142 196 : m_lItems.clear();
143 196 : }
144 :
145 : //-----------------------------------------------
146 1202 : void ItemHolder1::impl_newItem(TItemInfo& rItem)
147 : {
148 1202 : switch(rItem.eItem)
149 : {
150 : case E_ACCELCFG :
151 0 : rItem.pItem = new SvtAcceleratorConfiguration();
152 0 : break;
153 :
154 : case E_CMDOPTIONS :
155 72 : rItem.pItem = new SvtCommandOptions();
156 72 : break;
157 :
158 : case E_COMPATIBILITY :
159 24 : rItem.pItem = new SvtCompatibilityOptions();
160 24 : break;
161 :
162 : case E_DEFAULTOPTIONS :
163 0 : rItem.pItem = new SvtDefaultOptions();
164 0 : break;
165 :
166 : case E_DYNAMICMENUOPTIONS :
167 2 : rItem.pItem = new SvtDynamicMenuOptions();
168 2 : break;
169 :
170 : case E_EVENTCFG :
171 : //rItem.pItem = new GlobalEventConfig();
172 112 : break;
173 :
174 : case E_EXTENDEDSECURITYOPTIONS :
175 0 : rItem.pItem = new SvtExtendedSecurityOptions();
176 0 : break;
177 :
178 : case E_FLTRCFG :
179 : // no ref count rItem.pItem = new SvtFilterOptions();
180 0 : break;
181 :
182 : case E_FONTOPTIONS :
183 2 : rItem.pItem = new SvtFontOptions();
184 2 : break;
185 :
186 : case E_HISTORYOPTIONS :
187 72 : rItem.pItem = new SvtHistoryOptions();
188 72 : break;
189 :
190 : case E_INTERNALOPTIONS :
191 72 : rItem.pItem = new SvtInternalOptions();
192 72 : break;
193 :
194 : case E_JAVAOPTIONS :
195 : // no ref count rItem.pItem = new SvtJavaOptions();
196 0 : break;
197 :
198 : case E_LINGUCFG :
199 64 : rItem.pItem = new SvtLinguConfig();
200 64 : break;
201 :
202 : case E_LOCALISATIONOPTIONS :
203 72 : rItem.pItem = new SvtLocalisationOptions();
204 72 : break;
205 :
206 : case E_MODULEOPTIONS :
207 58 : rItem.pItem = new SvtModuleOptions();
208 58 : break;
209 :
210 : case E_OPTIONSDLGOPTIONS :
211 0 : rItem.pItem = new SvtOptionsDialogOptions();
212 0 : break;
213 :
214 : case E_PATHOPTIONS :
215 72 : rItem.pItem = new SvtPathOptions();
216 72 : break;
217 :
218 : case E_PRINTWARNINGOPTIONS :
219 0 : rItem.pItem = new SvtPrintWarningOptions();
220 0 : break;
221 :
222 : case E_MISCCFG :
223 62 : rItem.pItem = new ::utl::MiscCfg();
224 62 : break;
225 :
226 : case E_SAVEOPTIONS :
227 42 : rItem.pItem = new SvtSaveOptions();
228 42 : break;
229 :
230 : case E_SEARCHOPT :
231 : // no ref count rItem.pItem = new SvtSearchOptions();
232 0 : break;
233 :
234 : case E_SECURITYOPTIONS :
235 58 : rItem.pItem = new SvtSecurityOptions();
236 58 : break;
237 :
238 : case E_VIEWOPTIONS_DIALOG :
239 72 : rItem.pItem = new SvtViewOptions(E_DIALOG, ::rtl::OUString());
240 72 : break;
241 :
242 : case E_VIEWOPTIONS_TABDIALOG :
243 72 : rItem.pItem = new SvtViewOptions(E_TABDIALOG, ::rtl::OUString());
244 72 : break;
245 :
246 : case E_VIEWOPTIONS_TABPAGE :
247 72 : rItem.pItem = new SvtViewOptions(E_TABPAGE, ::rtl::OUString());
248 72 : break;
249 :
250 : case E_VIEWOPTIONS_WINDOW :
251 72 : rItem.pItem = new SvtViewOptions(E_WINDOW, ::rtl::OUString());
252 72 : break;
253 :
254 : case E_WORKINGSETOPTIONS :
255 0 : rItem.pItem = new SvtWorkingSetOptions();
256 0 : break;
257 :
258 : case E_XMLACCELCFG :
259 : // ??? TODO
260 0 : break;
261 :
262 : case E_USEROPTIONS :
263 32 : rItem.pItem = new SvtUserOptions();
264 32 : break;
265 :
266 : case E_SYSLOCALEOPTIONS :
267 98 : rItem.pItem = new SvtSysLocaleOptions();
268 98 : break;
269 :
270 : default:
271 : OSL_FAIL( "unknown item type" );
272 0 : break;
273 : }
274 1202 : }
275 :
276 : //-----------------------------------------------
277 1090 : void ItemHolder1::impl_deleteItem(TItemInfo& rItem)
278 : {
279 1090 : if (rItem.pItem)
280 : {
281 1090 : delete rItem.pItem;
282 1090 : rItem.pItem = 0;
283 : }
284 1090 : }
285 :
286 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|