Library: Rename count -> _size
Also make it private and provide accessor functions. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
754d45efd0
commit
ce8b3ada03
|
@ -31,13 +31,13 @@ Track :: Track(const std::string &f, Library *l)
|
||||||
play_count(0), last_year(0), last_month(0), last_day(0),
|
play_count(0), last_year(0), last_month(0), last_day(0),
|
||||||
filepath(f.substr(l->primary_key().size() + 1))
|
filepath(f.substr(l->primary_key().size() + 1))
|
||||||
{
|
{
|
||||||
library->count++;
|
library->inc_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Track :: ~Track()
|
Track :: ~Track()
|
||||||
{
|
{
|
||||||
if (library)
|
if (library)
|
||||||
library->count--;
|
library->dec_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Track :: primary_key() const
|
const std::string Track :: primary_key() const
|
||||||
|
@ -64,7 +64,7 @@ void Track :: read(File &f)
|
||||||
title_lower = filter :: add(title, index());
|
title_lower = filter :: add(title, index());
|
||||||
filter :: add(artist->name(), index());
|
filter :: add(artist->name(), index());
|
||||||
filter :: add(album->name(), index());
|
filter :: add(album->name(), index());
|
||||||
library->count++;
|
library->inc_size();
|
||||||
set_length_str();
|
set_length_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ bool Track :: tag()
|
||||||
TagLib :: AudioProperties *audio;
|
TagLib :: AudioProperties *audio;
|
||||||
TagLib :: FileRef ref(path().c_str(), true, TagLib::AudioProperties::Fast);
|
TagLib :: FileRef ref(path().c_str(), true, TagLib::AudioProperties::Fast);
|
||||||
|
|
||||||
library->count++;
|
library->inc_size();
|
||||||
if (ref.isNull()) {
|
if (ref.isNull()) {
|
||||||
print("WARNING: Could not read tags for file %s\n", path().c_str());
|
print("WARNING: Could not read tags for file %s\n", path().c_str());
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
#include <core/tags/library.h>
|
#include <core/tags/library.h>
|
||||||
|
|
||||||
Library :: Library()
|
Library :: Library()
|
||||||
: _enabled(false), count(0)
|
: _size(0), _enabled(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Library :: Library(const std::string &s)
|
Library :: Library(const std::string &s)
|
||||||
: _path(s), _enabled(true), count(0)
|
: _size(0), _path(s), _enabled(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,3 +39,18 @@ void Library :: set_enabled(bool enabled)
|
||||||
{
|
{
|
||||||
_enabled = enabled;
|
_enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unsigned int Library :: size()
|
||||||
|
{
|
||||||
|
return _size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Library :: inc_size()
|
||||||
|
{
|
||||||
|
_size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Library :: dec_size()
|
||||||
|
{
|
||||||
|
_size--;
|
||||||
|
}
|
||||||
|
|
|
@ -12,13 +12,11 @@
|
||||||
*/
|
*/
|
||||||
class Library : public DatabaseEntry {
|
class Library : public DatabaseEntry {
|
||||||
private:
|
private:
|
||||||
|
unsigned int _size; /**< Number of tracks in this library. */
|
||||||
std::string _path; /**< Path to the root directory of this library. */
|
std::string _path; /**< Path to the root directory of this library. */
|
||||||
bool _enabled; /**< Is this library path enabled? */
|
bool _enabled; /**< Is this library path enabled? */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Number of tracks in this library */
|
|
||||||
unsigned int count;
|
|
||||||
|
|
||||||
/** Library constructor */
|
/** Library constructor */
|
||||||
Library();
|
Library();
|
||||||
|
|
||||||
|
@ -60,6 +58,24 @@ public:
|
||||||
* @param enabled True if this path should be enabled, false otherwise.
|
* @param enabled True if this path should be enabled, false otherwise.
|
||||||
*/
|
*/
|
||||||
void set_enabled(bool);
|
void set_enabled(bool);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to access the number of tracks in this library.
|
||||||
|
*
|
||||||
|
* @return Library::_size.
|
||||||
|
*/
|
||||||
|
const unsigned int size();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to increase _size by 1.
|
||||||
|
*/
|
||||||
|
void inc_size();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to decrease _size by 1.
|
||||||
|
*/
|
||||||
|
void dec_size();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* OCARINA_CORE_TAGS_LIBRARY_H */
|
#endif /* OCARINA_CORE_TAGS_LIBRARY_H */
|
||||||
|
|
|
@ -45,7 +45,7 @@ static void list_path(Library *lib)
|
||||||
|
|
||||||
row[c_cols.c_id] = lib->index();
|
row[c_cols.c_id] = lib->index();
|
||||||
row[c_cols.c_enabled] = lib->enabled();
|
row[c_cols.c_enabled] = lib->enabled();
|
||||||
row[c_cols.c_size] = lib->count;
|
row[c_cols.c_size] = lib->size();
|
||||||
row[c_cols.c_path] = lib->primary_key();
|
row[c_cols.c_path] = lib->primary_key();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ void colmgr :: update_paths()
|
||||||
for (it = c_list->children().begin(); it != c_list->children().end(); it++) {
|
for (it = c_list->children().begin(); it != c_list->children().end(); it++) {
|
||||||
lib = find_library(*it);
|
lib = find_library(*it);
|
||||||
if (lib)
|
if (lib)
|
||||||
(*it)[c_cols.c_size] = lib->count;
|
(*it)[c_cols.c_size] = lib->size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,18 @@ static void test_library_tag()
|
||||||
File f("library_tag", 0);
|
File f("library_tag", 0);
|
||||||
|
|
||||||
test_equal(library.primary_key(), (std::string)"/home/Zelda/Music");
|
test_equal(library.primary_key(), (std::string)"/home/Zelda/Music");
|
||||||
test_equal(library.count, (unsigned)0);
|
test_equal(library.size(), (unsigned)0);
|
||||||
test_equal(library.enabled(), true);
|
test_equal(library.enabled(), true);
|
||||||
|
|
||||||
library.count = 42; /* not saved to disk */
|
|
||||||
|
for (unsigned int i = 0; i < 42; i++)
|
||||||
|
library.inc_size();
|
||||||
|
test_equal(library.size(), (unsigned)42);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < 21; i++)
|
||||||
|
library.dec_size();
|
||||||
|
test_equal(library.size(), (unsigned)21);
|
||||||
|
|
||||||
|
|
||||||
f.open(OPEN_WRITE);
|
f.open(OPEN_WRITE);
|
||||||
library.write(f);
|
library.write(f);
|
||||||
|
@ -22,7 +30,7 @@ static void test_library_tag()
|
||||||
|
|
||||||
library = Library();
|
library = Library();
|
||||||
test_equal(library.primary_key(), (std::string)"");
|
test_equal(library.primary_key(), (std::string)"");
|
||||||
test_equal(library.count, (unsigned)0);
|
test_equal(library.size(), (unsigned)0);
|
||||||
test_equal(library.enabled(), false);
|
test_equal(library.enabled(), false);
|
||||||
|
|
||||||
f.open(OPEN_READ);
|
f.open(OPEN_READ);
|
||||||
|
@ -30,7 +38,7 @@ static void test_library_tag()
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
test_equal(library.primary_key(), (std::string)"/home/Zelda/Music");
|
test_equal(library.primary_key(), (std::string)"/home/Zelda/Music");
|
||||||
test_equal(library.count, (unsigned)0);
|
test_equal(library.size(), (unsigned)0); /* _size is not saved to disk. */
|
||||||
test_equal(library.enabled(), true);
|
test_equal(library.enabled(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue