playqueue: Add a function to clear the playqueue sort order

I do this when reading in a saved library sort order to make sure the
correct values are set.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2014-01-29 21:37:06 -05:00 committed by Anna Schumaker
parent 8dbb4684c7
commit c9f1c07fa3
3 changed files with 18 additions and 13 deletions

View File

@ -43,7 +43,7 @@ private:
unsigned int length;
unsigned int find_sorted_id(library :: Song &);
void _add_sort(sort_t);
void _add_sort(sort_t, bool);
public:
Playqueue();
@ -64,8 +64,9 @@ public:
void del_track(unsigned int);
unsigned int size();
void add_sort(sort_t);
void reset_sort(sort_t);
void add_sort(sort_t, bool ascending = true);
void reset_sort(sort_t, bool ascending = true);
void force_clear_sort();
std::list <sort_info> &get_sort_order();
unsigned int operator[](unsigned int);

View File

@ -50,14 +50,13 @@ void deck :: read()
deck_file.open(OPEN_READ);
deck_file >> random >> num;
library_playqueue.force_clear_sort();
for (unsigned int i = 0; i < num; i++) {
deck_file >> field >> ascending;
if (i == 0)
library_playqueue.reset_sort((sort_t)field);
library_playqueue.reset_sort((sort_t)field, ascending);
else
library_playqueue.add_sort((sort_t)field);
if (ascending == false)
library_playqueue.add_sort((sort_t)field);
library_playqueue.add_sort((sort_t)field, ascending);
}
deck_file >> num;

View File

@ -280,7 +280,7 @@ public:
}
};
void Playqueue :: _add_sort(sort_t field)
void Playqueue :: _add_sort(sort_t field, bool ascending)
{
struct sort_info info;
std::list<sort_info>::iterator it;
@ -294,18 +294,18 @@ void Playqueue :: _add_sort(sort_t field)
}
info.field = field;
info.ascending = true;
info.ascending = ascending;
sort_order.push_back(info);
if (sort_order.size() >= 4)
sort_order.erase(sort_order.begin());
}
void Playqueue :: add_sort(sort_t field)
void Playqueue :: add_sort(sort_t field, bool ascending)
{
if (flags & PQ_NEVER_SORT)
return;
_add_sort(field);
_add_sort(field, ascending);
std::stable_sort(tracks.begin(), tracks.end(), SortTracks(sort_order));
for (unsigned int i = 0; i < tracks.size(); i++)
@ -313,13 +313,18 @@ void Playqueue :: add_sort(sort_t field)
get_callbacks()->on_queue_changed();
}
void Playqueue :: reset_sort(sort_t field)
void Playqueue :: reset_sort(sort_t field, bool ascending)
{
if (flags & PQ_NEVER_SORT)
return;
if (sort_order.front().field != field)
sort_order.clear();
add_sort(field);
add_sort(field, ascending);
}
void Playqueue :: force_clear_sort()
{
sort_order.clear();
}
std::list<sort_info> &Playqueue :: get_sort_order()