From 17818d33aaea8759439138da7a28efb2e5c95f26 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Sun, 18 Oct 2009 14:16:53 +0200 Subject: [PATCH 02/23] Show the number of downloads in the download manager dialog title, and blink it, after it's finished downloading. --- src/downloadmanager.cpp | 28 +++++++++++++++++++++++++++- src/downloadmanager.h | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git src/downloadmanager.cpp src/downloadmanager.cpp index 7be76fa..8196353 100644 --- src/downloadmanager.cpp +++ src/downloadmanager.cpp @@ -250,6 +250,7 @@ void DownloadItem::stop() tryAgainButton->show(); setUpdatesEnabled(true); m_reply->abort(); + emit downloadFinished(); } void DownloadItem::open() @@ -317,6 +318,7 @@ void DownloadItem::error(QNetworkReply::NetworkError) downloadInfoLabel->setText(tr("Network Error: %1").arg(m_reply->errorString())); tryAgainButton->setEnabled(true); tryAgainButton->setVisible(true); + emit downloadFinished(); } void DownloadItem::metaDataChanged() @@ -448,6 +450,7 @@ void DownloadItem::finished() m_output.close(); updateInfoLabel(); emit statusChanged(); + emit downloadFinished(); } /*! @@ -580,6 +583,7 @@ void DownloadManager::handleUnsupportedContent(QNetworkReply *reply, bool reques void DownloadManager::addItem(DownloadItem *item) { connect(item, SIGNAL(statusChanged()), this, SLOT(updateRow())); + connect(item, SIGNAL(downloadFinished()), this, SLOT(finished())); int row = m_downloads.count(); m_model->beginInsertRows(QModelIndex(), row, row); m_downloads.append(item); @@ -590,8 +594,28 @@ void DownloadManager::addItem(DownloadItem *item) item->fileIcon->setPixmap(icon.pixmap(48, 48)); downloadsView->setRowHeight(row, item->sizeHint().height()); updateRow(item); //incase download finishes before the constructor returns + updateActiveItemCount(); } +void DownloadManager::updateActiveItemCount() +{ + int acCount = activeDownloads(); + if (acCount > 0) { + setWindowTitle(QApplication::translate("DownloadDialog", "Downloading %1", 0, QApplication::UnicodeUTF8).arg(acCount)); + } else { + setWindowTitle(QApplication::translate("DownloadDialog", "Downloads", 0, QApplication::UnicodeUTF8)); + } +} + +void DownloadManager::finished() +{ + updateActiveItemCount(); + if (isVisible()) { + QApplication::alert(this); + } +} + + void DownloadManager::updateRow() { if (DownloadItem *item = qobject_cast(sender())) @@ -692,16 +716,17 @@ void DownloadManager::load() item->m_output.setFileName(fileName); item->fileNameLabel->setText(QFileInfo(item->m_output.fileName()).fileName()); item->m_url = url; - addItem(item); item->stopButton->setVisible(false); item->stopButton->setEnabled(false); item->tryAgainButton->setVisible(!done); item->tryAgainButton->setEnabled(!done); item->progressBar->setVisible(false); + addItem(item); } key = QString(QLatin1String("download_%1_")).arg(++i); } cleanupButton->setEnabled(m_downloads.count() - activeDownloads() > 0); + updateActiveItemCount(); } void DownloadManager::cleanup() @@ -710,6 +735,7 @@ void DownloadManager::cleanup() return; m_model->removeRows(0, m_downloads.count()); updateItemCount(); + updateActiveItemCount(); if (m_downloads.isEmpty() && m_iconProvider) { delete m_iconProvider; m_iconProvider = 0; diff --git src/downloadmanager.h src/downloadmanager.h index fb45b59..f37f8e1 100644 --- src/downloadmanager.h +++ src/downloadmanager.h @@ -79,6 +79,7 @@ class DownloadItem : public QWidget, public Ui_DownloadItem signals: void statusChanged(); void progress(qint64 bytesReceived = 0, qint64 bytesTotal = 0); + void downloadFinished(); public: DownloadItem(QNetworkReply *reply = 0, bool requestFileName = false, QWidget *parent = 0); @@ -170,12 +171,14 @@ private slots: void save() const; void updateRow(DownloadItem *item); void updateRow(); + void finished(); private: void addItem(DownloadItem *item); void updateItemCount(); void load(); bool externalDownload(const QUrl &url); + void updateActiveItemCount(); AutoSaver *m_autoSaver; DownloadModel *m_model; -- 2.44.0