1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Windows: Show taskbar progress on browser window in download manager

It will now show progress even when download manager window is not
opened, as download manager is no longer automatically opened when
starting new download.
This commit is contained in:
David Rosca 2018-03-25 20:38:48 +02:00
parent ba3563362d
commit 2eeee848b7
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 21 additions and 24 deletions

View File

@ -156,6 +156,20 @@ void DownloadManager::closeDownloadTab(const QUrl &url) const
} }
} }
QWinTaskbarButton *DownloadManager::taskbarButton()
{
#ifdef Q_OS_WIN
if (!m_taskbarButton) {
BrowserWindow *window = mApp->getWindow();
m_taskbarButton = new QWinTaskbarButton(window ? window->windowHandle() : windowHandle());
m_taskbarButton->progress()->setRange(0, 100);
}
return m_taskbarButton;
#else
return nullptr;
#endif
}
void DownloadManager::startExternalManager(const QUrl &url) void DownloadManager::startExternalManager(const QUrl &url)
{ {
QString arguments = m_externalArguments; QString arguments = m_externalArguments;
@ -176,9 +190,7 @@ void DownloadManager::timerEvent(QTimerEvent* e)
ui->speedLabel->clear(); ui->speedLabel->clear();
setWindowTitle(tr("Download Manager")); setWindowTitle(tr("Download Manager"));
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (m_taskbarButton) { taskbarButton()->progress()->hide();
m_taskbarButton->progress()->hide();
}
#endif #endif
return; return;
} }
@ -220,10 +232,8 @@ void DownloadManager::timerEvent(QTimerEvent* e)
#endif #endif
setWindowTitle(tr("%1% - Download Manager").arg(progress)); setWindowTitle(tr("%1% - Download Manager").arg(progress));
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (m_taskbarButton) { taskbarButton()->progress()->show();
m_taskbarButton->progress()->show(); taskbarButton()->progress()->setValue(progress);
m_taskbarButton->progress()->setValue(progress);
}
#endif #endif
} }
@ -407,9 +417,7 @@ void DownloadManager::downloadFinished(bool success)
ui->speedLabel->clear(); ui->speedLabel->clear();
setWindowTitle(tr("Download Manager")); setWindowTitle(tr("Download Manager"));
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (m_taskbarButton) { taskbarButton()->progress()->hide();
m_taskbarButton->progress()->hide();
}
#endif #endif
if (m_closeOnFinish) { if (m_closeOnFinish) {
close(); close();
@ -417,18 +425,6 @@ void DownloadManager::downloadFinished(bool success)
} }
} }
void DownloadManager::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
#ifdef Q_OS_WIN
if (!m_taskbarButton) {
m_taskbarButton = new QWinTaskbarButton(this);
}
m_taskbarButton->setWindow(windowHandle());
m_taskbarButton->progress()->setRange(0, 100);
#endif
}
void DownloadManager::deleteItem(DownloadItem* item) void DownloadManager::deleteItem(DownloadItem* item)
{ {
if (item && !item->isDownloading()) { if (item && !item->isDownloading()) {

View File

@ -19,6 +19,7 @@
#define DOWNLOADMANAGER_H #define DOWNLOADMANAGER_H
#include <QWidget> #include <QWidget>
#include <QPointer>
#include <QBasicTimer> #include <QBasicTimer>
#include "qzcommon.h" #include "qzcommon.h"
@ -89,13 +90,13 @@ Q_SIGNALS:
void downloadsCountChanged(); void downloadsCountChanged();
private: private:
void showEvent(QShowEvent *event) override;
void timerEvent(QTimerEvent* e) override; void timerEvent(QTimerEvent* e) override;
void closeEvent(QCloseEvent* e) override; void closeEvent(QCloseEvent* e) override;
void resizeEvent(QResizeEvent* e) override; void resizeEvent(QResizeEvent* e) override;
void keyPressEvent(QKeyEvent* e) override; void keyPressEvent(QKeyEvent* e) override;
void closeDownloadTab(const QUrl &url) const; void closeDownloadTab(const QUrl &url) const;
QWinTaskbarButton *taskbarButton();
Ui::DownloadManager* ui; Ui::DownloadManager* ui;
QBasicTimer m_timer; QBasicTimer m_timer;
@ -113,7 +114,7 @@ private:
DownloadOption m_lastDownloadOption; DownloadOption m_lastDownloadOption;
QWinTaskbarButton *m_taskbarButton = nullptr; QPointer<QWinTaskbarButton> m_taskbarButton;
}; };
#endif // DOWNLOADMANAGER_H #endif // DOWNLOADMANAGER_H