diff options
author | Holger Cremer <HolgerCremer@gmail.com> | 2018-08-27 19:38:11 +0200 |
---|---|---|
committer | Holger Cremer <HolgerCremer@gmail.com> | 2018-08-27 19:38:11 +0200 |
commit | 8f2ba2050ee78d0e4a47f1277c6bc4422d06170c (patch) | |
tree | c008d2878905e03df7a8bf8bd3330762cc2d8f43 /src/curses-ui | |
parent | bb55e121576a5b5d225bfc68c5062f386cc32db9 (diff) | |
parent | 3fc3ea6c6df237dbdf48d14703118b747bf5d647 (diff) | |
download | serial-barcode-scanner-8f2ba2050ee78d0e4a47f1277c6bc4422d06170c.tar.bz2 |
Merge branch 'master' into better_inventory
Conflicts:
README
data/templates/products/entry.html
docker/Dockerfile
docker/init.sh
src/database/database.vala
src/database/db-interface.vala
src/pdf-stock/Makefile
src/pdf-stock/pdf-stock-interface.vala
src/pdf-stock/pdf-stock.vala
src/web/Makefile
src/web/main.vala
templates/menu.html
templates/products/index.html
Diffstat (limited to 'src/curses-ui')
-rw-r--r-- | src/curses-ui/.gitignore | 1 | ||||
-rw-r--r-- | src/curses-ui/Makefile | 10 | ||||
-rw-r--r-- | src/curses-ui/clock.vala | 1 | ||||
-rw-r--r-- | src/curses-ui/curses-ui.vala | 18 | ||||
-rw-r--r-- | src/curses-ui/dialog.vala | 6 | ||||
-rw-r--r-- | src/curses-ui/logo.vala | 28 | ||||
-rw-r--r-- | src/curses-ui/main.vala | 28 | ||||
-rw-r--r-- | src/curses-ui/message_box.vala | 4 | ||||
-rw-r--r-- | src/curses-ui/message_box_overlay.vala | 6 | ||||
-rw-r--r-- | src/curses-ui/numbers.vala | 2 |
10 files changed, 62 insertions, 42 deletions
diff --git a/src/curses-ui/.gitignore b/src/curses-ui/.gitignore deleted file mode 100644 index b66c764..0000000 --- a/src/curses-ui/.gitignore +++ /dev/null @@ -1 +0,0 @@ -curses-ui diff --git a/src/curses-ui/Makefile b/src/curses-ui/Makefile deleted file mode 100644 index 1ca68cf..0000000 --- a/src/curses-ui/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -all: curses-ui - @echo > /dev/null - -curses-ui: *.vala ../audio/audio-interface.vala ../scanner-session/scannersession-interface.vala - valac -X -w -o $@ --pkg curses -X -lncursesw --pkg posix --pkg gio-2.0 $^ - -clean: - rm -rf curses-ui - -.PHONY: all clean diff --git a/src/curses-ui/clock.vala b/src/curses-ui/clock.vala index dd3ddcd..43ca48b 100644 --- a/src/curses-ui/clock.vala +++ b/src/curses-ui/clock.vala @@ -1,4 +1,5 @@ /* Copyright 2013, Sebastian Reichel <sre@ring0.de> + * Copyright 2018, Malte Modler <malte@malte-modler.de> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above diff --git a/src/curses-ui/curses-ui.vala b/src/curses-ui/curses-ui.vala index ab34787..539c959 100644 --- a/src/curses-ui/curses-ui.vala +++ b/src/curses-ui/curses-ui.vala @@ -1,4 +1,6 @@ /* Copyright 2013, Sebastian Reichel <sre@ring0.de> + * Copyright 2017-2018, Johannes Rudolph <johannes.rudolph@gmx.com> + * Copyright 2018, Malte Modler <malte@malte-modler.de> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -21,7 +23,7 @@ public class CursesUI { //StatusPanel statuswin; MessageBoxOverlay mbOverlay; - public CursesUI() { + public CursesUI(string configdir) { /* unicode support */ Intl.setlocale(LocaleCategory.CTYPE, ""); @@ -37,8 +39,8 @@ public class CursesUI { Curses.init_pair(1, Curses.Color.GREEN, Curses.Color.BLACK); Curses.init_pair(2, Curses.Color.WHITE, Curses.Color.RED); - /* initialize widgets */ - banner = new Logo(); + /* initialize widgets */ + banner = new Logo(configdir); //statuswin = new StatusPanel(); messages = new MessageBox(); clkwin = new ClockWindow(); @@ -68,18 +70,18 @@ public class CursesUI { //} public void log(MessageType type, string message) { - switch (type) { + switch (type) { case MessageType.WARNING: messages.add(message, MessageBox.WARN_COLOR); break; - case MessageType.ERROR: + case MessageType.ERROR: messages.add(message, MessageBox.ERROR_COLOR); break; default: messages.add(message, MessageBox.INFO_COLOR); break; } - + } public void log_overlay(string title, string message, int closeAfter) { @@ -87,7 +89,7 @@ public class CursesUI { Timeout.add_seconds(closeAfter, closeMbOverlay); } - public void dialog_open(string title, string message, int closeAfter=0) { + public void dialog_open(string title, string message, int closeAfter=0) { dialog = new Dialog(message, title, closeAfter); if (closeAfter > 0) { Timeout.add_seconds(closeAfter, close); @@ -102,7 +104,7 @@ public class CursesUI { return false; } - bool close() { + bool close() { dialog_close(); // just call me once return false; diff --git a/src/curses-ui/dialog.vala b/src/curses-ui/dialog.vala index 7d2902b..e7ae0b8 100644 --- a/src/curses-ui/dialog.vala +++ b/src/curses-ui/dialog.vala @@ -51,7 +51,7 @@ public class Dialog { if (countdownValue > 0) { Timeout.add_seconds(1, decrementTitleCountdown); - } + } } private void setTitle() { @@ -61,7 +61,7 @@ public class Dialog { } int title_x = (dialogWidth-title.length)/2; win.mvaddstr(0, title_x, title); - win.mvaddch(0, title_x-2, Acs.RTEE); + win.mvaddch(0, title_x-2, Acs.RTEE); win.mvaddch(0, title_x-1, ' '); win.mvaddch(0, title_x+title.length, ' '); win.mvaddch(0, title_x+title.length+1, Acs.LTEE); @@ -70,7 +70,7 @@ public class Dialog { win.mvaddch(0, title_x+title.length+3, Acs.HLINE); } - private bool decrementTitleCountdown() { + private bool decrementTitleCountdown() { countdownValue--; setTitle(); win.refresh(); diff --git a/src/curses-ui/logo.vala b/src/curses-ui/logo.vala index dbc716d..1bb609b 100644 --- a/src/curses-ui/logo.vala +++ b/src/curses-ui/logo.vala @@ -1,4 +1,5 @@ /* Copyright 2013, Sebastian Reichel <sre@ring0.de> + * Copyright 2017-2018, Johannes Rudolph <johannes.rudolph@gmx.com> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,17 +19,30 @@ using Curses; public class Logo { Window win; - public Logo() { + public Logo(string configdir) { win = new Window(8, COLS - 2, 0, 1); win.bkgdset(COLOR_PAIR(1) | Attribute.BOLD); win.addstr("\n"); - win.addstr(" _ ___ _____ ____ _ \n"); - win.addstr(" | |/ / ||_ _| / ___|| |__ ___ _ __ \n"); - win.addstr(" | ' /| __|| | \\___ \\| '_ \\ / _ \\| '_ \\ \n"); - win.addstr(" | . \\| |_ | | ___) | | | | (_) | |_) )\n"); - win.addstr(" |_|\\_\\\\__||_| |____/|_| |_|\\___/| .__/ \n"); - win.addstr(" |_| \n"); + + var logofilename = Path.build_filename(configdir, "logo.txt"); + var file = File.new_for_path(logofilename); + if (!file.query_exists()) { + stderr.printf (_("File '%s' doesn't exist.\n"), file.get_path ()); + } + + try { + // Open file for reading and wrap returned FileInputStream into a + // DataInputStream, so we can read line by line + var dis = new DataInputStream(file.read()); + string line; + // Read lines until end of file (null) is reached + while ((line = dis.read_line(null)) != null) { + win.addstr(line+"\n"); + } + } catch(Error e) { + error (_("Error: %s"), e.message); + } win.clrtobot(); diff --git a/src/curses-ui/main.vala b/src/curses-ui/main.vala index da822a9..adeb67f 100644 --- a/src/curses-ui/main.vala +++ b/src/curses-ui/main.vala @@ -1,4 +1,6 @@ /* Copyright 2013, Sebastian Reichel <sre@ring0.de> + * Copyright 2017-2018, Johannes Rudolph <johannes.rudolph@gmx.com> + * Copyright 2018, Malte Modler <malte@malte-modler.de> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -22,7 +24,9 @@ private static void play(string file) { try { audio.play_system(file); } catch(IOError e) { - ui.log(MessageType.WARNING, "could not play audio: %s".printf(e.message)); + ui.log(MessageType.WARNING, _("could not play audio: %s").printf(e.message)); + } catch(DBusError e) { + ui.log(MessageType.WARNING, _("could not play audio: %s").printf(e.message)); } } @@ -42,31 +46,39 @@ public void log_handler(string? log_domain, LogLevelFlags flags, string message) public static int main(string[] args) { loop = new MainLoop(); + Intl.setlocale(LocaleCategory.ALL, ""); + Intl.textdomain("shopsystem"); + /* handle unix signals */ - Unix.signal_add(Posix.SIGTERM, handle_signals); - Unix.signal_add(Posix.SIGINT, handle_signals); + Unix.signal_add(Posix.Signal.TERM, handle_signals); + Unix.signal_add(Posix.Signal.INT, handle_signals); try { audio = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.AudioPlayer", "/io/mainframe/shopsystem/audio"); scanner = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.ScannerSession", "/io/mainframe/shopsystem/scanner_session"); + + var configdir = "/etc/shopsystem"; + ui = new CursesUI(configdir); } catch(IOError e) { - error("IOError: %s\n", e.message); + error(_("IO Error: %s\n"), e.message); + } catch(DBusError e) { + error(_("DBus Error: %s\n"), e.message); + } catch(KeyFileError e) { + error(_("KeyFile Error: %s\n"), e.message); } - ui = new CursesUI(); - Log.set_default_handler(log_handler); scanner.msg.connect(msg_handler); scanner.msg_overlay.connect(msg_overlay_handler); - ui.log(MessageType.INFO, "KtT Shop System has been started"); + ui.log(MessageType.INFO, _("Shop System has been started")); play("startup.ogg"); /* run mainloop */ loop.run(); - ui.log(MessageType.INFO, "Stopping Shop System"); + ui.log(MessageType.INFO, _("Stopping Shop System")); play("shutdown.ogg"); /* leave curses mode */ diff --git a/src/curses-ui/message_box.vala b/src/curses-ui/message_box.vala index d6823fe..70c4d10 100644 --- a/src/curses-ui/message_box.vala +++ b/src/curses-ui/message_box.vala @@ -41,7 +41,7 @@ public class MessageBox { init_pair (INFO_COLOR, Color.WHITE, Color.BLACK); init_pair (WARN_COLOR, Color.YELLOW, Color.BLACK); - init_pair (ERROR_COLOR, Color.RED, Color.BLACK); + init_pair (ERROR_COLOR, Color.RED, Color.BLACK); } public void add(string msg, short color_pair = MessageBox.INFO_COLOR) { @@ -49,7 +49,7 @@ public class MessageBox { if(now.get_day_of_year() != last.get_day_of_year() || now.get_year() != last.get_year()) { string curtime = now.format("%Y-%m-%d"); - subwin.addstr("\nDate Changed: " + curtime); + subwin.addstr(_("\nDate Changed: ") + curtime); } last = now; diff --git a/src/curses-ui/message_box_overlay.vala b/src/curses-ui/message_box_overlay.vala index 721ab06..7b5a09b 100644 --- a/src/curses-ui/message_box_overlay.vala +++ b/src/curses-ui/message_box_overlay.vala @@ -37,13 +37,13 @@ public class MessageBoxOverlay { Timeout.add_seconds(1, decrementTitleCountdown); } - private void setTitle() { + private void setTitle() { var title = " === %s (%d) === ".printf(dialogTitle, countdownValue); int title_x = (COLS - title.length)/2; - win.mvaddstr(0, title_x, title); + win.mvaddstr(0, title_x, title); } - private bool decrementTitleCountdown() { + private bool decrementTitleCountdown() { countdownValue--; setTitle(); win.refresh(); diff --git a/src/curses-ui/numbers.vala b/src/curses-ui/numbers.vala index 200cf63..5cbcd23 100644 --- a/src/curses-ui/numbers.vala +++ b/src/curses-ui/numbers.vala @@ -1,4 +1,6 @@ /* Copyright 2013, Sebastian Reichel <sre@ring0.de> + * Copyright 2017-2018, Johannes Rudolph <johannes.rudolph@gmx.com> + * Copyright 2018, Malte Modler <malte@malte-modler.de> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above |