Initial version of getFeedTree implementation.
This commit is contained in:
parent
90d92e8aa8
commit
746e7aae1f
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
Category::Category(RootItem *parent) : RootItem(parent) {
|
Category::Category(RootItem *parent) : RootItem(parent) {
|
||||||
|
setKind(RootItemKind::Category);
|
||||||
}
|
}
|
||||||
|
|
||||||
Category::~Category() {
|
Category::~Category() {
|
||||||
|
@ -22,9 +22,11 @@
|
|||||||
|
|
||||||
Feed::Feed(RootItem *parent) : RootItem(parent) {
|
Feed::Feed(RootItem *parent) : RootItem(parent) {
|
||||||
m_status = Normal;
|
m_status = Normal;
|
||||||
m_autoUpdateType = DontAutoUpdate;
|
m_autoUpdateType = DefaultAutoUpdate;
|
||||||
m_autoUpdateInitialInterval = DEFAULT_AUTO_UPDATE_INTERVAL;
|
m_autoUpdateInitialInterval = DEFAULT_AUTO_UPDATE_INTERVAL;
|
||||||
m_autoUpdateRemainingInterval = DEFAULT_AUTO_UPDATE_INTERVAL;
|
m_autoUpdateRemainingInterval = DEFAULT_AUTO_UPDATE_INTERVAL;
|
||||||
|
|
||||||
|
setKind(RootItemKind::Feed);
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed::~Feed() {
|
Feed::~Feed() {
|
||||||
|
@ -37,13 +37,10 @@
|
|||||||
|
|
||||||
|
|
||||||
StandardCategory::StandardCategory(RootItem *parent_item) : Category(parent_item) {
|
StandardCategory::StandardCategory(RootItem *parent_item) : Category(parent_item) {
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StandardCategory::StandardCategory(const StandardCategory &other)
|
StandardCategory::StandardCategory(const StandardCategory &other)
|
||||||
: Category(NULL) {
|
: Category(NULL) {
|
||||||
init();
|
|
||||||
|
|
||||||
setId(other.id());
|
setId(other.id());
|
||||||
setTitle(other.title());
|
setTitle(other.title());
|
||||||
setDescription(other.description());
|
setDescription(other.description());
|
||||||
@ -61,10 +58,6 @@ StandardServiceRoot *StandardCategory::serviceRoot() {
|
|||||||
return static_cast<StandardServiceRoot*>(getParentServiceRoot());
|
return static_cast<StandardServiceRoot*>(getParentServiceRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardCategory::init() {
|
|
||||||
setKind(RootItemKind::Category);
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant StandardCategory::data(int column, int role) const {
|
QVariant StandardCategory::data(int column, int role) const {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
@ -222,8 +215,6 @@ bool StandardCategory::editItself(StandardCategory *new_category_data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StandardCategory::StandardCategory(const QSqlRecord &record) : Category(NULL) {
|
StandardCategory::StandardCategory(const QSqlRecord &record) : Category(NULL) {
|
||||||
init();
|
|
||||||
|
|
||||||
setId(record.value(CAT_DB_ID_INDEX).toInt());
|
setId(record.value(CAT_DB_ID_INDEX).toInt());
|
||||||
setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
|
setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
|
||||||
setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString());
|
setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString());
|
||||||
|
@ -67,9 +67,6 @@ class StandardCategory : public Category {
|
|||||||
|
|
||||||
bool addItself(RootItem *parent);
|
bool addItself(RootItem *parent);
|
||||||
bool editItself(StandardCategory *new_category_data);
|
bool editItself(StandardCategory *new_category_data);
|
||||||
|
|
||||||
private:
|
|
||||||
void init();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FEEDSMODELCLASSICCATEGORY_H
|
#endif // FEEDSMODELCLASSICCATEGORY_H
|
||||||
|
@ -55,8 +55,6 @@ StandardFeed::StandardFeed(RootItem *parent_item)
|
|||||||
m_unreadCount = 0;
|
m_unreadCount = 0;
|
||||||
m_encoding = QString();
|
m_encoding = QString();
|
||||||
m_url = QString();
|
m_url = QString();
|
||||||
|
|
||||||
setKind(RootItemKind::Feed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StandardFeed::StandardFeed(const StandardFeed &other)
|
StandardFeed::StandardFeed(const StandardFeed &other)
|
||||||
@ -76,7 +74,6 @@ StandardFeed::StandardFeed(const StandardFeed &other)
|
|||||||
setAutoUpdateInitialInterval(other.autoUpdateInitialInterval());
|
setAutoUpdateInitialInterval(other.autoUpdateInitialInterval());
|
||||||
setAutoUpdateRemainingInterval(other.autoUpdateRemainingInterval());
|
setAutoUpdateRemainingInterval(other.autoUpdateRemainingInterval());
|
||||||
|
|
||||||
setKind(RootItemKind::Feed);
|
|
||||||
setTitle(other.title());
|
setTitle(other.title());
|
||||||
setId(other.id());
|
setId(other.id());
|
||||||
setIcon(other.icon());
|
setIcon(other.icon());
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
#include "core/rootitem.h"
|
#include "core/rootitem.h"
|
||||||
#include "services/tt-rss/definitions.h"
|
#include "services/tt-rss/definitions.h"
|
||||||
#include "services/tt-rss/ttrssfeed.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 "network-web/networkfactory.h"
|
||||||
|
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
@ -207,17 +210,68 @@ TtRssGetFeedsCategoriesResponse::TtRssGetFeedsCategoriesResponse(const QString &
|
|||||||
TtRssGetFeedsCategoriesResponse::~TtRssGetFeedsCategoriesResponse() {
|
TtRssGetFeedsCategoriesResponse::~TtRssGetFeedsCategoriesResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<RootItem*> TtRssGetFeedsCategoriesResponse::feedsCategories() {
|
RootItem *TtRssGetFeedsCategoriesResponse::feedsCategories() {
|
||||||
QList<RootItem*> items;
|
RootItem *parent = new RootItem();
|
||||||
|
|
||||||
if (status() == API_STATUS_OK) {
|
if (status() == API_STATUS_OK) {
|
||||||
// We have data, construct object tree according to data.
|
// We have data, construct object tree according to data.
|
||||||
QList<QVariant> items_to_process = m_rawContent["content"].toMap()["categories"].toMap()["items"].toList();
|
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;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ class TtRssGetFeedsCategoriesResponse : public TtRssResponse {
|
|||||||
explicit TtRssGetFeedsCategoriesResponse(const QString &raw_content = QString());
|
explicit TtRssGetFeedsCategoriesResponse(const QString &raw_content = QString());
|
||||||
virtual ~TtRssGetFeedsCategoriesResponse();
|
virtual ~TtRssGetFeedsCategoriesResponse();
|
||||||
|
|
||||||
QList<RootItem*> feedsCategories();
|
RootItem *feedsCategories();
|
||||||
};
|
};
|
||||||
|
|
||||||
class TtRssNetworkFactory {
|
class TtRssNetworkFactory {
|
||||||
|
@ -15,11 +15,21 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
// 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() {
|
TtRssCategory::~TtRssCategory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TtRssCategory::customId() const {
|
||||||
|
return m_customId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TtRssCategory::setCustomId(int custom_id) {
|
||||||
|
m_customId = custom_id;
|
||||||
|
}
|
||||||
|
@ -25,6 +25,12 @@ class TtRssCategory : public Category {
|
|||||||
public:
|
public:
|
||||||
explicit TtRssCategory(RootItem *parent = NULL);
|
explicit TtRssCategory(RootItem *parent = NULL);
|
||||||
virtual ~TtRssCategory();
|
virtual ~TtRssCategory();
|
||||||
|
|
||||||
|
int customId() const;
|
||||||
|
void setCustomId(int custom_id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_customId;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TTRSSCATEGORY_H
|
#endif // TTRSSCATEGORY_H
|
||||||
|
@ -15,12 +15,29 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
// 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() {
|
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;
|
||||||
|
}
|
||||||
|
@ -18,13 +18,22 @@
|
|||||||
#ifndef TTRSSFEED_H
|
#ifndef TTRSSFEED_H
|
||||||
#define TTRSSFEED_H
|
#define TTRSSFEED_H
|
||||||
|
|
||||||
#include <services/abstract/feed.h>
|
#include "services/abstract/feed.h"
|
||||||
|
|
||||||
|
|
||||||
class TtRssFeed : public Feed {
|
class TtRssFeed : public Feed {
|
||||||
public:
|
public:
|
||||||
explicit TtRssFeed(RootItem *parent = NULL);
|
explicit TtRssFeed(RootItem *parent = NULL);
|
||||||
virtual ~TtRssFeed();
|
virtual ~TtRssFeed();
|
||||||
|
|
||||||
|
int update();
|
||||||
|
QList<Message> undeletedMessages() const;
|
||||||
|
|
||||||
|
int customId() const;
|
||||||
|
void setCustomId(int custom_id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_customId;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TTRSSFEED_H
|
#endif // TTRSSFEED_H
|
||||||
|
@ -230,5 +230,5 @@ void TtRssServiceRoot::syncIn() {
|
|||||||
QNetworkReply::NetworkError err;
|
QNetworkReply::NetworkError err;
|
||||||
|
|
||||||
|
|
||||||
QList<RootItem*> aa = m_network->getFeedsCategories(err).feedsCategories();
|
RootItem *aa = m_network->getFeedsCategories(err).feedsCategories();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user