1 | /* |
2 | * Copyright © 2010 Codethink Limited |
3 | * |
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.1 of the License, or (at your option) any later version. |
8 | * |
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. |
13 | * |
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/>. |
16 | * |
17 | * Author: Ryan Lortie <desrt@desrt.ca> |
18 | */ |
19 | |
20 | #include "config.h" |
21 | |
22 | #include "gsettingsbackendinternal.h" |
23 | #include "giomodule.h" |
24 | #include "gsimplepermission.h" |
25 | |
26 | |
27 | #define G_TYPE_NULL_SETTINGS_BACKEND (g_null_settings_backend_get_type ()) |
28 | #define G_NULL_SETTINGS_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ |
29 | G_TYPE_NULL_SETTINGS_BACKEND, \ |
30 | GNullSettingsBackend)) |
31 | |
32 | |
33 | typedef GSettingsBackendClass GNullSettingsBackendClass; |
34 | typedef GSettingsBackend GNullSettingsBackend; |
35 | |
36 | G_DEFINE_TYPE_WITH_CODE (GNullSettingsBackend, |
37 | g_null_settings_backend, |
38 | G_TYPE_SETTINGS_BACKEND, |
39 | g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME, |
40 | g_define_type_id, "null" , 10)) |
41 | |
42 | static GVariant * |
43 | g_null_settings_backend_read (GSettingsBackend *backend, |
44 | const gchar *key, |
45 | const GVariantType *expected_type, |
46 | gboolean default_value) |
47 | { |
48 | return NULL; |
49 | } |
50 | |
51 | static gboolean |
52 | g_null_settings_backend_write (GSettingsBackend *backend, |
53 | const gchar *key, |
54 | GVariant *value, |
55 | gpointer origin_tag) |
56 | { |
57 | if (value) |
58 | g_variant_unref (value: g_variant_ref_sink (value)); |
59 | return FALSE; |
60 | } |
61 | |
62 | static gboolean |
63 | g_null_settings_backend_write_one (gpointer key, |
64 | gpointer value, |
65 | gpointer data) |
66 | { |
67 | if (value) |
68 | g_variant_unref (value: g_variant_ref_sink (value)); |
69 | return FALSE; |
70 | } |
71 | |
72 | static gboolean |
73 | g_null_settings_backend_write_tree (GSettingsBackend *backend, |
74 | GTree *tree, |
75 | gpointer origin_tag) |
76 | { |
77 | g_tree_foreach (tree, func: g_null_settings_backend_write_one, user_data: backend); |
78 | return FALSE; |
79 | } |
80 | |
81 | static void |
82 | g_null_settings_backend_reset (GSettingsBackend *backend, |
83 | const gchar *key, |
84 | gpointer origin_tag) |
85 | { |
86 | } |
87 | |
88 | static gboolean |
89 | g_null_settings_backend_get_writable (GSettingsBackend *backend, |
90 | const gchar *name) |
91 | { |
92 | return FALSE; |
93 | } |
94 | |
95 | static GPermission * |
96 | g_null_settings_backend_get_permission (GSettingsBackend *backend, |
97 | const gchar *path) |
98 | { |
99 | return g_simple_permission_new (FALSE); |
100 | } |
101 | |
102 | static void |
103 | g_null_settings_backend_init (GNullSettingsBackend *memory) |
104 | { |
105 | } |
106 | |
107 | static void |
108 | g_null_settings_backend_class_init (GNullSettingsBackendClass *class) |
109 | { |
110 | GSettingsBackendClass *backend_class = G_SETTINGS_BACKEND_CLASS (class); |
111 | |
112 | backend_class->read = g_null_settings_backend_read; |
113 | backend_class->write = g_null_settings_backend_write; |
114 | backend_class->write_tree = g_null_settings_backend_write_tree; |
115 | backend_class->reset = g_null_settings_backend_reset; |
116 | backend_class->get_writable = g_null_settings_backend_get_writable; |
117 | backend_class->get_permission = g_null_settings_backend_get_permission; |
118 | } |
119 | |
120 | /** |
121 | * g_null_settings_backend_new: |
122 | * |
123 | * |
124 | * Creates a readonly #GSettingsBackend. |
125 | * |
126 | * This backend does not allow changes to settings, so all settings |
127 | * will always have their default values. |
128 | * |
129 | * Returns: (transfer full): a newly created #GSettingsBackend |
130 | * |
131 | * Since: 2.28 |
132 | */ |
133 | GSettingsBackend * |
134 | g_null_settings_backend_new (void) |
135 | { |
136 | return g_object_new (G_TYPE_NULL_SETTINGS_BACKEND, NULL); |
137 | } |
138 | |