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 : #include "itemholder1.hxx"
21 :
22 : #include <comphelper/processfactory.hxx>
23 : #include <com/sun/star/lang/XComponent.hpp>
24 : #include <com/sun/star/configuration/theDefaultProvider.hpp>
25 :
26 : #include <unotools/misccfg.hxx>
27 : #include <unotools/useroptions.hxx>
28 : #include <unotools/cmdoptions.hxx>
29 : #include <unotools/compatibility.hxx>
30 : #include <unotools/defaultoptions.hxx>
31 : #include <unotools/dynamicmenuoptions.hxx>
32 : #include <unotools/eventcfg.hxx>
33 : #include <unotools/extendedsecurityoptions.hxx>
34 : #include <unotools/fltrcfg.hxx>
35 : #include <unotools/fontoptions.hxx>
36 : #include <unotools/historyoptions.hxx>
37 : #include <unotools/lingucfg.hxx>
38 : #include <unotools/localisationoptions.hxx>
39 : #include <unotools/moduleoptions.hxx>
40 : #include <unotools/pathoptions.hxx>
41 : #include <unotools/printwarningoptions.hxx>
42 : #include <unotools/optionsdlg.hxx>
43 : #include <unotools/saveopt.hxx>
44 : #include <unotools/searchopt.hxx>
45 : #include <unotools/securityoptions.hxx>
46 : #include <unotools/viewoptions.hxx>
47 : #include <unotools/xmlaccelcfg.hxx>
48 : #include <unotools/options.hxx>
49 : #include <unotools/syslocaleoptions.hxx>
50 :
51 166 : ItemHolder1::ItemHolder1()
52 166 : : ItemHolderMutexBase()
53 : {
54 : try
55 : {
56 166 : css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
57 : css::uno::Reference< css::lang::XComponent > xCfg(
58 : css::configuration::theDefaultProvider::get( xContext ),
59 332 : css::uno::UNO_QUERY_THROW );
60 332 : xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
61 : }
62 : #ifdef DBG_UTIL
63 : catch(const css::uno::Exception& rEx)
64 : {
65 : static bool bMessage = true;
66 : if(bMessage)
67 : {
68 : bMessage = false;
69 : OString sMsg("CreateInstance with arguments exception: ");
70 : sMsg += OString(rEx.Message.getStr(),
71 : rEx.Message.getLength(),
72 : RTL_TEXTENCODING_ASCII_US);
73 : OSL_FAIL(sMsg.getStr());
74 : }
75 : }
76 : #else
77 0 : catch(css::uno::Exception&){}
78 : #endif
79 166 : }
80 :
81 495 : ItemHolder1::~ItemHolder1()
82 : {
83 165 : impl_releaseAllItems();
84 330 : }
85 :
86 2002 : void ItemHolder1::holdConfigItem(EItem eItem)
87 : {
88 2002 : static ItemHolder1* pHolder = new ItemHolder1();
89 2002 : pHolder->impl_addItem(eItem);
90 2002 : }
91 :
92 165 : void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&)
93 : throw(css::uno::RuntimeException, std::exception)
94 : {
95 165 : css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY);
96 165 : impl_releaseAllItems();
97 165 : }
98 :
99 2002 : void ItemHolder1::impl_addItem(EItem eItem)
100 : {
101 2002 : ::osl::ResettableMutexGuard aLock(m_aLock);
102 :
103 2002 : TItems::const_iterator pIt;
104 44505 : for ( pIt = m_lItems.begin();
105 29670 : pIt != m_lItems.end();
106 : ++pIt )
107 : {
108 12833 : const TItemInfo& rInfo = *pIt;
109 12833 : if (rInfo.eItem == eItem)
110 2002 : return;
111 : }
112 :
113 2002 : TItemInfo aNewItem;
114 2002 : aNewItem.eItem = eItem;
115 2002 : impl_newItem(aNewItem);
116 2002 : if (aNewItem.pItem)
117 1847 : m_lItems.push_back(aNewItem);
118 : }
119 :
120 330 : void ItemHolder1::impl_releaseAllItems()
121 : {
122 330 : ::osl::ResettableMutexGuard aLock(m_aLock);
123 :
124 330 : TItems::iterator pIt;
125 6483 : for ( pIt = m_lItems.begin();
126 4322 : pIt != m_lItems.end();
127 : ++pIt )
128 : {
129 1831 : TItemInfo& rInfo = *pIt;
130 1831 : impl_deleteItem(rInfo);
131 : }
132 330 : m_lItems.clear();
133 330 : }
134 :
135 2002 : void ItemHolder1::impl_newItem(TItemInfo& rItem)
136 : {
137 2002 : switch(rItem.eItem)
138 : {
139 : case E_CMDOPTIONS :
140 146 : rItem.pItem = new SvtCommandOptions();
141 146 : break;
142 :
143 : case E_COMPATIBILITY :
144 36 : rItem.pItem = new SvtCompatibilityOptions();
145 36 : break;
146 :
147 : case E_DEFAULTOPTIONS :
148 0 : rItem.pItem = new SvtDefaultOptions();
149 0 : break;
150 :
151 : case E_DYNAMICMENUOPTIONS :
152 31 : rItem.pItem = new SvtDynamicMenuOptions();
153 31 : break;
154 :
155 : case E_EVENTCFG :
156 : //rItem.pItem = new GlobalEventConfig();
157 155 : break;
158 :
159 : case E_EXTENDEDSECURITYOPTIONS :
160 0 : rItem.pItem = new SvtExtendedSecurityOptions();
161 0 : break;
162 :
163 : case E_FLTRCFG :
164 : // no ref count rItem.pItem = new SvtFilterOptions();
165 0 : break;
166 :
167 : case E_FONTOPTIONS :
168 25 : rItem.pItem = new SvtFontOptions();
169 25 : break;
170 :
171 : case E_HISTORYOPTIONS :
172 143 : rItem.pItem = new SvtHistoryOptions();
173 143 : break;
174 :
175 : case E_LINGUCFG :
176 76 : rItem.pItem = new SvtLinguConfig();
177 76 : break;
178 :
179 : case E_LOCALISATIONOPTIONS :
180 143 : rItem.pItem = new SvtLocalisationOptions();
181 143 : break;
182 :
183 : case E_MODULEOPTIONS :
184 76 : rItem.pItem = new SvtModuleOptions();
185 76 : break;
186 :
187 : case E_OPTIONSDLGOPTIONS :
188 0 : rItem.pItem = new SvtOptionsDialogOptions();
189 0 : break;
190 :
191 : case E_PATHOPTIONS :
192 145 : rItem.pItem = new SvtPathOptions();
193 145 : break;
194 :
195 : case E_PRINTWARNINGOPTIONS :
196 0 : rItem.pItem = new SvtPrintWarningOptions();
197 0 : break;
198 :
199 : case E_MISCCFG :
200 79 : rItem.pItem = new ::utl::MiscCfg();
201 79 : break;
202 :
203 : case E_SAVEOPTIONS :
204 63 : rItem.pItem = new SvtSaveOptions();
205 63 : break;
206 :
207 : case E_SEARCHOPT :
208 : // no ref count rItem.pItem = new SvtSearchOptions();
209 0 : break;
210 :
211 : case E_SECURITYOPTIONS :
212 91 : rItem.pItem = new SvtSecurityOptions();
213 91 : break;
214 :
215 : case E_VIEWOPTIONS_DIALOG :
216 143 : rItem.pItem = new SvtViewOptions(E_DIALOG, OUString());
217 143 : break;
218 :
219 : case E_VIEWOPTIONS_TABDIALOG :
220 143 : rItem.pItem = new SvtViewOptions(E_TABDIALOG, OUString());
221 143 : break;
222 :
223 : case E_VIEWOPTIONS_TABPAGE :
224 143 : rItem.pItem = new SvtViewOptions(E_TABPAGE, OUString());
225 143 : break;
226 :
227 : case E_VIEWOPTIONS_WINDOW :
228 143 : rItem.pItem = new SvtViewOptions(E_WINDOW, OUString());
229 143 : break;
230 :
231 : case E_USEROPTIONS :
232 55 : rItem.pItem = new SvtUserOptions();
233 55 : break;
234 :
235 : case E_SYSLOCALEOPTIONS :
236 166 : rItem.pItem = new SvtSysLocaleOptions();
237 166 : break;
238 :
239 : default:
240 : OSL_FAIL( "unknown item type" );
241 0 : break;
242 : }
243 2002 : }
244 :
245 1831 : void ItemHolder1::impl_deleteItem(TItemInfo& rItem)
246 : {
247 1831 : if (rItem.pItem)
248 : {
249 1831 : delete rItem.pItem;
250 1831 : rItem.pItem = 0;
251 : }
252 1831 : }
253 :
254 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|