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()); |
37 |
return "Global"; |
return "Global"; |
38 |
} |
} |
39 |
|
|
40 |
|
#if !HAS_GLIB_KEYFILE_SAVE_TO_FILE |
41 |
|
|
42 |
|
static bool saveToFile(Glib::KeyFile* keyfile, std::string filename) { |
43 |
|
Glib::ustring s = keyfile->to_data(); |
44 |
|
std::ofstream out; |
45 |
|
out.open(filename.c_str(), std::ios_base::out | std::ios_base::trunc); |
46 |
|
out << s; |
47 |
|
out.close(); |
48 |
|
return true; |
49 |
|
} |
50 |
|
|
51 |
|
#endif // ! HAS_GLIB_KEYFILE_SAVE_TO_FILE |
52 |
|
|
53 |
static Settings* _instance = NULL; |
static Settings* _instance = NULL; |
54 |
|
|
55 |
Settings* Settings::singleton() { |
Settings* Settings::singleton() { |
105 |
} |
} |
106 |
|
|
107 |
try { |
try { |
108 |
|
#if HAS_GLIB_KEYFILE_SAVE_TO_FILE |
109 |
bool ok = file.save_to_file(configFile()); |
bool ok = file.save_to_file(configFile()); |
110 |
|
#else |
111 |
|
bool ok = saveToFile(&file, configFile()); |
112 |
|
#endif |
113 |
if (!ok) { |
if (!ok) { |
114 |
std::cerr << "Failed saving gigedit config to '" << configFile() << "'\n" << std::flush; |
std::cerr << "Failed saving gigedit config to '" << configFile() << "'\n" << std::flush; |
115 |
} else { |
} else { |