diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 494d12bc8..79ed1d64c 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -19,10 +19,9 @@ #include "definitions/definitions.h" #include "services/abstract/feed.h" +#include "services/abstract/category.h" #include "services/abstract/serviceroot.h" -#include "services/standard/standardfeed.h" -#include "services/standard/standardcategory.h" -#include "services/standard/standardfeedsimportexportmodel.h" +#include "services/standard/standardserviceroot.h" #include "miscellaneous/textfactory.h" #include "miscellaneous/databasefactory.h" #include "miscellaneous/iconfactory.h" @@ -269,18 +268,18 @@ QList FeedsModel::feedsForScheduledUpdate(bool auto_update_now) { foreach (Feed *feed, allFeeds()) { switch (feed->autoUpdateType()) { - case StandardFeed::DontAutoUpdate: + case Feed::DontAutoUpdate: // Do not auto-update this feed ever. continue; - case StandardFeed::DefaultAutoUpdate: + case Feed::DefaultAutoUpdate: if (auto_update_now) { feeds_for_update.append(feed); } break; - case StandardFeed::SpecificAutoUpdate: + case Feed::SpecificAutoUpdate: default: int remaining_interval = feed->autoUpdateRemainingInterval(); @@ -306,8 +305,7 @@ QList FeedsModel::feedsForScheduledUpdate(bool auto_update_now) { QList FeedsModel::messagesForFeeds(const QList &feeds) { QList messages; - QSqlDatabase database = qApp->database()->connection(objectName(), - DatabaseFactory::FromSettings); + QSqlDatabase database = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings); QSqlQuery query_read_msg(database); query_read_msg.setForwardOnly(true); query_read_msg.prepare("SELECT title, url, author, date_created, contents " @@ -389,7 +387,7 @@ QModelIndex FeedsModel::indexForItem(RootItem *item) const { bool FeedsModel::hasAnyFeedNewMessages() { foreach (const Feed *feed, allFeeds()) { - if (feed->status() == StandardFeed::NewMessages) { + if (feed->status() == Feed::NewMessages) { return true; } } @@ -424,15 +422,16 @@ void FeedsModel::reloadWholeLayout() { } void FeedsModel::loadActivatedServiceAccounts() { - // Delete all childs of the root node and clear them from the memory. - qDeleteAll(m_rootItem->childItems()); - m_rootItem->clearChildren(); - + // Iterate all globally available feed "service plugins". foreach (ServiceEntryPoint *entry_point, qApp->feedServices()) { // Load all stored root nodes from the entry point and add those to the model. QList roots = entry_point->initializeSubtree(this); foreach (ServiceRoot *root, roots) { + if (SystemFactory::isInstanceOf(root)) { + + } + m_rootItem->appendChild(root); } } @@ -454,6 +453,7 @@ Feed *FeedsModel::feedForIndex(const QModelIndex &index) { } } +/* QList FeedsModel::feedsForIndexes(const QModelIndexList &indexes) { QList feeds; @@ -473,6 +473,7 @@ QList FeedsModel::feedsForIndexes(const QModelIndexList &indexes) { return feeds; } +*/ bool FeedsModel::markFeedsRead(const QList &feeds, int read) { QSqlDatabase db_handle = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings); @@ -564,10 +565,8 @@ QList FeedsModel::feedsForItem(RootItem *root) { QList feeds; foreach (RootItem *child, children) { - Feed *converted = dynamic_cast(child); - - if (converted != NULL) { - feeds.append(converted); + if (child->kind() == RootItemKind::Feed) { + feeds.append(child->toFeed()); } } diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 4470ccc0d..8bec2362c 100755 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -27,9 +27,7 @@ class Category; -class StandardCategory; class Feed; -class FeedsImportExportModel; class QTimer; class FeedsModel : public QAbstractItemModel { @@ -62,6 +60,7 @@ class FeedsModel : public QAbstractItemModel { } // Removes item with given index. + // NOTE: Also deletes item from memory. bool removeItem(const QModelIndex &index); // Assigns item to the new parent. @@ -91,9 +90,9 @@ class FeedsModel : public QAbstractItemModel { QList feedsForItem(RootItem *root); // Returns list of ALL CHILD feeds which belong to given parent indexes. - QList feedsForIndexes(const QModelIndexList &indexes); + //QList feedsForIndexes(const QModelIndexList &indexes); - // Returns ALL CHILD feeds contained within single index. + // Returns ALL RECURSIVE CHILD feeds contained within single index. QList feedsForIndex(const QModelIndex &index); // Returns pointer to feed if it lies on given index @@ -144,7 +143,11 @@ class FeedsModel : public QAbstractItemModel { // Is executed when next auto-update round could be done. void executeNextAutoUpdate(); - protected: + signals: + // Emitted when model requests update of some feeds. + void feedsUpdateRequested(const QList feeds); + + private: // Returns converted ids of given feeds // which are suitable as IN clause for SQL queries. QStringList textualFeedIds(const QList &feeds); @@ -152,11 +155,6 @@ class FeedsModel : public QAbstractItemModel { // Loads feed/categories from the database. void loadActivatedServiceAccounts(); - signals: - // Emitted when model requests update of some feeds. - void feedsUpdateRequested(const QList feeds); - - private: RootItem *m_rootItem; QList m_headerData; QList m_tooltipData; diff --git a/src/miscellaneous/systemfactory.h b/src/miscellaneous/systemfactory.h index 90852be91..59917f0e1 100755 --- a/src/miscellaneous/systemfactory.h +++ b/src/miscellaneous/systemfactory.h @@ -86,6 +86,12 @@ class SystemFactory : public QObject { // Tries to download list with new updates. QPair checkForUpdates(); + // Check whether given pointer belongs to instance of given class or not. + template + static bool isInstanceOf(T *ptr) { + return dynamic_cast(ptr) != NULL; + } + // Checks if update is newer than current application version. static bool isUpdateNewer(const QString &update_version); diff --git a/src/services/abstract/feed.h b/src/services/abstract/feed.h index 62ba9d2b2..8d6c5fb40 100755 --- a/src/services/abstract/feed.h +++ b/src/services/abstract/feed.h @@ -58,6 +58,8 @@ class Feed : public RootItem { // Updates counts of all/unread messages for this feed. virtual void updateCounts(bool including_total_count = true, bool update_feed_statuses = true) = 0; + + inline int autoUpdateInitialInterval() const { return m_autoUpdateInitialInterval; } diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index 6091e2f77..078fba56b 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -66,14 +66,10 @@ StandardFeed::StandardFeed(const StandardFeed &other) m_passwordProtected = other.passwordProtected(); m_username = other.username(); m_password = other.password(); - m_status = other.status(); m_networkError = other.networkError(); m_type = other.type(); m_totalCount = other.countOfAllMessages(); m_unreadCount = other.countOfUnreadMessages(); - m_autoUpdateType = other.autoUpdateType(); - m_autoUpdateInitialInterval = other.autoUpdateInitialInterval(); - m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval(); m_encoding = other.encoding(); m_url = other.url(); m_kind = RootItemKind::Feed; @@ -84,6 +80,10 @@ StandardFeed::StandardFeed(const StandardFeed &other) m_parentItem = other.parent(); m_creationDate = other.creationDate(); m_description = other.description(); + m_status = other.status(); + m_autoUpdateType = other.autoUpdateType(); + m_autoUpdateInitialInterval = other.autoUpdateInitialInterval(); + m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval(); } StandardFeed::~StandardFeed() { diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index adf773f35..4328ce1e6 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -34,8 +34,10 @@ StandardServiceRoot::StandardServiceRoot(FeedsModel *feeds_model, RootItem *parent) : ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)) { - m_title = qApp->system()->getUsername() + "@" + APP_LOW_NAME; + m_title = qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME); m_icon = StandardServiceEntryPoint().icon(); + m_description = tr("This is obligatory service account for standard RSS/RDF/ATOM feeds."); + m_creationDate = QDateTime::currentDateTime(); loadFromDatabase(); }