Sayonara Player
Main Page
Modules
Namespaces
Classes
src
Helper
Settings
SettingNotifier.h
1
/* SettingNotifier.h */
2
3
/* Copyright (C) 2011-2017 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 SETTINGNOTIFIER_H
22
#define SETTINGNOTIFIER_H
23
24
#include <QObject>
25
#include "Helper/Settings/AbstrSettingNotifier.h"
26
#pragma once
27
28
/* Connect a Setting to a private slot in a class that want to be notified
29
whenever the setting changed:
30
31
call: REGISTER_LISTENER(Set::LFM_Active, lfm_active_changed);
32
where lfm_active_changed() is a private Slot in that class;
33
*/
34
35
#define __REGISTER_LISTENER(setting_key, fn) \
36
SettingNotifier<setting_key##_t>* v_##fn = SettingNotifier<setting_key##_t>::getInstance();\
37
connect(v_##fn, SIGNAL(sig_value_changed()), this, SLOT( fn() ))
38
39
#define REGISTER_LISTENER(setting_key, fn) \
40
do { \
41
__REGISTER_LISTENER(setting_key, fn); \
42
fn(); \
43
} while(0)
44
45
#define REGISTER_LISTENER_NO_CALL(setting_key, fn) \
46
do { \
47
__REGISTER_LISTENER(setting_key, fn); \
48
} while(0)
49
50
51
/* A Setting notifier has to be a singleton */
52
template
<
typename
T >
53
class
SettingNotifier
:
public
AbstrSettingNotifier
{
54
private
:
55
explicit
SettingNotifier
( QObject* parent=0 ) :
AbstrSettingNotifier
(parent) {}
56
SettingNotifier
(
const
SettingNotifier
& ) {}
57
58
public
:
59
virtual
~
SettingNotifier
() {}
60
61
static
SettingNotifier< T >
* getInstance()
62
{
63
static
SettingNotifier< T >
inst;
64
return
&inst;
65
}
66
67
void
val_changed()
68
{
69
emit sig_value_changed();
70
}
71
};
72
73
#endif // SETTINGNOTIFIER_H
AbstrSettingNotifier
The AbstrSettingNotifier class The setting notifier emits a sig_value_changed whenever the value of t...
Definition:
AbstrSettingNotifier.h:37
SettingNotifier
Definition:
SettingNotifier.h:53
Generated on Sat May 13 2017 02:00:27 for Sayonara Player by
1.8.11