diff --git a/src/core/feeddownloader.cpp b/src/core/feeddownloader.cpp index 564548959..69952cb1d 100755 --- a/src/core/feeddownloader.cpp +++ b/src/core/feeddownloader.cpp @@ -88,7 +88,7 @@ void FeedDownloader::stopRunningUpdate() { m_feeds.clear(); } -void FeedDownloader::oneFeedUpdateFinished(const QList &messages) { +void FeedDownloader::oneFeedUpdateFinished(const QList &messages, bool error_during_obtaining) { QMutexLocker locker(m_mutex); m_feedsUpdated++; @@ -106,7 +106,7 @@ void FeedDownloader::oneFeedUpdateFinished(const QList &messages) { << feed->id() << " in thread: \'" << QThread::currentThreadId() << "\'."; - int updated_messages = feed->updateMessages(messages); + int updated_messages = feed->updateMessages(messages, error_during_obtaining); /* QMetaObject::invokeMethod(feed, "updateMessages", Qt::BlockingQueuedConnection, diff --git a/src/core/feeddownloader.h b/src/core/feeddownloader.h index 882a7854a..8c4ec24f7 100755 --- a/src/core/feeddownloader.h +++ b/src/core/feeddownloader.h @@ -71,7 +71,7 @@ class FeedDownloader : public QObject { void stopRunningUpdate(); private slots: - void oneFeedUpdateFinished(const QList &messages); + void oneFeedUpdateFinished(const QList &messages, bool error_during_obtaining); signals: // Emitted if feed updates started. diff --git a/src/services/abstract/feed.cpp b/src/services/abstract/feed.cpp index 3becdd061..d97d12822 100755 --- a/src/services/abstract/feed.cpp +++ b/src/services/abstract/feed.cpp @@ -50,7 +50,7 @@ QVariant Feed::data(int column, int role) const { case NewMessages: return QColor(Qt::blue); - case Error: + case NetworkError: case ParsingError: case OtherError: return QColor(Qt::red); @@ -146,44 +146,44 @@ void Feed::run() { << customId() << " in thread: \'" << QThread::currentThreadId() << "\'."; - QList msgs = obtainNewMessages(); - emit messagesObtained(msgs); + bool error_during_obtaining; + QList msgs = obtainNewMessages(&error_during_obtaining); + emit messagesObtained(msgs, error_during_obtaining); } -int Feed::updateMessages(const QList &messages) { +int Feed::updateMessages(const QList &messages, bool error_during_obtaining) { + QList items_to_update; + int updated_messages = 0; bool is_main_thread = QThread::currentThread() == qApp->thread(); qDebug("Updating messages in DB. Main thread: '%s'.", qPrintable(is_main_thread ? "true." : "false.")); - int custom_id = customId(); - int account_id = getParentServiceRoot()->accountId(); - bool anything_updated = false; - bool ok; - QSqlDatabase database = is_main_thread ? - qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) : - qApp->database()->connection(QSL("feed_upd"), DatabaseFactory::FromSettings); - int updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(), &anything_updated, &ok); - - if (ok) { - if (updated_messages > 0) { - setStatus(NewMessages); + if (!error_during_obtaining) { + bool anything_updated = false; + bool ok = true; + + if (!messages.isEmpty()) { + int custom_id = customId(); + int account_id = getParentServiceRoot()->accountId(); + QSqlDatabase database = is_main_thread ? + qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) : + qApp->database()->connection(QSL("feed_upd"), DatabaseFactory::FromSettings); + updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(), &anything_updated, &ok); } - else { - setStatus(Normal); - } - - QList items_to_update; - - updateCounts(true); - items_to_update.append(this); - - if (getParentServiceRoot()->recycleBin() != nullptr && anything_updated) { - getParentServiceRoot()->recycleBin()->updateCounts(true); - items_to_update.append(getParentServiceRoot()->recycleBin()); + + if (ok) { + setStatus(updated_messages > 0 ? NewMessages : Normal); + updateCounts(true); + + if (getParentServiceRoot()->recycleBin() != nullptr && anything_updated) { + getParentServiceRoot()->recycleBin()->updateCounts(true); + items_to_update.append(getParentServiceRoot()->recycleBin()); + } } - - getParentServiceRoot()->itemChanged(items_to_update); } + + items_to_update.append(this); + getParentServiceRoot()->itemChanged(items_to_update); return updated_messages; } diff --git a/src/services/abstract/feed.h b/src/services/abstract/feed.h index af3ebf105..178fb94a7 100755 --- a/src/services/abstract/feed.h +++ b/src/services/abstract/feed.h @@ -44,7 +44,7 @@ class Feed : public RootItem, public QRunnable { enum Status { Normal = 0, NewMessages = 1, - Error = 2, + NetworkError = 2, ParsingError = 3, OtherError = 4 }; @@ -83,14 +83,14 @@ class Feed : public RootItem, public QRunnable { public slots: void updateCounts(bool including_total_count); - int updateMessages(const QList &messages); + int updateMessages(const QList &messages, bool error_during_obtaining); private: // Performs synchronous obtaining of new messages for this feed. - virtual QList obtainNewMessages() = 0; + virtual QList obtainNewMessages(bool *error_during_obtaining) = 0; signals: - void messagesObtained(QList messages); + void messagesObtained(QList messages, bool error_during_obtaining); private: QString m_url; diff --git a/src/services/owncloud/owncloudfeed.cpp b/src/services/owncloud/owncloudfeed.cpp index 396ce6158..a4b49dd2e 100755 --- a/src/services/owncloud/owncloudfeed.cpp +++ b/src/services/owncloud/owncloudfeed.cpp @@ -108,15 +108,17 @@ OwnCloudServiceRoot *OwnCloudFeed::serviceRoot() const { return qobject_cast(getParentServiceRoot()); } -QList OwnCloudFeed::obtainNewMessages() { +QList OwnCloudFeed::obtainNewMessages(bool *error_during_obtaining) { OwnCloudGetMessagesResponse messages = serviceRoot()->network()->getMessages(customId()); if (serviceRoot()->network()->lastError() != QNetworkReply::NoError) { - setStatus(Feed::Error); + setStatus(Feed::NetworkError); + *error_during_obtaining = true; serviceRoot()->itemChanged(QList() << this); return QList(); } else { + *error_during_obtaining = false; return messages.messages(); } diff --git a/src/services/owncloud/owncloudfeed.h b/src/services/owncloud/owncloudfeed.h index b13fdec2f..83ab8ddd7 100755 --- a/src/services/owncloud/owncloudfeed.h +++ b/src/services/owncloud/owncloudfeed.h @@ -45,7 +45,7 @@ class OwnCloudFeed : public Feed { OwnCloudServiceRoot *serviceRoot() const; private: - QList obtainNewMessages(); + QList obtainNewMessages(bool *error_during_obtaining); }; #endif // OWNCLOUDFEED_H diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index 4749083ac..fb66458af 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -430,7 +430,7 @@ bool StandardFeed::editItself(StandardFeed *new_feed_data) { return true; } -QList StandardFeed::obtainNewMessages() { +QList StandardFeed::obtainNewMessages(bool *error_during_obtaining) { QByteArray feed_contents; int download_timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt(); m_networkError = NetworkFactory::downloadFeedFile(url(), download_timeout, feed_contents, @@ -438,11 +438,13 @@ QList StandardFeed::obtainNewMessages() { if (m_networkError != QNetworkReply::NoError) { qWarning("Error during fetching of new messages for feed '%s' (id %d).", qPrintable(url()), id()); - setStatus(Error); + setStatus(NetworkError); + *error_during_obtaining = true; return QList(); } else if (status() != NewMessages) { setStatus(Normal); + *error_during_obtaining = false; } // Encode downloaded data for further parsing. @@ -507,4 +509,6 @@ StandardFeed::StandardFeed(const QSqlRecord &record) : Feed(nullptr) { setAutoUpdateType(static_cast(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt())); setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt()); + + m_networkError = QNetworkReply::NoError; } diff --git a/src/services/standard/standardfeed.h b/src/services/standard/standardfeed.h index 7a471e6a9..036416c23 100755 --- a/src/services/standard/standardfeed.h +++ b/src/services/standard/standardfeed.h @@ -142,7 +142,7 @@ class StandardFeed : public Feed { void fetchMetadataForItself(); private: - QList obtainNewMessages(); + QList obtainNewMessages(bool *error_during_obtaining); private: bool m_passwordProtected; diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index 7740de265..ffa546116 100755 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -156,7 +156,7 @@ bool TtRssFeed::editItself(TtRssFeed *new_feed_data) { } } -QList TtRssFeed::obtainNewMessages() { +QList TtRssFeed::obtainNewMessages(bool *error_during_obtaining) { QList messages; int newly_added_messages = 0; int limit = MAX_MESSAGES; @@ -167,7 +167,8 @@ QList TtRssFeed::obtainNewMessages() { true, true, false); if (serviceRoot()->network()->lastError() != QNetworkReply::NoError) { - setStatus(Feed::Error); + setStatus(Feed::NetworkError); + *error_during_obtaining = true; serviceRoot()->itemChanged(QList() << this); return QList(); } @@ -181,6 +182,7 @@ QList TtRssFeed::obtainNewMessages() { } while (newly_added_messages > 0); + *error_during_obtaining = false; return messages; } diff --git a/src/services/tt-rss/ttrssfeed.h b/src/services/tt-rss/ttrssfeed.h index 817f05811..e1c7f55c9 100755 --- a/src/services/tt-rss/ttrssfeed.h +++ b/src/services/tt-rss/ttrssfeed.h @@ -47,7 +47,7 @@ class TtRssFeed : public Feed { bool removeItself(); private: - QList obtainNewMessages(); + QList obtainNewMessages(bool *error_during_obtaining); }; #endif // TTRSSFEED_H