11 |
#include <glibmm/keyfile.h> |
#include <glibmm/keyfile.h> |
12 |
#include <iostream> |
#include <iostream> |
13 |
#include <stdio.h> |
#include <stdio.h> |
14 |
|
#include <fstream> |
15 |
|
|
16 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 40) || GTKMM_MAJOR_VERSION < 2 |
17 |
|
# define HAS_GLIB_KEYFILE_SAVE_TO_FILE 0 |
18 |
|
#else |
19 |
|
# define HAS_GLIB_KEYFILE_SAVE_TO_FILE 1 |
20 |
|
#endif |
21 |
|
|
22 |
static std::string configDir() { |
static std::string configDir() { |
23 |
//printf("configDir '%s'\n", g_get_user_config_dir()); |
//printf("configDir '%s'\n", g_get_user_config_dir()); |
34 |
} |
} |
35 |
|
|
36 |
static std::string groupName(Settings::Group_t group) { |
static std::string groupName(Settings::Group_t group) { |
37 |
|
switch (group) { |
38 |
|
case Settings::GLOBAL: return "Global"; |
39 |
|
case Settings::MAIN_WINDOW: return "MainWindow"; |
40 |
|
case Settings::SCRIPT_EDITOR: return "ScriptEditor"; |
41 |
|
} |
42 |
return "Global"; |
return "Global"; |
43 |
} |
} |
44 |
|
|
45 |
|
#if !HAS_GLIB_KEYFILE_SAVE_TO_FILE |
46 |
|
|
47 |
|
static bool saveToFile(Glib::KeyFile* keyfile, std::string filename) { |
48 |
|
Glib::ustring s = keyfile->to_data(); |
49 |
|
std::ofstream out; |
50 |
|
out.open(filename.c_str(), std::ios_base::out | std::ios_base::trunc); |
51 |
|
out << s; |
52 |
|
out.close(); |
53 |
|
return true; |
54 |
|
} |
55 |
|
|
56 |
|
#endif // ! HAS_GLIB_KEYFILE_SAVE_TO_FILE |
57 |
|
|
58 |
static Settings* _instance = NULL; |
static Settings* _instance = NULL; |
59 |
|
|
60 |
Settings* Settings::singleton() { |
Settings* Settings::singleton() { |
69 |
warnUserOnExtensions(*this, GLOBAL, "warnUserOnExtensions", true), |
warnUserOnExtensions(*this, GLOBAL, "warnUserOnExtensions", true), |
70 |
syncSamplerInstrumentSelection(*this, GLOBAL, "syncSamplerInstrumentSelection", true), |
syncSamplerInstrumentSelection(*this, GLOBAL, "syncSamplerInstrumentSelection", true), |
71 |
moveRootNoteWithRegionMoved(*this, GLOBAL, "moveRootNoteWithRegionMoved", true), |
moveRootNoteWithRegionMoved(*this, GLOBAL, "moveRootNoteWithRegionMoved", true), |
72 |
|
mainWindowX(*this, MAIN_WINDOW, "x", -1), |
73 |
|
mainWindowY(*this, MAIN_WINDOW, "y", -1), |
74 |
|
mainWindowW(*this, MAIN_WINDOW, "w", -1), |
75 |
|
mainWindowH(*this, MAIN_WINDOW, "h", -1), |
76 |
|
scriptEditorWindowX(*this, SCRIPT_EDITOR, "x", -1), |
77 |
|
scriptEditorWindowY(*this, SCRIPT_EDITOR, "y", -1), |
78 |
|
scriptEditorWindowW(*this, SCRIPT_EDITOR, "w", -1), |
79 |
|
scriptEditorWindowH(*this, SCRIPT_EDITOR, "h", -1), |
80 |
m_ignoreNotifies(false) |
m_ignoreNotifies(false) |
81 |
{ |
{ |
82 |
m_boolProps.push_back(&warnUserOnExtensions); |
m_boolProps.push_back(&warnUserOnExtensions); |
83 |
m_boolProps.push_back(&syncSamplerInstrumentSelection); |
m_boolProps.push_back(&syncSamplerInstrumentSelection); |
84 |
m_boolProps.push_back(&moveRootNoteWithRegionMoved); |
m_boolProps.push_back(&moveRootNoteWithRegionMoved); |
85 |
|
m_intProps.push_back(&mainWindowX); |
86 |
|
m_intProps.push_back(&mainWindowY); |
87 |
|
m_intProps.push_back(&mainWindowW); |
88 |
|
m_intProps.push_back(&mainWindowH); |
89 |
|
m_intProps.push_back(&scriptEditorWindowX); |
90 |
|
m_intProps.push_back(&scriptEditorWindowY); |
91 |
|
m_intProps.push_back(&scriptEditorWindowW); |
92 |
|
m_intProps.push_back(&scriptEditorWindowH); |
93 |
} |
} |
94 |
|
|
95 |
void Settings::onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group) { |
void Settings::onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group) { |
126 |
} |
} |
127 |
|
|
128 |
try { |
try { |
129 |
|
#if HAS_GLIB_KEYFILE_SAVE_TO_FILE |
130 |
bool ok = file.save_to_file(configFile()); |
bool ok = file.save_to_file(configFile()); |
131 |
|
#else |
132 |
|
bool ok = saveToFile(&file, configFile()); |
133 |
|
#endif |
134 |
if (!ok) { |
if (!ok) { |
135 |
std::cerr << "Failed saving gigedit config to '" << configFile() << "'\n" << std::flush; |
std::cerr << "Failed saving gigedit config to '" << configFile() << "'\n" << std::flush; |
136 |
} else { |
} else { |