Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / unotools / source / config / itemholder1.cxx
blob81c0137cd8dc630b4187d8ae7474dcabf6817778
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 .
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()
52 try
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));
60 #ifdef DBG_UTIL
61 catch(const css::uno::Exception&)
63 static bool bMessage = true;
64 if(bMessage)
66 bMessage = false;
67 css::uno::Any ex( cppu::getCaughtException() );
68 SAL_WARN( "unotools", "CreateInstance with arguments exception: " << exceptionToString(ex));
71 #else
72 catch(css::uno::Exception&){}
73 #endif
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)
100 return;
103 TItemInfo aNewItem;
104 aNewItem.eItem = eItem;
105 impl_newItem(aNewItem);
106 if (aNewItem.pItem)
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)
123 switch(rItem.eItem)
125 case EItem::CmdOptions :
126 rItem.pItem.reset( new SvtCommandOptions() );
127 break;
129 case EItem::Compatibility :
130 rItem.pItem.reset( new SvtCompatibilityOptions() );
131 break;
133 case EItem::CompatibilityView :
134 rItem.pItem.reset( new SvtCompatibilityViewOptions() );
135 break;
137 case EItem::DefaultOptions :
138 rItem.pItem.reset( new SvtDefaultOptions() );
139 break;
141 case EItem::DynamicMenuOptions :
142 rItem.pItem.reset( new SvtDynamicMenuOptions() );
143 break;
145 case EItem::EventConfig :
146 //rItem.pItem.reset( new GlobalEventConfig() );
147 break;
149 case EItem::ExtendedSecurityOptions :
150 rItem.pItem.reset( new SvtExtendedSecurityOptions() );
151 break;
153 case EItem::FontOptions :
154 rItem.pItem.reset( new SvtFontOptions() );
155 break;
157 case EItem::HistoryOptions :
158 rItem.pItem.reset( new SvtHistoryOptions() );
159 break;
161 case EItem::LinguConfig :
162 rItem.pItem.reset( new SvtLinguConfig() );
163 break;
165 case EItem::ModuleOptions :
166 rItem.pItem.reset( new SvtModuleOptions() );
167 break;
169 case EItem::OptionsDialogOptions :
170 rItem.pItem.reset( new SvtOptionsDialogOptions() );
171 break;
173 case EItem::PathOptions :
174 rItem.pItem.reset( new SvtPathOptions() );
175 break;
177 case EItem::PrintWarningOptions :
178 rItem.pItem.reset( new SvtPrintWarningOptions() );
179 break;
181 case EItem::MiscConfig :
182 rItem.pItem.reset( new ::utl::MiscCfg() );
183 break;
185 case EItem::SecurityOptions :
186 rItem.pItem.reset( new SvtSecurityOptions() );
187 break;
189 case EItem::ViewOptionsDialog :
190 rItem.pItem.reset( new SvtViewOptions(EViewType::Dialog, OUString()) );
191 break;
193 case EItem::ViewOptionsTabDialog :
194 rItem.pItem.reset( new SvtViewOptions(EViewType::TabDialog, OUString()) );
195 break;
197 case EItem::ViewOptionsTabPage :
198 rItem.pItem.reset( new SvtViewOptions(EViewType::TabPage, OUString()) );
199 break;
201 case EItem::ViewOptionsWindow :
202 rItem.pItem.reset( new SvtViewOptions(EViewType::Window, OUString()) );
203 break;
205 case EItem::UserOptions :
206 rItem.pItem.reset( new SvtUserOptions() );
207 break;
209 case EItem::SysLocaleOptions :
210 rItem.pItem.reset( new SvtSysLocaleOptions() );
211 break;
213 default:
214 OSL_FAIL( "unknown item type" );
215 break;
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */