1 | #include <gio/gio.h> |
2 | #include <gio/gdesktopappinfo.h> |
3 | #include <locale.h> |
4 | #include <stdlib.h> |
5 | |
6 | static void |
7 | print (const gchar *str) |
8 | { |
9 | g_print (format: "%s\n" , str ? str : "nil" ); |
10 | } |
11 | |
12 | static void |
13 | print_app_list (GList *list) |
14 | { |
15 | while (list) |
16 | { |
17 | GAppInfo *info = list->data; |
18 | print (str: g_app_info_get_id (appinfo: info)); |
19 | list = g_list_delete_link (list, link_: list); |
20 | g_object_unref (object: info); |
21 | } |
22 | } |
23 | |
24 | static void |
25 | quit (gpointer user_data) |
26 | { |
27 | g_print (format: "appinfo database changed.\n" ); |
28 | exit (status: 0); |
29 | } |
30 | |
31 | int |
32 | main (int argc, char **argv) |
33 | { |
34 | setlocale (LC_ALL, locale: "" ); |
35 | |
36 | if (argv[1] == NULL) |
37 | ; |
38 | else if (g_str_equal (v1: argv[1], v2: "list" )) |
39 | { |
40 | GList *all, *i; |
41 | |
42 | all = g_app_info_get_all (); |
43 | for (i = all; i; i = i->next) |
44 | g_print (format: "%s%s" , g_app_info_get_id (appinfo: i->data), i->next ? " " : "\n" ); |
45 | g_list_free_full (list: all, free_func: g_object_unref); |
46 | } |
47 | else if (g_str_equal (v1: argv[1], v2: "search" )) |
48 | { |
49 | gchar ***results; |
50 | gint i, j; |
51 | |
52 | results = g_desktop_app_info_search (search_string: argv[2]); |
53 | for (i = 0; results[i]; i++) |
54 | { |
55 | for (j = 0; results[i][j]; j++) |
56 | g_print (format: "%s%s" , j ? " " : "" , results[i][j]); |
57 | g_print (format: "\n" ); |
58 | g_strfreev (str_array: results[i]); |
59 | } |
60 | g_free (mem: results); |
61 | } |
62 | else if (g_str_equal (v1: argv[1], v2: "implementations" )) |
63 | { |
64 | GList *results; |
65 | |
66 | results = g_desktop_app_info_get_implementations (interface: argv[2]); |
67 | print_app_list (list: results); |
68 | } |
69 | else if (g_str_equal (v1: argv[1], v2: "show-info" )) |
70 | { |
71 | GAppInfo *info; |
72 | |
73 | info = (GAppInfo *) g_desktop_app_info_new (desktop_id: argv[2]); |
74 | if (info) |
75 | { |
76 | print (str: g_app_info_get_id (appinfo: info)); |
77 | print (str: g_app_info_get_name (appinfo: info)); |
78 | print (str: g_app_info_get_display_name (appinfo: info)); |
79 | print (str: g_app_info_get_description (appinfo: info)); |
80 | g_object_unref (object: info); |
81 | } |
82 | } |
83 | else if (g_str_equal (v1: argv[1], v2: "default-for-type" )) |
84 | { |
85 | GAppInfo *info; |
86 | |
87 | info = g_app_info_get_default_for_type (content_type: argv[2], FALSE); |
88 | |
89 | if (info) |
90 | { |
91 | print (str: g_app_info_get_id (appinfo: info)); |
92 | g_object_unref (object: info); |
93 | } |
94 | } |
95 | else if (g_str_equal (v1: argv[1], v2: "recommended-for-type" )) |
96 | { |
97 | GList *list; |
98 | |
99 | list = g_app_info_get_recommended_for_type (content_type: argv[2]); |
100 | print_app_list (list); |
101 | } |
102 | else if (g_str_equal (v1: argv[1], v2: "all-for-type" )) |
103 | { |
104 | GList *list; |
105 | |
106 | list = g_app_info_get_all_for_type (content_type: argv[2]); |
107 | print_app_list (list); |
108 | } |
109 | |
110 | else if (g_str_equal (v1: argv[1], v2: "fallback-for-type" )) |
111 | { |
112 | GList *list; |
113 | |
114 | list = g_app_info_get_fallback_for_type (content_type: argv[2]); |
115 | print_app_list (list); |
116 | } |
117 | |
118 | else if (g_str_equal (v1: argv[1], v2: "should-show" )) |
119 | { |
120 | GAppInfo *info; |
121 | |
122 | info = (GAppInfo *) g_desktop_app_info_new (desktop_id: argv[2]); |
123 | if (info) |
124 | { |
125 | g_print (format: "%s\n" , g_app_info_should_show (appinfo: info) ? "true" : "false" ); |
126 | g_object_unref (object: info); |
127 | } |
128 | } |
129 | |
130 | else if (g_str_equal (v1: argv[1], v2: "monitor" )) |
131 | { |
132 | GAppInfoMonitor *monitor; |
133 | GAppInfo *info; |
134 | |
135 | monitor = g_app_info_monitor_get (); |
136 | |
137 | info = (GAppInfo *) g_desktop_app_info_new (desktop_id: "this-desktop-file-does-not-exist" ); |
138 | g_assert (!info); |
139 | |
140 | g_signal_connect (monitor, "changed" , G_CALLBACK (quit), NULL); |
141 | |
142 | while (1) |
143 | g_main_context_iteration (NULL, TRUE); |
144 | } |
145 | |
146 | return 0; |
147 | } |
148 | |