Add artist search in internet view, and use album artist

This commit is contained in:
Jonas Kvinge
2019-02-12 21:58:03 +01:00
parent e1abd28a88
commit 35f448c34f
15 changed files with 446 additions and 186 deletions

View File

@@ -69,7 +69,7 @@ InternetSearch::InternetSearch(Application *app, Song::Source source, QObject *p
cover_loader_options_.scale_output_image_ = true;
connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage)), SLOT(AlbumArtLoaded(quint64, QImage)));
connect(this, SIGNAL(SearchAsyncSig(int, QString, SearchBy)), this, SLOT(DoSearchAsync(int, QString, SearchBy)));
connect(this, SIGNAL(SearchAsyncSig(int, QString, SearchType)), this, SLOT(DoSearchAsync(int, QString, SearchType)));
connect(this, SIGNAL(ResultsAvailable(int, InternetSearch::ResultList)), SLOT(ResultsAvailableSlot(int, InternetSearch::ResultList)));
connect(this, SIGNAL(ArtLoaded(int, QImage)), SLOT(ArtLoadedSlot(int, QImage)));
connect(service_, SIGNAL(UpdateStatus(QString)), SLOT(UpdateStatusSlot(QString)));
@@ -113,29 +113,29 @@ bool InternetSearch::Matches(const QStringList &tokens, const QString &string) {
}
int InternetSearch::SearchAsync(const QString &query, SearchBy searchby) {
int InternetSearch::SearchAsync(const QString &query, SearchType type) {
const int id = searches_next_id_++;
emit SearchAsyncSig(id, query, searchby);
emit SearchAsyncSig(id, query, type);
return id;
}
void InternetSearch::SearchAsync(int id, const QString &query, SearchBy searchby) {
void InternetSearch::SearchAsync(int id, const QString &query, SearchType type) {
const int service_id = service_->Search(query, searchby);
const int service_id = service_->Search(query, type);
pending_searches_[service_id] = PendingState(id, TokenizeQuery(query));
}
void InternetSearch::DoSearchAsync(int id, const QString &query, SearchBy searchby) {
void InternetSearch::DoSearchAsync(int id, const QString &query, SearchType type) {
int timer_id = startTimer(kDelayedSearchTimeoutMs);
delayed_searches_[timer_id].id_ = id;
delayed_searches_[timer_id].query_ = query;
delayed_searches_[timer_id].searchby_ = searchby;
delayed_searches_[timer_id].type_ = type;
}
@@ -186,7 +186,7 @@ void InternetSearch::CancelSearch(int id) {
void InternetSearch::timerEvent(QTimerEvent *e) {
QMap<int, DelayedSearch>::iterator it = delayed_searches_.find(e->timerId());
if (it != delayed_searches_.end()) {
SearchAsync(it.value().id_, it.value().query_, it.value().searchby_);
SearchAsync(it.value().id_, it.value().query_, it.value().type_);
delayed_searches_.erase(it);
return;
}

View File

@@ -45,9 +45,10 @@ class InternetSearch : public QObject {
InternetSearch(Application *app, Song::Source source, QObject *parent = nullptr);
~InternetSearch();
enum SearchBy {
SearchBy_Songs = 1,
SearchBy_Albums = 2,
enum SearchType {
SearchType_Artists = 1,
SearchType_Albums = 2,
SearchType_Songs = 3,
};
struct Result {
@@ -63,7 +64,7 @@ class InternetSearch : public QObject {
Song::Source source() const { return source_; }
InternetService *service() const { return service_; }
int SearchAsync(const QString &query, SearchBy searchby);
int SearchAsync(const QString &query, SearchType type);
int LoadArtAsync(const InternetSearch::Result &result);
void CancelSearch(int id);
@@ -74,7 +75,7 @@ class InternetSearch : public QObject {
MimeData *LoadTracks(const ResultList &results);
signals:
void SearchAsyncSig(int id, const QString &query, SearchBy searchby);
void SearchAsyncSig(int id, const QString &query, SearchType type);
void ResultsAvailable(int id, const InternetSearch::ResultList &results);
void AddResults(int id, const InternetSearch::ResultList &results);
void SearchError(const int id, const QString error);
@@ -112,7 +113,7 @@ class InternetSearch : public QObject {
static bool Matches(const QStringList &tokens, const QString &string);
private slots:
void DoSearchAsync(int id, const QString &query, SearchBy searchby);
void DoSearchAsync(int id, const QString &query, SearchType type);
void SearchDone(int id, const SongList &songs);
void HandleError(const int id, const QString error);
void ResultsAvailableSlot(int id, InternetSearch::ResultList results);
@@ -125,7 +126,7 @@ class InternetSearch : public QObject {
void UpdateProgressSlot(int max);
private:
void SearchAsync(int id, const QString &query, SearchBy searchby);
void SearchAsync(int id, const QString &query, SearchType type);
void HandleLoadedArt(int id, const QImage &image);
bool FindCachedPixmap(const InternetSearch::Result &result, QPixmap *pixmap) const;
QString PixmapCacheKey(const InternetSearch::Result &result) const;
@@ -137,7 +138,7 @@ class InternetSearch : public QObject {
struct DelayedSearch {
int id_;
QString query_;
SearchBy searchby_;
SearchType type_;
};
static const int kArtHeight;

View File

@@ -41,17 +41,15 @@ InternetSearchModel::InternetSearchModel(InternetSearch *engine, QObject *parent
engine_(engine),
proxy_(nullptr),
use_pretty_covers_(true),
artist_icon_(IconLoader::Load("folder-sound")) {
artist_icon_(IconLoader::Load("folder-sound")),
album_icon_(IconLoader::Load("cdcase"))
{
group_by_[0] = CollectionModel::GroupBy_Artist;
group_by_[1] = CollectionModel::GroupBy_Album;
group_by_[2] = CollectionModel::GroupBy_None;
QIcon nocover = IconLoader::Load("cdcase");
no_cover_icon_ = nocover.pixmap(nocover.availableSizes().last()).scaled(CollectionModel::kPrettyCoverSize, CollectionModel::kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
//no_cover_icon_ = QPixmap(":/pictures/noalbumart.png").scaled(CollectionModel::kPrettyCoverSize, CollectionModel::kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
album_icon_ = no_cover_icon_;
no_cover_icon_ = album_icon_.pixmap(album_icon_.availableSizes().last()).scaled(CollectionModel::kPrettyCoverSize, CollectionModel::kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
@@ -93,6 +91,19 @@ QStandardItem *InternetSearchModel::BuildContainers(const Song &s, QStandardItem
int year = 0;
switch (group_by_[level]) {
case CollectionModel::GroupBy_AlbumArtist:
if (s.is_compilation()) {
display_text = tr("Various artists");
sort_text = "aaaaaa";
}
else {
display_text = CollectionModel::TextOrUnknown(s.effective_albumartist());
sort_text = CollectionModel::SortTextForArtist(s.effective_albumartist());
}
has_artist_icon = true;
break;
case CollectionModel::GroupBy_Artist:
if (s.is_compilation()) {
display_text = tr("Various artists");
@@ -134,28 +145,42 @@ QStandardItem *InternetSearchModel::BuildContainers(const Song &s, QStandardItem
break;
case CollectionModel::GroupBy_Composer:
display_text = s.composer();
display_text = CollectionModel::TextOrUnknown(s.composer());
sort_text = CollectionModel::SortTextForArtist(s.composer());
has_album_icon = true;
break;
case CollectionModel::GroupBy_Performer:
display_text = s.performer();
display_text = CollectionModel::TextOrUnknown(s.performer());
sort_text = CollectionModel::SortTextForArtist(s.performer());
has_album_icon = true;
break;
case CollectionModel::GroupBy_Disc:
display_text = s.disc();
case CollectionModel::GroupBy_Grouping:
display_text = s.grouping();
case CollectionModel::GroupBy_Genre:
if (display_text.isNull()) display_text = s.genre();
case CollectionModel::GroupBy_Album:
unique_tag = s.album_id();
if (display_text.isNull()) {
display_text = s.album();
}
// fallthrough
case CollectionModel::GroupBy_AlbumArtist:
if (display_text.isNull()) display_text = s.effective_albumartist();
display_text = CollectionModel::TextOrUnknown(display_text);
sort_text = CollectionModel::SortTextForArtist(display_text);
has_album_icon = true;
break;
case CollectionModel::GroupBy_Grouping:
display_text = CollectionModel::TextOrUnknown(s.grouping());
sort_text = CollectionModel::SortTextForArtist(s.grouping());
has_album_icon = true;
break;
case CollectionModel::GroupBy_Genre:
display_text = CollectionModel::TextOrUnknown(s.genre());
sort_text = CollectionModel::SortTextForArtist(s.genre());
has_album_icon = true;
break;
case CollectionModel::GroupBy_Album:
display_text = CollectionModel::TextOrUnknown(s.album());
sort_text = CollectionModel::SortTextForArtist(s.album());
unique_tag = s.album_id();
has_album_icon = true;
break;
case CollectionModel::GroupBy_FileType:
display_text = s.TextForFiletype();
sort_text = display_text;
@@ -180,6 +205,9 @@ QStandardItem *InternetSearchModel::BuildContainers(const Song &s, QStandardItem
return parent;
}
if (display_text.isEmpty()) display_text = "Unknown";
if (sort_text.isEmpty()) sort_text = "Unknown";
// Find a container for this level
key->group_[level] = display_text + QString::number(unique_tag);
QStandardItem *container = containers_[*key];

View File

@@ -81,8 +81,8 @@ class InternetSearchModel : public QStandardItemModel {
QSortFilterProxyModel *proxy_;
bool use_pretty_covers_;
QIcon artist_icon_;
QPixmap no_cover_icon_;
QIcon album_icon_;
QPixmap no_cover_icon_;
CollectionModel::Grouping group_by_;
QMap<ContainerKey, QStandardItem*> containers_;

View File

@@ -144,8 +144,9 @@ InternetSearchView::InternetSearchView(Application *app, InternetSearch *engine,
settings_menu->addAction(IconLoader::Load("configure"), QString("Configure %1...").arg(Song::TextForSource(engine->source())), this, SLOT(OpenSettingsDialog()));
ui_->settings->setMenu(settings_menu);
connect(ui_->radiobutton_searchbyalbums, SIGNAL(clicked(bool)), SLOT(SearchByAlbumsClicked(bool)));
connect(ui_->radiobutton_searchbysongs, SIGNAL(clicked(bool)), SLOT(SearchBySongsClicked(bool)));
connect(ui_->radiobutton_search_artists, SIGNAL(clicked(bool)), SLOT(SearchArtistsClicked(bool)));
connect(ui_->radiobutton_search_albums, SIGNAL(clicked(bool)), SLOT(SearchAlbumsClicked(bool)));
connect(ui_->radiobutton_search_songs, SIGNAL(clicked(bool)), SLOT(SearchSongsClicked(bool)));
connect(group_by_actions_, SIGNAL(triggered(QAction*)), SLOT(GroupByClicked(QAction*)));
@@ -180,18 +181,21 @@ void InternetSearchView::ReloadSettings() {
// Internet search settings
s.beginGroup(settings_group_);
searchby_ = InternetSearch::SearchBy(s.value("searchby", int(InternetSearch::SearchBy_Songs)).toInt());
switch (searchby_) {
case InternetSearch::SearchBy_Songs:
ui_->radiobutton_searchbysongs->setChecked(true);
search_type_ = InternetSearch::SearchType(s.value("type", int(InternetSearch::SearchType_Artists)).toInt());
switch (search_type_) {
case InternetSearch::SearchType_Artists:
ui_->radiobutton_search_artists->setChecked(true);
break;
case InternetSearch::SearchBy_Albums:
ui_->radiobutton_searchbyalbums->setChecked(true);
case InternetSearch::SearchType_Albums:
ui_->radiobutton_search_albums->setChecked(true);
break;
case InternetSearch::SearchType_Songs:
ui_->radiobutton_search_songs->setChecked(true);
break;
}
SetGroupBy(CollectionModel::Grouping(
CollectionModel::GroupBy(s.value("group_by1", int(CollectionModel::GroupBy_Artist)).toInt()),
CollectionModel::GroupBy(s.value("group_by1", int(CollectionModel::GroupBy_AlbumArtist)).toInt()),
CollectionModel::GroupBy(s.value("group_by2", int(CollectionModel::GroupBy_Album)).toInt()),
CollectionModel::GroupBy(s.value("group_by3", int(CollectionModel::GroupBy_None)).toInt())));
s.endGroup();
@@ -233,7 +237,7 @@ void InternetSearchView::TextEdited(const QString &text) {
}
else {
ui_->progressbar->reset();
last_search_id_ = engine_->SearchAsync(trimmed, searchby_);
last_search_id_ = engine_->SearchAsync(trimmed, search_type_);
}
}
@@ -293,7 +297,6 @@ void InternetSearchView::LazyLoadArt(const QModelIndex &proxy_index) {
// Is this an album?
const CollectionModel::GroupBy container_type = CollectionModel::GroupBy(proxy_index.data(CollectionModel::Role_ContainerType).toInt());
if (container_type != CollectionModel::GroupBy_Album &&
container_type != CollectionModel::GroupBy_AlbumArtist &&
container_type != CollectionModel::GroupBy_YearAlbum &&
container_type != CollectionModel::GroupBy_OriginalYearAlbum) {
return;
@@ -545,19 +548,23 @@ void InternetSearchView::SetGroupBy(const CollectionModel::Grouping &g) {
}
void InternetSearchView::SearchBySongsClicked(bool checked) {
SetSearchBy(InternetSearch::SearchBy_Songs);
void InternetSearchView::SearchArtistsClicked(bool checked) {
SetSearchType(InternetSearch::SearchType_Artists);
}
void InternetSearchView::SearchByAlbumsClicked(bool checked) {
SetSearchBy(InternetSearch::SearchBy_Albums);
void InternetSearchView::SearchAlbumsClicked(bool checked) {
SetSearchType(InternetSearch::SearchType_Albums);
}
void InternetSearchView::SetSearchBy(InternetSearch::SearchBy searchby) {
searchby_ = searchby;
void InternetSearchView::SearchSongsClicked(bool checked) {
SetSearchType(InternetSearch::SearchType_Songs);
}
void InternetSearchView::SetSearchType(InternetSearch::SearchType type) {
search_type_ = type;
QSettings s;
s.beginGroup(settings_group_);
s.setValue("searchby", int(searchby));
s.setValue("type", int(search_type_));
s.endGroup();
TextEdited(ui_->search->text());
}

View File

@@ -43,7 +43,6 @@
#include "settings/settingsdialog.h"
#include "playlist/playlistmanager.h"
#include "internetsearch.h"
//#include "settings/internetsettingspage.h"
class Application;
class GroupByDialog;
@@ -93,10 +92,11 @@ signals:
void SearchForThis();
void SearchBySongsClicked(bool);
void SearchByAlbumsClicked(bool);
void SearchArtistsClicked(bool);
void SearchAlbumsClicked(bool);
void SearchSongsClicked(bool);
void GroupByClicked(QAction *action);
void SetSearchBy(InternetSearch::SearchBy searchby);
void SetSearchType(InternetSearch::SearchType type);
void SetGroupBy(const CollectionModel::Grouping &g);
private:
@@ -133,7 +133,7 @@ signals:
QTimer *swap_models_timer_;
InternetSearch::SearchBy searchby_;
InternetSearch::SearchType search_type_;
bool error_;
};

View File

@@ -72,7 +72,7 @@
<bool>true</bool>
</property>
<property name="text">
<string>Search by</string>
<string>Search for</string>
</property>
<property name="margin">
<number>10</number>
@@ -80,14 +80,21 @@
</widget>
</item>
<item>
<widget class="QRadioButton" name="radiobutton_searchbyalbums">
<widget class="QRadioButton" name="radiobutton_search_artists">
<property name="text">
<string>ar&amp;tists</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radiobutton_search_albums">
<property name="text">
<string>a&amp;lbums</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radiobutton_searchbysongs">
<widget class="QRadioButton" name="radiobutton_search_songs">
<property name="text">
<string>son&amp;gs</string>
</property>
@@ -208,7 +215,7 @@
<x>0</x>
<y>0</y>
<width>398</width>
<height>502</height>
<height>521</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">

View File

@@ -52,7 +52,7 @@ class InternetService : public QObject {
virtual void InitialLoadSettings() {}
virtual void ReloadSettings() {}
virtual QIcon Icon() { return Song::IconForSource(source_); }
virtual int Search(const QString &query, InternetSearch::SearchBy searchby) = 0;
virtual int Search(const QString &query, InternetSearch::SearchType type) = 0;
virtual void CancelSearch() = 0;
public slots: