Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svl/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
#include <rtl/ref.hxx>
28
#include <svl/ctloptions.hxx>
29
#include <comphelper/diagnose_ex.hxx>
30
#include <unotools/options.hxx>
31
32
ItemHolder2::ItemHolder2()
33
0
{
34
0
    try
35
0
    {
36
0
        const css::uno::Reference< css::uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext();
37
0
        css::uno::Reference< css::lang::XComponent > xCfg( css::configuration::theDefaultProvider::get(xContext), css::uno::UNO_QUERY_THROW );
38
0
        xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
39
0
    }
40
0
    catch(const css::uno::RuntimeException&)
41
0
    {
42
0
        throw;
43
0
    }
44
#ifdef DBG_UTIL
45
    catch(const css::uno::Exception&)
46
    {
47
        static bool bMessage = true;
48
        if(bMessage)
49
        {
50
            bMessage = false;
51
            TOOLS_WARN_EXCEPTION( "svl", "" );
52
        }
53
    }
54
#else
55
0
    catch(css::uno::Exception&){}
56
0
#endif
57
0
}
58
59
ItemHolder2::~ItemHolder2()
60
0
{
61
0
    impl_releaseAllItems();
62
0
}
63
64
void ItemHolder2::holdConfigItem(EItem eItem)
65
0
{
66
0
    static rtl::Reference<ItemHolder2> pHolder = new ItemHolder2();
67
0
    pHolder->impl_addItem(eItem);
68
0
}
69
70
void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
71
0
{
72
0
    impl_releaseAllItems();
73
0
}
74
75
void ItemHolder2::impl_addItem(EItem eItem)
76
0
{
77
0
    std::scoped_lock aLock(m_aLock);
78
79
0
    for ( auto const & rInfo : m_lItems )
80
0
    {
81
0
        if (rInfo.eItem == eItem)
82
0
            return;
83
0
    }
84
85
0
    TItemInfo aNewItem;
86
0
    aNewItem.eItem = eItem;
87
0
    impl_newItem(aNewItem);
88
0
    if (aNewItem.pItem)
89
0
        m_lItems.emplace_back(std::move(aNewItem));
90
0
}
91
92
void ItemHolder2::impl_releaseAllItems()
93
0
{
94
0
    std::vector< TItemInfo > items;
95
0
    {
96
0
        std::scoped_lock aLock(m_aLock);
97
0
        items.swap(m_lItems);
98
0
    }
99
100
    // items will be freed when the block exits
101
0
}
102
103
void ItemHolder2::impl_newItem(TItemInfo& rItem)
104
0
{
105
0
    switch(rItem.eItem)
106
0
    {
107
0
        case EItem::CTLOptions :
108
0
            rItem.pItem.reset( new SvtCTLOptions() );
109
0
            break;
110
111
0
        default:
112
0
            OSL_ASSERT(false);
113
0
            break;
114
0
    }
115
0
}
116
117
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */