1 /*
2 * Copyright © 2010 Codethink Limited
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Ryan Lortie <desrt@desrt.ca>
20 */
21
22 #include "config.h"
23
24 #include "gsettingsbackendinternal.h"
25 #include "giomodule-priv.h"
26 #include "gsimplepermission.h"
27
28
29 #define G_TYPE_NULL_SETTINGS_BACKEND (g_null_settings_backend_get_type ())
30 #define G_NULL_SETTINGS_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
31 G_TYPE_NULL_SETTINGS_BACKEND, \
32 GNullSettingsBackend))
33
34
35 typedef GSettingsBackendClass GNullSettingsBackendClass;
36 typedef GSettingsBackend GNullSettingsBackend;
37
38 G_DEFINE_TYPE_WITH_CODE (GNullSettingsBackend,
39 g_null_settings_backend,
40 G_TYPE_SETTINGS_BACKEND,
41 _g_io_modules_ensure_extension_points_registered ();
42 g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
43 g_define_type_id, "null", 10))
44
45 static GVariant *
46 g_null_settings_backend_read (GSettingsBackend *backend,
47 const gchar *key,
48 const GVariantType *expected_type,
49 gboolean default_value)
50 {
51 return NULL;
52 }
53
54 static gboolean
55 g_null_settings_backend_write (GSettingsBackend *backend,
56 const gchar *key,
57 GVariant *value,
58 gpointer origin_tag)
59 {
60 if (value)
61 g_variant_unref (g_variant_ref_sink (value));
62 return FALSE;
63 }
64
65 static gboolean
66 g_null_settings_backend_write_one (gpointer key,
67 gpointer value,
68 gpointer data)
69 {
70 if (value)
71 g_variant_unref (g_variant_ref_sink (value));
72 return FALSE;
73 }
74
75 static gboolean
76 g_null_settings_backend_write_tree (GSettingsBackend *backend,
77 GTree *tree,
78 gpointer origin_tag)
79 {
80 g_tree_foreach (tree, g_null_settings_backend_write_one, backend);
81 return FALSE;
82 }
83
84 static void
85 g_null_settings_backend_reset (GSettingsBackend *backend,
86 const gchar *key,
87 gpointer origin_tag)
88 {
89 }
90
91 static gboolean
92 g_null_settings_backend_get_writable (GSettingsBackend *backend,
93 const gchar *name)
94 {
95 return FALSE;
96 }
97
98 static GPermission *
99 g_null_settings_backend_get_permission (GSettingsBackend *backend,
100 const gchar *path)
101 {
102 return g_simple_permission_new (FALSE);
103 }
104
105 static void
106 g_null_settings_backend_init (GNullSettingsBackend *memory)
107 {
108 }
109
110 static void
111 g_null_settings_backend_class_init (GNullSettingsBackendClass *class)
112 {
113 GSettingsBackendClass *backend_class = G_SETTINGS_BACKEND_CLASS (class);
114
115 backend_class->read = g_null_settings_backend_read;
116 backend_class->write = g_null_settings_backend_write;
117 backend_class->write_tree = g_null_settings_backend_write_tree;
118 backend_class->reset = g_null_settings_backend_reset;
119 backend_class->get_writable = g_null_settings_backend_get_writable;
120 backend_class->get_permission = g_null_settings_backend_get_permission;
121 }
122
123 /**
124 * g_null_settings_backend_new:
125 *
126 *
127 * Creates a readonly #GSettingsBackend.
128 *
129 * This backend does not allow changes to settings, so all settings
130 * will always have their default values.
131 *
132 * Returns: (transfer full): a newly created #GSettingsBackend
133 *
134 * Since: 2.28
135 */
136 GSettingsBackend *
137 g_null_settings_backend_new (void)
138 {
139 return g_object_new (G_TYPE_NULL_SETTINGS_BACKEND, NULL);
140 }