Mercurial > hg > svcore
comparison base/Preferences.cpp @ 145:82f529a08cf3
* Change preferences dialog to ok/apply/cancel model
* Make preferences persist in a config file
* Change instance() to getInstance() for all singleton types
* Make pasting to time-value layer with no values in clipboard ask you how to
generate the values
* Fix bad behaviour caused by importing "data"-type (i.e. 3d dense) model from
annotation file without a fixed window size available
author | Chris Cannam |
---|---|
date | Thu, 27 Jul 2006 16:06:32 +0000 |
parents | 0ba66b160a02 |
children | 4b2ea82fd0ed |
comparison
equal
deleted
inserted
replaced
144:a9c3ba1777e1 | 145:82f529a08cf3 |
---|---|
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #include "Preferences.h" | 16 #include "Preferences.h" |
17 | 17 |
18 #include "Exceptions.h" | |
19 | |
20 #include "TempDirectory.h" | |
21 | |
22 #include "fileio/ConfigFile.h" //!!! reorg | |
23 | |
24 #include <QDir> | |
25 #include <QFileInfo> | |
26 | |
18 Preferences * | 27 Preferences * |
19 Preferences::m_instance = new Preferences(); | 28 Preferences::m_instance = new Preferences(); |
20 | 29 |
21 Preferences::Preferences() : | 30 Preferences::Preferences() : |
22 m_smoothSpectrogram(true), | 31 m_smoothSpectrogram(true), |
23 m_tuningFrequency(440), | 32 m_tuningFrequency(440), |
24 m_propertyBoxLayout(VerticallyStacked), | 33 m_propertyBoxLayout(VerticallyStacked), |
25 m_windowType(HanningWindow) | 34 m_windowType(HanningWindow), |
26 { | 35 m_configFile(0) |
36 { | |
37 // Let TempDirectory do its thing first, so as to avoid any race | |
38 // condition if it happens that we both want to use the same directory | |
39 TempDirectory::getInstance(); | |
40 | |
41 QString svDirBase = ".sv1"; | |
42 QString svDir = QDir::home().filePath(svDirBase); | |
43 if (!QFileInfo(svDir).exists()) { | |
44 if (!QDir::home().mkdir(svDirBase)) { | |
45 throw DirectoryCreationFailed(QString("%1 directory in $HOME") | |
46 .arg(svDirBase)); | |
47 } | |
48 } else if (!QFileInfo(svDir).isDir()) { | |
49 throw DirectoryCreationFailed(QString("$HOME/%1 is not a directory") | |
50 .arg(svDirBase)); | |
51 } | |
52 | |
53 m_configFile = new ConfigFile(QDir(svDir).filePath("preferences.cfg")); | |
54 | |
55 m_smoothSpectrogram = | |
56 m_configFile->getBool("preferences-smooth-spectrogram", true); | |
57 m_tuningFrequency = | |
58 m_configFile->getFloat("preferences-tuning-frequency", 440.f); | |
59 m_propertyBoxLayout = PropertyBoxLayout | |
60 (m_configFile->getInt("preferences-property-box-layout", | |
61 int(VerticallyStacked))); | |
62 m_windowType = WindowType | |
63 (m_configFile->getInt("preferences-window-type", int(HanningWindow))); | |
64 } | |
65 | |
66 Preferences::~Preferences() | |
67 { | |
68 delete m_configFile; | |
27 } | 69 } |
28 | 70 |
29 Preferences::PropertyList | 71 Preferences::PropertyList |
30 Preferences::getProperties() const | 72 Preferences::getProperties() const |
31 { | 73 { |
153 void | 195 void |
154 Preferences::setSmoothSpectrogram(bool smooth) | 196 Preferences::setSmoothSpectrogram(bool smooth) |
155 { | 197 { |
156 if (m_smoothSpectrogram != smooth) { | 198 if (m_smoothSpectrogram != smooth) { |
157 m_smoothSpectrogram = smooth; | 199 m_smoothSpectrogram = smooth; |
200 m_configFile->set("preferences-smooth-spectrogram", smooth); | |
158 emit propertyChanged("Smooth Spectrogram"); | 201 emit propertyChanged("Smooth Spectrogram"); |
159 } | 202 } |
160 } | 203 } |
161 | 204 |
162 void | 205 void |
163 Preferences::setTuningFrequency(float freq) | 206 Preferences::setTuningFrequency(float freq) |
164 { | 207 { |
165 if (m_tuningFrequency != freq) { | 208 if (m_tuningFrequency != freq) { |
166 m_tuningFrequency = freq; | 209 m_tuningFrequency = freq; |
210 m_configFile->set("preferences-tuning-frequency", freq); | |
167 emit propertyChanged("Tuning Frequency"); | 211 emit propertyChanged("Tuning Frequency"); |
168 } | 212 } |
169 } | 213 } |
170 | 214 |
171 void | 215 void |
172 Preferences::setPropertyBoxLayout(PropertyBoxLayout layout) | 216 Preferences::setPropertyBoxLayout(PropertyBoxLayout layout) |
173 { | 217 { |
174 if (m_propertyBoxLayout != layout) { | 218 if (m_propertyBoxLayout != layout) { |
175 m_propertyBoxLayout = layout; | 219 m_propertyBoxLayout = layout; |
220 m_configFile->set("preferences-property-box-layout", int(layout)); | |
176 emit propertyChanged("Property Box Layout"); | 221 emit propertyChanged("Property Box Layout"); |
177 } | 222 } |
178 } | 223 } |
179 | 224 |
180 void | 225 void |
181 Preferences::setWindowType(WindowType type) | 226 Preferences::setWindowType(WindowType type) |
182 { | 227 { |
183 if (m_windowType != type) { | 228 if (m_windowType != type) { |
184 m_windowType = type; | 229 m_windowType = type; |
230 m_configFile->set("preferences-window-type", int(type)); | |
185 emit propertyChanged("Window Type"); | 231 emit propertyChanged("Window Type"); |
186 } | 232 } |
187 } | 233 } |
188 | 234 |