Refactoring, removed some unused methods also.

This commit is contained in:
Martin Rotter 2016-01-19 13:39:09 +01:00
parent d8217266ef
commit cc8a5c2822
8 changed files with 90 additions and 192 deletions

@ -521,7 +521,7 @@ StandardServiceRoot *FeedsModel::standardServiceRoot() const {
QList<Feed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) { QList<Feed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
QList<Feed*> feeds_for_update; QList<Feed*> feeds_for_update;
foreach (Feed *feed, allFeeds()) { foreach (Feed *feed, m_rootItem->getSubTreeFeeds()) {
switch (feed->autoUpdateType()) { switch (feed->autoUpdateType()) {
case Feed::DontAutoUpdate: case Feed::DontAutoUpdate:
// Do not auto-update this feed ever. // Do not auto-update this feed ever.
@ -602,7 +602,7 @@ QModelIndex FeedsModel::indexForItem(const RootItem *item) const {
} }
bool FeedsModel::hasAnyFeedNewMessages() const { bool FeedsModel::hasAnyFeedNewMessages() const {
foreach (const Feed *feed, allFeeds()) { foreach (const Feed *feed, m_rootItem->getSubTreeFeeds()) {
if (feed->status() == Feed::NewMessages) { if (feed->status() == Feed::NewMessages) {
return true; return true;
} }
@ -733,11 +733,3 @@ bool FeedsModel::markItemRead(RootItem *item, RootItem::ReadStatus read) {
bool FeedsModel::markItemCleared(RootItem *item, bool clean_read_only) { bool FeedsModel::markItemCleared(RootItem *item, bool clean_read_only) {
return item->cleanMessages(clean_read_only); return item->cleanMessages(clean_read_only);
} }
QList<Feed*> FeedsModel::allFeeds() const {
return m_rootItem->getSubTreeFeeds();
}
QList<Category*> FeedsModel::allCategories() const {
return m_rootItem->getSubTreeCategories();
}

@ -104,12 +104,6 @@ class FeedsModel : public QAbstractItemModel {
// in "newspaper" mode. // in "newspaper" mode.
QList<Message> messagesForItem(RootItem *item) const; QList<Message> messagesForItem(RootItem *item) const;
// Returns list of all categories contained in the model.
QList<Category*> allCategories() const;
// Returns list of all feeds contained in the model.
QList<Feed*> allFeeds() const;
// Returns ALL RECURSIVE CHILD feeds contained within single index. // Returns ALL RECURSIVE CHILD feeds contained within single index.
QList<Feed*> feedsForIndex(const QModelIndex &index) const; QList<Feed*> feedsForIndex(const QModelIndex &index) const;

@ -21,6 +21,7 @@
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/textfactory.h" #include "miscellaneous/textfactory.h"
#include "services/abstract/category.h" #include "services/abstract/category.h"
#include "services/abstract/recyclebin.h"
#include <QSqlQuery> #include <QSqlQuery>
#include <QSqlError> #include <QSqlError>
@ -142,6 +143,84 @@ void ServiceRoot::setAccountId(int account_id) {
m_accountId = account_id; m_accountId = account_id;
} }
bool ServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, RootItem::ReadStatus read) {
Q_UNUSED(messages)
Q_UNUSED(read)
Q_UNUSED(selected_item)
return true;
}
bool ServiceRoot::onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, RootItem::ReadStatus read) {
Q_UNUSED(messages)
Q_UNUSED(read)
selected_item->updateCounts(false);
itemChanged(QList<RootItem*>() << selected_item);
return true;
}
bool ServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message, RootItem::Importance> > &changes) {
Q_UNUSED(selected_item)
Q_UNUSED(changes)
return true;
}
bool ServiceRoot::onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message, RootItem::Importance> > &changes) {
Q_UNUSED(selected_item)
Q_UNUSED(changes)
return true;
}
bool ServiceRoot::onBeforeMessagesDelete(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(selected_item)
Q_UNUSED(messages)
return true;
}
bool ServiceRoot::onAfterMessagesDelete(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(messages)
// User deleted some messages he selected in message list.
selected_item->updateCounts(true);
RecycleBin *bin = recycleBin();
if (selected_item->kind() == RootItemKind::Bin) {
itemChanged(QList<RootItem*>() << bin);
}
else {
if (bin != NULL) {
bin->updateCounts(true);
itemChanged(QList<RootItem*>() << selected_item << bin);
}
else {
itemChanged(QList<RootItem*>() << selected_item);
}
}
return true;
}
bool ServiceRoot::onBeforeMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(selected_item)
Q_UNUSED(messages)
return true;
}
bool ServiceRoot::onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(selected_item)
Q_UNUSED(messages)
updateCounts(true);
itemChanged(getSubTree());
return true;
}
void ServiceRoot::assembleFeeds(Assignment feeds) { void ServiceRoot::assembleFeeds(Assignment feeds) {
QHash<int,Category*> categories = getHashedSubTreeCategories(); QHash<int,Category*> categories = getHashedSubTreeCategories();

@ -103,7 +103,7 @@ class ServiceRoot : public RootItem {
// some ONLINE service or something. // some ONLINE service or something.
// //
// "read" is status which is ABOUT TO BE SET. // "read" is status which is ABOUT TO BE SET.
virtual bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read) = 0; virtual bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
// Called AFTER this read status update (triggered by user in message list) is stored in DB, // Called AFTER this read status update (triggered by user in message list) is stored in DB,
// when false is returned, change is aborted. // when false is returned, change is aborted.
@ -111,7 +111,7 @@ class ServiceRoot : public RootItem {
// which items are actually changed. // which items are actually changed.
// //
// "read" is status which is ABOUT TO BE SET. // "read" is status which is ABOUT TO BE SET.
virtual bool onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read) = 0; virtual bool onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
// Called BEFORE this importance switch update is stored in DB, // Called BEFORE this importance switch update is stored in DB,
// when false is returned, change is aborted. // when false is returned, change is aborted.
@ -119,7 +119,7 @@ class ServiceRoot : public RootItem {
// some ONLINE service or something. // some ONLINE service or something.
// //
// "changes" - list of pairs - <message (integer id), new status> // "changes" - list of pairs - <message (integer id), new status>
virtual bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes) = 0; virtual bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
// Called AFTER this importance switch update is stored in DB, // Called AFTER this importance switch update is stored in DB,
// when false is returned, change is aborted. // when false is returned, change is aborted.
@ -127,25 +127,25 @@ class ServiceRoot : public RootItem {
// which items are actually changed. // which items are actually changed.
// //
// "changes" - list of pairs - <message (integer id), new status> // "changes" - list of pairs - <message (integer id), new status>
virtual bool onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes) = 0; virtual bool onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
// Called BEFORE the list of messages is about to be deleted // Called BEFORE the list of messages is about to be deleted
// by the user from message list. // by the user from message list.
virtual bool onBeforeMessagesDelete(RootItem *selected_item, const QList<Message> &messages) = 0; virtual bool onBeforeMessagesDelete(RootItem *selected_item, const QList<Message> &messages);
// Called AFTER the list of messages was deleted // Called AFTER the list of messages was deleted
// by the user from message list. // by the user from message list.
virtual bool onAfterMessagesDelete(RootItem *selected_item, const QList<Message> &messages) = 0; virtual bool onAfterMessagesDelete(RootItem *selected_item, const QList<Message> &messages);
// Called BEFORE the list of messages is about to be restored from recycle bin // Called BEFORE the list of messages is about to be restored from recycle bin
// by the user from message list. // by the user from message list.
// Selected item is naturally recycle bin. // Selected item is naturally recycle bin.
virtual bool onBeforeMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages) = 0; virtual bool onBeforeMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages);
// Called AFTER the list of messages was restored from recycle bin // Called AFTER the list of messages was restored from recycle bin
// by the user from message list. // by the user from message list.
// Selected item is naturally recycle bin. // Selected item is naturally recycle bin.
virtual bool onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages) = 0; virtual bool onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages);
///////////////////////////////////////// /////////////////////////////////////////
// Members to override. */ // Members to override. */

@ -310,17 +310,6 @@ void StandardServiceRoot::checkArgumentForFeedAdding(const QString &argument) {
} }
} }
QList<StandardCategory*> StandardServiceRoot::allCategories() {
QList<Category*> cats = getSubTreeCategories();
QList<StandardCategory*> std_cats;
foreach (Category *category, cats) {
std_cats.append(qobject_cast<StandardCategory*>(category));
}
return std_cats;
}
QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed *feed) { QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed *feed) {
if (m_feedContextMenu.isEmpty()) { if (m_feedContextMenu.isEmpty()) {
// Initialize. // Initialize.
@ -484,76 +473,3 @@ bool StandardServiceRoot::loadMessagesForItem(RootItem *item, QSqlTableModel *mo
return true; return true;
} }
bool StandardServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, RootItem::ReadStatus read) {
Q_UNUSED(messages)
Q_UNUSED(read)
Q_UNUSED(selected_item)
return true;
}
bool StandardServiceRoot::onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, RootItem::ReadStatus read) {
Q_UNUSED(messages)
Q_UNUSED(read)
selected_item->updateCounts(false);
itemChanged(QList<RootItem*>() << selected_item);
return true;
}
bool StandardServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item,
const QList<QPair<Message,Importance> > &changes) {
Q_UNUSED(selected_item)
Q_UNUSED(changes)
return true;
}
bool StandardServiceRoot::onAfterSwitchMessageImportance(RootItem *selected_item,
const QList<QPair<Message,Importance> > &changes) {
Q_UNUSED(selected_item)
Q_UNUSED(changes)
return true;
}
bool StandardServiceRoot::onBeforeMessagesDelete(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(selected_item)
Q_UNUSED(messages)
return true;
}
bool StandardServiceRoot::onAfterMessagesDelete(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(messages)
// User deleted some messages he selected in message list.
selected_item->updateCounts(true);
if (selected_item->kind() == RootItemKind::Bin) {
itemChanged(QList<RootItem*>() << m_recycleBin);
}
else {
m_recycleBin->updateCounts(true);
itemChanged(QList<RootItem*>() << selected_item << m_recycleBin);
}
return true;
}
bool StandardServiceRoot::onBeforeMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(selected_item)
Q_UNUSED(messages)
return true;
}
bool StandardServiceRoot::onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(selected_item)
Q_UNUSED(messages)
updateCounts(true);
itemChanged(getSubTree());
return true;
}

