X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgmemorysettingsbackend.c;h=b0d58b5681886f0d3aadea18643c597630b669d5;hb=958da1e9dc82fbb91862501226b8928faf2f9558;hp=bb04f39cbf54a87ca853f5a711027b0b52a1e14b;hpb=8dddf6499e9e8a052a5673fe8771aeaac08cccae;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gmemorysettingsbackend.c b/gio/gmemorysettingsbackend.c index bb04f39..b0d58b5 100644 --- a/gio/gmemorysettingsbackend.c +++ b/gio/gmemorysettingsbackend.c @@ -12,20 +12,17 @@ * 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. + * License along with this library; if not, see . * * Author: Ryan Lortie */ #include "config.h" -#include "gmemorysettingsbackend.h" -#include "gsettingsbackend.h" +#include "gsimplepermission.h" +#include "gsettingsbackendinternal.h" #include "giomodule.h" -#include "gioalias.h" #define G_TYPE_MEMORY_SETTINGS_BACKEND (g_memory_settings_backend_get_type()) #define G_MEMORY_SETTINGS_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ @@ -95,13 +92,16 @@ g_memory_settings_backend_write_one (gpointer key, { GMemorySettingsBackend *memory = data; - g_hash_table_insert (memory->table, g_strdup (key), g_variant_ref (value)); + if (value != NULL) + g_hash_table_insert (memory->table, g_strdup (key), g_variant_ref (value)); + else + g_hash_table_remove (memory->table, key); return FALSE; } static gboolean -g_memory_settings_backend_write_keys (GSettingsBackend *backend, +g_memory_settings_backend_write_tree (GSettingsBackend *backend, GTree *tree, gpointer origin_tag) { @@ -111,6 +111,20 @@ g_memory_settings_backend_write_keys (GSettingsBackend *backend, return TRUE; } +static void +g_memory_settings_backend_reset (GSettingsBackend *backend, + const gchar *key, + gpointer origin_tag) +{ + GMemorySettingsBackend *memory = G_MEMORY_SETTINGS_BACKEND (backend); + + if (g_hash_table_lookup (memory->table, key)) + { + g_hash_table_remove (memory->table, key); + g_settings_backend_changed (backend, key, origin_tag); + } +} + static gboolean g_memory_settings_backend_get_writable (GSettingsBackend *backend, const gchar *name) @@ -118,6 +132,13 @@ g_memory_settings_backend_get_writable (GSettingsBackend *backend, return TRUE; } +static GPermission * +g_memory_settings_backend_get_permission (GSettingsBackend *backend, + const gchar *path) +{ + return g_simple_permission_new (TRUE); +} + static void g_memory_settings_backend_finalize (GObject *object) { @@ -144,7 +165,28 @@ g_memory_settings_backend_class_init (GMemorySettingsBackendClass *class) backend_class->read = g_memory_settings_backend_read; backend_class->write = g_memory_settings_backend_write; - backend_class->write_keys = g_memory_settings_backend_write_keys; + backend_class->write_tree = g_memory_settings_backend_write_tree; + backend_class->reset = g_memory_settings_backend_reset; backend_class->get_writable = g_memory_settings_backend_get_writable; + backend_class->get_permission = g_memory_settings_backend_get_permission; object_class->finalize = g_memory_settings_backend_finalize; } + +/** + * g_memory_settings_backend_new: + * + * Creates a memory-backed #GSettingsBackend. + * + * This backend allows changes to settings, but does not write them + * to any backing storage, so the next time you run your application, + * the memory backend will start out with the default values again. + * + * Returns: (transfer full): a newly created #GSettingsBackend + * + * Since: 2.28 + */ +GSettingsBackend * +g_memory_settings_backend_new (void) +{ + return g_object_new (G_TYPE_MEMORY_SETTINGS_BACKEND, NULL); +}