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 <Anna@OcarinaProject.net>
This commit is contained in:
parent
2c65584e2d
commit
108dbacf41
|
@ -15,10 +15,10 @@ extern "C" {
|
|||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
}
|
||||
#include <gui/ocarina.h>
|
||||
#include <gtkmm.h>
|
||||
#include <glib.h>
|
||||
|
||||
|
||||
static std::string ocarina_dir = "";
|
||||
static Glib::RefPtr<Gtk::Application> 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);
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_H
|
||||
#define OCARINA_H
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
|
||||
/* main.cpp */
|
||||
namespace gui
|
||||
{
|
||||
const std::string share_file(const std::string &);
|
||||
}
|
||||
|
||||
|
||||
#endif /* OCARINA_H */
|
Loading…
Reference in New Issue