Falkon Develop
Cross-platform Qt-based web browser
downloadsbutton.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "downloadsbutton.h"
19#include "mainapplication.h"
20#include "downloadmanager.h"
21
24 , m_manager(mApp->downloadManager())
25{
26 setIcon(QIcon::fromTheme(QSL("edit-download"), QIcon(QSL(":icons/menu/download.svg"))));
27 setTitle(tr("Downloads"));
28 setToolTip(tr("Open Download Manager"));
29
30 connect(this, &AbstractButtonInterface::clicked, this, &DownloadsButton::clicked);
31 connect(m_manager, &DownloadManager::downloadsCountChanged, this, &DownloadsButton::updateState);
32
33 updateState();
34}
35
36QString DownloadsButton::id() const
37{
38 return QSL("button-downloads");
39}
40
41QString DownloadsButton::name() const
42{
43 return tr("Downloads");
44}
45
46void DownloadsButton::updateState()
47{
48 setVisible(m_manager->downloadsCount() > 0);
49 const int count = m_manager->activeDownloadsCount();
50 if (count > 0) {
51 setBadgeText(QString::number(count));
52 } else {
53 setBadgeText(QString());
54 }
55}
56
57void DownloadsButton::clicked(ClickController *controller)
58{
59 Q_UNUSED(controller)
60
61 mApp->downloadManager()->show();
62}
void clicked(AbstractButtonInterface::ClickController *controller)
void setTitle(const QString &text)
void setBadgeText(const QString &badgeText)
void setToolTip(const QString &toolTip)
void setIcon(const QIcon &icon)
int activeDownloadsCount() const
int downloadsCount() const
void downloadsCountChanged()
DownloadsButton(QObject *parent=nullptr)
QString name() const override
QString id() const override
#define mApp
#define QSL(x)
Definition: qzcommon.h:40