tagdb: Import track information
This allows upgrading from a previous Ocarina version. Signed-off-by: Anna Schumaker <anna@ocarinaproject.net>
This commit is contained in:
parent
ac338c5704
commit
2a01ce5159
7
DESIGN
7
DESIGN
|
@ -540,11 +540,10 @@ Tag Database:
|
|||
|
||||
- Import data:
|
||||
struct ImportData {
|
||||
std::string filepath;
|
||||
unsigned int last_day;
|
||||
unsigned int last_month;
|
||||
unsigned int last_year;
|
||||
unsigned int count;
|
||||
unsigned int last_month;
|
||||
unsigned int last_day;
|
||||
unsigned int play_count;
|
||||
};
|
||||
|
||||
- Databases:
|
||||
|
|
|
@ -20,6 +20,14 @@ enum sort_t {
|
|||
};
|
||||
|
||||
|
||||
struct ImportData {
|
||||
unsigned int last_year;
|
||||
unsigned int last_month;
|
||||
unsigned int last_day;
|
||||
unsigned int play_count;
|
||||
};
|
||||
|
||||
|
||||
class Artist : public DatabaseEntry {
|
||||
public:
|
||||
std::string name;
|
||||
|
@ -112,6 +120,7 @@ namespace tagdb
|
|||
{
|
||||
|
||||
Track *add_track(const std::string &, Library *);
|
||||
Track *import_track(const std::string &, Library *, const ImportData &);
|
||||
Library *add_library(const std::string &);
|
||||
void remove_track(unsigned int);
|
||||
void remove_library(unsigned int);
|
||||
|
|
14
lib/tags.cpp
14
lib/tags.cpp
|
@ -316,6 +316,20 @@ Track *tagdb :: add_track(const std::string &filepath, Library *library)
|
|||
Track *track = track_db.insert(Track(filepath, library));
|
||||
if (size == track_db.size())
|
||||
return NULL;
|
||||
track->tag();
|
||||
return track;
|
||||
}
|
||||
|
||||
Track *tagdb :: import_track(const std::string &filepath, Library *library,
|
||||
const ImportData &import)
|
||||
{
|
||||
Track *track = add_track(filepath, library);
|
||||
if (track) {
|
||||
track->last_year = import.last_year;
|
||||
track->last_month = import.last_month;
|
||||
track->last_day = import.last_day;
|
||||
track->play_count = import.play_count;
|
||||
}
|
||||
return track;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ int main(int argc, char **argv)
|
|||
library = tagdb :: add_library("Music");
|
||||
Track *track = tagdb :: add_track("Music/1.ogg", library);
|
||||
test_track_size(1, __LINE__);
|
||||
test_results(track->track == 1, __LINE__);
|
||||
Track *track_null = tagdb :: add_track("Music/1.ogg", library);
|
||||
test_track_size(1, __LINE__);
|
||||
|
||||
|
@ -97,5 +98,22 @@ int main(int argc, char **argv)
|
|||
tagdb :: remove_library(library->id);
|
||||
test_track_size(0, __LINE__);
|
||||
|
||||
|
||||
/**
|
||||
* Test importing a track
|
||||
*/
|
||||
ImportData import;
|
||||
import.last_year = 2014;
|
||||
import.last_month = 4;
|
||||
import.last_day = 1;
|
||||
import.play_count = 7;
|
||||
|
||||
library = tagdb :: add_library("Music");
|
||||
track = tagdb :: import_track("Music/1.ogg", library, import);
|
||||
test_results(track->last_year == 2014, __LINE__);
|
||||
test_results(track->last_month == 4, __LINE__);
|
||||
test_results(track->last_day == 1, __LINE__);
|
||||
test_results(track->play_count == 7, __LINE__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue