ocarina: Show the length of the currently visible playlist
I should eventually format this better... Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
e0ebe4c97f
commit
fcc48dbccb
|
@ -25,6 +25,7 @@ namespace ocarina
|
|||
|
||||
void set_now_playing();
|
||||
void update_controls();
|
||||
void set_length_label_text(string &);
|
||||
|
||||
GtkWidget *playlist_init();
|
||||
GtkWidget *footer_init();
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace ocarina
|
|||
|
||||
class Playlist : public libsaria::PlaylistRenderer {
|
||||
private:
|
||||
bool visible;
|
||||
GtkWidget *label;
|
||||
GtkWidget *box;
|
||||
GtkWidget *treeview;
|
||||
|
@ -17,6 +18,7 @@ namespace ocarina
|
|||
GtkTreeSelection *treesel;
|
||||
|
||||
void set_label_text();
|
||||
void set_length_label_text();
|
||||
void setup_treeview();
|
||||
|
||||
public:
|
||||
|
@ -24,6 +26,8 @@ namespace ocarina
|
|||
Playlist(libsaria::Playlist *);
|
||||
~Playlist();
|
||||
|
||||
void on_show();
|
||||
void on_hide();
|
||||
void switch_to();
|
||||
void right_click(guint, guint64);
|
||||
void select_none();
|
||||
|
|
|
@ -16,6 +16,7 @@ static GtkWidget *pause_button;
|
|||
static GtkWidget *stop_button;
|
||||
static GtkWidget *prev_button;
|
||||
static GtkWidget *next_button;
|
||||
static GtkWidget *length_label;
|
||||
static GstState last_state;
|
||||
|
||||
static void add_page(string text, GtkWidget *page)
|
||||
|
@ -120,12 +121,16 @@ namespace ocarina
|
|||
GtkWidget *footer = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *controls = make_controls();
|
||||
notebook = gtk_notebook_new();
|
||||
length_label = gtk_label_new("");
|
||||
|
||||
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
|
||||
g_object_set(notebook, "tab-border", 0, NULL);
|
||||
|
||||
gtk_misc_set_alignment(GTK_MISC(length_label), 1.0, 0.0);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(footer), controls, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(footer), notebook, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(footer), length_label, FALSE, FALSE, 0);
|
||||
|
||||
add_page("Now Playing", now_playing_page());
|
||||
add_page("Library", library_page());
|
||||
|
@ -133,6 +138,7 @@ namespace ocarina
|
|||
|
||||
gtk_widget_show(footer);
|
||||
gtk_widget_show(notebook);
|
||||
gtk_widget_show(length_label);
|
||||
return footer;
|
||||
};
|
||||
|
||||
|
@ -167,4 +173,9 @@ namespace ocarina
|
|||
}
|
||||
}
|
||||
|
||||
void body::set_length_label_text(string &text)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(length_label), text.c_str());
|
||||
}
|
||||
|
||||
}; /* Namespace: ocarina */
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace ocarina
|
|||
|
||||
Playlist::Playlist(unsigned int f) : libsaria::PlaylistRenderer(f)
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
Playlist::Playlist(libsaria::Playlist *plist): libsaria::PlaylistRenderer(PL_NONE)
|
||||
|
@ -33,6 +34,18 @@ namespace ocarina
|
|||
{
|
||||
}
|
||||
|
||||
void Playlist::set_length_label_text()
|
||||
{
|
||||
string text;
|
||||
stringstream stream;
|
||||
stream << playlist->get_size() << " ";
|
||||
stream << "songs, " << playlist->get_length();
|
||||
stream << " seconds";
|
||||
|
||||
text = stream.str();
|
||||
body::set_length_label_text(text);
|
||||
}
|
||||
|
||||
void Playlist::set_label_text()
|
||||
{
|
||||
string text;
|
||||
|
@ -43,6 +56,8 @@ namespace ocarina
|
|||
text = stream.str();
|
||||
|
||||
gtk_label_set_text(GTK_LABEL(label), text.c_str());
|
||||
if (visible)
|
||||
set_length_label_text();
|
||||
}
|
||||
|
||||
void Playlist::list_selected_tracks(list<libsaria::Track *> &tracks)
|
||||
|
@ -60,6 +75,17 @@ namespace ocarina
|
|||
body::switch_to_page(box);
|
||||
}
|
||||
|
||||
void Playlist::on_show()
|
||||
{
|
||||
visible = true;
|
||||
set_length_label_text();
|
||||
}
|
||||
|
||||
void Playlist::on_hide()
|
||||
{
|
||||
visible = false;
|
||||
}
|
||||
|
||||
void Playlist::goto_index(unsigned int index)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
|
|
@ -78,6 +78,18 @@ static GtkListStore *setup_liststore(GtkWidget *treeview)
|
|||
return liststore;
|
||||
}
|
||||
|
||||
static void mapped(GtkWidget *widget, gpointer data)
|
||||
{
|
||||
ocarina::Playlist *plist = (ocarina::Playlist *)data;
|
||||
plist->on_show();
|
||||
}
|
||||
|
||||
static void unmapped(GtkWidget *widget, gpointer data)
|
||||
{
|
||||
ocarina::Playlist *plist = (ocarina::Playlist *)data;
|
||||
plist->on_hide();
|
||||
}
|
||||
|
||||
namespace ocarina
|
||||
{
|
||||
|
||||
|
@ -94,6 +106,8 @@ namespace ocarina
|
|||
g_signal_connect(treeview, "row-activated", G_CALLBACK(track_selected), NULL);
|
||||
g_signal_connect(treeview, "button-release-event", G_CALLBACK(show_rc_menu), this);
|
||||
g_signal_connect(treeview, "key-press-event", G_CALLBACK(key_pressed), this);
|
||||
g_signal_connect(treeview, "map", G_CALLBACK(mapped), this);
|
||||
g_signal_connect(treeview, "unmap", G_CALLBACK(unmapped), this);
|
||||
|
||||
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(liststore));
|
||||
|
|
Loading…
Reference in New Issue