]> git.sur5r.net Git - minitube/blobdiff - src/downloadmanager.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / downloadmanager.cpp
index 340b8d6a9a159e48b2d2edbf86b8aa716f776ddf..4ea5d8c7b0a0f789eb137dd738286f1bdac46c7c 100644 (file)
@@ -31,6 +31,7 @@ $END_LICENSE */
 #include "extra.h"
 #endif
 #include "datautils.h"
+#include "iconutils.h"
 
 static DownloadManager *downloadManagerInstance = 0;
 
@@ -52,15 +53,15 @@ void DownloadManager::clear() {
 
 int DownloadManager::activeItems() {
     int num = 0;
-    foreach (DownloadItem *item, items) {
+    for (DownloadItem *item : items) {
         if (item->status() == Downloading || item->status() == Starting) num++;
     }
     return num;
 }
 
 DownloadItem* DownloadManager::itemForVideo(Video* video) {
-    foreach (DownloadItem *item, items) {
-        if (item->getVideo()->id() == video->id()) return item;
+    for (DownloadItem *item : items) {
+        if (item->getVideo()->getId() == video->getId()) return item;
     }
     return 0;
 }
@@ -68,40 +69,13 @@ DownloadItem* DownloadManager::itemForVideo(Video* video) {
 void DownloadManager::addItem(Video *video) {
     // qDebug() << __FUNCTION__ << video->title();
 
-#ifdef APP_ACTIVATION
-    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.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.")
-                        .arg(4));
-            msgBox.setModal(true);
-            // make it a "sheet" on the Mac
-            msgBox.setWindowModality(Qt::WindowModal);
-
-            msgBox.addButton(tr("Continue"), QMessageBox::RejectRole);
-            QPushButton *buyButton = msgBox.addButton(tr("Get the full version"), QMessageBox::ActionRole);
-
-            msgBox.exec();
-
-            if (msgBox.clickedButton() == buyButton) {
-                MainWindow::instance()->showActivationView();
-            }
-
-            return;
-        }
-    }
-#endif
-
     DownloadItem *item = itemForVideo(video);
     if (item != 0) {
         if (item->status() == Failed || item->status() == Idle) {
-            qDebug() << "Restarting download" << video->title();
+            qDebug() << "Restarting download" << video->getTitle();
             item->tryAgain();
         } else {
-            qDebug() << "Already downloading video" << video->title();
+            qDebug() << "Already downloading video" << video->getTitle();
         }
         return;
     }
@@ -124,8 +98,8 @@ void DownloadManager::gotStreamUrl(QUrl url) {
 
     video->disconnect(this);
 
-    QString basename = DataUtils::stringToFilename(video->title());
-    if (basename.isEmpty()) basename = video->id();
+    QString basename = DataUtils::stringToFilename(video->getTitle());
+    if (basename.isEmpty()) basename = video->getId();
 
     QString filename = currentDownloadFolder() + "/" + basename + ".mp4";
 
@@ -156,7 +130,7 @@ void DownloadManager::itemFinished() {
     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);
+    Extra::notify(tr("Download finished"), video->getTitle(), stats);
 #endif
 }
 
@@ -167,29 +141,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
 
-    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
 
-        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
         }
     }
     return path;