Hard work on issue #12.

This commit is contained in:
Martin Rotter 2015-06-30 09:19:05 +02:00
parent 60b2aaa37a
commit 4c7b361452
5 changed files with 60 additions and 9 deletions

View File

@ -18,12 +18,14 @@
#include "core/feeddownloader.h"
#include "core/feedsmodelfeed.h"
#include "definitions/definitions.h"
#include <QThread>
#include <QDebug>
FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) {
qRegisterMetaType<FeedDownloadResults>("FeedDownloadResults");
}
FeedDownloader::~FeedDownloader() {
@ -36,8 +38,15 @@ void FeedDownloader::updateFeeds(const QList<FeedsModelFeed*> &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<QString,int>(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<FeedsModelFeed*> &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'));
}

View File

@ -20,9 +20,24 @@
#include <QObject>
#include <QPair>
class FeedsModelFeed;
struct FeedDownloadResults {
explicit FeedDownloadResults() : m_updatedFeeds(QList<QPair<QString,int> >()) {
}
QString getOverview(int how_many_feeds);
static bool lessThan(const QPair<QString,int> &lhs, const QPair<QString,int> &rhs) {
return lhs.second > rhs.second;
}
QList<QPair<QString,int> > 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

View File

@ -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<FeedsModelFeed *> feeds) {
connect(this, SIGNAL(feedsUpdateRequested(QList<FeedsModelFeed*>)), m_feedDownloader, SLOT(updateFeeds(QList<FeedsModelFeed*>)));
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)));

View File

@ -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.

View File

@ -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);
}