Fix crash when fetching lyrics with the network remote.

This commit is contained in:
Andreas 2013-10-09 19:33:59 +02:00
parent 8e39e70c39
commit 90c8929f96
7 changed files with 87 additions and 5 deletions

View File

@ -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

View File

@ -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;

View File

@ -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"

View File

@ -49,6 +49,7 @@ public:
int relevance_;
QWidget* contents_;
QObject* content_object_;
};
CollapsibleInfoPane(const Data& data, QWidget* parent = 0);

View 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);
}

View 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

View File

@ -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);
}