ocarina: Remove old button generating code and old footer
I now only have a single instance of the control buttons, so the old code can be removed now. The footer has been completely replaced by now. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
2f26e5b869
commit
cb663075bd
|
@ -16,24 +16,9 @@ GtkWidget *make_text_button(const gchar *stockid,
|
|||
bool show);
|
||||
|
||||
|
||||
GtkWidget *make_play_button();
|
||||
GtkWidget *make_pause_button();
|
||||
GtkWidget *make_stop_button();
|
||||
GtkWidget *make_rewind_button();
|
||||
GtkWidget *make_forward_button();
|
||||
GtkWidget *make_next_button();
|
||||
|
||||
GtkWidget *make_random_button();
|
||||
|
||||
GtkWidget *make_open_button();
|
||||
GtkWidget *make_volume_button();
|
||||
|
||||
enum button_list_t {
|
||||
PLAY_BUTTON_LIST,
|
||||
PAUSE_BUTTON_LIST,
|
||||
};
|
||||
|
||||
void show_button_list(button_list_t);
|
||||
void hide_button_list(button_list_t);
|
||||
|
||||
#endif /* OCARINA_BUTTON_H */
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <libsaria/track.h>
|
||||
|
||||
void footer_init();
|
||||
GtkWidget *get_footer();
|
||||
void change_footer(libsaria::Track *);
|
||||
|
||||
#endif /* OCARINA_FOOTER */
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <ocarina/header.h>
|
||||
#include <ocarina/footer.h>
|
||||
#include <libsaria/print.h>
|
||||
|
||||
static GtkWidget *tabs = NULL;
|
||||
|
||||
static void make_tabs()
|
||||
{
|
||||
tabs = gtk_notebook_new();
|
||||
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_LEFT);
|
||||
gtk_widget_show(tabs);
|
||||
}
|
||||
|
||||
GtkWidget *get_tabs()
|
||||
{
|
||||
if (tabs == NULL)
|
||||
make_tabs();
|
||||
return tabs;
|
||||
}
|
||||
|
||||
void push_page(GtkWidget *page, GtkWidget *label, bool fill)
|
||||
{
|
||||
gtk_notebook_prepend_page(GTK_NOTEBOOK(tabs), page, label);
|
||||
if (fill == true) {
|
||||
gtk_notebook_set_tab_label_packing(GTK_NOTEBOOK(tabs),
|
||||
page,
|
||||
TRUE,
|
||||
TRUE,
|
||||
GTK_PACK_START);
|
||||
}
|
||||
}
|
||||
|
||||
void remove_page(GtkWidget *page)
|
||||
{
|
||||
int pg_num = gtk_notebook_page_num(GTK_NOTEBOOK(tabs), page);
|
||||
gtk_notebook_remove_page(GTK_NOTEBOOK(tabs), pg_num);
|
||||
}
|
||||
|
||||
GtkWidget *make_page(GtkWidget *content)
|
||||
{
|
||||
GtkWidget *page = gtk_vbox_new(FALSE, 0);
|
||||
|
||||
box_pack_start(page, get_header(), FALSE, FALSE, 0);
|
||||
box_pack_start(page, content, TRUE, TRUE, 0);
|
||||
box_pack_start(page, get_footer(), FALSE, FALSE, 0);
|
||||
|
||||
gtk_widget_show(page);
|
||||
return page;
|
||||
};
|
||||
|
||||
void set_current_page(GtkWidget *page)
|
||||
{
|
||||
int pg_num = gtk_notebook_page_num(GTK_NOTEBOOK(tabs), page);
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(tabs), pg_num);
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
#include <ocarina/button.h>
|
||||
#include <libsaria/controls.h>
|
||||
#include <libsaria/audio.h>
|
||||
|
||||
static list<GtkWidget *> play_buttons;
|
||||
static list<GtkWidget *> pause_buttons;
|
||||
|
||||
static list<GtkWidget *> *get_buttons(button_list_t bttn_list)
|
||||
{
|
||||
switch(bttn_list) {
|
||||
case PLAY_BUTTON_LIST:
|
||||
return &play_buttons;
|
||||
default:
|
||||
return &pause_buttons;
|
||||
}
|
||||
}
|
||||
|
||||
void show_button_list(button_list_t bttn_list)
|
||||
{
|
||||
list<GtkWidget *>::iterator it;
|
||||
list<GtkWidget *> *buttons = get_buttons(bttn_list);
|
||||
for (it = buttons->begin(); it != buttons->end(); it++)
|
||||
gtk_widget_show(*it);
|
||||
}
|
||||
|
||||
void hide_button_list(button_list_t bttn_list)
|
||||
{
|
||||
list<GtkWidget *>::iterator it;
|
||||
list<GtkWidget *> *buttons = get_buttons(bttn_list);
|
||||
for (it = buttons->begin(); it != buttons->end(); it++)
|
||||
gtk_widget_hide(*it);
|
||||
}
|
||||
|
||||
static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
{
|
||||
//libsaria::audio::play();
|
||||
}
|
||||
|
||||
static void destroyed(GtkWidget *button, list<GtkWidget *> *widget_list)
|
||||
{
|
||||
widget_list->remove(button);
|
||||
}
|
||||
|
||||
GtkWidget *make_play_button()
|
||||
{
|
||||
GtkWidget *b = make_button(GTK_STOCK_MEDIA_PLAY,
|
||||
on_click_play,
|
||||
true);
|
||||
play_buttons.push_back(b);
|
||||
GTK_CONNECT(b, "destroy", destroyed, &play_buttons);
|
||||
return b;
|
||||
}
|
||||
|
||||
static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
{
|
||||
//libsaria::audio::pause();
|
||||
}
|
||||
|
||||
GtkWidget *make_pause_button()
|
||||
{
|
||||
GtkWidget *b = make_button(GTK_STOCK_MEDIA_PAUSE,
|
||||
on_click_pause,
|
||||
false);
|
||||
pause_buttons.push_back(b);
|
||||
GTK_CONNECT(b, "destroy", destroyed, &pause_buttons);
|
||||
return b;
|
||||
}
|
||||
|
||||
static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
{
|
||||
//libsaria::audio::stop();
|
||||
}
|
||||
|
||||
GtkWidget *make_stop_button()
|
||||
{
|
||||
return make_button(GTK_STOCK_MEDIA_STOP,
|
||||
on_click_stop,
|
||||
true);
|
||||
}
|
||||
|
||||
static void on_click_rewind(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
{
|
||||
//libsaria::audio::seek(-5);
|
||||
}
|
||||
|
||||
GtkWidget *make_rewind_button()
|
||||
{
|
||||
return make_button(GTK_STOCK_MEDIA_REWIND,
|
||||
on_click_rewind,
|
||||
true);
|
||||
}
|
||||
|
||||
static void on_click_forward(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
{
|
||||
//libsaria::audio::seek(5);
|
||||
}
|
||||
|
||||
GtkWidget *make_forward_button()
|
||||
{
|
||||
return make_button(GTK_STOCK_MEDIA_FORWARD,
|
||||
on_click_forward,
|
||||
true);
|
||||
}
|
||||
|
||||
static void on_click_next(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
{
|
||||
//libsaria::next();
|
||||
}
|
||||
|
||||
GtkWidget *make_next_button()
|
||||
{
|
||||
return make_button(GTK_STOCK_MEDIA_NEXT,
|
||||
on_click_next,
|
||||
true);
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <ocarina/button.h>
|
||||
#include <ocarina/shortcut.h>
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/controls.h>
|
||||
#include "footer.h"
|
||||
|
||||
static GtkWidget *make_buttons()
|
||||
{
|
||||
GtkWidget *buttons = gtk_hbox_new(FALSE, 0);
|
||||
gtk_widget_show(buttons);
|
||||
|
||||
box_pack_end(buttons, make_next_button(), FALSE, FALSE, 0);
|
||||
box_pack_end(buttons, make_stop_button(), FALSE, FALSE, 0);
|
||||
box_pack_end(buttons, make_pause_button(), FALSE, FALSE, 0);
|
||||
box_pack_end(buttons, make_play_button(), FALSE, FALSE, 0);
|
||||
box_pack_end(buttons, make_forward_button(), FALSE, FALSE, 0);
|
||||
box_pack_end(buttons, make_rewind_button(), FALSE, FALSE, 0);
|
||||
|
||||
return buttons;
|
||||
}
|
||||
|
||||
/*static void toggle_pause_after()
|
||||
{
|
||||
libsaria::set_pause_after(!libsaria::get_pause_after());
|
||||
}*/
|
||||
|
||||
GtkWidget *get_controls()
|
||||
{
|
||||
GtkWidget *controls = gtk_vbox_new(FALSE, 0);
|
||||
gtk_widget_show(controls);
|
||||
/*
|
||||
* Putting the button hbox into a vbox will keep them from
|
||||
* expanding vertically to take up all the space.
|
||||
*/
|
||||
box_pack_start(controls, make_buttons(), TRUE, FALSE, 0);
|
||||
return controls;
|
||||
}
|
||||
|
||||
void controls_init()
|
||||
{
|
||||
/*register_shortcut("Left", libsaria::rewind);
|
||||
register_shortcut("Right", libsaria::forward);
|
||||
register_shortcut("space", libsaria::toggle_play);
|
||||
register_shortcut("n", libsaria::next);
|
||||
register_shortcut("s", libsaria::audio::stop);
|
||||
register_shortcut("p", toggle_pause_after);*/
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <ocarina/footer.h>
|
||||
#include "footer.h"
|
||||
|
||||
GtkWidget *get_footer()
|
||||
{
|
||||
GtkWidget *footer = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *sep = gtk_hseparator_new();
|
||||
GtkWidget *content = gtk_hbox_new(FALSE, 5);
|
||||
|
||||
box_pack_start(footer, sep, FALSE, FALSE, 0);
|
||||
box_pack_start(footer, get_progress(), FALSE, FALSE, 0);
|
||||
box_pack_start(footer, content, FALSE, FALSE, 0);
|
||||
|
||||
/*
|
||||
* The pause button begins life hidden, so show everything up until
|
||||
* this point, and then add the controls
|
||||
*/
|
||||
gtk_widget_show_all(footer);
|
||||
|
||||
box_pack_start(content, get_nowplaying(), TRUE, TRUE, 0);
|
||||
box_pack_start(content, get_controls(), FALSE, FALSE, 0);
|
||||
|
||||
return footer;
|
||||
}
|
||||
|
||||
void change_footer(libsaria::Track *track)
|
||||
{
|
||||
set_now_playing(track);
|
||||
}
|
||||
|
||||
void footer_init()
|
||||
{
|
||||
controls_init();
|
||||
progress_init();
|
||||
nowplaying_init();
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef OCARINA_FOOTER_PRIVATE_H
|
||||
#define OCARINA_FOOTER_PRIVATE_H
|
||||
|
||||
#include <libsaria/track.h>
|
||||
|
||||
GtkWidget *get_controls();
|
||||
GtkWidget *get_nowplaying();
|
||||
GtkWidget *get_progress();
|
||||
|
||||
void progress_init();
|
||||
void controls_init();
|
||||
void nowplaying_init();
|
||||
void set_now_playing(libsaria::Track *);
|
||||
|
||||
#endif /* OCARINA_FOOTER_PRIVATE_H */
|
|
@ -1,124 +0,0 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <libsaria/track.h>
|
||||
#include <ocarina/ocarina.h>
|
||||
#include "footer.h"
|
||||
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
struct NowPlayingWidgets {
|
||||
GtkWidget *title;
|
||||
GtkWidget *artist;
|
||||
GtkWidget *album;
|
||||
};
|
||||
|
||||
static list<NowPlayingWidgets> nowplaying_widgets;
|
||||
|
||||
static void set_label(GtkWidget *label, string text, string size)
|
||||
{
|
||||
char *escaped = g_markup_escape_text(text.c_str(), -1);
|
||||
string markup = "<span size='" + size + "'>" + escaped + "</span>";
|
||||
gtk_label_set_markup(GTK_LABEL(label), markup.c_str());
|
||||
g_free(escaped);
|
||||
}
|
||||
|
||||
static void set_now_playing(struct NowPlayingWidgets *widgets, string title,
|
||||
string artist, string album)
|
||||
{
|
||||
if (artist != "")
|
||||
artist = "by " + artist;
|
||||
|
||||
if (album != "")
|
||||
album = "from " + album;
|
||||
|
||||
set_label(widgets->title, title, "xx-large");
|
||||
set_label(widgets->artist, artist, "x-large");
|
||||
set_label(widgets->album, album, "x-large");
|
||||
}
|
||||
|
||||
static GtkWidget *align(GtkWidget *label)
|
||||
{
|
||||
GtkWidget *alignment = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
|
||||
container_add(alignment, label);
|
||||
return alignment;
|
||||
}
|
||||
|
||||
static GtkWidget *setup_window(GtkWidget *box)
|
||||
{
|
||||
GtkWidget *viewport = gtk_viewport_new(NULL, NULL);
|
||||
GtkWidget *window = gtk_scrolled_window_new(NULL, NULL);
|
||||
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
|
||||
container_add(viewport, box);
|
||||
container_add(window, viewport);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
static void destroyed(GtkWidget *title, gpointer data)
|
||||
{
|
||||
list<NowPlayingWidgets>::iterator it;
|
||||
for (it = nowplaying_widgets.begin(); it != nowplaying_widgets.end(); it++) {
|
||||
if ((*it).title == title) {
|
||||
nowplaying_widgets.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GtkWidget *get_nowplaying()
|
||||
{
|
||||
struct NowPlayingWidgets widgets;
|
||||
GtkWidget *box = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *window = setup_window(box);
|
||||
|
||||
widgets.title = gtk_label_new("");
|
||||
widgets.artist = gtk_label_new("");
|
||||
widgets.album = gtk_label_new("");
|
||||
|
||||
GTK_CONNECT(widgets.title, "destroy", destroyed, NULL);
|
||||
set_now_playing(&widgets, "", "", "");
|
||||
|
||||
box_pack_start(box, align(widgets.title), TRUE, FALSE, 0);
|
||||
box_pack_start(box, align(widgets.artist), TRUE, FALSE, 0);
|
||||
box_pack_start(box, align(widgets.album), TRUE, FALSE, 0);
|
||||
|
||||
nowplaying_widgets.push_back(widgets);
|
||||
gtk_widget_show_all(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
/*
|
||||
* This takes some explanation, so...
|
||||
* During startup, all the labels are set to the empty string. This
|
||||
* causes them to initially be rendered blank. This normally isn't
|
||||
* a problem BUT the three widgets placed on the settings tab don't have
|
||||
* a call to gtk_widget_show() once the page is added to the notebook and
|
||||
* for some reason switching tabs isn't enough to realize the widgets.
|
||||
* As a result, only the very beginning of the widget gets updated (as in,
|
||||
* you could see half of a "T" if you start ocarina, click "next" and then
|
||||
* switch to the settings tab). Realizing just one of the widgets before
|
||||
* trying to use them seems to fix the problem, so that's what I'm doing
|
||||
* here.
|
||||
*/
|
||||
void nowplaying_init()
|
||||
{
|
||||
list<struct NowPlayingWidgets>::iterator it;
|
||||
for (it = nowplaying_widgets.begin(); it != nowplaying_widgets.end(); it++)
|
||||
gtk_widget_realize(it->title);
|
||||
}
|
||||
|
||||
void set_now_playing(libsaria::Track *track)
|
||||
{
|
||||
list<struct NowPlayingWidgets>::iterator it;
|
||||
|
||||
/*for (it = nowplaying_widgets.begin(); it != nowplaying_widgets.end(); it++) {
|
||||
set_now_playing(&(*it),
|
||||
track->get_title(),
|
||||
track->get_artist(),
|
||||
track->get_album());
|
||||
};*/
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/print.h>
|
||||
#include "footer.h"
|
||||
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
struct ProgressWidgets {
|
||||
GtkWidget *position;
|
||||
GtkWidget *duration;
|
||||
GtkWidget *progress;
|
||||
};
|
||||
|
||||
static list<ProgressWidgets> widget_list;
|
||||
|
||||
static gboolean update_progress(struct ProgressWidgets *widgets)
|
||||
{
|
||||
/*gint64 pos = libsaria::audio::position();
|
||||
gint64 dur = libsaria::audio::duration() + 1;
|
||||
|
||||
gtk_label_set_text(GTK_LABEL(widgets->position), libsaria::audio::posstr().c_str());
|
||||
gtk_label_set_text(GTK_LABEL(widgets->duration), libsaria::audio::durstr().c_str());*/
|
||||
|
||||
/*
|
||||
* This happens when gstreamer's "about-to-finish" signal
|
||||
* is emitted and we queue up a shorter song before the
|
||||
* pipeline finishes.
|
||||
*/
|
||||
/*if (pos > dur)
|
||||
pos = 0;
|
||||
gtk_range_set_range(GTK_RANGE(widgets->progress), 0, dur);
|
||||
gtk_range_set_value(GTK_RANGE(widgets->progress), pos);*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean update_progress_widgets(gpointer data)
|
||||
{
|
||||
list<ProgressWidgets>::iterator it;
|
||||
for (it = widget_list.begin(); it != widget_list.end(); it++)
|
||||
update_progress(&(*it));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void progress_init()
|
||||
{
|
||||
gtk_timeout_add(100, update_progress_widgets, NULL);
|
||||
}
|
||||
|
||||
static void slider_changed(GtkWidget *slider, GtkScrollType scroll,
|
||||
gdouble value, gpointer data)
|
||||
{
|
||||
//libsaria::audio::seek_to(value);
|
||||
}
|
||||
|
||||
static GtkWidget *make_scale()
|
||||
{
|
||||
GtkWidget *scale = gtk_hscale_new_with_range(0, 1, 1000000000);
|
||||
gtk_scale_set_draw_value(GTK_SCALE(scale), FALSE);
|
||||
GTK_CONNECT(scale, "change-value", slider_changed, NULL);
|
||||
return scale;
|
||||
}
|
||||
|
||||
void destroyed(GtkWidget *position, gpointer data)
|
||||
{
|
||||
list<ProgressWidgets>::iterator it;
|
||||
for (it = widget_list.begin(); it != widget_list.end(); it++) {
|
||||
if ((*it).position == position) {
|
||||
widget_list.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GtkWidget *get_progress()
|
||||
{
|
||||
struct ProgressWidgets widgets;
|
||||
GtkWidget *box = gtk_hbox_new(FALSE, 0);
|
||||
widgets.position = gtk_label_new("");
|
||||
widgets.duration = gtk_label_new("");
|
||||
widgets.progress = make_scale();
|
||||
|
||||
GTK_CONNECT(widgets.position, "destroy", destroyed, NULL);
|
||||
|
||||
box_pack_start(box, widgets.position, FALSE, FALSE, 0);
|
||||
box_pack_start(box, widgets.progress, TRUE, TRUE, 0);
|
||||
box_pack_start(box, widgets.duration, FALSE, FALSE, 0);
|
||||
|
||||
gtk_widget_show_all(box);
|
||||
widget_list.push_back(widgets);
|
||||
return box;
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
#include <ocarina/ocarina.h>
|
||||
|
||||
static GtkWidget *settings_tabs = NULL;
|
||||
static GtkWidget *settings_page = NULL;
|
||||
//static GtkWidget *settings_page = NULL;
|
||||
|
||||
void settings_init()
|
||||
{
|
||||
|
@ -14,8 +14,8 @@ void settings_init()
|
|||
|
||||
gtk_widget_show(image);
|
||||
gtk_widget_show(settings_tabs);
|
||||
settings_page = make_page(settings_tabs);
|
||||
push_page(settings_page, image, false);
|
||||
//settings_page = make_page(settings_tabs);
|
||||
//push_page(settings_page, image, false);
|
||||
|
||||
general_settings_init();
|
||||
library_settings_init();
|
||||
|
|
|
@ -143,14 +143,14 @@ GtkWidget *SongList::init(string text, list <MenuItem> *menu, bool enable_filter
|
|||
gtk_widget_show(label);
|
||||
gtk_widget_show_all(window);
|
||||
|
||||
page = make_page(window);
|
||||
push_page(page, label, true);
|
||||
//page = make_page(window);
|
||||
//push_page(page, label, true);
|
||||
return page;
|
||||
}
|
||||
|
||||
void SongList::on_playlist_empty()
|
||||
{
|
||||
if (page)
|
||||
remove_page(page);
|
||||
/*if (page)
|
||||
remove_page(page);*/
|
||||
page = NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue