libsaria: Remove indices from the queue

This replaces the "remove id" ability and replaces it with a "remove
index" ability.  Removing an index will remove the correct song in the
case that the same song has been added multiple times.  I also modified
the UI to remove rows at a specific index.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-02-25 13:50:56 -05:00
parent 6637a82573
commit e03dfb33b8
8 changed files with 66 additions and 15 deletions

View File

@ -52,7 +52,7 @@ namespace libsaria
void add_ids(list<sid_t> &);
void add_track(Track *);
void rm_ids(list<sid_t> &);
void rm_indices(list<int> &);
void rm_track(Track *);
void sort();

View File

@ -18,7 +18,6 @@ namespace libsaria
}
void add_ids(list<sid_t> &);
void rm_ids(list<sid_t> &);
unsigned int size();
string next_file();

View File

@ -19,6 +19,7 @@ namespace libsaria
void fill();
virtual void insert(Track *) = 0;
virtual void index_removed(int) = 0;
};
}; /* Namespace: libsaria */

View File

@ -43,6 +43,8 @@ class SongList : public libsaria::PlaylistRenderer
void freeze();
void thaw();
void list_selected_indices(list<int> &);
public:
SongList();
SongList(libsaria::Playlist *);
@ -57,6 +59,8 @@ class SongList : public libsaria::PlaylistRenderer
void clear();
void refilter();
void list_selected_ids(list<sid_t> &);
void rm_selected_indices();
void index_removed(int);
void scroll_to(sid_t);
sid_t current_id();

View File

@ -11,6 +11,18 @@ static bool compare_tracks(libsaria::Track *one, libsaria::Track *two)
return *one < *two;
}
static void advance_iterator(list<libsaria::Track *>::iterator &it, int n)
{
for (int i = 0; i < n; i++)
it++;
}
static void remove_iterator(list<libsaria::Track *> &lst, list<libsaria::Track *>::iterator &it)
{
it = lst.erase(it);
it--;
}
namespace libsaria
{
@ -61,11 +73,21 @@ namespace libsaria
save();
}
void Playlist::rm_ids(list<sid_t> &ids)
void Playlist::rm_indices(list<int> &ids)
{
list<sid_t>::iterator it;
for (it = ids.begin(); it != ids.end(); it++)
plist.remove(library::lookup(*it));
int removed = 0, cur_index = 0;
list<int>::iterator it;
list<Track *>::iterator cur = plist.begin();
ids.sort();
for(it = ids.begin(); it != ids.end(); it++) {
advance_iterator(cur, (*it) - cur_index);
remove_iterator(plist, cur);
cur_index = *it;
if (renderer)
renderer->index_removed(*it - removed);
removed++;
}
save();
}

View File

@ -24,12 +24,6 @@ namespace libsaria
refresh();
}
void queue::rm_ids(list<sid_t> &ids)
{
q_queue.rm_ids(ids);
refresh();
}
unsigned int queue::size()
{
return q_queue.apparent_size();

View File

@ -16,9 +16,9 @@ unsigned int queue_index;
static void rm_from_queue()
{
list<sid_t> selected;
queue_list.list_selected_ids(selected);
libsaria::queue::rm_ids(selected);
queue_list.rm_selected_indices();
if (libsaria::queue::size() == 0)
hide_page(queue_index);
}
static void rm_from_queue_event(GtkMenuItem *menu, gpointer data)

View File

@ -47,11 +47,42 @@ static void selected_foreach_func(GtkTreeModel *model, GtkTreePath *path,
res->push_back(inode);
}
static void selected_foreach_func2(GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data)
{
list<int> *res = (list<int> *) data;
int *index = gtk_tree_path_get_indices(path);
res->push_back(*index);
println("Found index: %d", *index);
}
void SongList::list_selected_ids(list<sid_t> &res)
{
gtk_tree_selection_selected_foreach(selection, selected_foreach_func, &res);
}
void SongList::list_selected_indices(list<int> &res)
{
gtk_tree_selection_selected_foreach(selection, selected_foreach_func2, &res);
}
void SongList::rm_selected_indices()
{
list<int> selected;
list<int>::iterator it;
list_selected_indices(selected);
get_playlist()->rm_indices(selected);
}
void SongList::index_removed(int index)
{
GtkTreeIter iter;
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(liststore), &iter, NULL, index);
gtk_list_store_remove(liststore, &iter);
set_label_text();
}
GtkWidget *SongList::get_window()
{
return window;