Initial version of getFeedTree implementation.

This commit is contained in:
Martin Rotter 2015-12-07 20:41:16 +01:00
parent 90d92e8aa8
commit 746e7aae1f
12 changed files with 111 additions and 27 deletions

View File

@ -19,6 +19,7 @@
Category::Category(RootItem *parent) : RootItem(parent) {
setKind(RootItemKind::Category);
}
Category::~Category() {

View File

@ -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() {

View File

@ -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<StandardServiceRoot*>(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());

View File

@ -67,9 +67,6 @@ class StandardCategory : public Category {
bool addItself(RootItem *parent);
bool editItself(StandardCategory *new_category_data);
private:
void init();
};
#endif // FEEDSMODELCLASSICCATEGORY_H

View File

@ -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());

View File

@ -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 <QPair>
@ -207,17 +210,68 @@ TtRssGetFeedsCategoriesResponse::TtRssGetFeedsCategoriesResponse(const QString &
TtRssGetFeedsCategoriesResponse::~TtRssGetFeedsCategoriesResponse() {
}
QList<RootItem*> TtRssGetFeedsCategoriesResponse::feedsCategories() {
QList<RootItem*> items;
RootItem *TtRssGetFeedsCategoriesResponse::feedsCategories() {
RootItem *parent = new RootItem();
if (status() == API_STATUS_OK) {
// We have data, construct object tree according to data.
QList<QVariant> items_to_process = m_rawContent["content"].toMap()["categories"].toMap()["items"].toList();
QList<QPair<RootItem*,QVariant> > pairs;
while (!items_to_process.isEmpty()) {
foreach (QVariant item, items_to_process) {
pairs.append(QPair<RootItem*,QVariant>(parent, item));
}
while (!pairs.isEmpty()) {
QPair<RootItem*,QVariant> pair = pairs.takeFirst();
RootItem *act_parent = pair.first;
QMap<QString,QVariant> 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<RootItem*,QVariant>(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<RootItem*,QVariant>(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;
}

View File

@ -58,7 +58,7 @@ class TtRssGetFeedsCategoriesResponse : public TtRssResponse {
explicit TtRssGetFeedsCategoriesResponse(const QString &raw_content = QString());
virtual ~TtRssGetFeedsCategoriesResponse();
QList<RootItem*> feedsCategories();
RootItem *feedsCategories();
};
class TtRssNetworkFactory {

View File

@ -15,11 +15,21 @@
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#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;
}

View File

@ -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

View File

@ -15,12 +15,29 @@
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#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<Message> TtRssFeed::undeletedMessages() const {
return QList<Message>();
}
int TtRssFeed::customId() const {
return m_customId;
}
void TtRssFeed::setCustomId(int custom_id) {
m_customId = custom_id;
}

View File

@ -18,13 +18,22 @@
#ifndef TTRSSFEED_H
#define TTRSSFEED_H
#include <services/abstract/feed.h>
#include "services/abstract/feed.h"
class TtRssFeed : public Feed {
public:
explicit TtRssFeed(RootItem *parent = NULL);
virtual ~TtRssFeed();
int update();
QList<Message> undeletedMessages() const;
int customId() const;
void setCustomId(int custom_id);
private:
int m_customId;
};
#endif // TTRSSFEED_H

View File

@ -230,5 +230,5 @@ void TtRssServiceRoot::syncIn() {
QNetworkReply::NetworkError err;
QList<RootItem*> aa = m_network->getFeedsCategories(err).feedsCategories();
RootItem *aa = m_network->getFeedsCategories(err).feedsCategories();
}