2 * Copyright © 2010 Codethink Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Ryan Lortie <desrt@desrt.ca>
22 #define G_SETTINGS_ENABLE_BACKEND
23 #include <gio/gsettingsbackend.h>
24 #include "../engine/dconf-engine.h"
29 typedef GSettingsBackendClass DConfSettingsBackendClass
;
33 GSettingsBackend backend
;
35 } DConfSettingsBackend
;
37 static GType
dconf_settings_backend_get_type (void);
38 G_DEFINE_TYPE (DConfSettingsBackend
, dconf_settings_backend
, G_TYPE_SETTINGS_BACKEND
)
41 dconf_settings_backend_read (GSettingsBackend
*backend
,
43 const GVariantType
*expected_type
,
44 gboolean default_value
)
46 DConfSettingsBackend
*dcsb
= (DConfSettingsBackend
*) backend
;
48 return dconf_engine_read (dcsb
->engine
,
49 default_value
? DCONF_READ_DEFAULT_VALUE
: 0,
54 dconf_settings_backend_read_user_value (GSettingsBackend
*backend
,
56 const GVariantType
*expected_type
)
58 DConfSettingsBackend
*dcsb
= (DConfSettingsBackend
*) backend
;
60 return dconf_engine_read (dcsb
->engine
, DCONF_READ_USER_VALUE
, NULL
, key
);
64 dconf_settings_backend_write (GSettingsBackend
*backend
,
69 DConfSettingsBackend
*dcsb
= (DConfSettingsBackend
*) backend
;
70 DConfChangeset
*change
;
73 change
= dconf_changeset_new ();
74 dconf_changeset_set (change
, key
, value
);
76 success
= dconf_engine_change_fast (dcsb
->engine
, change
, origin_tag
, NULL
);
77 dconf_changeset_unref (change
);
83 dconf_settings_backend_add_to_changeset (gpointer key
,
87 dconf_changeset_set (data
, key
, value
);
93 dconf_settings_backend_write_tree (GSettingsBackend
*backend
,
97 DConfSettingsBackend
*dcsb
= (DConfSettingsBackend
*) backend
;
98 DConfChangeset
*change
;
101 if (g_tree_nnodes (tree
) == 0)
104 change
= dconf_changeset_new ();
105 g_tree_foreach (tree
, dconf_settings_backend_add_to_changeset
, change
);
106 success
= dconf_engine_change_fast (dcsb
->engine
, change
, origin_tag
, NULL
);
107 dconf_changeset_unref (change
);
113 dconf_settings_backend_reset (GSettingsBackend
*backend
,
117 dconf_settings_backend_write (backend
, key
, NULL
, origin_tag
);
121 dconf_settings_backend_get_writable (GSettingsBackend
*backend
,
124 DConfSettingsBackend
*dcsb
= (DConfSettingsBackend
*) backend
;
126 return dconf_engine_is_writable (dcsb
->engine
, name
);
130 dconf_settings_backend_subscribe (GSettingsBackend
*backend
,
133 DConfSettingsBackend
*dcsb
= (DConfSettingsBackend
*) backend
;
135 dconf_engine_watch_fast (dcsb
->engine
, name
);
139 dconf_settings_backend_unsubscribe (GSettingsBackend
*backend
,
142 DConfSettingsBackend
*dcsb
= (DConfSettingsBackend
*) backend
;
144 dconf_engine_unwatch_fast (dcsb
->engine
, name
);
148 dconf_settings_backend_sync (GSettingsBackend
*backend
)
150 DConfSettingsBackend
*dcsb
= (DConfSettingsBackend
*) backend
;
152 dconf_engine_sync (dcsb
->engine
);
156 dconf_settings_backend_free_weak_ref (gpointer data
)
158 GWeakRef
*weak_ref
= data
;
160 g_weak_ref_clear (weak_ref
);
161 g_slice_free (GWeakRef
, weak_ref
);
165 dconf_settings_backend_init (DConfSettingsBackend
*dcsb
)
169 weak_ref
= g_slice_new (GWeakRef
);
170 g_weak_ref_init (weak_ref
, dcsb
);
171 dcsb
->engine
= dconf_engine_new (NULL
, weak_ref
, dconf_settings_backend_free_weak_ref
);
175 dconf_settings_backend_finalize (GObject
*object
)
177 DConfSettingsBackend
*dcsb
= (DConfSettingsBackend
*) object
;
179 dconf_engine_unref (dcsb
->engine
);
181 G_OBJECT_CLASS (dconf_settings_backend_parent_class
)
186 dconf_settings_backend_class_init (GSettingsBackendClass
*class)
188 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
190 object_class
->finalize
= dconf_settings_backend_finalize
;
192 class->read
= dconf_settings_backend_read
;
193 class->read_user_value
= dconf_settings_backend_read_user_value
;
194 class->write
= dconf_settings_backend_write
;
195 class->write_tree
= dconf_settings_backend_write_tree
;
196 class->reset
= dconf_settings_backend_reset
;
197 class->get_writable
= dconf_settings_backend_get_writable
;
198 class->subscribe
= dconf_settings_backend_subscribe
;
199 class->unsubscribe
= dconf_settings_backend_unsubscribe
;
200 class->sync
= dconf_settings_backend_sync
;
204 g_io_module_load (GIOModule
*module
)
206 g_type_module_use (G_TYPE_MODULE (module
));
207 g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME
,
208 dconf_settings_backend_get_type (),
213 g_io_module_unload (GIOModule
*module
)
215 g_assert_not_reached ();
219 g_io_module_query (void)
221 return g_strsplit (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME
, "!", 0);
225 dconf_engine_change_notify (DConfEngine
*engine
,
227 const gchar
* const *changes
,
229 gboolean is_writability
,
233 GWeakRef
*weak_ref
= user_data
;
234 DConfSettingsBackend
*dcsb
;
235 g_debug ("change_notify: %s", prefix
);
237 dcsb
= g_weak_ref_get (weak_ref
);
242 if (changes
[0] == NULL
)
247 /* We know that the engine does it this way... */
248 g_assert (changes
[0][0] == '\0' && changes
[1] == NULL
);
250 if (g_str_has_suffix (prefix
, "/"))
251 g_settings_backend_path_writable_changed (G_SETTINGS_BACKEND (dcsb
), prefix
);
253 g_settings_backend_writable_changed (G_SETTINGS_BACKEND (dcsb
), prefix
);
256 /* We send the normal change notification even in the event that this
257 * was a writability notification because adding/removing a lock could
258 * impact the value that gets read.
260 if (changes
[1] == NULL
)
262 if (g_str_has_suffix (prefix
, "/"))
263 g_settings_backend_path_changed (G_SETTINGS_BACKEND (dcsb
), prefix
, origin_tag
);
265 g_settings_backend_changed (G_SETTINGS_BACKEND (dcsb
), prefix
, origin_tag
);
268 g_settings_backend_keys_changed (G_SETTINGS_BACKEND (dcsb
), prefix
, changes
, origin_tag
);