1 #include "../../config.h"
3 #include "../Common/Common.h"
5 #include "GnomeSettingsStore.h"
9 // FIXME - need to handle gconf errors better here
11 extern "C" void ListenerCallback(GConfClient
* pClient
, guint iCNXN_ID
, GConfEntry
* pEntry
, gpointer pUserData
);
14 CGnomeSettingsStore::CGnomeSettingsStore(Dasher::CEventHandler
*pEventHandler
):CSettingsStore(pEventHandler
) {
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
);
29 CGnomeSettingsStore::~CGnomeSettingsStore() {
31 g_object_unref(the_gconf_client
);
36 bool CGnomeSettingsStore::LoadSetting(const std::string
&Key
, bool *Value
) {
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
) {
50 *Value
= gconf_value_get_bool(got_value
);
51 gconf_value_free(got_value
);
59 bool CGnomeSettingsStore::LoadSetting(const std::string
&Key
, long *Value
) {
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
) {
73 *Value
= gconf_value_get_int(got_value
);
74 gconf_value_free(got_value
);
82 bool CGnomeSettingsStore::LoadSetting(const std::string
&Key
, std::string
*Value
) {
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
) {
96 *Value
= gconf_value_get_string(got_value
);
97 gconf_value_free(got_value
);
105 void CGnomeSettingsStore::SaveSetting(const std::string
&Key
, bool Value
) {
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
);
117 void CGnomeSettingsStore::SaveSetting(const std::string
&Key
, long Value
) {
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
);
129 void CGnomeSettingsStore::SaveSetting(const std::string
&Key
, const std::string
&Value
) {
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
);
142 void CGnomeSettingsStore::NotificationCallback(GConfClient
*pClient
, guint iCNXN_ID
, GConfEntry
*pEntry
) {
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
) {
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
);
166 for(int i(0); i
< NUM_OF_LPS
; ++i
) {
167 if(s_oParamTables
.LongParamTable
[i
].regName
== strKeyName
) {
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
);
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
);
199 extern "C" void ListenerCallback(GConfClient
*pClient
, guint iCnxn_ID
, GConfEntry
*pEntry
, gpointer pUserData
) {
200 static_cast < CGnomeSettingsStore
* >(pUserData
)->NotificationCallback(pClient
, iCnxn_ID
, pEntry
);