diff --git a/CMakeLists.txt b/CMakeLists.txt index 1027f8d9a..aaef3c5a2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -561,6 +561,8 @@ set(APP_HEADERS # TT-RSS service headers. src/services/tt-rss/ttrssserviceroot.h src/services/tt-rss/ttrssrecyclebin.h + src/services/tt-rss/ttrssfeed.h + src/services/tt-rss/ttrsscategory.h src/services/tt-rss/gui/formeditaccount.h # NETWORK-WEB headers. diff --git a/src/services/tt-rss/ttrsscategory.h b/src/services/tt-rss/ttrsscategory.h index c029d3435..54e573448 100755 --- a/src/services/tt-rss/ttrsscategory.h +++ b/src/services/tt-rss/ttrsscategory.h @@ -24,11 +24,15 @@ class TtRssCategory : public Category { + Q_OBJECT + public: explicit TtRssCategory(RootItem *parent = NULL); explicit TtRssCategory(const QSqlRecord &record); virtual ~TtRssCategory(); + + int customId() const; void setCustomId(int custom_id); diff --git a/src/services/tt-rss/ttrssfeed.h b/src/services/tt-rss/ttrssfeed.h index 87a2c3e9f..ccd78d386 100755 --- a/src/services/tt-rss/ttrssfeed.h +++ b/src/services/tt-rss/ttrssfeed.h @@ -26,6 +26,8 @@ class TtRssServiceRoot; class TtRssFeed : public Feed { + Q_OBJECT + public: explicit TtRssFeed(RootItem *parent = NULL); explicit TtRssFeed(const QSqlRecord &record); diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp index ea9f22036..ca6061a64 100755 --- a/src/services/tt-rss/ttrssserviceroot.cpp +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -222,6 +222,77 @@ TtRssNetworkFactory *TtRssServiceRoot::network() const { return m_network; } +QStringList TtRssServiceRoot::customIDSOfMessagesForItem(RootItem *item) { + if (item->getParentServiceRoot() != this) { + // Not item from this account. + return QStringList(); + } + else { + QStringList list; + + switch (item->kind()) { + case RootItemKind::Category: { + foreach (RootItem *child, item->childItems()) { + list.append(customIDSOfMessagesForItem(child)); + } + + return list; + } + + case RootItemKind::ServiceRoot: { + QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); + QSqlQuery query(database); + + query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;")); + query.bindValue(QSL(":account_id"), accountId()); + query.exec(); + + while (query.next()) { + list.append(query.value(0).toString()); + } + + break; + } + + case RootItemKind::Bin: { + QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); + QSqlQuery query(database); + + query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;")); + query.bindValue(QSL(":account_id"), accountId()); + query.exec(); + + while (query.next()) { + list.append(query.value(0).toString()); + } + + break; + } + + case RootItemKind::Feed: { + QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); + QSqlQuery query(database); + + query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND feed = :feed AND account_id = :account_id;")); + query.bindValue(QSL(":account_id"), accountId()); + query.bindValue(QSL(":feed"), qobject_cast(item)->customId()); + query.exec(); + + while (query.next()) { + list.append(query.value(0).toString()); + } + + break; + } + + default: + break; + } + + return list; + } +} + void TtRssServiceRoot::saveAccountDataToDatabase() { if (accountId() != NO_PARENT_CATEGORY) { // We are overwritting previously saved data. diff --git a/src/services/tt-rss/ttrssserviceroot.h b/src/services/tt-rss/ttrssserviceroot.h index 903100cb9..6f594ab7f 100755 --- a/src/services/tt-rss/ttrssserviceroot.h +++ b/src/services/tt-rss/ttrssserviceroot.h @@ -68,9 +68,11 @@ class TtRssServiceRoot : public ServiceRoot { TtRssNetworkFactory *network() const; + // Returns list of custom IDS of all DB messages in given item. + QStringList customIDSOfMessagesForItem(RootItem *item); + void saveAccountDataToDatabase(); void updateTitle(); - void completelyRemoveAllData(); public slots: