core/queue: Add queue_{save, load}_flags() function
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
92a53d90b4
commit
7f0e1ecc99
|
@ -125,8 +125,6 @@ static bool __validate_library(void *data)
|
|||
bool __collection_init_idle(void *data)
|
||||
{
|
||||
struct db_entry *track, *next;
|
||||
unsigned int i, n = 0;
|
||||
int field, ascending;
|
||||
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
if (TRACK(track)->tr_library->li_enabled &&
|
||||
|
@ -135,16 +133,10 @@ bool __collection_init_idle(void *data)
|
|||
}
|
||||
queue_unset_flag(&c_queue, Q_ADD_FRONT);
|
||||
|
||||
if (file_open(&c_file, OPEN_READ))
|
||||
file_readf(&c_file, "%u %u", &c_queue.q_flags, &n);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
file_readf(&c_file, "%u %d", &field, &ascending);
|
||||
queue_sort(&c_queue, field + 1, (i == 0) ? true : false);
|
||||
if (ascending == false)
|
||||
queue_sort(&c_queue, field + 1, false);
|
||||
if (file_open(&c_file, OPEN_READ)) {
|
||||
queue_load_flags(&c_queue, &c_file);
|
||||
file_close(&c_file);
|
||||
}
|
||||
file_close(&c_file);
|
||||
|
||||
if (!c_queue.q_sort) {
|
||||
queue_sort(&c_queue, COMPARE_ARTIST, true);
|
||||
|
@ -177,21 +169,12 @@ void collection_deinit()
|
|||
|
||||
void collection_save(struct queue *queue, enum queue_flags flag)
|
||||
{
|
||||
GSList *cur = c_queue.q_sort;
|
||||
int field;
|
||||
|
||||
if (&c_queue != queue)
|
||||
return;
|
||||
if (!file_open(&c_file, OPEN_WRITE))
|
||||
return;
|
||||
|
||||
file_writef(&c_file, "%u %u", c_queue.q_flags, g_slist_length(cur));
|
||||
while (cur) {
|
||||
field = GPOINTER_TO_INT(cur->data);
|
||||
file_writef(&c_file, " %u %d", abs(field) - 1, field > 0);
|
||||
cur = g_slist_next(cur);
|
||||
}
|
||||
file_writef(&c_file, "\n");
|
||||
queue_save_flags(&c_queue, &c_file);
|
||||
file_close(&c_file);
|
||||
}
|
||||
|
||||
|
|
30
core/queue.c
30
core/queue.c
|
@ -154,6 +154,20 @@ void queue_deinit(struct queue *queue)
|
|||
queue->q_sort = NULL;
|
||||
}
|
||||
|
||||
void queue_save_flags(struct queue *queue, struct file *file)
|
||||
{
|
||||
GSList *cur = queue->q_sort;
|
||||
int field;
|
||||
|
||||
file_writef(file, "%u %u", queue->q_flags, g_slist_length(cur));
|
||||
while (cur) {
|
||||
field = GPOINTER_TO_INT(cur->data);
|
||||
file_writef(file, " %u %d", abs(field) - 1, field > 0);
|
||||
cur = g_slist_next(cur);
|
||||
}
|
||||
file_writef(file, "\n");
|
||||
}
|
||||
|
||||
void queue_save_tracks(struct queue *queue, struct file *file)
|
||||
{
|
||||
struct queue_iter it;
|
||||
|
@ -163,6 +177,22 @@ void queue_save_tracks(struct queue *queue, struct file *file)
|
|||
file_writef(file, " %u", queue_iter_val(&it)->tr_dbe.dbe_index);
|
||||
}
|
||||
|
||||
void queue_load_flags(struct queue *queue, struct file *file)
|
||||
{
|
||||
unsigned int flags, n, i;
|
||||
int field, ascending;
|
||||
|
||||
file_readf(file, "%u %u", &flags, &n);
|
||||
for (i = 0; i < n; i++) {
|
||||
file_readf(file, "%u %d", &field, &ascending);
|
||||
queue_sort(queue, field + 1, (i == 0) ? true : false);
|
||||
if (ascending == false)
|
||||
queue_sort(queue, field + 1, false);
|
||||
}
|
||||
|
||||
queue->q_flags |= flags;
|
||||
}
|
||||
|
||||
void queue_load_tracks(struct queue *queue, struct file *file)
|
||||
{
|
||||
unsigned int i, n, t;
|
||||
|
|
|
@ -118,9 +118,15 @@ void queue_init(struct queue *, unsigned int, const struct queue_ops *);
|
|||
void queue_deinit(struct queue *);
|
||||
|
||||
|
||||
/* Called to save queue flags */
|
||||
void queue_save_flags(struct queue *, struct file *);
|
||||
|
||||
/* Called to save the list of queued tracks. */
|
||||
void queue_save_tracks(struct queue *, struct file *);
|
||||
|
||||
/* Called to load queue flags from file. */
|
||||
void queue_load_flags(struct queue *, struct file *);
|
||||
|
||||
/* Called to load queued tracks from file. */
|
||||
void queue_load_tracks(struct queue *, struct file *);
|
||||
|
||||
|
|
Loading…
Reference in New Issue