diff --git a/src/librssguard/miscellaneous/databasequeries.h b/src/librssguard/miscellaneous/databasequeries.h index 50677d28d..89390f230 100644 --- a/src/librssguard/miscellaneous/databasequeries.h +++ b/src/librssguard/miscellaneous/databasequeries.h @@ -92,6 +92,9 @@ class DatabaseQueries { // Common account methods. template static QList getAccounts(const QSqlDatabase& db, const QString& code, bool* ok = nullptr); + + template + static void loadFromDatabase(ServiceRoot* root); static bool storeNewOauthTokens(const QSqlDatabase& db, const QString& table_name, const QString& refresh_token, int account_id); static void createOverwriteAccount(const QSqlDatabase& db, ServiceRoot* account); @@ -320,4 +323,14 @@ Assignment DatabaseQueries::getFeeds(const QSqlDatabase& db, return feeds; } +template +void DatabaseQueries::loadFromDatabase(ServiceRoot* root) { + QSqlDatabase database = root->internalDatabase(); + Assignment categories = DatabaseQueries::getCategories(database, root->accountId()); + Assignment feeds = DatabaseQueries::getFeeds(database, root->internalFilters(), root->accountId()); + auto labels = DatabaseQueries::getLabels(database, root->accountId()); + + root->performInitialAssembly(categories, feeds, labels); +} + #endif // DATABASEQUERIES_H diff --git a/src/librssguard/services/abstract/serviceroot.h b/src/librssguard/services/abstract/serviceroot.h index b85874f5a..97b640ed5 100644 --- a/src/librssguard/services/abstract/serviceroot.h +++ b/src/librssguard/services/abstract/serviceroot.h @@ -6,8 +6,8 @@ #include "services/abstract/rootitem.h" #include "core/message.h" +#include "core/messagefilter.h" #include "definitions/typedefs.h" -#include "miscellaneous/databasequeries.h" #include #include @@ -62,9 +62,6 @@ class ServiceRoot : public RootItem { virtual QList customDatabaseAttributes() const; virtual void saveAccountDataToDatabase(); - template - void loadFromDatabase(); - // Returns list of specific actions for "Add new item" main window menu. // So typical list of returned actions could look like: // a) Add new feed @@ -201,13 +198,19 @@ class ServiceRoot : public RootItem { QStringList customIDsOfMessages(const QList& messages); QStringList customIDSOfMessagesForItem(RootItem* item); + void performInitialAssembly(const Assignment& categories, const Assignment& feeds, const QList& labels); + + // Helper methods to keep "application.h" inclusion + // out of this file. + QSqlDatabase internalDatabase() const; + QList internalFilters() const; + public slots: virtual void addNewFeed(RootItem* selected_item, const QString& url = QString()); virtual void addNewCategory(RootItem* selected_item); virtual void syncIn(); protected: - void performInitialAssembly(const Assignment& categories, const Assignment& feeds, const QList& labels); // This method should obtain new tree of feed/categories/whatever to perform sync in. virtual RootItem* obtainNewTreeForSyncIn() const; @@ -255,11 +258,6 @@ class ServiceRoot : public RootItem { virtual QMap storeCustomFeedsData(); virtual void restoreCustomFeedsData(const QMap& data, const QHash& feeds); - // Helper methods to keep "application.h" inclusion - // out of this file. - QSqlDatabase internalDatabase() const; - QList internalFilters() const; - protected: RecycleBin* m_recycleBin; ImportantNode* m_importantNode; @@ -272,15 +270,4 @@ class ServiceRoot : public RootItem { ServiceRoot::LabelOperation operator|(ServiceRoot::LabelOperation lhs, ServiceRoot::LabelOperation rhs); ServiceRoot::LabelOperation operator&(ServiceRoot::LabelOperation lhs, ServiceRoot::LabelOperation rhs); -template -void ServiceRoot::loadFromDatabase() { - - QSqlDatabase database = internalDatabase(); - Assignment categories = DatabaseQueries::getCategories(database, accountId()); - Assignment feeds = DatabaseQueries::getFeeds(database, internalFilters(), accountId()); - auto labels = DatabaseQueries::getLabels(database, accountId()); - - performInitialAssembly(categories, feeds, labels); -} - #endif // SERVICEROOT_H diff --git a/src/librssguard/services/tt-rss/ttrssserviceroot.cpp b/src/librssguard/services/tt-rss/ttrssserviceroot.cpp index b45b3dbf1..f741503c3 100644 --- a/src/librssguard/services/tt-rss/ttrssserviceroot.cpp +++ b/src/librssguard/services/tt-rss/ttrssserviceroot.cpp @@ -38,7 +38,7 @@ ServiceRoot::LabelOperation TtRssServiceRoot::supportedLabelOperations() const { void TtRssServiceRoot::start(bool freshly_activated) { if (!freshly_activated) { - loadFromDatabase(); + DatabaseQueries::loadFromDatabase(this); loadCacheFromFile(); }