1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

Download manager will now ask if you want or don't want delete file when

stopping download. Also fixed bug when you can close download manager
window when there is no main windows and thus losing your download
This commit is contained in:
nowrep 2011-03-29 19:55:21 +02:00
parent 4b30167998
commit 77b31b8f85
7 changed files with 57 additions and 16 deletions

View File

@ -106,7 +106,8 @@ SOURCES += main.cpp\
adblock/adblocknetwork.cpp \ adblock/adblocknetwork.cpp \
adblock/adblockmanager.cpp \ adblock/adblockmanager.cpp \
adblock/adblockdialog.cpp \ adblock/adblockdialog.cpp \
adblock/adblockblockednetworkreply.cpp adblock/adblockblockednetworkreply.cpp \
adblock/adblockicon.cpp
HEADERS += 3rdparty/squeezelabel.h \ HEADERS += 3rdparty/squeezelabel.h \
3rdparty/qtwin.h \ 3rdparty/qtwin.h \
@ -172,7 +173,8 @@ HEADERS += 3rdparty/squeezelabel.h \
adblock/adblocknetwork.h \ adblock/adblocknetwork.h \
adblock/adblockmanager.h \ adblock/adblockmanager.h \
adblock/adblockdialog.h \ adblock/adblockdialog.h \
adblock/adblockblockednetworkreply.h adblock/adblockblockednetworkreply.h \
adblock/adblockicon.h
FORMS += \ FORMS += \
preferences/autofillmanager.ui \ preferences/autofillmanager.ui \

View File

