library: Track the size of each path
I track the size of each library path for display purposes. I also had to add in a check for if a new track already exists in the db before tagging it so updating a library should be much faster now. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
a2665d4e41
commit
fa51433b94
|
@ -61,6 +61,7 @@ namespace library
|
|||
class Library : public DatabaseEntry {
|
||||
public:
|
||||
std::string root_path;
|
||||
unsigned int size;
|
||||
bool enabled;
|
||||
|
||||
Library();
|
||||
|
|
|
@ -136,12 +136,12 @@ void library :: Album :: print()
|
|||
*/
|
||||
|
||||
library :: Library :: Library()
|
||||
: root_path(""), enabled(false)
|
||||
: root_path(""), size(0), enabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
library :: Library :: Library(const std::string &path, bool is_enabled)
|
||||
: root_path(path), enabled(is_enabled)
|
||||
: root_path(path), size(0), enabled(is_enabled)
|
||||
{
|
||||
primary_key = root_path;
|
||||
}
|
||||
|
@ -150,6 +150,7 @@ void library :: Library :: read(File &f)
|
|||
{
|
||||
f >> enabled;
|
||||
root_path = f.getline();
|
||||
size = 0;
|
||||
}
|
||||
|
||||
void library :: Library :: write(File &f)
|
||||
|
@ -165,6 +166,7 @@ void library :: Library :: print()
|
|||
:: print(" (enabled)");
|
||||
else
|
||||
:: print(" (disabled)");
|
||||
:: print(", size = %u", size);
|
||||
}
|
||||
#endif /* CONFIG_DEBUG */
|
||||
|
||||
|
@ -201,6 +203,8 @@ library :: Track :: Track(TagLib :: Tag *tag, TagLib :: AudioProperties *audio,
|
|||
ss << "0";
|
||||
ss << seconds;
|
||||
length_str = ss.str();
|
||||
|
||||
library_db[library_id].size++;
|
||||
}
|
||||
|
||||
library :: Track :: Track(struct ImportData *data, unsigned int lib,
|
||||
|
@ -225,6 +229,8 @@ library :: Track :: Track(struct ImportData *data, unsigned int lib,
|
|||
ss << "0";
|
||||
ss << seconds;
|
||||
length_str = ss.str();
|
||||
|
||||
library_db[library_id].size++;
|
||||
}
|
||||
|
||||
void library :: Track :: read(File &f)
|
||||
|
@ -235,6 +241,7 @@ void library :: Track :: read(File &f)
|
|||
length_str = f.getline();
|
||||
title = f.getline();
|
||||
filepath = f.getline();
|
||||
library_db[library_id].size++;
|
||||
}
|
||||
|
||||
void library :: Track :: write(File &f)
|
||||
|
@ -304,8 +311,10 @@ static void process_path(unsigned int lib_id, const std :: string &dir,
|
|||
scan.lib_id = lib_id;
|
||||
scan.path = path;
|
||||
idle :: schedule (do_scan_path, scan);
|
||||
} else
|
||||
read_tags(lib_id, path);
|
||||
} else {
|
||||
if (track_db.has_key(path) == false)
|
||||
read_tags(lib_id, path);
|
||||
}
|
||||
}
|
||||
|
||||
static void save_all_dbs()
|
||||
|
@ -348,6 +357,7 @@ static void do_validate_library(unsigned int &lib_id)
|
|||
if (g_file_test(path.c_str(), G_FILE_TEST_EXISTS) == false) {
|
||||
dprint("Removing file: %s\n", path.c_str());
|
||||
track_db.remove(i);
|
||||
library_db[lib_id].size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,6 +194,7 @@ void test_6()
|
|||
system("rm -rf /tmp/library/0/Artist\\ 2/");
|
||||
library :: update_path(0);
|
||||
run_idle_tasks();
|
||||
library :: print_db(library :: DB_LIBRARY);
|
||||
library :: print_db(library :: DB_TRACK);
|
||||
print("\n");
|
||||
|
||||
|
|
Loading…
Reference in New Issue