tagging release
[dasher.git] / Src / DasherCore / GnomeSettingsStore.cpp
blob03cc0accd8689715f3369e89e987e1a52d7f7f50
1 #include "../../config.h"
3 #include "../Common/Common.h"
5 #include "GnomeSettingsStore.h"
7 #include <iostream>
9 // FIXME - need to handle gconf errors better here
10 #ifdef WITH_GCONF
11 extern "C" void ListenerCallback(GConfClient * pClient, guint iCNXN_ID, GConfEntry * pEntry, gpointer pUserData);
12 #endif
14 CGnomeSettingsStore::CGnomeSettingsStore(Dasher::CEventHandler *pEventHandler):CSettingsStore(pEventHandler) {
15 #ifdef WITH_GCONF
16 // GError *gconferror;
18 // gconf_init( argc, argv, &gconferror );
19 the_gconf_client = gconf_client_get_default();
21 gconf_client_add_dir(the_gconf_client, "/apps/dasher4", GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
23 gconf_client_notify_add(the_gconf_client, "/apps/dasher4", ListenerCallback, this, NULL, NULL);
24 #endif
26 LoadPersistent();
29 CGnomeSettingsStore::~CGnomeSettingsStore() {
30 #ifdef WITH_GCONF
31 g_object_unref(the_gconf_client);
32 #endif
36 bool CGnomeSettingsStore::LoadSetting(const std::string &Key, bool *Value) {
37 #ifdef WITH_GCONF
38 char keypath[1024];
40 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
42 GError *the_error = NULL;
44 GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath, &the_error);
46 if(got_value == NULL) {
47 return false;
50 *Value = gconf_value_get_bool(got_value);
51 gconf_value_free(got_value);
53 return true;
54 #else
55 return false;
56 #endif
59 bool CGnomeSettingsStore::LoadSetting(const std::string &Key, long *Value) {
60 #ifdef WITH_GCONF
61 char keypath[1024];
63 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
65 GError *the_error = NULL;
67 GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath, &the_error);
69 if(got_value == NULL) {
70 return false;
73 *Value = gconf_value_get_int(got_value);
74 gconf_value_free(got_value);
76 return true;
77 #else
78 return false;
79 #endif
82 bool CGnomeSettingsStore::LoadSetting(const std::string &Key, std::string *Value) {
83 #ifdef WITH_GCONF
84 char keypath[1024];
86 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
88 GError *the_error = NULL;
90 GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath, &the_error);
92 if(got_value == NULL) {
93 return false;
96 *Value = gconf_value_get_string(got_value);
97 gconf_value_free(got_value);
99 return true;
100 #else
101 return false;
102 #endif
105 void CGnomeSettingsStore::SaveSetting(const std::string &Key, bool Value) {
106 #ifdef WITH_GCONF
107 char keypath[1024];
109 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
111 GError *the_error = NULL;
113 gconf_client_set_bool(the_gconf_client, keypath, Value, &the_error);
114 #endif
117 void CGnomeSettingsStore::SaveSetting(const std::string &Key, long Value) {
118 #ifdef WITH_GCONF
119 char keypath[1024];
121 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
123 GError *the_error = NULL;
125 gconf_client_set_int(the_gconf_client, keypath, Value, &the_error);
126 #endif
129 void CGnomeSettingsStore::SaveSetting(const std::string &Key, const std::string &Value) {
130 #ifdef WITH_GCONF
131 char keypath[1024];
133 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
135 GError *the_error = NULL;
137 gconf_client_set_string(the_gconf_client, keypath, Value.c_str(), &the_error);
138 #endif
141 #ifdef WITH_GCONF
142 void CGnomeSettingsStore::NotificationCallback(GConfClient *pClient, guint iCNXN_ID, GConfEntry *pEntry) {
143 return;
145 std::string strKey(pEntry->key);
146 std::string strKeyName(strKey.substr(strKey.find_last_of("/") + 1));
148 for(int i(0); i < NUM_OF_BPS; ++i) {
149 if(s_oParamTables.BoolParamTable[i].regName == strKeyName) {
151 bool bValue;
152 LoadSetting(s_oParamTables.BoolParamTable[i].regName, &bValue);
154 bool bOldValue(s_oParamTables.BoolParamTable[i].value);
156 // We need to check that the value has actually changed, otherwise we'll get a loop
158 if(bValue != bOldValue) {
159 SetBoolParameter(i + FIRST_BP, bValue);
162 return;
166 for(int i(0); i < NUM_OF_LPS; ++i) {
167 if(s_oParamTables.LongParamTable[i].regName == strKeyName) {
169 long lValue;
170 LoadSetting(s_oParamTables.LongParamTable[i].regName, &lValue);
172 long lOldValue(s_oParamTables.LongParamTable[i].value);
174 if(lValue != lOldValue) {
175 SetLongParameter(i + FIRST_LP, lValue);
178 return;
182 for(int i(0); i < NUM_OF_SPS; ++i) {
183 if(s_oParamTables.StringParamTable[i].regName == strKeyName) {
185 std::string strValue;
186 LoadSetting(s_oParamTables.StringParamTable[i].regName, &strValue);
188 std::string strOldValue(s_oParamTables.StringParamTable[i].value);
190 if(strValue != strOldValue) {
191 SetStringParameter(i + FIRST_SP, strValue);
194 return;
199 extern "C" void ListenerCallback(GConfClient *pClient, guint iCnxn_ID, GConfEntry *pEntry, gpointer pUserData) {
200 static_cast < CGnomeSettingsStore * >(pUserData)->NotificationCallback(pClient, iCnxn_ID, pEntry);
202 #endif