From 4c7b361452c8ed14067285174c5beef680b7967f Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 30 Jun 2015 09:19:05 +0200 Subject: [PATCH] Hard work on issue #12. --- src/core/feeddownloader.cpp | 27 ++++++++++++++++++++++++-- src/core/feeddownloader.h | 17 +++++++++++++++- src/gui/feedmessageviewer.cpp | 9 +++++++-- src/gui/feedmessageviewer.h | 4 ++-- src/gui/notifications/notification.cpp | 12 ++++++++++-- 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/core/feeddownloader.cpp b/src/core/feeddownloader.cpp index 09f7fca8c..38f468fe7 100644 --- a/src/core/feeddownloader.cpp +++ b/src/core/feeddownloader.cpp @@ -18,12 +18,14 @@ #include "core/feeddownloader.h" #include "core/feedsmodelfeed.h" +#include "definitions/definitions.h" #include #include FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) { + qRegisterMetaType("FeedDownloadResults"); } FeedDownloader::~FeedDownloader() { @@ -36,8 +38,15 @@ void FeedDownloader::updateFeeds(const QList &feeds) { // Job starts now. emit started(); + FeedDownloadResults results; + for (int i = 0, total = feeds.size(); i < total; i++) { - feeds.at(i)->update(); + int updated_messages = feeds.at(i)->update(); + + if (updated_messages > 0) { + results.m_updatedFeeds.append(QPair(feeds.at(i)->title(), updated_messages)); + } + qDebug("Made progress in feed updates: %d/%d (id of feed is %d).", i + 1, total, feeds.at(i)->id()); emit progress(feeds.at(i), i + 1, total); } @@ -48,5 +57,19 @@ void FeedDownloader::updateFeeds(const QList &feeds) { // NOTE: This means that now "update lock" can be unlocked // and feeds can be added/edited/deleted and application // can eventually quit. - emit finished(); + emit finished(results); +} + + +QString FeedDownloadResults::getOverview(int how_many_feeds) { + qSort(m_updatedFeeds.begin(), m_updatedFeeds.end(), FeedDownloadResults::lessThan); + + QStringList result; + + // TODO: Maybe enhance the formatting of this output. + for (int i = 0, number_items_output = qMin(how_many_feeds, m_updatedFeeds.size()); i < number_items_output; i++) { + result.append(m_updatedFeeds.at(i).first + QSL(": ") + QString::number(m_updatedFeeds.at(i).second)); + } + + return result.join(QL1C('\n')); } diff --git a/src/core/feeddownloader.h b/src/core/feeddownloader.h index 365cb4012..8685ab3ee 100644 --- a/src/core/feeddownloader.h +++ b/src/core/feeddownloader.h @@ -20,9 +20,24 @@ #include +#include + class FeedsModelFeed; +struct FeedDownloadResults { + explicit FeedDownloadResults() : m_updatedFeeds(QList >()) { + } + + QString getOverview(int how_many_feeds); + + static bool lessThan(const QPair &lhs, const QPair &rhs) { + return lhs.second > rhs.second; + } + + QList > m_updatedFeeds; +}; + // This class offers means to "update" feeds // and "special" categories. // NOTE: This class is used within separate thread. @@ -47,7 +62,7 @@ class FeedDownloader : public QObject { // Emitted if all items from update queue are // processed. - void finished(); + void finished(FeedDownloadResults updated_feeds); // Emitted if any item is processed. // "Current" number indicates count of processed feeds diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 41f40369f..5134f5e20 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -251,10 +251,15 @@ void FeedMessageViewer::onFeedUpdatesProgress(FeedsModelFeed *feed, int current, tr("Updated feed '%1'").arg(feed->title())); } -void FeedMessageViewer::onFeedUpdatesFinished() { +void FeedMessageViewer::onFeedUpdatesFinished(FeedDownloadResults results) { qApp->feedUpdateLock()->unlock(); qApp->mainForm()->statusBar()->clearProgressFeeds(); m_messagesView->reloadSelections(true); + + if (!results.m_updatedFeeds.isEmpty()) { + // Now, inform about results via GUI message/notification. + qApp->showGuiMessage(tr("New messages downloaded"), results.getOverview(10), QSystemTrayIcon::Information); + } } void FeedMessageViewer::switchFeedComponentVisibility() { @@ -532,7 +537,7 @@ void FeedMessageViewer::updateFeeds(QList feeds) { connect(this, SIGNAL(feedsUpdateRequested(QList)), m_feedDownloader, SLOT(updateFeeds(QList))); connect(m_feedDownloaderThread, SIGNAL(finished()), m_feedDownloaderThread, SLOT(deleteLater())); - connect(m_feedDownloader, SIGNAL(finished()), this, SLOT(onFeedUpdatesFinished())); + connect(m_feedDownloader, SIGNAL(finished(FeedDownloadResults)), this, SLOT(onFeedUpdatesFinished(FeedDownloadResults))); connect(m_feedDownloader, SIGNAL(started()), this, SLOT(onFeedUpdatesStarted())); connect(m_feedDownloader, SIGNAL(progress(FeedsModelFeed*,int,int)), this, SLOT(onFeedUpdatesProgress(FeedsModelFeed*,int,int))); diff --git a/src/gui/feedmessageviewer.h b/src/gui/feedmessageviewer.h index 0772a9045..939c7cebb 100644 --- a/src/gui/feedmessageviewer.h +++ b/src/gui/feedmessageviewer.h @@ -21,6 +21,7 @@ #include "gui/tabcontent.h" #include "core/messagesmodel.h" +#include "core/feeddownloader.h" class WebBrowser; @@ -28,7 +29,6 @@ class MessagesView; class MessagesToolBar; class FeedsToolBar; class FeedsView; -class FeedDownloader; class DatabaseCleaner; class FeedsModelFeed; class QToolBar; @@ -110,7 +110,7 @@ class FeedMessageViewer : public TabContent { // Reacts on feed updates. void onFeedUpdatesStarted(); void onFeedUpdatesProgress(FeedsModelFeed *feed, int current, int total); - void onFeedUpdatesFinished(); + void onFeedUpdatesFinished(FeedDownloadResults results); // Switches visibility of feed list and related // toolbar. diff --git a/src/gui/notifications/notification.cpp b/src/gui/notifications/notification.cpp index c90f23dbd..cffb4dd6d 100644 --- a/src/gui/notifications/notification.cpp +++ b/src/gui/notifications/notification.cpp @@ -96,14 +96,18 @@ void Notification::cancel() { void Notification::updateGeometries() { // Calculate width and height of notification with given icon and text. + QFont bold_font = font(); + bold_font.setBold(true); + QFontMetrics bold_metrics(bold_font); + m_width = m_padding + - m_icon.width() + m_padding + /* contents */ qMax(TextFactory::stringWidth(m_title, fontMetrics()), + m_icon.width() + m_padding + /* contents */ qMax(TextFactory::stringWidth(m_title, bold_metrics), TextFactory::stringWidth(m_text, fontMetrics())) + m_padding; m_height = m_padding + /* contents */ qMax(m_icon.height(), - TextFactory::stringHeight(m_title, fontMetrics()) + m_padding + TextFactory::stringHeight(m_text, fontMetrics())) + + TextFactory::stringHeight(m_title, bold_metrics) + m_padding + TextFactory::stringHeight(m_text, fontMetrics())) + m_padding; // Calculate real position. @@ -242,4 +246,8 @@ void Notification::setupWidget() { // Window will be meant to be on top, but should not steal focus. setFocusPolicy(Qt::NoFocus); + + QFont font(font()); + font.setPointSize(font.pointSize() + 5); + setFont(font); }