From 1a2ebec81a74e478f4e2976882451434deb40f7a Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Sat, 2 Mar 2013 19:41:19 +0100 Subject: move specification of serial device into config file --- src/main.vala | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main.vala b/src/main.vala index 4a14cdf..67f00ff 100644 --- a/src/main.vala +++ b/src/main.vala @@ -25,12 +25,10 @@ public CursesUI ui; const OptionEntry[] option_entries = { { "version", 'v', OptionFlags.IN_MAIN, OptionArg.NONE, ref opt_version, "output version information and exit", null }, - { "", 0, 0, OptionArg.FILENAME_ARRAY, ref files, "serial device", "DEVICE" }, {null} }; /* parameters */ -static string[] files; static bool opt_version; public static int main(string[] args) { @@ -48,25 +46,14 @@ public static int main(string[] args) { } if(opt_version) { - stdout.puts("Ktt Shop System 0.1\n"); + stdout.puts("KtT Shop System 0.1\n"); return 0; } - if(files == null || files[0] == null) { - stderr.puts("Please specify serial device!\n"); - return 1; - } - /* handle unix signals */ Unix.signal_add(Posix.SIGTERM, handle_signals); Unix.signal_add(Posix.SIGINT, handle_signals); - dev = new Device(files[0], 9600, 8, 1); - db = new Database("shop.db"); - audio = new AudioPlayer(); - loop = new MainLoop(); - localsession = new ScannerSession(); - try { cfg = new KeyFile(); cfg.load_from_file("ktt-shopsystem.cfg", KeyFileFlags.NONE); @@ -74,6 +61,20 @@ public static int main(string[] args) { error("Could not load configuration file: %s", e.message); } + string devicefile = ""; + try { + devicefile = cfg.get_string("SERIAL", "device"); + } catch(KeyFileError e) { + stderr.puts("Please specify serial device in the configuration file!\n"); + return 1; + } + + dev = new Device(devicefile, 9600, 8, 1); + db = new Database("shop.db"); + audio = new AudioPlayer(); + loop = new MainLoop(); + localsession = new ScannerSession(); + pgp = new PGPKeyArchive(cfg); dev.received_barcode.connect((data) => { -- cgit v1.2.3