[Lunar-commits] <lconnman> lconnman.
Samuel Verstraete
samuel.verstraete at gmail.com
Sun Oct 16 22:42:14 CEST 2011
commit c47a11b413f70fc4ce35aee41ef3b6a39695ed9b
Author: Samuel Verstraete <samuel.verstraete at gmail.com>
Date: Sun Oct 16 22:42:14 2011 +0200
lconnman.
---
src/Makefile | 2 +-
src/connmanmanager.vala | 21 +++++++++++++++------
src/gui/curseslist.vala | 6 ++++++
src/lconnman.vala | 35 +++++++++++++++++++++++------------
4 files changed, 45 insertions(+), 19 deletions(-)
diff --git a/src/Makefile b/src/Makefile
index 7e705da..419a747 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,4 +1,4 @@
-VALAFILES=connmanmanager.vala lconnman.vala
+VALAFILES=service.vala connmanmanager.vala lconnman.vala
VALAFILES+=gui/curseslist.vala gui/enums.vala
#PFX=/home/pancake/prg/racu/tmp
#CFLAGS=-I${PFX}/include/ncurses
diff --git a/src/connmanmanager.vala b/src/connmanmanager.vala
index b4ba39b..e3e006d 100644
--- a/src/connmanmanager.vala
+++ b/src/connmanmanager.vala
@@ -1,11 +1,11 @@
[DBus (name = "net.connman.Manager")]
interface IConnmanManager : Object {
public abstract string get_state() throws IOError;
- public abstract Service[] get_services() throws IOError;
+ public abstract dbusService[] get_services() throws IOError;
public abstract GLib.HashTable<string, Variant> get_properties() throws IOError;
}
-public struct Service {
+public struct dbusService {
public GLib.ObjectPath ServicePath;
public GLib.HashTable<string, Variant> ServiceProperties;
}
@@ -30,15 +30,24 @@ public class ConnmanManager {
}
}
- public Service[] get_services() {
+ public dbusService[] get_services() {
try {
return connmanManager.get_services();
} catch (IOError e) {
stderr.printf (e.message + "\n");
- return new Service[0];
+ return new dbusService[0];
}
}
+ public Service[] get_r_services() {
+ dbusService[] dservices = this.get_services();
+ Service[] services = new Service[dservices.length];
+ for (int i = 0; i < dservices.length; i++){
+ services[i] = new Service(dservices[i]);
+ }
+ return services;
+ }
+
public GLib.HashTable<string, Variant> get_properties() {
try {
return connmanManager.get_properties();
@@ -48,7 +57,7 @@ public class ConnmanManager {
}
}
- public string print_service(Service service) {
+ /*public string print_service(dbusService service) {
StringBuilder result = new StringBuilder();
result.append("ServicePath: " + service.ServicePath.to_string() + "\n");
@@ -70,5 +79,5 @@ public class ConnmanManager {
result.append(hash_key.to_string() + " : " + hash_value.print(false) + "\n" );
}
return result.str;
- }
+ }*/
}
diff --git a/src/gui/curseslist.vala b/src/gui/curseslist.vala
index 360250a..ada1d73 100644
--- a/src/gui/curseslist.vala
+++ b/src/gui/curseslist.vala
@@ -49,6 +49,12 @@ public class CursesList {
this.print_choice_menu();
}
+ //refresh
+ public void new_choices(string[] choices){
+ this.Choices = choices;
+ this.print_choice_menu();
+ }
+
public void previous_choice(){
if (this.highlight == 1) {
this.highlight = this.Choices.length;
diff --git a/src/lconnman.vala b/src/lconnman.vala
index fcd39d5..d822eff 100644
--- a/src/lconnman.vala
+++ b/src/lconnman.vala
@@ -8,26 +8,24 @@ int main() {
start_color();
init_pair((short)1, Color.WHITE, Color.BLUE);
init_pair((short)2, Color.WHITE, Color.GREEN);
+ refresh();
//create a window to pull in events, this doesn't seem to work on the stdscr.
var d = new Window(1,1,0,0);
//enable up and down keys
d.keypad(true);
- //print instructions at the bottom of the screen
- mvprintw(LINES-1,1,"%s", "Push the 'q' key to quit");
- refresh();
-
- string[] services = get_services();
+ string[] services = get_r_services();
CursesList cw = new CursesList(services, Orientation.Vertical, Alignment.Top, COLS, LINES - 4);
- string[] buttons = new string[3];
+ string[] buttons = new string[4];
buttons[0] = "configure";
buttons[1] = "connect";
- buttons[2] = "exit";
+ buttons[2] = "refresh";
+ buttons[3] = "exit";
CursesList buttonBox = new CursesList(buttons, Orientation.Horizontal, Alignment.Bottom, COLS, 5);
string action = "";
int c;
- while(action != "quit"){
+ while(action != "quit" && action != "exit"){
c = d.getch();
switch(c) {
case Key.UP:
@@ -46,8 +44,10 @@ int main() {
action = "quit";
break;
case 10: //Key.ENTER
- if (buttonBox.get_selected_choice() == "exit") {
- action = "quit";
+ action = buttonBox.get_selected_choice();
+ if (action == "refresh") {
+ services = get_r_services();
+ cw.new_choices(services);
}
break;
default:
@@ -60,9 +60,8 @@ int main() {
private static string[] get_services(){
ConnmanManager manager = new ConnmanManager();
- Service[] services = manager.get_services();
+ dbusService[] services = manager.get_services();
string[] str_services = new string[services.length];
- int number_services = 0;
for( int i = 0; i < services.length; i++ ) {
string orig_key;
@@ -76,3 +75,15 @@ private static string[] get_services(){
return str_services;
}
+public static string[] get_r_services() {
+ ConnmanManager manager = new ConnmanManager();
+ Service[] services = manager.get_r_services();
+ string[] str_services = new string[services.length];
+ for (int i =0; i<services.length; i++){
+ str_services[i] = services[i].Technology + "." + services[i].Name;
+ if (services[i].Favorite){
+ str_services[i] = str_services[i] + " <*>";
+ }
+ }
+ return str_services;
+}
More information about the Lunar-commits
mailing list