Refactored some common code from categories/feeds classes.

This commit is contained in:
Martin Rotter 2017-09-20 13:06:45 +02:00
parent 39f73a0d02
commit f10ee91194
21 changed files with 33 additions and 53 deletions

View file

@ -20,6 +20,7 @@
#include "miscellaneous/application.h"
#include "miscellaneous/databasequeries.h"
#include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/feed.h"
#include "services/abstract/serviceroot.h"
@ -70,3 +71,14 @@ void Category::updateCounts(bool including_total_count) {
bool Category::cleanMessages(bool clean_read_only) {
return getParentServiceRoot()->cleanFeeds(getSubTreeFeeds(), clean_read_only);
}
bool Category::markAsReadUnread(RootItem::ReadStatus status) {
ServiceRoot* service = getParentServiceRoot();
CacheForServiceRoot* cache = dynamic_cast<CacheForServiceRoot*>(service);
if (cache != nullptr) {
cache->addMessageStatesToCache(service->customIDSOfMessagesForItem(this), status);
}
return service->markFeedsReadUnread(getSubTreeFeeds(), status);
}

View file

@ -30,6 +30,7 @@ class Category : public RootItem {
void updateCounts(bool including_total_count);
bool cleanMessages(bool clean_read_only);
bool markAsReadUnread(ReadStatus status);
};
#endif // CATEGORY_H

View file

@ -23,6 +23,7 @@
#include "miscellaneous/databasequeries.h"
#include "miscellaneous/feedreader.h"
#include "miscellaneous/mutex.h"
#include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/recyclebin.h"
#include "services/abstract/serviceroot.h"
@ -218,6 +219,17 @@ bool Feed::cleanMessages(bool clean_read_only) {
return getParentServiceRoot()->cleanFeeds(QList<Feed*>() << this, clean_read_only);
}
bool Feed::markAsReadUnread(RootItem::ReadStatus status) {
ServiceRoot* service = getParentServiceRoot();
CacheForServiceRoot* cache = dynamic_cast<CacheForServiceRoot*>(service);
if (cache != nullptr) {
cache->addMessageStatesToCache(service->customIDSOfMessagesForItem(this), status);
}
return service->markFeedsReadUnread(QList<Feed*>() << this, status);
}
int Feed::updateMessages(const QList<Message>& messages, bool error_during_obtaining) {
QList<RootItem*> items_to_update;
int updated_messages = 0;

View file

@ -82,6 +82,7 @@ class Feed : public RootItem, public QRunnable {
// Runs update in thread (thread pooled).
void run();
bool markAsReadUnread(ReadStatus status);
bool cleanMessages(bool clean_read_only);
public slots:

View file

@ -24,6 +24,7 @@
#include "miscellaneous/databasequeries.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h"
#include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/category.h"
#include "services/abstract/feed.h"
#include "services/abstract/recyclebin.h"
@ -49,6 +50,12 @@ bool ServiceRoot::deleteViaGui() {
}
bool ServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
CacheForServiceRoot* cache = dynamic_cast<CacheForServiceRoot*>(this);
if (cache != nullptr) {
cache->addMessageStatesToCache(customIDSOfMessagesForItem(this), status);
}
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
if (DatabaseQueries::markAccountReadUnread(database, accountId(), status)) {

View file

@ -38,9 +38,4 @@ OwnCloudServiceRoot* OwnCloudCategory::serviceRoot() const {
return qobject_cast<OwnCloudServiceRoot*>(getParentServiceRoot());
}
bool OwnCloudCategory::markAsReadUnread(RootItem::ReadStatus status) {
serviceRoot()->addMessageStatesToCache(getParentServiceRoot()->customIDSOfMessagesForItem(this), status);
return serviceRoot()->markFeedsReadUnread(getSubTreeFeeds(), status);
}
OwnCloudCategory::~OwnCloudCategory() {}

View file

@ -31,8 +31,6 @@ class OwnCloudCategory : public Category {
explicit OwnCloudCategory(const QSqlRecord& record);
virtual ~OwnCloudCategory();
bool markAsReadUnread(ReadStatus status);
private:
OwnCloudServiceRoot* serviceRoot() const;
};

View file

@ -86,11 +86,6 @@ bool OwnCloudFeed::removeItself() {
return DatabaseQueries::deleteFeed(database, customId(), serviceRoot()->accountId());
}
bool OwnCloudFeed::markAsReadUnread(RootItem::ReadStatus status) {
serviceRoot()->addMessageStatesToCache(getParentServiceRoot()->customIDSOfMessagesForItem(this), status);
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
}
OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const {
return qobject_cast<OwnCloudServiceRoot*>(getParentServiceRoot());
}

View file

@ -39,8 +39,6 @@ class OwnCloudFeed : public Feed {
bool editItself(OwnCloudFeed* new_feed_data);
bool removeItself();
bool markAsReadUnread(ReadStatus status);
OwnCloudServiceRoot* serviceRoot() const;
private:

View file

@ -103,11 +103,6 @@ QString OwnCloudServiceRoot::code() const {
return OwnCloudServiceEntryPoint().code();
}
bool OwnCloudServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
addMessageStatesToCache(customIDSOfMessagesForItem(this), status);
return ServiceRoot::markAsReadUnread(status);
}
OwnCloudNetworkFactory* OwnCloudServiceRoot::network() const {
return m_network;
}

View file

@ -45,8 +45,6 @@ class OwnCloudServiceRoot : public ServiceRoot, public CacheForServiceRoot {
void start(bool freshly_activated);
void stop();
QString code() const;
bool markAsReadUnread(ReadStatus status);
OwnCloudNetworkFactory* network() const;
bool onBeforeSetMessagesRead(RootItem* selected_item, const QList<Message>& messages, ReadStatus read);

View file

@ -112,10 +112,6 @@ bool StandardCategory::deleteViaGui() {
}
}
bool StandardCategory::markAsReadUnread(ReadStatus status) {
return serviceRoot()->markFeedsReadUnread(getSubTreeFeeds(), status);
}
bool StandardCategory::removeItself() {
bool children_removed = true;

View file

@ -59,8 +59,6 @@ class StandardCategory : public Category {
bool editViaGui();
bool deleteViaGui();
bool markAsReadUnread(ReadStatus status);
// Removes category and all its children from persistent
// database.
bool removeItself();

View file

@ -106,10 +106,6 @@ bool StandardFeed::deleteViaGui() {
}
}
bool StandardFeed::markAsReadUnread(ReadStatus status) {
return serviceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
}
QVariant StandardFeed::data(int column, int role) const {
switch (role) {
case Qt::ToolTipRole:

View file

@ -69,8 +69,6 @@ class StandardFeed : public Feed {
bool editViaGui();
bool deleteViaGui();
bool markAsReadUnread(ReadStatus status);
QVariant data(int column, int role) const;
// Obtains data related to this feed.

View file

@ -43,8 +43,3 @@ TtRssCategory::~TtRssCategory() {}
TtRssServiceRoot* TtRssCategory::serviceRoot() const {
return qobject_cast<TtRssServiceRoot*>(getParentServiceRoot());
}
bool TtRssCategory::markAsReadUnread(RootItem::ReadStatus status) {
serviceRoot()->addMessageStatesToCache(serviceRoot()->customIDSOfMessagesForItem(this), status);
return true;
}

View file

@ -34,8 +34,6 @@ class TtRssCategory : public Category {
virtual ~TtRssCategory();
TtRssServiceRoot* serviceRoot() const;
bool markAsReadUnread(ReadStatus status);
};
#endif // TTRSSCATEGORY_H

View file

@ -78,11 +78,6 @@ bool TtRssFeed::deleteViaGui() {
}
}
bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) {
serviceRoot()->addMessageStatesToCache(getParentServiceRoot()->customIDSOfMessagesForItem(this), status);
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
}
bool TtRssFeed::editItself(TtRssFeed* new_feed_data) {
QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings);

View file

@ -40,8 +40,6 @@ class TtRssFeed : public Feed {
bool canBeDeleted() const;
bool deleteViaGui();
bool markAsReadUnread(ReadStatus status);
bool editItself(TtRssFeed* new_feed_data);
bool removeItself();

View file

@ -88,11 +88,6 @@ bool TtRssServiceRoot::deleteViaGui() {
}
}
bool TtRssServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
addMessageStatesToCache(customIDSOfMessagesForItem(this), status);
return ServiceRoot::markAsReadUnread(status);
}
bool TtRssServiceRoot::supportsFeedAdding() const {
return true;
}

View file

@ -42,7 +42,6 @@ class TtRssServiceRoot : public ServiceRoot, public CacheForServiceRoot {
bool canBeDeleted() const;
bool editViaGui();
bool deleteViaGui();
bool markAsReadUnread(ReadStatus status);
bool supportsFeedAdding() const;
bool supportsCategoryAdding() const;
QVariant data(int column, int role) const;