From 746e7aae1f1b7e90b45b9cea797beb4590b1e34c Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 7 Dec 2015 20:41:16 +0100 Subject: [PATCH] Initial version of getFeedTree implementation. --- src/services/abstract/category.cpp | 1 + src/services/abstract/feed.cpp | 4 +- src/services/standard/standardcategory.cpp | 9 --- src/services/standard/standardcategory.h | 3 - src/services/standard/standardfeed.cpp | 3 - .../tt-rss/network/ttrssnetworkfactory.cpp | 62 +++++++++++++++++-- .../tt-rss/network/ttrssnetworkfactory.h | 2 +- src/services/tt-rss/ttrsscategory.cpp | 14 ++++- src/services/tt-rss/ttrsscategory.h | 6 ++ src/services/tt-rss/ttrssfeed.cpp | 21 ++++++- src/services/tt-rss/ttrssfeed.h | 11 +++- src/services/tt-rss/ttrssserviceroot.cpp | 2 +- 12 files changed, 111 insertions(+), 27 deletions(-) diff --git a/src/services/abstract/category.cpp b/src/services/abstract/category.cpp index 62829f673..097c9bc56 100755 --- a/src/services/abstract/category.cpp +++ b/src/services/abstract/category.cpp @@ -19,6 +19,7 @@ Category::Category(RootItem *parent) : RootItem(parent) { + setKind(RootItemKind::Category); } Category::~Category() { diff --git a/src/services/abstract/feed.cpp b/src/services/abstract/feed.cpp index a07cc8a7a..2faabce27 100755 --- a/src/services/abstract/feed.cpp +++ b/src/services/abstract/feed.cpp @@ -22,9 +22,11 @@ Feed::Feed(RootItem *parent) : RootItem(parent) { m_status = Normal; - m_autoUpdateType = DontAutoUpdate; + m_autoUpdateType = DefaultAutoUpdate; m_autoUpdateInitialInterval = DEFAULT_AUTO_UPDATE_INTERVAL; m_autoUpdateRemainingInterval = DEFAULT_AUTO_UPDATE_INTERVAL; + + setKind(RootItemKind::Feed); } Feed::~Feed() { diff --git a/src/services/standard/standardcategory.cpp b/src/services/standard/standardcategory.cpp index 8c7add25c..9cbe45021 100755 --- a/src/services/standard/standardcategory.cpp +++ b/src/services/standard/standardcategory.cpp @@ -37,13 +37,10 @@ StandardCategory::StandardCategory(RootItem *parent_item) : Category(parent_item) { - init(); } StandardCategory::StandardCategory(const StandardCategory &other) : Category(NULL) { - init(); - setId(other.id()); setTitle(other.title()); setDescription(other.description()); @@ -61,10 +58,6 @@ StandardServiceRoot *StandardCategory::serviceRoot() { return static_cast(getParentServiceRoot()); } -void StandardCategory::init() { - setKind(RootItemKind::Category); -} - QVariant StandardCategory::data(int column, int role) const { switch (role) { case Qt::ToolTipRole: @@ -222,8 +215,6 @@ bool StandardCategory::editItself(StandardCategory *new_category_data) { } StandardCategory::StandardCategory(const QSqlRecord &record) : Category(NULL) { - init(); - setId(record.value(CAT_DB_ID_INDEX).toInt()); setTitle(record.value(CAT_DB_TITLE_INDEX).toString()); setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString()); diff --git a/src/services/standard/standardcategory.h b/src/services/standard/standardcategory.h index 36ac62f9a..7a90fd1f1 100755 --- a/src/services/standard/standardcategory.h +++ b/src/services/standard/standardcategory.h @@ -67,9 +67,6 @@ class StandardCategory : public Category { bool addItself(RootItem *parent); bool editItself(StandardCategory *new_category_data); - - private: - void init(); }; #endif // FEEDSMODELCLASSICCATEGORY_H diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index c9a355880..a0f4332f3 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -55,8 +55,6 @@ StandardFeed::StandardFeed(RootItem *parent_item) m_unreadCount = 0; m_encoding = QString(); m_url = QString(); - - setKind(RootItemKind::Feed); } StandardFeed::StandardFeed(const StandardFeed &other) @@ -76,7 +74,6 @@ StandardFeed::StandardFeed(const StandardFeed &other) setAutoUpdateInitialInterval(other.autoUpdateInitialInterval()); setAutoUpdateRemainingInterval(other.autoUpdateRemainingInterval()); - setKind(RootItemKind::Feed); setTitle(other.title()); setId(other.id()); setIcon(other.icon()); diff --git a/src/services/tt-rss/network/ttrssnetworkfactory.cpp b/src/services/tt-rss/network/ttrssnetworkfactory.cpp index af563c2cf..6576b9c08 100755 --- a/src/services/tt-rss/network/ttrssnetworkfactory.cpp +++ b/src/services/tt-rss/network/ttrssnetworkfactory.cpp @@ -21,6 +21,9 @@ #include "core/rootitem.h" #include "services/tt-rss/definitions.h" #include "services/tt-rss/ttrssfeed.h" +#include "services/tt-rss/ttrsscategory.h" +#include "miscellaneous/application.h" +#include "miscellaneous/iconfactory.h" #include "network-web/networkfactory.h" #include @@ -207,17 +210,68 @@ TtRssGetFeedsCategoriesResponse::TtRssGetFeedsCategoriesResponse(const QString & TtRssGetFeedsCategoriesResponse::~TtRssGetFeedsCategoriesResponse() { } -QList TtRssGetFeedsCategoriesResponse::feedsCategories() { - QList items; +RootItem *TtRssGetFeedsCategoriesResponse::feedsCategories() { + RootItem *parent = new RootItem(); if (status() == API_STATUS_OK) { // We have data, construct object tree according to data. QList items_to_process = m_rawContent["content"].toMap()["categories"].toMap()["items"].toList(); + QList > pairs; - while (!items_to_process.isEmpty()) { + foreach (QVariant item, items_to_process) { + pairs.append(QPair(parent, item)); + } + + while (!pairs.isEmpty()) { + QPair pair = pairs.takeFirst(); + RootItem *act_parent = pair.first; + QMap item = pair.second.toMap(); + + if (item.contains("type") && item["type"].toString() == GFT_TYPE_CATEGORY) { + // Add category to the parent, go through children. + int item_bare_id = item["bare_id"].toInt(); + + if (item_bare_id < 0) { + // Ignore virtual categories or feeds. + continue; + } + + if (item_bare_id == 0) { + // This is "Uncategorized" category, all its feeds belong to total parent. + if (item.contains("items")) { + foreach (QVariant child_feed, item["items"].toList()) { + pairs.append(QPair(parent, child_feed)); + } + } + } + else if (item_bare_id > 0) { + TtRssCategory *category = new TtRssCategory(); + + category->setIcon(qApp->icons()->fromTheme(QSL("folder-category"))); + category->setTitle(item["name"].toString()); + category->setCustomId(item_bare_id); + act_parent->appendChild(category); + + if (item.contains("items")) { + foreach (QVariant child, item["items"].toList()) { + pairs.append(QPair(category, child)); + } + } + } + } + else { + // We have feed. + int item_bare_id = item["bare_id"].toInt(); + TtRssFeed *feed = new TtRssFeed(); + + // TODO: stahnout a nastavit ikonu + feed->setTitle(item["name"].toString()); + feed->setCustomId(item_bare_id); + act_parent->appendChild(feed); + } } } - return items; + return parent; } diff --git a/src/services/tt-rss/network/ttrssnetworkfactory.h b/src/services/tt-rss/network/ttrssnetworkfactory.h index 25cac350f..5bc259209 100755 --- a/src/services/tt-rss/network/ttrssnetworkfactory.h +++ b/src/services/tt-rss/network/ttrssnetworkfactory.h @@ -58,7 +58,7 @@ class TtRssGetFeedsCategoriesResponse : public TtRssResponse { explicit TtRssGetFeedsCategoriesResponse(const QString &raw_content = QString()); virtual ~TtRssGetFeedsCategoriesResponse(); - QList feedsCategories(); + RootItem *feedsCategories(); }; class TtRssNetworkFactory { diff --git a/src/services/tt-rss/ttrsscategory.cpp b/src/services/tt-rss/ttrsscategory.cpp index 4fc96230b..7b485288e 100644 --- a/src/services/tt-rss/ttrsscategory.cpp +++ b/src/services/tt-rss/ttrsscategory.cpp @@ -15,11 +15,21 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "ttrsscategory.h" +#include "services/tt-rss/ttrsscategory.h" + +#include "definitions/definitions.h" -TtRssCategory::TtRssCategory(RootItem *parent) : Category(parent) { +TtRssCategory::TtRssCategory(RootItem *parent) : Category(parent), m_customId(NO_PARENT_CATEGORY) { } TtRssCategory::~TtRssCategory() { } + +int TtRssCategory::customId() const { + return m_customId; +} + +void TtRssCategory::setCustomId(int custom_id) { + m_customId = custom_id; +} diff --git a/src/services/tt-rss/ttrsscategory.h b/src/services/tt-rss/ttrsscategory.h index 2758d2c78..fb7df9a24 100644 --- a/src/services/tt-rss/ttrsscategory.h +++ b/src/services/tt-rss/ttrsscategory.h @@ -25,6 +25,12 @@ class TtRssCategory : public Category { public: explicit TtRssCategory(RootItem *parent = NULL); virtual ~TtRssCategory(); + + int customId() const; + void setCustomId(int custom_id); + + private: + int m_customId; }; #endif // TTRSSCATEGORY_H diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index e12fbefc2..45d90dc31 100644 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -15,12 +15,29 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "ttrssfeed.h" +#include "services/tt-rss/ttrssfeed.h" + +#include "definitions/definitions.h" -TtRssFeed::TtRssFeed(RootItem *parent) : Feed(parent) { +TtRssFeed::TtRssFeed(RootItem *parent) : Feed(parent), m_customId(NO_PARENT_CATEGORY) { } TtRssFeed::~TtRssFeed() { } +int TtRssFeed::update() { + return 0; +} + +QList TtRssFeed::undeletedMessages() const { + return QList(); +} + +int TtRssFeed::customId() const { + return m_customId; +} + +void TtRssFeed::setCustomId(int custom_id) { + m_customId = custom_id; +} diff --git a/src/services/tt-rss/ttrssfeed.h b/src/services/tt-rss/ttrssfeed.h index b947e805d..314ad880d 100644 --- a/src/services/tt-rss/ttrssfeed.h +++ b/src/services/tt-rss/ttrssfeed.h @@ -18,13 +18,22 @@ #ifndef TTRSSFEED_H #define TTRSSFEED_H -#include +#include "services/abstract/feed.h" class TtRssFeed : public Feed { public: explicit TtRssFeed(RootItem *parent = NULL); virtual ~TtRssFeed(); + + int update(); + QList undeletedMessages() const; + + int customId() const; + void setCustomId(int custom_id); + + private: + int m_customId; }; #endif // TTRSSFEED_H diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp index 381606e8f..48575f313 100755 --- a/src/services/tt-rss/ttrssserviceroot.cpp +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -230,5 +230,5 @@ void TtRssServiceRoot::syncIn() { QNetworkReply::NetworkError err; - QList aa = m_network->getFeedsCategories(err).feedsCategories(); + RootItem *aa = m_network->getFeedsCategories(err).feedsCategories(); }