Refactoring, common code moved to superclasses.

This commit is contained in:
Martin Rotter 2017-09-20 11:58:30 +02:00
parent e758511cc2
commit 39f73a0d02
15 changed files with 14 additions and 39 deletions

View File

@ -66,3 +66,7 @@ void Category::updateCounts(bool including_total_count) {
} }
} }
} }
bool Category::cleanMessages(bool clean_read_only) {
return getParentServiceRoot()->cleanFeeds(getSubTreeFeeds(), clean_read_only);
}

View File

@ -29,6 +29,7 @@ class Category : public RootItem {
virtual ~Category(); virtual ~Category();
void updateCounts(bool including_total_count); void updateCounts(bool including_total_count);
bool cleanMessages(bool clean_read_only);
}; };
#endif // CATEGORY_H #endif // CATEGORY_H

View File

@ -214,6 +214,10 @@ void Feed::run() {
emit messagesObtained(msgs, error_during_obtaining); emit messagesObtained(msgs, error_during_obtaining);
} }
bool Feed::cleanMessages(bool clean_read_only) {
return getParentServiceRoot()->cleanFeeds(QList<Feed*>() << this, clean_read_only);
}
int Feed::updateMessages(const QList<Message>& messages, bool error_during_obtaining) { int Feed::updateMessages(const QList<Message>& messages, bool error_during_obtaining) {
QList<RootItem*> items_to_update; QList<RootItem*> items_to_update;
int updated_messages = 0; int updated_messages = 0;

View File

@ -82,6 +82,8 @@ class Feed : public RootItem, public QRunnable {
// Runs update in thread (thread pooled). // Runs update in thread (thread pooled).
void run(); void run();
bool cleanMessages(bool clean_read_only);
public slots: public slots:
void updateCounts(bool including_total_count); void updateCounts(bool including_total_count);
int updateMessages(const QList<Message>& messages, bool error_during_obtaining); int updateMessages(const QList<Message>& messages, bool error_during_obtaining);

View File

@ -73,8 +73,7 @@ class RootItem;
class OwnCloudGetFeedsCategoriesResponse { class OwnCloudGetFeedsCategoriesResponse {
public: public:
explicit OwnCloudGetFeedsCategoriesResponse(const QString& raw_categories = QString(), explicit OwnCloudGetFeedsCategoriesResponse(const QString& raw_categories = QString(), const QString& raw_feeds = QString());
const QString& raw_feeds = QString());
virtual ~OwnCloudGetFeedsCategoriesResponse(); virtual ~OwnCloudGetFeedsCategoriesResponse();
// Returns tree of feeds/categories. // Returns tree of feeds/categories.

View File

@ -91,10 +91,6 @@ bool OwnCloudFeed::markAsReadUnread(RootItem::ReadStatus status) {
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status); return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
} }
bool OwnCloudFeed::cleanMessages(bool clear_only_read) {
return getParentServiceRoot()->cleanFeeds(QList<Feed*>() << this, clear_only_read);
}
OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const { OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const {
return qobject_cast<OwnCloudServiceRoot*>(getParentServiceRoot()); return qobject_cast<OwnCloudServiceRoot*>(getParentServiceRoot());
} }

View File

@ -40,7 +40,6 @@ class OwnCloudFeed : public Feed {
bool removeItself(); bool removeItself();
bool markAsReadUnread(ReadStatus status); bool markAsReadUnread(ReadStatus status);
bool cleanMessages(bool clear_only_read);
OwnCloudServiceRoot* serviceRoot() const; OwnCloudServiceRoot* serviceRoot() const;

View File

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

View File

@ -60,7 +60,6 @@ class StandardCategory : public Category {
bool deleteViaGui(); bool deleteViaGui();
bool markAsReadUnread(ReadStatus status); bool markAsReadUnread(ReadStatus status);
bool cleanMessages(bool clean_read_only);
// Removes category and all its children from persistent // Removes category and all its children from persistent
// database. // database.

View File

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

View File

@ -70,7 +70,6 @@ class StandardFeed : public Feed {
bool deleteViaGui(); bool deleteViaGui();
bool markAsReadUnread(ReadStatus status); bool markAsReadUnread(ReadStatus status);
bool cleanMessages(bool clean_read_only);
QVariant data(int column, int role) const; QVariant data(int column, int role) const;

View File

@ -45,20 +45,6 @@ TtRssServiceRoot* TtRssCategory::serviceRoot() const {
} }
bool TtRssCategory::markAsReadUnread(RootItem::ReadStatus status) { bool TtRssCategory::markAsReadUnread(RootItem::ReadStatus status) {
const QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this); serviceRoot()->addMessageStatesToCache(serviceRoot()->customIDSOfMessagesForItem(this), status);
TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread, return true;
status == RootItem::Unread ?
UpdateArticle::SetToTrue :
UpdateArticle::SetToFalse);
if (serviceRoot()->network()->lastError() != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
return false;
}
else {
return serviceRoot()->markFeedsReadUnread(getSubTreeFeeds(), status);
}
}
bool TtRssCategory::cleanMessages(bool clear_only_read) {
return serviceRoot()->cleanFeeds(getSubTreeFeeds(), clear_only_read);
} }

View File

@ -36,7 +36,6 @@ class TtRssCategory : public Category {
TtRssServiceRoot* serviceRoot() const; TtRssServiceRoot* serviceRoot() const;
bool markAsReadUnread(ReadStatus status); bool markAsReadUnread(ReadStatus status);
bool cleanMessages(bool clear_only_read);
}; };
#endif // TTRSSCATEGORY_H #endif // TTRSSCATEGORY_H

View File

@ -83,10 +83,6 @@ bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) {
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status); return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
} }
bool TtRssFeed::cleanMessages(bool clear_only_read) {
return getParentServiceRoot()->cleanFeeds(QList<Feed*>() << this, clear_only_read);
}
bool TtRssFeed::editItself(TtRssFeed* new_feed_data) { bool TtRssFeed::editItself(TtRssFeed* new_feed_data) {
QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings);

View File

@ -41,7 +41,6 @@ class TtRssFeed : public Feed {
bool deleteViaGui(); bool deleteViaGui();
bool markAsReadUnread(ReadStatus status); bool markAsReadUnread(ReadStatus status);
bool cleanMessages(bool clear_only_read);
bool editItself(TtRssFeed* new_feed_data); bool editItself(TtRssFeed* new_feed_data);
bool removeItself(); bool removeItself();