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