/[svn]/gigedit/trunk/src/gigedit/Settings.h
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/Settings.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2893 - (show annotations) (download) (as text)
Fri Apr 29 14:19:53 2016 UTC (7 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4876 byte(s)
* Automatically save & restore window size and position
  (yet limited to main window and script editor window).
* Bumped version (1.0.0.svn6).

1 /*
2 Copyright (c) 2014-2016 Christian Schoenebeck
3
4 This file is part of "gigedit" and released under the terms of the
5 GNU General Public License version 2.
6 */
7
8 #ifndef GIGEDIT_SETTINGS
9 #define GIGEDIT_SETTINGS
10
11 #include <typeinfo>
12 #include <glibmm/object.h>
13 #include <glibmm/property.h>
14 #include <vector>
15
16 /**
17 * Reflects, saves and restores all settings for the gigedit application.
18 *
19 * This class holds a bunch of custom Property objects which can be accessed
20 * as if they were basic data types (i.e. by using assignment operator, etc.).
21 * As soon as a property gets modified this way, it will automatically be saved
22 * to a local config file.
23 */
24 class Settings : public Glib::Object {
25 public:
26 /**
27 * Data types for the individual settings.
28 */
29 enum RawValueType_t {
30 BOOLEAN,
31 INTEGER,
32 UNKNOWN
33 };
34
35 /**
36 * All settings are grouped into these settings groups.
37 */
38 enum Group_t {
39 GLOBAL,
40 MAIN_WINDOW,
41 SCRIPT_EDITOR,
42 };
43
44 /**
45 * Extension of regular Glib::Property template class; this one
46 * automatically calls Settings::onPropertyChanged() method passing this
47 * property object as pointer; and it allows to assign new values to this
48 * property by using the regular assignment operator; and requires a
49 * "Setting group" to be assigned to the property at construction time.
50 */
51 template<typename T>
52 class Property : public Glib::Property<T> {
53 public:
54 Property(Settings& object, Group_t group, const Glib::ustring& name)
55 : Glib::Property<T>::Property(object, name)
56 {
57 m_settings = &object;
58 m_group = group;
59 const RawValueType_t type = rawValueType();
60 Glib::Property<T>::get_proxy().signal_changed().connect(
61 sigc::bind(
62 sigc::bind(
63 sigc::bind(
64 sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
65 m_group
66 ),
67 type
68 ),
69 this
70 )
71 );
72 }
73
74 Property(Settings& object, Group_t group, const Glib::ustring& name, const T& default_value)
75 : Glib::Property<T>::Property(object, name, default_value)
76 {
77 m_settings = &object;
78 m_group = group;
79 const RawValueType_t type = rawValueType();
80 Glib::Property<T>::get_proxy().signal_changed().connect(
81 sigc::bind(
82 sigc::bind(
83 sigc::bind(
84 sigc::mem_fun(m_settings, &Settings::onPropertyChanged),
85 m_group
86 ),
87 type
88 ),
89 this
90 )
91 );
92 }
93
94 Property<T>& operator=(const T value) {
95 Glib::Property<T>::set_value(value);
96 return *this;
97 }
98
99 RawValueType_t rawValueType() const {
100 const std::string name = typeid(T).name();
101 if (name == "bool" || name == "b") return BOOLEAN;
102 if (name == "int" || name == "i") return INTEGER;
103 return UNKNOWN;
104 }
105
106 Group_t group() const { return m_group; }
107
108 private:
109 Settings* m_settings;
110 Group_t m_group;
111 };
112
113 // settings of "Global" group
114 Property<bool> warnUserOnExtensions; ///< if enabled, the user shall he be warned if he is trying to use a gig format extension that will not work with Gigasampler/GigaStudio
115 Property<bool> syncSamplerInstrumentSelection; ///< if enabled, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit
116 Property<bool> moveRootNoteWithRegionMoved; ///< if enabled, the root note(s) of regions are automatically moving when the user drags a region around at the virtual keyboard
117
118 // settings of "MainWindow" group
119 Property<int> mainWindowX;
120 Property<int> mainWindowY;
121 Property<int> mainWindowW;
122 Property<int> mainWindowH;
123
124 // settings of "ScriptEditor" group
125 Property<int> scriptEditorWindowX;
126 Property<int> scriptEditorWindowY;
127 Property<int> scriptEditorWindowW;
128 Property<int> scriptEditorWindowH;
129
130 static Settings* singleton();
131 Settings();
132 void load();
133
134 protected:
135 void onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group);
136
137 private:
138 std::vector<Glib::PropertyBase*> m_boolProps; ///< Pointers to all 'bool' type properties this Setting class manages.
139 std::vector<Glib::PropertyBase*> m_intProps; ///< Pointers to all 'int' type properties this Setting class manages.
140 bool m_ignoreNotifies;
141 };
142
143 #endif // GIGEDIT_SETTINGS

  ViewVC Help
Powered by ViewVC