ocarina: Set length label when tabs are changed
My old code was doing this by looking for widgets getting mapped or unmapped. This was stupid, so now I'm using the GtkNotebook switch-page signal. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
ead70aef7d
commit
7483aa3c4f
|
@ -36,7 +36,7 @@ void init_playlist();
|
|||
|
||||
/* status.cpp */
|
||||
bool update_idle_bar(int);
|
||||
void update_length_label(string &);
|
||||
void update_length_label(const string &);
|
||||
void update_labels(libsaria::Track *);
|
||||
void update_buttons(notify_t);
|
||||
void update_progress();
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <ocarina/playlist.h>
|
||||
#include <ocarina/body.h>
|
||||
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/format.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <libsaria/deck.h>
|
||||
#include <libsaria/ban.h>
|
||||
|
||||
#include <ocarina/ocarina.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
struct PlaylistWidgets {
|
||||
libsaria::Playlist *playlist;
|
||||
|
@ -57,7 +59,33 @@ static string formatted(string str)
|
|||
return ret;
|
||||
}
|
||||
|
||||
struct PlaylistWidgets *find_widgets(libsaria::Playlist *plist)
|
||||
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;
|
||||
|
@ -89,14 +117,29 @@ static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
|
|||
-1);
|
||||
}
|
||||
|
||||
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 set_playlist_size(libsaria::Playlist *plist)
|
||||
{
|
||||
char buf[11];
|
||||
struct PlaylistWidgets *widgets = find_widgets(plist);
|
||||
if (widgets) {
|
||||
sprintf(buf, "%u", plist->get_size());
|
||||
gtk_label_set_text(widgets->label, buf);
|
||||
}
|
||||
if (!widgets)
|
||||
return;
|
||||
|
||||
sprintf(buf, "%u", plist->get_size());
|
||||
gtk_label_set_text(widgets->label, buf);
|
||||
if (plist == current_playlist())
|
||||
set_playlist_length(plist);
|
||||
}
|
||||
|
||||
static void playlist_refilter(libsaria::Playlist *plist)
|
||||
|
@ -138,6 +181,12 @@ static void init_playlist_tab(struct PlaylistWidgets *widgets,
|
|||
connect_signal(entry_name, "changed", G_CALLBACK(do_filter), playlist);
|
||||
}
|
||||
|
||||
static void on_switch_page(GtkNotebook *tabs, gpointer page,
|
||||
unsigned int page_num, gpointer data)
|
||||
{
|
||||
set_playlist_length(find_playlist(page_num));
|
||||
}
|
||||
|
||||
void init_playlist()
|
||||
{
|
||||
init_playlist2();
|
||||
|
@ -151,4 +200,6 @@ void init_playlist()
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ bool update_idle_bar(int size)
|
|||
return true;
|
||||
}
|
||||
|
||||
void update_length_label(string &text)
|
||||
void update_length_label(const string &text)
|
||||
{
|
||||
GtkWidget *label = get_widget("LengthLabel");
|
||||
if (label)
|
||||
|
|
Loading…
Reference in New Issue