Sayonara Player
Settings.h
1 /* Settings.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 #pragma once
21 #ifndef SAYONARA_SETTINGS_H_
22 #define SAYONARA_SETTINGS_H_
23 
24 
25 #include "Helper/Settings/Setting.h"
26 #include "Helper/Settings/SettingNotifier.h"
27 #include "Helper/Singleton.h"
28 
29 
34 class Settings : public QObject
35 {
36  SINGLETON(Settings)
37  PIMPL(Settings)
38 
39 private:
40  AbstrSetting* setting(SK::SettingKey key) const;
41 
42 public:
43 
44  /* get all settings (used by database) */
45  AbstrSetting** get_settings();
46 
47 
48  /* before you want to access a setting you have to register it */
49  void register_setting(AbstrSetting* s);
50 
51 
52  /* checks if all settings are registered */
53  bool check_settings();
54 
55 
56  /* get a setting, defined by a unique, REGISTERED key */
57  template<typename T, SK::SettingKey S>
58  const T& get(const SettingKey<T,S>& k) const
59  {
60  Q_UNUSED(k);
61  Setting<T>* s = (Setting<T>*) setting(S);
62  return s->value();
63  }
64 
65  /* set a setting, define by a unique, REGISTERED key */
66  template<typename T, SK::SettingKey S>
67  void set(const SettingKey<T,S>& key, const T& val)
68  {
69  Q_UNUSED(key)
70  Setting<T>* s = (Setting<T>*) setting(S);
71 
72  if( s->set_value(val)) {
74  sn->val_changed();
75  }
76  }
77 
78  /* get a setting, defined by a unique, REGISTERED key */
79  template<typename T, SK::SettingKey S>
80  void shout(const SettingKey<T,S>& k) const
81  {
82  Q_UNUSED(k);
84  sn->val_changed();
85  }
86 };
87 
88 #endif // SAYONARA_SETTINGS_H_
The Setting class T is the pure value type e.g. QString.
Definition: Setting.h:73
Definition: SettingNotifier.h:53
Definition: SettingKey.h:174
The Settings class.
Definition: Settings.h:34
The AbstrSetting class Every setting needs a key and a value The SK::SettingKey is only used inside t...
Definition: Setting.h:38