2 #include <gio/gdesktopappinfo.h>
7 print (const gchar
*str
)
9 g_print ("%s\n", str
? str
: "nil");
13 print_app_list (GList
*list
)
17 GAppInfo
*info
= list
->data
;
18 print (g_app_info_get_id (info
));
19 list
= g_list_delete_link (list
, list
);
20 g_object_unref (info
);
25 quit (gpointer user_data
)
27 g_print ("appinfo database changed.\n");
32 main (int argc
, char **argv
)
34 setlocale (LC_ALL
, "");
38 else if (g_str_equal (argv
[1], "list"))
42 all
= g_app_info_get_all ();
43 for (i
= all
; i
; i
= i
->next
)
44 g_print ("%s%s", g_app_info_get_id (i
->data
), i
->next
? " " : "\n");
45 g_list_free_full (all
, g_object_unref
);
47 else if (g_str_equal (argv
[1], "search"))
52 results
= g_desktop_app_info_search (argv
[2]);
53 for (i
= 0; results
[i
]; i
++)
55 for (j
= 0; results
[i
][j
]; j
++)
56 g_print ("%s%s", j
? " " : "", results
[i
][j
]);
58 g_strfreev (results
[i
]);
62 else if (g_str_equal (argv
[1], "implementations"))
66 results
= g_desktop_app_info_get_implementations (argv
[2]);
67 print_app_list (results
);
69 else if (g_str_equal (argv
[1], "show-info"))
73 info
= (GAppInfo
*) g_desktop_app_info_new (argv
[2]);
76 print (g_app_info_get_id (info
));
77 print (g_app_info_get_name (info
));
78 print (g_app_info_get_display_name (info
));
79 print (g_app_info_get_description (info
));
80 g_object_unref (info
);
83 else if (g_str_equal (argv
[1], "default-for-type"))
87 info
= g_app_info_get_default_for_type (argv
[2], FALSE
);
91 print (g_app_info_get_id (info
));
92 g_object_unref (info
);
95 else if (g_str_equal (argv
[1], "recommended-for-type"))
99 list
= g_app_info_get_recommended_for_type (argv
[2]);
100 print_app_list (list
);
102 else if (g_str_equal (argv
[1], "all-for-type"))
106 list
= g_app_info_get_all_for_type (argv
[2]);
107 print_app_list (list
);
110 else if (g_str_equal (argv
[1], "fallback-for-type"))
114 list
= g_app_info_get_fallback_for_type (argv
[2]);
115 print_app_list (list
);
118 else if (g_str_equal (argv
[1], "should-show"))
122 info
= (GAppInfo
*) g_desktop_app_info_new (argv
[2]);
125 g_print ("%s\n", g_app_info_should_show (info
) ? "true" : "false");
126 g_object_unref (info
);
130 else if (g_str_equal (argv
[1], "monitor"))
132 GAppInfoMonitor
*monitor
;
135 monitor
= g_app_info_monitor_get ();
137 info
= (GAppInfo
*) g_desktop_app_info_new ("this-desktop-file-does-not-exist");
140 g_signal_connect (monitor
, "changed", G_CALLBACK (quit
), NULL
);
143 g_main_context_iteration (NULL
, TRUE
);