Add an option not to skip “The” when sorting artist names

This commit is contained in:
Sami Boukortt 2024-03-11 11:09:33 +01:00 committed by Jonas Kvinge
parent 4626a6f609
commit 2aa70b6ab8
7 changed files with 57 additions and 29 deletions

View File

@ -86,6 +86,7 @@ CollectionModel::CollectionModel(SharedPtr<CollectionBackend> backend, Applicati
app_(app), app_(app),
dir_model_(new CollectionDirectoryModel(backend, this)), dir_model_(new CollectionDirectoryModel(backend, this)),
show_various_artists_(true), show_various_artists_(true),
sort_skips_articles_(true),
total_song_count_(0), total_song_count_(0),
total_artist_count_(0), total_artist_count_(0),
total_album_count_(0), total_album_count_(0),
@ -163,6 +164,15 @@ void CollectionModel::set_show_dividers(const bool show_dividers) {
} }
void CollectionModel::set_sort_skips_articles(const bool sort_skips_articles) {
if (sort_skips_articles != sort_skips_articles_) {
sort_skips_articles_ = sort_skips_articles;
Reset();
}
}
void CollectionModel::ReloadSettings() { void CollectionModel::ReloadSettings() {
QSettings s; QSettings s;
@ -1242,14 +1252,14 @@ CollectionItem *CollectionModel::ItemFromQuery(const GroupBy group_by, const boo
item->metadata.set_albumartist(row.value(0).toString()); item->metadata.set_albumartist(row.value(0).toString());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata));
item->display_text = TextOrUnknown(item->metadata.albumartist()); item->display_text = TextOrUnknown(item->metadata.albumartist());
item->sort_text = SortTextForArtist(item->metadata.albumartist()); item->sort_text = SortTextForArtist(item->metadata.albumartist(), sort_skips_articles_);
break; break;
} }
case GroupBy::Artist:{ case GroupBy::Artist:{
item->metadata.set_artist(row.value(0).toString()); item->metadata.set_artist(row.value(0).toString());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata));
item->display_text = TextOrUnknown(item->metadata.artist()); item->display_text = TextOrUnknown(item->metadata.artist());
item->sort_text = SortTextForArtist(item->metadata.artist()); item->sort_text = SortTextForArtist(item->metadata.artist(), sort_skips_articles_);
break; break;
} }
case GroupBy::Album:{ case GroupBy::Album:{
@ -1258,7 +1268,7 @@ CollectionItem *CollectionModel::ItemFromQuery(const GroupBy group_by, const boo
item->metadata.set_grouping(row.value(2).toString()); item->metadata.set_grouping(row.value(2).toString());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata));
item->display_text = TextOrUnknown(item->metadata.album()); item->display_text = TextOrUnknown(item->metadata.album());
item->sort_text = SortTextForArtist(item->metadata.album()); item->sort_text = SortTextForArtist(item->metadata.album(), sort_skips_articles_);
break; break;
} }
case GroupBy::AlbumDisc:{ case GroupBy::AlbumDisc:{
@ -1343,28 +1353,28 @@ CollectionItem *CollectionModel::ItemFromQuery(const GroupBy group_by, const boo
item->metadata.set_genre(row.value(0).toString()); item->metadata.set_genre(row.value(0).toString());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata));
item->display_text = TextOrUnknown(item->metadata.genre()); item->display_text = TextOrUnknown(item->metadata.genre());
item->sort_text = SortTextForArtist(item->metadata.genre()); item->sort_text = SortTextForArtist(item->metadata.genre(), sort_skips_articles_);
break; break;
} }
case GroupBy::Composer:{ case GroupBy::Composer:{
item->metadata.set_composer(row.value(0).toString()); item->metadata.set_composer(row.value(0).toString());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata));
item->display_text = TextOrUnknown(item->metadata.composer()); item->display_text = TextOrUnknown(item->metadata.composer());
item->sort_text = SortTextForArtist(item->metadata.composer()); item->sort_text = SortTextForArtist(item->metadata.composer(), sort_skips_articles_);
break; break;
} }
case GroupBy::Performer:{ case GroupBy::Performer:{
item->metadata.set_performer(row.value(0).toString()); item->metadata.set_performer(row.value(0).toString());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata));
item->display_text = TextOrUnknown(item->metadata.performer()); item->display_text = TextOrUnknown(item->metadata.performer());
item->sort_text = SortTextForArtist(item->metadata.performer()); item->sort_text = SortTextForArtist(item->metadata.performer(), sort_skips_articles_);
break; break;
} }
case GroupBy::Grouping:{ case GroupBy::Grouping:{
item->metadata.set_grouping(row.value(0).toString()); item->metadata.set_grouping(row.value(0).toString());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, item->metadata));
item->display_text = TextOrUnknown(item->metadata.grouping()); item->display_text = TextOrUnknown(item->metadata.grouping());
item->sort_text = SortTextForArtist(item->metadata.grouping()); item->sort_text = SortTextForArtist(item->metadata.grouping(), sort_skips_articles_);
break; break;
} }
case GroupBy::FileType:{ case GroupBy::FileType:{
@ -1441,14 +1451,14 @@ CollectionItem *CollectionModel::ItemFromSong(const GroupBy group_by, const bool
item->metadata.set_albumartist(s.effective_albumartist()); item->metadata.set_albumartist(s.effective_albumartist());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s));
item->display_text = TextOrUnknown(s.effective_albumartist()); item->display_text = TextOrUnknown(s.effective_albumartist());
item->sort_text = SortTextForArtist(s.effective_albumartist()); item->sort_text = SortTextForArtist(s.effective_albumartist(), sort_skips_articles_);
break; break;
} }
case GroupBy::Artist:{ case GroupBy::Artist:{
item->metadata.set_artist(s.artist()); item->metadata.set_artist(s.artist());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s));
item->display_text = TextOrUnknown(s.artist()); item->display_text = TextOrUnknown(s.artist());
item->sort_text = SortTextForArtist(s.artist()); item->sort_text = SortTextForArtist(s.artist(), sort_skips_articles_);
break; break;
} }
case GroupBy::Album:{ case GroupBy::Album:{
@ -1457,7 +1467,7 @@ CollectionItem *CollectionModel::ItemFromSong(const GroupBy group_by, const bool
item->metadata.set_grouping(s.grouping()); item->metadata.set_grouping(s.grouping());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s));
item->display_text = TextOrUnknown(s.album()); item->display_text = TextOrUnknown(s.album());
item->sort_text = SortTextForArtist(s.album()); item->sort_text = SortTextForArtist(s.album(), sort_skips_articles_);
break; break;
} }
case GroupBy::AlbumDisc:{ case GroupBy::AlbumDisc:{
@ -1542,28 +1552,28 @@ CollectionItem *CollectionModel::ItemFromSong(const GroupBy group_by, const bool
item->metadata.set_genre(s.genre()); item->metadata.set_genre(s.genre());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s));
item->display_text = TextOrUnknown(s.genre()); item->display_text = TextOrUnknown(s.genre());
item->sort_text = SortTextForArtist(s.genre()); item->sort_text = SortTextForArtist(s.genre(), sort_skips_articles_);
break; break;
} }
case GroupBy::Composer:{ case GroupBy::Composer:{
item->metadata.set_composer(s.composer()); item->metadata.set_composer(s.composer());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s));
item->display_text = TextOrUnknown(s.composer()); item->display_text = TextOrUnknown(s.composer());
item->sort_text = SortTextForArtist(s.composer()); item->sort_text = SortTextForArtist(s.composer(), sort_skips_articles_);
break; break;
} }
case GroupBy::Performer:{ case GroupBy::Performer:{
item->metadata.set_performer(s.performer()); item->metadata.set_performer(s.performer());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s));
item->display_text = TextOrUnknown(s.performer()); item->display_text = TextOrUnknown(s.performer());
item->sort_text = SortTextForArtist(s.performer()); item->sort_text = SortTextForArtist(s.performer(), sort_skips_articles_);
break; break;
} }
case GroupBy::Grouping:{ case GroupBy::Grouping:{
item->metadata.set_grouping(s.grouping()); item->metadata.set_grouping(s.grouping());
item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s)); item->key.append(ContainerKey(group_by, separate_albums_by_grouping, s));
item->display_text = TextOrUnknown(s.grouping()); item->display_text = TextOrUnknown(s.grouping());
item->sort_text = SortTextForArtist(s.grouping()); item->sort_text = SortTextForArtist(s.grouping(), sort_skips_articles_);
break; break;
} }
case GroupBy::FileType:{ case GroupBy::FileType:{
@ -1719,15 +1729,17 @@ QString CollectionModel::SortText(QString text) {
} }
QString CollectionModel::SortTextForArtist(QString artist) { QString CollectionModel::SortTextForArtist(QString artist, const bool skip_articles) {
artist = SortText(artist); artist = SortText(artist);
for (const auto &i : Song::kArticles) { if (skip_articles) {
if (artist.startsWith(i)) { for (const auto &i : Song::kArticles) {
qint64 ilen = i.length(); if (artist.startsWith(i)) {
artist = artist.right(artist.length() - ilen) + ", " + i.left(ilen - 1); qint64 ilen = i.length();
break; artist = artist.right(artist.length() - ilen) + ", " + i.left(ilen - 1);
break;
}
} }
} }

View File

@ -162,6 +162,9 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
// Whether or not to show letters heading in the collection view // Whether or not to show letters heading in the collection view
void set_show_dividers(const bool show_dividers); void set_show_dividers(const bool show_dividers);
// Whether to skip articles such as “The” when sorting artist names
void set_sort_skips_articles(const bool sort_skips_articles);
// Reload settings. // Reload settings.
void ReloadSettings(); void ReloadSettings();
@ -173,7 +176,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
static QString PrettyDisc(const int disc); static QString PrettyDisc(const int disc);
static QString SortText(QString text); static QString SortText(QString text);
static QString SortTextForNumber(const int number); static QString SortTextForNumber(const int number);
static QString SortTextForArtist(QString artist); static QString SortTextForArtist(QString artist, const bool skip_articles);
static QString SortTextForSong(const Song &song); static QString SortTextForSong(const Song &song);
static QString SortTextForYear(const int year); static QString SortTextForYear(const int year);
static QString SortTextForBitrate(const int bitrate); static QString SortTextForBitrate(const int bitrate);
@ -278,6 +281,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
Application *app_; Application *app_;
CollectionDirectoryModel *dir_model_; CollectionDirectoryModel *dir_model_;
bool show_various_artists_; bool show_various_artists_;
bool sort_skips_articles_;
int total_song_count_; int total_song_count_;
int total_artist_count_; int total_artist_count_;

View File

@ -232,6 +232,7 @@ void CollectionView::ReloadSettings() {
if (app_) { if (app_) {
app_->collection_model()->set_pretty_covers(settings.value("pretty_covers", true).toBool()); app_->collection_model()->set_pretty_covers(settings.value("pretty_covers", true).toBool());
app_->collection_model()->set_show_dividers(settings.value("show_dividers", true).toBool()); app_->collection_model()->set_show_dividers(settings.value("show_dividers", true).toBool());
app_->collection_model()->set_sort_skips_articles(settings.value("sort_skips_articles", true).toBool());
} }
delete_files_ = settings.value("delete_files", false).toBool(); delete_files_ = settings.value("delete_files", false).toBool();

View File

@ -89,6 +89,7 @@ void InternetCollectionView::Init(Application *app, SharedPtr<CollectionBackend>
collection_model_->set_pretty_covers(true); collection_model_->set_pretty_covers(true);
collection_model_->set_show_dividers(true); collection_model_->set_show_dividers(true);
collection_model_->set_sort_skips_articles(true);
ReloadSettings(); ReloadSettings();

View File

@ -95,7 +95,7 @@ QStandardItem *InternetSearchModel::BuildContainers(const Song &s, QStandardItem
} }
else { else {
display_text = CollectionModel::TextOrUnknown(s.effective_albumartist()); display_text = CollectionModel::TextOrUnknown(s.effective_albumartist());
sort_text = CollectionModel::SortTextForArtist(s.effective_albumartist()); sort_text = CollectionModel::SortTextForArtist(s.effective_albumartist(), true);
} }
has_artist_icon = true; has_artist_icon = true;
break; break;
@ -107,14 +107,14 @@ QStandardItem *InternetSearchModel::BuildContainers(const Song &s, QStandardItem
} }
else { else {
display_text = CollectionModel::TextOrUnknown(s.artist()); display_text = CollectionModel::TextOrUnknown(s.artist());
sort_text = CollectionModel::SortTextForArtist(s.artist()); sort_text = CollectionModel::SortTextForArtist(s.artist(), true);
} }
has_artist_icon = true; has_artist_icon = true;
break; break;
case CollectionModel::GroupBy::Album: case CollectionModel::GroupBy::Album:
display_text = CollectionModel::TextOrUnknown(s.album()); display_text = CollectionModel::TextOrUnknown(s.album());
sort_text = CollectionModel::SortTextForArtist(s.album()); sort_text = CollectionModel::SortTextForArtist(s.album(), true);
unique_tag = s.album_id(); unique_tag = s.album_id();
has_album_icon = true; has_album_icon = true;
break; break;
@ -168,7 +168,7 @@ QStandardItem *InternetSearchModel::BuildContainers(const Song &s, QStandardItem
case CollectionModel::GroupBy::Disc: case CollectionModel::GroupBy::Disc:
display_text = CollectionModel::PrettyDisc(s.disc()); display_text = CollectionModel::PrettyDisc(s.disc());
sort_text = CollectionModel::SortTextForArtist(display_text); sort_text = CollectionModel::SortTextForArtist(display_text, true);
has_album_icon = true; has_album_icon = true;
break; break;
@ -188,25 +188,25 @@ QStandardItem *InternetSearchModel::BuildContainers(const Song &s, QStandardItem
case CollectionModel::GroupBy::Genre: case CollectionModel::GroupBy::Genre:
display_text = CollectionModel::TextOrUnknown(s.genre()); display_text = CollectionModel::TextOrUnknown(s.genre());
sort_text = CollectionModel::SortTextForArtist(s.genre()); sort_text = CollectionModel::SortTextForArtist(s.genre(), true);
has_album_icon = true; has_album_icon = true;
break; break;
case CollectionModel::GroupBy::Composer: case CollectionModel::GroupBy::Composer:
display_text = CollectionModel::TextOrUnknown(s.composer()); display_text = CollectionModel::TextOrUnknown(s.composer());
sort_text = CollectionModel::SortTextForArtist(s.composer()); sort_text = CollectionModel::SortTextForArtist(s.composer(), true);
has_album_icon = true; has_album_icon = true;
break; break;
case CollectionModel::GroupBy::Performer: case CollectionModel::GroupBy::Performer:
display_text = CollectionModel::TextOrUnknown(s.performer()); display_text = CollectionModel::TextOrUnknown(s.performer());
sort_text = CollectionModel::SortTextForArtist(s.performer()); sort_text = CollectionModel::SortTextForArtist(s.performer(), true);
has_album_icon = true; has_album_icon = true;
break; break;
case CollectionModel::GroupBy::Grouping: case CollectionModel::GroupBy::Grouping:
display_text = CollectionModel::TextOrUnknown(s.grouping()); display_text = CollectionModel::TextOrUnknown(s.grouping());
sort_text = CollectionModel::SortTextForArtist(s.grouping()); sort_text = CollectionModel::SortTextForArtist(s.grouping(), true);
has_album_icon = true; has_album_icon = true;
break; break;

View File

@ -179,6 +179,7 @@ void CollectionSettingsPage::Load() {
ui_->auto_open->setChecked(s.value("auto_open", true).toBool()); ui_->auto_open->setChecked(s.value("auto_open", true).toBool());
ui_->pretty_covers->setChecked(s.value("pretty_covers", true).toBool()); ui_->pretty_covers->setChecked(s.value("pretty_covers", true).toBool());
ui_->show_dividers->setChecked(s.value("show_dividers", true).toBool()); ui_->show_dividers->setChecked(s.value("show_dividers", true).toBool());
ui_->sort_skips_articles->setChecked(s.value("sort_skips_articles", true).toBool());
ui_->startup_scan->setChecked(s.value("startup_scan", true).toBool()); ui_->startup_scan->setChecked(s.value("startup_scan", true).toBool());
ui_->monitor->setChecked(s.value("monitor", true).toBool()); ui_->monitor->setChecked(s.value("monitor", true).toBool());
ui_->song_tracking->setChecked(s.value("song_tracking", false).toBool()); ui_->song_tracking->setChecked(s.value("song_tracking", false).toBool());
@ -226,6 +227,7 @@ void CollectionSettingsPage::Save() {
s.setValue("auto_open", ui_->auto_open->isChecked()); s.setValue("auto_open", ui_->auto_open->isChecked());
s.setValue("pretty_covers", ui_->pretty_covers->isChecked()); s.setValue("pretty_covers", ui_->pretty_covers->isChecked());
s.setValue("show_dividers", ui_->show_dividers->isChecked()); s.setValue("show_dividers", ui_->show_dividers->isChecked());
s.setValue("sort_skips_articles", ui_->sort_skips_articles->isChecked());
s.setValue("startup_scan", ui_->startup_scan->isChecked()); s.setValue("startup_scan", ui_->startup_scan->isChecked());
s.setValue("monitor", ui_->monitor->isChecked()); s.setValue("monitor", ui_->monitor->isChecked());
s.setValue("song_tracking", ui_->song_tracking->isChecked()); s.setValue("song_tracking", ui_->song_tracking->isChecked());

View File

@ -225,6 +225,13 @@ If there are no matches then it will use the largest image in the directory.</st
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="sort_skips_articles">
<property name="text">
<string>Skip leading articles (&quot;the&quot;, &quot;a&quot;, &quot;an&quot;) when sorting artist names</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -506,6 +513,7 @@ If there are no matches then it will use the largest image in the directory.</st
<tabstop>auto_open</tabstop> <tabstop>auto_open</tabstop>
<tabstop>pretty_covers</tabstop> <tabstop>pretty_covers</tabstop>
<tabstop>show_dividers</tabstop> <tabstop>show_dividers</tabstop>
<tabstop>sort_skips_articles</tabstop>
<tabstop>spinbox_cache_size</tabstop> <tabstop>spinbox_cache_size</tabstop>
<tabstop>combobox_cache_size</tabstop> <tabstop>combobox_cache_size</tabstop>
<tabstop>checkbox_disk_cache</tabstop> <tabstop>checkbox_disk_cache</tabstop>