ocarina: Don't make playlist filters visible through get_widget()
Instead, I implement a new struct for grouping together the important widgets of a playlist tab. I should be able to re-use this structure for dynamic playlists. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
ae39628b01
commit
ead70aef7d
|
@ -15,9 +15,6 @@ static GtkWidget *ban_button;
|
|||
static GtkWidget *open_button;
|
||||
static GtkWidget *yes_image;
|
||||
static GtkWidget *no_image;
|
||||
static GtkTreeModel *library_filter;
|
||||
static GtkTreeModel *recent_filter;
|
||||
static GtkTreeModel *banned_filter;
|
||||
|
||||
static void find_exe_path(string &res)
|
||||
{
|
||||
|
@ -91,12 +88,6 @@ GObject *get_object(const string &name)
|
|||
return G_OBJECT(yes_image);
|
||||
else if (name == "NoImage")
|
||||
return G_OBJECT(no_image);
|
||||
else if (name == "LibraryFilter")
|
||||
return G_OBJECT(library_filter);
|
||||
else if (name == "RecentFilter")
|
||||
return G_OBJECT(recent_filter);
|
||||
else if (name == "BannedFilter")
|
||||
return G_OBJECT(banned_filter);
|
||||
return gtk_builder_get_object(builder, name.c_str());
|
||||
}
|
||||
|
||||
|
@ -146,16 +137,6 @@ static void init_widgets()
|
|||
|
||||
open_button = gtk_button_new();
|
||||
gtk_button_set_image(GTK_BUTTON(open_button), image);
|
||||
|
||||
library_filter = gtk_tree_model_filter_new(
|
||||
GTK_TREE_MODEL(get_object("LibraryPlist")),
|
||||
NULL);
|
||||
recent_filter = gtk_tree_model_filter_new(
|
||||
GTK_TREE_MODEL(get_object("RecentPlist")),
|
||||
NULL);
|
||||
banned_filter = gtk_tree_model_filter_new(
|
||||
GTK_TREE_MODEL(get_object("BannedPlist")),
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void init(int argc, char **argv)
|
||||
|
|
|
@ -9,6 +9,17 @@
|
|||
|
||||
#include <cstdio>
|
||||
|
||||
struct PlaylistWidgets {
|
||||
libsaria::Playlist *playlist;
|
||||
GtkListStore *liststore;
|
||||
GtkTreeModel *filter;
|
||||
GtkLabel *label;
|
||||
};
|
||||
|
||||
PlaylistWidgets library_widgets;
|
||||
PlaylistWidgets recent_widgets;
|
||||
PlaylistWidgets banned_widgets;
|
||||
|
||||
static gboolean is_visible(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
libsaria::Track *track;
|
||||
|
@ -46,73 +57,53 @@ static string formatted(string str)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static GtkListStore *find_list(libsaria::Playlist *plist)
|
||||
struct PlaylistWidgets *find_widgets(libsaria::Playlist *plist)
|
||||
{
|
||||
if (plist == libsaria::library::get_playlist())
|
||||
return GTK_LIST_STORE(get_object("LibraryPlist"));
|
||||
else if (plist == libsaria::deck::get_recent_plist())
|
||||
return GTK_LIST_STORE(get_object("RecentPlist"));
|
||||
else if (plist == libsaria::ban::get_banned_plist())
|
||||
return GTK_LIST_STORE(get_object("BannedPlist"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GtkWidget *find_label(libsaria::Playlist *plist)
|
||||
{
|
||||
if (plist == libsaria::library::get_playlist())
|
||||
return get_widget("LibrarySize");
|
||||
else if (plist == libsaria::deck::get_recent_plist())
|
||||
return get_widget("RecentSize");
|
||||
else if (plist == libsaria::ban::get_banned_plist())
|
||||
return get_widget("BannedSize");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GtkTreeModelFilter *find_filter(libsaria::Playlist *plist)
|
||||
{
|
||||
if (plist == libsaria::library::get_playlist())
|
||||
return GTK_TREE_MODEL_FILTER(get_object("LibraryFilter"));
|
||||
else if (plist == libsaria::deck::get_recent_plist())
|
||||
return GTK_TREE_MODEL_FILTER(get_object("RecentFilter"));
|
||||
else if (plist == libsaria::ban::get_banned_plist())
|
||||
return GTK_TREE_MODEL_FILTER(get_object("BannedFilter"));
|
||||
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 void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
|
||||
unsigned int index)
|
||||
{
|
||||
GtkListStore *list = find_list(plist);
|
||||
if (!list)
|
||||
struct PlaylistWidgets *widgets = find_widgets(plist);
|
||||
if (!widgets)
|
||||
return;
|
||||
|
||||
gtk_list_store_insert_with_values(list, NULL, index,
|
||||
0, track,
|
||||
1, track->get_track(),
|
||||
2, track->get_title().c_str(),
|
||||
3, track->get_lenstr().c_str(),
|
||||
4, track->get_artist().c_str(),
|
||||
5, track->get_album().c_str(),
|
||||
6, track->get_year(),
|
||||
7, track->get_count(),
|
||||
8, track->get_last_played().c_str(),
|
||||
9, formatted(track->get_filepath()).c_str(),
|
||||
-1);
|
||||
gtk_list_store_insert_with_values(widgets->liststore, NULL, index,
|
||||
0, track,
|
||||
1, track->get_track(),
|
||||
2, track->get_title().c_str(),
|
||||
3, track->get_lenstr().c_str(),
|
||||
4, track->get_artist().c_str(),
|
||||
5, track->get_album().c_str(),
|
||||
6, track->get_year(),
|
||||
7, track->get_count(),
|
||||
8, track->get_last_played().c_str(),
|
||||
9, formatted(track->get_filepath()).c_str(),
|
||||
-1);
|
||||
}
|
||||
|
||||
static void set_playlist_size(libsaria::Playlist *plist)
|
||||
{
|
||||
char buf[11];
|
||||
GtkWidget *label = find_label(plist);
|
||||
if (label) {
|
||||
struct PlaylistWidgets *widgets = find_widgets(plist);
|
||||
if (widgets) {
|
||||
sprintf(buf, "%u", plist->get_size());
|
||||
gtk_label_set_text(GTK_LABEL(label), buf);
|
||||
gtk_label_set_text(widgets->label, buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void playlist_refilter(libsaria::Playlist *plist)
|
||||
{
|
||||
gtk_tree_model_filter_refilter(find_filter(plist));
|
||||
struct PlaylistWidgets *widgets = find_widgets(plist);
|
||||
if (widgets)
|
||||
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(widgets->filter));
|
||||
}
|
||||
|
||||
void update_playlist(notify_t event, libsaria::PlaylistNotification *data)
|
||||
|
@ -125,14 +116,23 @@ void update_playlist(notify_t event, libsaria::PlaylistNotification *data)
|
|||
playlist_refilter(data->plist);
|
||||
}
|
||||
|
||||
static void init_playlist_tab(libsaria::Playlist *playlist, const string &view_name,
|
||||
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)
|
||||
{
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(find_filter(playlist));
|
||||
GtkWidget *treeview = get_widget(view_name);
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), model);
|
||||
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model),
|
||||
is_visible, playlist, NULL);
|
||||
widgets->playlist = playlist;
|
||||
widgets->liststore = GTK_LIST_STORE(get_object(list_name));
|
||||
widgets->filter = gtk_tree_model_filter_new(
|
||||
GTK_TREE_MODEL(widgets->liststore), NULL);
|
||||
widgets->label = GTK_LABEL(get_widget(label_name));
|
||||
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(get_widget(view_name)),
|
||||
GTK_TREE_MODEL(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);
|
||||
|
@ -142,7 +142,13 @@ void init_playlist()
|
|||
{
|
||||
init_playlist2();
|
||||
|
||||
init_playlist_tab(libsaria::library::get_playlist(), "LibraryPlistView", "LibraryEntry");
|
||||
init_playlist_tab(libsaria::deck::get_recent_plist(), "RecentView", "RecentEntry");
|
||||
init_playlist_tab(libsaria::ban::get_banned_plist(), "BannedView", "BannedEntry");
|
||||
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");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue