#include "jsfunctions.h"
#include "networkaccess.h"
-#include <QDesktopServices>
#include "constants.h"
+#include "compatibility/qurlqueryhelper.h"
+#include "compatibility/pathsservice.h"
namespace The {
NetworkAccess* http();
}
QString JsFunctions::jsPath() {
- return QString(
- #if QT_VERSION >= 0x050000
- QStandardPaths::writableLocation(QStandardPaths::DataLocation)
- #else
- QDesktopServices::storageLocation(QDesktopServices::DataLocation)
- #endif
- + "/" + jsFilename());
+ return Paths::getDataLocation() + "/" + jsFilename();
}
void JsFunctions::loadJs() {
QUrl url(this->url);
- url.addQueryItem("v", Constants::VERSION);
+ {
+ QUrlQueryHelper urlHelper(url);
+ urlHelper.addQueryItem("v", Constants::VERSION);
+ }
+
NetworkReply* reply = The::http()->get(url);
connect(reply, SIGNAL(data(QByteArray)), SLOT(gotJs(QByteArray)));
connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(errorJs(QNetworkReply*)));
qWarning() << "Got empty js";
return;
}
+ if (!QDir().mkpath(Paths::getDataLocation())) {
+ qCritical() << "Failed to create" << Paths::getDataLocation();
+ return;
+ }
QFile file(jsPath());
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << "Cannot write" << file.errorString() << file.fileName();