diff --git a/core/library.cpp b/core/library.cpp index 5817b5bc..51111526 100644 --- a/core/library.cpp +++ b/core/library.cpp @@ -212,13 +212,10 @@ void collection :: update(struct library *library) void collection :: update_all() { - struct library *library; + struct library *library, *next; - for (unsigned int i = 0; i < tags :: library_size(); i++) { - library = library_get(i); - if (library) - update(library); - } + db_for_each(library, next, library_db_get()) + update(library); } void collection :: set_enabled(struct library *library, bool enabled) diff --git a/core/tags/library.cpp b/core/tags/library.cpp index 8627227f..44da68e0 100644 --- a/core/tags/library.cpp +++ b/core/tags/library.cpp @@ -78,6 +78,11 @@ void library_db_deinit() db_deinit(&library_db); } +const database *library_db_get() +{ + return &library_db; +} + struct library *library_find(const std::string &path) { return db_find(&library_db, path.c_str()); @@ -93,8 +98,3 @@ void library_remove(struct library *library) if (library) db_remove(&library_db, library); } - -unsigned int tags :: library_size() -{ - return db_actual_size(&library_db); -} diff --git a/gui/manager.cpp b/gui/manager.cpp index 553b7202..a6295271 100644 --- a/gui/manager.cpp +++ b/gui/manager.cpp @@ -174,6 +174,8 @@ static void on_toggled(const Glib::ustring &str) void manager :: init() { + struct library *library, *next; + c_add = gui :: get_widget("colmgr_add"); c_update = gui :: get_widget("colmgr_update"); @@ -192,6 +194,6 @@ void manager :: init() 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)); - for (unsigned int i = 0; i < tags :: library_size(); i++) - list_path(library_get(i)); + db_for_each(library, next, library_db_get()) + list_path(library); } diff --git a/include/core/tags/library.h b/include/core/tags/library.h index c51fb86a..963589f0 100644 --- a/include/core/tags/library.h +++ b/include/core/tags/library.h @@ -86,19 +86,6 @@ struct library : public DatabaseEntry { 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. */ void library_db_init(); @@ -106,6 +93,9 @@ void library_db_init(); /* Called to clean up the library database. */ void library_db_deinit(); +/* Called to access the library database. */ +const database *library_db_get(); + /* Called to find a library tag by library path. */ struct library *library_find(const std::string &); diff --git a/tests/core/tags/library.cpp b/tests/core/tags/library.cpp index 25d50b00..377f5718 100644 --- a/tests/core/tags/library.cpp +++ b/tests/core/tags/library.cpp @@ -71,13 +71,14 @@ static void test_library_db() database library_db; 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 = library_find("/home/Zelda/Music"); 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_get(0), library); test_equal(library_get(1), (struct library *)NULL); @@ -93,7 +94,7 @@ static void test_library_db() library_remove(library); 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(); db_deinit(&library_db);