core/tags/library: Replace tags :: library_size() with library_db_get()
It's easier to just pass off the library database rather than forcing higher layers to iterate over the entire thing (including possible invalid entries). Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
768f86e802
commit
f41235e5b2
|
@ -212,13 +212,10 @@ void collection :: update(struct library *library)
|
||||||
|
|
||||||
void collection :: update_all()
|
void collection :: update_all()
|
||||||
{
|
{
|
||||||
struct library *library;
|
struct library *library, *next;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tags :: library_size(); i++) {
|
db_for_each(library, next, library_db_get())
|
||||||
library = library_get(i);
|
update(library);
|
||||||
if (library)
|
|
||||||
update(library);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void collection :: set_enabled(struct library *library, bool enabled)
|
void collection :: set_enabled(struct library *library, bool enabled)
|
||||||
|
|
|
@ -78,6 +78,11 @@ void library_db_deinit()
|
||||||
db_deinit(&library_db);
|
db_deinit(&library_db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const database<struct library> *library_db_get()
|
||||||
|
{
|
||||||
|
return &library_db;
|
||||||
|
}
|
||||||
|
|
||||||
struct library *library_find(const std::string &path)
|
struct library *library_find(const std::string &path)
|
||||||
{
|
{
|
||||||
return db_find(&library_db, path.c_str());
|
return db_find(&library_db, path.c_str());
|
||||||
|
@ -93,8 +98,3 @@ void library_remove(struct library *library)
|
||||||
if (library)
|
if (library)
|
||||||
db_remove(&library_db, library);
|
db_remove(&library_db, library);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int tags :: library_size()
|
|
||||||
{
|
|
||||||
return db_actual_size(&library_db);
|
|
||||||
}
|
|
||||||
|
|
|
@ -174,6 +174,8 @@ static void on_toggled(const Glib::ustring &str)
|
||||||
|
|
||||||
void manager :: init()
|
void manager :: init()
|
||||||
{
|
{
|
||||||
|
struct library *library, *next;
|
||||||
|
|
||||||
c_add = gui :: get_widget<Gtk::Button>("colmgr_add");
|
c_add = gui :: get_widget<Gtk::Button>("colmgr_add");
|
||||||
c_update = gui :: get_widget<Gtk::Button>("colmgr_update");
|
c_update = gui :: get_widget<Gtk::Button>("colmgr_update");
|
||||||
|
|
||||||
|
@ -192,6 +194,6 @@ void manager :: init()
|
||||||
c_treeview->signal_cursor_changed().connect(sigc::ptr_fun(on_cursor_changed));
|
c_treeview->signal_cursor_changed().connect(sigc::ptr_fun(on_cursor_changed));
|
||||||
c_treeview->signal_key_press_event().connect(sigc::ptr_fun(on_key_pressed));
|
c_treeview->signal_key_press_event().connect(sigc::ptr_fun(on_key_pressed));
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tags :: library_size(); i++)
|
db_for_each(library, next, library_db_get())
|
||||||
list_path(library_get(i));
|
list_path(library);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,19 +86,6 @@ struct library : public DatabaseEntry {
|
||||||
void dec_size();
|
void dec_size();
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace tags
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called to find the number of rows in the library_db,
|
|
||||||
* including NULL rows.
|
|
||||||
*
|
|
||||||
* @return The Database::actual_size() of the library_db.
|
|
||||||
*/
|
|
||||||
unsigned int library_size();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Called to initialize the library database. */
|
/* Called to initialize the library database. */
|
||||||
void library_db_init();
|
void library_db_init();
|
||||||
|
@ -106,6 +93,9 @@ void library_db_init();
|
||||||
/* Called to clean up the library database. */
|
/* Called to clean up the library database. */
|
||||||
void library_db_deinit();
|
void library_db_deinit();
|
||||||
|
|
||||||
|
/* Called to access the library database. */
|
||||||
|
const database<struct library> *library_db_get();
|
||||||
|
|
||||||
/* Called to find a library tag by library path. */
|
/* Called to find a library tag by library path. */
|
||||||
struct library *library_find(const std::string &);
|
struct library *library_find(const std::string &);
|
||||||
|
|
||||||
|
|
|
@ -71,13 +71,14 @@ static void test_library_db()
|
||||||
database<struct library> library_db;
|
database<struct library> library_db;
|
||||||
struct library *library, *library2;
|
struct library *library, *library2;
|
||||||
|
|
||||||
test_equal(tags :: library_size(), 0);
|
test_not_equal(library_db_get(), NULL);
|
||||||
|
test_equal(library_db_get()->db_size, 0);
|
||||||
|
|
||||||
library_db_init();
|
library_db_init();
|
||||||
library = library_find("/home/Zelda/Music");
|
library = library_find("/home/Zelda/Music");
|
||||||
test_verify_zelda(library);
|
test_verify_zelda(library);
|
||||||
|
|
||||||
test_equal(tags :: library_size(), 1);
|
test_equal(library_db_get()->db_size, 1);
|
||||||
test_equal(library_find("/home/Zelda/Music"), library);
|
test_equal(library_find("/home/Zelda/Music"), library);
|
||||||
test_equal(library_get(0), library);
|
test_equal(library_get(0), library);
|
||||||
test_equal(library_get(1), (struct library *)NULL);
|
test_equal(library_get(1), (struct library *)NULL);
|
||||||
|
@ -93,7 +94,7 @@ static void test_library_db()
|
||||||
|
|
||||||
library_remove(library);
|
library_remove(library);
|
||||||
test_equal(library_get(0), (struct library *)NULL);
|
test_equal(library_get(0), (struct library *)NULL);
|
||||||
test_equal(tags :: library_size(), 1);
|
test_equal(library_db_get()->db_size, 0);
|
||||||
|
|
||||||
library_db_deinit();
|
library_db_deinit();
|
||||||
db_deinit(&library_db);
|
db_deinit(&library_db);
|
||||||
|
|
Loading…
Reference in New Issue