/src/libreoffice/unotools/source/config/options.cxx
Line | Count | Source (jump to first uncovered line) |
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 <sal/config.h> |
21 | | #include <unotools/options.hxx> |
22 | | |
23 | | #include <algorithm> |
24 | | |
25 | | using utl::detail::Options; |
26 | | using utl::ConfigurationBroadcaster; |
27 | | |
28 | 3.10M | utl::ConfigurationListener::~ConfigurationListener() {} |
29 | | |
30 | | ConfigurationBroadcaster::ConfigurationBroadcaster() |
31 | 2.62M | : m_nBroadcastBlocked( 0 ) |
32 | 2.62M | , m_nBlockedHint( ConfigurationHints::NONE ) |
33 | 2.62M | { |
34 | 2.62M | } |
35 | | |
36 | | ConfigurationBroadcaster::ConfigurationBroadcaster(ConfigurationBroadcaster const & rSource) |
37 | 0 | : mpList( rSource.mpList ? new IMPL_ConfigurationListenerList(*rSource.mpList) : nullptr ) |
38 | 0 | , m_nBroadcastBlocked( rSource.m_nBroadcastBlocked ) |
39 | 0 | , m_nBlockedHint( rSource.m_nBlockedHint ) |
40 | 0 | { |
41 | 0 | } |
42 | | |
43 | | ConfigurationBroadcaster::~ConfigurationBroadcaster() |
44 | 2.61M | { |
45 | 2.61M | } |
46 | | |
47 | | ConfigurationBroadcaster & ConfigurationBroadcaster::operator =( |
48 | | ConfigurationBroadcaster const & other) |
49 | 0 | { |
50 | 0 | if (&other != this) { |
51 | 0 | mpList.reset( |
52 | 0 | other.mpList == nullptr ? nullptr : new IMPL_ConfigurationListenerList(*other.mpList)); |
53 | 0 | m_nBroadcastBlocked = other.m_nBroadcastBlocked; |
54 | 0 | m_nBlockedHint = other.m_nBlockedHint; |
55 | 0 | } |
56 | 0 | return *this; |
57 | 0 | } |
58 | | |
59 | | void ConfigurationBroadcaster::AddListener( utl::ConfigurationListener* pListener ) |
60 | 698k | { |
61 | 698k | if ( !mpList ) |
62 | 536k | mpList.reset(new IMPL_ConfigurationListenerList); |
63 | 698k | mpList->push_back( pListener ); |
64 | 698k | } |
65 | | |
66 | | void ConfigurationBroadcaster::RemoveListener( utl::ConfigurationListener const * pListener ) |
67 | 698k | { |
68 | 698k | if ( mpList ) { |
69 | 698k | auto it = std::find(mpList->begin(), mpList->end(), pListener); |
70 | 698k | if ( it != mpList->end() ) |
71 | 698k | mpList->erase( it ); |
72 | 698k | } |
73 | 698k | } |
74 | | |
75 | | void ConfigurationBroadcaster::NotifyListeners( ConfigurationHints nHint ) |
76 | 0 | { |
77 | 0 | if ( m_nBroadcastBlocked ) |
78 | 0 | m_nBlockedHint |= nHint; |
79 | 0 | else |
80 | 0 | { |
81 | 0 | nHint |= m_nBlockedHint; |
82 | 0 | m_nBlockedHint = ConfigurationHints::NONE; |
83 | 0 | if ( mpList ) { |
84 | 0 | for ( size_t n = 0; n < mpList->size(); n++ ) |
85 | 0 | (*mpList)[ n ]->ConfigurationChanged( this, nHint ); |
86 | 0 | } |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | | void ConfigurationBroadcaster::BlockBroadcasts( bool bBlock ) |
91 | 0 | { |
92 | 0 | if ( bBlock ) |
93 | 0 | ++m_nBroadcastBlocked; |
94 | 0 | else if ( m_nBroadcastBlocked ) |
95 | 0 | { |
96 | 0 | if ( --m_nBroadcastBlocked == 0 ) |
97 | 0 | NotifyListeners( ConfigurationHints::NONE ); |
98 | 0 | } |
99 | 0 | } |
100 | | |
101 | | Options::Options() |
102 | 2.56M | { |
103 | 2.56M | } |
104 | | |
105 | | Options::~Options() |
106 | 2.56M | { |
107 | 2.56M | } |
108 | | |
109 | | void Options::ConfigurationChanged( ConfigurationBroadcaster*, ConfigurationHints nHint ) |
110 | 0 | { |
111 | 0 | NotifyListeners( nHint ); |
112 | 0 | } |
113 | | |
114 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |