2018-08-27 03:34:27 +00:00
|
|
|
/* command-list.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 <glib/gi18n.h>
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
|
|
#include "commands.h"
|
|
|
|
#include "common.h"
|
2018-08-27 04:16:54 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LIST_FLAGS_NONE = 0,
|
|
|
|
LIST_FLAGS_USER = 1 << 0,
|
|
|
|
LIST_FLAGS_SYSTEM = 1 << 1,
|
|
|
|
LIST_FLAGS_ENABLED = 1 << 2,
|
2019-01-11 11:18:14 +00:00
|
|
|
LIST_FLAGS_DISABLED = 1 << 3,
|
2019-11-30 18:52:42 +00:00
|
|
|
LIST_FLAGS_NO_PREFS = 1 << 4,
|
|
|
|
LIST_FLAGS_NO_UPDATES = 1 << 5,
|
2018-08-27 04:16:54 +00:00
|
|
|
} ListFilterFlags;
|
2018-08-27 03:34:27 +00:00
|
|
|
|
|
|
|
static gboolean
|
2018-08-27 04:16:54 +00:00
|
|
|
list_extensions (ListFilterFlags filter, DisplayFormat format)
|
2018-08-27 03:34:27 +00:00
|
|
|
{
|
|
|
|
g_autoptr (GDBusProxy) proxy = NULL;
|
|
|
|
g_autoptr (GVariant) response = NULL;
|
|
|
|
g_autoptr (GVariant) extensions = NULL;
|
|
|
|
g_autoptr (GError) error = NULL;
|
2018-08-27 04:16:54 +00:00
|
|
|
gboolean needs_newline = FALSE;
|
2018-08-27 03:34:27 +00:00
|
|
|
GVariantIter iter;
|
|
|
|
GVariant *value;
|
|
|
|
char *uuid;
|
|
|
|
|
|
|
|
proxy = get_shell_proxy (&error);
|
|
|
|
if (proxy == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
response = g_dbus_proxy_call_sync (proxy,
|
|
|
|
"ListExtensions",
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
&error);
|
|
|
|
if (response == NULL)
|
2020-03-14 10:00:49 +00:00
|
|
|
{
|
|
|
|
g_printerr (_("Failed to connect to GNOME Shell\n"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-08-27 03:34:27 +00:00
|
|
|
|
|
|
|
extensions = g_variant_get_child_value (response, 0);
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, extensions);
|
|
|
|
while (g_variant_iter_loop (&iter, "{s@a{sv}}", &uuid, &value))
|
2018-08-27 04:16:54 +00:00
|
|
|
{
|
|
|
|
g_autoptr (GVariantDict) info = NULL;
|
|
|
|
double type, state;
|
2019-01-11 11:18:14 +00:00
|
|
|
gboolean has_prefs;
|
2019-11-30 18:52:42 +00:00
|
|
|
gboolean has_update;
|
2018-08-27 04:16:54 +00:00
|
|
|
|
|
|
|
info = g_variant_dict_new (value);
|
|
|
|
g_variant_dict_lookup (info, "type", "d", &type);
|
|
|
|
g_variant_dict_lookup (info, "state", "d", &state);
|
2019-01-11 11:18:14 +00:00
|
|
|
g_variant_dict_lookup (info, "hasPrefs", "b", &has_prefs);
|
2019-11-30 18:52:42 +00:00
|
|
|
g_variant_dict_lookup (info, "hasUpdate", "b", &has_update);
|
2018-08-27 04:16:54 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-01-11 11:18:14 +00:00
|
|
|
if (!has_prefs && (filter & LIST_FLAGS_NO_PREFS) == 0)
|
|
|
|
continue;
|
|
|
|
|
2019-11-30 18:52:42 +00:00
|
|
|
if (!has_update && (filter & LIST_FLAGS_NO_UPDATES) == 0)
|
|
|
|
continue;
|
|
|
|
|
2018-08-27 04:16:54 +00:00
|
|
|
if (needs_newline)
|
|
|
|
g_print ("\n");
|
|
|
|
|
|
|
|
print_extension_info (info, format);
|
|
|
|
needs_newline = (format != DISPLAY_ONELINE);
|
|
|
|
}
|
2018-08-27 03:34:27 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
handle_list (int argc, char *argv[], gboolean do_help)
|
|
|
|
{
|
|
|
|
g_autoptr (GOptionContext) context = NULL;
|
|
|
|
g_autoptr (GError) error = NULL;
|
2018-08-27 04:16:54 +00:00
|
|
|
int flags = LIST_FLAGS_NONE;
|
|
|
|
gboolean details = FALSE;
|
|
|
|
gboolean user = FALSE;
|
|
|
|
gboolean system = FALSE;
|
|
|
|
gboolean enabled = FALSE;
|
|
|
|
gboolean disabled = FALSE;
|
2019-01-11 11:18:14 +00:00
|
|
|
gboolean has_prefs = FALSE;
|
2019-11-30 18:52:42 +00:00
|
|
|
gboolean has_updates = FALSE;
|
2018-08-27 04:16:54 +00:00
|
|
|
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") },
|
2019-01-11 11:18:14 +00:00
|
|
|
{ .long_name = "prefs",
|
|
|
|
.arg = G_OPTION_ARG_NONE, .arg_data = &has_prefs,
|
|
|
|
.description = _("Show extensions with preferences") },
|
2019-11-30 18:52:42 +00:00
|
|
|
{ .long_name = "updates",
|
|
|
|
.arg = G_OPTION_ARG_NONE, .arg_data = &has_updates,
|
|
|
|
.description = _("Show extensions with updates") },
|
2018-08-27 04:16:54 +00:00
|
|
|
{ .long_name = "details", .short_name = 'd',
|
|
|
|
.arg = G_OPTION_ARG_NONE, .arg_data = &details,
|
|
|
|
.description = _("Print extension details") },
|
|
|
|
{ NULL }
|
|
|
|
};
|
2018-08-27 03:34:27 +00:00
|
|
|
|
|
|
|
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"));
|
2018-08-27 04:16:54 +00:00
|
|
|
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
2020-03-14 11:58:04 +00:00
|
|
|
g_option_context_add_group (context, get_option_group());
|
2018-08-27 03:34:27 +00:00
|
|
|
|
|
|
|
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 (argc > 1)
|
|
|
|
{
|
|
|
|
show_help (context, _("Unknown arguments"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-27 04:16:54 +00:00
|
|
|
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;
|
|
|
|
|
2019-01-11 11:18:14 +00:00
|
|
|
if (!has_prefs)
|
|
|
|
flags |= LIST_FLAGS_NO_PREFS;
|
|
|
|
|
2019-11-30 18:52:42 +00:00
|
|
|
if (!has_updates)
|
|
|
|
flags |= LIST_FLAGS_NO_UPDATES;
|
|
|
|
|
2018-08-27 04:16:54 +00:00
|
|
|
return list_extensions (flags, details ? DISPLAY_DETAILED
|
|
|
|
: DISPLAY_ONELINE) ? 0 : 2;
|
2018-08-27 03:34:27 +00:00
|
|
|
}
|