]> git.sur5r.net Git - minitube/blobdiff - src/downloadmanager.cpp
Merge tag 'upstream/2.1.5'
[minitube] / src / downloadmanager.cpp
index ee597d899f3ba46ed44f510d17081edaf6a0590e..33d2adacf66371feae05b5679614da3ef7eec4de 100644 (file)
@@ -1,9 +1,35 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
 #include "downloadmanager.h"
 #include "downloaditem.h"
 #include "downloadmodel.h"
 #include "video.h"
 #include "constants.h"
-#include "MainWindow.h"
+#include "mainwindow.h"
+#ifdef APP_ACTIVATION
+#include "activation.h"
+#endif
+#ifdef APP_EXTRA
+#include "extra.h"
+#endif
 
 static DownloadManager *downloadManagerInstance = 0;
 
@@ -41,28 +67,30 @@ DownloadItem* DownloadManager::itemForVideo(Video* video) {
 void DownloadManager::addItem(Video *video) {
     // qDebug() << __FUNCTION__ << video->title();
 
-#ifdef APP_DEMO
-    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) {
-            QDesktopServices::openUrl(QUrl(QString(Constants::WEBSITE) + "#download"));
-        }
+#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);
 
-        return;
+            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
 
@@ -95,9 +123,6 @@ void DownloadManager::gotStreamUrl(QUrl url) {
 
     video->disconnect(this);
 
-    QString path = currentDownloadFolder();
-
-    // TODO ensure all chars are filename compatible
     QString basename = video->title();
     basename.replace('(', '[');
     basename.replace(')', ']');
@@ -112,7 +137,12 @@ void DownloadManager::gotStreamUrl(QUrl url) {
     basename.replace('*', ' ');
     basename = basename.simplified();
 
-    QString filename = path + "/" + basename + ".mp4";
+    if (!basename.isEmpty() && basename.at(0) == '.')
+        basename = basename.mid(1).trimmed();
+
+    if (basename.isEmpty()) basename = video->id();
+
+    QString filename = currentDownloadFolder() + "/" + basename + ".mp4";
 
     Video *videoCopy = video->clone();
     DownloadItem *item = new DownloadItem(videoCopy, url, filename, this);
@@ -130,8 +160,7 @@ void DownloadManager::gotStreamUrl(QUrl url) {
 
 void DownloadManager::itemFinished() {
     if (activeItems() == 0) emit finished();
-#ifdef Q_WS_MAC
-    if (mac::canNotify()) {
+#ifdef APP_EXTRA
         DownloadItem *item = static_cast<DownloadItem*>(sender());
         if (!item) {
             qDebug() << "Cannot get item in" << __FUNCTION__;
@@ -142,13 +171,12 @@ void DownloadManager::itemFinished() {
         QString stats = tr("%1 downloaded in %2").arg(
                     DownloadItem::formattedFilesize(item->bytesTotal()),
                     DownloadItem::formattedTime(item->totalTime(), false));
-        mac::notify(tr("Download finished"), video->title(), stats);
-    }
+        Extra::notify(tr("Download finished"), video->title(), stats);
 #endif
 }
 
 void DownloadManager::updateStatusMessage() {
-    QString message = tr("%n Download(s)", "", items.size());
+    QString message = tr("%n Download(s)", "", activeItems());
     emit statusMessageChanged(message);
 }