a simple test program for applet configuration stuff
authormishas <mikhail.sobolev@gmail.com>
Wed, 13 Dec 2006 22:08:02 +0000 (22:08 +0000)
committermishas <mikhail.sobolev@gmail.com>
Wed, 13 Dec 2006 22:08:02 +0000 (22:08 +0000)
git-svn-id: file:///svnroot/simple-launcher/trunk@55 3ba93dab-e023-0410-b42a-de7732cf370a

Makefile
test1.cc [new file with mode: 0644]

index cf18254..c5e0a35 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ GTKLIBS := $(shell pkg-config gtk+-2.0 --libs)
 DBUSCFLAGS := $(shell pkg-config dbus-1 --cflags)
 DBUSLIBS := $(shell pkg-config dbus-1 --libs)
 
-CXXFLAGS=-Wall -MMD $(GTKCFLAGS) $(DBUSCFLAGS)
+CXXFLAGS=-Wall -g -MMD $(GTKCFLAGS) $(DBUSCFLAGS)
 #LDFLAGS = -module -avoid-version
 LDFLAGS = -shared
 LIBS = -lstdc++
@@ -13,11 +13,16 @@ TARGET=simple-launcher.so
 
 all: $(TARGET)
 
+tests: test test1
+
 $(TARGET): simple-launcher.o launcher-item.o sla-list.o
        $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
 
 test: test.o launcher-item.o
-       g++ -o $@ $^ $(GTKLIBS) $(DBUSLIBS)  $(LIBS) -losso
+       g++ -o $@ $^ $(GTKLIBS) $(DBUSLIBS) $(LIBS) -losso
+
+test1: test1.o sla-list.o launcher-item.o
+       g++ -g -o $@ $^ $(GTKLIBS) $(DBUSLIBS) $(LIBS)
 
 clean:
        rm -f *.d *.o $(TARGET) test
diff --git a/test1.cc b/test1.cc
new file mode 100644 (file)
index 0000000..c840352
--- /dev/null
+++ b/test1.cc
@@ -0,0 +1,71 @@
+#include <iostream>
+#include <map>
+
+#include <string.h>
+#include <dirent.h>
+
+#include <gtk/gtkmain.h>
+#include <gtk/gtkdialog.h>
+#include <gtk/gtkstock.h>
+
+#include "sla-list.h"
+#include "launcher-item.h"
+
+static std::string appdir = "/usr/share/applications";
+
+int main(int argc, char *argv[]) {
+  gtk_init(&argc, &argv);
+
+  DIR *handle = opendir(appdir.c_str());
+
+  if (handle != 0) {
+    std::map<std::string, LauncherItem *> apps;
+
+    SLAList sla_list(26);
+
+    struct dirent *entry;
+
+    while ((entry = readdir(handle)) != 0) {
+      if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
+        continue;
+      }
+
+      LauncherItem *item = new LauncherItem();
+
+      if (item->load(appdir + "/" + entry->d_name)) {
+        std::cout << "Loaded " << entry->d_name << std::endl;
+
+        apps[entry->d_name] = item;
+
+        sla_list.addItem(entry->d_name, item->getIcon(26), item->getName().c_str(), false);
+      } else {
+        std::cout << "Failed to load " << entry->d_name << std::endl;
+
+        delete item;
+      }
+    }
+
+    if (!apps.empty()) {
+      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));
+
+      gtk_container_add(GTK_CONTAINER(dialog->vbox), sla_list.getWidget());
+
+      if (gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT) {
+        // print sla_list.items()
+        std::vector<std::pair<std::string, bool> > items;
+        
+        sla_list.collectItems(items);
+
+        for (std::vector<std::pair<std::string, bool> >::const_iterator it = items.begin(); it != items.end(); ++it) {
+          std::cout << it->first << (it->second ? " active" : " passive") << std::endl;
+        }
+      }
+
+      gtk_widget_destroy(GTK_WIDGET(dialog));
+    }
+  } else {
+    std::cerr << "Cannot list applications directory" << std::endl;
+  }
+
+  return 0;
+}