Commit 3f50c16c authored by Andrea Scarpino's avatar Andrea Scarpino

Fix segfault when using QWebPage, switch to LyricsWiki

parent 4b333cf6
......@@ -6,15 +6,15 @@ SOURCES += \
src/main.cpp \
src/lyricsmanager.cpp \
src/lyric.cpp \
src/chartlyricsapi.cpp
# src/lyricswikiapi.cpp
src/lyricswikiapi.cpp
# src/chartlyricsapi.cpp
HEADERS += \
src/lyricsmanager.h \
src/lyric_p.h \
src/lyric.h \
src/chartlyricsapi.h
# src/lyricswikiapi.h
src/lyricswikiapi.h
# src/chartlyricsapi.h
OTHER_FILES += \
qml/cover/CoverPage.qml \
......@@ -30,7 +30,7 @@ CONFIG += sailfishapp_i18n
TRANSLATIONS += translations/harbour-lyrics-it.ts
# LyricsWiki
# QT += webkitwidgets
QT += webkitwidgets
# ChartLyrics
QT += xml
#QT += xml
......@@ -13,7 +13,7 @@ Name: harbour-lyrics
%{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Music lyrics application
Version: 0.1.1
Version: 0.2
Release: 1
Group: Qt/Qt
License: MIT
......@@ -25,7 +25,7 @@ BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: pkgconfig(Qt5Xml)
BuildRequires: pkgconfig(Qt5WebKitWidgets)
BuildRequires: desktop-file-utils
%description
......
Name: harbour-lyrics
Summary: Music lyrics application
Version: 0.1.1
Version: 0.2
Release: 1
# The contents of the Group field should be one of the groups listed here:
# http://gitorious.org/meego-developer-tools/spectacle/blobs/master/data/GROUPS
......@@ -25,8 +25,8 @@ PkgConfigBR:
- Qt5Core
- Qt5Qml
- Qt5Quick
- Qt5Xml # ChartLyrics
# - Qt5WebKitWidgets # LyricsWiki
- Qt5WebKitWidgets # LyricsWiki
# - Qt5Xml # ChartLyrics
# Build dependencies without a pkgconfig setup can be listed here
# PkgBR:
......
......@@ -28,7 +28,7 @@
#include <QObject>
#include <QString>
#include "chartlyricsapi.h"
#include "lyricswikiapi.h"
#include "lyric.h"
class LyricsManager : public QObject
......@@ -44,7 +44,7 @@ Q_SIGNALS:
void searchResult(Lyric *lyric, const bool &found);
private:
ChartLyricsAPI api;
LyricsWikiAPI api;
};
......
......@@ -104,15 +104,14 @@ void LyricsWikiAPI::onGetLyricResult()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender());
bool err = false;
bool err = true;
if (reply->error() != QNetworkReply::NoError) {
qCritical() << "Cannot fetch lyric";
err = true;
} else {
QJsonDocument json = QJsonDocument::fromJson(reply->readAll());
if (!json.isNull()) {
qDebug() << "Got lyric:\n" << json;
qDebug() << "Got lyric JSON";
QJsonObject jsonObj = json.object();
......@@ -123,18 +122,17 @@ void LyricsWikiAPI::onGetLyricResult()
const QUrl url(jsonObj.value("url").toString());
getLyricText(url, lyric);
err = false;
} else {
qDebug() << "No lyric found";
err = true;
}
} else {
qCritical() << "Got an invalid JSON!";
err = true;
}
}
if (err) {
emit lyricFetched(0, false);
emit lyricFetched(0, !err);
}
reply->deleteLater();
......@@ -157,8 +155,13 @@ void LyricsWikiAPI::onGetLyricPageResult()
QWebElement lyricbox = page.mainFrame()->findFirstElement("div[class=lyricbox]");
if (lyricbox.isNull()) {
qCritical() << "Cannot parse HTML page";
qCritical() << "Cannot find lyric text in HTML page";
} else {
// Remove the <script> tags
Q_FOREACH (QWebElement script, lyricbox.findAll(QStringLiteral("script"))) {
script.removeFromDocument();
}
lyric = lyrics.take(reply);
if (!lyric) {
......@@ -171,6 +174,7 @@ void LyricsWikiAPI::onGetLyricPageResult()
}
}
qDebug() << "Lyric found:" << found;
emit lyricFetched(lyric, found);
reply->deleteLater();
......
......@@ -22,6 +22,7 @@
SOFTWARE.
*/
#include <QApplication>
#include <QtQuick>
#include <sailfishapp.h>
......@@ -30,7 +31,9 @@
int main(int argc, char *argv[])
{
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
//QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
// Needed by QWebPage
QScopedPointer<QApplication> app(new QApplication(argc, argv));
QScopedPointer<QQuickView> view(SailfishApp::createView());
LyricsManager manager;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment