X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fdownloadmanager.cpp;h=6944e1639f77c87d4c9374fb66970c795160ac41;hb=3c8c537559e6bef5f019196b0989e95863ddd3ee;hp=36ede9bf384930b10bf2aa82affc8229b5ddc7ed;hpb=7b529d6a918efe39ca6d63201fcdb954a3c881b4;p=minitube diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 36ede9b..6944e16 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -3,10 +3,11 @@ #include "downloadmodel.h" #include "video.h" #include "constants.h" +#include "MainWindow.h" static DownloadManager *downloadManagerInstance = 0; -DownloadManager::DownloadManager(QObject *parent) : +DownloadManager::DownloadManager(QWidget *parent) : QObject(parent), downloadModel(new DownloadModel(this, this)) { } @@ -39,30 +40,31 @@ DownloadItem* DownloadManager::itemForVideo(Video* video) { void DownloadManager::addItem(Video *video) { // qDebug() << __FUNCTION__ << video->title(); - + #ifdef APP_DEMO if (video->duration() >= 60*4) { - QMessageBox msgBox; + 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::APP_NAME)); + 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); - QPushButton *quitButton = msgBox.addButton(tr("Continue"), QMessageBox::RejectRole); + 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(QString(Constants::WEBSITE) + "#download"); + QDesktopServices::openUrl(QUrl(QString(Constants::WEBSITE) + "#download")); } return; } #endif - DownloadItem *item = itemForVideo(video); if (item != 0) { @@ -96,11 +98,20 @@ void DownloadManager::gotStreamUrl(QUrl url) { QString path = currentDownloadFolder(); // TODO ensure all chars are filename compatible - QString basename = video->title().simplified(); + 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.replace('?', ' '); + basename.replace('*', ' '); + basename = basename.simplified(); + QString filename = path + "/" + basename + ".mp4"; Video *videoCopy = video->clone(); @@ -134,6 +145,12 @@ QString DownloadManager::defaultDownloadFolder() { if (!moviesDir.exists()) { // fallback to Desktop path = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); + + QDir desktopDir(path); + if (!desktopDir.exists()) { + // fallback to Home + path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation); + } } return path; }