]> git.sur5r.net Git - minitube/blobdiff - src/downloadmanager.cpp
Imported Upstream version 2.3
[minitube] / src / downloadmanager.cpp
index 33d2adacf66371feae05b5679614da3ef7eec4de..340b8d6a9a159e48b2d2edbf86b8aa716f776ddf 100644 (file)
@@ -30,6 +30,7 @@ $END_LICENSE */
 #ifdef APP_EXTRA
 #include "extra.h"
 #endif
+#include "datautils.h"
 
 static DownloadManager *downloadManagerInstance = 0;
 
@@ -123,23 +124,7 @@ void DownloadManager::gotStreamUrl(QUrl url) {
 
     video->disconnect(this);
 
-    QString basename = video->title();
-    basename.replace('(', '[');
-    basename.replace(')', ']');
-    basename.replace('/', ' ');
-    basename.replace('\\', ' ');
-    basename.replace('<', ' ');
-    basename.replace('>', ' ');
-    basename.replace(':', ' ');
-    basename.replace('"', ' ');
-    basename.replace('|', ' ');
-    basename.replace('?', ' ');
-    basename.replace('*', ' ');
-    basename = basename.simplified();
-
-    if (!basename.isEmpty() && basename.at(0) == '.')
-        basename = basename.mid(1).trimmed();
-
+    QString basename = DataUtils::stringToFilename(video->title());
     if (basename.isEmpty()) basename = video->id();
 
     QString filename = currentDownloadFolder() + "/" + basename + ".mp4";
@@ -161,17 +146,17 @@ void DownloadManager::gotStreamUrl(QUrl url) {
 void DownloadManager::itemFinished() {
     if (activeItems() == 0) emit finished();
 #ifdef APP_EXTRA
-        DownloadItem *item = static_cast<DownloadItem*>(sender());
-        if (!item) {
-            qDebug() << "Cannot get item in" << __FUNCTION__;
-            return;
-        }
-        Video *video = item->getVideo();
-        if (!video) return;
-        QString stats = tr("%1 downloaded in %2").arg(
-                    DownloadItem::formattedFilesize(item->bytesTotal()),
-                    DownloadItem::formattedTime(item->totalTime(), false));
-        Extra::notify(tr("Download finished"), video->title(), stats);
+    DownloadItem *item = static_cast<DownloadItem*>(sender());
+    if (!item) {
+        qDebug() << "Cannot get item in" << __FUNCTION__;
+        return;
+    }
+    Video *video = item->getVideo();
+    if (!video) return;
+    QString stats = tr("%1 downloaded in %2").arg(
+                DownloadItem::formattedFilesize(item->bytesTotal()),
+                DownloadItem::formattedTime(item->totalTime(), false));
+    Extra::notify(tr("Download finished"), video->title(), stats);
 #endif
 }
 
@@ -182,16 +167,29 @@ void DownloadManager::updateStatusMessage() {
 
 QString DownloadManager::defaultDownloadFolder() {
     // download in the Movies system folder
+#if QT_VERSION >= 0x050000
+    QString path = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
+#else
     QString path = QDesktopServices::storageLocation(QDesktopServices::MoviesLocation);
+#endif
+
     QDir moviesDir(path);
     if (!moviesDir.exists()) {
         // fallback to Desktop
+#if QT_VERSION >= 0x050000
+        path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
+#else
         path = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
+#endif
 
         QDir desktopDir(path);
         if (!desktopDir.exists()) {
             // fallback to Home
+#if QT_VERSION >= 0x050000
+            path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
+#else
             path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
+#endif
         }
     }
     return path;