summaryrefslogtreecommitdiff
path: root/meta-openembedded/meta-xfce/recipes-apps/mousepad/files/0001-Plugin-support-Properly-handle-plugin-settings.patch
blob: 0ace907c41ce008ef687f4eafc0be3f3cd8661ee (plain)
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
From 6d1800a305698f801236a2d73ebe178fa2d1139d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABl=20Bonithon?= <gael@xfce.org>
Date: Sat, 12 Jun 2021 16:45:56 +0200
Subject: [PATCH] Plugin support: Properly handle plugin settings

What was done in !92 was strictly speaking only suitable for one plugin.
This could be extended to several plugins by adding a `.gschema.xml`
file in `plugins/`, intermediate between the one of the application and
those of the plugins, or by refactoring the Makefiles with inclusions
and a single call to `@GSETTINGS_RULES@`.

But in any case, due to the relative rigidity of the `.gschema.xml` file
format and the internal workings of `glib-compile-schemas`, this would
only be suitable for plugins that are present at compile time, i.e.
"fake plugins".

Instead, this commit adds the plugin settings at load time, as is
natural and as the `GSettingsSchema` documentation states. To do this,
the setting store is extended to contain several roots: the application
root and the plugin roots.

For the latter, a unified naming convention is preserved, with the
prefix `org.xfce.mousepad.plugins.`, but they are in fact completely
independent of each other and independent of the application root.

Fixes #136, related to !92.

Upstream-Status: Backport [https://gitlab.xfce.org/apps/mousepad/-/commit/0d9d4f05aace800118d0a390e4e5dc5ebb940ca5]

Signed-off-by: Changqing Li <changqing.li@windriver.com>
---
 mousepad/mousepad-application.c               | 12 +++-
 mousepad/mousepad-settings-store.c            | 70 ++++++++++++-------
 mousepad/mousepad-settings-store.h            |  3 +
 mousepad/mousepad-settings.c                  | 14 +++-
 mousepad/mousepad-settings.h                  |  1 +
 mousepad/org.xfce.mousepad.gschema.xml        |  1 -
 ...g.xfce.mousepad.plugins.gspell.gschema.xml |  4 --
 7 files changed, 71 insertions(+), 34 deletions(-)

diff --git a/mousepad/mousepad-application.c b/mousepad/mousepad-application.c
index d9a64ff..378d78e 100644
--- a/mousepad/mousepad-application.c
+++ b/mousepad/mousepad-application.c
@@ -721,7 +721,7 @@ mousepad_application_load_plugins (MousepadApplication *application)
   GError                  *error = NULL;
   GDir                    *dir;
   const gchar             *basename;
-  gchar                   *provider_name;
+  gchar                   *provider_name, *schema_id;
   gchar                  **strs;
   gsize                    n_strs;
 
@@ -775,6 +775,16 @@ mousepad_application_load_plugins (MousepadApplication *application)
                                            application, G_CONNECT_SWAPPED);
           g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
 
