]> git.sur5r.net Git - minitube/blobdiff - src/downloadmanager.cpp
2.5.2
[minitube] / src / downloadmanager.cpp
index c42b0746c7029ed1ccbd2ce0249dbb09985a349c..9375bb082f6a4164b6ad6ccf87a6e9e0c95a2580 100644 (file)
@@ -30,6 +30,9 @@ $END_LICENSE */
 #ifdef APP_EXTRA
 #include "extra.h"
 #endif
+#include "datautils.h"
+#include "compatibility/pathsservice.h"
+#include "iconutils.h"
 
 static DownloadManager *downloadManagerInstance = 0;
 
@@ -71,7 +74,7 @@ void DownloadManager::addItem(Video *video) {
     if (!Activation::instance().isActivated()) {
         if (video->duration() >= 60*4) {
             QMessageBox msgBox(MainWindow::instance());
-            msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+            msgBox.setIconPixmap(IconUtils::pixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
             msgBox.setText(tr("This is just the demo version of %1.").arg(Constants::NAME));
             msgBox.setInformativeText(
                         tr("It can only download videos shorter than %1 minutes so you can test the download functionality.")
@@ -123,23 +126,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";
@@ -182,29 +169,17 @@ 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
+    QString path = Paths::getMoviesLocation();
 
-    QDir moviesDir(path);
+    const 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
+        path = Paths::getDesktopLocation();
 
-        QDir desktopDir(path);
+        const 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
+            path = Paths::getHomeLocation();
         }
     }
     return path;