From b33ca54964b823da8764710dbee141a548240baf Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Wed, 8 Aug 2012 03:07:35 +0200 Subject: switch from terminal to gtk window --- Makefile | 2 +- db.vala | 21 +- device.vala | 15 ++ main.vala | 48 +++-- ui.vala | 49 ++++- user-interface.ui | 601 +++++++++++++++++++++++++++++++++++++++++++++++++++++- web.vala | 15 ++ 7 files changed, 726 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index cdf1b8e..680783b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ PREFIX=/usr/local # web.vala (currently disabled) barcode-scanner: main.vala device.vala db.vala ui.vala - valac-0.16 --output $@ --pkg posix --pkg linux --pkg libsoup-2.4 --pkg sqlite3 --pkg gtk+-3.0 --pkg gee-1.0 $^ + valac-0.16 --output $@ --pkg posix --pkg linux --pkg libsoup-2.4 --pkg sqlite3 --pkg gtk+-3.0 --pkg gee-1.0 --pkg gmodule-2.0 $^ shop.db: create_db.sql sqlite3 shop.db < create_db.sql diff --git a/db.vala b/db.vala index 6686df9..b6218a9 100644 --- a/db.vala +++ b/db.vala @@ -1,3 +1,18 @@ +/* Copyright 2012, Sebastian Reichel + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + public class Database { private Sqlite.Database db; private Sqlite.Statement product_stmt; @@ -165,10 +180,10 @@ public class Database { else return this.price_stmt.column_int(1); case Sqlite.DONE: - stderr.printf("unbekanntes Produkt: %llu\n", article); + write_to_log("unbekanntes Produkt: %llu\n", article); return 0; default: - stderr.printf("[interner Fehler: %d]\n", rc); + write_to_log("[interner Fehler: %d]\n", rc); return 0; } } @@ -187,7 +202,7 @@ public class Database { pid = uint64.parse(this.undo_stmt1.column_text(0)); break; case Sqlite.DONE: - stdout.printf("undo not possible without purchases\n"); + write_to_log("undo not possible without purchases"); return false; default: error("[interner Fehler: %d]".printf(rc)); diff --git a/device.vala b/device.vala index b27f73d..0bbc806 100644 --- a/device.vala +++ b/device.vala @@ -1,3 +1,18 @@ +/* Copyright 2012, Sebastian Reichel + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + public class Device { private Posix.termios newtio; private Posix.termios restoretio; diff --git a/main.vala b/main.vala index d540ada..cd441e3 100644 --- a/main.vala +++ b/main.vala @@ -1,3 +1,18 @@ +/* Copyright 2012, Sebastian Reichel + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + public Device dev; public Database db; public Gtk.Builder builder; @@ -16,9 +31,10 @@ public static int main(string[] args) { try { builder.add_from_file("user-interface.ui"); } catch(Error e) { - stderr.printf ("Could not load UI: %s\n", e.message); + stderr.printf("Could not load UI: %s\n", e.message); return 1; } + builder.connect_signals(null); dev.received_barcode.connect((data) => { if(interpret(data)) @@ -27,56 +43,58 @@ public static int main(string[] args) { init_ui(); + show_main_window(); + + write_to_log("KtT Shop System has been started"); + Gtk.main(); return 0; } public static bool interpret(string data) { - int64 timestamp = (new DateTime.now_utc()).to_unix(); - if(data.has_prefix("USER ")) { string str_id = data.substring(5); int32 id = int.parse(str_id); /* check if data has valid format */ if(data != "USER %d".printf(id)) { - stdout.printf("[%lld] ungültige Benutzernummer: %s\n", timestamp, data); + write_to_log("ungültige Benutzernummer: %s", data); return false; } if(db.is_logged_in()) { - stdout.printf("[%lld] Last User forgot to logout!\n", timestamp); + write_to_log("Last User forgot to logout!"); db.logout(); } - stdout.printf("[%lld] Login: %d\n", timestamp, id); + write_to_log("Login: %d", id); return db.login(id); } else if(data == "GUEST") { if(db.is_logged_in()) { - stdout.printf("[%lld] Last User forgot to logout!\n", timestamp); + write_to_log("Last User forgot to logout!"); db.logout(); } - stdout.printf("[%lld] Login: Guest\n", timestamp); + write_to_log("Login: Guest"); return db.login(0); } else if(data == "UNDO") { if(!db.is_logged_in()) { - stdout.printf("[%lld] Can't undo if not logged in!\n", timestamp); + write_to_log("Can't undo if not logged in!"); return false; } else { - stdout.printf("[%lld] Undo last purchase!\n", timestamp); + write_to_log("Undo last purchase!"); return db.undo(); } } else if(data == "LOGOUT") { if(db.is_logged_in()) { - stdout.printf("[%lld] Logout!\n", timestamp); + write_to_log("Logout!"); return db.logout(); } return false; } else if(data == "STOCK") { if(!db.is_logged_in()) { - stdout.printf("[%lld] You must be logged in to go into the stock mode\n", timestamp); + write_to_log("You must be logged in to go into the stock mode"); return false; } else { show_restock_dialog(); @@ -87,15 +105,15 @@ public static bool interpret(string data) { /* check if data has valid format */ if(data != "%llu".printf(id)) { - stdout.printf("[%lld] ungültiges Produkt: %s\n", timestamp, data); + write_to_log("ungültiges Produkt: %s", data); return false; } if(db.buy(id)) { - stdout.printf("[%lld] gekaufter Artikel: %s (%d,%02d €)\n", timestamp, db.get_product_name(id), db.get_product_price(id)/100, db.get_product_price(id) % 100); + write_to_log("gekaufter Artikel: %s (%d,%02d €)", db.get_product_name(id), db.get_product_price(id)/100, db.get_product_price(id) % 100); return true; } else { - stdout.printf("[%lld] Kauf fehlgeschlagen!\n", timestamp); + write_to_log("Kauf fehlgeschlagen!"); return false; } } diff --git a/ui.vala b/ui.vala index e3a21aa..843198b 100644 --- a/ui.vala +++ b/ui.vala @@ -1,5 +1,30 @@ +/* Copyright 2012, Sebastian Reichel + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + public void init_ui() { init_restock_dialog(); + init_main_window(); +} + +public void init_main_window() { + var window = builder.get_object("main") as Gtk.Window; + + /* TODO */ + window.destroy.connect(() => { + Gtk.main_quit(); + }); } public void init_restock_dialog() { @@ -29,8 +54,7 @@ public void init_restock_dialog() { var product = (id != null) ? uint64.parse(id) : 0; var amount = (int) spinner.get_value(); - int64 timestamp = (new DateTime.now_utc()).to_unix(); - stdout.printf("[%lld] restock: %lld - %d\n", timestamp, product, amount); + write_to_log("restock: %lld - %d\n", product, amount); if(db.restock(product, amount)) { spinner.value = 0.0; @@ -41,5 +65,24 @@ public void init_restock_dialog() { } public void show_restock_dialog() { - (builder.get_object("restock_dialog") as Gtk.Window).show(); + (builder.get_object("restock-dialog") as Gtk.Window).show(); +} + +public void show_about_dialog() { + (builder.get_object("about-dialog") as Gtk.Window).show(); +} + +public void show_main_window() { + (builder.get_object("main") as Gtk.Window).show(); +} + +[PrintfFormat] +public void write_to_log(string format, ...) { + var arguments = va_list(); + var message = format.vprintf(arguments); + var time = new DateTime.now_local(); + + var view = builder.get_object("logview") as Gtk.TextView; + view.buffer.insert_at_cursor(time.format("[%Y-%m-%d %H:%M:%S] ") + message + "\n", -1); + view.scroll_to_mark(view.buffer.get_insert(), 0.0, true, 0.0, 1.0); } diff --git a/user-interface.ui b/user-interface.ui index 55266f5..be36742 100644 --- a/user-interface.ui +++ b/user-interface.ui @@ -1,12 +1,474 @@ - + + False + 5 + dialog + KtT Shop System + 0.1 + Copyright (c) 2012 Sebastian Reichel + https://github.com/ktt-ol/serial-barcode-scanner + KtT Shop System @ github + Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + Sebastian Reichel <sre@ring0.de> +Lennart Weller <lhw@ring0.de> + + + + + + False + vertical + 2 + + + False + end + + + False + True + end + 0 + + + + + + + + + 100 1 10 - + + 100 + 0.01 + 1 + + + True + False + gtk-add + 1 + + + True + False + gtk-new + 1 + + + True + False + gtk-info + 1 + + + 640 + 480 + False + KtT Shop System + + + True + False + vertical + + + True + False + + + False + True + False + _File + True + + + True + False + + + gtk-connect + False + True + False + False + True + True + + + + + False + True + False + + + + + gtk-quit + False + True + False + True + True + + + + + + + + + + False + True + False + _View + True + + + True + False + + + Add Stock + False + True + False + False + image2 + False + + + + + Add New Item + False + True + False + False + image3 + False + + + + + + + + + False + True + False + _Help + True + + + True + False + + + Stock & Price Information + False + True + False + False + image4 + False + + + + + gtk-about + False + True + False + True + True + + + + + + + + + + False + True + 0 + + + + + True + True + in + + + True + True + False + False + + + + + True + True + 1 + + + + + True + False + + + True + False + vertical + 2 + + + True + True + 0 + + + + + True + False + gtk-missing-image + + + False + True + 1 + + + + + False + False + 2 + + + + + + + 100 + 0.01 + 1 + + + 1.8446744073709552e+19 + 1 + 10 + + + False + 5 + new product + dialog + + + False + vertical + 2 + + + False + end + + + gtk-cancel + False + True + True + True + False + True + + + False + True + 0 + + + + + gtk-add + False + True + True + True + False + True + + + False + True + 1 + + + + + False + True + end + 0 + + + + + True + False + + + True + False + ID + + + 0 + 0 + 1 + 1 + + + + + True + False + Name + + + 0 + 1 + 1 + 1 + + + + + True + False + Memberprice + + + 0 + 2 + 1 + 1 + + + + + True + False + Guestprice + + + 0 + 3 + 1 + 1 + + + + + True + True + + + + 1 + 1 + 1 + 1 + + + + + True + True + + memberprice-adjustment + 0.10000000000000001 + 2 + + + 1 + 2 + 1 + 1 + + + + + True + True + + guestprice-adjustment + 0.10000000000000001 + 2 + + + 1 + 3 + 1 + 1 + + + + + True + True + + productid-adjustment + + + 1 + 0 + 1 + 1 + + + + + False + True + 1 + + + + + + button2 + button1 + + + False 5 restock @@ -98,7 +560,7 @@ True 3 - adjustment1 + amount-adjustment 1 True @@ -137,4 +599,137 @@ button-restock-add + + False + 5 + stock + dialog + + + False + vertical + 2 + + + False + end + + + gtk-ok + False + True + True + True + False + True + + + False + True + 0 + + + + + False + True + end + 0 + + + + + True + True + in + + + True + False + + + True + False + + + True + False + EAN + + + 0 + 0 + 1 + 1 + + + + + True + False + Name + + + 1 + 0 + 1 + 1 + + + + + True + False + Amount + + + 2 + 0 + 1 + 1 + + + + + True + False + Member Price + + + 3 + 0 + 1 + 1 + + + + + True + False + Guest Price + + + 4 + 0 + 1 + 1 + + + + + + + + + False + True + 1 + + + + + + button3 + + diff --git a/web.vala b/web.vala index 5f3e1e1..e782623 100644 --- a/web.vala +++ b/web.vala @@ -1,3 +1,18 @@ +/* Copyright 2012, Sebastian Reichel + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + public class Web { private Soup.SessionAsync session; private static string server = "https://shop.kreativitaet-trifft-technik.de"; -- cgit v1.2.3