Ban songs in the library
Right now, this just toggles the "banned" field in the Track class and then skips to the next track. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
e8e8589614
commit
bb7a662f92
|
@ -59,6 +59,9 @@ namespace libsaria
|
|||
unsigned int &get_track();
|
||||
unsigned int &get_libid();
|
||||
unsigned int &get_id();
|
||||
bool &get_banned();
|
||||
|
||||
void set_banned(bool);
|
||||
|
||||
bool operator<(Track &);
|
||||
};
|
||||
|
|
|
@ -6,6 +6,8 @@ using namespace std;
|
|||
|
||||
#include <ocarina/ocarina.h>
|
||||
|
||||
GtkWidget *get_image(const gchar *stockid, GtkIconSize size);
|
||||
|
||||
GtkWidget *make_button_data(const gchar *stockid,
|
||||
void (* func)(GtkWidget *, gpointer),
|
||||
gpointer data,
|
||||
|
@ -24,6 +26,10 @@ GtkWidget *make_text_button(const gchar *stockid,
|
|||
void (* func)(GtkWidget *, gpointer),
|
||||
bool show);
|
||||
|
||||
GtkWidget *make_toggle_button(const gchar *stockid,
|
||||
void (* func)(GtkWidget *, gpointer),
|
||||
bool show);
|
||||
|
||||
|
||||
GtkWidget *make_random_button();
|
||||
GtkWidget *make_volume_button();
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
|
|
@ -54,4 +54,9 @@ namespace libsaria
|
|||
return path->id;
|
||||
}
|
||||
|
||||
bool &Track::get_banned()
|
||||
{
|
||||
return banned;
|
||||
}
|
||||
|
||||
} /* Namespace: libsaria */
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker.
|
||||
#include <libsaria/track.h>
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void Track::set_banned(bool state)
|
||||
{
|
||||
banned = state;
|
||||
path->data_state = DIRTY;
|
||||
libsaria::library::save_path(path);
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
|
@ -1,13 +1,17 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <ocarina/button.h>
|
||||
#include <ocarina/body.h>
|
||||
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/deck.h>
|
||||
|
||||
static libsaria::Track *current = NULL;
|
||||
static GtkWidget *title;
|
||||
static GtkWidget *artist;
|
||||
static GtkWidget *album;
|
||||
static GtkWidget *ban;
|
||||
static bool ignore_ban = false;
|
||||
|
||||
static void set_label(GtkWidget *label, string text, string size)
|
||||
{
|
||||
|
@ -35,33 +39,68 @@ static GtkWidget *align(GtkWidget *w)
|
|||
return alignment;
|
||||
}
|
||||
|
||||
static GtkWidget *make_tag_labels()
|
||||
{
|
||||
GtkWidget *box = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *window = gtk_scrolled_window_new(NULL, NULL);
|
||||
GtkWidget *viewport = gtk_viewport_new(NULL, NULL);
|
||||
|
||||
title = gtk_label_new("");
|
||||
artist = gtk_label_new("");
|
||||
album = gtk_label_new("");
|
||||
|
||||
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);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(viewport), box);
|
||||
gtk_container_add(GTK_CONTAINER(window), viewport);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(box), align(title), TRUE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), align(artist), TRUE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), align(album), TRUE, FALSE, 0);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
static void on_ban(GtkWidget *w, gpointer d)
|
||||
{
|
||||
bool banned;
|
||||
|
||||
if (ignore_ban) {
|
||||
ignore_ban = false;
|
||||
return;
|
||||
}
|
||||
|
||||
banned = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ban));
|
||||
current->set_banned(banned);
|
||||
if (banned)
|
||||
libsaria::deck::next();
|
||||
}
|
||||
|
||||
static GtkWidget *make_buttons()
|
||||
{
|
||||
GtkWidget *box = gtk_vbox_new(FALSE, 0);
|
||||
ban = make_toggle_button(GTK_STOCK_DIALOG_ERROR, on_ban, true);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(box), ban, FALSE, FALSE, 0);
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
namespace ocarina
|
||||
{
|
||||
|
||||
GtkWidget *body::now_playing_page()
|
||||
{
|
||||
GtkWidget *box = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *window = gtk_scrolled_window_new(NULL, NULL);
|
||||
GtkWidget *viewport = gtk_viewport_new(NULL, NULL);
|
||||
GtkWidget *box = gtk_hbox_new(FALSE, 0);
|
||||
|
||||
title = gtk_label_new("");
|
||||
artist = gtk_label_new("");
|
||||
album = gtk_label_new("");
|
||||
gtk_box_pack_start(GTK_BOX(box), make_tag_labels(), TRUE, TRUE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), make_buttons(), FALSE, FALSE, 0);
|
||||
gtk_widget_show_all(box);
|
||||
|
||||
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);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(viewport), box);
|
||||
gtk_container_add(GTK_CONTAINER(window), viewport);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(box), align(title), TRUE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), align(artist), TRUE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), align(album), TRUE, FALSE, 0);
|
||||
|
||||
gtk_widget_show_all(window);
|
||||
return window;
|
||||
return box;
|
||||
}
|
||||
|
||||
void body::set_now_playing()
|
||||
|
@ -72,6 +111,10 @@ namespace ocarina
|
|||
current = cur;
|
||||
refresh_widgets();
|
||||
update_automatic_pause();
|
||||
|
||||
ignore_ban = true;
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ban), current->get_banned());
|
||||
|
||||
println("Current track changed");
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ static GtkWidget *get_button(void (* func)(GtkWidget *, gpointer),
|
|||
return button;
|
||||
}
|
||||
|
||||
static GtkWidget *get_image(const gchar *stockid, GtkIconSize size)
|
||||
GtkWidget *get_image(const gchar *stockid, GtkIconSize size)
|
||||
{
|
||||
GtkWidget *img = gtk_image_new_from_stock(stockid, size);
|
||||
gtk_widget_show(img);
|
||||
|
|
|
@ -1,49 +1,21 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <ocarina/button.h>
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <libsaria/prefs.h>
|
||||
|
||||
static GtkWidget *get_toggle_button(void (* func)(GtkWidget *, GdkEvent *, gpointer),
|
||||
bool state, bool show)
|
||||
static GtkWidget *get_toggle_button(void (* func)(GtkWidget *, gpointer), bool show)
|
||||
{
|
||||
GtkWidget *button = gtk_toggle_button_new();
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), state == TRUE);
|
||||
GTK_CONNECT(button, "toggled", func, NULL);
|
||||
if (show == true)
|
||||
gtk_widget_show(button);
|
||||
return button;
|
||||
}
|
||||
|
||||
static GtkWidget *get_image(string path)
|
||||
GtkWidget *make_toggle_button(const gchar *stockid,
|
||||
void (* func)(GtkWidget *, gpointer),
|
||||
bool show)
|
||||
{
|
||||
GtkWidget *image = gtk_image_new();
|
||||
gtk_image_set_from_file(GTK_IMAGE(image), path.c_str());
|
||||
gtk_widget_show(image);
|
||||
return image;
|
||||
}
|
||||
|
||||
static GtkWidget *make_toggle_button(string file,
|
||||
void (* func)(GtkWidget *, GdkEvent *, gpointer),
|
||||
bool state,
|
||||
bool show)
|
||||
{
|
||||
GtkWidget *button = get_toggle_button(func, state, show);
|
||||
GtkWidget *image = get_image(file);
|
||||
GtkWidget *button = get_toggle_button(func, show);
|
||||
GtkWidget *image = get_image(stockid, GTK_ICON_SIZE_MENU);
|
||||
container_add(button, image);
|
||||
return button;
|
||||
}
|
||||
|
||||
static void toggle_random(GtkWidget *b, GdkEvent *e, gpointer d)
|
||||
{
|
||||
bool active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b)) == TRUE;
|
||||
libsaria::prefs::set("random", active);
|
||||
}
|
||||
|
||||
GtkWidget *make_random_button()
|
||||
{
|
||||
return make_toggle_button(ocarina::full_path("images/random.png"),
|
||||
toggle_random,
|
||||
true, //libsaria::prefs::get_bool("random"),
|
||||
true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue