07ad4d8911
We already support displaying extension details for the list command, so it's a logical extension to also support showing extension info for a particular extension (not least because the shell has a corresponding D-Bus method). https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234
232 lines
6.1 KiB
C
232 lines
6.1 KiB
C
/* main.c
|
|
*
|
|
* Copyright 2018 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 <gio/gio.h>
|
|
#include <glib/gi18n.h>
|
|
#include <locale.h>
|
|
|
|
#include "config.h"
|
|
#include "commands.h"
|
|
#include "common.h"
|
|
|
|
static const char *
|
|
extension_state_to_string (ExtensionState state)
|
|
{
|
|
switch (state)
|
|
{
|
|
case STATE_ENABLED:
|
|
return "ENABLED";
|
|
case STATE_DISABLED:
|
|
return "DISABLED";
|
|
case STATE_ERROR:
|
|
return "ERROR";
|
|
case STATE_OUT_OF_DATE:
|
|
return "OUT OF DATE";
|
|
case STATE_DOWNLOADING:
|
|
return "DOWNLOADING";
|
|
case STATE_INITIALIZED:
|
|
return "INITIALIZED";
|
|
case STATE_UNINSTALLED:
|
|
return "UNINSTALLED";
|
|
}
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
void
|
|
show_help (GOptionContext *context, const char *message)
|
|
{
|
|
g_autofree char *help = NULL;
|
|
|
|
if (message)
|
|
g_printerr ("gnome-extensions: %s\n\n", message);
|
|
|
|
help = g_option_context_get_help (context, TRUE, NULL);
|
|
g_printerr ("%s", help);
|
|
}
|
|
|
|
GDBusProxy *
|
|
get_shell_proxy (GError **error)
|
|
{
|
|
return g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
|
|
G_DBUS_PROXY_FLAGS_NONE,
|
|
NULL,
|
|
"org.gnome.Shell",
|
|
"/org/gnome/Shell",
|
|
"org.gnome.Shell.Extensions",
|
|
NULL,
|
|
error);
|
|
}
|
|
|
|
GSettings *
|
|
get_shell_settings (void)
|
|
{
|
|
g_autoptr (GSettingsSchema) schema = NULL;
|
|
GSettingsSchemaSource *schema_source;
|
|
|
|
schema_source = g_settings_schema_source_get_default ();
|
|
schema = g_settings_schema_source_lookup (schema_source,
|
|
"org.gnome.shell",
|
|
TRUE);
|
|
|
|
if (schema == NULL)
|
|
return NULL;
|
|
|
|
return g_settings_new_full (schema, NULL, NULL);
|
|
}
|
|
|
|
void
|
|
print_extension_info (GVariantDict *info,
|
|
DisplayFormat format)
|
|
{
|
|
const char *uuid, *name, *desc, *path, *url, *author;
|
|
double state, version;
|
|
|
|
g_variant_dict_lookup (info, "uuid", "&s", &uuid);
|
|
g_print ("%s\n", uuid);
|
|
|
|
if (format == DISPLAY_ONELINE)
|
|
return;
|
|
|
|
g_variant_dict_lookup (info, "name", "&s", &name);
|
|
g_print (" %s: %s\n", _("Name"), name);
|
|
|
|
g_variant_dict_lookup (info, "description", "&s", &desc);
|
|
g_print (" %s: %s\n", _("Description"), desc);
|
|
|
|
g_variant_dict_lookup (info, "path", "&s", &path);
|
|
g_print (" %s: %s\n", _("Path"), path);
|
|
|
|
if (g_variant_dict_lookup (info, "url", "&s", &url))
|
|
g_print (" %s: %s\n", _("URL"), url);
|
|
|
|
if (g_variant_dict_lookup (info, "original-author", "&s", &author))
|
|
g_print (" %s: %s\n", _("Original author"), author);
|
|
|
|
if (g_variant_dict_lookup (info, "version", "d", &version))
|
|
g_print (" %s: %.0f\n", _("Version"), version);
|
|
|
|
g_variant_dict_lookup (info, "state", "d", &state);
|
|
g_print (" %s: %s\n", _("State"), extension_state_to_string (state));
|
|
}
|
|
|
|
static int
|
|
handle_version (int argc, char *argv[], gboolean do_help)
|
|
{
|
|
if (do_help || argc > 1)
|
|
{
|
|
if (!do_help)
|
|
g_printerr ("gnome-extensions: %s\n\n", _("“version” takes no arguments"));
|
|
|
|
g_printerr ("%s\n", _("Usage:"));
|
|
g_printerr (" gnome-extensions version\n");
|
|
g_printerr ("\n");
|
|
g_printerr ("%s\n", _("Print version information and exit."));
|
|
|
|
return do_help ? 0 : 2;
|
|
}
|
|
|
|
g_print ("%s\n", VERSION);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
usage (void)
|
|
{
|
|
g_printerr ("%s\n", _("Usage:"));
|
|
g_printerr (" gnome-extensions %s %s\n", _("COMMAND"), _("[ARGS…]"));
|
|
g_printerr ("\n");
|
|
g_printerr ("%s\n", _("Commands:"));
|
|
g_printerr (" help %s\n", _("Print help"));
|
|
g_printerr (" version %s\n", _("Print version"));
|
|
g_printerr (" enable %s\n", _("Enable extension"));
|
|
g_printerr (" disable %s\n", _("Disable extension"));
|
|
g_printerr (" list %s\n", _("List extensions"));
|
|
g_printerr (" info %s\n", _("Show extension info"));
|
|
g_printerr (" create %s\n", _("Create extension"));
|
|
g_printerr ("\n");
|
|
g_printerr (_("Use %s to get detailed help.\n"), "“gnome-extensions help COMMAND”");
|
|
}
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
const char *command;
|
|
gboolean do_help = FALSE;
|
|
|
|
setlocale (LC_ALL, "");
|
|
textdomain (GETTEXT_PACKAGE);
|
|
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
|
|
|
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
#endif
|
|
|
|
if (argc < 2)
|
|
{
|
|
usage ();
|
|
return 1;
|
|
}
|
|
|
|
command = argv[1];
|
|
argc--;
|
|
argv++;
|
|
|
|
if (g_str_equal (command, "help"))
|
|
{
|
|
if (argc == 1)
|
|
{
|
|
usage ();
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
command = argv[1];
|
|
do_help = TRUE;
|
|
}
|
|
}
|
|
else if (g_str_equal (command, "--help"))
|
|
{
|
|
usage ();
|
|
return 0;
|
|
}
|
|
else if (g_str_equal (command, "--version"))
|
|
{
|
|
command = "version";
|
|
}
|
|
|
|
if (g_str_equal (command, "version"))
|
|
return handle_version (argc, argv, do_help);
|
|
else if (g_str_equal (command, "enable"))
|
|
return handle_enable (argc, argv, do_help);
|
|
else if (g_str_equal (command, "disable"))
|
|
return handle_disable (argc, argv, do_help);
|
|
else if (g_str_equal (command, "list"))
|
|
return handle_list (argc, argv, do_help);
|
|
else if (g_str_equal (command, "info"))
|
|
return handle_info (argc, argv, do_help);
|
|
else if (g_str_equal (command, "create"))
|
|
return handle_create (argc, argv, do_help);
|
|
else
|
|
usage ();
|
|
|
|
return 1;
|
|
}
|