Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Commit

Permalink
Show download progress in taskbar on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nowrep committed Jan 20, 2017
1 parent f791f81 commit b13c896
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 39 deletions.
7 changes: 0 additions & 7 deletions BUILDING.md
Expand Up @@ -109,13 +109,6 @@ Available Defines
Compiler 2010
(enabled by default)

W7TASKBAR Enable Windows 7 Taskbar support
Requires linking against libraries from Microsoft Visual C++
Compiler 2010
May cause crash when downloading files on some systems.
(disabled by default)


Linux / Unix specific defines:

NO_X11 Disable all X11 calls.
Expand Down
49 changes: 26 additions & 23 deletions src/lib/downloads/downloadmanager.cpp
Expand Up @@ -39,6 +39,8 @@

#ifdef Q_OS_WIN
#include <QtWin>
#include <QWinTaskbarButton>
#include <QWinTaskbarProgress>
#endif

DownloadManager::DownloadManager(QWidget* parent)
Expand All @@ -65,12 +67,6 @@ DownloadManager::DownloadManager(QWidget* parent)
loadSettings();

QzTools::setWmClass("Download Manager", this);

#ifdef W7TASKBAR
if (QtWin::isRunningWindows7()) {
win7.init(QtWin::hwndOfWidget(this));
}
#endif
}

void DownloadManager::loadSettings()
Expand Down Expand Up @@ -126,15 +122,6 @@ void DownloadManager::startExternalManager(const QUrl &url)
m_lastDownloadOption = ExternalManager;
}

#ifdef W7TASKBAR
bool DownloadManager::nativeEvent(const QByteArray &eventType, void* _message, long* result)
{
Q_UNUSED(eventType)
MSG* message = static_cast<MSG*>(_message);
return win7.winEvent(message, result);
}
#endif

void DownloadManager::timerEvent(QTimerEvent* e)
{
QVector<QTime> remTimes;
Expand All @@ -145,6 +132,11 @@ void DownloadManager::timerEvent(QTimerEvent* e)
if (!ui->list->count()) {
ui->speedLabel->clear();
setWindowTitle(tr("Download Manager"));
#ifdef Q_OS_WIN
if (m_taskbarButton) {
m_taskbarButton->progress()->hide();
}
#endif
return;
}
for (int i = 0; i < ui->list->count(); i++) {
Expand Down Expand Up @@ -184,10 +176,10 @@ void DownloadManager::timerEvent(QTimerEvent* e)
DownloadItem::remaingTimeToString(remaining)));
#endif
setWindowTitle(tr("%1% - Download Manager").arg(progress));
#ifdef W7TASKBAR
if (QtWin::isRunningWindows7()) {
win7.setProgressValue(progress, 100);
win7.setProgressState(win7.Normal);
#ifdef Q_OS_WIN
if (m_taskbarButton) {
m_taskbarButton->progress()->show();
m_taskbarButton->progress()->setValue(progress);
}
#endif
}
Expand Down Expand Up @@ -344,10 +336,9 @@ void DownloadManager::downloadFinished(bool success)
}
ui->speedLabel->clear();
setWindowTitle(tr("Download Manager"));
#ifdef W7TASKBAR
if (QtWin::isRunningWindows7()) {
win7.setProgressValue(0, 100);
win7.setProgressState(win7.NoProgress);
#ifdef Q_OS_WIN
if (m_taskbarButton) {
m_taskbarButton->progress()->hide();
}
#endif
if (m_closeOnFinish) {
Expand All @@ -356,6 +347,18 @@ 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)
{
if (item && !item->isDownloading()) {
Expand Down
13 changes: 4 additions & 9 deletions src/lib/downloads/downloadmanager.h
Expand Up @@ -32,9 +32,9 @@ class QUrl;
class QNetworkAccessManager;
class QListWidgetItem;
class QWebEngineDownloadItem;
class QWinTaskbarButton;

class DownloadItem;
class EcWin7;
class WebPage;

class QUPZILLA_EXPORT DownloadManager : public QWidget
Expand Down Expand Up @@ -76,11 +76,6 @@ class QUPZILLA_EXPORT DownloadManager : public QWidget
public slots:
void show();

#ifdef W7TASKBAR
protected:
virtual bool nativeEvent(const QByteArray &eventType, void* _message, long* result);
#endif

private slots:
void clearList();
void deleteItem(DownloadItem* item);
Expand All @@ -90,9 +85,7 @@ private slots:
void resized(QSize);

private:
#ifdef W7TASKBAR
EcWin7 win7;
#endif
void showEvent(QShowEvent *event) override;
void timerEvent(QTimerEvent* e);
void closeEvent(QCloseEvent* e);
void resizeEvent(QResizeEvent* e);
Expand All @@ -112,6 +105,8 @@ private slots:
QString m_externalArguments;

DownloadOption m_lastDownloadOption;

QWinTaskbarButton *m_taskbarButton = nullptr;
};

#endif // DOWNLOADMANAGER_H

0 comments on commit b13c896

Please sign in to comment.