CollectionView: Fix search for this

Fixes #1510
This commit is contained in:
Jonas Kvinge 2024-07-29 20:23:42 +02:00
parent 2ba20b013d
commit 061e0562d1
1 changed files with 16 additions and 15 deletions

View File

@ -580,7 +580,7 @@ void CollectionView::OpenInNewPlaylist() {
void CollectionView::SearchForThis() { void CollectionView::SearchForThis() {
QModelIndex current = currentIndex(); const QModelIndex current = currentIndex();
const QVariant role_type = model()->data(current, CollectionModel::Role_Type); const QVariant role_type = model()->data(current, CollectionModel::Role_Type);
if (!role_type.isValid()) { if (!role_type.isValid()) {
return; return;
@ -599,7 +599,7 @@ void CollectionView::SearchForThis() {
if (!songs.isEmpty()) { if (!songs.isEmpty()) {
last_selected_song_ = songs.last(); last_selected_song_ = songs.last();
} }
search = QStringLiteral("title:%1").arg(last_selected_song_.title()); search = QStringLiteral("title:\"%1\"").arg(last_selected_song_.title());
break; break;
} }
@ -609,28 +609,29 @@ void CollectionView::SearchForThis() {
case CollectionItem::Type::Container:{ case CollectionItem::Type::Container:{
CollectionItem *item = app_->collection_model()->IndexToItem(index); CollectionItem *item = app_->collection_model()->IndexToItem(index);
const CollectionModel::GroupBy group_by = app_->collection_model()->GetGroupBy()[item->container_level];
while (!item->children.isEmpty()) {
item = item->children.first();
}
int container_level = item->container_level; switch (group_by) {
CollectionModel::GroupBy container_group_by = app_->collection_model()->GetGroupBy()[container_level];
switch (container_group_by) {
case CollectionModel::GroupBy::AlbumArtist: case CollectionModel::GroupBy::AlbumArtist:
search = QStringLiteral("albumartist:%1").arg(item->metadata.effective_albumartist()); search = QStringLiteral("albumartist:\"%1\"").arg(item->metadata.effective_albumartist());
break; break;
case CollectionModel::GroupBy::Artist: case CollectionModel::GroupBy::Artist:
search = QStringLiteral("artist:%1").arg(item->metadata.artist()); search = QStringLiteral("artist:\"%1\"").arg(item->metadata.artist());
break; break;
case CollectionModel::GroupBy::Album: case CollectionModel::GroupBy::Album:
case CollectionModel::GroupBy::AlbumDisc: case CollectionModel::GroupBy::AlbumDisc:
search = QStringLiteral("album:%1").arg(item->metadata.album()); search = QStringLiteral("album:\"%1\"").arg(item->metadata.album());
break; break;
case CollectionModel::GroupBy::YearAlbum: case CollectionModel::GroupBy::YearAlbum:
case CollectionModel::GroupBy::YearAlbumDisc: case CollectionModel::GroupBy::YearAlbumDisc:
search = QStringLiteral("year:%1 album:%2").arg(item->metadata.year()).arg(item->metadata.album()); search = QStringLiteral("year:%1 album:\"%2\"").arg(item->metadata.year()).arg(item->metadata.album());
break; break;
case CollectionModel::GroupBy::OriginalYearAlbum: case CollectionModel::GroupBy::OriginalYearAlbum:
case CollectionModel::GroupBy::OriginalYearAlbumDisc: case CollectionModel::GroupBy::OriginalYearAlbumDisc:
search = QStringLiteral("year:%1 album:%2").arg(item->metadata.effective_originalyear()).arg(item->metadata.album()); search = QStringLiteral("year:%1 album:\"%2\"").arg(item->metadata.effective_originalyear()).arg(item->metadata.album());
break; break;
case CollectionModel::GroupBy::Year: case CollectionModel::GroupBy::Year:
search = QStringLiteral("year:%1").arg(item->metadata.year()); search = QStringLiteral("year:%1").arg(item->metadata.year());
@ -639,16 +640,16 @@ void CollectionView::SearchForThis() {
search = QStringLiteral("year:%1").arg(item->metadata.effective_originalyear()); search = QStringLiteral("year:%1").arg(item->metadata.effective_originalyear());
break; break;
case CollectionModel::GroupBy::Genre: case CollectionModel::GroupBy::Genre:
search = QStringLiteral("genre:%1").arg(item->metadata.genre()); search = QStringLiteral("genre:\"%1\"").arg(item->metadata.genre());
break; break;
case CollectionModel::GroupBy::Composer: case CollectionModel::GroupBy::Composer:
search = QStringLiteral("composer:%1").arg(item->metadata.composer()); search = QStringLiteral("composer:\"%1\"").arg(item->metadata.composer());
break; break;
case CollectionModel::GroupBy::Performer: case CollectionModel::GroupBy::Performer:
search = QStringLiteral("performer:%1").arg(item->metadata.performer()); search = QStringLiteral("performer:\"%1\"").arg(item->metadata.performer());
break; break;
case CollectionModel::GroupBy::Grouping: case CollectionModel::GroupBy::Grouping:
search = QStringLiteral("grouping:%1").arg(item->metadata.grouping()); search = QStringLiteral("grouping:\"%1\"").arg(item->metadata.grouping());
break; break;
case CollectionModel::GroupBy::Samplerate: case CollectionModel::GroupBy::Samplerate:
search = QStringLiteral("samplerate:%1").arg(item->metadata.samplerate()); search = QStringLiteral("samplerate:%1").arg(item->metadata.samplerate());