diff --git a/src/librssguard/core/feeddownloader.cpp b/src/librssguard/core/feeddownloader.cpp index e0926f460..6e0715c27 100644 --- a/src/librssguard/core/feeddownloader.cpp +++ b/src/librssguard/core/feeddownloader.cpp @@ -44,7 +44,7 @@ void FeedDownloader::updateAvailableFeeds() { qDebugNN << LOGSEC_FEEDDOWNLOADER << "Saving cache for feed with DB ID '" << feed->id() << "' and title '" << feed->title() << "'."; - cache->saveAllCachedData(); + cache->saveAllCachedData(false); } if (m_stopCacheSynchronization) { @@ -66,7 +66,7 @@ void FeedDownloader::synchronizeAccountCaches(const QList& for (CacheForServiceRoot* cache : caches) { qDebugNN << LOGSEC_FEEDDOWNLOADER << "Synchronizing cache back to server on thread" << QUOTE_W_SPACE_DOT(QThread::currentThreadId()); - cache->saveAllCachedData(); + cache->saveAllCachedData(false); if (m_stopCacheSynchronization) { qWarningNN << LOGSEC_FEEDDOWNLOADER << "Aborting cache synchronization."; diff --git a/src/librssguard/services/abstract/cacheforserviceroot.h b/src/librssguard/services/abstract/cacheforserviceroot.h index d02e92397..c9fd8d605 100644 --- a/src/librssguard/services/abstract/cacheforserviceroot.h +++ b/src/librssguard/services/abstract/cacheforserviceroot.h @@ -22,7 +22,7 @@ class CacheForServiceRoot { public: explicit CacheForServiceRoot(); - virtual void saveAllCachedData() = 0; + virtual void saveAllCachedData(bool ignore_errors) = 0; void addLabelsAssignmentsToCache(const QStringList& ids_of_messages, const QString& lbl_custom_id, bool assign); void addLabelsAssignmentsToCache(const QList& ids_of_messages, Label* lbl, bool assign); diff --git a/src/librssguard/services/abstract/gui/formaccountdetails.cpp b/src/librssguard/services/abstract/gui/formaccountdetails.cpp index 8d494b794..ddbad6c89 100644 --- a/src/librssguard/services/abstract/gui/formaccountdetails.cpp +++ b/src/librssguard/services/abstract/gui/formaccountdetails.cpp @@ -16,7 +16,17 @@ FormAccountDetails::FormAccountDetails(const QIcon& icon, QWidget* parent) : QDi createConnections(); } -void FormAccountDetails::apply() {} +void FormAccountDetails::apply() { + if (m_account != nullptr) { + // Perform last-time operations before account is changed. + auto* cached_account = dynamic_cast(m_account); + + if (cached_account != nullptr) { + qWarningNN << LOGSEC_CORE << "Last-time account cache saving before account gets changed."; + cached_account->saveAllCachedData(true); + } + } +} void FormAccountDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) { m_ui.m_tabWidget->insertTab(index, custom_tab, title); diff --git a/src/librssguard/services/abstract/serviceroot.cpp b/src/librssguard/services/abstract/serviceroot.cpp index 90afa03f6..4b288208d 100644 --- a/src/librssguard/services/abstract/serviceroot.cpp +++ b/src/librssguard/services/abstract/serviceroot.cpp @@ -94,7 +94,7 @@ QList ServiceRoot::serviceMenu() { auto* act_sync_cache = new QAction(qApp->icons()->fromTheme(QSL("view-refresh")), tr("Synchronize message cache"), this); connect(act_sync_cache, &QAction::triggered, this, [cache]() { - cache->saveAllCachedData(); + cache->saveAllCachedData(false); }); m_serviceMenu.append(act_sync_cache); diff --git a/src/librssguard/services/gmail/gmailserviceroot.cpp b/src/librssguard/services/gmail/gmailserviceroot.cpp index 9539bbd47..c8c3ac8b1 100644 --- a/src/librssguard/services/gmail/gmailserviceroot.cpp +++ b/src/librssguard/services/gmail/gmailserviceroot.cpp @@ -205,7 +205,7 @@ QString GmailServiceRoot::additionalTooltip() const { network()->oauth()->tokensExpireIn().toString() : QSL("-")); } -void GmailServiceRoot::saveAllCachedData() { +void GmailServiceRoot::saveAllCachedData(bool ignore_errors) { auto msg_cache = takeMessageCache(); QMapIterator i(msg_cache.m_cachedStatesRead); @@ -216,7 +216,7 @@ void GmailServiceRoot::saveAllCachedData() { QStringList ids = i.value(); if (!ids.isEmpty()) { - if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError) { + if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) { addMessageStatesToCache(ids, key); } } @@ -237,7 +237,7 @@ void GmailServiceRoot::saveAllCachedData() { custom_ids.append(msg.m_customId); } - if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError) { + if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) { addMessageStatesToCache(messages, key); } } diff --git a/src/librssguard/services/gmail/gmailserviceroot.h b/src/librssguard/services/gmail/gmailserviceroot.h index 6c701a2cd..b3b4e4cb6 100644 --- a/src/librssguard/services/gmail/gmailserviceroot.h +++ b/src/librssguard/services/gmail/gmailserviceroot.h @@ -33,7 +33,7 @@ class GmailServiceRoot : public ServiceRoot, public CacheForServiceRoot { virtual void start(bool freshly_activated); virtual QString code() const; virtual QString additionalTooltip() const; - virtual void saveAllCachedData(); + virtual void saveAllCachedData(bool ignore_errors); void updateTitle(); diff --git a/src/librssguard/services/inoreader/inoreaderserviceroot.cpp b/src/librssguard/services/inoreader/inoreaderserviceroot.cpp index 5642aba4d..4d0f51217 100644 --- a/src/librssguard/services/inoreader/inoreaderserviceroot.cpp +++ b/src/librssguard/services/inoreader/inoreaderserviceroot.cpp @@ -148,7 +148,7 @@ RootItem* InoreaderServiceRoot::obtainNewTreeForSyncIn() const { } } -void InoreaderServiceRoot::saveAllCachedData() { +void InoreaderServiceRoot::saveAllCachedData(bool ignore_errors) { auto msg_cache = takeMessageCache(); QMapIterator i(msg_cache.m_cachedStatesRead); @@ -159,7 +159,7 @@ void InoreaderServiceRoot::saveAllCachedData() { QStringList ids = i.value(); if (!ids.isEmpty()) { - if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError) { + if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) { addMessageStatesToCache(ids, key); } } @@ -180,7 +180,7 @@ void InoreaderServiceRoot::saveAllCachedData() { custom_ids.append(msg.m_customId); } - if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError) { + if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) { addMessageStatesToCache(messages, key); } } @@ -195,7 +195,7 @@ void InoreaderServiceRoot::saveAllCachedData() { QStringList messages = k.value(); if (!messages.isEmpty()) { - if (network()->editLabels(label_custom_id, true, messages) != QNetworkReply::NetworkError::NoError) { + if (network()->editLabels(label_custom_id, true, messages) != QNetworkReply::NetworkError::NoError && !ignore_errors) { addLabelsAssignmentsToCache(messages, label_custom_id, true); } } @@ -210,7 +210,7 @@ void InoreaderServiceRoot::saveAllCachedData() { QStringList messages = l.value(); if (!messages.isEmpty()) { - if (network()->editLabels(label_custom_id, false, messages) != QNetworkReply::NetworkError::NoError) { + if (network()->editLabels(label_custom_id, false, messages) != QNetworkReply::NetworkError::NoError && !ignore_errors) { addLabelsAssignmentsToCache(messages, label_custom_id, false); } } diff --git a/src/librssguard/services/inoreader/inoreaderserviceroot.h b/src/librssguard/services/inoreader/inoreaderserviceroot.h index d1ff46b59..cbdd997c6 100644 --- a/src/librssguard/services/inoreader/inoreaderserviceroot.h +++ b/src/librssguard/services/inoreader/inoreaderserviceroot.h @@ -31,7 +31,7 @@ class InoreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot { virtual void start(bool freshly_activated); virtual QString code() const; virtual QString additionalTooltip() const; - virtual void saveAllCachedData(); + virtual void saveAllCachedData(bool ignore_errors); void updateTitle(); diff --git a/src/librssguard/services/owncloud/owncloudserviceroot.cpp b/src/librssguard/services/owncloud/owncloudserviceroot.cpp index 50bf5404c..9225a2904 100644 --- a/src/librssguard/services/owncloud/owncloudserviceroot.cpp +++ b/src/librssguard/services/owncloud/owncloudserviceroot.cpp @@ -80,7 +80,7 @@ OwnCloudNetworkFactory* OwnCloudServiceRoot::network() const { return m_network; } -void OwnCloudServiceRoot::saveAllCachedData() { +void OwnCloudServiceRoot::saveAllCachedData(bool ignore_errors) { auto msg_cache = takeMessageCache(); QMapIterator i(msg_cache.m_cachedStatesRead); @@ -93,7 +93,7 @@ void OwnCloudServiceRoot::saveAllCachedData() { if (!ids.isEmpty()) { auto res = network()->markMessagesRead(key, ids); - if (res.first != QNetworkReply::NetworkError::NoError) { + if (!ignore_errors && res.first != QNetworkReply::NetworkError::NoError) { addMessageStatesToCache(ids, key); } } @@ -117,7 +117,7 @@ void OwnCloudServiceRoot::saveAllCachedData() { auto res = network()->markMessagesStarred(key, feed_ids, guid_hashes); - if (res.first != QNetworkReply::NetworkError::NoError) { + if (!ignore_errors && res.first != QNetworkReply::NetworkError::NoError) { addMessageStatesToCache(messages, key); } } diff --git a/src/librssguard/services/owncloud/owncloudserviceroot.h b/src/librssguard/services/owncloud/owncloudserviceroot.h index 917e7e205..4d539b7a6 100644 --- a/src/librssguard/services/owncloud/owncloudserviceroot.h +++ b/src/librssguard/services/owncloud/owncloudserviceroot.h @@ -27,7 +27,7 @@ class OwnCloudServiceRoot : public ServiceRoot, public CacheForServiceRoot { virtual bool supportsCategoryAdding() const; virtual void start(bool freshly_activated); virtual QString code() const; - virtual void saveAllCachedData(); + virtual void saveAllCachedData(bool ignore_errors); OwnCloudNetworkFactory* network() const; diff --git a/src/librssguard/services/tt-rss/gui/formeditttrssaccount.cpp b/src/librssguard/services/tt-rss/gui/formeditttrssaccount.cpp index 473b7c135..23673b5cc 100644 --- a/src/librssguard/services/tt-rss/gui/formeditttrssaccount.cpp +++ b/src/librssguard/services/tt-rss/gui/formeditttrssaccount.cpp @@ -28,6 +28,8 @@ TtRssServiceRoot* FormEditTtRssAccount::addEditAccount(TtRssServiceRoot* account } void FormEditTtRssAccount::apply() { + FormAccountDetails::apply(); + bool editing_account = true; if (m_account == nullptr) { diff --git a/src/librssguard/services/tt-rss/ttrssserviceroot.cpp b/src/librssguard/services/tt-rss/ttrssserviceroot.cpp index 8797fb654..4b5b073de 100644 --- a/src/librssguard/services/tt-rss/ttrssserviceroot.cpp +++ b/src/librssguard/services/tt-rss/ttrssserviceroot.cpp @@ -117,7 +117,7 @@ bool TtRssServiceRoot::canBeDeleted() const { return true; } -void TtRssServiceRoot::saveAllCachedData() { +void TtRssServiceRoot::saveAllCachedData(bool ignore_errors) { auto msg_cache = takeMessageCache(); QMapIterator i(msg_cache.m_cachedStatesRead); @@ -134,7 +134,7 @@ void TtRssServiceRoot::saveAllCachedData() { ? UpdateArticle::Mode::SetToTrue : UpdateArticle::Mode::SetToFalse); - if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) { + if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) { addMessageStatesToCache(ids, key); } } @@ -156,7 +156,7 @@ void TtRssServiceRoot::saveAllCachedData() { ? UpdateArticle::Mode::SetToTrue : UpdateArticle::Mode::SetToFalse); - if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) { + if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) { addMessageStatesToCache(messages, key); } } @@ -173,7 +173,7 @@ void TtRssServiceRoot::saveAllCachedData() { if (!messages.isEmpty()) { auto res = network()->setArticleLabel(messages, label_custom_id, true); - if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) { + if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) { addLabelsAssignmentsToCache(messages, label_custom_id, true); } } @@ -190,7 +190,7 @@ void TtRssServiceRoot::saveAllCachedData() { if (!messages.isEmpty()) { auto res = network()->setArticleLabel(messages, label_custom_id, false); - if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) { + if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) { addLabelsAssignmentsToCache(messages, label_custom_id, false); } } diff --git a/src/librssguard/services/tt-rss/ttrssserviceroot.h b/src/librssguard/services/tt-rss/ttrssserviceroot.h index 94f0bdc4d..2792c7886 100644 --- a/src/librssguard/services/tt-rss/ttrssserviceroot.h +++ b/src/librssguard/services/tt-rss/ttrssserviceroot.h @@ -32,7 +32,7 @@ class TtRssServiceRoot : public ServiceRoot, public CacheForServiceRoot { virtual bool supportsCategoryAdding() const; virtual void addNewFeed(RootItem* selected_item, const QString& url = QString()); virtual QString additionalTooltip() const; - virtual void saveAllCachedData(); + virtual void saveAllCachedData(bool ignore_errors); // Access to network. TtRssNetworkFactory* network() const;