1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include "itemholder1.hxx"
22 #include <comphelper/processfactory.hxx>
23 #include <com/sun/star/lang/XComponent.hpp>
24 #include <com/sun/star/configuration/theDefaultProvider.hpp>
26 #include <unotools/misccfg.hxx>
27 #include <unotools/useroptions.hxx>
28 #include <unotools/cmdoptions.hxx>
29 #include <unotools/compatibility.hxx>
30 #include <unotools/compatibilityviewoptions.hxx>
31 #include <unotools/defaultoptions.hxx>
32 #include <unotools/dynamicmenuoptions.hxx>
33 #include <unotools/extendedsecurityoptions.hxx>
34 #include <unotools/fontoptions.hxx>
35 #include <unotools/historyoptions.hxx>
36 #include <unotools/lingucfg.hxx>
37 #include <unotools/moduleoptions.hxx>
38 #include <unotools/pathoptions.hxx>
39 #include <unotools/printwarningoptions.hxx>
40 #include <unotools/optionsdlg.hxx>
41 #include <unotools/securityoptions.hxx>
42 #include <unotools/viewoptions.hxx>
43 #include <unotools/options.hxx>
44 #include <unotools/syslocaleoptions.hxx>
45 #include <sal/log.hxx>
46 #include <osl/diagnose.h>
47 #include <tools/diagnose_ex.h>
49 ItemHolder1::ItemHolder1()
50 : ItemHolderMutexBase()
54 css::uno::Reference
< css::uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
55 css::uno::Reference
< css::lang::XComponent
> xCfg(
56 css::configuration::theDefaultProvider::get( xContext
),
57 css::uno::UNO_QUERY_THROW
);
58 xCfg
->addEventListener(static_cast< css::lang::XEventListener
* >(this));
61 catch(const css::uno::Exception
&)
63 static bool bMessage
= true;
67 css::uno::Any
ex( cppu::getCaughtException() );
68 SAL_WARN( "unotools", "CreateInstance with arguments exception: " << exceptionToString(ex
));
72 catch(css::uno::Exception
&){}
76 ItemHolder1::~ItemHolder1()
78 impl_releaseAllItems();
81 void ItemHolder1::holdConfigItem(EItem eItem
)
83 static ItemHolder1
* pHolder
= new ItemHolder1();
84 pHolder
->impl_addItem(eItem
);
87 void SAL_CALL
ItemHolder1::disposing(const css::lang::EventObject
&)
89 css::uno::Reference
< css::uno::XInterface
> xSelfHold(static_cast< css::lang::XEventListener
* >(this), css::uno::UNO_QUERY
);
90 impl_releaseAllItems();
93 void ItemHolder1::impl_addItem(EItem eItem
)
95 osl::MutexGuard
aLock(m_aLock
);
97 for ( auto const & rInfo
: m_lItems
)
99 if (rInfo
.eItem
== eItem
)
104 aNewItem
.eItem
= eItem
;
105 impl_newItem(aNewItem
);
107 m_lItems
.emplace_back(std::move(aNewItem
));
110 void ItemHolder1::impl_releaseAllItems()
112 std::vector
< TItemInfo
> items
;
114 ::osl::MutexGuard
aLock(m_aLock
);
115 items
.swap(m_lItems
);
118 // items will be freed when the block exits
121 void ItemHolder1::impl_newItem(TItemInfo
& rItem
)
125 case EItem::CmdOptions
:
126 rItem
.pItem
.reset( new SvtCommandOptions() );
129 case EItem::Compatibility
:
130 rItem
.pItem
.reset( new SvtCompatibilityOptions() );
133 case EItem::CompatibilityView
:
134 rItem
.pItem
.reset( new SvtCompatibilityViewOptions() );
137 case EItem::DefaultOptions
:
138 rItem
.pItem
.reset( new SvtDefaultOptions() );
141 case EItem::DynamicMenuOptions
:
142 rItem
.pItem
.reset( new SvtDynamicMenuOptions() );
145 case EItem::EventConfig
:
146 //rItem.pItem.reset( new GlobalEventConfig() );
149 case EItem::ExtendedSecurityOptions
:
150 rItem
.pItem
.reset( new SvtExtendedSecurityOptions() );
153 case EItem::FontOptions
:
154 rItem
.pItem
.reset( new SvtFontOptions() );
157 case EItem::HistoryOptions
:
158 rItem
.pItem
.reset( new SvtHistoryOptions() );
161 case EItem::LinguConfig
:
162 rItem
.pItem
.reset( new SvtLinguConfig() );
165 case EItem::ModuleOptions
:
166 rItem
.pItem
.reset( new SvtModuleOptions() );
169 case EItem::OptionsDialogOptions
:
170 rItem
.pItem
.reset( new SvtOptionsDialogOptions() );
173 case EItem::PathOptions
:
174 rItem
.pItem
.reset( new SvtPathOptions() );
177 case EItem::PrintWarningOptions
:
178 rItem
.pItem
.reset( new SvtPrintWarningOptions() );
181 case EItem::MiscConfig
:
182 rItem
.pItem
.reset( new ::utl::MiscCfg() );
185 case EItem::SecurityOptions
:
186 rItem
.pItem
.reset( new SvtSecurityOptions() );
189 case EItem::ViewOptionsDialog
:
190 rItem
.pItem
.reset( new SvtViewOptions(EViewType::Dialog
, OUString()) );
193 case EItem::ViewOptionsTabDialog
:
194 rItem
.pItem
.reset( new SvtViewOptions(EViewType::TabDialog
, OUString()) );
197 case EItem::ViewOptionsTabPage
:
198 rItem
.pItem
.reset( new SvtViewOptions(EViewType::TabPage
, OUString()) );
201 case EItem::ViewOptionsWindow
:
202 rItem
.pItem
.reset( new SvtViewOptions(EViewType::Window
, OUString()) );
205 case EItem::UserOptions
:
206 rItem
.pItem
.reset( new SvtUserOptions() );
209 case EItem::SysLocaleOptions
:
210 rItem
.pItem
.reset( new SvtSysLocaleOptions() );
214 OSL_FAIL( "unknown item type" );
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */