Fixing selections.

This commit is contained in:
Martin Rotter 2015-05-04 18:25:00 +02:00
parent 48a8763606
commit 1df7ce45e3
5 changed files with 27 additions and 6 deletions

View File

@ -23,7 +23,7 @@
#include <QDebug> #include <QDebug>
FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) { FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent), m_updateAbortionRequested(false) {
} }
FeedDownloader::~FeedDownloader() { FeedDownloader::~FeedDownloader() {
@ -33,10 +33,20 @@ FeedDownloader::~FeedDownloader() {
void FeedDownloader::updateFeeds(const QList<FeedsModelFeed*> &feeds) { void FeedDownloader::updateFeeds(const QList<FeedsModelFeed*> &feeds) {
qDebug().nospace() << "Performing feed updates in thread: \'" << QThread::currentThreadId() << "\'."; qDebug().nospace() << "Performing feed updates in thread: \'" << QThread::currentThreadId() << "\'.";
if (m_updateAbortionRequested) {
m_updateAbortionRequested = false;
}
// Job starts now. // Job starts now.
emit started(); emit started();
for (int i = 0, total = feeds.size(); i < total; i++) { for (int i = 0, total = feeds.size(); i < total; i++) {
if (m_updateAbortionRequested) {
m_updateAbortionRequested = false;
qWarning("Interruption of feeds update process was requested. Interrupting it now.");
break;
}
feeds.at(i)->update(); feeds.at(i)->update();
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);
@ -50,3 +60,7 @@ void FeedDownloader::updateFeeds(const QList<FeedsModelFeed*> &feeds) {
// can eventually quit. // can eventually quit.
emit finished(); emit finished();
} }
void FeedDownloader::abortOngoingUpdate() {
m_updateAbortionRequested = true;
}

View File

@ -41,6 +41,9 @@ class FeedDownloader : public QObject {
// Appropriate signals are emitted. // Appropriate signals are emitted.
void updateFeeds(const QList<FeedsModelFeed*> &feeds); void updateFeeds(const QList<FeedsModelFeed*> &feeds);
// Aborts ongoing message if there is any.
void abortOngoingUpdate();
signals: signals:
// Emitted if feed updates started. // Emitted if feed updates started.
void started(); void started();
@ -54,6 +57,9 @@ class FeedDownloader : public QObject {
// and "total" number indicates total number of feeds // and "total" number indicates total number of feeds
// which were in the initial queue. // which were in the initial queue.
void progress(FeedsModelFeed *feed, int current, int total); void progress(FeedsModelFeed *feed, int current, int total);
private:
bool m_updateAbortionRequested;
}; };
#endif // FEEDDOWNLOADER_H #endif // FEEDDOWNLOADER_H

View File

@ -34,19 +34,19 @@ FeedsSelection::~FeedsSelection() {
FeedsSelection::SelectionMode FeedsSelection::mode() { FeedsSelection::SelectionMode FeedsSelection::mode() {
if (m_selectedItem == NULL) { if (m_selectedItem == NULL) {
return SelectionMode::NoMode; return FeedsSelection::NoMode;
} }
switch (m_selectedItem->kind()) { switch (m_selectedItem->kind()) {
case FeedsModelRootItem::RecycleBin: case FeedsModelRootItem::RecycleBin:
return SelectionMode::MessagesFromRecycleBin; return FeedsSelection::MessagesFromRecycleBin;
case FeedsModelRootItem::Category: case FeedsModelRootItem::Category:
case FeedsModelRootItem::Feed: case FeedsModelRootItem::Feed:
return SelectionMode::MessagesFromFeeds; return FeedsSelection::MessagesFromFeeds;
default: default:
return SelectionMode::NoMode; return FeedsSelection::NoMode;
} }
} }

View File

@ -19,7 +19,7 @@
#define FEEDSSELECTION_H #define FEEDSSELECTION_H
#include <QString> #include <QString>
#include <QObject> #include <QMetaType>
class FeedsModelRootItem; class FeedsModelRootItem;

View File

@ -123,6 +123,7 @@ void FeedMessageViewer::quit() {
m_feedsView->quit(); m_feedsView->quit();
qDebug("Quitting feed downloader thread."); qDebug("Quitting feed downloader thread.");
m_feedDownloader->abortOngoingUpdate();
m_feedDownloaderThread->quit(); m_feedDownloaderThread->quit();
m_feedDownloaderThread->wait(); m_feedDownloaderThread->wait();