@ -70,22 +70,6 @@ class StandardServiceRoot : public ServiceRoot {
// Message stuff. // Message stuff.
bool loadMessagesForItem(RootItem *item, QSqlTableModel *model); bool loadMessagesForItem(RootItem *item, QSqlTableModel *model);
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
bool onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
bool onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
bool onBeforeMessagesDelete(RootItem *selected_item, const QList<Message> &messages);
bool onAfterMessagesDelete(RootItem *selected_item, const QList<Message> &messages);
bool onBeforeMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages);
bool onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages);
// Returns all categories from this root, each pair
// consists of ID of parent item and pointer to category.
QList<StandardCategory*> allCategories();
// Returns context specific menu actions for given feed. // Returns context specific menu actions for given feed.
QList<QAction*> getContextMenuForFeed(StandardFeed *feed); QList<QAction*> getContextMenuForFeed(StandardFeed *feed);

@ -198,8 +198,7 @@ QList<QAction*> TtRssServiceRoot::contextMenu() {
return serviceMenu(); return serviceMenu();
} }
bool TtRssServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, bool TtRssServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, RootItem::ReadStatus read) {
RootItem::ReadStatus read) {
Q_UNUSED(selected_item) Q_UNUSED(selected_item)
TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(messages), TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(messages),
@ -216,15 +215,6 @@ bool TtRssServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QL
} }
} }
bool TtRssServiceRoot::onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, RootItem::ReadStatus read) {
Q_UNUSED(messages)
Q_UNUSED(read)
selected_item->updateCounts(false);
itemChanged(QList<RootItem*>() << selected_item);
return true;
}
bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,Importance> > &changes) { bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,Importance> > &changes) {
Q_UNUSED(selected_item) Q_UNUSED(selected_item)
@ -243,53 +233,6 @@ bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item,
} }
} }
bool TtRssServiceRoot::onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,Importance> > &changes) {
Q_UNUSED(selected_item)
Q_UNUSED(changes)
return true;
}
bool TtRssServiceRoot::onBeforeMessagesDelete(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(selected_item)
Q_UNUSED(messages)
return true;
}
bool TtRssServiceRoot::onAfterMessagesDelete(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(messages)
// User deleted some messages he selected in message list.
selected_item->updateCounts(true);
if (selected_item->kind() == RootItemKind::Bin) {
itemChanged(QList<RootItem*>() << m_recycleBin);
}
else {
m_recycleBin->updateCounts(true);
itemChanged(QList<RootItem*>() << selected_item << m_recycleBin);
}
return true;
}
bool TtRssServiceRoot::onBeforeMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(selected_item)
Q_UNUSED(messages)
return true;
}
bool TtRssServiceRoot::onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages) {
Q_UNUSED(selected_item)
Q_UNUSED(messages)
updateCounts(true);
itemChanged(getSubTree());
return true;
}
TtRssNetworkFactory *TtRssServiceRoot::network() const { TtRssNetworkFactory *TtRssServiceRoot::network() const {
return m_network; return m_network;
} }

@ -59,18 +59,8 @@ class TtRssServiceRoot : public ServiceRoot {
RecycleBin *recycleBin() const; RecycleBin *recycleBin() const;
bool loadMessagesForItem(RootItem *item, QSqlTableModel *model); bool loadMessagesForItem(RootItem *item, QSqlTableModel *model);
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read); bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
bool onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes); bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
bool onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
bool onBeforeMessagesDelete(RootItem *selected_item, const QList<Message> &messages);
bool onAfterMessagesDelete(RootItem *selected_item, const QList<Message> &messages);
bool onBeforeMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages);
bool onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList<Message> &messages);
// Access to network. // Access to network.
TtRssNetworkFactory *network() const; TtRssNetworkFactory *network() const;