+          /* add its settings to the setting store */
+          if (g_str_has_prefix (provider_name, "mousepad-plugin-"))
+            schema_id = provider_name + 16;
+          else
+            schema_id = provider_name;
+
+          schema_id = g_strconcat (MOUSEPAD_ID, ".plugins.", schema_id, NULL);
+          mousepad_settings_add_root (schema_id);
+          g_free (schema_id);
+
           /* instantiate this provider types and initialize its action state */
           if (g_strv_contains ((const gchar *const *) strs, provider_name))
             {
diff --git a/mousepad/mousepad-settings-store.c b/mousepad/mousepad-settings-store.c
index de989bd..d117c53 100644
--- a/mousepad/mousepad-settings-store.c
+++ b/mousepad/mousepad-settings-store.c
@@ -29,9 +29,11 @@
 
 struct MousepadSettingsStore_
 {
-  GObject     parent;
-  GSettings  *root;
-  GHashTable *keys;
+  GObject parent;
+
+  GSettingsBackend *backend;
+  GList            *roots;
+  GHashTable       *keys;
 };
 
 
@@ -76,8 +78,10 @@ mousepad_setting_key_new (const gchar *key_name,
 
 
 static void
-mousepad_setting_key_free (MousepadSettingKey *key)
+mousepad_setting_key_free (gpointer data)
 {
+  MousepadSettingKey *key = data;
+
   if (G_LIKELY (key != NULL))
     {
       g_object_unref (key->settings);
@@ -138,16 +142,16 @@ mousepad_settings_store_class_init (MousepadSettingsStoreClass *klass)
 static void
 mousepad_settings_store_finalize (GObject *object)
 {
-  MousepadSettingsStore *self;
+  MousepadSettingsStore *self = MOUSEPAD_SETTINGS_STORE (object);
 
   g_return_if_fail (MOUSEPAD_IS_SETTINGS_STORE (object));
 
-  self = MOUSEPAD_SETTINGS_STORE (object);
+  if (self->backend != NULL)
+    g_object_unref (self->backend);
 
+  g_list_free_full (self->roots, g_object_unref);
   g_hash_table_destroy (self->keys);
 
-  g_object_unref (self->root);
-
   G_OBJECT_CLASS (mousepad_settings_store_parent_class)->finalize (object);
 }
 
@@ -212,28 +216,19 @@ static void
 mousepad_settings_store_init (MousepadSettingsStore *self)
 {
 #ifdef MOUSEPAD_SETTINGS_KEYFILE_BACKEND
-  GSettingsBackend *backend;
-  gchar            *conf_file;
-  conf_file = g_build_filename (g_get_user_config_dir (),
-                                "Mousepad",
-                                "settings.conf",
-                                NULL);
-  backend = g_keyfile_settings_backend_new (conf_file, "/", NULL);
+  gchar *conf_file;
+
+  conf_file = g_build_filename (g_get_user_config_dir (), "Mousepad", "settings.conf", NULL);
+  self->backend = g_keyfile_settings_backend_new (conf_file, "/", NULL);
   g_free (conf_file);
-  self->root = g_settings_new_with_backend (MOUSEPAD_ID, backend);
-  g_object_unref (backend);
 #else
-  self->root = g_settings_new (MOUSEPAD_ID);
+  self->backend = NULL;
 #endif
 
-  self->keys = g_hash_table_new_full (g_str_hash,
-                                      g_str_equal,
-                                      NULL,
-                                      (GDestroyNotify) mousepad_setting_key_free);
+  self->roots = NULL;
+  self->keys = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, mousepad_setting_key_free);
 
-  mousepad_settings_store_add_settings (self, MOUSEPAD_ID,
-                                        g_settings_schema_source_get_default (),
-                                        self->root);
+  mousepad_settings_store_add_root (self, MOUSEPAD_ID);
 }
 
 
@@ -246,6 +241,31 @@ mousepad_settings_store_new (void)
 
 
 
+void
+mousepad_settings_store_add_root (MousepadSettingsStore *self,
+                                  const gchar           *schema_id)
+{
+  GSettingsSchemaSource *source;
+  GSettingsSchema       *schema;
+  GSettings             *root;
+
+  source = g_settings_schema_source_get_default ();
+  schema = g_settings_schema_source_lookup (source, schema_id, TRUE);
+
+  /* exit silently if no schema is found: plugins may have settings or not */
+  if (schema == NULL)
+    return;
+
+  root = g_settings_new_full (schema, self->backend, NULL);
+  g_settings_schema_unref (schema);
+
+  self->roots = g_list_prepend (self->roots, root);
+
+  mousepad_settings_store_add_settings (self, schema_id, source, root);
+}
+
+
+
 const gchar *
 mousepad_settings_store_lookup_key_name (MousepadSettingsStore *self,
                                          const gchar           *setting)
diff --git a/mousepad/mousepad-settings-store.h b/mousepad/mousepad-settings-store.h
index 3f5cae1..4842036 100644
--- a/mousepad/mousepad-settings-store.h
+++ b/mousepad/mousepad-settings-store.h
@@ -38,6 +38,9 @@ GType                  mousepad_settings_store_get_type        (void);
 
 MousepadSettingsStore *mousepad_settings_store_new             (void);
 
+void                   mousepad_settings_store_add_root        (MousepadSettingsStore  *store,
+                                                                const gchar            *schema_id);
+
 const gchar           *mousepad_settings_store_lookup_key_name (MousepadSettingsStore  *store,
                                                                 const gchar            *setting);
 
diff --git a/mousepad/mousepad-settings.c b/mousepad/mousepad-settings.c
index d071de6..66b338d 100644
--- a/mousepad/mousepad-settings.c
+++ b/mousepad/mousepad-settings.c
@@ -24,6 +24,15 @@ static MousepadSettingsStore *settings_store = NULL;
 
 
 
+void
+mousepad_settings_init (void)
+{
+  if (settings_store == NULL)
+    settings_store = mousepad_settings_store_new ();
+}
+
+
+
 void
 mousepad_settings_finalize (void)
 {
@@ -39,10 +48,9 @@ mousepad_settings_finalize (void)
 
 
 void
-mousepad_settings_init (void)
+mousepad_settings_add_root (const gchar *schema_id)
 {
-  if (settings_store == NULL)
-    settings_store = mousepad_settings_store_new ();
+  mousepad_settings_store_add_root (settings_store, schema_id);
 }
 
 
diff --git a/mousepad/mousepad-settings.h b/mousepad/mousepad-settings.h
index bc63d11..615be51 100644
--- a/mousepad/mousepad-settings.h
+++ b/mousepad/mousepad-settings.h
@@ -87,6 +87,7 @@ G_BEGIN_DECLS
 
 void       mousepad_settings_init          (void);
 void       mousepad_settings_finalize      (void);
+void       mousepad_settings_add_root      (const gchar        *schema_id);
 
 void       mousepad_setting_bind           (const gchar        *setting,
                                             gpointer            object,
diff --git a/mousepad/org.xfce.mousepad.gschema.xml b/mousepad/org.xfce.mousepad.gschema.xml
index e802719..8509ee3 100644
--- a/mousepad/org.xfce.mousepad.gschema.xml
+++ b/mousepad/org.xfce.mousepad.gschema.xml
@@ -39,7 +39,6 @@
 
   <!-- generic schemas -->
   <schema id="org.xfce.mousepad" path="/org/xfce/mousepad/" gettext-domain="mousepad">
-    <child name="plugins" schema="org.xfce.mousepad.plugins"/>
     <child name="preferences" schema="org.xfce.mousepad.preferences"/>
     <child name="state" schema="org.xfce.mousepad.state"/>
   </schema>
diff --git a/plugins/gspell-plugin/org.xfce.mousepad.plugins.gspell.gschema.xml b/plugins/gspell-plugin/org.xfce.mousepad.plugins.gspell.gschema.xml
index 6db65b6..95295ba 100644
--- a/plugins/gspell-plugin/org.xfce.mousepad.plugins.gspell.gschema.xml
+++ b/plugins/gspell-plugin/org.xfce.mousepad.plugins.gspell.gschema.xml
@@ -1,9 +1,5 @@
 <schemalist>
 
-  <schema id="org.xfce.mousepad.plugins" path="/org/xfce/mousepad/plugins/" gettext-domain="mousepad">
-    <child name="gspell" schema="org.xfce.mousepad.plugins.gspell"/>
-  </schema>
-
   <schema id="org.xfce.mousepad.plugins.gspell" path="/org/xfce/mousepad/plugins/gspell/" gettext-domain="mousepad">
     <child name="preferences" schema="org.xfce.mousepad.plugins.gspell.preferences"/>
   </schema>
-- 
2.17.1