core/collection: Wire up the qop_save() operation
This will be triggered both when queue flags are changed and when the queue is sorted. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
ce55ef2421
commit
9451a41ff1
|
@ -12,11 +12,11 @@ extern "C" {
|
|||
#include <core/playlist.h>
|
||||
|
||||
|
||||
void core :: init()
|
||||
void core :: init(struct core_init_data *init)
|
||||
{
|
||||
filter_init();
|
||||
tags_init();
|
||||
collection :: init();
|
||||
collection :: init(init->collection_ops);
|
||||
playlist :: init();
|
||||
deck :: init();
|
||||
audio :: init();
|
||||
|
|
|
@ -25,7 +25,9 @@ public:
|
|||
{
|
||||
std::vector<struct sort_info>::iterator it;
|
||||
|
||||
file_open(&f, OPEN_WRITE);
|
||||
if (!file_open(&f, OPEN_WRITE))
|
||||
return;
|
||||
|
||||
file_writef(&f, "%u %u", q_flags, q_sort.size());
|
||||
for (it = q_sort.begin(); it != q_sort.end(); it++)
|
||||
file_writef(&f, " %u %d", it->field, it->ascending);
|
||||
|
@ -51,16 +53,6 @@ public:
|
|||
}
|
||||
file_close(&f);
|
||||
}
|
||||
|
||||
void set_flag(queue_flags f) { queue :: set_flag(f); save(); }
|
||||
void unset_flag(queue_flags f) { queue :: unset_flag(f); save(); }
|
||||
|
||||
void sort(compare_t field, bool ascending)
|
||||
{
|
||||
queue :: sort(field, ascending);
|
||||
save();
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
static LibraryQueue library_q;
|
||||
|
@ -147,11 +139,11 @@ static void validate_library(void *data)
|
|||
* External API begins here
|
||||
*/
|
||||
|
||||
void collection :: init()
|
||||
void collection :: init(struct queue_ops *ops)
|
||||
{
|
||||
struct db_entry *track, *next;
|
||||
|
||||
queue_init(&library_q, Q_ENABLED | Q_REPEAT, NULL);
|
||||
queue_init(&library_q, Q_ENABLED | Q_REPEAT, ops);
|
||||
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
if (TRACK(track)->tr_library->li_enabled)
|
||||
|
@ -164,6 +156,14 @@ void collection :: init()
|
|||
library_q.sort(COMPARE_YEAR, false);
|
||||
library_q.sort(COMPARE_TRACK, false);
|
||||
}
|
||||
|
||||
library_q.set_flag(Q_SAVE_SORT);
|
||||
library_q.set_flag(Q_SAVE_FLAGS);
|
||||
}
|
||||
|
||||
void collection :: save(struct queue *queue, enum queue_flags flag)
|
||||
{
|
||||
library_q.save();
|
||||
}
|
||||
|
||||
struct library *collection :: add(const std::string &dir)
|
||||
|
|
|
@ -48,6 +48,10 @@ public:
|
|||
|
||||
static CollectionTab *collection_tab;
|
||||
|
||||
struct queue_ops collection_ops = {
|
||||
collection :: save,
|
||||
};
|
||||
|
||||
void init_collection_tab()
|
||||
{
|
||||
collection_tab = new CollectionTab;
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
static std::string ocarina_dir = "";
|
||||
static Glib::RefPtr<Gtk::Application> ocarina_app;
|
||||
|
||||
|
||||
struct core_init_data init_data = {
|
||||
&collection_ops,
|
||||
};
|
||||
|
||||
namespace gui
|
||||
{
|
||||
Glib::RefPtr<Gtk::Builder> __O_BUILDER;
|
||||
|
@ -47,7 +52,7 @@ int main(int argc, char **argv)
|
|||
|
||||
gst :: init(&argc, &argv);
|
||||
|
||||
core :: init();
|
||||
core :: init(&init_data);
|
||||
|
||||
plist :: init();
|
||||
manager :: init();
|
||||
|
|
|
@ -4,6 +4,13 @@
|
|||
#ifndef OCARINA_CORE_CORE_H
|
||||
#define OCARINA_CORE_CORE_H
|
||||
|
||||
#include <core/queue.h>
|
||||
|
||||
|
||||
struct core_init_data {
|
||||
struct queue_ops *collection_ops;
|
||||
};
|
||||
|
||||
/**
|
||||
* Namespace for basic core library functions.
|
||||
*/
|
||||
|
@ -14,7 +21,7 @@ namespace core
|
|||
* Initializes all components of the core library, including reading
|
||||
* databases from disk and setting up gstreamer.
|
||||
*/
|
||||
void init();
|
||||
void init(struct core_init_data *);
|
||||
void deinit();
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace collection
|
|||
* Scan over every Track tag and add each enabled Track to the
|
||||
* library queue.
|
||||
*/
|
||||
void init();
|
||||
void init(struct queue_ops *);
|
||||
|
||||
void save(struct queue *, enum queue_flags);
|
||||
|
||||
/**
|
||||
* Add a new directory to the library.
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace gui
|
|||
}
|
||||
}
|
||||
|
||||
extern struct queue_ops collection_ops;
|
||||
|
||||
void on_pq_created(queue *, unsigned int);
|
||||
void post_init_queue_tabs();
|
||||
|
|
|
@ -88,7 +88,7 @@ void test_init()
|
|||
|
||||
filter_init();
|
||||
tags_init();
|
||||
collection :: init();
|
||||
collection :: init(NULL);
|
||||
deck :: init();
|
||||
audio :: init();
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ static void test_init()
|
|||
test_cp_data_dir();
|
||||
filter_init();
|
||||
tags_init();
|
||||
collection :: init();
|
||||
collection :: init(NULL);
|
||||
deck :: init();
|
||||
|
||||
test_equal(queue_has_flag(collection :: get_queue(), Q_RANDOM), true);
|
||||
|
|
|
@ -19,7 +19,7 @@ static void test_init()
|
|||
test_cp_data_dir();
|
||||
filter_init();
|
||||
tags_init();
|
||||
collection :: init();
|
||||
collection :: init(NULL);
|
||||
|
||||
test_not_equal(q, Q_NULL);
|
||||
test_equal(queue_has_flag(q, Q_ENABLED), true);
|
||||
|
|
|
@ -20,7 +20,7 @@ static void test_init()
|
|||
test_cp_data_dir();
|
||||
filter_init();
|
||||
tags_init();
|
||||
collection :: init();
|
||||
collection :: init(NULL);
|
||||
playlist :: init();
|
||||
|
||||
test_not_equal(q, Q_NULL);
|
||||
|
|
Loading…
Reference in New Issue