added [empty] dialog-entry.cc; stubbed dialog-entry.h
[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     LauncherItems apps;
23
24     struct dirent *entry;
25
26     while ((entry = readdir(handle)) != 0) {
27       if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
28         continue;
29       }
30
31       LauncherItem *item = new LauncherItem();
32
33       if (item->load(appdir + "/" + entry->d_name)) {
34         std::cout << "Loaded " << entry->d_name << std::endl;
35       } else {
36         std::cout << "Failed to load " << entry->d_name << std::endl;
37       }
38
39       apps.push_back(std::pair<std::string, LauncherItem *>(entry->d_name, item));
40     }
41
42     if (!apps.empty()) {
43       SLAList sla_list(26, apps);
44
45       GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new_with_buttons("Launcher settings", 0, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, 0));
46
47       gtk_container_add(GTK_CONTAINER(dialog->vbox), sla_list.getWidget());
48
49       if (gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT) {
50         for (LauncherItems::const_iterator it = apps.begin(); it != apps.end(); ++it) {
51           std::cout << it->first << (it->second->isEnabled() ? " active" : " passive") << std::endl;
52         }
53       }
54
55       gtk_widget_destroy(GTK_WIDGET(dialog));
56     }
57   } else {
58     std::cerr << "Cannot list applications directory" << std::endl;
59   }
60
61   return 0;
62 }