2010-10-10 18:09:20 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-10-10 18:09:20 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-11-27 15:22:59 +01:00
|
|
|
#include "songinfo/songinfoview.h"
|
2010-12-18 18:28:02 +01:00
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
#include <QFuture>
|
2010-10-10 18:46:35 +02:00
|
|
|
#include <QSettings>
|
2010-10-10 18:09:20 +02:00
|
|
|
#include <QtConcurrentRun>
|
|
|
|
|
2015-11-27 15:22:59 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "core/closure.h"
|
|
|
|
#include "songinfo/songinfoprovider.h"
|
|
|
|
#include "songinfo/taglyricsinfoprovider.h"
|
|
|
|
#include "songinfo/ultimatelyricsprovider.h"
|
|
|
|
#include "songinfo/ultimatelyricsreader.h"
|
2010-10-10 18:46:35 +02:00
|
|
|
|
2015-11-27 15:22:59 +01:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
|
|
|
#include "songinfo/lastfmtrackinfoprovider.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const char* SongInfoView::kSettingsGroup = "SongInfo";
|
2010-10-10 18:09:20 +02:00
|
|
|
|
2010-10-16 19:20:54 +02:00
|
|
|
SongInfoView::SongInfoView(QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: SongInfoBase(parent), ultimate_reader_(new UltimateLyricsReader(this)) {
|
2010-10-10 18:09:20 +02:00
|
|
|
// Parse the ultimate lyrics xml file in the background
|
2014-02-07 16:34:20 +01:00
|
|
|
QFuture<ProviderList> future =
|
|
|
|
QtConcurrent::run(ultimate_reader_.get(), &UltimateLyricsReader::Parse,
|
|
|
|
QString(":lyrics/ultimate_providers.xml"));
|
2015-11-27 15:22:59 +01:00
|
|
|
NewClosure(future, this, SLOT(UltimateLyricsParsed(QFuture<ProviderList>)),
|
|
|
|
future);
|
2010-10-10 19:59:23 +02:00
|
|
|
|
2010-12-18 18:28:02 +01:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2010-10-10 19:59:23 +02:00
|
|
|
fetcher_->AddProvider(new LastfmTrackInfoProvider);
|
2010-12-18 18:28:02 +01:00
|
|
|
#endif
|
2015-04-10 21:05:07 +02:00
|
|
|
fetcher_->AddProvider(new TagLyricsInfoProvider);
|
2010-10-10 18:09:20 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
SongInfoView::~SongInfoView() {}
|
2010-10-10 18:09:20 +02:00
|
|
|
|
2015-11-27 15:22:59 +01:00
|
|
|
void SongInfoView::UltimateLyricsParsed(QFuture<ProviderList> future) {
|
|
|
|
for (SongInfoProvider* provider : future.result()) {
|
2010-10-10 18:09:20 +02:00
|
|
|
fetcher_->AddProvider(provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
ultimate_reader_.reset();
|
2010-10-10 18:46:35 +02:00
|
|
|
|
|
|
|
ReloadSettings();
|
2010-10-10 18:09:20 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool SongInfoView::NeedsUpdate(const Song& old_metadata,
|
|
|
|
const Song& new_metadata) const {
|
2010-10-10 20:57:23 +02:00
|
|
|
if (new_metadata.title().isEmpty() || new_metadata.artist().isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return old_metadata.title() != new_metadata.title() ||
|
|
|
|
old_metadata.artist() != new_metadata.artist();
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void SongInfoView::InfoResultReady(int id,
|
|
|
|
const CollapsibleInfoPane::Data& data) {
|
|
|
|
if (id != current_request_id_) return;
|
|
|
|
|
|
|
|
AddSection(new CollapsibleInfoPane(data, this));
|
2010-10-11 21:49:12 +02:00
|
|
|
CollapseSections();
|
2010-10-10 18:09:20 +02:00
|
|
|
}
|
2010-10-10 18:46:35 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void SongInfoView::ResultReady(int id, const SongInfoFetcher::Result& result) {}
|
2013-12-21 19:58:51 +01:00
|
|
|
|
2010-10-10 18:46:35 +02:00
|
|
|
void SongInfoView::ReloadSettings() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
|
|
|
// Put the providers in the right order
|
|
|
|
QList<SongInfoProvider*> ordered_providers;
|
|
|
|
|
2010-12-26 16:06:11 +01:00
|
|
|
QVariantList default_order;
|
|
|
|
default_order << "lyrics.wikia.com"
|
|
|
|
<< "lyricstime.com"
|
|
|
|
<< "lyricsreg.com"
|
|
|
|
<< "lyricsmania.com"
|
|
|
|
<< "metrolyrics.com"
|
|
|
|
<< "azlyrics.com"
|
|
|
|
<< "songlyrics.com"
|
|
|
|
<< "elyrics.net"
|
|
|
|
<< "lyricsdownload.com"
|
|
|
|
<< "lyrics.com"
|
|
|
|
<< "lyricsbay.com"
|
|
|
|
<< "directlyrics.com"
|
|
|
|
<< "loudson.gs"
|
|
|
|
<< "teksty.org"
|
|
|
|
<< "tekstowo.pl (Polish translations)"
|
|
|
|
<< "vagalume.uol.com.br"
|
2012-02-12 16:17:18 +01:00
|
|
|
<< "vagalume.uol.com.br (Portuguese translations)"
|
|
|
|
<< "darklyrics.com";
|
2010-12-26 16:06:11 +01:00
|
|
|
|
|
|
|
QVariant saved_order = s.value("search_order", default_order);
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QVariant& name : saved_order.toList()) {
|
2010-12-26 16:06:11 +01:00
|
|
|
SongInfoProvider* provider = ProviderByName(name.toString());
|
2014-02-07 16:34:20 +01:00
|
|
|
if (provider) ordered_providers << provider;
|
2010-10-10 18:46:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enable all the providers in the list and rank them
|
2010-10-16 14:56:58 +02:00
|
|
|
int relevance = 100;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (SongInfoProvider* provider : ordered_providers) {
|
2010-10-10 18:46:35 +02:00
|
|
|
provider->set_enabled(true);
|
2010-10-16 14:56:58 +02:00
|
|
|
qobject_cast<UltimateLyricsProvider*>(provider)->set_relevance(relevance--);
|
2010-10-10 18:46:35 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Any lyric providers we don't have in ordered_providers are considered
|
|
|
|
// disabled
|
2014-02-10 14:29:07 +01:00
|
|
|
for (SongInfoProvider* provider : fetcher_->providers()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (qobject_cast<UltimateLyricsProvider*>(provider) &&
|
|
|
|
!ordered_providers.contains(provider)) {
|
2010-10-10 18:46:35 +02:00
|
|
|
provider->set_enabled(false);
|
|
|
|
}
|
|
|
|
}
|
2010-10-16 15:56:49 +02:00
|
|
|
|
|
|
|
SongInfoBase::ReloadSettings();
|
2010-10-10 18:46:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SongInfoProvider* SongInfoView::ProviderByName(const QString& name) const {
|
2014-02-10 14:29:07 +01:00
|
|
|
for (SongInfoProvider* provider : fetcher_->providers()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (UltimateLyricsProvider* lyrics =
|
|
|
|
qobject_cast<UltimateLyricsProvider*>(provider)) {
|
|
|
|
if (lyrics->name() == name) return provider;
|
2010-10-10 18:46:35 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-06 16:49:49 +01:00
|
|
|
return nullptr;
|
2010-10-10 18:46:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2014-02-07 16:34:20 +01:00
|
|
|
bool CompareLyricProviders(const UltimateLyricsProvider* a,
|
|
|
|
const UltimateLyricsProvider* b) {
|
|
|
|
if (a->is_enabled() && !b->is_enabled()) return true;
|
|
|
|
if (!a->is_enabled() && b->is_enabled()) return false;
|
|
|
|
return a->relevance() > b->relevance();
|
|
|
|
}
|
2010-10-10 18:46:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<const UltimateLyricsProvider*> SongInfoView::lyric_providers() const {
|
|
|
|
QList<const UltimateLyricsProvider*> ret;
|
2014-02-10 14:29:07 +01:00
|
|
|
for (SongInfoProvider* provider : fetcher_->providers()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (UltimateLyricsProvider* lyrics =
|
|
|
|
qobject_cast<UltimateLyricsProvider*>(provider)) {
|
2010-10-10 18:46:35 +02:00
|
|
|
ret << lyrics;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qSort(ret.begin(), ret.end(), CompareLyricProviders);
|
|
|
|
return ret;
|
|
|
|
}
|