d790249dafbf7683ed92df5cedfa05dd568800dc
[platform/upstream/glib.git] / gio / tests / apps.c
1 #include <gio/gio.h>
2 #include <gio/gdesktopappinfo.h>
3 #include <locale.h>
4
5 static void
6 print (const gchar *str)
7 {
8   g_print ("%s\n", str ? str : "nil");
9 }
10
11 int
12 main (int argc, char **argv)
13 {
14   setlocale (LC_ALL, "");
15
16   if (argv[1] == NULL)
17     ;
18   else if (g_str_equal (argv[1], "list"))
19     {
20       GList *all, *i;
21
22       all = g_app_info_get_all ();
23       for (i = all; i; i = i->next)
24         g_print ("%s%s", g_app_info_get_id (i->data), i->next ? " " : "\n");
25       g_list_free_full (all, g_object_unref);
26     }
27   else if (g_str_equal (argv[1], "search"))
28     {
29       gchar ***results;
30       gint i, j;
31
32       results = g_desktop_app_info_search (argv[2]);
33       for (i = 0; results[i]; i++)
34         {
35           for (j = 0; results[i][j]; j++)
36             g_print ("%s%s", j ? " " : "", results[i][j]);
37           g_print ("\n");
38           g_strfreev (results[i]);
39         }
40       g_free (results);
41     }
42   else if (g_str_equal (argv[1], "show-info"))
43     {
44       GAppInfo *info;
45
46       info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
47       if (info)
48         {
49           print (g_app_info_get_id (info));
50           print (g_app_info_get_name (info));
51           print (g_app_info_get_display_name (info));
52           print (g_app_info_get_description (info));
53           g_object_unref (info);
54         }
55     }
56
57   return 0;
58 }