core/queue: Move queue_sort() out of the queue struct
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
13723856fc
commit
4c4d0ab6ce
|
@ -67,9 +67,9 @@ static void upgrade_v0()
|
|||
|
||||
for (unsigned int i = 0; i < num; i++) {
|
||||
file_readf(&deck_file, "%u %d", &field, &ascending);
|
||||
library->sort((compare_t)field, (i == 0) ? true : false);
|
||||
queue_sort(library, (compare_t)field, (i == 0) ? true : false);
|
||||
if (!ascending)
|
||||
library->sort((compare_t)field, false);
|
||||
queue_sort(library, (compare_t)field, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,9 +47,9 @@ public:
|
|||
file_readf(&f, "%u %u", &q_flags, &n);
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
file_readf(&f, "%u %d", &field, &ascending);
|
||||
queue :: sort((compare_t)field, (i == 0) ? true : false);
|
||||
queue_sort(this, (compare_t)field, (i == 0) ? true : false);
|
||||
if (ascending == false)
|
||||
queue :: sort((compare_t)field, false);
|
||||
queue_sort(this, (compare_t)field, false);
|
||||
}
|
||||
file_close(&f);
|
||||
}
|
||||
|
@ -152,9 +152,9 @@ void collection :: init(struct queue_ops *ops)
|
|||
|
||||
library_q.load();
|
||||
if (library_q.q_sort.size() == 0) {
|
||||
library_q.sort(COMPARE_ARTIST, true);
|
||||
library_q.sort(COMPARE_YEAR, false);
|
||||
library_q.sort(COMPARE_TRACK, false);
|
||||
queue_sort(&library_q, COMPARE_ARTIST, true);
|
||||
queue_sort(&library_q, COMPARE_YEAR, false);
|
||||
queue_sort(&library_q, COMPARE_TRACK, false);
|
||||
}
|
||||
|
||||
queue_set_flag(&library_q, Q_SAVE_SORT);
|
||||
|
|
|
@ -74,9 +74,9 @@ void playlist :: init()
|
|||
struct set_iter it;
|
||||
|
||||
queue_init(&playlist_q, Q_ENABLED | Q_REPEAT, NULL);
|
||||
playlist_q.sort(COMPARE_ARTIST, true);
|
||||
playlist_q.sort(COMPARE_YEAR, false);
|
||||
playlist_q.sort(COMPARE_TRACK, false);
|
||||
queue_sort(&playlist_q, COMPARE_ARTIST, true);
|
||||
queue_sort(&playlist_q, COMPARE_YEAR, false);
|
||||
queue_sort(&playlist_q, COMPARE_TRACK, false);
|
||||
queue_set_flag(&playlist_q, Q_NO_SORT);
|
||||
|
||||
index_init(&playlist_db, "playlist.db", true);
|
||||
|
|
|
@ -195,30 +195,32 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
void queue :: sort(compare_t field, bool reset)
|
||||
void queue_sort(struct queue *queue, enum compare_t field, bool reset)
|
||||
{
|
||||
bool found = false;
|
||||
struct sort_info info = { field, true };
|
||||
|
||||
if (queue_has_flag(this, Q_NO_SORT))
|
||||
if (queue_has_flag(queue, Q_NO_SORT))
|
||||
return;
|
||||
if (reset)
|
||||
q_sort.clear();
|
||||
queue->q_sort.clear();
|
||||
|
||||
for (unsigned int i = 0; i < q_sort.size(); i++) {
|
||||
if (q_sort[i].field == info.field) {
|
||||
q_sort[i].ascending = !q_sort[i].ascending;
|
||||
for (unsigned int i = 0; i < queue->q_sort.size(); i++) {
|
||||
if (queue->q_sort[i].field == info.field) {
|
||||
queue->q_sort[i].ascending = !queue->q_sort[i].ascending;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
q_sort.push_back(info);
|
||||
queue->q_sort.push_back(info);
|
||||
|
||||
std::stable_sort(q_tracks.begin(), q_tracks.end(), SortTracks(q_sort));
|
||||
std::stable_sort(queue->q_tracks.begin(),
|
||||
queue->q_tracks.end(),
|
||||
SortTracks(queue->q_sort));
|
||||
|
||||
for (unsigned int i = 0; i < q_tracks.size(); i++)
|
||||
q_notify->on_track_updated(i);
|
||||
__queue_save(this, Q_SAVE_SORT);
|
||||
for (unsigned int i = 0; i < queue->q_tracks.size(); i++)
|
||||
queue->q_notify->on_track_updated(i);
|
||||
__queue_save(queue, Q_SAVE_SORT);
|
||||
}
|
||||
|
|
|
@ -280,9 +280,9 @@ void Tab :: on_column_clicked(unsigned int col)
|
|||
{
|
||||
if (tab_sorting_count == 0) {
|
||||
tab_sorting_title = tab_window->q_treeview->get_column(col)->get_title();
|
||||
tab_pq->sort(sort_fields[col], true);
|
||||
queue_sort(tab_pq, sort_fields[col], true);
|
||||
} else
|
||||
tab_pq->sort(sort_fields[col], false);
|
||||
queue_sort(tab_pq, sort_fields[col], false);
|
||||
|
||||
tab_sorting_count++;
|
||||
tab_display_sorting();
|
||||
|
|
|
@ -134,19 +134,6 @@ struct queue {
|
|||
* @param track Track to remove from the queue.
|
||||
*/
|
||||
virtual void del(struct track *);
|
||||
|
||||
|
||||
/**
|
||||
* Add a new sort field to the queue. If the field is already in the
|
||||
* _sort_order then it's ascending or descending value will be toggled.
|
||||
*
|
||||
* If reset is set to True then the _sort_order will be cleared before
|
||||
* adding the new value.
|
||||
*
|
||||
* @param field Field to sort by.
|
||||
* @param reset Set to true if current sort data should be discarded.
|
||||
*/
|
||||
virtual void sort(compare_t, bool);
|
||||
};
|
||||
|
||||
|
||||
|
@ -189,4 +176,7 @@ void queue_selected(struct queue *, unsigned int);
|
|||
/* Called to pick the next track from the queue. */
|
||||
struct track *queue_next(struct queue *);
|
||||
|
||||
/* Called to sort the queue. */
|
||||
void queue_sort(struct queue *, enum compare_t, bool);
|
||||
|
||||
#endif /* OCARINA_CORE_QUEUE_H */
|
||||
|
|
|
@ -302,7 +302,7 @@ static void test_sorting()
|
|||
q.add(track);
|
||||
}
|
||||
|
||||
q.sort(COMPARE_COUNT, true);
|
||||
queue_sort(&q, COMPARE_COUNT, true);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
|
@ -311,7 +311,7 @@ static void test_sorting()
|
|||
test_equal(count_sort, 1);
|
||||
|
||||
queue_set_flag(&q, Q_NO_SORT);
|
||||
q.sort(COMPARE_TITLE, true);
|
||||
queue_sort(&q, COMPARE_TITLE, true);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
|
@ -319,7 +319,7 @@ static void test_sorting()
|
|||
} test_loop_passed();
|
||||
|
||||
queue_unset_flag(&q, Q_NO_SORT);
|
||||
q.sort(COMPARE_TITLE, true);
|
||||
queue_sort(&q, COMPARE_TITLE, true);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
|
@ -327,9 +327,9 @@ static void test_sorting()
|
|||
} test_loop_passed();
|
||||
test_equal(count_sort, 2);
|
||||
|
||||
q.sort(COMPARE_COUNT, true);
|
||||
q.sort(COMPARE_TITLE, false);
|
||||
q.sort(COMPARE_COUNT, false);
|
||||
queue_sort(&q, COMPARE_COUNT, true);
|
||||
queue_sort(&q, COMPARE_TITLE, false);
|
||||
queue_sort(&q, COMPARE_COUNT, false);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
|
@ -338,10 +338,10 @@ static void test_sorting()
|
|||
test_equal(count_sort, 5);
|
||||
|
||||
queue_unset_flag(&q, Q_SAVE_SORT);
|
||||
q.sort(COMPARE_ARTIST, true);
|
||||
q.sort(COMPARE_ALBUM, false);
|
||||
q.sort(COMPARE_TRACK, false);
|
||||
q.sort(COMPARE_TRACK, false);
|
||||
queue_sort(&q, COMPARE_ARTIST, true);
|
||||
queue_sort(&q, COMPARE_ALBUM, false);
|
||||
queue_sort(&q, COMPARE_TRACK, false);
|
||||
queue_sort(&q, COMPARE_TRACK, false);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
|
@ -362,8 +362,8 @@ static void test_save_load()
|
|||
|
||||
for (i = 0; i < 13; i++)
|
||||
q.add(track_get(i));
|
||||
q.sort(COMPARE_TRACK, true);
|
||||
q.sort(COMPARE_TRACK, false);
|
||||
queue_sort(&q, COMPARE_TRACK, true);
|
||||
queue_sort(&q, COMPARE_TRACK, false);
|
||||
|
||||
file_init(&f, "test.q", 0);
|
||||
file_open(&f, OPEN_WRITE);
|
||||
|
|
Loading…
Reference in New Issue