[Lunar-commits] <lconnman> lconnman: first gui!

Samuel Verstraete samuel.verstraete at gmail.com
Sat Aug 20 08:18:23 CEST 2011


commit 8a0ff9387bcca58a0de02ea99111cac10df08c96
Author: Samuel Verstraete <samuel.verstraete at gmail.com>
Date:   Sat Aug 20 08:18:23 2011 +0200

    lconnman: first gui!
---
 Makefile                   |   18 ++++++++
 src/Makefile               |   27 ++++++++++++
 src/connmanmanager.vala    |   21 +---------
 src/gui/choice_window.vala |   96 ++++++++++++++++++++++++++++++++++++++++++++
 src/lconnman.vala          |   42 +++++++++++++++++++
 5 files changed, 184 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..555cfd4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,18 @@
+PREFIX?=/usr
+DESTDIR=
+PFX=${DESTDIR}/${PREFIX}
+
+all:
+	cd src && ${MAKE} all
+
+clean:
+	cd src && ${MAKE} clean
+
+dist: clean
+	cd src && ${MAKE} c
+	cd .. && tar czvf racu.tar.gz racu
+	cd .. && scp racu.tar.gz pancake at radare.org:/srv/http/lolcathostorg/b
+
+install:
+	mkdir -p ${PFX}/bin
+	cp src/racu ${PFX}/bin
diff --git a/src/Makefile b/src/Makefile
new file mode 100644
index 0000000..81d728e
--- /dev/null
+++ b/src/Makefile
@@ -0,0 +1,27 @@
+VALAFILES=connmanmanager.vala lconnman.vala
+VALAFILES+=gui/choice_window.vala
+#PFX=/home/pancake/prg/racu/tmp
+#CFLAGS=-I${PFX}/include/ncurses
+LDFLAGS=-Wl -ldl -lncurses
+LDFLAGS_PKGCONFIG=`pkg-config gobject-2.0 --cflags --libs`
+
+VALAPKGS=--vapidir .
+VALAPKGS+=--pkg curses --pkg gio-2.0
+
+BIN=lconnman
+
+all:
+	valac -g -o ${BIN} ${VALAFILES} ${VALAPKGS} -X -lncurses
+
+vapi:
+	valac --vapi lconnman.vapi --library=lconnman ${VALAFILES} ${VALAPKGS} -X -lncurses
+
+c:
+	valac -C ${VALAFILES} ${VALAPKGS} -X -lncurses
+	mv w/file.c w/file.vala.c
+
+allc:
+	gcc -g ${CFLAGS} ${LDFLAGS_PKGCONFIG} ${LDFLAGS} -o ${BIN} w/*.c *.c -I. 
+
+clean:
+	rm -f w/*.c *.c main a.out ${BIN}
diff --git a/src/connmanmanager.vala b/src/connmanmanager.vala
index 8c27d23..b4ba39b 100644
--- a/src/connmanmanager.vala
+++ b/src/connmanmanager.vala
@@ -21,25 +21,6 @@ public class ConnmanManager {
     }
   }
 
-//void main () {
-
-//  try {
-//    connmanManager = Bus.get_proxy_sync (BusType.SYSTEM, "net.connman", "/");
-//    stdout.printf( "System state:\n" );
-//    string state = get_state();
-//    stdout.printf(state +"\n");
-//  } catch (IOError e) {
-//    stderr.printf (e.message +"\n");
-//  }
-//  stdout.printf( "Available Services:\n");
-//  foreach (Service service in get_services()) {
-//    stdout.printf(print_service(service));
-//  }
-//  stdout.printf( "System Properties:\n");
-//  GLib.HashTable<string,Variant> systemProperties = get_properties();
-//  stdout.printf( print_system_properties(systemProperties) );
-//}
-
   public string get_state() {
     try {
       return connmanManager.get_state();
@@ -67,7 +48,7 @@ public class ConnmanManager {
     }
   }
 
-  private string print_service(Service service) {
+  public string print_service(Service service) {
     StringBuilder result = new StringBuilder();
     result.append("ServicePath: " + service.ServicePath.to_string() + "\n");
 
diff --git a/src/gui/choice_window.vala b/src/gui/choice_window.vala
new file mode 100644
index 0000000..03a5d73
--- /dev/null
+++ b/src/gui/choice_window.vala
@@ -0,0 +1,96 @@
+using Curses;
+
+public class ChoiceWindow {
+  //construction information
+  private int Width;
+  private int Height;
+  private string[] Choices;
+
+  //internal affairs
+  private int highlight = 1;
+  private int choice = 0;
+  private int c;
+  private Window window;
+
+
+  public ChoiceWindow(string[] choices, int width, int height) {
+    this.Width = width;
+    this.Height = height;
+    this.Choices = choices;
+
+    //initscr();
+
+    //start_color();
+    //init_pair((short)1, Color.WHITE, Color.BLUE);
+
+    //clear();
+    //noecho();
+    //cbreak();
+
+    //put the window in the middle of the screen;
+    int startx = (80 - Width) / 2;
+    int starty = (24 - Height) / 2;
+
+    this.window = new Window (Height, Width, starty, startx);
+    this.window.bkgdset (COLOR_PAIR(1));
+    this.window.keypad (true); //enable the up and down movement;
+    this.window.box(0,0);
+
+    //this will not work, need to figure out a way, maybe create a new window?
+    //mvprintw(0,0, "Use arrow keys to go up and down, Press enter to select a choice");
+
+    this.window.refresh();
+
+    this.print_choice_menu();
+
+    while(true){
+      c = this.window.getch();
+      switch(c) {
+        case Key.UP:
+          if (this.highlight == 1){
+            this.highlight = this.Choices.length;
+          } else {
+            --this.highlight;
+          }
+          break;
+        case Key.DOWN:
+          if (this.highlight == this.Choices.length) {
+            this.highlight = 1;
+          } else {
+            ++this.highlight;
+          }
+          break;
+        case 10:
+          this.choice = this.highlight;
+          break;
+        default:
+          //this will not work
+          //mvprintw (24, 0, "Character pressed is not valid");
+          refresh();
+          break;
+      }
+      this.print_choice_menu();
+      if (this.choice != 0)
+        break;
+    }
+    this.window.clrtoeol();
+    refresh();
+  }
+
+  private void print_choice_menu() {
+    int x,y,i;
+
+    x = 2;
+    y = 2;
+    for (i = 0; i < this.Choices.length; i++) {
+      if (this.highlight == i + 1) { //if this is the currently highlighted item, inverse colors;
+        this.window.attron(Attribute.REVERSE);
+        this.window.mvprintw(y, x, "%s", this.Choices[i]);
+        this.window.attroff(Attribute.REVERSE);
+      } else {
+        this.window.mvprintw(y, x, "%s", this.Choices[i]);
+      }
+      y++;
+    }
+  }
+}
diff --git a/src/lconnman.vala b/src/lconnman.vala
new file mode 100644
index 0000000..d78e1af
--- /dev/null
+++ b/src/lconnman.vala
@@ -0,0 +1,42 @@
+using Curses;
+
+int main() {
+  initscr();
+  noecho();
+  cbreak();
+  curs_set(0);
+
+  start_color();
+  init_pair((short)1, Color.WHITE, Color.BLUE);
+
+  string[] services =  get_services();
+  ChoiceWindow cw = new ChoiceWindow(services, 60, 10);
+
+  endwin();
+  foreach (var service in services) {
+    stdout.printf(service +"\n");
+  }
+
+  return 0;
+}
+
+private static string[] get_services(){
+  ConnmanManager manager = new ConnmanManager();
+  Service[] services = manager.get_services();
+  string[] str_services = new string[services.length + 1];
+  int number_services = 0;
+
+  for( int i = 0; i < services.length; i++ ) {
+    string orig_key;
+    GLib.Variant service_type;
+    GLib.Variant service_name;
+    services[i].ServiceProperties.lookup_extended("Type", out orig_key, out service_type);
+    services[i].ServiceProperties.lookup_extended("Name", out orig_key, out service_name);
+
+    str_services[i] = service_type.print(false) + "." + service_name.print(false);
+  }
+
+  str_services[services.length] = "Exit";
+
+  return str_services;
+}


More information about the Lunar-commits mailing list