/src/libreoffice/svtools/source/config/itemholder2.cxx
Line | Count | Source |
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 "itemholder2.hxx" |
22 | | |
23 | | #include <osl/diagnose.h> |
24 | | #include <comphelper/processfactory.hxx> |
25 | | #include <com/sun/star/lang/XComponent.hpp> |
26 | | #include <com/sun/star/configuration/theDefaultProvider.hpp> |
27 | | |
28 | | #include <svtools/colorcfg.hxx> |
29 | | #include <unotools/options.hxx> |
30 | | #include <svtools/miscopt.hxx> |
31 | | #include <comphelper/diagnose_ex.hxx> |
32 | | #include <rtl/ref.hxx> |
33 | | |
34 | | namespace svtools { |
35 | | |
36 | | ItemHolder2::ItemHolder2() |
37 | 0 | { |
38 | 0 | try |
39 | 0 | { |
40 | 0 | const css::uno::Reference< css::uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext(); |
41 | 0 | css::uno::Reference< css::lang::XComponent > xCfg( |
42 | 0 | css::configuration::theDefaultProvider::get( xContext ), |
43 | 0 | css::uno::UNO_QUERY_THROW ); |
44 | 0 | xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this)); |
45 | 0 | } |
46 | 0 | catch(const css::uno::RuntimeException&) |
47 | 0 | { |
48 | 0 | throw; |
49 | 0 | } |
50 | | #ifdef DBG_UTIL |
51 | | catch(const css::uno::Exception&) |
52 | | { |
53 | | static bool bMessage = true; |
54 | | if(bMessage) |
55 | | { |
56 | | bMessage = false; |
57 | | TOOLS_WARN_EXCEPTION( "svtools", "CreateInstance with arguments" ); |
58 | | } |
59 | | } |
60 | | #else |
61 | 0 | catch(css::uno::Exception&){} |
62 | 0 | #endif |
63 | 0 | } |
64 | | |
65 | | |
66 | | ItemHolder2::~ItemHolder2() |
67 | 0 | { |
68 | 0 | impl_releaseAllItems(); |
69 | 0 | } |
70 | | |
71 | | |
72 | | void ItemHolder2::holdConfigItem(EItem eItem) |
73 | 0 | { |
74 | 0 | static rtl::Reference<ItemHolder2> pHolder = new ItemHolder2(); |
75 | 0 | pHolder->impl_addItem(eItem); |
76 | 0 | } |
77 | | |
78 | | |
79 | | void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&) |
80 | 0 | { |
81 | 0 | impl_releaseAllItems(); |
82 | 0 | } |
83 | | |
84 | | |
85 | | void ItemHolder2::impl_addItem(EItem eItem) |
86 | 0 | { |
87 | 0 | std::scoped_lock aLock(m_aLock); |
88 | |
|
89 | 0 | for ( auto const & rInfo : m_lItems ) |
90 | 0 | { |
91 | 0 | if (rInfo.eItem == eItem) |
92 | 0 | return; |
93 | 0 | } |
94 | | |
95 | 0 | TItemInfo aNewItem; |
96 | 0 | aNewItem.eItem = eItem; |
97 | 0 | impl_newItem(aNewItem); |
98 | 0 | if (aNewItem.pItem) |
99 | 0 | m_lItems.emplace_back(std::move(aNewItem)); |
100 | 0 | } |
101 | | |
102 | | |
103 | | void ItemHolder2::impl_releaseAllItems() |
104 | 0 | { |
105 | 0 | std::vector<TItemInfo> items; |
106 | 0 | { |
107 | 0 | std::scoped_lock aLock(m_aLock); |
108 | 0 | items.swap(m_lItems); |
109 | 0 | } |
110 | | |
111 | | // items will be freed when the block exits |
112 | 0 | } |
113 | | |
114 | | |
115 | | void ItemHolder2::impl_newItem(TItemInfo& rItem) |
116 | 0 | { |
117 | 0 | switch(rItem.eItem) |
118 | 0 | { |
119 | 0 | case EItem::ColorConfig : |
120 | 0 | rItem.pItem.reset( new ::svtools::ColorConfig() ); |
121 | 0 | break; |
122 | | |
123 | 0 | case EItem::MiscOptions : |
124 | 0 | rItem.pItem.reset( new SvtMiscOptions() ); |
125 | 0 | break; |
126 | | |
127 | 0 | default: |
128 | 0 | OSL_ASSERT(false); |
129 | 0 | break; |
130 | 0 | } |
131 | 0 | } |
132 | | |
133 | | } // namespace svtools |
134 | | |
135 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |