mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Hopefully fixed one crash and one possible crash in download manager
This commit is contained in:
parent
d699f4b32b
commit
8e29818bb3
Binary file not shown.
@ -134,7 +134,8 @@ SOURCES += main.cpp\
|
|||||||
preferences/thememanager.cpp \
|
preferences/thememanager.cpp \
|
||||||
network/qupzillaschemehandler.cpp \
|
network/qupzillaschemehandler.cpp \
|
||||||
tools/globalfunctions.cpp \
|
tools/globalfunctions.cpp \
|
||||||
other/pagescreen.cpp
|
other/pagescreen.cpp \
|
||||||
|
downloads/downloadfilehelper.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
3rdparty/qtwin.h \
|
3rdparty/qtwin.h \
|
||||||
@ -229,7 +230,8 @@ HEADERS += \
|
|||||||
preferences/thememanager.h \
|
preferences/thememanager.h \
|
||||||
network/qupzillaschemehandler.h \
|
network/qupzillaschemehandler.h \
|
||||||
tools/globalfunctions.h \
|
tools/globalfunctions.h \
|
||||||
other/pagescreen.h
|
other/pagescreen.h \
|
||||||
|
downloads/downloadfilehelper.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
preferences/autofillmanager.ui \
|
preferences/autofillmanager.ui \
|
||||||
@ -294,3 +296,5 @@ win32:LIBS += User32.lib Ole32.lib Shell32.lib ShlWapi.lib Gdi32.lib ComCtl32.li
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
||||||
<meta http-equiv="Content-Language" content="en-us" />
|
|
||||||
<title>CSS Rounded Corners + Liquid + Images</title>
|
|
||||||
<meta name="description" content="css rounded corners" />
|
|
||||||
<meta name="keywords" content="Search Engine Optimization,Internet Marketing,Website Promotion,SEO,SEO Articles,Web Site Promotion,Search Engine Marketing" />
|
|
||||||
<style type="text/css">
|
|
||||||
.cssbox, .cssbox_body, .cssbox_head, .cssbox_head h2{
|
|
||||||
background: transparent url(box-border.png) no-repeat bottom right}
|
|
||||||
.cssbox{
|
|
||||||
width:335px !important;
|
|
||||||
width: 320px;
|
|
||||||
padding-right:15px;
|
|
||||||
margin:20px auto}
|
|
||||||
|
|
||||||
.cssbox_head{background-position:top right;
|
|
||||||
margin-right:-15px;
|
|
||||||
padding-right:40px}
|
|
||||||
|
|
||||||
.cssbox_head h2{
|
|
||||||
background-position:top left;
|
|
||||||
margin:0;
|
|
||||||
border:0;
|
|
||||||
padding:25px 0 15px 40px;
|
|
||||||
height:auto !important;}
|
|
||||||
|
|
||||||
.cssbox_body{
|
|
||||||
background-position:bottom left;
|
|
||||||
margin-right:25px;
|
|
||||||
padding:15px 0 15px 40px}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="cssbox">
|
|
||||||
<div class="cssbox_head">
|
|
||||||
<h2>This is a header</h2>
|
|
||||||
</div>
|
|
||||||
<div class="cssbox_body">
|
|
||||||
<p>This is for your content.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
190
src/downloads/downloadfilehelper.cpp
Normal file
190
src/downloads/downloadfilehelper.cpp
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
#include "downloadfilehelper.h"
|
||||||
|
#include "webpage.h"
|
||||||
|
#include "webview.h"
|
||||||
|
#include "downloadoptionsdialog.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "qupzilla.h"
|
||||||
|
#include "downloaditem.h"
|
||||||
|
#include "downloadmanager.h"
|
||||||
|
|
||||||
|
DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog)
|
||||||
|
: QObject()
|
||||||
|
, m_lastDownloadPath(lastDownloadPath)
|
||||||
|
, m_downloadPath(downloadPath)
|
||||||
|
, m_useNativeDialog(useNativeDialog)
|
||||||
|
, m_reply(0)
|
||||||
|
, m_openFileChoosed(false)
|
||||||
|
, m_iconProvider(new QFileIconProvider)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//// Getting where to download requested file
|
||||||
|
//// in 3 functions, as we are using non blocking
|
||||||
|
//// dialogs ( this is important to make secure downloading
|
||||||
|
//// on windows working properly )
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo)
|
||||||
|
{
|
||||||
|
m_timer = new QTime();
|
||||||
|
m_timer->start();
|
||||||
|
m_h_fileName = getFileName(reply);
|
||||||
|
m_reply = reply;
|
||||||
|
|
||||||
|
QFileInfo info(reply->url().toString());
|
||||||
|
QTemporaryFile tempFile("XXXXXX."+info.suffix());
|
||||||
|
tempFile.open();
|
||||||
|
QFileInfo tempInfo(tempFile.fileName());
|
||||||
|
m_fileIcon = m_iconProvider->icon(tempInfo).pixmap(30,30);
|
||||||
|
QString mimeType = m_iconProvider->type(tempInfo);
|
||||||
|
|
||||||
|
//Get Download Page and Close Empty Tab
|
||||||
|
QNetworkRequest request = m_reply->request();
|
||||||
|
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
||||||
|
WebPage* webPage = (WebPage*)(v.value<void*>());
|
||||||
|
if (webPage) {
|
||||||
|
if (!webPage->mainFrame()->url().isEmpty())
|
||||||
|
m_downloadPage = webPage->mainFrame()->url();
|
||||||
|
else if (webPage->history()->canGoBack())
|
||||||
|
m_downloadPage = webPage->history()->backItem().url();
|
||||||
|
else if (webPage->history()->count() == 0)
|
||||||
|
webPage->getView()->closeTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (askWhatToDo) {
|
||||||
|
DownloadOptionsDialog* dialog = new DownloadOptionsDialog(m_h_fileName, m_fileIcon, mimeType, reply->url(), mApp->activeWindow());
|
||||||
|
dialog->show();
|
||||||
|
connect(dialog, SIGNAL(dialogFinished(int)), this, SLOT(optionsDialogAccepted(int)));
|
||||||
|
} else
|
||||||
|
optionsDialogAccepted(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFileHelper::optionsDialogAccepted(int finish)
|
||||||
|
{
|
||||||
|
m_openFileChoosed = false;
|
||||||
|
switch (finish) {
|
||||||
|
case 0: //Cancelled
|
||||||
|
if (m_timer)
|
||||||
|
delete m_timer;
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case 1: //Open
|
||||||
|
m_openFileChoosed = true;
|
||||||
|
break;
|
||||||
|
case 2: //Save
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_openFileChoosed) {
|
||||||
|
if (m_downloadPath.isEmpty()) {
|
||||||
|
if (m_useNativeDialog) {
|
||||||
|
fileNameChoosed(QFileDialog::getSaveFileName(mApp->getWindow(), tr("Save file as..."), m_lastDownloadPath + m_h_fileName));
|
||||||
|
} else {
|
||||||
|
QFileDialog* dialog = new QFileDialog(mApp->getWindow());
|
||||||
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
dialog->setWindowTitle(tr("Save file as..."));
|
||||||
|
dialog->setDirectory(m_lastDownloadPath);
|
||||||
|
dialog->selectFile(m_h_fileName);
|
||||||
|
dialog->show();
|
||||||
|
connect(dialog, SIGNAL(fileSelected(QString)), this, SLOT(fileNameChoosed(QString)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fileNameChoosed(m_downloadPath + m_h_fileName, true);
|
||||||
|
} else
|
||||||
|
fileNameChoosed(QDir::tempPath() + "/" + m_h_fileName, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFileHelper::fileNameChoosed(const QString &name, bool fileNameAutoGenerated)
|
||||||
|
{
|
||||||
|
m_userFileName = name;
|
||||||
|
if (m_userFileName.isEmpty()) {
|
||||||
|
m_reply->abort();
|
||||||
|
if (m_timer)
|
||||||
|
delete m_timer;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = m_userFileName.lastIndexOf("/");
|
||||||
|
if (pos != -1) {
|
||||||
|
int size = m_userFileName.size();
|
||||||
|
m_path = m_userFileName.left(pos+1);
|
||||||
|
m_fileName = m_userFileName.right(size-pos-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileNameAutoGenerated && QFile::exists(m_userFileName)) {
|
||||||
|
QString _tmpFileName = m_fileName;
|
||||||
|
int i = 1;
|
||||||
|
while (QFile::exists(m_path + "/" + _tmpFileName)) {
|
||||||
|
_tmpFileName = m_fileName;
|
||||||
|
int index = _tmpFileName.lastIndexOf(".");
|
||||||
|
|
||||||
|
if (index == -1) {
|
||||||
|
_tmpFileName.append("("+QString::number(i)+")");
|
||||||
|
} else {
|
||||||
|
_tmpFileName = _tmpFileName.mid(0, index) + "("+QString::number(i)+")" + _tmpFileName.mid(index);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
m_fileName = _tmpFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_path.contains(QDir::tempPath()))
|
||||||
|
m_lastDownloadPath = m_path;
|
||||||
|
|
||||||
|
QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat);
|
||||||
|
settings.beginGroup("DownloadManager");
|
||||||
|
settings.setValue("lastDownloadPath", m_lastDownloadPath);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
QListWidgetItem* item = new QListWidgetItem(m_listWidget);
|
||||||
|
DownloadItem* downItem = new DownloadItem(item, m_reply, m_path, m_fileName, m_fileIcon, m_timer, m_openFileChoosed, m_downloadPage);
|
||||||
|
|
||||||
|
emit itemCreated(item, downItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//// End here
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
QString DownloadFileHelper::getFileName(QNetworkReply* reply)
|
||||||
|
{
|
||||||
|
QString path;
|
||||||
|
if (reply->hasRawHeader("Content-Disposition")) {
|
||||||
|
QString value = reply->rawHeader("Content-Disposition");
|
||||||
|
int pos = value.indexOf("filename=");
|
||||||
|
if (pos!=-1) {
|
||||||
|
QString name = value.mid(pos + 9);
|
||||||
|
if (name.startsWith('"') && name.endsWith('"'))
|
||||||
|
name = name.mid(1, name.size() - 2);
|
||||||
|
path = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (path.isEmpty())
|
||||||
|
path = reply->url().path();
|
||||||
|
|
||||||
|
QFileInfo info(path);
|
||||||
|
QString baseName = info.completeBaseName();
|
||||||
|
QString endName = info.suffix();
|
||||||
|
|
||||||
|
if (baseName.isEmpty()) {
|
||||||
|
baseName = tr("NoNameDownload");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!endName.isEmpty())
|
||||||
|
endName="."+endName;
|
||||||
|
|
||||||
|
QString name = baseName+endName;
|
||||||
|
if (name.startsWith("\""))
|
||||||
|
name = name.mid(1);
|
||||||
|
if (name.endsWith("\";"))
|
||||||
|
name.remove("\";");
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadFileHelper::~DownloadFileHelper()
|
||||||
|
{
|
||||||
|
delete m_iconProvider;
|
||||||
|
}
|
54
src/downloads/downloadfilehelper.h
Normal file
54
src/downloads/downloadfilehelper.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#ifndef DOWNLOADFILEHELPER_H
|
||||||
|
#define DOWNLOADFILEHELPER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTime>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QTemporaryFile>
|
||||||
|
#include <QFileIconProvider>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
|
class DownloadItem;
|
||||||
|
class DownloadFileHelper : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog);
|
||||||
|
~DownloadFileHelper();
|
||||||
|
|
||||||
|
void setListWidget(QListWidget* tw) { m_listWidget = tw; }
|
||||||
|
void handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void itemCreated(QListWidgetItem* item, DownloadItem* downItem);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void optionsDialogAccepted(int finish);
|
||||||
|
void fileNameChoosed(const QString &name, bool fileNameAutoGenerated = false);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString getFileName(QNetworkReply* reply);
|
||||||
|
|
||||||
|
QString m_lastDownloadPath;
|
||||||
|
QString m_downloadPath;
|
||||||
|
bool m_useNativeDialog;
|
||||||
|
|
||||||
|
QTime* m_timer;
|
||||||
|
QString m_path;
|
||||||
|
QString m_fileName;
|
||||||
|
QString m_userFileName;
|
||||||
|
QString m_h_fileName;
|
||||||
|
QNetworkReply* m_reply;
|
||||||
|
QPixmap m_fileIcon;
|
||||||
|
QUrl m_downloadPage;
|
||||||
|
bool m_openFileChoosed;
|
||||||
|
|
||||||
|
QListWidget* m_listWidget;
|
||||||
|
QFileIconProvider* m_iconProvider;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DOWNLOADFILEHELPER_H
|
@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
//#define DOWNMANAGER_DEBUG
|
//#define DOWNMANAGER_DEBUG
|
||||||
|
|
||||||
DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString path, QString fileName, QPixmap fileIcon, QTime* timer, bool openAfterFinishedDownload, QWidget* parent)
|
DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QString &path, const QString &fileName, const QPixmap &fileIcon, QTime* timer, bool openAfterFinishedDownload, const QUrl &downloadPage)
|
||||||
: QWidget(parent)
|
: QWidget()
|
||||||
, ui(new Ui::DownloadItem)
|
, ui(new Ui::DownloadItem)
|
||||||
, m_item(item)
|
, m_item(item)
|
||||||
, m_reply(reply)
|
, m_reply(reply)
|
||||||
@ -34,7 +34,7 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString
|
|||||||
, m_fileName(fileName)
|
, m_fileName(fileName)
|
||||||
, m_downTimer(timer)
|
, m_downTimer(timer)
|
||||||
, m_downUrl(reply->url())
|
, m_downUrl(reply->url())
|
||||||
,m_downloadPage(QUrl())
|
, m_downloadPage(downloadPage)
|
||||||
, m_downloading(false)
|
, m_downloading(false)
|
||||||
, m_openAfterFinish(openAfterFinishedDownload)
|
, m_openAfterFinish(openAfterFinishedDownload)
|
||||||
{
|
{
|
||||||
@ -85,19 +85,6 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString
|
|||||||
error(m_reply->error());
|
error(m_reply->error());
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
|
|
||||||
//Get Download Page
|
|
||||||
QNetworkRequest request = m_reply->request();
|
|
||||||
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
|
||||||
WebPage* webPage = (WebPage*)(v.value<void*>());
|
|
||||||
if (webPage) {
|
|
||||||
if (!webPage->mainFrame()->url().isEmpty())
|
|
||||||
m_downloadPage = webPage->mainFrame()->url();
|
|
||||||
else if (webPage->history()->canGoBack())
|
|
||||||
m_downloadPage = webPage->history()->backItem().url();
|
|
||||||
// else if (webPage->history()->count() == 0)
|
|
||||||
// webPage->getView()->closeTab();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadItem::parentResized(const QSize &size)
|
void DownloadItem::parentResized(const QSize &size)
|
||||||
|
@ -42,7 +42,7 @@ class DownloadItem : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString path, QString fileName, QPixmap fileIcon, QTime* timer, bool openAfterFinishedDownload, QWidget* parent = 0);
|
explicit DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QString &path, const QString &fileName, const QPixmap &fileIcon, QTime* timer, bool openAfterFinishedDownload, const QUrl &downloadPage);
|
||||||
bool isDownloading() { return m_downloading; }
|
bool isDownloading() { return m_downloading; }
|
||||||
bool isCancelled();
|
bool isCancelled();
|
||||||
QTime remainingTime() { return m_remTime; }
|
QTime remainingTime() { return m_remTime; }
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "desktopnotificationsfactory.h"
|
#include "desktopnotificationsfactory.h"
|
||||||
#include "globalfunctions.h"
|
#include "globalfunctions.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
|
#include "downloadfilehelper.h"
|
||||||
|
|
||||||
DownloadManager::DownloadManager(QWidget* parent) :
|
DownloadManager::DownloadManager(QWidget* parent) :
|
||||||
QWidget(parent)
|
QWidget(parent)
|
||||||
@ -41,7 +42,6 @@ DownloadManager::DownloadManager(QWidget* parent) :
|
|||||||
ui->clearButton->setIcon(QIcon::fromTheme("edit-clear"));
|
ui->clearButton->setIcon(QIcon::fromTheme("edit-clear"));
|
||||||
qz_centerWidgetOnScreen(this);
|
qz_centerWidgetOnScreen(this);
|
||||||
|
|
||||||
m_iconProvider = new QFileIconProvider();
|
|
||||||
m_networkManager = mApp->networkManager();
|
m_networkManager = mApp->networkManager();
|
||||||
|
|
||||||
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearList()));
|
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearList()));
|
||||||
@ -154,140 +154,27 @@ void DownloadManager::download(const QNetworkRequest &request, bool askWhatToDo)
|
|||||||
handleUnsupportedContent(m_networkManager->get(request), askWhatToDo);
|
handleUnsupportedContent(m_networkManager->get(request), askWhatToDo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//// Getting where to download requested file
|
|
||||||
//// in 3 functions, as we are using non blocking
|
|
||||||
//// dialogs ( this is important to make secured downloading
|
|
||||||
//// on windows working properly )
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo)
|
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo)
|
||||||
{
|
{
|
||||||
m_htimer = new QTime();
|
DownloadFileHelper* h = new DownloadFileHelper(m_lastDownloadPath, m_downloadPath, m_useNativeDialog);
|
||||||
m_htimer->start();
|
h->setListWidget(ui->list);
|
||||||
m_h_fileName = getFileName(reply);
|
h->handleUnsupportedContent(reply, askWhatToDo);
|
||||||
m_hreply = reply;
|
|
||||||
|
|
||||||
QFileInfo info(reply->url().toString());
|
connect(h, SIGNAL(itemCreated(QListWidgetItem*,DownloadItem*)), this, SLOT(itemCreated(QListWidgetItem*,DownloadItem*)));
|
||||||
QTemporaryFile tempFile("XXXXXX."+info.suffix());
|
|
||||||
tempFile.open();
|
|
||||||
QFileInfo tempInfo(tempFile.fileName());
|
|
||||||
m_hfileIcon = m_iconProvider->icon(tempInfo).pixmap(30,30);
|
|
||||||
QString mimeType = m_iconProvider->type(tempInfo);
|
|
||||||
|
|
||||||
//Get Download Page and Close Empty Tab
|
|
||||||
QNetworkRequest request = m_hreply->request();
|
|
||||||
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
|
||||||
WebPage* webPage = (WebPage*)(v.value<void*>());
|
|
||||||
if (webPage && webPage->mainFrame()->url().isEmpty() && !webPage->history()->canGoBack() && webPage->history()->count() == 0)
|
|
||||||
webPage->getView()->closeTab();
|
|
||||||
|
|
||||||
if (askWhatToDo) {
|
|
||||||
DownloadOptionsDialog* dialog = new DownloadOptionsDialog(m_h_fileName, m_hfileIcon, mimeType, reply->url(), mApp->activeWindow());
|
|
||||||
dialog->show();
|
|
||||||
connect(dialog, SIGNAL(dialogFinished(int)), this, SLOT(optionsDialogAccepted(int)));
|
|
||||||
} else
|
|
||||||
optionsDialogAccepted(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadManager::optionsDialogAccepted(int finish)
|
void DownloadManager::itemCreated(QListWidgetItem *item, DownloadItem *downItem)
|
||||||
{
|
{
|
||||||
m_hOpenFileChoosed = false;
|
downItem->setParent(this);
|
||||||
switch (finish) {
|
|
||||||
case 0: //Cancelled
|
|
||||||
if (m_htimer)
|
|
||||||
delete m_htimer;
|
|
||||||
return;
|
|
||||||
break;
|
|
||||||
case 1: //Open
|
|
||||||
m_hOpenFileChoosed = true;
|
|
||||||
break;
|
|
||||||
case 2: //Save
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_hOpenFileChoosed) {
|
|
||||||
if (m_downloadPath.isEmpty()) {
|
|
||||||
if (m_useNativeDialog) {
|
|
||||||
fileNameChoosed(QFileDialog::getSaveFileName(mApp->getWindow(), tr("Save file as..."), m_lastDownloadPath + m_h_fileName));
|
|
||||||
} else {
|
|
||||||
QFileDialog* dialog = new QFileDialog(mApp->getWindow());
|
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
dialog->setWindowTitle(tr("Save file as..."));
|
|
||||||
dialog->setDirectory(m_lastDownloadPath);
|
|
||||||
dialog->selectFile(m_h_fileName);
|
|
||||||
dialog->show();
|
|
||||||
connect(dialog, SIGNAL(fileSelected(QString)), this, SLOT(fileNameChoosed(QString)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fileNameChoosed(m_downloadPath + m_h_fileName, true);
|
|
||||||
} else
|
|
||||||
fileNameChoosed(QDir::tempPath() + "/" + m_h_fileName, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownloadManager::fileNameChoosed(const QString &name, bool fileNameAutoGenerated)
|
|
||||||
{
|
|
||||||
m_huserFileName = name;
|
|
||||||
if (m_huserFileName.isEmpty()) {
|
|
||||||
m_hreply->abort();
|
|
||||||
if (m_htimer)
|
|
||||||
delete m_htimer;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pos = m_huserFileName.lastIndexOf("/");
|
|
||||||
if (pos != -1) {
|
|
||||||
int size = m_huserFileName.size();
|
|
||||||
m_hpath = m_huserFileName.left(pos+1);
|
|
||||||
m_hfileName = m_huserFileName.right(size-pos-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileNameAutoGenerated && QFile::exists(m_huserFileName)) {
|
|
||||||
QString _tmpFileName = m_hfileName;
|
|
||||||
int i = 1;
|
|
||||||
while (QFile::exists(m_hpath + "/" + _tmpFileName)) {
|
|
||||||
_tmpFileName = m_hfileName;
|
|
||||||
int index = _tmpFileName.lastIndexOf(".");
|
|
||||||
|
|
||||||
if (index == -1) {
|
|
||||||
_tmpFileName.append("("+QString::number(i)+")");
|
|
||||||
} else {
|
|
||||||
_tmpFileName = _tmpFileName.mid(0, index) + "("+QString::number(i)+")" + _tmpFileName.mid(index);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
m_hfileName = _tmpFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_hpath.contains(QDir::tempPath()))
|
|
||||||
m_lastDownloadPath = m_hpath;
|
|
||||||
|
|
||||||
QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat);
|
|
||||||
settings.beginGroup("DownloadManager");
|
|
||||||
settings.setValue("lastDownloadPath",m_lastDownloadPath);
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
QListWidgetItem* item = new QListWidgetItem(ui->list);
|
|
||||||
DownloadItem* downItem = new DownloadItem(item, m_hreply, m_hpath, m_hfileName, m_hfileIcon, m_htimer, m_hOpenFileChoosed, this);
|
|
||||||
connect(downItem, SIGNAL(deleteItem(DownloadItem*)), this, SLOT(deleteItem(DownloadItem*)));
|
connect(downItem, SIGNAL(deleteItem(DownloadItem*)), this, SLOT(deleteItem(DownloadItem*)));
|
||||||
connect(downItem, SIGNAL(downloadFinished(bool)), this, SLOT(downloadFinished(bool)));
|
connect(downItem, SIGNAL(downloadFinished(bool)), this, SLOT(downloadFinished(bool)));
|
||||||
|
|
||||||
ui->list->setItemWidget(item, downItem);
|
ui->list->setItemWidget(item, downItem);
|
||||||
item->setSizeHint(downItem->sizeHint());
|
item->setSizeHint(downItem->sizeHint());
|
||||||
|
|
||||||
show();
|
show();
|
||||||
activateWindow();
|
activateWindow();
|
||||||
|
|
||||||
//Negating all used variables
|
|
||||||
m_hpath.clear();
|
|
||||||
m_hfileName.clear();
|
|
||||||
m_huserFileName.clear();
|
|
||||||
m_h_fileName.clear();
|
|
||||||
m_hreply = 0;
|
|
||||||
m_hfileIcon = QPixmap();
|
|
||||||
m_hOpenFileChoosed = false;
|
|
||||||
}
|
}
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//// End here
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void DownloadManager::downloadFinished(bool success)
|
void DownloadManager::downloadFinished(bool success)
|
||||||
{
|
{
|
||||||
@ -322,42 +209,6 @@ void DownloadManager::deleteItem(DownloadItem* item)
|
|||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DownloadManager::getFileName(QNetworkReply* reply)
|
|
||||||
{
|
|
||||||
QString path;
|
|
||||||
if (reply->hasRawHeader("Content-Disposition")) {
|
|
||||||
QString value = reply->rawHeader("Content-Disposition");
|
|
||||||
int pos = value.indexOf("filename=");
|
|
||||||
if (pos!=-1) {
|
|
||||||
QString name = value.mid(pos + 9);
|
|
||||||
if (name.startsWith('"') && name.endsWith('"'))
|
|
||||||
name = name.mid(1, name.size() - 2);
|
|
||||||
path = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (path.isEmpty())
|
|
||||||
path = reply->url().path();
|
|
||||||
|
|
||||||
QFileInfo info(path);
|
|
||||||
QString baseName = info.completeBaseName();
|
|
||||||
QString endName = info.suffix();
|
|
||||||
|
|
||||||
if (baseName.isEmpty()) {
|
|
||||||
baseName = tr("NoNameDownload");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!endName.isEmpty())
|
|
||||||
endName="."+endName;
|
|
||||||
|
|
||||||
QString name = baseName+endName;
|
|
||||||
if (name.startsWith("\""))
|
|
||||||
name = name.mid(1);
|
|
||||||
if (name.endsWith("\";"))
|
|
||||||
name.remove("\";");
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DownloadManager::canClose()
|
bool DownloadManager::canClose()
|
||||||
{
|
{
|
||||||
if (m_isClosing)
|
if (m_isClosing)
|
||||||
@ -398,5 +249,4 @@ DownloadManager::~DownloadManager()
|
|||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
delete m_networkManager;
|
delete m_networkManager;
|
||||||
delete m_iconProvider;
|
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,10 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QFileIconProvider>
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTime>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
@ -34,6 +31,7 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QListWidgetItem>
|
||||||
|
|
||||||
#include "ecwin7.h"
|
#include "ecwin7.h"
|
||||||
|
|
||||||
@ -68,12 +66,10 @@ protected:
|
|||||||
private slots:
|
private slots:
|
||||||
void clearList();
|
void clearList();
|
||||||
void deleteItem(DownloadItem* item);
|
void deleteItem(DownloadItem* item);
|
||||||
|
|
||||||
|
void itemCreated(QListWidgetItem* item, DownloadItem* downItem);
|
||||||
void downloadFinished(bool success);
|
void downloadFinished(bool success);
|
||||||
|
|
||||||
|
|
||||||
void optionsDialogAccepted(int finish);
|
|
||||||
void fileNameChoosed(const QString &name, bool fileNameAutoGenerated = false);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void resized(QSize);
|
void resized(QSize);
|
||||||
|
|
||||||
@ -82,31 +78,17 @@ private:
|
|||||||
EcWin7 win7;
|
EcWin7 win7;
|
||||||
#endif
|
#endif
|
||||||
void timerEvent(QTimerEvent* event);
|
void timerEvent(QTimerEvent* event);
|
||||||
QString getFileName(QNetworkReply* reply);
|
|
||||||
void closeEvent(QCloseEvent* e);
|
void closeEvent(QCloseEvent* e);
|
||||||
void resizeEvent(QResizeEvent *e);
|
void resizeEvent(QResizeEvent *e);
|
||||||
|
|
||||||
Ui::DownloadManager* ui;
|
Ui::DownloadManager* ui;
|
||||||
NetworkManager* m_networkManager;
|
NetworkManager* m_networkManager;
|
||||||
QFileIconProvider* m_iconProvider;
|
QBasicTimer m_timer;
|
||||||
|
|
||||||
QString m_lastDownloadPath;
|
QString m_lastDownloadPath;
|
||||||
QString m_downloadPath;
|
QString m_downloadPath;
|
||||||
bool m_useNativeDialog;
|
bool m_useNativeDialog;
|
||||||
|
|
||||||
QBasicTimer m_timer;
|
|
||||||
|
|
||||||
bool m_isClosing;
|
bool m_isClosing;
|
||||||
|
|
||||||
// Variables used by HandleUnsupportContent:
|
|
||||||
QTime* m_htimer;
|
|
||||||
QString m_hpath;
|
|
||||||
QString m_hfileName;
|
|
||||||
QString m_huserFileName;
|
|
||||||
QString m_h_fileName;
|
|
||||||
QNetworkReply* m_hreply;
|
|
||||||
QPixmap m_hfileIcon;
|
|
||||||
bool m_hOpenFileChoosed;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DOWNLOADMANAGER_H
|
#endif // DOWNLOADMANAGER_H
|
||||||
|
@ -23,18 +23,9 @@
|
|||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="leftMargin">
|
<property name="margin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>4</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="list">
|
<widget class="QListWidget" name="list">
|
||||||
<property name="horizontalScrollBarPolicy">
|
<property name="horizontalScrollBarPolicy">
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#include "downloadoptionsdialog.h"
|
#include "downloadoptionsdialog.h"
|
||||||
#include "ui_downloadoptionsdialog.h"
|
#include "ui_downloadoptionsdialog.h"
|
||||||
|
|
||||||
DownloadOptionsDialog::DownloadOptionsDialog(QString fileName, QPixmap fileIcon, QString mimeType, QUrl url, QWidget *parent)
|
DownloadOptionsDialog::DownloadOptionsDialog(const QString &fileName, const QPixmap &fileIcon, const QString &mimeType, const QUrl &url, QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, ui(new Ui::DownloadOptionsDialog)
|
, ui(new Ui::DownloadOptionsDialog)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@ class DownloadOptionsDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DownloadOptionsDialog(QString fileName, QPixmap fileIcon, QString mimeType, QUrl url, QWidget* parent = 0);
|
explicit DownloadOptionsDialog(const QString &fileName, const QPixmap &fileIcon, const QString &mimeType, const QUrl &url, QWidget* parent = 0);
|
||||||
~DownloadOptionsDialog();
|
~DownloadOptionsDialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -1035,7 +1035,7 @@ nebyl nalezen!</translation>
|
|||||||
<translation>Správce stahování</translation>
|
<translation>Správce stahování</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/downloads/downloadmanager.ui" line="82"/>
|
<location filename="../src/downloads/downloadmanager.ui" line="73"/>
|
||||||
<source>Clear</source>
|
<source>Clear</source>
|
||||||
<translation>Vyčistit</translation>
|
<translation>Vyčistit</translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -1038,7 +1038,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<translation>Správca sťahovania</translation>
|
<translation>Správca sťahovania</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/downloads/downloadmanager.ui" line="82"/>
|
<location filename="../src/downloads/downloadmanager.ui" line="73"/>
|
||||||
<source>Clear</source>
|
<source>Clear</source>
|
||||||
<translation>Vyčistiť</translation>
|
<translation>Vyčistiť</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -1063,7 +1063,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<message>
|
<message>
|
||||||
<location filename="../src/downloads/downloadoptionsdialog.ui" line="107"/>
|
<location filename="../src/downloads/downloadoptionsdialog.ui" line="107"/>
|
||||||
<source>What should QupZilla do with this file?</source>
|
<source>What should QupZilla do with this file?</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation>Čo by mala QupZilla urobiť s tímto súborom?</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/downloads/downloadoptionsdialog.ui" line="32"/>
|
<location filename="../src/downloads/downloadoptionsdialog.ui" line="32"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user