Added some initial network methods for adding/removed TT-RSS feeds.
This commit is contained in:
parent
806a5a0475
commit
284768c93f
@ -20,12 +20,9 @@
|
|||||||
#include "definitions/definitions.h"
|
#include "definitions/definitions.h"
|
||||||
|
|
||||||
|
|
||||||
Feed::Feed(RootItem *parent) : RootItem(parent) {
|
Feed::Feed(RootItem *parent)
|
||||||
m_status = Normal;
|
: RootItem(parent), m_url(QString()), m_status(Normal), m_autoUpdateType(DefaultAutoUpdate),
|
||||||
m_autoUpdateType = DefaultAutoUpdate;
|
m_autoUpdateInitialInterval(DEFAULT_AUTO_UPDATE_INTERVAL), m_autoUpdateRemainingInterval(DEFAULT_AUTO_UPDATE_INTERVAL) {
|
||||||
m_autoUpdateInitialInterval = DEFAULT_AUTO_UPDATE_INTERVAL;
|
|
||||||
m_autoUpdateRemainingInterval = DEFAULT_AUTO_UPDATE_INTERVAL;
|
|
||||||
|
|
||||||
setKind(RootItemKind::Feed);
|
setKind(RootItemKind::Feed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,16 @@ class Feed : public RootItem {
|
|||||||
m_status = status;
|
m_status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QString url() const {
|
||||||
|
return m_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setUrl(const QString &url) {
|
||||||
|
m_url = url;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString m_url;
|
||||||
Status m_status;
|
Status m_status;
|
||||||
AutoUpdateType m_autoUpdateType;
|
AutoUpdateType m_autoUpdateType;
|
||||||
int m_autoUpdateInitialInterval;
|
int m_autoUpdateInitialInterval;
|
||||||
|
@ -54,7 +54,6 @@ StandardFeed::StandardFeed(RootItem *parent_item)
|
|||||||
m_totalCount = 0;
|
m_totalCount = 0;
|
||||||
m_unreadCount = 0;
|
m_unreadCount = 0;
|
||||||
m_encoding = QString();
|
m_encoding = QString();
|
||||||
m_url = QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StandardFeed::StandardFeed(const StandardFeed &other)
|
StandardFeed::StandardFeed(const StandardFeed &other)
|
||||||
@ -67,8 +66,8 @@ StandardFeed::StandardFeed(const StandardFeed &other)
|
|||||||
m_totalCount = other.countOfAllMessages();
|
m_totalCount = other.countOfAllMessages();
|
||||||
m_unreadCount = other.countOfUnreadMessages();
|
m_unreadCount = other.countOfUnreadMessages();
|
||||||
m_encoding = other.encoding();
|
m_encoding = other.encoding();
|
||||||
m_url = other.url();
|
|
||||||
|
|
||||||
|
setUrl(other.url());
|
||||||
setStatus(other.status());
|
setStatus(other.status());
|
||||||
setAutoUpdateType(other.autoUpdateType());
|
setAutoUpdateType(other.autoUpdateType());
|
||||||
setAutoUpdateInitialInterval(other.autoUpdateInitialInterval());
|
setAutoUpdateInitialInterval(other.autoUpdateInitialInterval());
|
||||||
|
@ -138,14 +138,6 @@ class StandardFeed : public Feed {
|
|||||||
m_encoding = encoding;
|
m_encoding = encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QString url() const {
|
|
||||||
return m_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void setUrl(const QString &url) {
|
|
||||||
m_url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkReply::NetworkError networkError() const;
|
QNetworkReply::NetworkError networkError() const;
|
||||||
|
|
||||||
// Tries to guess feed hidden under given URL
|
// Tries to guess feed hidden under given URL
|
||||||
@ -179,7 +171,6 @@ class StandardFeed : public Feed {
|
|||||||
int m_unreadCount;
|
int m_unreadCount;
|
||||||
|
|
||||||
QString m_encoding;
|
QString m_encoding;
|
||||||
QString m_url;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(StandardFeed::Type)
|
Q_DECLARE_METATYPE(StandardFeed::Type)
|
||||||
|
@ -40,4 +40,8 @@
|
|||||||
#define STF_URL_MANY_FEEDS 4
|
#define STF_URL_MANY_FEEDS 4
|
||||||
#define STF_INSERTED 1
|
#define STF_INSERTED 1
|
||||||
|
|
||||||
|
// Unsubscribe from feed.
|
||||||
|
#define UFF_FEED_NOT_FOUND "FEED_NOT_FOUND"
|
||||||
|
#define UFF_OK "OK"
|
||||||
|
|
||||||
#endif // DEFINITIONS_H
|
#endif // DEFINITIONS_H
|
||||||
|
@ -267,6 +267,64 @@ TtRssSubscribeToFeedResponse TtRssNetworkFactory::subscribeToFeed(const QString
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TtRssGetFeedsResponse TtRssNetworkFactory::getFeeds(int category_id) {
|
||||||
|
QtJson::JsonObject json;
|
||||||
|
json["op"] = "getFeeds";
|
||||||
|
json["sid"] = m_sessionId;
|
||||||
|
json["cat_id"] = category_id;
|
||||||
|
|
||||||
|
QByteArray result_raw;
|
||||||
|
NetworkResult network_reply = NetworkFactory::uploadData(m_url, DOWNLOAD_TIMEOUT, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
||||||
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
|
TtRssGetFeedsResponse result(QString::fromUtf8(result_raw));
|
||||||
|
|
||||||
|
if (result.isNotLoggedIn()) {
|
||||||
|
// We are not logged in.
|
||||||
|
login();
|
||||||
|
json["sid"] = m_sessionId;
|
||||||
|
|
||||||
|
network_reply = NetworkFactory::uploadData(m_url, DOWNLOAD_TIMEOUT, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
||||||
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
|
result = TtRssGetFeedsResponse(QString::fromUtf8(result_raw));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (network_reply.first != QNetworkReply::NoError) {
|
||||||
|
qWarning("TT-RSS: getFeeds failed with error %d.", network_reply.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastError = network_reply.first;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
TtRssUnsubscribeFeedResponse TtRssNetworkFactory::unsubscribeFeed(int feed_id) {
|
||||||
|
QtJson::JsonObject json;
|
||||||
|
json["op"] = "unsubscribeFeed";
|
||||||
|
json["sid"] = m_sessionId;
|
||||||
|
json["cat_id"] = feed_id;
|
||||||
|
|
||||||
|
QByteArray result_raw;
|
||||||
|
NetworkResult network_reply = NetworkFactory::uploadData(m_url, DOWNLOAD_TIMEOUT, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
||||||
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
|
TtRssUnsubscribeFeedResponse result(QString::fromUtf8(result_raw));
|
||||||
|
|
||||||
|
if (result.isNotLoggedIn()) {
|
||||||
|
// We are not logged in.
|
||||||
|
login();
|
||||||
|
json["sid"] = m_sessionId;
|
||||||
|
|
||||||
|
network_reply = NetworkFactory::uploadData(m_url, DOWNLOAD_TIMEOUT, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
||||||
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
|
result = TtRssUnsubscribeFeedResponse(QString::fromUtf8(result_raw));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (network_reply.first != QNetworkReply::NoError) {
|
||||||
|
qWarning("TT-RSS: getFeeds failed with error %d.", network_reply.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastError = network_reply.first;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TtRssGetConfigResponse TtRssNetworkFactory::getConfig() {
|
TtRssGetConfigResponse TtRssNetworkFactory::getConfig() {
|
||||||
QtJson::JsonObject json;
|
QtJson::JsonObject json;
|
||||||
@ -588,3 +646,49 @@ int TtRssSubscribeToFeedResponse::code() const {
|
|||||||
return STF_UNKNOWN;
|
return STF_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TtRssUnsubscribeFeedResponse::TtRssUnsubscribeFeedResponse(const QString &raw_content) : TtRssResponse(raw_content) {
|
||||||
|
}
|
||||||
|
|
||||||
|
TtRssUnsubscribeFeedResponse::~TtRssUnsubscribeFeedResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TtRssUnsubscribeFeedResponse::code() const {
|
||||||
|
if (m_rawContent.contains(QSL("content"))) {
|
||||||
|
QVariantMap map = m_rawContent["content"].toMap();
|
||||||
|
|
||||||
|
if (map.contains(QSL("error"))) {
|
||||||
|
return map["error"].toString();
|
||||||
|
}
|
||||||
|
else if (map.contains(QSL("status"))) {
|
||||||
|
return map["status"].toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TtRssGetFeedsResponse::TtRssGetFeedsResponse(const QString &raw_content) {
|
||||||
|
}
|
||||||
|
|
||||||
|
TtRssGetFeedsResponse::~TtRssGetFeedsResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<TtRssFeed*> TtRssGetFeedsResponse::feeds() const {
|
||||||
|
QList<TtRssFeed*> feeds;
|
||||||
|
|
||||||
|
foreach (QVariant feed_var, m_rawContent["content"].toList()) {
|
||||||
|
QVariantMap feed_map = feed_var.toMap();
|
||||||
|
TtRssFeed *feed = new TtRssFeed();
|
||||||
|
|
||||||
|
feed->setTitle(feed_map["title"].toString());
|
||||||
|
feed->setUrl(feed_map["feed_url"].toString());
|
||||||
|
feed->setCustomId(feed_map["id"].toInt());
|
||||||
|
|
||||||
|
feeds.append(feed);
|
||||||
|
}
|
||||||
|
|
||||||
|
return feeds;
|
||||||
|
}
|
||||||
|
@ -92,6 +92,23 @@ class TtRssSubscribeToFeedResponse : public TtRssResponse {
|
|||||||
int code() const;
|
int code() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TtRssUnsubscribeFeedResponse : public TtRssResponse {
|
||||||
|
public:
|
||||||
|
explicit TtRssUnsubscribeFeedResponse(const QString &raw_content = QString());
|
||||||
|
virtual ~TtRssUnsubscribeFeedResponse();
|
||||||
|
|
||||||
|
QString code() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TtRssGetFeedsResponse : public TtRssResponse {
|
||||||
|
public:
|
||||||
|
explicit TtRssGetFeedsResponse(const QString &raw_content = QString());
|
||||||
|
virtual ~TtRssGetFeedsResponse();
|
||||||
|
|
||||||
|
QList<TtRssFeed*> feeds() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
class TtRssGetConfigResponse : public TtRssResponse {
|
class TtRssGetConfigResponse : public TtRssResponse {
|
||||||
public:
|
public:
|
||||||
@ -168,6 +185,10 @@ class TtRssNetworkFactory {
|
|||||||
TtRssSubscribeToFeedResponse subscribeToFeed(const QString &url, int category_id, bool protectd = false,
|
TtRssSubscribeToFeedResponse subscribeToFeed(const QString &url, int category_id, bool protectd = false,
|
||||||
const QString &username = QString(), const QString &password = QString());
|
const QString &username = QString(), const QString &password = QString());
|
||||||
|
|
||||||
|
TtRssGetFeedsResponse getFeeds(int category_id);
|
||||||
|
|
||||||
|
TtRssUnsubscribeFeedResponse unsubscribeFeed(int feed_id);
|
||||||
|
|
||||||
//TtRssGetConfigResponse getConfig();
|
//TtRssGetConfigResponse getConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -246,7 +246,6 @@ bool TtRssFeed::addItself(RootItem *parent, const QString &url, bool protectd,
|
|||||||
int category_id = parent->kind() == RootItemKind::ServiceRoot ?
|
int category_id = parent->kind() == RootItemKind::ServiceRoot ?
|
||||||
0 :
|
0 :
|
||||||
qobject_cast<TtRssCategory*>(parent)->customId();
|
qobject_cast<TtRssCategory*>(parent)->customId();
|
||||||
|
|
||||||
TtRssSubscribeToFeedResponse response = root->network()->subscribeToFeed(url, category_id, protectd, username, password);
|
TtRssSubscribeToFeedResponse response = root->network()->subscribeToFeed(url, category_id, protectd, username, password);
|
||||||
|
|
||||||
if (response.code() == STF_INSERTED || response.code() == STF_UPDATED) {
|
if (response.code() == STF_INSERTED || response.code() == STF_UPDATED) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user