From cce1953eb1f8fe8c927a1720c95caed45b71ef1d Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Fri, 29 Jun 2018 21:05:46 +0200 Subject: all: simplify datadir configuration This simplifies the datadir configuration and removes the expectation, that the code is executed from the repository. It should now be possible to install this into the system like any other common Linux application. --- src/audio/main.vala | 3 ++- src/config/main.vala | 4 +--- src/curses-ui/curses-ui.vala | 4 ++-- src/curses-ui/logo.vala | 14 +++++++------- src/curses-ui/main.vala | 14 ++++++++++---- src/invoice/invoice.vala | 3 ++- src/pdf-invoice/main.vala | 3 ++- src/web/main.vala | 3 ++- 8 files changed, 28 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/audio/main.vala b/src/audio/main.vala index 4a1da2f..2fdaf61 100644 --- a/src/audio/main.vala +++ b/src/audio/main.vala @@ -31,7 +31,8 @@ public static int main(string[] args) { try { Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - var path = cfg.get_string("AUDIO", "path"); + var datapath = cfg.get_string("GENERAL", "datapath"); + var path = Path.build_filename(datapath, "sounds"); player = new AudioPlayerImplementation(path); } catch(IOError e) { error(_("IO Error: %s\n"), e.message); diff --git a/src/config/main.vala b/src/config/main.vala index c24b572..6a90ad0 100644 --- a/src/config/main.vala +++ b/src/config/main.vala @@ -19,9 +19,7 @@ public static int main(string[] args) { Intl.setlocale(LocaleCategory.ALL, ""); Intl.textdomain("shopsystem"); - string binarylocation = File.new_for_path(args[0]).get_parent().get_path(); - - cfg = new Cfg(binarylocation + "/../../ktt-shopsystem.cfg"); + cfg = new Cfg("/etc/shopsystem.cfg"); Bus.own_name( BusType.SYSTEM, diff --git a/src/curses-ui/curses-ui.vala b/src/curses-ui/curses-ui.vala index 0cd6281..e98c6ea 100644 --- a/src/curses-ui/curses-ui.vala +++ b/src/curses-ui/curses-ui.vala @@ -23,7 +23,7 @@ public class CursesUI { //StatusPanel statuswin; MessageBoxOverlay mbOverlay; - public CursesUI(string binarylocation) { + public CursesUI(string datadir) { /* unicode support */ Intl.setlocale(LocaleCategory.CTYPE, ""); @@ -40,7 +40,7 @@ public class CursesUI { Curses.init_pair(2, Curses.Color.WHITE, Curses.Color.RED); /* initialize widgets */ - banner = new Logo(binarylocation); + banner = new Logo(datadir); //statuswin = new StatusPanel(); messages = new MessageBox(); clkwin = new ClockWindow(); diff --git a/src/curses-ui/logo.vala b/src/curses-ui/logo.vala index e7f6fb8..a4a2c2c 100644 --- a/src/curses-ui/logo.vala +++ b/src/curses-ui/logo.vala @@ -19,28 +19,28 @@ using Curses; public class Logo { Window win; - public Logo(string binarylocation) { + public Logo(string datadir) { win = new Window(8, COLS - 2, 0, 1); win.bkgdset(COLOR_PAIR(1) | Attribute.BOLD); win.addstr("\n"); - var file = File.new_for_path (binarylocation + "/../../logo.txt"); - - if (!file.query_exists ()) { + var logofilename = Path.build_filename(datadir, "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 ()); + var dis = new DataInputStream(file.read()); string line; // Read lines until end of file (null) is reached - while ((line = dis.read_line (null)) != null) { + while ((line = dis.read_line(null)) != null) { win.addstr(line+"\n"); } - } catch (Error e) { + } catch(Error e) { error (_("Error: %s"), e.message); } diff --git a/src/curses-ui/main.vala b/src/curses-ui/main.vala index e5ad4c8..3518bb2 100644 --- a/src/curses-ui/main.vala +++ b/src/curses-ui/main.vala @@ -19,6 +19,7 @@ public MainLoop loop; public AudioPlayer audio; public ScannerSession scanner; public CursesUI ui; +private Config cfg; private static void play(string file) { try { @@ -56,14 +57,19 @@ public static int main(string[] args) { 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"); + cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); + + var datapath = cfg.get_string("GENERAL", "datapath"); + var datadir = Path.build_filename(datapath, "curses-ui"); + ui = new CursesUI(datadir); } catch(IOError e) { 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); } - string binarylocation = File.new_for_path(args[0]).get_parent().get_path(); - - ui = new CursesUI(binarylocation); - Log.set_default_handler(log_handler); scanner.msg.connect(msg_handler); diff --git a/src/invoice/invoice.vala b/src/invoice/invoice.vala index f899cb5..1321071 100644 --- a/src/invoice/invoice.vala +++ b/src/invoice/invoice.vala @@ -44,7 +44,8 @@ public class InvoiceImplementation { db = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Database", "/io/mainframe/shopsystem/database"); pdf = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.InvoicePDF", "/io/mainframe/shopsystem/invoicepdf"); Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - datadir = cfg.get_string("INVOICE", "datadir"); + var datapath = cfg.get_string("GENERAL", "datapath"); + datadir = Path.build_filename(datapath, "invoice"); mailfromaddress = cfg.get_string("MAIL", "mailfromaddress"); treasurermailaddress = cfg.get_string("MAIL", "treasurermailaddress"); shortname = cfg.get_string("GENERAL", "shortname"); diff --git a/src/pdf-invoice/main.vala b/src/pdf-invoice/main.vala index 1848852..4217eb8 100644 --- a/src/pdf-invoice/main.vala +++ b/src/pdf-invoice/main.vala @@ -21,7 +21,8 @@ public static int main(string[] args) { try { Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - datadir = cfg.get_string("INVOICE", "datadir"); + var datapath = cfg.get_string("GENERAL", "datapath"); + datadir = Path.build_filename(datapath, "invoice"); } catch(DBusError e) { error(_("DBus Error: %s\n"), e.message); } catch(IOError e) { diff --git a/src/web/main.vala b/src/web/main.vala index f7b0c30..2043df0 100644 --- a/src/web/main.vala +++ b/src/web/main.vala @@ -34,7 +34,8 @@ public static int main(string[] args) { pgp = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.PGP", "/io/mainframe/shopsystem/pgp"); cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); audio = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.AudioPlayer", "/io/mainframe/shopsystem/audio"); - templatedir = cfg.get_string("WEB", "filepath"); + var datapath = cfg.get_string("GENERAL", "datapath"); + templatedir = Path.build_filename(datapath, "templates"); port = cfg.get_integer("WEB", "port"); try { -- cgit v1.2.3