extensions-tool: Add list options
In addition to a plain list of all extensions, add options to display additional details of each extensions and to filter the list by enabled state or install location. https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234
This commit is contained in:
parent
ac4b88f25d
commit
07fad38a50
@ -23,14 +23,25 @@
|
||||
|
||||
#include "commands.h"
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
typedef enum {
|
||||
LIST_FLAGS_NONE = 0,
|
||||
LIST_FLAGS_USER = 1 << 0,
|
||||
LIST_FLAGS_SYSTEM = 1 << 1,
|
||||
LIST_FLAGS_ENABLED = 1 << 2,
|
||||
LIST_FLAGS_DISABLED = 1 << 3
|
||||
} ListFilterFlags;
|
||||
|
||||
static gboolean
|
||||
list_extensions (void)
|
||||
list_extensions (ListFilterFlags filter, DisplayFormat format)
|
||||
{
|
||||
g_autoptr (GDBusProxy) proxy = NULL;
|
||||
g_autoptr (GVariant) response = NULL;
|
||||
g_autoptr (GVariant) extensions = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
gboolean needs_newline = FALSE;
|
||||
GVariantIter iter;
|
||||
GVariant *value;
|
||||
char *uuid;
|
||||
@ -53,7 +64,32 @@ list_extensions (void)
|
||||
|
||||
g_variant_iter_init (&iter, extensions);
|
||||
while (g_variant_iter_loop (&iter, "{s@a{sv}}", &uuid, &value))
|
||||
g_print ("%s\n", uuid);
|
||||
{
|
||||
g_autoptr (GVariantDict) info = NULL;
|
||||
double type, state;
|
||||
|
||||
info = g_variant_dict_new (value);
|
||||
g_variant_dict_lookup (info, "type", "d", &type);
|
||||
g_variant_dict_lookup (info, "state", "d", &state);
|
||||
|
||||
if (type == TYPE_USER && (filter & LIST_FLAGS_USER) == 0)
|
||||
continue;
|
||||
|
||||
if (type == TYPE_SYSTEM && (filter & LIST_FLAGS_SYSTEM) == 0)
|
||||
continue;
|
||||
|
||||
if (state == STATE_ENABLED && (filter & LIST_FLAGS_ENABLED) == 0)
|
||||
continue;
|
||||
|
||||
if (state != STATE_ENABLED && (filter & LIST_FLAGS_DISABLED) == 0)
|
||||
continue;
|
||||
|
||||
if (needs_newline)
|
||||
g_print ("\n");
|
||||
|
||||
print_extension_info (info, format);
|
||||
needs_newline = (format != DISPLAY_ONELINE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -63,12 +99,37 @@ handle_list (int argc, char *argv[], gboolean do_help)
|
||||
{
|
||||
g_autoptr (GOptionContext) context = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
int flags = LIST_FLAGS_NONE;
|
||||
gboolean details = FALSE;
|
||||
gboolean user = FALSE;
|
||||
gboolean system = FALSE;
|
||||
gboolean enabled = FALSE;
|
||||
gboolean disabled = FALSE;
|
||||
GOptionEntry entries[] = {
|
||||
{ .long_name = "user",
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &user,
|
||||
.description = _("Show user-installed extensions") },
|
||||
{ .long_name = "system",
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &system,
|
||||
.description = _("Show system-installed extensions") },
|
||||
{ .long_name = "enabled",
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &enabled,
|
||||
.description = _("Show enabled extensions") },
|
||||
{ .long_name = "disabled",
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &disabled,
|
||||
.description = _("Show disabled extensions") },
|
||||
{ .long_name = "details", .short_name = 'd',
|
||||
.arg = G_OPTION_ARG_NONE, .arg_data = &details,
|
||||
.description = _("Print extension details") },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
g_set_prgname ("gnome-extensions list");
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("List installed extensions"));
|
||||
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
||||
|
||||
if (do_help)
|
||||
{
|
||||
@ -88,5 +149,18 @@ handle_list (int argc, char *argv[], gboolean do_help)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return list_extensions () ? 0 : 2;
|
||||
if (user || !system)
|
||||
flags |= LIST_FLAGS_USER;
|
||||
|
||||
if (system || !user)
|
||||
flags |= LIST_FLAGS_SYSTEM;
|
||||
|
||||
if (enabled || !disabled)
|
||||
flags |= LIST_FLAGS_ENABLED;
|
||||
|
||||
if (disabled || !enabled)
|
||||
flags |= LIST_FLAGS_DISABLED;
|
||||
|
||||
return list_extensions (flags, details ? DISPLAY_DETAILED
|
||||
: DISPLAY_ONELINE) ? 0 : 2;
|
||||
}
|
||||
|
@ -24,9 +24,33 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
TYPE_SYSTEM = 1,
|
||||
TYPE_USER
|
||||
} ExtensionType;
|
||||
|
||||
typedef enum {
|
||||
STATE_ENABLED = 1,
|
||||
STATE_DISABLED,
|
||||
STATE_ERROR,
|
||||
STATE_OUT_OF_DATE,
|
||||
STATE_DOWNLOADING,
|
||||
STATE_INITIALIZED,
|
||||
|
||||
STATE_UNINSTALLED = 99
|
||||
} ExtensionState;
|
||||
|
||||
typedef enum {
|
||||
DISPLAY_ONELINE,
|
||||
DISPLAY_DETAILED
|
||||
} DisplayFormat;
|
||||
|
||||
void show_help (GOptionContext *context,
|
||||
const char *message);
|
||||
|
||||
void print_extension_info (GVariantDict *info,
|
||||
DisplayFormat format);
|
||||
|
||||
GDBusProxy *get_shell_proxy (GError **error);
|
||||
GSettings *get_shell_settings (void);
|
||||
|
||||
|
@ -26,6 +26,29 @@
|
||||
#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)
|
||||
{
|
||||
@ -68,6 +91,41 @@ get_shell_settings (void)
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user