/src/libreoffice/unotools/source/config/itemholder1.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 | | #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/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> |
37 | | |
38 | | ItemHolder1::ItemHolder1() |
39 | 21 | { |
40 | 21 | try |
41 | 21 | { |
42 | 21 | const css::uno::Reference< css::uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext(); |
43 | 21 | css::uno::Reference< css::lang::XComponent > xCfg( |
44 | 21 | css::configuration::theDefaultProvider::get( xContext ), |
45 | 21 | css::uno::UNO_QUERY_THROW ); |
46 | 21 | xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this)); |
47 | 21 | } |
48 | | #ifdef DBG_UTIL |
49 | | catch(const css::uno::Exception&) |
50 | | { |
51 | | static bool bMessage = true; |
52 | | if(bMessage) |
53 | | { |
54 | | bMessage = false; |
55 | | TOOLS_WARN_EXCEPTION( "unotools", "CreateInstance with arguments"); |
56 | | } |
57 | | } |
58 | | #else |
59 | 21 | catch(css::uno::Exception&){} |
60 | 21 | #endif |
61 | 21 | } |
62 | | |
63 | | ItemHolder1::~ItemHolder1() |
64 | 9 | { |
65 | 9 | impl_releaseAllItems(); |
66 | 9 | } |
67 | | |
68 | | void ItemHolder1::holdConfigItem(EItem eItem) |
69 | 38 | { |
70 | 38 | static rtl::Reference<ItemHolder1> pHolder = new ItemHolder1(); |
71 | 38 | pHolder->impl_addItem(eItem); |
72 | 38 | } |
73 | | |
74 | | void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&) |
75 | 0 | { |
76 | 0 | css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY); |
77 | 0 | impl_releaseAllItems(); |
78 | 0 | } |
79 | | |
80 | | void ItemHolder1::impl_addItem(EItem eItem) |
81 | 38 | { |
82 | 38 | std::scoped_lock aLock(m_aLock); |
83 | | |
84 | 38 | for ( auto const & rInfo : m_lItems ) |
85 | 27 | { |
86 | 27 | if (rInfo.eItem == eItem) |
87 | 0 | return; |
88 | 27 | } |
89 | | |
90 | 38 | TItemInfo aNewItem; |
91 | 38 | aNewItem.eItem = eItem; |
92 | 38 | impl_newItem(aNewItem); |
93 | 38 | if (aNewItem.pItem) |
94 | 32 | m_lItems.emplace_back(std::move(aNewItem)); |
95 | 38 | } |
96 | | |
97 | | void ItemHolder1::impl_releaseAllItems() |
98 | 9 | { |
99 | 9 | std::vector< TItemInfo > items; |
100 | 9 | { |
101 | 9 | std::scoped_lock aLock(m_aLock); |
102 | 9 | items.swap(m_lItems); |
103 | 9 | } |
104 | | |
105 | | // items will be freed when the block exits |
106 | 9 | } |
107 | | |
108 | | void ItemHolder1::impl_newItem(TItemInfo& rItem) |
109 | 38 | { |
110 | 38 | switch(rItem.eItem) |
111 | 38 | { |
112 | 2 | case EItem::CmdOptions : |
113 | 2 | rItem.pItem.reset( new SvtCommandOptions() ); |
114 | 2 | break; |
115 | | |
116 | 6 | case EItem::EventConfig : |
117 | | //rItem.pItem.reset( new GlobalEventConfig() ); |
118 | 6 | break; |
119 | | |
120 | 14 | case EItem::LinguConfig : |
121 | 14 | rItem.pItem.reset( new SvtLinguConfig() ); |
122 | 14 | break; |
123 | | |
124 | 10 | case EItem::ModuleOptions : |
125 | 10 | rItem.pItem.reset( new SvtModuleOptions() ); |
126 | 10 | break; |
127 | | |
128 | 0 | case EItem::PathOptions : |
129 | 0 | rItem.pItem.reset( new SvtPathOptions() ); |
130 | 0 | break; |
131 | | |
132 | 6 | case EItem::UserOptions : |
133 | 6 | rItem.pItem.reset( new SvtUserOptions() ); |
134 | 6 | break; |
135 | | |
136 | 0 | case EItem::SysLocaleOptions : |
137 | 0 | rItem.pItem.reset( new SvtSysLocaleOptions() ); |
138 | 0 | break; |
139 | | |
140 | 0 | default: |
141 | 0 | OSL_FAIL( "unknown item type" ); |
142 | 0 | break; |
143 | 38 | } |
144 | 38 | } |
145 | | |
146 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |