mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 06:56:14 +01:00
test: improvements for GAppInfo test
· Add a usage output that is printed when called with no argument or with '--help' argument. This is helpful as it avoids having to read the source code to know how to run the different options. · Adds new '--should-show-only' option to 'search' command, to better mimick the gnome-shell app search, by not returning apps with NoDisplay=true. Example for running a desktop app search with the new option from inside the GLib build dir: $ gio/tests/apps search --should-show-only settings
This commit is contained in:
parent
1cd0dfa55b
commit
3c22e2745c
@ -33,8 +33,13 @@ main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
|
|
||||||
if (argv[1] == NULL)
|
if (argv[1] == NULL || g_str_equal (argv[1], "--help"))
|
||||||
;
|
g_print ("Usage:\n apps --help\n apps COMMAND [COMMAND_OPTIONS]\n\nCOMMANDS:\n list\n "
|
||||||
|
"search [--should-show-only] TEXT_TO_SEARCH\n implementations INTERFACE_NAME\n "
|
||||||
|
"show-info DESKTOP_FILE\n default-for-type MIME_TYPE\n recommended-for-type MIME_TYPE\n "
|
||||||
|
"all-for-type MIME_TYPE\n fallback-for-type MIME_TYPE\n should-show DESKTOP_FILE\n "
|
||||||
|
"monitor\n\nExamples:\n apps search --should-show-only ter\n"
|
||||||
|
" apps show-info org.gnome.Nautilus.desktop\n apps default-for-type image/png\n\n");
|
||||||
else if (g_str_equal (argv[1], "list"))
|
else if (g_str_equal (argv[1], "list"))
|
||||||
{
|
{
|
||||||
GList *all, *i;
|
GList *all, *i;
|
||||||
@ -47,13 +52,31 @@ main (int argc, char **argv)
|
|||||||
else if (g_str_equal (argv[1], "search"))
|
else if (g_str_equal (argv[1], "search"))
|
||||||
{
|
{
|
||||||
gchar ***results;
|
gchar ***results;
|
||||||
|
gboolean should_show_only;
|
||||||
gint i, j;
|
gint i, j;
|
||||||
|
|
||||||
results = g_desktop_app_info_search (argv[2]);
|
should_show_only = argc > 3 && g_str_equal (argv[2], "--should-show-only");
|
||||||
|
results = g_desktop_app_info_search (argv[ should_show_only ? 3 : 2 ]);
|
||||||
for (i = 0; results[i]; i++)
|
for (i = 0; results[i]; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; results[i][j]; j++)
|
for (j = 0; results[i][j]; j++)
|
||||||
g_print ("%s%s", j ? " " : "", results[i][j]);
|
{
|
||||||
|
if (should_show_only)
|
||||||
|
{
|
||||||
|
GDesktopAppInfo *info;
|
||||||
|
gboolean should_show;
|
||||||
|
|
||||||
|
info = g_desktop_app_info_new (results[i][j]);
|
||||||
|
if (info)
|
||||||
|
{
|
||||||
|
should_show = g_app_info_should_show (G_APP_INFO (info));
|
||||||
|
g_object_unref (info);
|
||||||
|
if (!should_show)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_print ("%s%s", j ? " " : "", results[i][j]);
|
||||||
|
}
|
||||||
g_print ("\n");
|
g_print ("\n");
|
||||||
g_strfreev (results[i]);
|
g_strfreev (results[i]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user