Adding of feeds could work.
This commit is contained in:
parent
284768c93f
commit
0f5f224db8
BIN
resources/graphics/icons/mini-kfaenza/application-owncloud.png
Executable file
BIN
resources/graphics/icons/mini-kfaenza/application-owncloud.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
resources/graphics/icons/numix/application-owncloud.png
Executable file
BIN
resources/graphics/icons/numix/application-owncloud.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
@ -18,13 +18,18 @@
|
|||||||
#include "services/tt-rss/gui/formeditfeed.h"
|
#include "services/tt-rss/gui/formeditfeed.h"
|
||||||
|
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.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 "services/tt-rss/ttrssserviceroot.h"
|
#include "services/tt-rss/ttrssserviceroot.h"
|
||||||
|
#include "services/tt-rss/network/ttrssnetworkfactory.h"
|
||||||
|
#include "gui/dialogs/formmain.h"
|
||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
FormEditFeed::FormEditFeed(TtRssServiceRoot *root, QWidget *parent)
|
FormEditFeed::FormEditFeed(TtRssServiceRoot *root, QWidget *parent)
|
||||||
@ -198,22 +203,30 @@ void FormEditFeed::saveFeed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FormEditFeed::addNewFeed() {
|
void FormEditFeed::addNewFeed() {
|
||||||
TtRssFeed *new_feed= new TtRssFeed();
|
|
||||||
RootItem *parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
|
RootItem *parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
|
||||||
|
TtRssServiceRoot *root = parent->kind() == RootItemKind::Category ?
|
||||||
|
qobject_cast<TtRssCategory*>(parent)->serviceRoot() :
|
||||||
|
qobject_cast<TtRssServiceRoot*>(parent);
|
||||||
|
int category_id = parent->kind() == RootItemKind::ServiceRoot ?
|
||||||
|
0 :
|
||||||
|
qobject_cast<TtRssCategory*>(parent)->customId();
|
||||||
|
TtRssSubscribeToFeedResponse response = root->network()->subscribeToFeed(m_ui->m_txtUrl->lineEdit()->text(),
|
||||||
|
category_id,
|
||||||
|
m_ui->m_gbAuthentication->isChecked(),
|
||||||
|
m_ui->m_txtUsername->lineEdit()->text(),
|
||||||
|
m_ui->m_txtPassword->lineEdit()->text());
|
||||||
|
|
||||||
new_feed->setAutoUpdateType(static_cast<Feed::AutoUpdateType>(m_ui->m_cmbAutoUpdateType->itemData(m_ui->m_cmbAutoUpdateType->currentIndex()).toInt()));
|
if (response.code() == STF_INSERTED || response.code() == STF_UPDATED) {
|
||||||
new_feed->setAutoUpdateInitialInterval(m_ui->m_spinAutoUpdateInterval->value());
|
// Feed was added online.
|
||||||
|
|
||||||
if (new_feed->addItself(parent, m_ui->m_txtUrl->lineEdit()->text(), m_ui->m_gbAuthentication->isChecked(),
|
|
||||||
m_ui->m_txtUsername->lineEdit()->text(), m_ui->m_txtPassword->lineEdit()->text())) {
|
|
||||||
m_root->requestItemReassignment(new_feed, parent);
|
|
||||||
accept();
|
accept();
|
||||||
|
qApp->showGuiMessage(tr("Feed added"), tr("Feed was added, triggering sync in now."), QSystemTrayIcon::Information);
|
||||||
|
QTimer::singleShot(100, root, SLOT(syncIn()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
delete new_feed;
|
reject();
|
||||||
qApp->showGuiMessage(tr("Cannot add feed"),
|
qApp->showGuiMessage(tr("Cannot add feed"),
|
||||||
tr("Feed was not added due to error."),
|
tr("Feed was not added due to error."),
|
||||||
QSystemTrayIcon::Critical, this, true);
|
QSystemTrayIcon::Critical, qApp->mainForm(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,35 +267,6 @@ 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) {
|
TtRssUnsubscribeFeedResponse TtRssNetworkFactory::unsubscribeFeed(int feed_id) {
|
||||||
QtJson::JsonObject json;
|
QtJson::JsonObject json;
|
||||||
json["op"] = "unsubscribeFeed";
|
json["op"] = "unsubscribeFeed";
|
||||||
@ -668,27 +639,3 @@ QString TtRssUnsubscribeFeedResponse::code() const {
|
|||||||
|
|
||||||
return QString();
|
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;
|
|
||||||
}
|
|
||||||
|
@ -100,15 +100,6 @@ class TtRssUnsubscribeFeedResponse : public TtRssResponse {
|
|||||||
QString code() const;
|
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:
|
||||||
@ -185,8 +176,6 @@ 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);
|
TtRssUnsubscribeFeedResponse unsubscribeFeed(int feed_id);
|
||||||
|
|
||||||
//TtRssGetConfigResponse getConfig();
|
//TtRssGetConfigResponse getConfig();
|
||||||
|
@ -238,32 +238,6 @@ void TtRssFeed::setCustomId(int custom_id) {
|
|||||||
m_customId = custom_id;
|
m_customId = custom_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssFeed::addItself(RootItem *parent, const QString &url, bool protectd,
|
|
||||||
const QString &username, const QString &password) {
|
|
||||||
TtRssServiceRoot *root = parent->kind() == RootItemKind::Category ?
|
|
||||||
qobject_cast<TtRssCategory*>(parent)->serviceRoot() :
|
|
||||||
qobject_cast<TtRssServiceRoot*>(parent);
|
|
||||||
int category_id = parent->kind() == RootItemKind::ServiceRoot ?
|
|
||||||
0 :
|
|
||||||
qobject_cast<TtRssCategory*>(parent)->customId();
|
|
||||||
TtRssSubscribeToFeedResponse response = root->network()->subscribeToFeed(url, category_id, protectd, username, password);
|
|
||||||
|
|
||||||
if (response.code() == STF_INSERTED || response.code() == STF_UPDATED) {
|
|
||||||
// Feed added on TT-RSS server, get its ID.
|
|
||||||
|
|
||||||
// TODO: ted potrebujeme vyplnit customID toho přidaného kanálu
|
|
||||||
// asi přes getFeeds
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: todo
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TtRssFeed::editItself(TtRssFeed *new_feed_data) {
|
bool TtRssFeed::editItself(TtRssFeed *new_feed_data) {
|
||||||
QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings);
|
QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings);
|
||||||
QSqlQuery query_update(database);
|
QSqlQuery query_update(database);
|
||||||
|
@ -54,8 +54,6 @@ class TtRssFeed : public Feed {
|
|||||||
int customId() const;
|
int customId() const;
|
||||||
void setCustomId(int custom_id);
|
void setCustomId(int custom_id);
|
||||||
|
|
||||||
bool addItself(RootItem *parent, const QString &url, bool protectd = false,
|
|
||||||
const QString &username = QString(), const QString &password = QString());
|
|
||||||
bool editItself(TtRssFeed *new_feed_data);
|
bool editItself(TtRssFeed *new_feed_data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user