From 09e2f6bee60c6872ba5ea28e5283bbbef948a95e Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 29 May 2013 12:38:01 +0200 Subject: [PATCH] 0000952: Download manager --- src/Gui/DownloadItem.cpp | 27 +++++++++++++++++++++++++++ src/Gui/DownloadItem.h | 2 ++ src/Gui/MainWindow.cpp | 20 ++++++++++++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Gui/DownloadItem.cpp b/src/Gui/DownloadItem.cpp index 29b14a68bb..a86c5527bc 100644 --- a/src/Gui/DownloadItem.cpp +++ b/src/Gui/DownloadItem.cpp @@ -26,7 +26,9 @@ #include #include +#include #include +#include #include #include #include @@ -289,6 +291,7 @@ void DownloadItem::getFileName() } m_output.setFileName(fileName); fileNameLabel->setText(QFileInfo(m_output.fileName()).fileName()); + fileNameLabel->setToolTip(m_output.fileName()); if (m_requestFileName) downloadReadyRead(); } @@ -359,6 +362,13 @@ void DownloadItem::open() } } +void DownloadItem::openFolder() +{ + QFileInfo info(m_output); + QUrl url = QUrl::fromLocalFile(info.absolutePath()); + QDesktopServices::openUrl(url); +} + void DownloadItem::tryAgain() { if (!tryAgainButton->isEnabled()) @@ -380,6 +390,14 @@ void DownloadItem::tryAgain() /*emit*/ statusChanged(); } +void DownloadItem::contextMenuEvent (QContextMenuEvent * e) +{ + QMenu menu; + QAction* a = menu.addAction(tr("Open containing folder"), this, SLOT(openFolder())); + a->setEnabled(m_output.exists()); + menu.exec(e->globalPos()); +} + void DownloadItem::downloadReadyRead() { if (m_requestFileName && m_output.fileName().isEmpty()) @@ -395,6 +413,7 @@ void DownloadItem::downloadReadyRead() /*emit*/ statusChanged(); return; } + downloadInfoLabel->setToolTip(m_url.toString()); /*emit*/ statusChanged(); } if (-1 == m_output.write(m_reply->readAll())) { @@ -419,12 +438,20 @@ void DownloadItem::metaDataChanged() int index = header.indexOf("filename="); if (index > 0) { header = header.mid(index+9); + if (header.startsWith("\"") || header.startsWith("'")) + header = header.mid(1); + if (header.endsWith("\"") || header.endsWith("'")) + header.chop(1); m_fileName = QUrl::fromPercentEncoding(header); } else { index = header.indexOf("filename*=UTF-8''"); if (index > 0) { header = header.mid(index+17); + if (header.startsWith("\"") || header.startsWith("'")) + header = header.mid(1); + if (header.endsWith("\"") || header.endsWith("'")) + header.chop(1); m_fileName = QUrl::fromPercentEncoding(header); } } diff --git a/src/Gui/DownloadItem.h b/src/Gui/DownloadItem.h index ea828eb439..a357fffe9c 100644 --- a/src/Gui/DownloadItem.h +++ b/src/Gui/DownloadItem.h @@ -127,6 +127,7 @@ private Q_SLOTS: void stop(); void tryAgain(); void open(); + void openFolder(); void downloadReadyRead(); void error(QNetworkReply::NetworkError code); @@ -135,6 +136,7 @@ private Q_SLOTS: void finished(); private: + void contextMenuEvent(QContextMenuEvent *); void getFileName(); void init(); void updateInfoLabel(); diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index a46388adb0..3c003b7ea2 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1401,10 +1401,21 @@ void MainWindow::dragEnterEvent (QDragEnterEvent * e) { // Here we must allow uri drafs and check them in dropEvent const QMimeData* data = e->mimeData(); - if (data->hasUrls()) + if (data->hasUrls()) { +#ifdef QT_NO_OPENSSL + QList urls = data->urls(); + for (QList::ConstIterator it = urls.begin(); it != urls.end(); ++it) { + if (it->scheme().toLower() == QLatin1String("https")) { + e->ignore(); + return; + } + } +#endif e->accept(); - else + } + else { e->ignore(); + } } QMimeData * MainWindow::createMimeDataFromSelection () const @@ -1548,6 +1559,11 @@ void MainWindow::loadUrls(App::Document* doc, const QList& url) else if (it->scheme().toLower() == QLatin1String("http")) { Gui::Dialog::DownloadManager::getInstance()->download(*it); } +#ifndef QT_NO_OPENSSL + else if (it->scheme().toLower() == QLatin1String("https")) { + Gui::Dialog::DownloadManager::getInstance()->download(*it); + } +#endif else if (it->scheme().toLower() == QLatin1String("ftp")) { Gui::Dialog::DownloadManager::getInstance()->download(*it); }