summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2013-05-16 19:18:27 +0200
committerSebastian Reichel <sre@ring0.de>2013-05-16 19:18:27 +0200
commit6b7c4b38331ec880a1bc67cf65c5f0c5e9c52add (patch)
tree5ad7107ddf037f7ecaefdb091d7a6cac3363ce00
parente075f9d8060bb08da46fd2be679e2cc2f226fec1 (diff)
downloadserial-barcode-scanner-6b7c4b38331ec880a1bc67cf65c5f0c5e9c52add.tar.bz2
pdf-invoice: get datapath from config
-rw-r--r--invoice/pdf-template.txt (renamed from src/pdf-invoice/template.txt)0
-rw-r--r--src/pdf-invoice/Makefile2
-rw-r--r--src/pdf-invoice/main.vala13
-rw-r--r--src/pdf-invoice/pdf-invoice.vala11
4 files changed, 20 insertions, 6 deletions
diff --git a/src/pdf-invoice/template.txt b/invoice/pdf-template.txt
index bb603b9..bb603b9 100644
--- a/src/pdf-invoice/template.txt
+++ b/invoice/pdf-template.txt
diff --git a/src/pdf-invoice/Makefile b/src/pdf-invoice/Makefile
index ef07ba1..0e930fd 100644
--- a/src/pdf-invoice/Makefile
+++ b/src/pdf-invoice/Makefile
@@ -1,6 +1,6 @@
all: pdf-invoice
-pdf-invoice: main.vala pdf-invoice.vala pdf-invoice-interface.vala ../database/db-interface.vala ../price.vapi
+pdf-invoice: main.vala pdf-invoice.vala pdf-invoice-interface.vala ../config/config-interface.vala ../database/db-interface.vala ../price.vapi
valac -g -o $@ --pkg pangocairo --pkg librsvg-2.0 --pkg posix --pkg gdk-2.0 --pkg gio-2.0 $^
test: pdf-invoice-interface.vala test.vala ../price.vapi
diff --git a/src/pdf-invoice/main.vala b/src/pdf-invoice/main.vala
index 76b03c6..cbb73f2 100644
--- a/src/pdf-invoice/main.vala
+++ b/src/pdf-invoice/main.vala
@@ -13,7 +13,18 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+private string datadir;
+
public static int main(string[] args) {
+ try {
+ Config cfg = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config");
+ datadir = cfg.get_string("INVOICE", "datadir");
+ } catch(IOError e) {
+ error("IOError: %s\n", e.message);
+ } catch(KeyFileError e) {
+ error("Config Error: %s\n", e.message);
+ }
+
Bus.own_name(
BusType.SESSION,
"io.mainframe.shopsystem.InvoicePDF",
@@ -29,7 +40,7 @@ public static int main(string[] args) {
void on_bus_aquired(DBusConnection conn) {
try {
- conn.register_object("/io/mainframe/shopsystem/invoicepdf", new InvoicePDF());
+ conn.register_object("/io/mainframe/shopsystem/invoicepdf", new InvoicePDF(datadir));
} catch(IOError e) {
stderr.printf("Could not register service\n");
}
diff --git a/src/pdf-invoice/pdf-invoice.vala b/src/pdf-invoice/pdf-invoice.vala
index 15f40d0..9a09ed9 100644
--- a/src/pdf-invoice/pdf-invoice.vala
+++ b/src/pdf-invoice/pdf-invoice.vala
@@ -43,6 +43,8 @@ public class InvoicePDF {
/* internal helper */
private DateTime previous_tm;
+ private string datadir;
+
private const string[] calendermonths = {
"Januar",
"Februar",
@@ -58,7 +60,8 @@ public class InvoicePDF {
"Dezember"
};
- public InvoicePDF() {
+ public InvoicePDF(string datadir) {
+ this.datadir = datadir;
}
private void render_svg(Cairo.Context ctx, string file) {
@@ -74,14 +77,14 @@ public class InvoicePDF {
ctx.save();
ctx.translate(-20, 818);
ctx.scale(1.42, 1.42);
- render_svg(ctx, "../../invoice/footer-line.svg");
+ render_svg(ctx, datadir + "/footer-line.svg");
ctx.restore();
}
private void draw_logo(Cairo.Context ctx) {
ctx.save();
ctx.translate(366,25);
- render_svg(ctx, "../../invoice/logo.svg");
+ render_svg(ctx, datadir + "/logo.svg");
ctx.restore();
}
@@ -355,7 +358,7 @@ public class InvoicePDF {
/* load text template */
try {
var text = "";
- FileUtils.get_contents("template.txt", out text);
+ FileUtils.get_contents(datadir + "/pdf-template.txt", out text);
text = text.replace("{{{ADDRESS}}}", address);
text = text.replace("{{{LASTNAME}}}", invoice_recipient.lastname);
text = text.replace("{{{SUM}}}", @"$sum");