Create a PLAYLIST_UPDATE notification
This notification is sent when a track in the playlist is updated, such as when the play count is incremented. I also remove the track_updated() functions from the library renderer and ocarina::Playlist. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
e8fd94cdeb
commit
a985ff70a9
|
@ -16,6 +16,7 @@ enum notify_t {
|
|||
PLAYLIST_RM, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_SIZE, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_FILTER,// libsaria::PlaylistNotification *
|
||||
PLAYLIST_UPDATE,// libsaria::PlaylistNotification *
|
||||
NOTIFY_SIZE,
|
||||
};
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace libsaria
|
|||
void incr_iter();
|
||||
Track *picked_next();
|
||||
unsigned int find_cur_index();
|
||||
unsigned int find_index(Track *);
|
||||
void add_track(Track *, unsigned int);
|
||||
void do_remove_tracks(list<Track *> &);
|
||||
unsigned int remove_track_it(list<Track *>::iterator &it, unsigned int);
|
||||
|
|
|
@ -18,7 +18,6 @@ namespace libsaria
|
|||
void set_playlist(Playlist *);
|
||||
Playlist *get_playlist();
|
||||
virtual void renumbered(int);
|
||||
virtual void track_updated(Track *);
|
||||
|
||||
bool is_static();
|
||||
virtual void prepare_for_removal();
|
||||
|
|
|
@ -38,7 +38,6 @@ namespace ocarina
|
|||
|
||||
void set_playlist(libsaria::Playlist *);
|
||||
void renumbered(int);
|
||||
void track_updated(libsaria::Track *);
|
||||
void prepare_for_removal();
|
||||
void on_disable(bool);
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace libsaria
|
|||
|
||||
void Playlist::track_updated(Track *track)
|
||||
{
|
||||
RENDER( track_updated(track) );
|
||||
notify_ui(PLAYLIST_UPDATE, track, find_index(track));
|
||||
}
|
||||
|
||||
void Playlist::prepare_for_removal()
|
||||
|
@ -144,6 +144,19 @@ namespace libsaria
|
|||
return index;
|
||||
}
|
||||
|
||||
unsigned int Playlist::find_index(Track *track)
|
||||
{
|
||||
list<Track *>::iterator it;
|
||||
unsigned int index = 0;
|
||||
|
||||
for (it = plist.begin(); it != cur; it++) {
|
||||
if (*it == track)
|
||||
return index;
|
||||
index++;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
void Playlist::notify_ui(notify_t type, Track *track, unsigned int index)
|
||||
{
|
||||
struct PlaylistNotification data;
|
||||
|
|
|
@ -29,10 +29,6 @@ namespace libsaria
|
|||
{
|
||||
}
|
||||
|
||||
void PlaylistRenderer::track_updated(Track *track)
|
||||
{
|
||||
}
|
||||
|
||||
bool PlaylistRenderer::is_static()
|
||||
{
|
||||
return (flags & PL_STATIC) == PL_STATIC;
|
||||
|
|
|
@ -39,6 +39,7 @@ void on_notify(notify_t event, void *data)
|
|||
case PLAYLIST_RM:
|
||||
case PLAYLIST_SIZE:
|
||||
case PLAYLIST_FILTER:
|
||||
case PLAYLIST_UPDATE:
|
||||
update_playlist(event, (libsaria::PlaylistNotification *)data);
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -108,14 +108,10 @@ static void set_playlist_length(libsaria::Playlist *playlist)
|
|||
update_length_label(stream.str());
|
||||
}
|
||||
|
||||
static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
|
||||
unsigned int index)
|
||||
static void update_track(libsaria::Track *track, GtkListStore *liststore,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
struct PlaylistWidgets *widgets = find_widgets(plist);
|
||||
if (!widgets)
|
||||
return;
|
||||
|
||||
gtk_list_store_insert_with_values(widgets->liststore, NULL, index,
|
||||
gtk_list_store_set(liststore, iter,
|
||||
0, track,
|
||||
1, track->get_track(),
|
||||
2, track->get_title().c_str(),
|
||||
|
@ -129,6 +125,18 @@ static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
|
|||
-1);
|
||||
}
|
||||
|
||||
static void playlist_add(libsaria::Playlist *plist, libsaria::Track *track,
|
||||
unsigned int index)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
struct PlaylistWidgets *widgets = find_widgets(plist);
|
||||
if (!widgets)
|
||||
return;
|
||||
|
||||
gtk_list_store_insert(widgets->liststore, &iter, index);
|
||||
update_track(track, widgets->liststore, &iter);
|
||||
}
|
||||
|
||||
static void playlist_rm(libsaria::Playlist *plist, unsigned int index)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
@ -139,6 +147,15 @@ static void playlist_rm(libsaria::Playlist *plist, unsigned int index)
|
|||
set_playlist_length(plist);
|
||||
}
|
||||
|
||||
static void playlist_update(libsaria::Playlist *plist, libsaria::Track *track,
|
||||
unsigned int index)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
PlaylistWidgets *widgets = find_widgets(plist);
|
||||
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(widgets->liststore), &iter, NULL, index);
|
||||
update_track(track, widgets->liststore, &iter);
|
||||
}
|
||||
|
||||
static void set_playlist_size(libsaria::Playlist *plist)
|
||||
{
|
||||
char buf[11];
|
||||
|
@ -169,6 +186,8 @@ void update_playlist(notify_t event, libsaria::PlaylistNotification *data)
|
|||
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,
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker
|
||||
#include <ocarina/playlist.h>
|
||||
#include <libsaria/track.h>
|
||||
|
||||
static string formatted(string str)
|
||||
{
|
||||
char *escaped = g_markup_escape_text(str.c_str(), -1);
|
||||
string ret = escaped;
|
||||
g_free(escaped);
|
||||
return ret;
|
||||
}
|
||||
|
||||
namespace ocarina
|
||||
{
|
||||
|
||||
void Playlist::track_updated(libsaria::Track *track)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
libsaria::Track *t;
|
||||
|
||||
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &iter);
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(liststore), &iter, 0, &t, -1);
|
||||
|
||||
while (t != track) {
|
||||
if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(liststore), &iter))
|
||||
return;
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(liststore), &iter, 0, &t, -1);
|
||||
}
|
||||
|
||||
gtk_list_store_set(liststore, &iter,
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
Loading…
Reference in New Issue