diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-07-13 10:58:06 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-07-13 10:58:06 +1000 |
| commit | b6bc6b9e47605ede9bffe50445d1afe3acf0ab49 (patch) | |
| tree | 05c9281c2763919b6a6780191f6ecc54547063ae /src/database | |
| parent | 2dc700b12f26109d987ad22f530e39d165025656 (diff) | |
| download | tangara-fw-b6bc6b9e47605ede9bffe50445d1afe3acf0ab49.tar.gz | |
Ui polish and fleshing out
Diffstat (limited to 'src/database')
| -rw-r--r-- | src/database/index.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/database/index.cpp b/src/database/index.cpp index 84d00bcd..d480e84b 100644 --- a/src/database/index.cpp +++ b/src/database/index.cpp @@ -31,6 +31,22 @@ const IndexInfo kAllTracks{ .components = {Tag::kTitle}, }; +static auto missing_component_text(Tag tag) -> std::optional<std::string> { + switch (tag) { + case Tag::kArtist: + return "Unknown Artist"; + case Tag::kAlbum: + return "Unknown Album"; + case Tag::kGenre: + return "Unknown Genre"; + case Tag::kAlbumTrack: + case Tag::kDuration: + case Tag::kTitle: + default: + return {}; + } +} + auto Index(const IndexInfo& info, const Track& t, leveldb::WriteBatch* batch) -> bool { IndexKey key{ @@ -43,6 +59,7 @@ auto Index(const IndexInfo& info, const Track& t, leveldb::WriteBatch* batch) .track = {}, }; + std::optional<std::string> value; for (std::uint8_t i = 0; i < info.components.size(); i++) { // Fill in the text for this depth. auto text = t.tags().at(info.components.at(i)); @@ -50,22 +67,22 @@ auto Index(const IndexInfo& info, const Track& t, leveldb::WriteBatch* batch) key.item = *text; } else { key.item = {}; + value = missing_component_text(info.components.at(i)); } // If this is the last component, then we should also fill in the track id // and title. - std::optional<std::string> title; if (i == info.components.size() - 1) { key.track = t.data().id(); if (info.components.at(i) != Tag::kTitle) { - title = t.TitleOrFilename(); + value = t.TitleOrFilename(); } } else { key.track = {}; } auto encoded = EncodeIndexKey(key); - batch->Put(encoded.slice, title.value_or("")); + batch->Put(encoded.slice, value.value_or("")); // If there are more components after this, then we need to finish by // narrowing the header with the current title. |
