summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2013-04-29 00:07:16 +0200
committerSebastian Reichel <sre@ring0.de>2013-04-29 00:07:43 +0200
commitf5f02c1615a30d88fbd0d77709ee9c924c048849 (patch)
treef0ceba6f13f6a545b868b5b08830cb4490f96df8
parent21273de2382f07ca2c799fb800de189608bb5529 (diff)
downloadserial-barcode-scanner-f5f02c1615a30d88fbd0d77709ee9c924c048849.tar.bz2
add template dir to config
-rw-r--r--src/web/Makefile2
-rw-r--r--src/web/main.vala6
-rw-r--r--src/web/template.vala28
-rw-r--r--src/web/web.vala2
4 files changed, 22 insertions, 16 deletions
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)) {