diff --git a/gui/button.cpp b/gui/button.cpp index dcdd6808..5f80ce76 100644 --- a/gui/button.cpp +++ b/gui/button.cpp @@ -1,23 +1,10 @@ #include +#include + #include #include -static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d) -{ - libsaria_get()->play(); -} - -static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d) -{ - libsaria_get()->pause(); -} - -static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d) -{ - libsaria_get()->stop(); -} - static GtkWidget *make_button(const gchar *stockid, GtkIconSize size, void (* func)(GtkWidget *, GdkEvent *, gpointer)) { @@ -33,17 +20,43 @@ static GtkWidget *make_button(const gchar *stockid, GtkIconSize size, return button; } +static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d) +{ + libsaria_get()->play(); +} + GtkWidget *make_play_button(GtkIconSize size) { return make_button(GTK_STOCK_MEDIA_PLAY, size, on_click_play); } +static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d) +{ + libsaria_get()->pause(); +} + GtkWidget *make_pause_button(GtkIconSize size) { return make_button(GTK_STOCK_MEDIA_PAUSE, size, on_click_pause); } +static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d) +{ + libsaria_get()->stop(); +} + GtkWidget *make_stop_button(GtkIconSize size) { return make_button(GTK_STOCK_MEDIA_STOP, size, on_click_stop); } + +static void on_click_open_file(GtkWidget *b, GdkEvent *e, gpointer d) +{ + string file = ocarina_choose_file(); + print("Playing file: " + file); +} + +GtkWidget *make_open_button(GtkIconSize size) +{ + return make_button(GTK_STOCK_OPEN, size, on_click_open_file); +} diff --git a/gui/chooser.cpp b/gui/chooser.cpp new file mode 100644 index 00000000..97bf6557 --- /dev/null +++ b/gui/chooser.cpp @@ -0,0 +1,26 @@ + +#include +#include + +string ocarina_choose_file() +{ + GtkWidget *chooser = gtk_file_chooser_dialog_new( + "Open File", + NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + char *c_file; + string filename = ""; + + if ( gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_ACCEPT) { + c_file = gtk_file_chooser_get_filename( + GTK_FILE_CHOOSER(chooser)); + filename = c_file; + g_free(c_file); + } + gtk_widget_destroy(chooser); + return filename; +} + diff --git a/gui/ocarina.cpp b/gui/ocarina.cpp index eb46934d..028c7094 100644 --- a/gui/ocarina.cpp +++ b/gui/ocarina.cpp @@ -7,6 +7,7 @@ void ocarina_init(int argc, char **argv) { + GtkWidget *open; GtkWidget *play; GtkWidget *pause; GtkWidget *stop; @@ -17,10 +18,12 @@ void ocarina_init(int argc, char **argv) window_icon("images/ocarina.png"); hbox = gtk_hbox_new(FALSE, 0); + open = make_open_button(GTK_ICON_SIZE_MENU); play = make_play_button(GTK_ICON_SIZE_MENU); pause = make_pause_button(GTK_ICON_SIZE_MENU); stop = make_stop_button(GTK_ICON_SIZE_MENU); + box_pack_start(hbox, open, FALSE, FALSE, 0); box_pack_start(hbox, play, FALSE, FALSE, 0); box_pack_start(hbox, pause, FALSE, FALSE, 0); box_pack_start(hbox, stop, FALSE, FALSE, 0); diff --git a/include/ocarina/button.h b/include/ocarina/button.h index e96866d2..5a6e630a 100644 --- a/include/ocarina/button.h +++ b/include/ocarina/button.h @@ -9,5 +9,6 @@ using namespace std; GtkWidget *make_play_button(GtkIconSize); GtkWidget *make_pause_button(GtkIconSize); GtkWidget *make_stop_button(GtkIconSize); +GtkWidget *make_open_button(GtkIconSize); #endif /* OCARINA_BUTTON_H */ diff --git a/include/ocarina/chooser.h b/include/ocarina/chooser.h new file mode 100644 index 00000000..c9dba07d --- /dev/null +++ b/include/ocarina/chooser.h @@ -0,0 +1,9 @@ +#ifndef OCARINA_CHOOSER_H +#define OCARINA_CHOOSER_H + +#include +using namespace std; + +string ocarina_choose_file(); + +#endif