From 5b34b11dd8ea3054784bc9d537843c65102435f5 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 1 Mar 2014 17:39:00 -0500 Subject: [PATCH] gui: Move ocarina6.glade to share/ocarina/ This directory will be copied directly into /usr/ during an install. Signed-off-by: Anna Schumaker --- .gitignore | 2 +- gui/main.cpp | 18 ++++++++++++++++++ gui/wires.cpp | 2 +- include/ocarina.h | 1 + {gui => share/ocarina}/ocarina6.glade | 0 5 files changed, 21 insertions(+), 2 deletions(-) rename {gui => share/ocarina}/ocarina6.glade (100%) diff --git a/.gitignore b/.gitignore index 678692e5..e42436a8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,6 @@ *.run *.test *.glade~ -gui/#* +share/ocarina/#* bin/ .sconsign.dblite diff --git a/gui/main.cpp b/gui/main.cpp index 2f964b1f..6f0161bc 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -7,6 +7,23 @@ #include #include +const std::string share_file(const std::string &file) +{ + char buf[1024]; + std::string res; + ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); + + if (len == -1) + return ""; + + buf[len] = '\0'; + res = std::string(buf); + + // len("bin/ocarina") == 11 + res = res.substr(0, res.size() - 11); + return res + "share/ocarina/" + file; +} + Gtk::Window *ocarina_init(int *argc, char ***argv) { Gtk::Window *window = connect_wires(); @@ -15,6 +32,7 @@ Gtk::Window *ocarina_init(int *argc, char ***argv) library::init(); playlist::init(); + share_file("ocarina6.glade"); post_init_tabs(); return window; } diff --git a/gui/wires.cpp b/gui/wires.cpp index 70f62769..e9bc9d0c 100644 --- a/gui/wires.cpp +++ b/gui/wires.cpp @@ -242,7 +242,7 @@ Gtk::Window *connect_wires() struct Callbacks *cb = get_callbacks(); builder = Gtk::Builder::create(); - builder->add_from_file("gui/ocarina6.glade"); + builder->add_from_file(share_file("ocarina6.glade")); /* Controls */ diff --git a/include/ocarina.h b/include/ocarina.h index 9ed53418..40c4b18d 100644 --- a/include/ocarina.h +++ b/include/ocarina.h @@ -13,6 +13,7 @@ void collection_mgr_init(); /* main.cpp */ +const std::string share_file(const std::string &); Gtk::Window *ocarina_init(int *, char ***); diff --git a/gui/ocarina6.glade b/share/ocarina/ocarina6.glade similarity index 100% rename from gui/ocarina6.glade rename to share/ocarina/ocarina6.glade