7 #include <gtk/gtkmain.h>
8 #include <gtk/gtkdialog.h>
9 #include <gtk/gtkstock.h>
12 #include "launcher-item.h"
14 static std::string appdir = "/usr/share/applications";
16 int main(int argc, char *argv[]) {
17 gtk_init(&argc, &argv);
19 DIR *handle = opendir(appdir.c_str());
22 std::map<std::string, LauncherItem *> apps;
28 while ((entry = readdir(handle)) != 0) {
29 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
33 LauncherItem *item = new LauncherItem();
35 if (item->load(appdir + "/" + entry->d_name)) {
36 std::cout << "Loaded " << entry->d_name << std::endl;
38 apps[entry->d_name] = item;
40 sla_list.addItem(entry->d_name, item->getIcon(26), item->getName().c_str(), false);
42 std::cout << "Failed to load " << entry->d_name << std::endl;
49 GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new_with_buttons("My dialog", 0, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, 0));
51 gtk_container_add(GTK_CONTAINER(dialog->vbox), sla_list.getWidget());
53 if (gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT) {
54 // print sla_list.items()
55 std::vector<std::pair<std::string, bool> > items;
57 sla_list.collectItems(items);
59 for (std::vector<std::pair<std::string, bool> >::const_iterator it = items.begin(); it != items.end(); ++it) {
60 std::cout << it->first << (it->second ? " active" : " passive") << std::endl;
64 gtk_widget_destroy(GTK_WIDGET(dialog));
67 std::cerr << "Cannot list applications directory" << std::endl;