LibreOffice Module unotools (master) 1
itemholder1.cxx
Go to the documentation of this file.
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
23#include <com/sun/star/lang/XComponent.hpp>
24#include <com/sun/star/configuration/theDefaultProvider.hpp>
25
29#include <unotools/lingucfg.hxx>
32#include <unotools/options.hxx>
34#include <rtl/ref.hxx>
35#include <osl/diagnose.h>
37
39{
40 try
41 {
42 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
43 css::uno::Reference< css::lang::XComponent > xCfg(
45 css::uno::UNO_QUERY_THROW );
46 xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
47 }
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 catch(css::uno::Exception&){}
60#endif
61}
62
64{
66}
67
69{
70 static rtl::Reference<ItemHolder1> pHolder = new ItemHolder1();
71 pHolder->impl_addItem(eItem);
72}
73
74void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&)
75{
76 css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY);
78}
79
81{
82 std::scoped_lock aLock(m_aLock);
83
84 for ( auto const & rInfo : m_lItems )
85 {
86 if (rInfo.eItem == eItem)
87 return;
88 }
89
90 TItemInfo aNewItem;
91 aNewItem.eItem = eItem;
92 impl_newItem(aNewItem);
93 if (aNewItem.pItem)
94 m_lItems.emplace_back(std::move(aNewItem));
95}
96
98{
99 std::vector< TItemInfo > items;
100 {
101 std::scoped_lock aLock(m_aLock);
102 items.swap(m_lItems);
103 }
104
105 // items will be freed when the block exits
106}
107
109{
110 switch(rItem.eItem)
111 {
112 case EItem::CmdOptions :
113 rItem.pItem.reset( new SvtCommandOptions() );
114 break;
115
117 rItem.pItem.reset( new SvtCompatibilityOptions() );
118 break;
119
120 case EItem::EventConfig :
121 //rItem.pItem.reset( new GlobalEventConfig() );
122 break;
123
124 case EItem::LinguConfig :
125 rItem.pItem.reset( new SvtLinguConfig() );
126 break;
127
129 rItem.pItem.reset( new SvtModuleOptions() );
130 break;
131
132 case EItem::PathOptions :
133 rItem.pItem.reset( new SvtPathOptions() );
134 break;
135
136 case EItem::UserOptions :
137 rItem.pItem.reset( new SvtUserOptions() );
138 break;
139
141 rItem.pItem.reset( new SvtSysLocaleOptions() );
142 break;
143
144 default:
145 OSL_FAIL( "unknown item type" );
146 break;
147 }
148}
149
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void impl_releaseAllItems()
Definition: itemholder1.cxx:97
static void holdConfigItem(EItem eItem)
Definition: itemholder1.cxx:68
std::mutex m_aLock
Definition: itemholder1.hxx:33
virtual ~ItemHolder1() override
Definition: itemholder1.cxx:63
std::vector< TItemInfo > m_lItems
Definition: itemholder1.hxx:34
void impl_addItem(EItem eItem)
Definition: itemholder1.cxx:80
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
Definition: itemholder1.cxx:74
static void impl_newItem(TItemInfo &rItem)
#define TOOLS_WARN_EXCEPTION(area, stream)
@ UserOptions
@ LinguConfig
@ PathOptions
@ CmdOptions
@ ModuleOptions
@ Compatibility
@ SysLocaleOptions
@ EventConfig
OUString get(TranslateId sContextAndId, const std::locale &loc)
Definition: resmgr.cxx:211
std::unique_ptr< utl::detail::Options > pItem