diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index 166f16a38..0f7e181f7 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -212,7 +212,7 @@ PluginInterface* Plugins::initPlugin(PluginInterface::InitState state, PluginInt return 0; } - pluginInterface->init(state, DataPaths::currentProfilePath() + "/extensions/"); + pluginInterface->init(state, DataPaths::currentProfilePath() + QL1S("/extensions/")); if (!pluginInterface->testPlugin()) { pluginInterface->unload(); diff --git a/src/lib/tools/emptynetworkreply.cpp b/src/lib/tools/emptynetworkreply.cpp index 59d43ec6e..bfe168184 100644 --- a/src/lib/tools/emptynetworkreply.cpp +++ b/src/lib/tools/emptynetworkreply.cpp @@ -23,14 +23,15 @@ EmptyNetworkReply::EmptyNetworkReply(QObject* parent) : QNetworkReply(parent) { setOperation(QNetworkAccessManager::GetOperation); - setError(QNetworkReply::OperationCanceledError, "QupZilla:No Error"); + setError(QNetworkReply::OperationCanceledError, QSL("QupZilla:No Error")); + + open(QIODevice::ReadOnly); QTimer::singleShot(0, this, SLOT(delayedFinish())); } void EmptyNetworkReply::delayedFinish() { - emit finished(); } diff --git a/src/lib/tools/followredirectreply.cpp b/src/lib/tools/followredirectreply.cpp index f65d7cbca..dbeaf4de6 100644 --- a/src/lib/tools/followredirectreply.cpp +++ b/src/lib/tools/followredirectreply.cpp @@ -48,6 +48,11 @@ QNetworkReply::NetworkError FollowRedirectReply::error() const return m_reply->error(); } +QString FollowRedirectReply::errorString() const +{ + return m_reply->errorString(); +} + QByteArray FollowRedirectReply::readAll() { return m_reply->readAll(); diff --git a/src/lib/tools/followredirectreply.h b/src/lib/tools/followredirectreply.h index 19374c51b..8073f7498 100644 --- a/src/lib/tools/followredirectreply.h +++ b/src/lib/tools/followredirectreply.h @@ -40,6 +40,8 @@ public: QUrl url() const; QNetworkReply::NetworkError error() const; + QString errorString() const; + QByteArray readAll(); signals: diff --git a/src/plugins/GreaseMonkey/gm_downloader.cpp b/src/plugins/GreaseMonkey/gm_downloader.cpp index 37277ec7b..a7a284bb0 100644 --- a/src/plugins/GreaseMonkey/gm_downloader.cpp +++ b/src/plugins/GreaseMonkey/gm_downloader.cpp @@ -53,34 +53,39 @@ void GM_Downloader::scriptDownloaded() return; } - QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8(); + if (m_reply->error() != QNetworkReply::NoError) { + qWarning() << "GreaseMonkey: Cannot download script" << m_reply->errorString(); + } + else { + const QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8(); - if (m_reply->error() == QNetworkReply::NoError && response.contains("// ==UserScript==")) { - const QString filePath = m_manager->scriptsDirectory() + QzTools::getFileNameFromUrl(m_reply->url()); - m_fileName = QzTools::ensureUniqueFilename(filePath); + if (response.contains(QByteArray("// ==UserScript=="))) { + const QString filePath = m_manager->scriptsDirectory() + QzTools::getFileNameFromUrl(m_reply->url()); + m_fileName = QzTools::ensureUniqueFilename(filePath); - QFile file(m_fileName); + QFile file(m_fileName); - if (!file.open(QFile::WriteOnly)) { - qWarning() << "GreaseMonkey: Cannot open file for writing" << m_fileName; - deleteLater(); - return; - } + if (!file.open(QFile::WriteOnly)) { + qWarning() << "GreaseMonkey: Cannot open file for writing" << m_fileName; + deleteLater(); + return; + } - file.write(response); - file.close(); + file.write(response); + file.close(); - QSettings settings(m_manager->settinsPath() + "greasemonkey/requires/requires.ini", QSettings::IniFormat); - settings.beginGroup("Files"); + QSettings settings(m_manager->settinsPath() + QL1S("greasemonkey/requires/requires.ini"), QSettings::IniFormat); + settings.beginGroup("Files"); - QzRegExp rx("@require(.*)\\n"); - rx.setMinimal(true); - rx.indexIn(response); + QzRegExp rx("@require(.*)\\n"); + rx.setMinimal(true); + rx.indexIn(response); - for (int i = 1; i <= rx.captureCount(); ++i) { - const QString url = rx.cap(i).trimmed(); - if (!url.isEmpty() && !settings.contains(url)) { - m_requireUrls.append(QUrl(url)); + for (int i = 1; i <= rx.captureCount(); ++i) { + const QString url = rx.cap(i).trimmed(); + if (!url.isEmpty() && !settings.contains(url)) { + m_requireUrls.append(QUrl(url)); + } } } } @@ -98,26 +103,31 @@ void GM_Downloader::requireDownloaded() return; } - QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8(); + if (m_reply->error() != QNetworkReply::NoError) { + qWarning() << "GreaseMonkey: Cannot download require script" << m_reply->errorString(); + } + else { + const QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8(); - if (m_reply->error() == QNetworkReply::NoError && !response.isEmpty()) { - const QString filePath = m_manager->settinsPath() + "/greasemonkey/requires/require.js"; - const QString fileName = QzTools::ensureUniqueFilename(filePath, "%1"); + if (!response.isEmpty()) { + const QString filePath = m_manager->settinsPath() + QL1S("/greasemonkey/requires/require.js"); + const QString fileName = QzTools::ensureUniqueFilename(filePath, "%1"); - QFile file(fileName); + QFile file(fileName); - if (!file.open(QFile::WriteOnly)) { - qWarning() << "GreaseMonkey: Cannot open file for writing" << fileName; - deleteLater(); - return; + if (!file.open(QFile::WriteOnly)) { + qWarning() << "GreaseMonkey: Cannot open file for writing" << fileName; + deleteLater(); + return; + } + + file.write(response); + file.close(); + + QSettings settings(m_manager->settinsPath() + QL1S("/greasemonkey/requires/requires.ini"), QSettings::IniFormat); + settings.beginGroup("Files"); + settings.setValue(m_reply->originalUrl().toString(), fileName); } - - file.write(response); - file.close(); - - QSettings settings(m_manager->settinsPath() + "greasemonkey/requires/requires.ini", QSettings::IniFormat); - settings.beginGroup("Files"); - settings.setValue(m_reply->originalUrl().toString(), fileName); } m_reply->deleteLater(); diff --git a/src/plugins/GreaseMonkey/gm_manager.cpp b/src/plugins/GreaseMonkey/gm_manager.cpp index 46360bf45..500d8c5e3 100644 --- a/src/plugins/GreaseMonkey/gm_manager.cpp +++ b/src/plugins/GreaseMonkey/gm_manager.cpp @@ -64,17 +64,17 @@ QString GM_Manager::settinsPath() const QString GM_Manager::scriptsDirectory() const { - return m_settingsPath + "/greasemonkey/"; + return m_settingsPath + QL1S("/greasemonkey"); } QString GM_Manager::requireScripts(const QStringList &urlList) const { - QDir requiresDir(m_settingsPath + "greasemonkey/requires"); + QDir requiresDir(m_settingsPath + QL1S("/greasemonkey/requires")); if (!requiresDir.exists() || urlList.isEmpty()) { return QString(); } - QSettings settings(m_settingsPath + "greasemonkey/requires/requires.ini", QSettings::IniFormat); + QSettings settings(m_settingsPath + QL1S("/greasemonkey/requires/requires.ini"), QSettings::IniFormat); settings.beginGroup("Files"); QString script; @@ -245,7 +245,7 @@ void GM_Manager::load() gmDir.mkdir("requires"); } - QSettings settings(m_settingsPath + "extensions.ini", QSettings::IniFormat); + QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat); settings.beginGroup("GreaseMonkey"); m_disabledScripts = settings.value("disabledScripts", QStringList()).toStringList(); @@ -271,7 +271,7 @@ void GM_Manager::load() } m_bootstrap = QzTools::readAllFileContents(":gm/data/bootstrap.min.js"); - m_jsObject->setSettingsFile(m_settingsPath + "extensions.ini"); + m_jsObject->setSettingsFile(m_settingsPath + QL1S("/extensions.ini")); } bool GM_Manager::canRunOnScheme(const QString &scheme) diff --git a/src/plugins/GreaseMonkey/gm_plugin.cpp b/src/plugins/GreaseMonkey/gm_plugin.cpp index 9b6e9c6bd..e3524854d 100644 --- a/src/plugins/GreaseMonkey/gm_plugin.cpp +++ b/src/plugins/GreaseMonkey/gm_plugin.cpp @@ -41,7 +41,7 @@ PluginSpec GM_Plugin::pluginSpec() spec.name = "GreaseMonkey"; spec.info = "Userscripts for QupZilla"; spec.description = "Provides support for userscripts (www.userscripts.org)"; - spec.version = "0.4.3"; + spec.version = "0.4.4"; spec.author = "David Rosca "; spec.icon = QPixmap(":gm/data/icon.png"); spec.hasSettings = true;