f6cb19145d
I only have one application so there is no point in having a way to create multiple application directories. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
175 lines
3.9 KiB
C++
175 lines
3.9 KiB
C++
// Copyright (c) 2011 Bryan Schumaker
|
|
#include <version.h>
|
|
#include <libsaria.h>
|
|
#include <notify.h>
|
|
#include <audio.h>
|
|
#include <deck.h>
|
|
#include <idle.h>
|
|
|
|
#include "ocarina.h"
|
|
|
|
static string lib_path;
|
|
static GtkBuilder *builder;
|
|
static GtkWidget *ban_button;
|
|
static GtkWidget *yes_image;
|
|
static GtkWidget *no_image;
|
|
|
|
static void find_exe_path(string &res)
|
|
{
|
|
char buf[1024];
|
|
ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) -1);
|
|
if (len != -1)
|
|
res = string(buf);
|
|
}
|
|
|
|
static void rstrip_word(string &path)
|
|
{
|
|
unsigned int index = path.rfind("/");
|
|
if (index != string::npos)
|
|
path = path.substr(0, index);
|
|
}
|
|
|
|
static void find_lib_path()
|
|
{
|
|
string exe;
|
|
|
|
find_exe_path(exe);
|
|
if (exe == "")
|
|
return;
|
|
|
|
rstrip_word(exe); // ocarina-player
|
|
rstrip_word(exe); // bin/
|
|
|
|
lib_path = exe + "/lib/ocarina";
|
|
println("Lib directory? %s", lib_path.c_str());
|
|
}
|
|
|
|
string lib_file(const string &path)
|
|
{
|
|
string res = lib_path + "/" + path;
|
|
println("Expanding to path: " + res);
|
|
return res;
|
|
}
|
|
|
|
gboolean ocarina_idle(gpointer data)
|
|
{
|
|
int size = libsaria::idle::run_task();
|
|
return update_idle_bar(size);
|
|
}
|
|
|
|
static gboolean timeout_poll(gpointer data)
|
|
{
|
|
update_progress();
|
|
return TRUE;
|
|
}
|
|
|
|
GObject *get_object(const string &name)
|
|
{
|
|
/* TODO: Figure out GtkNotebook action area in GtkBuilder */
|
|
if (name == "BanButton")
|
|
return G_OBJECT(ban_button);
|
|
else if (name == "YesImage")
|
|
return G_OBJECT(yes_image);
|
|
else if (name == "NoImage")
|
|
return G_OBJECT(no_image);
|
|
return gtk_builder_get_object(builder, name.c_str());
|
|
}
|
|
|
|
GtkWidget *get_widget(const string &name)
|
|
{
|
|
GtkWidget *widget = GTK_WIDGET(get_object(name));
|
|
if (!widget)
|
|
println(name + " is not a widget!");
|
|
return widget;
|
|
}
|
|
|
|
void connect_signal(const string &name, const string &signal, GCallback func, void *data)
|
|
{
|
|
GObject *widget = get_object(name);
|
|
if (widget)
|
|
g_signal_connect(widget, signal.c_str(), func, data);
|
|
}
|
|
|
|
string run_chooser(const string &name)
|
|
{
|
|
char *file;
|
|
string filename = "";
|
|
GtkWidget *chooser = get_widget(name);
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_OK) {
|
|
file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser));
|
|
filename = file;
|
|
g_free(file);
|
|
}
|
|
gtk_widget_hide(chooser);
|
|
return filename;
|
|
}
|
|
|
|
static void init_widgets()
|
|
{
|
|
ban_button = gtk_toggle_button_new();
|
|
yes_image = gtk_image_new_from_file(lib_file("thumbs_up.png").c_str());
|
|
no_image = gtk_image_new_from_file(lib_file("thumbs_down.png").c_str());
|
|
gtk_button_set_image(GTK_BUTTON(ban_button), yes_image);
|
|
|
|
/* Prevent widgets from being destroyed when toggling banned button */
|
|
g_object_ref(yes_image);
|
|
g_object_ref(no_image);
|
|
}
|
|
|
|
static void init(int argc, char **argv)
|
|
{
|
|
gtk_init(&argc, &argv);
|
|
|
|
builder = gtk_builder_new();
|
|
gtk_builder_add_from_file(builder, lib_file("ocarina.xml").c_str(), NULL);
|
|
|
|
/* Set up small button style */
|
|
gtk_rc_parse_string(
|
|
"style \"small-button-style\"\n"
|
|
"{\n"
|
|
" GtkButton::inner-border = {0,0,0,0}\n"
|
|
"}\n"
|
|
"widget \"*.ocarina-small-button\" style \"small-button-style\"");
|
|
|
|
/* Initialize widgets static to this file */
|
|
init_widgets();
|
|
|
|
/* Other setup */
|
|
init_window();
|
|
init_library();
|
|
init_tabs();
|
|
init_playlist();
|
|
init_status();
|
|
init_pipe();
|
|
|
|
/* Connect signals */
|
|
connect_signal("PlayButton", "clicked", libsaria::audio::play, NULL);
|
|
connect_signal("PauseButton", "clicked", libsaria::audio::pause, NULL);
|
|
connect_signal("StopButton", "clicked", libsaria::audio::stop, NULL);
|
|
connect_signal("PrevButton", "clicked", libsaria::deck::prev, NULL);
|
|
connect_signal("NextButton", "clicked", libsaria::deck::next, NULL);
|
|
|
|
/* Show any widgets that need showing */
|
|
gtk_timeout_add(250, timeout_poll, NULL);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
struct libsaria::initdata ls_init = {
|
|
argc,
|
|
argv,
|
|
on_notify, /* notification handler */
|
|
};
|
|
println("Ocarina " + vers_str());
|
|
find_lib_path();
|
|
|
|
libsaria::init(&ls_init);
|
|
init(argc, argv);
|
|
|
|
gtk_main();
|
|
libsaria::quit();
|
|
|
|
return 0;
|
|
}
|