1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
/*
* Copyright © 2010 Codethink Limited
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the licence, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
#define G_SETTINGS_ENABLE_BACKEND
#include <gio/gsettingsbackend.h>
#include "../engine/dconf-engine.h"
#include <gio/gio.h>
#include <string.h>
typedef GSettingsBackendClass DConfSettingsBackendClass;
typedef struct
{
GSettingsBackend backend;
DConfEngine *engine;
} DConfSettingsBackend;
static GType dconf_settings_backend_get_type (void);
G_DEFINE_TYPE (DConfSettingsBackend, dconf_settings_backend, G_TYPE_SETTINGS_BACKEND)
static GVariant *
dconf_settings_backend_read (GSettingsBackend *backend,
const gchar *key,
const GVariantType *expected_type,
gboolean default_value)
{
DConfSettingsBackend *dcsb = (DConfSettingsBackend *) backend;
/* XXX default value */
return dconf_engine_read (dcsb->engine, NULL, key);
}
static gboolean
dconf_settings_backend_write (GSettingsBackend *backend,
const gchar *key,
GVariant *value,
gpointer origin_tag)
{
DConfSettingsBackend *dcsb = (DConfSettingsBackend *) backend;
DConfChangeset *change;
gboolean success;
change = dconf_changeset_new ();
dconf_changeset_set (change, key, value);
success = dconf_engine_change_fast (dcsb->engine, change, origin_tag, NULL);
dconf_changeset_unref (change);
return success;
}
static gboolean
dconf_settings_backend_add_to_changeset (gpointer key,
gpointer value,
gpointer data)
{
dconf_changeset_set (data, key, value);
return FALSE;
}
static gboolean
dconf_settings_backend_write_tree (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag)
{
DConfSettingsBackend *dcsb = (DConfSettingsBackend *) backend;
DConfChangeset *change;
gboolean success;
change= dconf_changeset_new ();
g_tree_foreach (tree, dconf_settings_backend_add_to_changeset, change);
success = dconf_engine_change_fast (dcsb->engine, change, origin_tag, NULL);
dconf_changeset_unref (change);
return success;
}
static void
dconf_settings_backend_reset (GSettingsBackend *backend,
const gchar *key,
gpointer origin_tag)
{
dconf_settings_backend_write (backend, key, NULL, origin_tag);
}
static gboolean
dconf_settings_backend_get_writable (GSettingsBackend *backend,
const gchar *name)
{
DConfSettingsBackend *dcsb = (DConfSettingsBackend *) backend;
return dconf_engine_is_writable (dcsb->engine, name);
}
static void
dconf_settings_backend_subscribe (GSettingsBackend *backend,
const gchar *name)
{
DConfSettingsBackend *dcsb = (DConfSettingsBackend *) backend;
dconf_engine_watch_fast (dcsb->engine, name);
}
static void
dconf_settings_backend_unsubscribe (GSettingsBackend *backend,
const gchar *name)
{
DConfSettingsBackend *dcsb = (DConfSettingsBackend *) backend;
dconf_engine_unwatch_fast (dcsb->engine, name);
}
static void
dconf_settings_backend_sync (GSettingsBackend *backend)
{
DConfSettingsBackend *dcsb = (DConfSettingsBackend *) backend;
dconf_engine_sync (dcsb->engine);
}
static void
dconf_settings_backend_free_weak_ref (gpointer data)
{
GWeakRef *weak_ref = data;
g_weak_ref_clear (weak_ref);
g_slice_free (GWeakRef, weak_ref);
}
static void
dconf_settings_backend_init (DConfSettingsBackend *dcsb)
{
GWeakRef *weak_ref;
weak_ref = g_slice_new (GWeakRef);
g_weak_ref_init (weak_ref, dcsb);
dcsb->engine = dconf_engine_new (weak_ref, dconf_settings_backend_free_weak_ref);
}
static void
dconf_settings_backend_finalize (GObject *object)
{
DConfSettingsBackend *dcsb = (DConfSettingsBackend *) object;
dconf_engine_unref (dcsb->engine);
G_OBJECT_CLASS (dconf_settings_backend_parent_class)
->finalize (object);
}
static void
dconf_settings_backend_class_init (GSettingsBackendClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = dconf_settings_backend_finalize;
class->read = dconf_settings_backend_read;
class->write = dconf_settings_backend_write;
class->write_tree = dconf_settings_backend_write_tree;
class->reset = dconf_settings_backend_reset;
class->get_writable = dconf_settings_backend_get_writable;
class->subscribe = dconf_settings_backend_subscribe;
class->unsubscribe = dconf_settings_backend_unsubscribe;
class->sync = dconf_settings_backend_sync;
}
void
g_io_module_load (GIOModule *module)
{
g_type_module_use (G_TYPE_MODULE (module));
g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
dconf_settings_backend_get_type (),
"dconf", 100);
}
void
g_io_module_unload (GIOModule *module)
{
g_assert_not_reached ();
}
gchar **
g_io_module_query (void)
{
return g_strsplit (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME, "!", 0);
}
void
dconf_engine_change_notify (DConfEngine *engine,
const gchar *prefix,
const gchar * const *changes,
const gchar *tag,
gpointer origin_tag,
gpointer user_data)
{
GWeakRef *weak_ref = user_data;
DConfSettingsBackend *dcsb;
dcsb = g_weak_ref_get (weak_ref);
if (dcsb == NULL)
return;
if (changes[0] == NULL)
return;
if (changes[1] == NULL)
{
if (g_str_has_suffix (prefix, "/"))
g_settings_backend_path_changed (G_SETTINGS_BACKEND (dcsb), prefix, origin_tag);
else
g_settings_backend_changed (G_SETTINGS_BACKEND (dcsb), prefix, origin_tag);
}
else
g_settings_backend_keys_changed (G_SETTINGS_BACKEND (dcsb), prefix, changes, origin_tag);
}
|