From 108dbacf41ed5ebad67f9e21e2830ee97dd3ba96 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 22 Jan 2016 16:36:06 -0500 Subject: [PATCH] gui/ocarina: Replace share_file() with find_file_path() And don't keep the result around any longer than we need to. Signed-off-by: Anna Schumaker --- gui/ocarina.cpp | 39 +++++++++++++++------------------------ include/gui/ocarina.h | 17 ----------------- 2 files changed, 15 insertions(+), 41 deletions(-) delete mode 100644 include/gui/ocarina.h diff --git a/gui/ocarina.cpp b/gui/ocarina.cpp index 0deef0db..565a8173 100644 --- a/gui/ocarina.cpp +++ b/gui/ocarina.cpp @@ -15,10 +15,10 @@ extern "C" { #include #include } -#include +#include +#include -static std::string ocarina_dir = ""; static Glib::RefPtr ocarina_app; @@ -30,27 +30,15 @@ struct core_init_data init_data = { &audio_ops, }; -namespace gui +static gchar *find_file_path(const gchar *file) { - const std::string share_file(const std::string &f) - { - return ocarina_dir + f; - } -} + gchar *path = g_strjoin("/", "share", "ocarina", file, NULL); + if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) + return path; + g_free(path); -static void setup_share(const std::string &path) -{ - char buf[1024]; - ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); - - if (len == -1) - return; - buf[len] = '\0'; - - ocarina_dir = std::string(buf); - ocarina_dir = ocarina_dir.substr(0, ocarina_dir.size() - 11); - ocarina_dir = ocarina_dir + "share/ocarina/"; + return g_strjoin("/", "/usr", "share", "ocarina", file, NULL); } static void on_window_removed(Gtk::Window *window) @@ -61,21 +49,24 @@ static void on_window_removed(Gtk::Window *window) int main(int argc, char **argv) { Gtk::Window *window; + gchar *ui = find_file_path("ocarina6.glade"); + gchar *icon = find_file_path("ocarina.png"); - setup_share(argv[0]); ocarina_app = Gtk::Application::create(argc, argv, "org.gtkmm.ocarina"); - gui_builder_init(gui :: share_file("ocarina6.glade").c_str()); - + gui_builder_init(ui); core_init(&argc, &argv, &init_data); gui_settings_init(); gui_view_init(); - gui_window_init(gui :: share_file("ocarina.png").c_str()); + gui_window_init(icon); gui_sidebar_init(); gui_collection_init(); gui_playlist_init(); gui_audio_init(); + g_free(ui); + g_free(icon); + window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false); ocarina_app->signal_window_removed().connect(sigc::ptr_fun(on_window_removed)); ocarina_app->run(*window, argc, argv); diff --git a/include/gui/ocarina.h b/include/gui/ocarina.h deleted file mode 100644 index 9d6fd52e..00000000 --- a/include/gui/ocarina.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2014 (c) Anna Schumaker. - */ -#ifndef OCARINA_H -#define OCARINA_H - -#include - - -/* main.cpp */ -namespace gui -{ - const std::string share_file(const std::string &); -} - - -#endif /* OCARINA_H */