]> git.sur5r.net Git - minitube/blobdiff - src/jsfunctions.cpp
Imported Upstream version 2.5.1
[minitube] / src / jsfunctions.cpp
index 0d39dfbf5bc8e6774c393919d22941b4d60043c3..67077ef720c83212b7c59213cbc2300fc15adee5 100644 (file)
@@ -20,8 +20,9 @@ $END_LICENSE */
 
 #include "jsfunctions.h"
 #include "networkaccess.h"
-#include <QDesktopServices>
 #include "constants.h"
+#include "compatibility/qurlqueryhelper.h"
+#include "compatibility/pathsservice.h"
 
 namespace The {
 NetworkAccess* http();
@@ -64,18 +65,16 @@ QString JsFunctions::jsFilename() {
 }
 
 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*)));
@@ -86,6 +85,10 @@ void JsFunctions::gotJs(const QByteArray &bytes) {
         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();