EditTagDialog: Add button to fetch lyrics
Co-Authored-By: Jonas Kvinge <jonas@jkvinge.net>
This commit is contained in:
committed by
Jonas Kvinge
parent
a3207a5703
commit
27ee6e7643
@@ -631,7 +631,12 @@ void ContextView::UpdateLyrics(const quint64 id, const QString &provider, const
|
|||||||
|
|
||||||
if (static_cast<qint64>(id) != lyrics_id_) return;
|
if (static_cast<qint64>(id) != lyrics_id_) return;
|
||||||
|
|
||||||
lyrics_ = lyrics + "\n\n(Lyrics from " + provider + ")\n";
|
if (lyrics.isEmpty()) {
|
||||||
|
lyrics_ = "No lyrics found.\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lyrics_ = lyrics + "\n\n(Lyrics from " + provider + ")\n";
|
||||||
|
}
|
||||||
lyrics_id_ = -1;
|
lyrics_id_ = -1;
|
||||||
|
|
||||||
if (action_show_lyrics_->isChecked() && !lyrics_.isEmpty()) {
|
if (action_show_lyrics_->isChecked() && !lyrics_.isEmpty()) {
|
||||||
|
|||||||
@@ -87,6 +87,7 @@
|
|||||||
# include "musicbrainz/tagfetcher.h"
|
# include "musicbrainz/tagfetcher.h"
|
||||||
# include "trackselectiondialog.h"
|
# include "trackselectiondialog.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "lyrics/lyricsfetcher.h"
|
||||||
#include "covermanager/albumcoverchoicecontroller.h"
|
#include "covermanager/albumcoverchoicecontroller.h"
|
||||||
#include "covermanager/albumcoverloader.h"
|
#include "covermanager/albumcoverloader.h"
|
||||||
#include "covermanager/albumcoverloaderoptions.h"
|
#include "covermanager/albumcoverloaderoptions.h"
|
||||||
@@ -112,13 +113,15 @@ EditTagDialog::EditTagDialog(Application *app, QWidget *parent)
|
|||||||
tag_fetcher_(new TagFetcher(app->network(), this)),
|
tag_fetcher_(new TagFetcher(app->network(), this)),
|
||||||
results_dialog_(new TrackSelectionDialog(this)),
|
results_dialog_(new TrackSelectionDialog(this)),
|
||||||
#endif
|
#endif
|
||||||
|
lyrics_fetcher_(new LyricsFetcher(app->lyrics_providers(), this)),
|
||||||
image_no_cover_thumbnail_(ImageUtils::GenerateNoCoverImage(QSize(128, 128), devicePixelRatioF())),
|
image_no_cover_thumbnail_(ImageUtils::GenerateNoCoverImage(QSize(128, 128), devicePixelRatioF())),
|
||||||
loading_(false),
|
loading_(false),
|
||||||
ignore_edits_(false),
|
ignore_edits_(false),
|
||||||
summary_cover_art_id_(-1),
|
summary_cover_art_id_(-1),
|
||||||
tags_cover_art_id_(-1),
|
tags_cover_art_id_(-1),
|
||||||
cover_art_is_set_(false),
|
cover_art_is_set_(false),
|
||||||
save_tag_pending_(0) {
|
save_tag_pending_(0),
|
||||||
|
lyrics_id_(-1) {
|
||||||
|
|
||||||
QObject::connect(&*app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &EditTagDialog::AlbumCoverLoaded);
|
QObject::connect(&*app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &EditTagDialog::AlbumCoverLoaded);
|
||||||
|
|
||||||
@@ -128,6 +131,7 @@ EditTagDialog::EditTagDialog(Application *app, QWidget *parent)
|
|||||||
QObject::connect(results_dialog_, &TrackSelectionDialog::SongChosen, this, &EditTagDialog::FetchTagSongChosen);
|
QObject::connect(results_dialog_, &TrackSelectionDialog::SongChosen, this, &EditTagDialog::FetchTagSongChosen);
|
||||||
QObject::connect(results_dialog_, &TrackSelectionDialog::finished, tag_fetcher_, &TagFetcher::Cancel);
|
QObject::connect(results_dialog_, &TrackSelectionDialog::finished, tag_fetcher_, &TagFetcher::Cancel);
|
||||||
#endif
|
#endif
|
||||||
|
QObject::connect(lyrics_fetcher_, &LyricsFetcher::LyricsFetched, this, &EditTagDialog::UpdateLyrics);
|
||||||
|
|
||||||
album_cover_choice_controller_->Init(app_);
|
album_cover_choice_controller_->Init(app_);
|
||||||
|
|
||||||
@@ -193,6 +197,7 @@ EditTagDialog::EditTagDialog(Application *app, QWidget *parent)
|
|||||||
#ifdef HAVE_MUSICBRAINZ
|
#ifdef HAVE_MUSICBRAINZ
|
||||||
QObject::connect(ui_->fetch_tag, &QPushButton::clicked, this, &EditTagDialog::FetchTag);
|
QObject::connect(ui_->fetch_tag, &QPushButton::clicked, this, &EditTagDialog::FetchTag);
|
||||||
#endif
|
#endif
|
||||||
|
QObject::connect(ui_->fetch_lyrics, &QPushButton::clicked, this, &EditTagDialog::FetchLyrics);
|
||||||
|
|
||||||
// Set up the album cover menu
|
// Set up the album cover menu
|
||||||
cover_menu_ = new QMenu(this);
|
cover_menu_ = new QMenu(this);
|
||||||
@@ -606,6 +611,8 @@ void EditTagDialog::SelectionChanged() {
|
|||||||
// Set the editable fields
|
// Set the editable fields
|
||||||
UpdateUI(indexes);
|
UpdateUI(indexes);
|
||||||
|
|
||||||
|
lyrics_id_ = -1;
|
||||||
|
|
||||||
// If we're editing multiple songs then we have to disable certain tabs
|
// If we're editing multiple songs then we have to disable certain tabs
|
||||||
const bool multiple = indexes.count() > 1;
|
const bool multiple = indexes.count() > 1;
|
||||||
ui_->tab_widget->setTabEnabled(ui_->tab_widget->indexOf(ui_->tab_summary), !multiple);
|
ui_->tab_widget->setTabEnabled(ui_->tab_widget->indexOf(ui_->tab_summary), !multiple);
|
||||||
@@ -1411,6 +1418,31 @@ void EditTagDialog::FetchTagSongChosen(const Song &original_song, const Song &ne
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditTagDialog::FetchLyrics() {
|
||||||
|
|
||||||
|
if (ui_->song_list->selectionModel()->selectedIndexes().isEmpty()) return;
|
||||||
|
const Song &song = data_[ui_->song_list->selectionModel()->selectedIndexes().first().row()].current_;
|
||||||
|
lyrics_fetcher_->Clear();
|
||||||
|
ui_->lyrics->setPlainText(tr("loading..."));
|
||||||
|
lyrics_id_ = static_cast<qint64>(lyrics_fetcher_->Search(song.effective_albumartist(), song.artist(), song.album(), song.title()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditTagDialog::UpdateLyrics(const quint64 id, const QString &provider, const QString &lyrics) {
|
||||||
|
|
||||||
|
Q_UNUSED(provider);
|
||||||
|
|
||||||
|
if (static_cast<qint64>(id) != lyrics_id_) return;
|
||||||
|
lyrics_id_ = -1;
|
||||||
|
if (lyrics.isEmpty()) {
|
||||||
|
ui_->lyrics->setPlainText(tr("Not found."));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui_->lyrics->setPlainText(lyrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void EditTagDialog::SongSaveTagsComplete(TagReaderReply *reply, const QString &filename, Song song, const UpdateCoverAction cover_action) {
|
void EditTagDialog::SongSaveTagsComplete(TagReaderReply *reply, const QString &filename, Song song, const UpdateCoverAction cover_action) {
|
||||||
|
|
||||||
--save_tag_pending_;
|
--save_tag_pending_;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class Ui_EditTagDialog;
|
|||||||
#ifdef HAVE_MUSICBRAINZ
|
#ifdef HAVE_MUSICBRAINZ
|
||||||
class TrackSelectionDialog;
|
class TrackSelectionDialog;
|
||||||
class TagFetcher;
|
class TagFetcher;
|
||||||
|
class LyricsFetcher;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class EditTagDialog : public QDialog {
|
class EditTagDialog : public QDialog {
|
||||||
@@ -120,6 +121,8 @@ class EditTagDialog : public QDialog {
|
|||||||
void SongRated(const float rating);
|
void SongRated(const float rating);
|
||||||
void FetchTag();
|
void FetchTag();
|
||||||
void FetchTagSongChosen(const Song &original_song, const Song &new_metadata);
|
void FetchTagSongChosen(const Song &original_song, const Song &new_metadata);
|
||||||
|
void FetchLyrics();
|
||||||
|
void UpdateLyrics(const quint64 id, const QString &provider, const QString &lyrics);
|
||||||
|
|
||||||
void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &cover_result);
|
void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &cover_result);
|
||||||
|
|
||||||
@@ -185,6 +188,7 @@ class EditTagDialog : public QDialog {
|
|||||||
TagFetcher *tag_fetcher_;
|
TagFetcher *tag_fetcher_;
|
||||||
TrackSelectionDialog *results_dialog_;
|
TrackSelectionDialog *results_dialog_;
|
||||||
#endif
|
#endif
|
||||||
|
LyricsFetcher *lyrics_fetcher_;
|
||||||
|
|
||||||
const QImage image_no_cover_thumbnail_;
|
const QImage image_no_cover_thumbnail_;
|
||||||
|
|
||||||
@@ -210,6 +214,8 @@ class EditTagDialog : public QDialog {
|
|||||||
QMap<int, Song> collection_songs_;
|
QMap<int, Song> collection_songs_;
|
||||||
|
|
||||||
AlbumCoverLoaderOptions::Types cover_types_;
|
AlbumCoverLoaderOptions::Types cover_types_;
|
||||||
|
|
||||||
|
qint64 lyrics_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EDITTAGDIALOG_H
|
#endif // EDITTAGDIALOG_H
|
||||||
|
|||||||
@@ -1131,6 +1131,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="21" column="1">
|
||||||
|
<widget class="QPushButton" name="fetch_lyrics">
|
||||||
|
<property name="text">
|
||||||
|
<string>Complete lyrics automatically</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -1213,6 +1220,7 @@
|
|||||||
<tabstop>fetch_tag</tabstop>
|
<tabstop>fetch_tag</tabstop>
|
||||||
<tabstop>comment</tabstop>
|
<tabstop>comment</tabstop>
|
||||||
<tabstop>lyrics</tabstop>
|
<tabstop>lyrics</tabstop>
|
||||||
|
<tabstop>fetch_lyrics</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../data/data.qrc"/>
|
<include location="../../data/data.qrc"/>
|
||||||
|
|||||||
@@ -134,6 +134,9 @@ void LyricsFetcherSearch::AllProvidersFinished() {
|
|||||||
qLog(Debug) << "Using lyrics from" << results_.last().provider << "for" << request_.artist << request_.title << "with score" << results_.last().score;
|
qLog(Debug) << "Using lyrics from" << results_.last().provider << "for" << request_.artist << request_.title << "with score" << results_.last().score;
|
||||||
emit LyricsFetched(id_, results_.last().provider, results_.last().lyrics);
|
emit LyricsFetched(id_, results_.last().provider, results_.last().lyrics);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
emit LyricsFetched(id_, QString(), QString());
|
||||||
|
}
|
||||||
|
|
||||||
emit SearchFinished(id_, results_);
|
emit SearchFinished(id_, results_);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user