Create a PLAYLIST_GOTO notification

To move the cursor to the current song.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-09-03 12:14:54 -04:00
parent 9fb1d05376
commit c46671b1fb
7 changed files with 23 additions and 9 deletions

View File

@ -19,6 +19,7 @@ enum notify_t {
PLAYLIST_RM, // libsaria::PlaylistNotification *
PLAYLIST_UPDATE, // libsaria::PlaylistNotification *
PLAYLIST_SIZE, // libsaria::PlaylistNotification *
PLAYLIST_GOTO, // libsaria::PlaylistNotification *
NOTIFY_SIZE,
};

View File

@ -21,8 +21,6 @@ namespace libsaria
bool is_static();
virtual void on_disable(bool);
virtual void goto_index(unsigned int);
};
}; /* Namespace: libsaria */

View File

@ -25,14 +25,14 @@ namespace libsaria
index = find_cur_index();
if (flags & PL_NO_DRAIN) {
RENDER(goto_index(index));
notify_ui(PLAYLIST_GOTO, res, index);
return res;
}
index = remove_track_it(cur, index);
schedule_save();
if (get_size() != 0)
RENDER(goto_index(index));
notify_ui(PLAYLIST_GOTO, res, index);
return res;
}

View File

@ -118,7 +118,7 @@ namespace libsaria
void Playlist::reset_iterator()
{
cur = plist.begin();
RENDER(goto_index(0));
notify_ui(PLAYLIST_GOTO, *cur, 0);
}
unsigned int Playlist::find_cur_index()

View File

@ -34,8 +34,4 @@ namespace libsaria
{
}
void PlaylistRenderer::goto_index(unsigned int index)
{
}
}; /* Namespace: libsaria */

View File

@ -44,6 +44,7 @@ void on_notify(notify_t event, void *data)
case PLAYLIST_RM:
case PLAYLIST_SIZE:
case PLAYLIST_UPDATE:
case PLAYLIST_GOTO:
update_playlist(event, (libsaria::PlaylistNotification *)data);
default:
break;

View File

@ -83,6 +83,22 @@ static void set_playlist_size(libsaria::Playlist *plist)
update_length_label();
}
static void playlist_goto_index(libsaria::Playlist *playlist, unsigned int index)
{
GtkTreeIter iter;
GtkTreePath *path;
struct PlaylistWidgets *widgets = find_playlist_widgets(playlist);
GtkTreeModel *model = GTK_TREE_MODEL(widgets->liststore);
gtk_tree_model_get_iter_first(model, &iter);
path = gtk_tree_model_get_path(model, &iter);
for (unsigned int i = 0; i < index; i++)
gtk_tree_path_next(path);
gtk_tree_view_set_cursor(widgets->treeview, path, NULL, FALSE);
gtk_tree_path_free(path);
}
void update_playlist(notify_t event, libsaria::PlaylistNotification *data)
{
if (event == PLAYLIST_ADD)
@ -93,6 +109,8 @@ void update_playlist(notify_t event, libsaria::PlaylistNotification *data)
playlist_update(data->plist, data->track, data->index);
else if (event == PLAYLIST_SIZE)
set_playlist_size(data->plist);
else if (event == PLAYLIST_GOTO)
playlist_goto_index(data->plist, data->index);
}
static gboolean is_visible(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)