ocarina: Create a FileChooser dialog

I use this to select songs anywhere in the filesystem, not necessarily
in the library.  I also renamed LibraryPathChooser to DirectoryChooser.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-08-17 08:08:30 -04:00
parent 22694e1bfe
commit 2221bca25e
4 changed files with 107 additions and 30 deletions

View File

@ -10,18 +10,16 @@
using namespace std;
static GtkWidget *tabs;
static GtkWidget *action_box;
static GtkWidget *open_button;
static map<GtkWidget *, libsaria::Playlist *> tab_mapping;
/*static void on_click_open_file(GtkWidget *b, gpointer d)
static void on_click_open(GtkWidget *b, gpointer d)
{
string file = ocarina::choose_file();
string file = run_chooser("FileChooser");
if (file != "") {
println("Playing file: " + file);
libsaria::play_outside_song(file);
}
}*/
}
static void on_page_reordered(GtkWidget *t, GtkWidget *page, guint num, gpointer d)
{
@ -31,9 +29,27 @@ static void on_page_reordered(GtkWidget *t, GtkWidget *page, guint num, gpointer
gtk_notebook_reorder_child(GTK_NOTEBOOK(tabs), page, n);
}
static GtkWidget *init_playlist_action()
{
GtkWidget *box = gtk_vbox_new(FALSE, 0);
GtkWidget *open_button = gtk_button_new();
GtkWidget *open_icon = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
gtk_container_add(GTK_CONTAINER(open_button), open_icon);
gtk_box_pack_start(GTK_BOX(box), open_button, false, false, 0);
gtk_widget_show_all(box);
g_signal_connect(open_button, "clicked", G_CALLBACK(on_click_open), NULL);
return box;
}
void init_playlist()
{
tabs = get_widget("PlaylistTabs");
gtk_notebook_set_action_widget(GTK_NOTEBOOK(tabs),
init_playlist_action(),
GTK_PACK_END);
}
namespace ocarina
@ -42,20 +58,13 @@ namespace ocarina
GtkWidget *body::playlist_init()
{
tabs = gtk_notebook_new();
action_box = gtk_vbox_new(FALSE, 0);
//open_button = make_larger_button(GTK_STOCK_OPEN, on_click_open_file, true);
gtk_box_pack_start(GTK_BOX(action_box), open_button, FALSE, FALSE, 0);
gtk_notebook_set_scrollable(GTK_NOTEBOOK(tabs), true);
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_LEFT);
gtk_notebook_set_action_widget(GTK_NOTEBOOK(tabs), action_box, GTK_PACK_END);
g_signal_connect(tabs, "page-reordered", G_CALLBACK(on_page_reordered), NULL);
g_object_set(tabs, "tab-border", 0, NULL);
gtk_widget_show(tabs);
gtk_widget_show(action_box);
return tabs;
};

View File

@ -98,7 +98,7 @@ void LibraryDriver::path_removed(libsaria::library::Path *path)
static void add_library(GtkWidget *b, gpointer d)
{
string dir = run_chooser("LibraryPathChooser");
string dir = run_chooser("DirectoryChooser");
if (dir != "") {
println("Scanning dir: " + dir);
libsaria::library::add_path(dir);

View File

@ -120,6 +120,10 @@ static void init(int argc, char **argv)
init_playlist();
init_status();
/*gtk_notebook_set_action_widget(GTK_NOTEBOOK(get_widget("PlaylistTabs")),
get_widget("ActionWidget"),
GTK_PACK_START);*/
/* Connect signals */
connect_signal("PlayButton", "clicked", libsaria::audio::play, NULL);
connect_signal("PauseButton", "clicked", libsaria::audio::pause, NULL);

View File

@ -2,20 +2,8 @@
<interface>
<!-- interface-requires gtk+ 3.0 -->
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkListStore" id="LibraryList">
<columns>
<!-- column-name Pointer -->
<column type="gpointer"/>
<!-- column-name Enabled -->
<column type="gboolean"/>
<!-- column-name Path1 -->
<column type="gchararray"/>
<!-- column-name Size -->
<column type="guint"/>
</columns>
</object>
<object class="GtkAction" id="action1"/>
<object class="GtkFileChooserDialog" id="LibraryPathChooser">
<object class="GtkFileChooserDialog" id="DirectoryChooser">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Choose a directory</property>
@ -34,7 +22,7 @@
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button1">
<object class="GtkButton" id="DirectoryCancelButton">
<property name="label">gtk-cancel</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
@ -49,7 +37,7 @@
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<object class="GtkButton" id="DirectoryOpenButton">
<property name="label">gtk-open</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
@ -77,10 +65,86 @@
</object>
</child>
<action-widgets>
<action-widget response="-6">button1</action-widget>
<action-widget response="-5">button2</action-widget>
<action-widget response="-6">DirectoryCancelButton</action-widget>
<action-widget response="-5">DirectoryOpenButton</action-widget>
</action-widgets>
</object>
<object class="GtkFileChooserDialog" id="FileChooser">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Choose a file</property>
<property name="role">GtkFileChooserDialog</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="FileCancelButton">
<property name="label">gtk-cancel</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="FileOpenButton">
<property name="label">gtk-open</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">FileCancelButton</action-widget>
<action-widget response="-5">FileOpenButton</action-widget>
</action-widgets>
</object>
<object class="GtkListStore" id="LibraryList">
<columns>
<!-- column-name Pointer -->
<column type="gpointer"/>
<!-- column-name Enabled -->
<column type="gboolean"/>
<!-- column-name Path1 -->
<column type="gchararray"/>
<!-- column-name Size -->
<column type="guint"/>
</columns>
</object>
<object class="GtkAdjustment" id="PauseAdjustment">
<property name="upper">256</property>
<property name="step_increment">1</property>