mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-06 06:03:23 +01:00
Fix crash when fetching lyrics with the network remote.
(cherry picked from commit 90c8929f96805bc25020bd03ec9f19dd6fb1f13b)
This commit is contained in:
parent
a8e8898111
commit
9d0b1611c7
@ -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
|
||||
|
||||
|
@ -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<SongInfoTextView*>(data.contents_);
|
||||
UltimateLyricsLyric* editor = qobject_cast<UltimateLyricsLyric*>(data.content_object_);
|
||||
if (editor->toPlainText().length() == 0)
|
||||
continue;
|
||||
|
||||
|
@ -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"
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
int relevance_;
|
||||
|
||||
QWidget* contents_;
|
||||
QObject* content_object_;
|
||||
};
|
||||
|
||||
CollapsibleInfoPane(const Data& data, QWidget* parent = 0);
|
||||
|
37
src/songinfo/ultimatelyricslyric.cpp
Normal file
37
src/songinfo/ultimatelyricslyric.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/* This file is part of Clementine.
|
||||
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include "ultimatelyricslyric.h"
|
||||
|
||||
#include <QRegExp>
|
||||
|
||||
UltimateLyricsLyric::UltimateLyricsLyric(QObject* parent) :
|
||||
QTextDocument(parent) {
|
||||
}
|
||||
|
||||
void UltimateLyricsLyric::SetHtml(const QString& html) {
|
||||
QString copy(html.trimmed());
|
||||
|
||||
// Simplify newlines, and convert them to <p>
|
||||
copy.replace(QRegExp("[\\r\\n]+"), "\n");
|
||||
copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1<p>");
|
||||
|
||||
// Strip any newlines from the end
|
||||
copy.replace(QRegExp("((<\\s*br\\s*/?\\s*>)|(<\\s*/?\\s*p\\s*/?\\s*>))+$"), "");
|
||||
|
||||
setHtml(copy);
|
||||
}
|
33
src/songinfo/ultimatelyricslyric.h
Normal file
33
src/songinfo/ultimatelyricslyric.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* This file is part of Clementine.
|
||||
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef ULTIMATELYRICSLYRIC_H
|
||||
#define ULTIMATELYRICSLYRIC_H
|
||||
|
||||
#include <QString>
|
||||
#include <QTextDocument>
|
||||
|
||||
class UltimateLyricsLyric : public QTextDocument {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UltimateLyricsLyric(QObject* parent = 0);
|
||||
|
||||
void SetHtml(const QString& html);
|
||||
};
|
||||
|
||||
#endif // ULTIMATELYRICSLYRIC_H
|
@ -16,12 +16,15 @@
|
||||
*/
|
||||
|
||||
#include "songinfotextview.h"
|
||||
#include "ultimatelyricslyric.h"
|
||||
#include "ultimatelyricsprovider.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/network.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QNetworkReply>
|
||||
#include <QTextCodec>
|
||||
#include <QThread>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user