diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 289bbb6fe..1104542b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -308,6 +308,7 @@ set(SOURCES songinfo/songkickconcerts.cpp songinfo/songkickconcertwidget.cpp songinfo/songplaystats.cpp + songinfo/ultimatelyricslyric.cpp songinfo/ultimatelyricsprovider.cpp songinfo/ultimatelyricsreader.cpp @@ -592,6 +593,7 @@ set(HEADERS songinfo/songkickconcerts.h songinfo/songkickconcertwidget.h songinfo/songplaystats.h + songinfo/ultimatelyricslyric.h songinfo/ultimatelyricsprovider.h songinfo/ultimatelyricsreader.h diff --git a/src/networkremote/outgoingdatacreator.cpp b/src/networkremote/outgoingdatacreator.cpp index 97924c450..85ae8cdfb 100644 --- a/src/networkremote/outgoingdatacreator.cpp +++ b/src/networkremote/outgoingdatacreator.cpp @@ -535,7 +535,7 @@ void OutgoingDataCreator::SendLyrics(int id, const SongInfoFetcher::Result& resu foreach (const CollapsibleInfoPane::Data& data, result.info_) { // If the size is zero, do not send the provider - SongInfoTextView* editor = qobject_cast(data.contents_); + UltimateLyricsLyric* editor = qobject_cast(data.content_object_); if (editor->toPlainText().length() == 0) continue; diff --git a/src/networkremote/outgoingdatacreator.h b/src/networkremote/outgoingdatacreator.h index cdeab7178..cddabca43 100644 --- a/src/networkremote/outgoingdatacreator.h +++ b/src/networkremote/outgoingdatacreator.h @@ -18,8 +18,8 @@ #include "songinfo/collapsibleinfopane.h" #include "songinfo/songinfofetcher.h" #include "songinfo/songinfoprovider.h" -#include "songinfo/songinfotextview.h" #include "songinfo/songinfoview.h" +#include "songinfo/ultimatelyricslyric.h" #include "songinfo/ultimatelyricsprovider.h" #include "songinfo/ultimatelyricsreader.h" #include "remotecontrolmessages.pb.h" diff --git a/src/songinfo/collapsibleinfopane.h b/src/songinfo/collapsibleinfopane.h index a3bb69960..cc884ba9d 100644 --- a/src/songinfo/collapsibleinfopane.h +++ b/src/songinfo/collapsibleinfopane.h @@ -49,6 +49,7 @@ public: int relevance_; QWidget* contents_; + QObject* content_object_; }; CollapsibleInfoPane(const Data& data, QWidget* parent = 0); diff --git a/src/songinfo/ultimatelyricslyric.cpp b/src/songinfo/ultimatelyricslyric.cpp new file mode 100644 index 000000000..6c226032b --- /dev/null +++ b/src/songinfo/ultimatelyricslyric.cpp @@ -0,0 +1,37 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + 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 . +*/ + +#include "ultimatelyricslyric.h" + +#include + +UltimateLyricsLyric::UltimateLyricsLyric(QObject* parent) : + QTextDocument(parent) { +} + +void UltimateLyricsLyric::SetHtml(const QString& html) { + QString copy(html.trimmed()); + + // Simplify newlines, and convert them to

+ copy.replace(QRegExp("[\\r\\n]+"), "\n"); + copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1

"); + + // Strip any newlines from the end + copy.replace(QRegExp("((<\\s*br\\s*/?\\s*>)|(<\\s*/?\\s*p\\s*/?\\s*>))+$"), ""); + + setHtml(copy); +} diff --git a/src/songinfo/ultimatelyricslyric.h b/src/songinfo/ultimatelyricslyric.h new file mode 100644 index 000000000..7e27ad69c --- /dev/null +++ b/src/songinfo/ultimatelyricslyric.h @@ -0,0 +1,33 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + 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 . +*/ + +#ifndef ULTIMATELYRICSLYRIC_H +#define ULTIMATELYRICSLYRIC_H + +#include +#include + +class UltimateLyricsLyric : public QTextDocument { + Q_OBJECT + +public: + UltimateLyricsLyric(QObject* parent = 0); + + void SetHtml(const QString& html); +}; + +#endif // ULTIMATELYRICSLYRIC_H diff --git a/src/songinfo/ultimatelyricsprovider.cpp b/src/songinfo/ultimatelyricsprovider.cpp index 3fec8355c..ccab2ce4c 100644 --- a/src/songinfo/ultimatelyricsprovider.cpp +++ b/src/songinfo/ultimatelyricsprovider.cpp @@ -16,12 +16,15 @@ */ #include "songinfotextview.h" +#include "ultimatelyricslyric.h" #include "ultimatelyricsprovider.h" #include "core/logging.h" #include "core/network.h" +#include #include #include +#include #include @@ -137,9 +140,15 @@ void UltimateLyricsProvider::LyricsFetched() { data.type_ = CollapsibleInfoPane::Data::Type_Lyrics; data.relevance_ = relevance(); - SongInfoTextView* editor = new SongInfoTextView; - editor->SetHtml(lyrics); - data.contents_ = editor; + if (QThread::currentThread() == QCoreApplication::instance()->thread()) { + SongInfoTextView* editor = new SongInfoTextView; + editor->SetHtml(lyrics); + data.contents_ = editor; + } else { + UltimateLyricsLyric* editor = new UltimateLyricsLyric; + editor->SetHtml(lyrics); + data.content_object_ = editor; + } emit InfoReady(id, data); }