Sayonara Player
Loading...
Searching...
No Matches
src
Utils
Settings
SettingNotifier.h
1
/* SettingNotifier.h */
2
3
/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
4
*
5
* This file is part of sayonara player
6
*
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
11
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*/
20
21
#ifndef SAYONARA_PLAYER_SETTINGNOTIFIER_H
22
#define SAYONARA_PLAYER_SETTINGNOTIFIER_H
23
#pragma once
24
25
#include <QObject>
26
27
#include <functional>
28
#include <memory>
29
30
class
AbstrSettingNotifier
:
31
public
QObject
32
{
33
Q_OBJECT
34
35
signals:
36
void
sigValueChanged();
37
38
public
:
39
template
<
typename
Listener>
40
void
addListener(Listener* listener,
void
(Listener::*fn)())
41
{
42
connect(
this
, &AbstrSettingNotifier::sigValueChanged, listener, fn);
43
}
44
45
void
emitValueChanged();
46
};
47
48
template
<
typename
KeyClass>
49
class
SettingNotifier
50
{
51
public
:
52
SettingNotifier
(
const
SettingNotifier
& other) =
delete
;
53
SettingNotifier
(
SettingNotifier
&& other) =
delete
;
54
SettingNotifier
& operator=(
const
SettingNotifier
& other) =
delete
;
55
SettingNotifier
& operator=(
SettingNotifier
&& other) =
delete
;
56
57
~SettingNotifier
() =
default
;
58
59
static
SettingNotifier<KeyClass>
* instance()
60
{
61
static
SettingNotifier<KeyClass>
inst;
62
return
&inst;
63
}
64
65
void
valueChanged()
66
{
67
m_settingNotifier->emitValueChanged();
68
}
69
70
template
<
typename
T>
71
void
addListener(T* c,
void
(T::*fn)())
72
{
73
m_settingNotifier->addListener(c, fn);
74
}
75
76
private
:
77
SettingNotifier
() =
default
;
78
79
std::unique_ptr<AbstrSettingNotifier> m_settingNotifier {std::make_unique<AbstrSettingNotifier>()};
80
};
81
82
namespace
Set
83
{
84
template
<
typename
KeyClass,
typename
Listener>
85
void
listen(Listener* t,
void
(Listener::*fn)(),
const
bool
run =
true
)
86
{
87
SettingNotifier<KeyClass>::instance
()->addListener(t, fn);
88
89
if
(run)
90
{
91
auto
callable = std::bind(fn, t);
92
callable();
93
}
94
}
95
96
template
<
typename
KeyClass>
97
void
shout()
98
{
99
SettingNotifier<KeyClass>::instance
()->valueChanged();
100
}
101
}
102
103
#endif
// SAYONARA_PLAYER_SETTINGNOTIFIER_H
AbstrSettingNotifier
Definition
SettingNotifier.h:32
SettingNotifier
Definition
SettingNotifier.h:50
Generated on Thu Jul 25 2024 00:00:00 for Sayonara Player by
1.12.0