ocarina: add a current_widgets() function
I use this to find the set of widgets associated with the current playlist page. This also makes current_playlist() easy, since I can just return the playlist from the widgets struct. I also moved these functions to the top of the file so the filter entries can eventually set focus when "slash" is pressed. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
55431421bf
commit
a2e0375ac9
|
@ -24,6 +24,61 @@ PlaylistWidgets recent_widgets;
|
|||
PlaylistWidgets banned_widgets;
|
||||
static GtkWidget *focused_entry = NULL;
|
||||
|
||||
static string formatted(string str)
|
||||
{
|
||||
char *escaped = g_markup_escape_text(str.c_str(), -1);
|
||||
string ret = escaped;
|
||||
g_free(escaped);
|
||||
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 struct PlaylistWidgets *find_nth_widgets(unsigned int n)
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
unsigned int size = gtk_notebook_get_n_pages(tabs) - 3;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
static gboolean is_visible(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
libsaria::Track *track;
|
||||
|
@ -67,51 +122,6 @@ static void track_selected(GtkWidget *treeview, GtkTreePath *path,
|
|||
track->load(true);
|
||||
}
|
||||
|
||||
static string formatted(string str)
|
||||
{
|
||||
char *escaped = g_markup_escape_text(str.c_str(), -1);
|
||||
string ret = escaped;
|
||||
g_free(escaped);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static libsaria::Playlist *find_playlist(unsigned int n)
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
unsigned int size = gtk_notebook_get_n_pages(tabs) - 3;
|
||||
|
||||
/* Dynamic playlists */
|
||||
if (n < size)
|
||||
return NULL;
|
||||
|
||||
switch (n - size) {
|
||||
case 0:
|
||||
return library_widgets.playlist;
|
||||
case 1:
|
||||
return recent_widgets.playlist;
|
||||
case 2:
|
||||
return banned_widgets.playlist;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static libsaria::Playlist *current_playlist()
|
||||
{
|
||||
GtkNotebook *tabs = GTK_NOTEBOOK(get_widget("PlaylistTabs"));
|
||||
return find_playlist(gtk_notebook_get_current_page(tabs));
|
||||
}
|
||||
|
||||
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 void set_playlist_length(libsaria::Playlist *playlist)
|
||||
{
|
||||
stringstream stream;
|
||||
|
|
Loading…
Reference in New Issue