summaryrefslogtreecommitdiff
path: root/src/database/index.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-09-05 14:36:28 +1000
committerjacqueline <me@jacqueline.id.au>2023-09-05 14:36:28 +1000
commitb413b2f2641b0c7448762e9dc801f4ca7f00095c (patch)
treecb9c9314c56cae39841ebecb03a81d843c9e3447 /src/database/index.cpp
parent02c1eb4be35559c127368d1419ebb79e9f23f3c3 (diff)
downloadtangara-fw-b413b2f2641b0c7448762e9dc801f4ca7f00095c.tar.gz
Add all albums index, do some locales prep
Diffstat (limited to 'src/database/index.cpp')
-rw-r--r--src/database/index.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/database/index.cpp b/src/database/index.cpp
index d480e84b..844b33a3 100644
--- a/src/database/index.cpp
+++ b/src/database/index.cpp
@@ -31,6 +31,12 @@ const IndexInfo kAllTracks{
.components = {Tag::kTitle},
};
+const IndexInfo kAllAlbums{
+ .id = 4,
+ .name = "All Albums",
+ .components = {Tag::kAlbum, Tag::kAlbumTrack},
+};
+
static auto missing_component_text(Tag tag) -> std::optional<std::string> {
switch (tag) {
case Tag::kArtist:
@@ -59,15 +65,19 @@ auto Index(const IndexInfo& info, const Track& t, leveldb::WriteBatch* batch)
.track = {},
};
- std::optional<std::string> value;
+ auto& col = std::use_facet<std::collate<char>>(std::locale());
+
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));
+ std::string value;
if (text) {
- key.item = *text;
+ std::string orig = *text;
+ key.item = col.transform(&orig[0], &orig[0] + orig.size());
+ value = *text;
} else {
key.item = {};
- value = missing_component_text(info.components.at(i));
+ value = missing_component_text(info.components.at(i)).value_or("");
}
// If this is the last component, then we should also fill in the track id
@@ -82,7 +92,7 @@ auto Index(const IndexInfo& info, const Track& t, leveldb::WriteBatch* batch)
}
auto encoded = EncodeIndexKey(key);
- batch->Put(encoded.slice, value.value_or(""));
+ batch->Put(encoded.slice, value);
// If there are more components after this, then we need to finish by
// narrowing the header with the current title.