From f5f02c1615a30d88fbd0d77709ee9c924c048849 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Mon, 29 Apr 2013 00:07:16 +0200 Subject: add template dir to config --- src/web/Makefile | 2 +- src/web/main.vala | 6 ++++++ src/web/template.vala | 28 ++++++++++++++-------------- src/web/web.vala | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src/web') diff --git a/src/web/Makefile b/src/web/Makefile index de305d9..3737582 100644 --- a/src/web/Makefile +++ b/src/web/Makefile @@ -1,6 +1,6 @@ all: web -web: main.vala web.vala websession.vala csv.vala template.vala ../database/db-interface.vala ../pgp/pgp-interface.vala ../price.vapi +web: main.vala web.vala websession.vala csv.vala template.vala ../database/db-interface.vala ../pgp/pgp-interface.vala ../price.vapi ../config/config-interface.vala valac -o $@ --vapidir=../../vapi --enable-experimental --pkg gee-1.0 --pkg gio-2.0 --pkg libsoup-2.4 --pkg posix $^ clean: diff --git a/src/web/main.vala b/src/web/main.vala index 07dbb03..b5fdde3 100644 --- a/src/web/main.vala +++ b/src/web/main.vala @@ -16,13 +16,19 @@ Database db; public CSVMemberFile csvimport; public PGP pgp; +public Config cfg; +string templatedir; public static int main(string[] args) { try { db = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Database", "/io/mainframe/shopsystem/database"); pgp = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.PGP", "/io/mainframe/shopsystem/pgp"); + cfg = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); + templatedir = cfg.get_string("WEB", "filepath"); } catch(IOError e) { error("IOError: %s\n", e.message); + } catch(KeyFileError e) { + error("KeyFileError: %s\n", e.message); } /* attach WebServer to MainLoop */ diff --git a/src/web/template.vala b/src/web/template.vala index 8fe56d0..690de00 100644 --- a/src/web/template.vala +++ b/src/web/template.vala @@ -24,39 +24,39 @@ public class WebTemplate { public uint8[] data { get { return template.data; } } public WebTemplate(string file, WebSession login) throws TemplateError { - var b = File.new_for_path("templates/base.html"); - var m = File.new_for_path("templates/menu.html"); - var f = File.new_for_path("templates/"+file); + var b = File.new_for_path(templatedir+"base.html"); + var m = File.new_for_path(templatedir+"menu.html"); + var f = File.new_for_path(templatedir+file); File fauth; if(login.logged_in) - fauth = File.new_for_path("templates/menu_logout.html"); + fauth = File.new_for_path(templatedir+"menu_logout.html"); else - fauth = File.new_for_path("templates/menu_login.html"); + fauth = File.new_for_path(templatedir+"menu_login.html"); uint8[] basis, menu, template, auth; if(!b.query_exists()) - throw new TemplateError.NOT_FOUND("templates/base.html not found!"); + throw new TemplateError.NOT_FOUND(templatedir+"base.html not found!"); if(!m.query_exists()) - throw new TemplateError.NOT_FOUND("templates/menu.html not found!"); + throw new TemplateError.NOT_FOUND(templatedir+"menu.html not found!"); if(!fauth.query_exists()) throw new TemplateError.NOT_FOUND(fauth.get_path()+" not found!"); if(!f.query_exists()) - throw new TemplateError.NOT_FOUND("templates/"+file+" not found!"); + throw new TemplateError.NOT_FOUND(templatedir+file+" not found!"); try { if(!b.load_contents(null, out basis, null)) - throw new TemplateError.NOT_LOADABLE("templates/base.html could not be loaded!"); + throw new TemplateError.NOT_LOADABLE(templatedir+"base.html could not be loaded!"); if(!m.load_contents(null, out menu, null)) - throw new TemplateError.NOT_LOADABLE("templates/menu.html could not be loaded!"); + throw new TemplateError.NOT_LOADABLE(templatedir+"menu.html could not be loaded!"); if(!fauth.load_contents(null, out auth, null)) throw new TemplateError.NOT_LOADABLE(fauth.get_path()+" could not be loaded!"); if(!f.load_contents(null, out template, null)) - throw new TemplateError.NOT_LOADABLE("templates/"+file+" could not be loaded!"); + throw new TemplateError.NOT_LOADABLE(templatedir+file+" could not be loaded!"); } catch(Error e) { throw new TemplateError.NOT_LOADABLE("could not load templates!"); } @@ -70,15 +70,15 @@ public class WebTemplate { } public WebTemplate.DATA(string file) throws TemplateError { - var f = File.new_for_path("templates/"+file); + var f = File.new_for_path(templatedir+file); uint8[] template; if(!f.query_exists()) - throw new TemplateError.NOT_FOUND("templates/"+file+" not found!"); + throw new TemplateError.NOT_FOUND(templatedir+file+" not found!"); try { if(!f.load_contents(null, out template, null)) - throw new TemplateError.NOT_LOADABLE("templates/"+file+" could not be loaded!"); + throw new TemplateError.NOT_LOADABLE(templatedir+file+" could not be loaded!"); } catch(Error e) { throw new TemplateError.NOT_LOADABLE("could not load templates!"); } diff --git a/src/web/web.vala b/src/web/web.vala index 3e58fe6..8d39153 100644 --- a/src/web/web.vala +++ b/src/web/web.vala @@ -844,7 +844,7 @@ public class WebServer { void handler_img(Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) { try { - var f = File.new_for_path("templates/"+path); + var f = File.new_for_path(templatedir+path); uint8[] data = null; if(f.query_exists() && f.load_contents(null, out data, null)) { -- cgit v1.2.3