File indexing completed on 2024-05-19 04:58:48
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2018 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "downloadsbutton.h" 0019 #include "mainapplication.h" 0020 #include "downloadmanager.h" 0021 0022 DownloadsButton::DownloadsButton(QObject *parent) 0023 : AbstractButtonInterface(parent) 0024 , m_manager(mApp->downloadManager()) 0025 { 0026 setIcon(QIcon::fromTheme(QSL("edit-download"), QIcon(QSL(":icons/menu/download.svg")))); 0027 setTitle(tr("Downloads")); 0028 setToolTip(tr("Open Download Manager")); 0029 0030 connect(this, &AbstractButtonInterface::clicked, this, &DownloadsButton::clicked); 0031 connect(m_manager, &DownloadManager::downloadsCountChanged, this, &DownloadsButton::updateState); 0032 0033 updateState(); 0034 } 0035 0036 QString DownloadsButton::id() const 0037 { 0038 return QSL("button-downloads"); 0039 } 0040 0041 QString DownloadsButton::name() const 0042 { 0043 return tr("Downloads"); 0044 } 0045 0046 void DownloadsButton::updateState() 0047 { 0048 setVisible(m_manager->downloadsCount() > 0); 0049 const int count = m_manager->activeDownloadsCount(); 0050 if (count > 0) { 0051 setBadgeText(QString::number(count)); 0052 } else { 0053 setBadgeText(QString()); 0054 } 0055 } 0056 0057 void DownloadsButton::clicked(ClickController *controller) 0058 { 0059 Q_UNUSED(controller) 0060 0061 mApp->downloadManager()->show(); 0062 }