[gnome-shell] extensions-tool: Split out settings_list_add/remove helpers
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] extensions-tool: Split out settings_list_add/remove helpers
- Date: Wed, 21 Aug 2019 16:39:57 +0000 (UTC)
commit 7141c5be6d51ab9484988300114b1dc719ae3407
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Jul 24 01:24:52 2019 +0200
extensions-tool: Split out settings_list_add/remove helpers
With the addition of the 'disabled-extensions' key in commit ce1bee727,
the way extensions are enabled/disabled changed: Now a UUID is always
added to one list and removed from another.
Prepare for that by generalizing the relevant bits of the existing
enable/disable commands as helper functions.
https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234
src/extensions-tool/command-disable.c | 24 +-------------
src/extensions-tool/command-enable.c | 23 +------------
src/extensions-tool/common.h | 7 ++++
src/extensions-tool/main.c | 61 +++++++++++++++++++++++++++++++++++
4 files changed, 70 insertions(+), 45 deletions(-)
---
diff --git a/src/extensions-tool/command-disable.c b/src/extensions-tool/command-disable.c
index e578959abe..9c50e1a3dd 100644
--- a/src/extensions-tool/command-disable.c
+++ b/src/extensions-tool/command-disable.c
@@ -29,33 +29,11 @@ static gboolean
disable_extension (const char *uuid)
{
g_autoptr(GSettings) settings = get_shell_settings ();
- g_auto(GStrv) extensions = NULL;
- g_auto(GStrv) new_value = NULL;
- const char **s;
- guint n_extensions;
- int i;
if (settings == NULL)
return FALSE;
- if (!g_settings_is_writable (settings, "enabled-extensions"))
- return FALSE;
-
- extensions = g_settings_get_strv (settings, "enabled-extensions");
-
- if (!g_strv_contains ((const char **)extensions, uuid))
- return TRUE;
-
- n_extensions = g_strv_length (extensions);
- new_value = g_new0 (char *, n_extensions);
- for (i = 0, s = (const char **)extensions; i < n_extensions; i++, s++)
- if (!g_str_equal (*s, uuid))
- new_value[i] = g_strdup (*s);
-
- g_settings_set_strv (settings, "enabled-extensions", (const char **)new_value);
- g_settings_sync ();
-
- return TRUE;
+ return settings_list_remove (settings, "enabled-extensions", uuid);
}
int
diff --git a/src/extensions-tool/command-enable.c b/src/extensions-tool/command-enable.c
index 25b3e92309..2358f8ba2a 100644
--- a/src/extensions-tool/command-enable.c
+++ b/src/extensions-tool/command-enable.c
@@ -29,32 +29,11 @@ static gboolean
enable_extension (const char *uuid)
{
g_autoptr(GSettings) settings = get_shell_settings ();
- g_auto(GStrv) extensions = NULL;
- g_auto(GStrv) new_value = NULL;
- guint n_extensions;
- int i;
if (settings == NULL)
return FALSE;
- if (!g_settings_is_writable (settings, "enabled-extensions"))
- return FALSE;
-
- extensions = g_settings_get_strv (settings, "enabled-extensions");
-
- if (g_strv_contains ((const char **)extensions, uuid))
- return TRUE;
-
- n_extensions = g_strv_length (extensions);
- new_value = g_new0 (char *, n_extensions + 2);
- for (i = 0; i < n_extensions; i++)
- new_value[i] = g_strdup (extensions[i]);
- new_value[i] = g_strdup (uuid);
-
- g_settings_set_strv (settings, "enabled-extensions", (const char **)new_value);
- g_settings_sync ();
-
- return TRUE;
+ return settings_list_add (settings, "enabled-extensions", uuid);
}
int
diff --git a/src/extensions-tool/common.h b/src/extensions-tool/common.h
index 860813a07b..32f4b788b8 100644
--- a/src/extensions-tool/common.h
+++ b/src/extensions-tool/common.h
@@ -54,6 +54,13 @@ void print_extension_info (GVariantDict *info,
GDBusProxy *get_shell_proxy (GError **error);
GSettings *get_shell_settings (void);
+gboolean settings_list_add (GSettings *settings,
+ const char *key,
+ const char *value);
+gboolean settings_list_remove (GSettings *settings,
+ const char *key,
+ const char *value);
+
gboolean file_delete_recursively (GFile *file,
GError **error);
diff --git a/src/extensions-tool/main.c b/src/extensions-tool/main.c
index e6792ad64b..96117a90d3 100644
--- a/src/extensions-tool/main.c
+++ b/src/extensions-tool/main.c
@@ -91,6 +91,67 @@ get_shell_settings (void)
return g_settings_new_full (schema, NULL, NULL);
}
+gboolean
+settings_list_add (GSettings *settings,
+ const char *key,
+ const char *value)
+{
+ g_auto(GStrv) list = NULL;
+ g_auto(GStrv) new_value = NULL;
+ guint n_values;
+ int i;
+
+ if (!g_settings_is_writable (settings, key))
+ return FALSE;
+
+ list = g_settings_get_strv (settings, key);
+
+ if (g_strv_contains ((const char **)list, value))
+ return TRUE;
+
+ n_values = g_strv_length (list);
+ new_value = g_new0 (char *, n_values + 2);
+ for (i = 0; i < n_values; i++)
+ new_value[i] = g_strdup (list[i]);
+ new_value[i] = g_strdup (value);
+
+ g_settings_set_strv (settings, key, (const char **)new_value);
+ g_settings_sync ();
+
+ return TRUE;
+}
+
+gboolean
+settings_list_remove (GSettings *settings,
+ const char *key,
+ const char *value)
+{
+ g_auto(GStrv) list = NULL;
+ g_auto(GStrv) new_value = NULL;
+ const char **s;
+ guint n_values;
+ int i;
+
+ if (!g_settings_is_writable (settings, key))
+ return FALSE;
+
+ list = g_settings_get_strv (settings, key);
+
+ if (!g_strv_contains ((const char **)list, value))
+ return TRUE;
+
+ n_values = g_strv_length (list);
+ new_value = g_new0 (char *, n_values);
+ for (i = 0, s = (const char **)list; i < n_values; i++, s++)
+ if (!g_str_equal (*s, value))
+ new_value[i] = g_strdup (*s);
+
+ g_settings_set_strv (settings, key, (const char **)new_value);
+ g_settings_sync ();
+
+ return TRUE;
+}
+
void
print_extension_info (GVariantDict *info,
DisplayFormat format)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]