From d6cc1e7da591f784bddecce19e12097de88d0fe8 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Mon, 16 Jul 2018 00:32:57 +0200 Subject: fix templatedir --- src/audio/audio.vala | 26 +++++++++++++++++--------- src/invoice/invoice.vala | 6 +++--- src/pdf-invoice/pdf-invoice.vala | 8 ++++---- src/web/template.vala | 32 ++++++++++++++++++-------------- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/audio/audio.vala b/src/audio/audio.vala index 679e5c7..0d969e2 100644 --- a/src/audio/audio.vala +++ b/src/audio/audio.vala @@ -34,12 +34,18 @@ public class AudioPlayerImplementation { this.path = path; var alsa = Gst.ElementFactory.make("alsasink", "alsa"); - if (alsa == null) - throw new GLib.IOError.FAILED(_("Cannot find alsa GStreamer plugin")); + if (alsa == null) { + var msg = _("Cannot find alsa GStreamer plugin"); + stderr.printf(msg); + throw new GLib.IOError.FAILED(msg); + } p = Gst.ElementFactory.make("playbin", "player"); - if (p == null) - throw new GLib.IOError.FAILED(_("Cannot find playbin2 GStreamer plugin")); + if (p == null) { + var msg = _("Cannot find playbin2 GStreamer plugin"); + stderr.printf(msg); + throw new GLib.IOError.FAILED(msg); + } p.set("audio-sink", alsa); p.get_bus().add_watch(Priority.DEFAULT, bus_callback); @@ -47,7 +53,8 @@ public class AudioPlayerImplementation { public void play_system(string file) throws IOError, DBusError { p.set_state(Gst.State.NULL); - p.uri = "file://" + path + "system/" + file; + p.uri = "file://" + Path.build_filename(path, "system", file); + stdout.printf("Play: %s\n", p.uri); p.set_state(Gst.State.PLAYING); } @@ -77,17 +84,18 @@ public class AudioPlayerImplementation { } public string get_random_user_theme() throws IOError, DBusError { - return get_random_file(path + "user/"); + return get_random_file(Path.build_filename(path, "user")); } public string[] get_user_themes() throws IOError, DBusError { - return get_files(path + "user/"); + return get_files(Path.build_filename(path, "user")); } public void play_user(string theme, string type) throws IOError, DBusError { p.set_state(Gst.State.NULL); - var file = get_random_file(path + "user/" + theme+ "/" + type); - p.uri = "file://" + path + "user/" + theme+ "/" + type + "/" + file; + var file = get_random_file(Path.build_filename(path, "user", theme, type)); + p.uri = "file://" + Path.build_filename(path, "user", theme, type, file); + stdout.printf("Play: %s\n", p.uri); p.set_state(Gst.State.PLAYING); } } diff --git a/src/invoice/invoice.vala b/src/invoice/invoice.vala index 1321071..e83f4bf 100644 --- a/src/invoice/invoice.vala +++ b/src/invoice/invoice.vala @@ -248,7 +248,7 @@ public class InvoiceImplementation { string text; try { - FileUtils.get_contents(datadir + "/treasurer.mail.txt", out text); + FileUtils.get_contents(Path.build_filename(datadir, "/treasurer.mail.txt"), out text); } catch(GLib.FileError e) { throw new IOError.FAILED(_("Could not open invoice template: %s"), e.message); } @@ -315,7 +315,7 @@ public class InvoiceImplementation { throw new IOError.FAILED(_("Unknown MessageType")); try { - FileUtils.get_contents(datadir + "/" + filename, out text); + FileUtils.get_contents(Path.build_filename(datadir, filename), out text); } catch(GLib.FileError e) { throw new IOError.FAILED(_("Could not open invoice template: %s"), e.message); } @@ -334,7 +334,7 @@ public class InvoiceImplementation { vattextfilename = (type == MessageType.HTML) ? "vat.html" : "vat.txt"; try { - FileUtils.get_contents(datadir + "/" + vattextfilename, out vattext); + FileUtils.get_contents(Path.build_filename(datadir, vattextfilename), out vattext); } catch(GLib.FileError e) { throw new IOError.FAILED(_("Could not open VAT template: %s"), e.message); } diff --git a/src/pdf-invoice/pdf-invoice.vala b/src/pdf-invoice/pdf-invoice.vala index b41817d..d3177c9 100644 --- a/src/pdf-invoice/pdf-invoice.vala +++ b/src/pdf-invoice/pdf-invoice.vala @@ -86,14 +86,14 @@ public class InvoicePDF { ctx.save(); ctx.translate(-20, 818); ctx.scale(1.42, 1.42); - render_svg(ctx, datadir + "/footer-line.svg"); + render_svg(ctx, Path.build_filename(datadir, "footer-line.svg")); ctx.restore(); } private void draw_logo(Cairo.Context ctx) { ctx.save(); ctx.translate(366,25); - render_svg(ctx, datadir + "/logo.svg"); + render_svg(ctx, Path.build_filename(datadir, "logo.svg")); ctx.restore(); } @@ -362,7 +362,7 @@ public class InvoicePDF { /* load text template */ try { var text = ""; - FileUtils.get_contents(datadir + "/pdf-template.txt", out text); + FileUtils.get_contents(Path.build_filename(datadir, "pdf-template.txt"), out text); text = text.replace("{{{ADDRESS}}}", address); text = text.replace("{{{LASTNAME}}}", invoice_recipient.lastname); text = text.replace("{{{SUM}}}", @"$sum"); @@ -374,7 +374,7 @@ public class InvoicePDF { string vattext; try { - FileUtils.get_contents(datadir + "/" + "vat.txt", out vattext); + FileUtils.get_contents(Path.build_filename(datadir, "vat.txt"), out vattext); } catch(GLib.FileError e) { throw new IOError.FAILED(_("Could not open VAT template: %s"), e.message); } diff --git a/src/web/template.vala b/src/web/template.vala index f5c6d75..4dcda38 100644 --- a/src/web/template.vala +++ b/src/web/template.vala @@ -24,39 +24,42 @@ public class WebTemplate { public uint8[] data { get { return template.data; } } public WebTemplate(string file, WebSession login) throws TemplateError { - 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); + var bf = Path.build_filename(templatedir, "base.html"); + var b = File.new_for_path(bf); + var mf = Path.build_filename(templatedir, "menu.html"); + var m = File.new_for_path(mf); + var ff = Path.build_filename(templatedir, file); + var f = File.new_for_path(ff); File fauth; if(login.logged_in) - fauth = File.new_for_path(templatedir+"menu_logout.html"); + fauth = File.new_for_path(Path.build_filename(templatedir, "menu_logout.html")); else - fauth = File.new_for_path(templatedir+"menu_login.html"); + fauth = File.new_for_path(Path.build_filename(templatedir, "menu_login.html")); uint8[] basis, menu, template, auth; if(!b.query_exists()) - throw new TemplateError.NOT_FOUND(_("%s not found!").printf(templatedir+"base.html")); + throw new TemplateError.NOT_FOUND(_("%s not found!").printf(bf)); if(!m.query_exists()) - throw new TemplateError.NOT_FOUND(_("%s not found!").printf(templatedir+"menu.html")); + throw new TemplateError.NOT_FOUND(_("%s not found!").printf(mf)); if(!fauth.query_exists()) throw new TemplateError.NOT_FOUND(_("%s not found!").printf(fauth.get_path())); if(!f.query_exists()) - throw new TemplateError.NOT_FOUND(_("%s not found!").printf(templatedir+file)); + throw new TemplateError.NOT_FOUND(_("%s not found!").printf(ff)); try { if(!b.load_contents(null, out basis, null)) - throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(templatedir+"base.html")); + throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(bf)); if(!m.load_contents(null, out menu, null)) - throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(templatedir+"menu.html")); + throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(mf)); if(!fauth.load_contents(null, out auth, null)) throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(fauth.get_path())); if(!f.load_contents(null, out template, null)) - throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(templatedir+file)); + throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(ff)); } catch(Error e) { throw new TemplateError.NOT_LOADABLE(_("could not load templates!")); } @@ -71,15 +74,16 @@ public class WebTemplate { } public WebTemplate.DATA(string file) throws TemplateError { - var f = File.new_for_path(templatedir+file); + var ff = Path.build_filename(templatedir, file); + var f = File.new_for_path(ff); uint8[] template; if(!f.query_exists()) - throw new TemplateError.NOT_FOUND(_("%s not found!").printf(templatedir+file)); + throw new TemplateError.NOT_FOUND(_("%s not found!").printf(ff)); try { if(!f.load_contents(null, out template, null)) - throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(templatedir+file)); + throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(ff)); } catch(Error e) { throw new TemplateError.NOT_LOADABLE(_("could not load templates!")); } -- cgit v1.2.3