diff --git a/src/services/abstract/feed.cpp b/src/services/abstract/feed.cpp index 877f1131e..5f4d5393b 100755 --- a/src/services/abstract/feed.cpp +++ b/src/services/abstract/feed.cpp @@ -23,13 +23,21 @@ Feed::Feed(RootItem *parent) : RootItem(parent), m_url(QString()), m_status(Normal), m_autoUpdateType(DefaultAutoUpdate), m_autoUpdateInitialInterval(DEFAULT_AUTO_UPDATE_INTERVAL), m_autoUpdateRemainingInterval(DEFAULT_AUTO_UPDATE_INTERVAL), - m_totalCount(0), m_unreadCount(0) { + m_totalCount(0), m_unreadCount(0), m_customId(NO_PARENT_CATEGORY) { setKind(RootItemKind::Feed); } Feed::~Feed() { } +int Feed::customId() const { + return m_customId; +} + +void Feed::setCustomId(int custom_id) { + m_customId = custom_id; +} + QVariant Feed::data(int column, int role) const { switch (role) { case Qt::ForegroundRole: diff --git a/src/services/abstract/feed.h b/src/services/abstract/feed.h index 0085d2ba4..9f3e347c0 100755 --- a/src/services/abstract/feed.h +++ b/src/services/abstract/feed.h @@ -100,6 +100,11 @@ class Feed : public RootItem { m_url = url; } + int customId() const; + void setCustomId(int custom_id); + + virtual int messageForeignKeyId() const = 0; + private: QString m_url; Status m_status; @@ -108,6 +113,7 @@ class Feed : public RootItem { int m_autoUpdateRemainingInterval; int m_totalCount; int m_unreadCount; + int m_customId; }; #endif // FEED_H diff --git a/src/services/abstract/rootitem.h b/src/services/abstract/rootitem.h index 2a551a064..b48fb60d0 100755 --- a/src/services/abstract/rootitem.h +++ b/src/services/abstract/rootitem.h @@ -204,7 +204,8 @@ class RootItem : public QObject { m_icon = icon; } - // Each item has some kind of id. Usually taken from primary key attribute from DB. + // This ALWAYS represents primary column number/ID under which + // the item is stored in DB. inline int id() const { return m_id; } diff --git a/src/services/abstract/serviceroot.cpp b/src/services/abstract/serviceroot.cpp index 90a42bbeb..2cee0e2f9 100755 --- a/src/services/abstract/serviceroot.cpp +++ b/src/services/abstract/serviceroot.cpp @@ -21,8 +21,10 @@ #include "miscellaneous/application.h" #include "miscellaneous/textfactory.h" #include "services/abstract/category.h" +#include "services/abstract/feed.h" #include "services/abstract/recyclebin.h" +#include #include #include @@ -135,6 +137,17 @@ void ServiceRoot::requestItemRemoval(RootItem *item) { emit itemRemovalRequested(item); } +QStringList ServiceRoot::textualFeedIds(const QList &feeds) const { + QStringList stringy_ids; + stringy_ids.reserve(feeds.size()); + + foreach (const Feed *feed, feeds) { + stringy_ids.append(QString("'%1'").arg(QString::number(feed->messageForeignKeyId()))); + } + + return stringy_ids; +} + int ServiceRoot::accountId() const { return m_accountId; } @@ -143,6 +156,22 @@ void ServiceRoot::setAccountId(int account_id) { m_accountId = account_id; } +bool ServiceRoot::loadMessagesForItem(RootItem *item, QSqlTableModel *model) { + if (item->kind() == RootItemKind::Bin) { + model->setFilter(QString("is_deleted = 1 AND is_pdeleted = 0 AND account_id = %1").arg(QString::number(accountId()))); + } + else { + QList children = item->getSubTreeFeeds(); + QString filter_clause = textualFeedIds(children).join(QSL(", ")); + + model->setFilter(QString("feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = %2").arg(filter_clause, + QString::number(accountId()))); + qDebug("Loading messages from feeds: %s.", qPrintable(filter_clause)); + } + + return true; +} + bool ServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QList &messages, RootItem::ReadStatus read) { Q_UNUSED(messages) Q_UNUSED(read) diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index ce32ab2a0..d489b2a70 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -95,7 +95,7 @@ class ServiceRoot : public RootItem { // and then use method QSqlTableModel::setFilter(....). // NOTE: It would be more preferable if all messages are downloaded // right when feeds are updated. - virtual bool loadMessagesForItem(RootItem *item, QSqlTableModel *model) = 0; + virtual bool loadMessagesForItem(RootItem *item, QSqlTableModel *model); // Called BEFORE this read status update (triggered by user in message list) is stored in DB, // when false is returned, change is aborted. @@ -164,6 +164,8 @@ class ServiceRoot : public RootItem { virtual void addNewCategory() = 0; protected: + QStringList textualFeedIds(const QList &feeds) const; + // Takes lists of feeds/categories and assembles them into the tree structure. void assembleCategories(Assignment categories); void assembleFeeds(Assignment feeds); diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index afe4dae6e..d307fb728 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -605,6 +605,10 @@ bool StandardFeed::editItself(StandardFeed *new_feed_data) { return true; } +int StandardFeed::messageForeignKeyId() const { + return id(); +} + int StandardFeed::updateMessages(const QList &messages) { int feed_id = id(); int updated_messages = 0; diff --git a/src/services/standard/standardfeed.h b/src/services/standard/standardfeed.h index 449592ebf..ab67a2583 100755 --- a/src/services/standard/standardfeed.h +++ b/src/services/standard/standardfeed.h @@ -90,6 +90,8 @@ class StandardFeed : public Feed { bool addItself(RootItem *parent); bool editItself(StandardFeed *new_feed_data); + int messageForeignKeyId() const; + // Other getters/setters. inline Type type() const { return m_type; diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index 85ff0fb0e..43bb91212 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -445,17 +445,6 @@ void StandardServiceRoot::exportFeeds() { form.data()->exec(); } -QStringList StandardServiceRoot::textualFeedIds(const QList &feeds) { - QStringList stringy_ids; - stringy_ids.reserve(feeds.size()); - - foreach (Feed *feed, feeds) { - stringy_ids.append(QString("'%1'").arg(QString::number(feed->id()))); - } - - return stringy_ids; -} - QList StandardServiceRoot::addItemMenu() { return QList(); } @@ -478,19 +467,3 @@ QList StandardServiceRoot::serviceMenu() { QList StandardServiceRoot::contextMenu() { return serviceMenu(); } - -bool StandardServiceRoot::loadMessagesForItem(RootItem *item, QSqlTableModel *model) { - if (item->kind() == RootItemKind::Bin) { - model->setFilter(QString("is_deleted = 1 AND is_pdeleted = 0 AND account_id = %1").arg(QString::number(accountId()))); - } - else { - QList children = item->getSubTreeFeeds(); - QString filter_clause = textualFeedIds(children).join(QSL(", ")); - - model->setFilter(QString(QSL("feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = %2")).arg(filter_clause, - QString::number(accountId()))); - qDebug("Loading messages from feeds: %s.", qPrintable(filter_clause)); - } - - return true; -} diff --git a/src/services/standard/standardserviceroot.h b/src/services/standard/standardserviceroot.h index 437ec29cb..81687da99 100755 --- a/src/services/standard/standardserviceroot.h +++ b/src/services/standard/standardserviceroot.h @@ -67,9 +67,6 @@ class StandardServiceRoot : public ServiceRoot { // Returns context menu. QList contextMenu(); - // Message stuff. - bool loadMessagesForItem(RootItem *item, QSqlTableModel *model); - // Returns context specific menu actions for given feed. QList getContextMenuForFeed(StandardFeed *feed); @@ -93,10 +90,6 @@ class StandardServiceRoot : public ServiceRoot { private: void checkArgumentsForFeedAdding(); - // Returns converted ids of given feeds - // which are suitable as IN clause for SQL queries. - QStringList textualFeedIds(const QList &feeds); - RecycleBin *m_recycleBin; QAction *m_actionExportFeeds; QAction *m_actionImportFeeds; diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index 2573dea56..949d5ab65 100755 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -35,7 +35,7 @@ TtRssFeed::TtRssFeed(RootItem *parent) - : Feed(parent), m_customId(NO_PARENT_CATEGORY) { + : Feed(parent) { } TtRssFeed::TtRssFeed(const QSqlRecord &record) : Feed(NULL) { @@ -57,6 +57,10 @@ QString TtRssFeed::hashCode() const { QString::number(customId()); } +int TtRssFeed::messageForeignKeyId() const { + return customId(); +} + TtRssServiceRoot *TtRssFeed::serviceRoot() const { return qobject_cast(getParentServiceRoot()); } @@ -241,14 +245,6 @@ bool TtRssFeed::cleanMessages(bool clear_only_read) { return serviceRoot()->cleanFeeds(QList() << this, clear_only_read); } -int TtRssFeed::customId() const { - return m_customId; -} - -void TtRssFeed::setCustomId(int custom_id) { - m_customId = custom_id; -} - bool TtRssFeed::editItself(TtRssFeed *new_feed_data) { QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings); QSqlQuery query_update(database); diff --git a/src/services/tt-rss/ttrssfeed.h b/src/services/tt-rss/ttrssfeed.h index fe19ed422..0622d1d86 100755 --- a/src/services/tt-rss/ttrssfeed.h +++ b/src/services/tt-rss/ttrssfeed.h @@ -35,6 +35,8 @@ class TtRssFeed : public Feed { QString hashCode() const; + int messageForeignKeyId() const; + TtRssServiceRoot *serviceRoot() const; QVariant data(int column, int role) const; @@ -52,18 +54,11 @@ class TtRssFeed : public Feed { bool markAsReadUnread(ReadStatus status); bool cleanMessages(bool clear_only_read); - - int customId() const; - void setCustomId(int custom_id); - bool editItself(TtRssFeed *new_feed_data); private: bool removeItself(); - int updateMessages(const QList &messages); - - int m_customId; }; #endif // TTRSSFEED_H diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp index 1c6d5bdd7..c2ede1aef 100755 --- a/src/services/tt-rss/ttrssserviceroot.cpp +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -177,22 +177,6 @@ RecycleBin *TtRssServiceRoot::recycleBin() const { return m_recycleBin; } -bool TtRssServiceRoot::loadMessagesForItem(RootItem *item, QSqlTableModel *model) { - if (item->kind() == RootItemKind::Bin) { - model->setFilter(QString("is_deleted = 1 AND is_pdeleted = 0 AND account_id = %1").arg(QString::number(accountId()))); - } - else { - QList children = item->getSubTreeFeeds(); - QString filter_clause = textualFeedIds(children).join(QSL(", ")); - - model->setFilter(QString(QSL("feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = '%2'")).arg(filter_clause, - QString::number(accountId()))); - qDebug("Loading messages from feeds: %s.", qPrintable(filter_clause)); - } - - return true; -} - QList TtRssServiceRoot::serviceMenu() { if (m_serviceMenu.isEmpty()) { m_actionSyncIn = new QAction(qApp->icons()->fromTheme(QSL("item-sync")), tr("Sync in"), this); @@ -603,17 +587,6 @@ QStringList TtRssServiceRoot::customIDsOfMessages(const QList &messages return list; } -QStringList TtRssServiceRoot::textualFeedIds(const QList &feeds) { - QStringList stringy_ids; - stringy_ids.reserve(feeds.size()); - - foreach (const Feed *feed, feeds) { - stringy_ids.append(QString("'%1'").arg(QString::number(qobject_cast(feed)->customId()))); - } - - return stringy_ids; -} - void TtRssServiceRoot::removeOldFeedTree(bool including_messages) { QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlQuery query(database); diff --git a/src/services/tt-rss/ttrssserviceroot.h b/src/services/tt-rss/ttrssserviceroot.h index 1a02785a9..59a9b65a7 100755 --- a/src/services/tt-rss/ttrssserviceroot.h +++ b/src/services/tt-rss/ttrssserviceroot.h @@ -58,7 +58,6 @@ class TtRssServiceRoot : public ServiceRoot { RecycleBin *recycleBin() const; - bool loadMessagesForItem(RootItem *item, QSqlTableModel *model); bool onBeforeSetMessagesRead(RootItem *selected_item, const QList &messages, ReadStatus read); bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList > &changes); @@ -84,10 +83,6 @@ class TtRssServiceRoot : public ServiceRoot { QStringList customIDsOfMessages(const QList > &changes); QStringList customIDsOfMessages(const QList &messages); - // Returns converted ids of given feeds - // which are suitable as IN clause for SQL queries. - QStringList textualFeedIds(const QList &feeds); - void removeOldFeedTree(bool including_messages); void removeLeftOverMessages(); void cleanAllItems();