1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include <locale.h>
static void
print (const gchar *str)
{
g_print ("%s\n", str ? str : "nil");
}
static void
print_app_list (GList *list)
{
while (list)
{
GAppInfo *info = list->data;
print (g_app_info_get_id (info));
list = g_list_delete_link (list, list);
g_object_unref (info);
}
}
int
main (int argc, char **argv)
{
setlocale (LC_ALL, "");
if (argv[1] == NULL)
;
else if (g_str_equal (argv[1], "list"))
{
GList *all, *i;
all = g_app_info_get_all ();
for (i = all; i; i = i->next)
g_print ("%s%s", g_app_info_get_id (i->data), i->next ? " " : "\n");
g_list_free_full (all, g_object_unref);
}
else if (g_str_equal (argv[1], "search"))
{
gchar ***results;
gint i, j;
results = g_desktop_app_info_search (argv[2]);
for (i = 0; results[i]; i++)
{
for (j = 0; results[i][j]; j++)
g_print ("%s%s", j ? " " : "", results[i][j]);
g_print ("\n");
g_strfreev (results[i]);
}
g_free (results);
}
else if (g_str_equal (argv[1], "show-info"))
{
GAppInfo *info;
info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
if (info)
{
print (g_app_info_get_id (info));
print (g_app_info_get_name (info));
print (g_app_info_get_display_name (info));
print (g_app_info_get_description (info));
g_object_unref (info);
}
}
else if (g_str_equal (argv[1], "default-for-type"))
{
GAppInfo *info;
info = g_app_info_get_default_for_type (argv[2], FALSE);
if (info)
{
print (g_app_info_get_id (info));
g_object_unref (info);
}
}
else if (g_str_equal (argv[1], "recommended-for-type"))
{
GList *list;
list = g_app_info_get_recommended_for_type (argv[2]);
print_app_list (list);
}
else if (g_str_equal (argv[1], "all-for-type"))
{
GList *list;
list = g_app_info_get_all_for_type (argv[2]);
print_app_list (list);
}
else if (g_str_equal (argv[1], "fallback-for-type"))
{
GList *list;
list = g_app_info_get_fallback_for_type (argv[2]);
print_app_list (list);
}
return 0;
}
|