0000952: Download manager

This commit is contained in:
wmayer
2013-05-29 12:38:01 +02:00
parent effdd7dca8
commit 09e2f6bee6
3 changed files with 47 additions and 2 deletions

View File

@@ -26,7 +26,9 @@
#include <math.h>
#include <QAuthenticator>
#include <QContextMenuEvent>
#include <QFileInfo>
#include <QMenu>
#include <QNetworkDiskCache>
#include <QNetworkRequest>
#include <QNetworkProxy>
@@ -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);
}
}

View File

@@ -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();

View File

@@ -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<QUrl> urls = data->urls();
for (QList<QUrl>::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<QUrl>& 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);
}