1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Add DownloadsButton to navigation toolbar

It is visible only when there are items in download manager and shows
number of active downloads in badge text.
This commit is contained in:
David Rosca 2018-01-08 19:49:05 +01:00
parent 0e41fd0785
commit 1f9599aac7
14 changed files with 175 additions and 8 deletions

View File

@ -106,6 +106,7 @@ set(SRCS ${SRCS}
downloads/downloaditem.cpp downloads/downloaditem.cpp
downloads/downloadmanager.cpp downloads/downloadmanager.cpp
downloads/downloadoptionsdialog.cpp downloads/downloadoptionsdialog.cpp
downloads/downloadsbutton.cpp
history/history.cpp history/history.cpp
history/historyitem.cpp history/historyitem.cpp
history/historymanager.cpp history/historymanager.cpp

View File

@ -26,7 +26,6 @@
#include "websearchbar.h" #include "websearchbar.h"
#include "pluginproxy.h" #include "pluginproxy.h"
#include "sidebar.h" #include "sidebar.h"
#include "downloadmanager.h"
#include "cookiejar.h" #include "cookiejar.h"
#include "cookiemanager.h" #include "cookiemanager.h"
#include "bookmarkstoolbar.h" #include "bookmarkstoolbar.h"
@ -55,6 +54,7 @@
#include "bookmarksmenu.h" #include "bookmarksmenu.h"
#include "historymenu.h" #include "historymenu.h"
#include "mainmenu.h" #include "mainmenu.h"
#include "downloadsbutton.h"
#include <algorithm> #include <algorithm>
@ -385,6 +385,8 @@ void BrowserWindow::setupUi()
statusBar()->addPermanentWidget(m_progressBar); statusBar()->addPermanentWidget(m_progressBar);
statusBar()->addPermanentWidget(m_ipLabel); statusBar()->addPermanentWidget(m_ipLabel);
m_navigationToolbar->addToolButton(new DownloadsButton(this));
QDesktopWidget* desktop = mApp->desktop(); QDesktopWidget* desktop = mApp->desktop();
int windowWidth = desktop->availableGeometry().width() / 1.3; int windowWidth = desktop->availableGeometry().width() / 1.3;
int windowHeight = desktop->availableGeometry().height() / 1.3; int windowHeight = desktop->availableGeometry().height() / 1.3;

View File

@ -61,5 +61,6 @@
<file>icons/preferences/shortcuts.svg</file> <file>icons/preferences/shortcuts.svg</file>
<file>icons/preferences/spellcheck.svg</file> <file>icons/preferences/spellcheck.svg</file>
<file>icons/preferences/tabs.svg</file> <file>icons/preferences/tabs.svg</file>
<file>icons/menu/download.svg</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -0,0 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<defs id="defs3051">
<style type="text/css" id="current-color-scheme">
.ColorScheme-Text {
color:#4d4d4d;
}
</style>
</defs>
<path style="fill:currentColor;fill-opacity:1;stroke:none"
d="M 6 2 L 6 3 L 6 6 L 7 6 L 7 3 L 9 3 L 9 6 L 10 6 L 10 3 L 10 2 L 9 2 L 7 2 L 6 2 z M 3.8046875 6 L 3 6.8320312 L 8 12 L 13 6.8320312 L 12.195312 6 L 8 10.337891 L 3.8046875 6 z M 2 12 L 2 14 L 3 14 L 13 14 L 14 14 L 14 13 L 14 12 L 13 12 L 13 13 L 3 13 L 3 12 L 2 12 z "
class="ColorScheme-Text"
/>
</svg>

After

Width:  |  Height:  |  Size: 605 B

View File

@ -244,6 +244,7 @@ void DownloadManager::clearList()
items.append(downItem); items.append(downItem);
} }
qDeleteAll(items); qDeleteAll(items);
emit downloadsCountChanged();
} }
void DownloadManager::download(QWebEngineDownloadItem *downloadItem) void DownloadManager::download(QWebEngineDownloadItem *downloadItem)
@ -361,22 +362,40 @@ void DownloadManager::download(QWebEngineDownloadItem *downloadItem)
listItem->setSizeHint(downItem->sizeHint()); listItem->setSizeHint(downItem->sizeHint());
downItem->show(); downItem->show();
show(); m_activeDownloadsCount++;
raise(); emit downloadsCountChanged();
activateWindow(); }
int DownloadManager::downloadsCount() const
{
return ui->list->count();
}
int DownloadManager::activeDownloadsCount() const
{
return m_activeDownloadsCount;
} }
void DownloadManager::downloadFinished(bool success) void DownloadManager::downloadFinished(bool success)
{ {
m_activeDownloadsCount = 0;
bool downloadingAllFilesFinished = true; bool downloadingAllFilesFinished = true;
for (int i = 0; i < ui->list->count(); i++) { for (int i = 0; i < ui->list->count(); i++) {
DownloadItem* downItem = qobject_cast<DownloadItem*>(ui->list->itemWidget(ui->list->item(i))); DownloadItem* downItem = qobject_cast<DownloadItem*>(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; continue;
} }
downloadingAllFilesFinished = false; downloadingAllFilesFinished = false;
} }
emit downloadsCountChanged();
if (downloadingAllFilesFinished) { if (downloadingAllFilesFinished) {
if (success && qApp->activeWindow() != this) { 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.")); 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."));

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* Falkon - Qt web browser * Falkon - Qt web browser
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -65,6 +65,9 @@ public:
void download(QWebEngineDownloadItem *downloadItem); void download(QWebEngineDownloadItem *downloadItem);
int downloadsCount() const;
int activeDownloadsCount() const;
bool canClose(); bool canClose();
bool useExternalManager() const; bool useExternalManager() const;
@ -83,6 +86,7 @@ private slots:
signals: signals:
void resized(QSize); void resized(QSize);
void downloadsCountChanged();
private: private:
void showEvent(QShowEvent *event) override; void showEvent(QShowEvent *event) override;
@ -101,6 +105,7 @@ private:
bool m_useNativeDialog; bool m_useNativeDialog;
bool m_isClosing; bool m_isClosing;
bool m_closeOnFinish; bool m_closeOnFinish;
int m_activeDownloadsCount = 0;
bool m_useExternalManager; bool m_useExternalManager;
QString m_externalExecutable; QString m_externalExecutable;

View File

@ -0,0 +1,62 @@
/* ============================================================
* QupZilla - Qt web browser
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#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();
}

View File

@ -0,0 +1,39 @@
/* ============================================================
* QupZilla - Qt web browser
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#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;
};

View File

@ -308,6 +308,7 @@ void NavigationBar::addToolButton(AbstractButtonInterface *button)
} }
NavigationBarToolButton *toolButton = new NavigationBarToolButton(button, this); NavigationBarToolButton *toolButton = new NavigationBarToolButton(button, this);
toolButton->setProperty("button-id", button->id());
connect(toolButton, &NavigationBarToolButton::visibilityChangeRequested, this, [=]() { connect(toolButton, &NavigationBarToolButton::visibilityChangeRequested, this, [=]() {
if (m_layout->indexOf(toolButton) != -1) { if (m_layout->indexOf(toolButton) != -1) {
toolButton->updateVisibility(); toolButton->updateVisibility();
@ -498,6 +499,7 @@ void NavigationBar::loadSettings()
QSL("button-reloadstop"), QSL("button-reloadstop"),
QSL("button-home"), QSL("button-home"),
QSL("locationbar"), QSL("locationbar"),
QSL("button-downloads"),
QSL("button-tools") QSL("button-tools")
}; };

View File

@ -59,8 +59,11 @@ QString ToolButton::themeIcon() const
void ToolButton::setThemeIcon(const QString &icon) void ToolButton::setThemeIcon(const QString &icon)
{ {
const QIcon ic = QIcon::fromTheme(icon);
if (!ic.isNull()) {
m_themeIcon = icon; m_themeIcon = icon;
setIcon(QIcon::fromTheme(m_themeIcon)); setIcon(QIcon::fromTheme(m_themeIcon));
}
} }
QIcon ToolButton::fallbackIcon() const QIcon ToolButton::fallbackIcon() const

View File

@ -113,6 +113,11 @@
margin: 0px 1px; margin: 0px 1px;
} }
ToolButton[button-id="button-downloads"]
{
qproperty-icon: url(images/navigation-downloads.png);
}
ToolButton[toolbar-look="true"] ToolButton[toolbar-look="true"]
{ {
qproperty-iconSize: 19px 19px; qproperty-iconSize: 19px 19px;

View File

@ -72,6 +72,11 @@
margin: 0px 1px; margin: 0px 1px;
} }
ToolButton[button-id="button-downloads"]
{
qproperty-themeIcon: "edit-download";
}
/*TabWidget*/ /*TabWidget*/
#tabbar #tabbar
{ {

View File

@ -114,6 +114,11 @@
margin: 0px 1px; margin: 0px 1px;
} }
ToolButton[button-id="button-downloads"]
{
qproperty-icon: url(images/navigation-downloads.png);
}
ToolButton[toolbar-look="true"] ToolButton[toolbar-look="true"]
{ {
qproperty-iconSize: 16px 16px; qproperty-iconSize: 16px 16px;

View File

@ -93,6 +93,11 @@
margin: 0px 1px; margin: 0px 1px;
} }
ToolButton[button-id="button-downloads"]
{
qproperty-themeIcon: "edit-download";
}
/*TabWidget*/ /*TabWidget*/
#tabbar-button-right #tabbar-button-right
{ {