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();
void updateCounts(bool including_total_count);
bool cleanMessages(bool clean_read_only);
};
#endif // CATEGORY_H

View File

@ -214,6 +214,10 @@ void Feed::run() {
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) {
QList<RootItem*> items_to_update;
int updated_messages = 0;

View File

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

View File

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

View File

@ -91,10 +91,6 @@ bool OwnCloudFeed::markAsReadUnread(RootItem::ReadStatus 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 {
return qobject_cast<OwnCloudServiceRoot*>(getParentServiceRoot());
}

View File

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

View File

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

View File

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

View File

@ -110,10 +110,6 @@ bool StandardFeed::markAsReadUnread(ReadStatus 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 {
switch (role) {
case Qt::ToolTipRole:

View File

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

View File

@ -45,20 +45,6 @@ TtRssServiceRoot* TtRssCategory::serviceRoot() const {
}
bool TtRssCategory::markAsReadUnread(RootItem::ReadStatus status) {
const QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this);
TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread,
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);
serviceRoot()->addMessageStatesToCache(serviceRoot()->customIDSOfMessagesForItem(this), status);
return true;
}

View File

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

View File

@ -83,10 +83,6 @@ bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus 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) {
QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings);

View File

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