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/useroptions.hxx>
27 #include <unotools/cmdoptions.hxx>
28 #include <unotools/compatibility.hxx>
29 #include <unotools/lingucfg.hxx>
30 #include <unotools/moduleoptions.hxx>
31 #include <unotools/pathoptions.hxx>
32 #include <unotools/options.hxx>
33 #include <unotools/syslocaleoptions.hxx>
34 #include <rtl/ref.hxx>
35 #include <osl/diagnose.h>
36 #include <comphelper/diagnose_ex.hxx>
38 ItemHolder1::ItemHolder1()
42 css::uno::Reference
< css::uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
43 css::uno::Reference
< css::lang::XComponent
> xCfg(
44 css::configuration::theDefaultProvider::get( xContext
),
45 css::uno::UNO_QUERY_THROW
);
46 xCfg
->addEventListener(static_cast< css::lang::XEventListener
* >(this));
49 catch(const css::uno::Exception
&)
51 static bool bMessage
= true;
55 TOOLS_WARN_EXCEPTION( "unotools", "CreateInstance with arguments");
59 catch(css::uno::Exception
&){}
63 ItemHolder1::~ItemHolder1()
65 impl_releaseAllItems();
68 void ItemHolder1::holdConfigItem(EItem eItem
)
70 static rtl::Reference
<ItemHolder1
> pHolder
= new ItemHolder1();
71 pHolder
->impl_addItem(eItem
);
74 void SAL_CALL
ItemHolder1::disposing(const css::lang::EventObject
&)
76 css::uno::Reference
< css::uno::XInterface
> xSelfHold(static_cast< css::lang::XEventListener
* >(this), css::uno::UNO_QUERY
);
77 impl_releaseAllItems();
80 void ItemHolder1::impl_addItem(EItem eItem
)
82 std::scoped_lock
aLock(m_aLock
);
84 for ( auto const & rInfo
: m_lItems
)
86 if (rInfo
.eItem
== eItem
)
91 aNewItem
.eItem
= eItem
;
92 impl_newItem(aNewItem
);
94 m_lItems
.emplace_back(std::move(aNewItem
));
97 void ItemHolder1::impl_releaseAllItems()
99 std::vector
< TItemInfo
> items
;
101 std::scoped_lock
aLock(m_aLock
);
102 items
.swap(m_lItems
);
105 // items will be freed when the block exits
108 void ItemHolder1::impl_newItem(TItemInfo
& rItem
)
112 case EItem::CmdOptions
:
113 rItem
.pItem
.reset( new SvtCommandOptions() );
116 case EItem::EventConfig
:
117 //rItem.pItem.reset( new GlobalEventConfig() );
120 case EItem::LinguConfig
:
121 rItem
.pItem
.reset( new SvtLinguConfig() );
124 case EItem::ModuleOptions
:
125 rItem
.pItem
.reset( new SvtModuleOptions() );
128 case EItem::PathOptions
:
129 rItem
.pItem
.reset( new SvtPathOptions() );
132 case EItem::UserOptions
:
133 rItem
.pItem
.reset( new SvtUserOptions() );
136 case EItem::SysLocaleOptions
:
137 rItem
.pItem
.reset( new SvtSysLocaleOptions() );
141 OSL_FAIL( "unknown item type" );
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */