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:
Anna Schumaker 2015-11-24 08:18:31 -05:00
parent ce55ef2421
commit 9451a41ff1
11 changed files with 41 additions and 22 deletions

View File

@ -12,11 +12,11 @@ extern "C" {
#include <core/playlist.h> #include <core/playlist.h>
void core :: init() void core :: init(struct core_init_data *init)
{ {
filter_init(); filter_init();
tags_init(); tags_init();
collection :: init(); collection :: init(init->collection_ops);
playlist :: init(); playlist :: init();
deck :: init(); deck :: init();
audio :: init(); audio :: init();

View File

@ -25,7 +25,9 @@ public:
{ {
std::vector<struct sort_info>::iterator it; 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()); file_writef(&f, "%u %u", q_flags, q_sort.size());
for (it = q_sort.begin(); it != q_sort.end(); it++) for (it = q_sort.begin(); it != q_sort.end(); it++)
file_writef(&f, " %u %d", it->field, it->ascending); file_writef(&f, " %u %d", it->field, it->ascending);
@ -51,16 +53,6 @@ public:
} }
file_close(&f); 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; static LibraryQueue library_q;
@ -147,11 +139,11 @@ static void validate_library(void *data)
* External API begins here * External API begins here
*/ */
void collection :: init() void collection :: init(struct queue_ops *ops)
{ {
struct db_entry *track, *next; 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()) { db_for_each(track, next, track_db_get()) {
if (TRACK(track)->tr_library->li_enabled) if (TRACK(track)->tr_library->li_enabled)
@ -164,6 +156,14 @@ void collection :: init()
library_q.sort(COMPARE_YEAR, false); library_q.sort(COMPARE_YEAR, false);
library_q.sort(COMPARE_TRACK, 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) struct library *collection :: add(const std::string &dir)

View File

@ -48,6 +48,10 @@ public:
static CollectionTab *collection_tab; static CollectionTab *collection_tab;
struct queue_ops collection_ops = {
collection :: save,
};
void init_collection_tab() void init_collection_tab()
{ {
collection_tab = new CollectionTab; collection_tab = new CollectionTab;

View File

@ -9,6 +9,11 @@
static std::string ocarina_dir = ""; static std::string ocarina_dir = "";
static Glib::RefPtr<Gtk::Application> ocarina_app; static Glib::RefPtr<Gtk::Application> ocarina_app;
struct core_init_data init_data = {
&collection_ops,
};
namespace gui namespace gui
{ {
Glib::RefPtr<Gtk::Builder> __O_BUILDER; Glib::RefPtr<Gtk::Builder> __O_BUILDER;
@ -47,7 +52,7 @@ int main(int argc, char **argv)
gst :: init(&argc, &argv); gst :: init(&argc, &argv);
core :: init(); core :: init(&init_data);
plist :: init(); plist :: init();
manager :: init(); manager :: init();

View File

@ -4,6 +4,13 @@
#ifndef OCARINA_CORE_CORE_H #ifndef OCARINA_CORE_CORE_H
#define 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. * Namespace for basic core library functions.
*/ */
@ -14,7 +21,7 @@ namespace core
* Initializes all components of the core library, including reading * Initializes all components of the core library, including reading
* databases from disk and setting up gstreamer. * databases from disk and setting up gstreamer.
*/ */
void init(); void init(struct core_init_data *);
void deinit(); void deinit();
} }

View File

@ -26,7 +26,9 @@ namespace collection
* Scan over every Track tag and add each enabled Track to the * Scan over every Track tag and add each enabled Track to the
* library queue. * library queue.
*/ */
void init(); void init(struct queue_ops *);
void save(struct queue *, enum queue_flags);
/** /**
* Add a new directory to the library. * Add a new directory to the library.

View File

@ -30,6 +30,7 @@ namespace gui
} }
} }
extern struct queue_ops collection_ops;
void on_pq_created(queue *, unsigned int); void on_pq_created(queue *, unsigned int);
void post_init_queue_tabs(); void post_init_queue_tabs();

View File

@ -88,7 +88,7 @@ void test_init()
filter_init(); filter_init();
tags_init(); tags_init();
collection :: init(); collection :: init(NULL);
deck :: init(); deck :: init();
audio :: init(); audio :: init();

View File

@ -23,7 +23,7 @@ static void test_init()
test_cp_data_dir(); test_cp_data_dir();
filter_init(); filter_init();
tags_init(); tags_init();
collection :: init(); collection :: init(NULL);
deck :: init(); deck :: init();
test_equal(queue_has_flag(collection :: get_queue(), Q_RANDOM), true); test_equal(queue_has_flag(collection :: get_queue(), Q_RANDOM), true);

View File

@ -19,7 +19,7 @@ static void test_init()
test_cp_data_dir(); test_cp_data_dir();
filter_init(); filter_init();
tags_init(); tags_init();
collection :: init(); collection :: init(NULL);
test_not_equal(q, Q_NULL); test_not_equal(q, Q_NULL);
test_equal(queue_has_flag(q, Q_ENABLED), true); test_equal(queue_has_flag(q, Q_ENABLED), true);

View File

@ -20,7 +20,7 @@ static void test_init()
test_cp_data_dir(); test_cp_data_dir();
filter_init(); filter_init();
tags_init(); tags_init();
collection :: init(); collection :: init(NULL);
playlist :: init(); playlist :: init();
test_not_equal(q, Q_NULL); test_not_equal(q, Q_NULL);