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/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-10 19:59:23 +02:00
|
|
|
#include "lastfmtrackinfoprovider.h"
|
2010-10-10 18:09:20 +02:00
|
|
|
#include "songinfoprovider.h"
|
|
|
|
#include "songinfoview.h"
|
|
|
|
#include "ultimatelyricsprovider.h"
|
|
|
|
#include "ultimatelyricsreader.h"
|
|
|
|
|
|
|
|
#include <QFuture>
|
|
|
|
#include <QFutureWatcher>
|
2010-10-10 18:46:35 +02:00
|
|
|
#include <QSettings>
|
2010-10-10 18:09:20 +02:00
|
|
|
#include <QtConcurrentRun>
|
|
|
|
|
2010-10-10 18:46:35 +02:00
|
|
|
const char* SongInfoView::kSettingsGroup = "SongInfo";
|
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
typedef QList<SongInfoProvider*> ProviderList;
|
|
|
|
|
2010-10-16 19:20:54 +02:00
|
|
|
SongInfoView::SongInfoView(QWidget* parent)
|
|
|
|
: SongInfoBase(parent),
|
|
|
|
ultimate_reader_(new UltimateLyricsReader(this))
|
2010-10-10 18:09:20 +02:00
|
|
|
{
|
|
|
|
// Parse the ultimate lyrics xml file in the background
|
|
|
|
QFuture<ProviderList> future = QtConcurrent::run(
|
|
|
|
ultimate_reader_.get(), &UltimateLyricsReader::Parse,
|
|
|
|
QString(":lyrics/ultimate_providers.xml"));
|
|
|
|
QFutureWatcher<ProviderList>* watcher = new QFutureWatcher<ProviderList>(this);
|
|
|
|
watcher->setFuture(future);
|
|
|
|
connect(watcher, SIGNAL(finished()), SLOT(UltimateLyricsParsed()));
|
2010-10-10 19:59:23 +02:00
|
|
|
|
|
|
|
fetcher_->AddProvider(new LastfmTrackInfoProvider);
|
2010-10-10 18:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SongInfoView::~SongInfoView() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void SongInfoView::UltimateLyricsParsed() {
|
|
|
|
QFutureWatcher<ProviderList>* watcher =
|
|
|
|
static_cast<QFutureWatcher<ProviderList>*>(sender());
|
|
|
|
|
|
|
|
foreach (SongInfoProvider* provider, watcher->result()) {
|
|
|
|
fetcher_->AddProvider(provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
watcher->deleteLater();
|
|
|
|
ultimate_reader_.reset();
|
2010-10-10 18:46:35 +02:00
|
|
|
|
|
|
|
ReloadSettings();
|
2010-10-10 18:09:20 +02:00
|
|
|
}
|
|
|
|
|
2010-10-10 20:57:23 +02:00
|
|
|
bool SongInfoView::NeedsUpdate(const Song& old_metadata, const Song& new_metadata) const {
|
|
|
|
if (new_metadata.title().isEmpty() || new_metadata.artist().isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return old_metadata.title() != new_metadata.title() ||
|
|
|
|
old_metadata.artist() != new_metadata.artist();
|
|
|
|
}
|
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
void SongInfoView::ResultReady(int id, const SongInfoFetcher::Result& result) {
|
|
|
|
if (id != current_request_id_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Clear();
|
|
|
|
|
|
|
|
foreach (const CollapsibleInfoPane::Data& data, result.info_) {
|
|
|
|
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
|
|
|
|
|
|
|
void SongInfoView::ReloadSettings() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
|
|
|
// Put the providers in the right order
|
|
|
|
QList<SongInfoProvider*> ordered_providers;
|
|
|
|
|
|
|
|
QVariant saved_order = s.value("search_order");
|
|
|
|
if (saved_order.isNull()) {
|
|
|
|
// Hardcoded default order
|
|
|
|
ordered_providers << ProviderByName("lyrics.wikia.com")
|
|
|
|
<< ProviderByName("lyricstime.com")
|
|
|
|
<< ProviderByName("lyricsreg.com")
|
|
|
|
<< ProviderByName("lyricsmania.com")
|
|
|
|
<< ProviderByName("metrolyrics.com")
|
|
|
|
<< ProviderByName("azlyrics.com")
|
|
|
|
<< ProviderByName("songlyrics.com")
|
|
|
|
<< ProviderByName("elyrics.net")
|
|
|
|
<< ProviderByName("lyricsdownload.com")
|
|
|
|
<< ProviderByName("lyrics.com")
|
|
|
|
<< ProviderByName("lyricsbay.com")
|
|
|
|
<< ProviderByName("directlyrics.com")
|
|
|
|
<< ProviderByName("loudson.gs")
|
|
|
|
<< ProviderByName("teksty.org")
|
|
|
|
<< ProviderByName("tekstowo.pl (Polish translations)")
|
|
|
|
<< ProviderByName("vagalume.uol.com.br")
|
|
|
|
<< ProviderByName("vagalume.uol.com.br (Portuguese translations)");
|
|
|
|
} else {
|
|
|
|
foreach (const QVariant& name, saved_order.toList()) {
|
|
|
|
SongInfoProvider* provider = ProviderByName(name.toString());
|
|
|
|
if (provider)
|
|
|
|
ordered_providers << provider;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable all the providers in the list and rank them
|
2010-10-16 14:56:58 +02:00
|
|
|
int relevance = 100;
|
2010-10-10 18:46:35 +02:00
|
|
|
foreach (SongInfoProvider* provider, ordered_providers) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Any lyric providers we don't have in ordered_providers are considered disabled
|
|
|
|
foreach (SongInfoProvider* provider, fetcher_->providers()) {
|
|
|
|
if (qobject_cast<UltimateLyricsProvider*>(provider) && !ordered_providers.contains(provider)) {
|
|
|
|
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 {
|
|
|
|
foreach (SongInfoProvider* provider, fetcher_->providers()) {
|
|
|
|
if (UltimateLyricsProvider* lyrics = qobject_cast<UltimateLyricsProvider*>(provider)) {
|
|
|
|
if (lyrics->name() == name)
|
|
|
|
return provider;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<const UltimateLyricsProvider*> SongInfoView::lyric_providers() const {
|
|
|
|
QList<const UltimateLyricsProvider*> ret;
|
|
|
|
foreach (SongInfoProvider* provider, fetcher_->providers()) {
|
|
|
|
if (UltimateLyricsProvider* lyrics = qobject_cast<UltimateLyricsProvider*>(provider)) {
|
|
|
|
ret << lyrics;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qSort(ret.begin(), ret.end(), CompareLyricProviders);
|
|
|
|
return ret;
|
|
|
|
}
|