From 6b1d0898d57ef91e552d79d90fd6bb3c8d6e584c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 17 Jul 2018 11:15:34 +0200 Subject: [PATCH 1/4] Print a message when we fail to open a zim file. --- kiwixapp.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kiwixapp.cpp b/kiwixapp.cpp index 7732617..2ad9107 100644 --- a/kiwixapp.cpp +++ b/kiwixapp.cpp @@ -1,4 +1,5 @@ #include "kiwixapp.h" +#include "zim/error.h" KiwixApp::KiwixApp(int& argc, char *argv[]) : QApplication(argc, argv), @@ -21,7 +22,12 @@ void KiwixApp::openZimFile(const QString &zimfile) std::cout << "Opening " << zimfile_ << std::endl; try { reader = new kiwix::Reader(zimfile_); - } catch (...) { + } catch (const zim::ZimFileFormatError& e) { + std::cout << "Cannot open " << zimfile_ << std::endl; + std::cout << e.what() << std::endl; + reader = nullptr; + } catch (const std::exception& e) { + std::cout << "oup" << e.what() << std::endl; reader = nullptr; } } From fab22ab9095ae6d9b0fb50d8dd913d939a769ecb Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 17 Jul 2018 11:16:20 +0200 Subject: [PATCH 2/4] Better convertion of the mimetype from std::string to QByteArray. --- kiwixschemehandler.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kiwixschemehandler.cpp b/kiwixschemehandler.cpp index dca7963..3b8a5a9 100644 --- a/kiwixschemehandler.cpp +++ b/kiwixschemehandler.cpp @@ -44,10 +44,9 @@ KiwixSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request) request->fail(QWebEngineUrlRequestJob::UrlNotFound); return; } - BlobBuffer* buffer = new BlobBuffer(entry.getBlob()); - std::cout << " mimetype : " << entry.getMimetype() << std::endl; - auto mimeType = QByteArray::fromRawData(entry.getMimetype().data(), entry.getMimetype().size()); + std::cout << " mimetype : '" << entry.getMimetype() << "'" << std::endl; + auto mimeType = QByteArray::fromStdString(entry.getMimetype()); connect(buffer, &QIODevice::aboutToClose, buffer, &QObject::deleteLater); request->reply(mimeType, buffer); } From 4849b5e364272d856185c8da65da7cf1311d7903 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 17 Jul 2018 11:19:43 +0200 Subject: [PATCH 3/4] Rewrite the request interceptor. It seems that there are request in the form "blob://foo.zim/". I don't know where it come from, we cannot handle it and even Qt is parsing it wrongly (scheme and host are empty, path is the full url request). By using a string to handle the url, it is simpler to change "http://" to "zim://". --- kiwixrequestinterceptor.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kiwixrequestinterceptor.cpp b/kiwixrequestinterceptor.cpp index 53af39f..31da7b3 100644 --- a/kiwixrequestinterceptor.cpp +++ b/kiwixrequestinterceptor.cpp @@ -14,10 +14,12 @@ void KiwixRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) { std::cout << "Intercept request" << std::endl; auto url = info.requestUrl(); - std::cout << " - " << url.toString().toUtf8().constData() << std::endl; - url.setScheme("zim"); - std::cout << " + " << url.toString().toUtf8().constData() << std::endl; - info.redirect(url); - + auto urlString = url.toString(); + std::cout << " - " << urlString.toUtf8().constData() << std::endl; + if (urlString.startsWith("http://")) { + urlString.replace(0, 7, "zim://"); + } + std::cout << " + " << urlString.toUtf8().constData() << std::endl; + info.redirect(QUrl(urlString)); } From a41b923ae7e435280f7da7f8ef6ed06505a1f4f4 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 17 Jul 2018 11:21:22 +0200 Subject: [PATCH 4/4] Use the static option to define how we link to kiwix-lib. We cannot create a static binary because we cannot build QtWebEngine statically. So the static config, should only be used to define if we are linking to the dynamic or static kiwix-lib. --- kiwix-desktop.pro | 1 - 1 file changed, 1 deletion(-) diff --git a/kiwix-desktop.pro b/kiwix-desktop.pro index 4f78ee8..bf3f519 100644 --- a/kiwix-desktop.pro +++ b/kiwix-desktop.pro @@ -57,7 +57,6 @@ INSTALLS += target static { PKGCONFIG_OPTION = "--static" - QMAKE_LFLAGS += "-static-libstdc++ --static" } unix {