[svn-buildpackage] Tagging simple-launcher (0.7)
[simple-launcher] / test1.cc
1 #include <iostream>
2 #include <map>
3
4 #include <string.h>
5 #include <dirent.h>
6
7 #include <gtk/gtkmain.h>
8 #include <gtk/gtkdialog.h>
9 #include <gtk/gtkstock.h>
10
11 #include "sla-list.h"
12 #include "launcher-item.h"
13
14 static std::string appdir = "/usr/share/applications";
15
16 int main(int argc, char *argv[]) {
17   gtk_init(&argc, &argv);
18
19   DIR *handle = opendir(appdir.c_str());
20
21   if (handle != 0) {
22     std::map<std::string, LauncherItem *> apps;
23
24     SLAList sla_list(26);
25
26     struct dirent *entry;
27
28     while ((entry = readdir(handle)) != 0) {
29       if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
30         continue;
31       }
32
33       LauncherItem *item = new LauncherItem();
34
35       if (item->load(appdir + "/" + entry->d_name)) {
36         std::cout << "Loaded " << entry->d_name << std::endl;
37
38         apps[entry->d_name] = item;
39
40         sla_list.addItem(entry->d_name, item->getIcon(26), item->getName().c_str(), false);
41       } else {
42         std::cout << "Failed to load " << entry->d_name << std::endl;
43
44         delete item;
45       }
46     }
47
48     if (!apps.empty()) {
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));
50
51       gtk_container_add(GTK_CONTAINER(dialog->vbox), sla_list.getWidget());
52
53       if (gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT) {
54         // print sla_list.items()
55         std::vector<std::pair<std::string, bool> > items;
56         
57         sla_list.collectItems(items);
58
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;
61         }
62       }
63
64       gtk_widget_destroy(GTK_WIDGET(dialog));
65     }
66   } else {
67     std::cerr << "Cannot list applications directory" << std::endl;
68   }
69
70   return 0;
71 }