@ -138,7 +138,8 @@ MainApplication::MainApplication(int &argc, char **argv)
networkManager()->loadCertExceptions(); networkManager()->loadCertExceptions();
plugins()->loadPlugins(); plugins()->loadPlugins();
loadSettings(); loadSettings();
QApplication::restoreOverrideCursor();
QTimer::singleShot(2000, this, SLOT(restoreCursor()));
} }
void MainApplication::loadSettings() void MainApplication::loadSettings()
@ -414,8 +415,6 @@ void MainApplication::aboutToCloseWindow(QupZilla* window)
return; return;
m_mainWindows.removeOne(window); m_mainWindows.removeOne(window);
if (m_mainWindows.count() == 0 )
quitApplication();
} }
//Version of session.dat file //Version of session.dat file
@ -443,13 +442,13 @@ bool MainApplication::saveStateSlot()
stream << m_mainWindows.at(i)->saveState(); stream << m_mainWindows.at(i)->saveState();
} }
file.close(); file.close();
getWindow()->tabWidget()->savePinnedTabs();
settings.setValue("restoreSession",true); settings.setValue("restoreSession",true);
settings.endGroup(); settings.endGroup();
QupZilla* qupzilla_ = getWindow(); QupZilla* qupzilla_ = getWindow();
if (qupzilla_) { if (qupzilla_) {
qupzilla_->tabWidget()->savePinnedTabs();
settings.setValue("Browser-View-Settings/showBookmarksToolbar",qupzilla_->bookmarksToolbar()->isVisible()); settings.setValue("Browser-View-Settings/showBookmarksToolbar",qupzilla_->bookmarksToolbar()->isVisible());
settings.setValue("Browser-View-Settings/showNavigationToolbar",qupzilla_->navigationToolbar()->isVisible()); settings.setValue("Browser-View-Settings/showNavigationToolbar",qupzilla_->navigationToolbar()->isVisible());
settings.setValue("Browser-View-Settings/showStatusbar",qupzilla_->statusBar()->isVisible()); settings.setValue("Browser-View-Settings/showStatusbar",qupzilla_->statusBar()->isVisible());
@ -564,7 +563,7 @@ bool MainApplication::checkProfileDir()
versionFile.write(QupZilla::VERSION.toAscii()); versionFile.write(QupZilla::VERSION.toAscii());
versionFile.close(); versionFile.close();
if (rData.contains("0.9.6") || rData.contains("0.9.7")) // Data not changed from this version if (rData.contains("0.9.6") || rData.contains("0.9.7") || rData.contains("0.9.8")) // Data not changed from this version
return true; return true;
dir.mkdir("profiles"); dir.mkdir("profiles");

View File

@ -92,6 +92,9 @@ public slots:
signals: signals:
void message(MainApplication::MessageType mes, bool state); void message(MainApplication::MessageType mes, bool state);
private slots:
void restoreCursor() { QApplication::restoreOverrideCursor(); }
private: private:
void connectDatabase(); void connectDatabase();
void translateApp(); void translateApp();

View File

@ -715,13 +715,15 @@ void QupZilla::closeEvent(QCloseEvent* event)
{ {
if (mApp->isClosing()) if (mApp->isClosing())
return; return;
if (mApp->windowCount() == 1) {
mApp->saveStateSlot();
mApp->aboutToCloseWindow(this);
if (mApp->windowCount() == 0) {
quitApp() ? event->accept() : event->ignore(); quitApp() ? event->accept() : event->ignore();
return; return;
} }
mApp->aboutToCloseWindow(this);
mApp->saveStateSlot();
event->accept(); event->accept();
} }

View File

@ -70,6 +70,7 @@ class BookmarksToolbar;
class AutoFillModel; class AutoFillModel;
class MainApplication; class MainApplication;
class WebTab; class WebTab;
class AdBlockIcon;
class QupZilla : public QMainWindow class QupZilla : public QMainWindow
{ {
Q_OBJECT Q_OBJECT

View File

@ -18,6 +18,8 @@
#include "downloaditem.h" #include "downloaditem.h"
#include "ui_downloaditem.h" #include "ui_downloaditem.h"
//#define DOWNMANAGER_DEBUG
DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString path, QString fileName, QPixmap fileIcon, bool openAfterFinishedDownload, QWidget* parent) DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString path, QString fileName, QPixmap fileIcon, bool openAfterFinishedDownload, QWidget* parent)
: QWidget(parent) : QWidget(parent)
,ui(new Ui::DownloadItem) ,ui(new Ui::DownloadItem)
@ -28,6 +30,9 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString
,m_downloading(false) ,m_downloading(false)
,m_openAfterFinish(openAfterFinishedDownload) ,m_openAfterFinish(openAfterFinishedDownload)
{ {
#ifdef DOWNMANAGER_DEBUG
qDebug() << __FUNCTION__ << item << reply << path << fileName;
#endif
QString fullPath = path+fileName; QString fullPath = path+fileName;
if (QFile::exists(fullPath)) if (QFile::exists(fullPath))
QFile::remove(fullPath); QFile::remove(fullPath);
@ -51,6 +56,8 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint)));
m_reply->setParent(this);
connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
connect(m_reply, SIGNAL(readyRead()), this, SLOT(readyRead())); connect(m_reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(m_reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64))); connect(m_reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
@ -74,11 +81,14 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString
void DownloadItem::metaDataChanged() void DownloadItem::metaDataChanged()
{ {
QVariant locationHeader = m_reply->header(QNetworkRequest::LocationHeader); QVariant locationHeader = m_reply->header(QNetworkRequest::LocationHeader);
QMessageBox::information(this, "Meta Data Changed", QString("Meta data changed feature unimplemented yet, sorry.\n URL: '%̈́'").arg(locationHeader.toUrl().toString())); QMessageBox::information(m_item->listWidget()->parentWidget(), "Meta Data Changed", QString("Meta data changed feature unimplemented yet, sorry.\n URL: '%̈́'").arg(locationHeader.toUrl().toString()));
} }
void DownloadItem::finished() void DownloadItem::finished()
{ {
#ifdef DOWNMANAGER_DEBUG
qDebug() << __FUNCTION__ << m_reply;
#endif
m_timer.stop(); m_timer.stop();
ui->downloadInfo->setText(tr("Done - %1").arg(m_reply->url().host())); ui->downloadInfo->setText(tr("Done - %1").arg(m_reply->url().host()));
ui->progressBar->hide(); ui->progressBar->hide();
@ -99,6 +109,9 @@ void DownloadItem::finished()
void DownloadItem::downloadProgress(qint64 received, qint64 total) void DownloadItem::downloadProgress(qint64 received, qint64 total)
{ {
#ifdef DOWNMANAGER_DEBUG
qDebug() << __FUNCTION__ << received << total;
#endif
qint64 currentValue = 0; qint64 currentValue = 0;
qint64 totalValue = 0; qint64 totalValue = 0;
if (total > 0) { if (total > 0) {
@ -164,6 +177,9 @@ QString DownloadItem::fileSizeToString(int size)
void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 total) void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 total)
{ {
#ifdef DOWNMANAGER_DEBUG
qDebug() << __FUNCTION__ << currSpeed << received << total;
#endif
// QString QString QString QString // QString QString QString QString
// | m_remTime | |m_currSize| |m_fileSize| |m_speed| // | m_remTime | |m_currSize| |m_fileSize| |m_speed|
// Remaining 26 minutes - 339MB of 693 MB (350kB/s) // Remaining 26 minutes - 339MB of 693 MB (350kB/s)
@ -183,8 +199,12 @@ void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64
ui->downloadInfo->setText(tr("Remaining %1 - %2 of %3 (%4)").arg(remTime, currSize, fileSize, speed)); ui->downloadInfo->setText(tr("Remaining %1 - %2 of %3 (%4)").arg(remTime, currSize, fileSize, speed));
} }
void DownloadItem::stop() void DownloadItem::stop(bool askForDeleteFile)
{ {
#ifdef DOWNMANAGER_DEBUG
qDebug() << __FUNCTION__;
#endif
m_openAfterFinish = false;
m_timer.stop(); m_timer.stop();
m_reply->abort(); m_reply->abort();
QString outputfile = QFileInfo(m_outputFile).absoluteFilePath(); QString outputfile = QFileInfo(m_outputFile).absoluteFilePath();
@ -198,9 +218,14 @@ void DownloadItem::stop()
ui->button->show(); ui->button->show();
ui->button->hide(); ui->button->hide();
#endif #endif
QFile::remove(outputfile);
m_downloading = false; m_downloading = false;
if (askForDeleteFile) {
QMessageBox::StandardButton button = QMessageBox::question(m_item->listWidget()->parentWidget(), tr("Delete file"), tr("Do you want to also delete dowloaded file?"), QMessageBox::Yes | QMessageBox::No);
if (button != QMessageBox::Yes)
return;
}
QFile::remove(outputfile);
} }
void DownloadItem::mouseDoubleClickEvent(QMouseEvent* e) void DownloadItem::mouseDoubleClickEvent(QMouseEvent* e)
@ -247,7 +272,7 @@ void DownloadItem::openFile()
if (info.exists()) if (info.exists())
QDesktopServices::openUrl(QUrl::fromLocalFile(info.absoluteFilePath())); QDesktopServices::openUrl(QUrl::fromLocalFile(info.absoluteFilePath()));
else else
QMessageBox::warning(m_item->listWidget(), tr("Not found"), tr("Sorry, the file \n %1 \n is not found!").arg(info.absoluteFilePath())); QMessageBox::warning(m_item->listWidget()->parentWidget(), tr("Not found"), tr("Sorry, the file \n %1 \n was not found!").arg(info.absoluteFilePath()));
} }
void DownloadItem::openFolder() void DownloadItem::openFolder()
@ -257,6 +282,9 @@ void DownloadItem::openFolder()
void DownloadItem::readyRead() void DownloadItem::readyRead()
{ {
#ifdef DOWNMANAGER_DEBUG
qDebug() << __FUNCTION__ ;
#endif
if (!m_outputFile.isOpen() && !m_outputFile.open(QIODevice::WriteOnly)) { if (!m_outputFile.isOpen() && !m_outputFile.open(QIODevice::WriteOnly)) {
stop(); stop();
ui->downloadInfo->setText(tr("Error: Cannot write to file!")); ui->downloadInfo->setText(tr("Error: Cannot write to file!"));
@ -267,12 +295,18 @@ void DownloadItem::readyRead()
void DownloadItem::error(QNetworkReply::NetworkError error) void DownloadItem::error(QNetworkReply::NetworkError error)
{ {
#ifdef DOWNMANAGER_DEBUG
qDebug() << __FUNCTION__ << error;
#endif
if (error != QNetworkReply::NoError) if (error != QNetworkReply::NoError)
ui->downloadInfo->setText(tr("Error: ")+m_reply->errorString()); ui->downloadInfo->setText(tr("Error: ")+m_reply->errorString());
} }
void DownloadItem::updateDownload() void DownloadItem::updateDownload()
{ {
#ifdef DOWNMANAGER_DEBUG
qDebug() << __FUNCTION__ ;
#endif
if (ui->progressBar->maximum() == 0 && m_outputFile.isOpen() && m_reply->isFinished()) { if (ui->progressBar->maximum() == 0 && m_outputFile.isOpen() && m_reply->isFinished()) {
downloadProgress(0,0); downloadProgress(0,0);
finished(); finished();

View File

@ -61,7 +61,7 @@ private slots:
void finished(); void finished();
void metaDataChanged(); void metaDataChanged();
void downloadProgress(qint64 received, qint64 total); void downloadProgress(qint64 received, qint64 total);
void stop(); void stop(bool askForDeleteFile = true);
void openFile(); void openFile();
void openFolder(); void openFolder();
void readyRead(); void readyRead();