ocarina: Split playlist.cpp into two files
One for managing the notebook tabs (tabs.cpp) and one for managing a specific playlist page (playlist.cpp). Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
e6c44bf1a9
commit
5a4b9df2b2
|
@ -14,9 +14,9 @@ enum notify_t {
|
|||
PAUSE_COUNT, // unsigned int *
|
||||
PLAYLIST_ADD, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_RM, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_UPDATE,// libsaria::PlaylistNotification *
|
||||
PLAYLIST_SIZE, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_FILTER,// libsaria::PlaylistNotification *
|
||||
PLAYLIST_UPDATE,// libsaria::PlaylistNotification *
|
||||
NOTIFY_SIZE,
|
||||
};
|
||||
|
||||
|
|
|
@ -10,6 +10,15 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
struct PlaylistWidgets {
|
||||
libsaria::Playlist *playlist;
|
||||
GtkListStore *liststore;
|
||||
GtkTreeView *treeview;
|
||||
GtkTreeModel *filter;
|
||||
GtkLabel *label;
|
||||
GtkEntry *entry;
|
||||
};
|
||||
|
||||
/* library.cpp */
|
||||
void notify_library(notify_t, libsaria::library::Path *);
|
||||
void init_library();
|
||||
|
@ -25,20 +34,12 @@ GtkWidget *get_widget(const string &);
|
|||
void connect_signal(const string &, const string &, GCallback, void *);
|
||||
string run_chooser(const string &);
|
||||
|
||||
/* window.cpp */
|
||||
void init_window();
|
||||
|
||||
/* playlist.cpp */
|
||||
bool playlist_entry_focused();
|
||||
void playlist_focus_entry();
|
||||
void playlist_focus_treeview();
|
||||
void playlist_switch_to(string &);
|
||||
void update_playlist(notify_t, libsaria::PlaylistNotification *);
|
||||
void init_playlist();
|
||||
|
||||
/* status.cpp */
|
||||
bool update_idle_bar(int);
|
||||
void update_length_label(const string &);
|
||||
void update_length_label();
|
||||
void update_labels(libsaria::Track *);
|
||||
void update_buttons(notify_t);
|
||||
void update_progress();
|
||||
|
@ -46,6 +47,18 @@ void update_autopause_type(AutoPauseType *);
|
|||
void update_autopause_count(unsigned int *);
|
||||
void init_status();
|
||||
|
||||
/* tabs.cpp */
|
||||
struct PlaylistWidgets *find_playlist_widgets(libsaria::Playlist *);
|
||||
libsaria::Playlist *current_playlist();
|
||||
bool playlist_entry_focused();
|
||||
void playlist_focus_entry();
|
||||
void playlist_focus_treeview();
|
||||
void playlist_switch_to(string &);
|
||||
void init_tabs();
|
||||
|
||||
/* window.cpp */
|
||||
void init_window();
|
||||
|
||||
namespace ocarina
|
||||
{
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ static void init(int argc, char **argv)
|
|||
/* Other setup */
|
||||
init_window();
|
||||
init_library();
|
||||
init_playlist();
|
||||
init_tabs();
|
||||
init_status();
|
||||
|
||||
/* Connect signals */
|
||||
|
|
|
@ -1,31 +1,7 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/format.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <libsaria/deck.h>
|
||||
#include <libsaria/ban.h>
|
||||
|
||||
// Copyright (c) 2012 Bryan Schumaker
|
||||
#include <libsaria/track.h>
|
||||
#include <ocarina/ocarina.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
struct PlaylistWidgets {
|
||||
libsaria::Playlist *playlist;
|
||||
GtkListStore *liststore;
|
||||
GtkTreeView *treeview;
|
||||
GtkTreeModel *filter;
|
||||
GtkLabel *label;
|
||||
GtkEntry *entry;
|
||||
};
|
||||
|
||||
static PlaylistWidgets library_widgets;
|
||||
static PlaylistWidgets recent_widgets;
|
||||
static PlaylistWidgets banned_widgets;
|
||||
static GtkWidget *focused_entry = NULL;
|
||||
|
||||
static string formatted(string str)
|
||||
{
|
||||
char *escaped = g_markup_escape_text(str.c_str(), -1);
|
||||
|
@ -34,136 +10,6 @@ static string formatted(string str)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static struct PlaylistWidgets *find_widgets(libsaria::Playlist *plist)
|
||||
{
|
||||
if (plist == library_widgets.playlist)
|
||||
return &library_widgets;
|
||||
else if (plist == recent_widgets.playlist)
|
||||
return &recent_widgets;
|
||||
else if (plist == banned_widgets.playlist)
|
||||
return &banned_widgets;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static unsigned int tabs_size()
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
return gtk_notebook_get_n_pages(tabs) - 3;
|
||||
}
|
||||
|
||||
static struct PlaylistWidgets *find_nth_widgets(unsigned int n)
|
||||
{
|
||||
unsigned int size = tabs_size();
|
||||
|
||||
/* Dynamic playlists */
|
||||
if (n < size)
|
||||
return NULL;
|
||||
|
||||
switch (n - size) {
|
||||
case 0:
|
||||
return &library_widgets;
|
||||
case 1:
|
||||
return &recent_widgets;
|
||||
case 2:
|
||||
return &banned_widgets;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct PlaylistWidgets *current_widgets()
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
return find_nth_widgets(gtk_notebook_get_current_page(tabs));
|
||||
}
|
||||
|
||||
static libsaria::Playlist *find_playlist(unsigned int n)
|
||||
{
|
||||
return find_nth_widgets(n)->playlist;
|
||||
}
|
||||
|
||||
static libsaria::Playlist *current_playlist()
|
||||
{
|
||||
return current_widgets()->playlist;
|
||||
}
|
||||
|
||||
void playlist_switch_to(string &key)
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
unsigned int size = tabs_size();
|
||||
|
||||
if (key == "l")
|
||||
gtk_notebook_set_current_page(tabs, size);
|
||||
else if (key == "r")
|
||||
gtk_notebook_set_current_page(tabs, size + 1);
|
||||
else if (key == "b")
|
||||
gtk_notebook_set_current_page(tabs, size + 2);
|
||||
}
|
||||
|
||||
static gboolean is_visible(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
libsaria::Track *track;
|
||||
libsaria::Playlist *plist = (libsaria::Playlist *)data;
|
||||
|
||||
gtk_tree_model_get(model, iter, 0, &track, -1);
|
||||
return plist->is_visible(track);
|
||||
}
|
||||
|
||||
static void do_filter(GtkWidget *entry, gpointer d)
|
||||
{
|
||||
string text = gtk_entry_get_text(GTK_ENTRY(entry));
|
||||
libsaria::Playlist *plist = (libsaria::Playlist *)d;
|
||||
plist->set_filter_text(text);
|
||||
}
|
||||
|
||||
static gboolean on_focus_change(GtkWidget *entry, GdkEvent *event, gpointer data)
|
||||
{
|
||||
if (gtk_widget_is_focus(entry))
|
||||
focused_entry = entry;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool playlist_entry_focused()
|
||||
{
|
||||
if (!focused_entry)
|
||||
return false;
|
||||
return gtk_widget_is_focus(focused_entry);
|
||||
}
|
||||
|
||||
void playlist_focus_entry()
|
||||
{
|
||||
gtk_widget_grab_focus(GTK_WIDGET(current_widgets()->entry));
|
||||
}
|
||||
|
||||
void playlist_focus_treeview()
|
||||
{
|
||||
gtk_widget_grab_focus(GTK_WIDGET(current_widgets()->treeview));
|
||||
}
|
||||
|
||||
static void track_selected(GtkWidget *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *col, gpointer data)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
libsaria::Track *track;
|
||||
|
||||
model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
gtk_tree_model_get(model, &iter, 0, &track, -1);
|
||||
track->load(true);
|
||||
}
|
||||
|
||||
static void set_playlist_length(libsaria::Playlist *playlist)
|
||||
{
|
||||
stringstream stream;
|
||||
unsigned int size = playlist->get_size();
|
||||
stream << size << " song";
|
||||
if (size != 1)
|
||||
stream << "s";
|
||||
if (size != 0)
|
||||
stream << ": " << libsaria::length_string(playlist->get_length());
|
||||
update_length_label(stream.str());
|
||||
}
|
||||
|
||||
static void update_track(libsaria::Track *track, GtkListStore *liststore,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
|
@ -185,7 +31,7 @@ static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
|
|||
unsigned int index)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
struct PlaylistWidgets *widgets = find_widgets(plist);
|
||||
struct PlaylistWidgets *widgets = find_playlist_widgets(plist);
|
||||
if (!widgets)
|
||||
return;
|
||||
|
||||
|
@ -196,18 +42,17 @@ static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
|
|||
static void playlist_rm(libsaria::Playlist *plist, unsigned int index)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
PlaylistWidgets *widgets = find_widgets(plist);
|
||||
PlaylistWidgets *widgets = find_playlist_widgets(plist);
|
||||
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(widgets->liststore), &iter, NULL, index);
|
||||
gtk_list_store_remove(widgets->liststore, &iter);
|
||||
if (plist == current_playlist())
|
||||
set_playlist_length(plist);
|
||||
update_length_label();
|
||||
}
|
||||
|
||||
static void playlist_update(libsaria::Playlist *plist, libsaria::Track *track,
|
||||
unsigned int index)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
PlaylistWidgets *widgets = find_widgets(plist);
|
||||
PlaylistWidgets *widgets = find_playlist_widgets(plist);
|
||||
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(widgets->liststore), &iter, NULL, index);
|
||||
update_track(track, widgets->liststore, &iter);
|
||||
}
|
||||
|
@ -215,19 +60,18 @@ static void playlist_update(libsaria::Playlist *plist, libsaria::Track *track,
|
|||
static void set_playlist_size(libsaria::Playlist *plist)
|
||||
{
|
||||
char buf[11];
|
||||
struct PlaylistWidgets *widgets = find_widgets(plist);
|
||||
struct PlaylistWidgets *widgets = find_playlist_widgets(plist);
|
||||
if (!widgets)
|
||||
return;
|
||||
|
||||
sprintf(buf, "%u", plist->get_size());
|
||||
gtk_label_set_text(widgets->label, buf);
|
||||
if (plist == current_playlist())
|
||||
set_playlist_length(plist);
|
||||
update_length_label();
|
||||
}
|
||||
|
||||
static void playlist_refilter(libsaria::Playlist *plist)
|
||||
{
|
||||
struct PlaylistWidgets *widgets = find_widgets(plist);
|
||||
struct PlaylistWidgets *widgets = find_playlist_widgets(plist);
|
||||
if (widgets)
|
||||
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(widgets->filter));
|
||||
}
|
||||
|
@ -238,82 +82,10 @@ void update_playlist(notify_t event, libsaria::PlaylistNotification *data)
|
|||
playlist_add(data->plist, data->track, data->index);
|
||||
else if (event == PLAYLIST_RM)
|
||||
playlist_rm(data->plist, data->index);
|
||||
else if (event == PLAYLIST_UPDATE)
|
||||
playlist_update(data->plist, data->track, data->index);
|
||||
else if (event == PLAYLIST_SIZE)
|
||||
set_playlist_size(data->plist);
|
||||
else if (event == PLAYLIST_FILTER)
|
||||
playlist_refilter(data->plist);
|
||||
else if (event == PLAYLIST_UPDATE)
|
||||
playlist_update(data->plist, data->track, data->index);
|
||||
}
|
||||
|
||||
static void init_playlist_tab(struct PlaylistWidgets *widgets,
|
||||
libsaria::Playlist *playlist,
|
||||
const string &list_name,
|
||||
const string &view_name,
|
||||
const string &label_name,
|
||||
const string &entry_name)
|
||||
{
|
||||
widgets->playlist = playlist;
|
||||
widgets->liststore = GTK_LIST_STORE(get_object(list_name));
|
||||
widgets->treeview = GTK_TREE_VIEW(get_widget(view_name));
|
||||
widgets->filter = gtk_tree_model_filter_new(
|
||||
GTK_TREE_MODEL(widgets->liststore), NULL);
|
||||
widgets->label = GTK_LABEL(get_widget(label_name));
|
||||
widgets->entry = GTK_ENTRY(get_widget(entry_name));
|
||||
|
||||
gtk_tree_view_set_model(widgets->treeview, widgets->filter);
|
||||
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(widgets->filter),
|
||||
is_visible, playlist, NULL);
|
||||
|
||||
connect_signal(view_name, "row-activated", G_CALLBACK(track_selected), NULL);
|
||||
connect_signal(entry_name, "changed", G_CALLBACK(do_filter), playlist);
|
||||
connect_signal(entry_name, "focus-in-event", G_CALLBACK(on_focus_change), NULL);
|
||||
}
|
||||
|
||||
static void on_switch_page(GtkNotebook *tabs, gpointer page,
|
||||
unsigned int page_num, gpointer data)
|
||||
{
|
||||
set_playlist_length(find_playlist(page_num));
|
||||
}
|
||||
|
||||
static void on_click_open(GtkWidget *b, gpointer d)
|
||||
{
|
||||
string file = run_chooser("FileChooser");
|
||||
if (file != "") {
|
||||
println("Playing file: " + file);
|
||||
libsaria::play_outside_song(file);
|
||||
}
|
||||
}
|
||||
|
||||
static void init_tab_action()
|
||||
{
|
||||
GtkWidget *box = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
|
||||
GtkWidget *open = gtk_button_new();
|
||||
|
||||
gtk_button_set_image(GTK_BUTTON(open), img);
|
||||
g_signal_connect(open, "clicked", G_CALLBACK(on_click_open), NULL);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(box), open, false, false, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), get_widget("BanButton"), false, false, 0);
|
||||
gtk_widget_show_all(box);
|
||||
gtk_notebook_set_action_widget(GTK_NOTEBOOK(get_widget("PlaylistTabs")),
|
||||
box, GTK_PACK_END);
|
||||
}
|
||||
|
||||
void init_playlist()
|
||||
{
|
||||
init_tab_action();
|
||||
|
||||
init_playlist_tab(&library_widgets, libsaria::library::get_playlist(),
|
||||
"LibraryPlist", "LibraryPlistView",
|
||||
"LibrarySize", "LibraryEntry");
|
||||
init_playlist_tab(&recent_widgets, libsaria::deck::get_recent_plist(),
|
||||
"RecentPlist", "RecentView",
|
||||
"RecentSize", "RecentEntry");
|
||||
init_playlist_tab(&banned_widgets, libsaria::ban::get_banned_plist(),
|
||||
"BannedPlist", "BannedView",
|
||||
"BannedSize", "BannedEntry");
|
||||
|
||||
connect_signal("PlaylistTabs", "switch-page", G_CALLBACK(on_switch_page), NULL);
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace ocarina
|
|||
stream << "songs: " << libsaria::length_string(playlist->get_length());
|
||||
|
||||
text = stream.str();
|
||||
update_length_label(text);
|
||||
//update_length_label(text);
|
||||
}
|
||||
|
||||
void Playlist::set_label_text()
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <libsaria/format.h>
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/deck.h>
|
||||
#include <libsaria/idle.h>
|
||||
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
static void set_label(const string &name, const string &text, const string &size)
|
||||
{
|
||||
GtkWidget *label = get_widget(name);
|
||||
|
@ -139,11 +143,21 @@ bool update_idle_bar(int size)
|
|||
return true;
|
||||
}
|
||||
|
||||
void update_length_label(const string &text)
|
||||
void update_length_label()
|
||||
{
|
||||
stringstream stream;
|
||||
libsaria::Playlist *playlist = current_playlist();
|
||||
unsigned int size = playlist->get_size();
|
||||
GtkWidget *label = get_widget("LengthLabel");
|
||||
if (label)
|
||||
gtk_label_set_text(GTK_LABEL(label), text.c_str());
|
||||
if (!label)
|
||||
return;
|
||||
|
||||
stream << size << " song";
|
||||
if (size != 1)
|
||||
stream << "s";
|
||||
if (size != 0)
|
||||
stream << ": " << libsaria::length_string(playlist->get_length());
|
||||
gtk_label_set_text(GTK_LABEL(label), stream.str().c_str());
|
||||
}
|
||||
|
||||
void init_status()
|
||||
|
|
|
@ -0,0 +1,201 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <libsaria/deck.h>
|
||||
#include <libsaria/ban.h>
|
||||
|
||||
#include <ocarina/ocarina.h>
|
||||
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
|
||||
static PlaylistWidgets library_widgets;
|
||||
static PlaylistWidgets recent_widgets;
|
||||
static PlaylistWidgets banned_widgets;
|
||||
static GtkWidget *focused_entry = NULL;
|
||||
|
||||
struct PlaylistWidgets *find_playlist_widgets(libsaria::Playlist *plist)
|
||||
{
|
||||
if (plist == library_widgets.playlist)
|
||||
return &library_widgets;
|
||||
else if (plist == recent_widgets.playlist)
|
||||
return &recent_widgets;
|
||||
else if (plist == banned_widgets.playlist)
|
||||
return &banned_widgets;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static unsigned int tabs_size()
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
return gtk_notebook_get_n_pages(tabs) - 3;
|
||||
}
|
||||
|
||||
static struct PlaylistWidgets *find_nth_widgets(unsigned int n)
|
||||
{
|
||||
unsigned int size = tabs_size();
|
||||
|
||||
/* Dynamic playlists */
|
||||
if (n < size)
|
||||
return NULL;
|
||||
|
||||
switch (n - size) {
|
||||
case 0:
|
||||
return &library_widgets;
|
||||
case 1:
|
||||
return &recent_widgets;
|
||||
case 2:
|
||||
return &banned_widgets;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct PlaylistWidgets *current_widgets()
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
return find_nth_widgets(gtk_notebook_get_current_page(tabs));
|
||||
}
|
||||
|
||||
libsaria::Playlist *current_playlist()
|
||||
{
|
||||
return current_widgets()->playlist;
|
||||
}
|
||||
|
||||
void playlist_switch_to(string &key)
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
unsigned int size = tabs_size();
|
||||
|
||||
if (key == "l")
|
||||
gtk_notebook_set_current_page(tabs, size);
|
||||
else if (key == "r")
|
||||
gtk_notebook_set_current_page(tabs, size + 1);
|
||||
else if (key == "b")
|
||||
gtk_notebook_set_current_page(tabs, size + 2);
|
||||
}
|
||||
|
||||
static gboolean is_visible(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
libsaria::Track *track;
|
||||
libsaria::Playlist *plist = (libsaria::Playlist *)data;
|
||||
|
||||
gtk_tree_model_get(model, iter, 0, &track, -1);
|
||||
return plist->is_visible(track);
|
||||
}
|
||||
|
||||
static void do_filter(GtkWidget *entry, gpointer d)
|
||||
{
|
||||
string text = gtk_entry_get_text(GTK_ENTRY(entry));
|
||||
libsaria::Playlist *plist = (libsaria::Playlist *)d;
|
||||
plist->set_filter_text(text);
|
||||
}
|
||||
|
||||
static gboolean on_focus_change(GtkWidget *entry, GdkEvent *event, gpointer data)
|
||||
{
|
||||
if (gtk_widget_is_focus(entry))
|
||||
focused_entry = entry;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool playlist_entry_focused()
|
||||
{
|
||||
if (!focused_entry)
|
||||
return false;
|
||||
return gtk_widget_is_focus(focused_entry);
|
||||
}
|
||||
|
||||
void playlist_focus_entry()
|
||||
{
|
||||
gtk_widget_grab_focus(GTK_WIDGET(current_widgets()->entry));
|
||||
}
|
||||
|
||||
void playlist_focus_treeview()
|
||||
{
|
||||
gtk_widget_grab_focus(GTK_WIDGET(current_widgets()->treeview));
|
||||
}
|
||||
|
||||
static void track_selected(GtkWidget *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *col, gpointer data)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
libsaria::Track *track;
|
||||
|
||||
model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
gtk_tree_model_get(model, &iter, 0, &track, -1);
|
||||
track->load(true);
|
||||
}
|
||||
|
||||
static void on_switch_page(GtkNotebook *tabs, gpointer page,
|
||||
unsigned int page_num, gpointer data)
|
||||
{
|
||||
update_length_label();
|
||||
}
|
||||
|
||||
static void on_click_open(GtkWidget *b, gpointer d)
|
||||
{
|
||||
string file = run_chooser("FileChooser");
|
||||
if (file != "") {
|
||||
println("Playing file: " + file);
|
||||
libsaria::play_outside_song(file);
|
||||
}
|
||||
}
|
||||
|
||||
static void init_tab_action()
|
||||
{
|
||||
GtkWidget *box = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
|
||||
GtkWidget *open = gtk_button_new();
|
||||
|
||||
gtk_button_set_image(GTK_BUTTON(open), img);
|
||||
g_signal_connect(open, "clicked", G_CALLBACK(on_click_open), NULL);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(box), open, false, false, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), get_widget("BanButton"), false, false, 0);
|
||||
gtk_widget_show_all(box);
|
||||
gtk_notebook_set_action_widget(GTK_NOTEBOOK(get_widget("PlaylistTabs")),
|
||||
box, GTK_PACK_END);
|
||||
}
|
||||
|
||||
static void init_playlist_tab(struct PlaylistWidgets *widgets,
|
||||
libsaria::Playlist *playlist,
|
||||
const string &list_name,
|
||||
const string &view_name,
|
||||
const string &label_name,
|
||||
const string &entry_name)
|
||||
{
|
||||
widgets->playlist = playlist;
|
||||
widgets->liststore = GTK_LIST_STORE(get_object(list_name));
|
||||
widgets->treeview = GTK_TREE_VIEW(get_widget(view_name));
|
||||
widgets->filter = gtk_tree_model_filter_new(
|
||||
GTK_TREE_MODEL(widgets->liststore), NULL);
|
||||
widgets->label = GTK_LABEL(get_widget(label_name));
|
||||
widgets->entry = GTK_ENTRY(get_widget(entry_name));
|
||||
|
||||
gtk_tree_view_set_model(widgets->treeview, widgets->filter);
|
||||
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(widgets->filter),
|
||||
is_visible, playlist, NULL);
|
||||
|
||||
connect_signal(view_name, "row-activated", G_CALLBACK(track_selected), NULL);
|
||||
connect_signal(entry_name, "changed", G_CALLBACK(do_filter), playlist);
|
||||
connect_signal(entry_name, "focus-in-event", G_CALLBACK(on_focus_change), NULL);
|
||||
}
|
||||
|
||||
void init_tabs()
|
||||
{
|
||||
init_tab_action();
|
||||
|
||||
init_playlist_tab(&library_widgets, libsaria::library::get_playlist(),
|
||||
"LibraryPlist", "LibraryPlistView",
|
||||
"LibrarySize", "LibraryEntry");
|
||||
init_playlist_tab(&recent_widgets, libsaria::deck::get_recent_plist(),
|
||||
"RecentPlist", "RecentView",
|
||||
"RecentSize", "RecentEntry");
|
||||
init_playlist_tab(&banned_widgets, libsaria::ban::get_banned_plist(),
|
||||
"BannedPlist", "BannedView",
|
||||
"BannedSize", "BannedEntry");
|
||||
|
||||
connect_signal("PlaylistTabs", "switch-page", G_CALLBACK(on_switch_page), NULL);
|
||||
}
|
Loading…
Reference in New Issue