summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-12-06 19:24:57 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-12-06 19:24:57 +0100
commitf536558610b76d417bfea081d8230bf52db964a0 (patch)
tree4b517f889b041f45ae21e315c7914eb12f8cc4c4
parented61ec21a21378e55dcfa87c04b2a6823e74e67f (diff)
sorting for search window
-rw-r--r--deadbeef.h2
-rw-r--r--playlist.c45
-rw-r--r--playlist.h2
-rw-r--r--plugins/gtkui/gtkplaylist.c2
4 files changed, 22 insertions, 29 deletions
diff --git a/deadbeef.h b/deadbeef.h
index c87de95f..ff5d5ddc 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -284,7 +284,7 @@ typedef struct {
void (*pl_delete_all_meta) (DB_playItem_t *it);
void (*pl_set_item_duration) (DB_playItem_t *it, float duration);
float (*pl_get_item_duration) (DB_playItem_t *it);
- void (*pl_sort) (int id, const char *format, int ascending);
+ void (*pl_sort) (int iter, int id, const char *format, int ascending);
// cuesheet support
DB_playItem_t *(*pl_insert_cue_from_buffer) (DB_playItem_t *after, const char *fname, const uint8_t *buffer, int buffersize, struct DB_decoder_s *decoder, const char *ftype, int numsamples, int samplerate);
DB_playItem_t * (*pl_insert_cue) (DB_playItem_t *after, const char *filename, struct DB_decoder_s *decoder, const char *ftype, int numsamples, int samplerate);
diff --git a/playlist.c b/playlist.c
index 68af5381..6c73b900 100644
--- a/playlist.c
+++ b/playlist.c
@@ -1717,16 +1717,14 @@ pl_format_title (playItem_t *it, char *s, int size, int id, const char *fmt) {
}
void
-pl_sort (int id, const char *format, int ascending) {
+pl_sort (int iter, int id, const char *format, int ascending) {
int sorted = 0;
- int iter = 0;
do {
-// printf ("iter: %d\n", iter);
sorted = 1;
playItem_t *it;
playItem_t *next = NULL;
- for (it = playlist_head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
- playItem_t *next = it->next[PL_MAIN];
+ for (it = playlist_head[iter]; it; it = it->next[iter]) {
+ playItem_t *next = it->next[iter];
if (!next) {
break;
}
@@ -1741,33 +1739,30 @@ pl_sort (int id, const char *format, int ascending) {
// printf ("%p %p swapping %s and %s\n", it, next, meta1, meta2);
sorted = 0;
// swap them
- if (it->prev[PL_MAIN]) {
- it->prev[PL_MAIN]->next[PL_MAIN] = next;
+ if (it->prev[iter]) {
+ it->prev[iter]->next[iter] = next;
// printf ("it->prev->next = it->next\n");
}
else {
- playlist_head[PL_MAIN] = next;
- next->prev[PL_MAIN] = NULL;
+ playlist_head[iter] = next;
+ next->prev[iter] = NULL;
// printf ("head = it->next\n");
}
- if (next->next[PL_MAIN]) {
- next->next[PL_MAIN]->prev[PL_MAIN] = it;
+ if (next->next[iter]) {
+ next->next[iter]->prev[iter] = it;
// printf ("it->next->next->prev = it\n");
}
else {
- playlist_tail[PL_MAIN] = it;
- it->next[PL_MAIN] = NULL;
+ playlist_tail[iter] = it;
+ it->next[iter] = NULL;
// printf ("tail = it\n");
}
- playItem_t *it_prev = it->prev[PL_MAIN];
- it->next[PL_MAIN] = next->next[PL_MAIN];
- it->prev[PL_MAIN] = next;
- next->next[PL_MAIN] = it;
- next->prev[PL_MAIN] = it_prev;
+ playItem_t *it_prev = it->prev[iter];
+ it->next[iter] = next->next[iter];
+ it->prev[iter] = next;
+ next->next[iter] = it;
+ next->prev[iter] = it_prev;
it = next;
-// if (iter >= 10) {
-// exit (0);
-// }
}
#if 0
else {
@@ -1778,10 +1773,10 @@ pl_sort (int id, const char *format, int ascending) {
// print list
int k = 0;
playItem_t *p = NULL;
- for (playItem_t *i = playlist_head[PL_MAIN]; i; p = i, i = i->next[PL_MAIN], k++) {
+ for (playItem_t *i = playlist_head[iter]; i; p = i, i = i->next[iter], k++) {
printf ("%p ", i);
- if (i->prev[PL_MAIN] != p) {
- printf ("\n\033[0;33mbroken link, i=%p, i->prev=%p, prev=%p\033[37;0m\n", i, i->prev[PL_MAIN], p);
+ if (i->prev[iter] != p) {
+ printf ("\n\033[0;33mbroken link, i=%p, i->prev=%p, prev=%p\033[37;0m\n", i, i->prev[iter], p);
}
if (k > 20) {
printf ("\033[0;31mlist corrupted\033[37;0m\n");
@@ -1791,9 +1786,7 @@ pl_sort (int id, const char *format, int ascending) {
printf ("\n");
#endif
}
- iter++;
} while (!sorted);
-// printf ("sorted in %d iterations\n", iter);
}
void
diff --git a/playlist.h b/playlist.h
index 5a4d5208..7350227e 100644
--- a/playlist.h
+++ b/playlist.h
@@ -212,6 +212,6 @@ int
pl_process_search (const char *text);
void
-pl_sort (int id, const char *format, int ascending);
+pl_sort (int iter, int id, const char *format, int ascending);
#endif // __PLAYLIST_H
diff --git a/plugins/gtkui/gtkplaylist.c b/plugins/gtkui/gtkplaylist.c
index 69a3d866..0bf5f368 100644
--- a/plugins/gtkui/gtkplaylist.c
+++ b/plugins/gtkui/gtkplaylist.c
@@ -1530,7 +1530,7 @@ on_header_button_release_event (GtkWidget *widget,
else if (c->sort_order == 2) {
c->sort_order = 1;
}
- deadbeef->pl_sort (c->id, c->format, c->sort_order-1);
+ deadbeef->pl_sort (ps == &main_playlist ? PL_MAIN : PL_SEARCH, c->id, c->format, c->sort_order-1);
sorted = 1;
}
else {