]> git.sur5r.net Git - minitube/blobdiff - src/downloadmanager.cpp
Merge tag 'upstream/2.4'
[minitube] / src / downloadmanager.cpp
index 21115d3ceab2fd759b344e10080ad7366a67696d..340b8d6a9a159e48b2d2edbf86b8aa716f776ddf 100644 (file)
@@ -1,3 +1,23 @@
+/* $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"
@@ -7,9 +27,10 @@
 #ifdef APP_ACTIVATION
 #include "activation.h"
 #endif
-#ifdef Q_WS_MAC
-#include "macutils.h"
+#ifdef APP_EXTRA
+#include "extra.h"
 #endif
+#include "datautils.h"
 
 static DownloadManager *downloadManagerInstance = 0;
 
@@ -103,24 +124,10 @@ 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(')', ']');
-    basename.replace('/', ' ');
-    basename.replace('\\', ' ');
-    basename.replace('<', ' ');
-    basename.replace('>', ' ');
-    basename.replace(':', ' ');
-    basename.replace('"', ' ');
-    basename.replace('|', ' ');
-    basename.replace('?', ' ');
-    basename.replace('*', ' ');
-    basename = basename.simplified();
-
-    QString filename = path + "/" + basename + ".mp4";
+    QString basename = DataUtils::stringToFilename(video->title());
+    if (basename.isEmpty()) basename = video->id();
+
+    QString filename = currentDownloadFolder() + "/" + basename + ".mp4";
 
     Video *videoCopy = video->clone();
     DownloadItem *item = new DownloadItem(videoCopy, url, filename, this);
@@ -138,20 +145,18 @@ void DownloadManager::gotStreamUrl(QUrl url) {
 
 void DownloadManager::itemFinished() {
     if (activeItems() == 0) emit finished();
-#ifdef Q_WS_MAC
-    if (mac::canNotify()) {
-        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));
-        mac::notify(tr("Download finished"), video->title(), stats);
+#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);
 #endif
 }
 
@@ -162,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;