Hard work on issue #12.
This commit is contained in:
parent
60b2aaa37a
commit
4c7b361452
src
@ -18,12 +18,14 @@
|
|||||||
#include "core/feeddownloader.h"
|
#include "core/feeddownloader.h"
|
||||||
|
|
||||||
#include "core/feedsmodelfeed.h"
|
#include "core/feedsmodelfeed.h"
|
||||||
|
#include "definitions/definitions.h"
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) {
|
FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) {
|
||||||
|
qRegisterMetaType<FeedDownloadResults>("FeedDownloadResults");
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedDownloader::~FeedDownloader() {
|
FeedDownloader::~FeedDownloader() {
|
||||||
@ -36,8 +38,15 @@ void FeedDownloader::updateFeeds(const QList<FeedsModelFeed*> &feeds) {
|
|||||||
// Job starts now.
|
// Job starts now.
|
||||||
emit started();
|
emit started();
|
||||||
|
|
||||||
|
FeedDownloadResults results;
|
||||||
|
|
||||||
for (int i = 0, total = feeds.size(); i < total; i++) {
|
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());
|
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);
|
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
|
// NOTE: This means that now "update lock" can be unlocked
|
||||||
// and feeds can be added/edited/deleted and application
|
// and feeds can be added/edited/deleted and application
|
||||||
// can eventually quit.
|
// 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'));
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,24 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <QPair>
|
||||||
|
|
||||||
|
|
||||||
class FeedsModelFeed;
|
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
|
// This class offers means to "update" feeds
|
||||||
// and "special" categories.
|
// and "special" categories.
|
||||||
// NOTE: This class is used within separate thread.
|
// NOTE: This class is used within separate thread.
|
||||||
@ -47,7 +62,7 @@ class FeedDownloader : public QObject {
|
|||||||
|
|
||||||
// Emitted if all items from update queue are
|
// Emitted if all items from update queue are
|
||||||
// processed.
|
// processed.
|
||||||
void finished();
|
void finished(FeedDownloadResults updated_feeds);
|
||||||
|
|
||||||
// Emitted if any item is processed.
|
// Emitted if any item is processed.
|
||||||
// "Current" number indicates count of processed feeds
|
// "Current" number indicates count of processed feeds
|
||||||
|
@ -251,10 +251,15 @@ void FeedMessageViewer::onFeedUpdatesProgress(FeedsModelFeed *feed, int current,
|
|||||||
tr("Updated feed '%1'").arg(feed->title()));
|
tr("Updated feed '%1'").arg(feed->title()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedMessageViewer::onFeedUpdatesFinished() {
|
void FeedMessageViewer::onFeedUpdatesFinished(FeedDownloadResults results) {
|
||||||
qApp->feedUpdateLock()->unlock();
|
qApp->feedUpdateLock()->unlock();
|
||||||
qApp->mainForm()->statusBar()->clearProgressFeeds();
|
qApp->mainForm()->statusBar()->clearProgressFeeds();
|
||||||
m_messagesView->reloadSelections(true);
|
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() {
|
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(this, SIGNAL(feedsUpdateRequested(QList<FeedsModelFeed*>)), m_feedDownloader, SLOT(updateFeeds(QList<FeedsModelFeed*>)));
|
||||||
connect(m_feedDownloaderThread, SIGNAL(finished()), m_feedDownloaderThread, SLOT(deleteLater()));
|
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(started()), this, SLOT(onFeedUpdatesStarted()));
|
||||||
connect(m_feedDownloader, SIGNAL(progress(FeedsModelFeed*,int,int)), this, SLOT(onFeedUpdatesProgress(FeedsModelFeed*,int,int)));
|
connect(m_feedDownloader, SIGNAL(progress(FeedsModelFeed*,int,int)), this, SLOT(onFeedUpdatesProgress(FeedsModelFeed*,int,int)));
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "gui/tabcontent.h"
|
#include "gui/tabcontent.h"
|
||||||
|
|
||||||
#include "core/messagesmodel.h"
|
#include "core/messagesmodel.h"
|
||||||
|
#include "core/feeddownloader.h"
|
||||||
|
|
||||||
|
|
||||||
class WebBrowser;
|
class WebBrowser;
|
||||||
@ -28,7 +29,6 @@ class MessagesView;
|
|||||||
class MessagesToolBar;
|
class MessagesToolBar;
|
||||||
class FeedsToolBar;
|
class FeedsToolBar;
|
||||||
class FeedsView;
|
class FeedsView;
|
||||||
class FeedDownloader;
|
|
||||||
class DatabaseCleaner;
|
class DatabaseCleaner;
|
||||||
class FeedsModelFeed;
|
class FeedsModelFeed;
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
@ -110,7 +110,7 @@ class FeedMessageViewer : public TabContent {
|
|||||||
// Reacts on feed updates.
|
// Reacts on feed updates.
|
||||||
void onFeedUpdatesStarted();
|
void onFeedUpdatesStarted();
|
||||||
void onFeedUpdatesProgress(FeedsModelFeed *feed, int current, int total);
|
void onFeedUpdatesProgress(FeedsModelFeed *feed, int current, int total);
|
||||||
void onFeedUpdatesFinished();
|
void onFeedUpdatesFinished(FeedDownloadResults results);
|
||||||
|
|
||||||
// Switches visibility of feed list and related
|
// Switches visibility of feed list and related
|
||||||
// toolbar.
|
// toolbar.
|
||||||
|
@ -96,14 +96,18 @@ void Notification::cancel() {
|
|||||||
|
|
||||||
void Notification::updateGeometries() {
|
void Notification::updateGeometries() {
|
||||||
// Calculate width and height of notification with given icon and text.
|
// 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_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())) +
|
TextFactory::stringWidth(m_text, fontMetrics())) +
|
||||||
m_padding;
|
m_padding;
|
||||||
m_height = m_padding +
|
m_height = m_padding +
|
||||||
/* contents */
|
/* contents */
|
||||||
qMax(m_icon.height(),
|
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;
|
m_padding;
|
||||||
|
|
||||||
// Calculate real position.
|
// Calculate real position.
|
||||||
@ -242,4 +246,8 @@ void Notification::setupWidget() {
|
|||||||
|
|
||||||
// Window will be meant to be on top, but should not steal focus.
|
// Window will be meant to be on top, but should not steal focus.
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
|
|
||||||
|
QFont font(font());
|
||||||
|
font.setPointSize(font.pointSize() + 5);
|
||||||
|
setFont(font);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user