implemented infinite backoff (fixes #311767)
[dasher.git] / Src / DasherCore / GnomeSettingsStore.cpp
bloba82d42ac012e72f5ee4018d03f430e4589343dc4
1 #include "GnomeSettingsStore.h"
3 #include <iostream>
5 // FIXME - need to handle gconf errors better here
7 extern "C" void ListenerCallback(GConfClient * pClient, guint iCNXN_ID, GConfEntry * pEntry, gpointer pUserData);
9 CGnomeSettingsStore::CGnomeSettingsStore(Dasher::CEventHandler *pEventHandler):CSettingsStore(pEventHandler) {
11 // GError *gconferror;
13 // gconf_init( argc, argv, &gconferror );
14 the_gconf_client = gconf_client_get_default();
16 gconf_client_add_dir(the_gconf_client, "/apps/dasher4", GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
18 gconf_client_notify_add(the_gconf_client, "/apps/dasher4", ListenerCallback, this, NULL, NULL);
20 LoadPersistent();
24 CGnomeSettingsStore::~CGnomeSettingsStore() {
26 g_object_unref(the_gconf_client);
30 bool CGnomeSettingsStore::LoadSetting(const std::string &Key, bool *Value) {
31 char keypath[1024];
33 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
35 GError *the_error = NULL;
37 GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath, &the_error);
39 if(got_value == NULL) {
40 return false;
43 *Value = gconf_value_get_bool(got_value);
44 gconf_value_free(got_value);
46 return true;
49 bool CGnomeSettingsStore::LoadSetting(const std::string &Key, long *Value) {
50 char keypath[1024];
52 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
54 GError *the_error = NULL;
56 GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath, &the_error);
58 if(got_value == NULL) {
59 return false;
62 *Value = gconf_value_get_int(got_value);
63 gconf_value_free(got_value);
65 return true;
68 bool CGnomeSettingsStore::LoadSetting(const std::string &Key, std::string *Value) {
69 char keypath[1024];
71 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
73 GError *the_error = NULL;
75 GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath, &the_error);
77 if(got_value == NULL) {
78 return false;
81 *Value = gconf_value_get_string(got_value);
82 gconf_value_free(got_value);
84 return true;
87 void CGnomeSettingsStore::SaveSetting(const std::string &Key, bool Value) {
88 char keypath[1024];
90 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
92 GError *the_error = NULL;
94 gconf_client_set_bool(the_gconf_client, keypath, Value, &the_error);
97 void CGnomeSettingsStore::SaveSetting(const std::string &Key, long Value) {
98 char keypath[1024];
100 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
102 GError *the_error = NULL;
104 gconf_client_set_int(the_gconf_client, keypath, Value, &the_error);
107 void CGnomeSettingsStore::SaveSetting(const std::string &Key, const std::string &Value) {
108 char keypath[1024];
110 snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
112 GError *the_error = NULL;
114 gconf_client_set_string(the_gconf_client, keypath, Value.c_str(), &the_error);
117 void CGnomeSettingsStore::NotificationCallback(GConfClient *pClient, guint iCNXN_ID, GConfEntry *pEntry) {
118 std::string strKey(pEntry->key);
119 std::string strKeyName(strKey.substr(strKey.find_last_of("/") + 1));
121 for(int i(0); i < NUM_OF_BPS; ++i) {
122 if(s_oParamTables.BoolParamTable[i].regName == strKeyName) {
124 bool bValue;
125 LoadSetting(s_oParamTables.BoolParamTable[i].regName, &bValue);
127 bool bOldValue(s_oParamTables.BoolParamTable[i].value);
129 // We need to check that the value has actually changed, otherwise we'll get a loop
131 if(bValue != bOldValue) {
132 SetBoolParameter(i + FIRST_BP, bValue);
135 return;
139 for(int i(0); i < NUM_OF_LPS; ++i) {
140 if(s_oParamTables.LongParamTable[i].regName == strKeyName) {
142 long lValue;
143 LoadSetting(s_oParamTables.LongParamTable[i].regName, &lValue);
145 long lOldValue(s_oParamTables.LongParamTable[i].value);
147 if(lValue != lOldValue) {
148 SetLongParameter(i + FIRST_LP, lValue);
151 return;
155 for(int i(0); i < NUM_OF_SPS; ++i) {
156 if(s_oParamTables.StringParamTable[i].regName == strKeyName) {
158 std::string strValue;
159 LoadSetting(s_oParamTables.StringParamTable[i].regName, &strValue);
161 std::string strOldValue(s_oParamTables.StringParamTable[i].value);
163 if(strValue != strOldValue) {
164 SetStringParameter(i + FIRST_SP, strValue);
167 return;
172 extern "C" void ListenerCallback(GConfClient *pClient, guint iCnxn_ID, GConfEntry *pEntry, gpointer pUserData) {
173 static_cast < CGnomeSettingsStore * >(pUserData)->NotificationCallback(pClient, iCnxn_ID, pEntry);