[gnome-shell] extensions-tool: Add 'prefs' command



commit 653e6c85bbe6b098a5bb5298d7ede491169a8511
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jan 11 12:03:17 2019 +0100

    extensions-tool: Add 'prefs' command
    
    Easily launching an extension's preference dialog from the command
    line can be quicker than using a UI like Tweaks or the extension
    website, so add that functionality.
    
    https://gitlab.gnome.org/fmuellner/gnome-extensions-tool/merge_requests/2
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234

 src/extensions-tool/command-prefs.c                | 117 +++++++++++++++++++++
 src/extensions-tool/commands.h                     |   1 +
 .../completion/bash/gnome-extensions               |   7 +-
 src/extensions-tool/main.c                         |   3 +
 src/extensions-tool/man/gnome-extensions.txt       |   6 ++
 src/extensions-tool/meson-src.build                |   1 +
 src/extensions-tool/meson.build                    |   1 +
 7 files changed, 134 insertions(+), 2 deletions(-)
---
diff --git a/src/extensions-tool/command-prefs.c b/src/extensions-tool/command-prefs.c
new file mode 100644
index 0000000000..022ff8f86f
--- /dev/null
+++ b/src/extensions-tool/command-prefs.c
@@ -0,0 +1,117 @@
+/* commands-prefs.c
+ *
+ * Copyright 2019 Florian Müllner <fmuellner gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "commands.h"
+#include "common.h"
+#include "config.h"
+
+static gboolean
+launch_extension_prefs (const char *uuid)
+{
+  g_autoptr (GDBusProxy) proxy = NULL;
+  g_autoptr (GVariant) response = NULL;
+  g_autoptr (GVariant) asv = NULL;
+  g_autoptr (GVariantDict) info = NULL;
+  g_autoptr (GError) error = NULL;
+  gboolean has_prefs;
+
+  proxy = get_shell_proxy (&error);
+  if (proxy == NULL)
+    return FALSE;
+
+  response = g_dbus_proxy_call_sync (proxy,
+                                     "GetExtensionInfo",
+                                     g_variant_new ("(s)", uuid),
+                                     0,
+                                     -1,
+                                     NULL,
+                                     &error);
+  if (response == NULL)
+    return FALSE;
+
+  asv = g_variant_get_child_value (response, 0);
+  info = g_variant_dict_new (asv);
+
+  if (!g_variant_dict_contains (info, "uuid"))
+    return FALSE;
+
+  g_variant_dict_lookup (info, "hasPrefs", "b", &has_prefs);
+  if (!has_prefs)
+    return FALSE;
+
+  g_dbus_proxy_call_sync (proxy,
+                          "LaunchExtensionPrefs",
+                          g_variant_new ("(s)", uuid),
+                          0,
+                          -1,
+                          NULL,
+                          &error);
+
+  return TRUE;
+}
+
+int
+handle_prefs (int argc, char *argv[], gboolean do_help)
+{
+  g_autoptr (GOptionContext) context = NULL;
+  g_autoptr (GError) error = NULL;
+  g_auto(GStrv) uuids = NULL;
+  GOptionEntry entries[] = {
+    { .long_name = G_OPTION_REMAINING,
+      .arg_description = "UUID",
+      .arg = G_OPTION_ARG_STRING_ARRAY, .arg_data = &uuids },
+    { NULL }
+  };
+
+  g_set_prgname ("gnome-extensions prefs");
+
+  context = g_option_context_new (NULL);
+  g_option_context_set_help_enabled (context, FALSE);
+  g_option_context_set_summary (context, _("Opens extension preferences"));
+  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+
+  if (do_help)
+    {
+      show_help (context, NULL);
+      return 0;
+    }
+
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    {
+      show_help (context, error->message);
+      return 1;
+    }
+
+  if (uuids == NULL)
+    {
+      show_help (context, _("No UUID given"));
+      return 1;
+    }
+  else if (g_strv_length (uuids) > 1)
+    {
+      show_help (context, _("More than one UUID given"));
+      return 1;
+    }
+
+  return launch_extension_prefs (*uuids) ? 0 : 2;
+}
diff --git a/src/extensions-tool/commands.h b/src/extensions-tool/commands.h
index 247a14434c..04de71c7c1 100644
--- a/src/extensions-tool/commands.h
+++ b/src/extensions-tool/commands.h
@@ -28,6 +28,7 @@ int handle_enable     (int argc, char *argv[], gboolean do_help);
 int handle_disable    (int argc, char *argv[], gboolean do_help);
 int handle_list       (int argc, char *argv[], gboolean do_help);
 int handle_info       (int argc, char *argv[], gboolean do_help);
+int handle_prefs      (int argc, char *argv[], gboolean do_help);
 int handle_create     (int argc, char *argv[], gboolean do_help);
 int handle_pack       (int argc, char *argv[], gboolean do_help);
 int handle_install    (int argc, char *argv[], gboolean do_help);
diff --git a/src/extensions-tool/completion/bash/gnome-extensions 
b/src/extensions-tool/completion/bash/gnome-extensions
index 73b5942812..aaff309c08 100644
--- a/src/extensions-tool/completion/bash/gnome-extensions
+++ b/src/extensions-tool/completion/bash/gnome-extensions
@@ -5,7 +5,7 @@
 ################################################################################
 
 __gnome_extensions() {
-  local commands="version enable disable info install show list create pack"
+  local commands="version enable disable info install show list create pack prefs"
   local COMMAND=${COMP_WORDS[1]}
 
   _init_completion -s || return
@@ -29,7 +29,10 @@ __gnome_extensions() {
         enable)
           local list_opt=--disabled
           ;;&
-        enable|disable|info|show)
+        prefs)
+          local list_opt=--prefs
+          ;;&
+        enable|disable|info|show|prefs)
           COMPREPLY=($(compgen -W "`gnome-extensions list $list_opt`" -- "$2"))
           return 0
           ;;
diff --git a/src/extensions-tool/main.c b/src/extensions-tool/main.c
index 467f498050..ef94abc5f7 100644
--- a/src/extensions-tool/main.c
+++ b/src/extensions-tool/main.c
@@ -186,6 +186,7 @@ usage (void)
   g_printerr ("  list      %s\n", _("List extensions"));
   g_printerr ("  info      %s\n", _("Show extension info"));
   g_printerr ("  show      %s\n", _("Show extension info"));
+  g_printerr ("  prefs     %s\n", _("Open extension preferences"));
   g_printerr ("  create    %s\n", _("Create extension"));
   g_printerr ("  pack      %s\n", _("Package extension"));
   g_printerr ("  install   %s\n", _("Install extension bundle"));
@@ -252,6 +253,8 @@ main (int argc, char *argv[])
     return handle_info (argc, argv, do_help);
   else if (g_str_equal (command, "show"))
     return handle_info (argc, argv, do_help);
+  else if (g_str_equal (command, "prefs"))
+    return handle_prefs (argc, argv, do_help);
   else if (g_str_equal (command, "create"))
     return handle_create (argc, argv, do_help);
   else if (g_str_equal (command, "pack"))
diff --git a/src/extensions-tool/man/gnome-extensions.txt b/src/extensions-tool/man/gnome-extensions.txt
index e782103fd6..2322f6d312 100644
--- a/src/extensions-tool/man/gnome-extensions.txt
+++ b/src/extensions-tool/man/gnome-extensions.txt
@@ -25,6 +25,8 @@ SYNOPSIS
 
 *gnome-extensions* list ['OPTION'...]
 
+*gnome-extensions* prefs 'UUID'
+
 *gnome-extensions* create ['OPTION'...]
 
 *gnome-extensions* pack ['OPTION'...]
@@ -88,6 +90,10 @@ Displays a list of installed extensions.
   *--details*;;
     Show some extra information for each extension
 
+*prefs* 'UUID'::
+Open the preference dialog of the extension identified by 'UUID'.
+
+
 *create* ['OPTION'...]::
 Creates a new extension from a template.
 +
diff --git a/src/extensions-tool/meson-src.build b/src/extensions-tool/meson-src.build
index 7af5365e4e..10ca7b42af 100644
--- a/src/extensions-tool/meson-src.build
+++ b/src/extensions-tool/meson-src.build
@@ -7,6 +7,7 @@ sources = [
   'command-install.c',
   'command-list.c',
   'command-pack.c',
+  'command-prefs.c',
   'common.h',
   'main.c'
 ]
diff --git a/src/extensions-tool/meson.build b/src/extensions-tool/meson.build
index 3902274901..ab93e85c8f 100644
--- a/src/extensions-tool/meson.build
+++ b/src/extensions-tool/meson.build
@@ -16,6 +16,7 @@ sources = [
   'command-install.c',
   'command-list.c',
   'command-pack.c',
+  'command-prefs.c',
   'main.c'
 ]
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]