diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 5b3e02ed4..d2438da94 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -106,6 +106,7 @@ set(SRCS ${SRCS} downloads/downloaditem.cpp downloads/downloadmanager.cpp downloads/downloadoptionsdialog.cpp + downloads/downloadsbutton.cpp history/history.cpp history/historyitem.cpp history/historymanager.cpp diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index 02746680e..4a42935fd 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -26,7 +26,6 @@ #include "websearchbar.h" #include "pluginproxy.h" #include "sidebar.h" -#include "downloadmanager.h" #include "cookiejar.h" #include "cookiemanager.h" #include "bookmarkstoolbar.h" @@ -55,6 +54,7 @@ #include "bookmarksmenu.h" #include "historymenu.h" #include "mainmenu.h" +#include "downloadsbutton.h" #include @@ -385,6 +385,8 @@ void BrowserWindow::setupUi() statusBar()->addPermanentWidget(m_progressBar); statusBar()->addPermanentWidget(m_ipLabel); + m_navigationToolbar->addToolButton(new DownloadsButton(this)); + QDesktopWidget* desktop = mApp->desktop(); int windowWidth = desktop->availableGeometry().width() / 1.3; int windowHeight = desktop->availableGeometry().height() / 1.3; diff --git a/src/lib/data/icons.qrc b/src/lib/data/icons.qrc index 316068927..a8cfb60e4 100644 --- a/src/lib/data/icons.qrc +++ b/src/lib/data/icons.qrc @@ -61,5 +61,6 @@ icons/preferences/shortcuts.svg icons/preferences/spellcheck.svg icons/preferences/tabs.svg + icons/menu/download.svg diff --git a/src/lib/data/icons/menu/download.svg b/src/lib/data/icons/menu/download.svg new file mode 100644 index 000000000..293505e8d --- /dev/null +++ b/src/lib/data/icons/menu/download.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/src/lib/downloads/downloadmanager.cpp b/src/lib/downloads/downloadmanager.cpp index 1b6324b5a..5b1d73f1e 100644 --- a/src/lib/downloads/downloadmanager.cpp +++ b/src/lib/downloads/downloadmanager.cpp @@ -244,6 +244,7 @@ void DownloadManager::clearList() items.append(downItem); } qDeleteAll(items); + emit downloadsCountChanged(); } void DownloadManager::download(QWebEngineDownloadItem *downloadItem) @@ -361,22 +362,40 @@ void DownloadManager::download(QWebEngineDownloadItem *downloadItem) listItem->setSizeHint(downItem->sizeHint()); downItem->show(); - show(); - raise(); - activateWindow(); + m_activeDownloadsCount++; + emit downloadsCountChanged(); +} + +int DownloadManager::downloadsCount() const +{ + return ui->list->count(); +} + +int DownloadManager::activeDownloadsCount() const +{ + return m_activeDownloadsCount; } void DownloadManager::downloadFinished(bool success) { + m_activeDownloadsCount = 0; bool downloadingAllFilesFinished = true; for (int i = 0; i < ui->list->count(); i++) { DownloadItem* downItem = qobject_cast(ui->list->itemWidget(ui->list->item(i))); - if (!downItem || downItem->isCancelled() || !downItem->isDownloading()) { + if (!downItem) { + continue; + } + if (downItem->isDownloading()) { + m_activeDownloadsCount++; + } + if (downItem->isCancelled() || !downItem->isDownloading()) { continue; } downloadingAllFilesFinished = false; } + emit downloadsCountChanged(); + if (downloadingAllFilesFinished) { if (success && qApp->activeWindow() != this) { mApp->desktopNotifications()->showNotification(QIcon::fromTheme(QSL("download"), QIcon(QSL(":icons/other/download.svg"))).pixmap(48), tr("Falkon: Download Finished"), tr("All files have been successfully downloaded.")); diff --git a/src/lib/downloads/downloadmanager.h b/src/lib/downloads/downloadmanager.h index 7613fb1ed..882175cfa 100644 --- a/src/lib/downloads/downloadmanager.h +++ b/src/lib/downloads/downloadmanager.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2017 David Rosca +* Copyright (C) 2010-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -65,6 +65,9 @@ public: void download(QWebEngineDownloadItem *downloadItem); + int downloadsCount() const; + int activeDownloadsCount() const; + bool canClose(); bool useExternalManager() const; @@ -83,6 +86,7 @@ private slots: signals: void resized(QSize); + void downloadsCountChanged(); private: void showEvent(QShowEvent *event) override; @@ -101,6 +105,7 @@ private: bool m_useNativeDialog; bool m_isClosing; bool m_closeOnFinish; + int m_activeDownloadsCount = 0; bool m_useExternalManager; QString m_externalExecutable; diff --git a/src/lib/downloads/downloadsbutton.cpp b/src/lib/downloads/downloadsbutton.cpp new file mode 100644 index 000000000..a12df4260 --- /dev/null +++ b/src/lib/downloads/downloadsbutton.cpp @@ -0,0 +1,62 @@ +/* ============================================================ +* QupZilla - Qt web browser +* Copyright (C) 2018 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#include "downloadsbutton.h" +#include "mainapplication.h" +#include "downloadmanager.h" + +DownloadsButton::DownloadsButton(QObject *parent) + : AbstractButtonInterface(parent) + , m_manager(mApp->downloadManager()) +{ + setIcon(QIcon::fromTheme(QSL("edit-download"), QIcon(QSL(":icons/menu/download.svg")))); + setTitle(tr("Downloads")); + setToolTip(tr("Open Download Manager")); + + connect(this, &AbstractButtonInterface::clicked, this, &DownloadsButton::clicked); + connect(m_manager, &DownloadManager::downloadsCountChanged, this, &DownloadsButton::updateState); + + updateState(); +} + +QString DownloadsButton::id() const +{ + return QSL("button-downloads"); +} + +QString DownloadsButton::name() const +{ + return tr("Downloads"); +} + +void DownloadsButton::updateState() +{ + setVisible(m_manager->downloadsCount() > 0); + const int count = m_manager->activeDownloadsCount(); + if (count > 0) { + setBadgeText(QString::number(count)); + } else { + setBadgeText(QString()); + } +} + +void DownloadsButton::clicked(ClickController *controller) +{ + Q_UNUSED(controller) + + mApp->downloadManager()->show(); +} diff --git a/src/lib/downloads/downloadsbutton.h b/src/lib/downloads/downloadsbutton.h new file mode 100644 index 000000000..5b9a4374e --- /dev/null +++ b/src/lib/downloads/downloadsbutton.h @@ -0,0 +1,39 @@ +/* ============================================================ +* QupZilla - Qt web browser +* Copyright (C) 2018 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#pragma once + +#include "abstractbuttoninterface.h" + +class DownloadManager; + +class DownloadsButton : public AbstractButtonInterface +{ + Q_OBJECT + +public: + explicit DownloadsButton(QObject *parent = nullptr); + + QString id() const override; + QString name() const override; + +private: + void updateState(); + void clicked(ClickController *controller); + + DownloadManager *m_manager; +}; diff --git a/src/lib/navigation/navigationbar.cpp b/src/lib/navigation/navigationbar.cpp index bc8d00309..e913c0d9f 100644 --- a/src/lib/navigation/navigationbar.cpp +++ b/src/lib/navigation/navigationbar.cpp @@ -308,6 +308,7 @@ void NavigationBar::addToolButton(AbstractButtonInterface *button) } NavigationBarToolButton *toolButton = new NavigationBarToolButton(button, this); + toolButton->setProperty("button-id", button->id()); connect(toolButton, &NavigationBarToolButton::visibilityChangeRequested, this, [=]() { if (m_layout->indexOf(toolButton) != -1) { toolButton->updateVisibility(); @@ -498,6 +499,7 @@ void NavigationBar::loadSettings() QSL("button-reloadstop"), QSL("button-home"), QSL("locationbar"), + QSL("button-downloads"), QSL("button-tools") }; diff --git a/src/lib/tools/toolbutton.cpp b/src/lib/tools/toolbutton.cpp index c7430324c..bfcb37133 100644 --- a/src/lib/tools/toolbutton.cpp +++ b/src/lib/tools/toolbutton.cpp @@ -59,8 +59,11 @@ QString ToolButton::themeIcon() const void ToolButton::setThemeIcon(const QString &icon) { - m_themeIcon = icon; - setIcon(QIcon::fromTheme(m_themeIcon)); + const QIcon ic = QIcon::fromTheme(icon); + if (!ic.isNull()) { + m_themeIcon = icon; + setIcon(QIcon::fromTheme(m_themeIcon)); + } } QIcon ToolButton::fallbackIcon() const diff --git a/themes/chrome/main.css b/themes/chrome/main.css index ed6dc01bd..cd75b2a53 100644 --- a/themes/chrome/main.css +++ b/themes/chrome/main.css @@ -113,6 +113,11 @@ margin: 0px 1px; } +ToolButton[button-id="button-downloads"] +{ + qproperty-icon: url(images/navigation-downloads.png); +} + ToolButton[toolbar-look="true"] { qproperty-iconSize: 19px 19px; diff --git a/themes/linux/main.css b/themes/linux/main.css index 5b64f2888..16cc00560 100644 --- a/themes/linux/main.css +++ b/themes/linux/main.css @@ -72,6 +72,11 @@ margin: 0px 1px; } +ToolButton[button-id="button-downloads"] +{ + qproperty-themeIcon: "edit-download"; +} + /*TabWidget*/ #tabbar { diff --git a/themes/mac/main.css b/themes/mac/main.css index 401c07958..b17ed190f 100644 --- a/themes/mac/main.css +++ b/themes/mac/main.css @@ -114,6 +114,11 @@ margin: 0px 1px; } +ToolButton[button-id="button-downloads"] +{ + qproperty-icon: url(images/navigation-downloads.png); +} + ToolButton[toolbar-look="true"] { qproperty-iconSize: 16px 16px; diff --git a/themes/windows/main.css b/themes/windows/main.css index 81fd4c452..1d1e9e762 100644 --- a/themes/windows/main.css +++ b/themes/windows/main.css @@ -93,6 +93,11 @@ margin: 0px 1px; } +ToolButton[button-id="button-downloads"] +{ + qproperty-themeIcon: "edit-download"; +} + /*TabWidget*/ #tabbar-button-right {