mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-30 17:15:01 +01:00
Work on syncing.
This commit is contained in:
parent
746e7aae1f
commit
a9f44bdd02
@ -148,7 +148,7 @@ void FormEditAccount::onClickedOk() {
|
||||
m_editableRoot->network()->setUrl(m_ui->m_txtUrl->lineEdit()->text());
|
||||
m_editableRoot->network()->setUsername(m_ui->m_txtUsername->lineEdit()->text());
|
||||
m_editableRoot->network()->setPassword(m_ui->m_txtPassword->lineEdit()->text());
|
||||
m_editableRoot->saveToDatabase();
|
||||
m_editableRoot->saveAccountDataToDatabase();
|
||||
|
||||
accept();
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ TtRssResponse TtRssNetworkFactory::logout(QNetworkReply::NetworkError &error) {
|
||||
return TtRssResponse(QString::fromUtf8(result_raw));
|
||||
}
|
||||
|
||||
TtRssGetFeedsCategoriesResponse TtRssNetworkFactory::getFeedsCategories(QNetworkReply::NetworkError &error) {
|
||||
TtRssGetFeedsTreeResponse TtRssNetworkFactory::getFeedsTree(QNetworkReply::NetworkError &error) {
|
||||
QtJson::JsonObject json;
|
||||
json["op"] = "getFeedTree";
|
||||
json["sid"] = m_sessionId;
|
||||
@ -111,7 +111,7 @@ TtRssGetFeedsCategoriesResponse TtRssNetworkFactory::getFeedsCategories(QNetwork
|
||||
|
||||
QByteArray result_raw;
|
||||
NetworkResult network_reply = NetworkFactory::uploadData(m_url, DOWNLOAD_TIMEOUT, QtJson::serialize(json), CONTENT_TYPE, result_raw);
|
||||
TtRssGetFeedsCategoriesResponse result(QString::fromUtf8(result_raw));
|
||||
TtRssGetFeedsTreeResponse result(QString::fromUtf8(result_raw));
|
||||
|
||||
if (result.isNotLoggedIn()) {
|
||||
// We are not logged in.
|
||||
@ -119,7 +119,7 @@ TtRssGetFeedsCategoriesResponse TtRssNetworkFactory::getFeedsCategories(QNetwork
|
||||
json["sid"] = m_sessionId;
|
||||
|
||||
network_reply = NetworkFactory::uploadData(m_url, DOWNLOAD_TIMEOUT, QtJson::serialize(json), CONTENT_TYPE, result_raw);
|
||||
result = TtRssGetFeedsCategoriesResponse(QString::fromUtf8(result_raw));
|
||||
result = TtRssGetFeedsTreeResponse(QString::fromUtf8(result_raw));
|
||||
}
|
||||
|
||||
error = network_reply.first;
|
||||
@ -203,14 +203,13 @@ bool TtRssResponse::hasError() const {
|
||||
}
|
||||
|
||||
|
||||
TtRssGetFeedsCategoriesResponse::TtRssGetFeedsCategoriesResponse(const QString &raw_content) : TtRssResponse(raw_content) {
|
||||
|
||||
TtRssGetFeedsTreeResponse::TtRssGetFeedsTreeResponse(const QString &raw_content) : TtRssResponse(raw_content) {
|
||||
}
|
||||
|
||||
TtRssGetFeedsCategoriesResponse::~TtRssGetFeedsCategoriesResponse() {
|
||||
TtRssGetFeedsTreeResponse::~TtRssGetFeedsTreeResponse() {
|
||||
}
|
||||
|
||||
RootItem *TtRssGetFeedsCategoriesResponse::feedsCategories() {
|
||||
RootItem *TtRssGetFeedsTreeResponse::feedsTree() {
|
||||
RootItem *parent = new RootItem();
|
||||
|
||||
if (status() == API_STATUS_OK) {
|
||||
|
@ -53,12 +53,12 @@ class TtRssLoginResponse : public TtRssResponse {
|
||||
QString sessionId() const;
|
||||
};
|
||||
|
||||
class TtRssGetFeedsCategoriesResponse : public TtRssResponse {
|
||||
class TtRssGetFeedsTreeResponse : public TtRssResponse {
|
||||
public:
|
||||
explicit TtRssGetFeedsCategoriesResponse(const QString &raw_content = QString());
|
||||
virtual ~TtRssGetFeedsCategoriesResponse();
|
||||
explicit TtRssGetFeedsTreeResponse(const QString &raw_content = QString());
|
||||
virtual ~TtRssGetFeedsTreeResponse();
|
||||
|
||||
RootItem *feedsCategories();
|
||||
RootItem *feedsTree();
|
||||
};
|
||||
|
||||
class TtRssNetworkFactory {
|
||||
@ -84,7 +84,7 @@ class TtRssNetworkFactory {
|
||||
TtRssResponse logout(QNetworkReply::NetworkError &error);
|
||||
|
||||
// Gets feeds from the server.
|
||||
TtRssGetFeedsCategoriesResponse getFeedsCategories(QNetworkReply::NetworkError &error);
|
||||
TtRssGetFeedsTreeResponse getFeedsTree(QNetworkReply::NetworkError &error);
|
||||
|
||||
private:
|
||||
QString m_url;
|
||||
|
@ -87,7 +87,6 @@ QList<ServiceRoot*> TtRssServiceEntryPoint::initializeSubtree() {
|
||||
root->network()->setPassword(query.value(2).toString());
|
||||
root->network()->setUrl(query.value(3).toString());
|
||||
root->updateTitle();
|
||||
root->loadFromDatabase();
|
||||
roots.append(root);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ TtRssServiceRoot::~TtRssServiceRoot() {
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::start() {
|
||||
loadFeedTreeFromDatabase();
|
||||
|
||||
if (childItems().isEmpty()) {
|
||||
syncIn();
|
||||
}
|
||||
@ -164,7 +166,7 @@ TtRssNetworkFactory *TtRssServiceRoot::network() const {
|
||||
return m_network;
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::saveToDatabase() {
|
||||
void TtRssServiceRoot::saveAccountDataToDatabase() {
|
||||
if (accountId() != NO_PARENT_CATEGORY) {
|
||||
// We are overwritting previously saved data.
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
@ -209,10 +211,6 @@ void TtRssServiceRoot::saveToDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::loadFromDatabase() {
|
||||
// TODO: Load feeds/categories from DB.
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::updateTitle() {
|
||||
QString host = QUrl(m_network->url()).host();
|
||||
|
||||
@ -227,8 +225,34 @@ void TtRssServiceRoot::syncIn() {
|
||||
// TODO: provede stažení kanálů/kategorií
|
||||
// ze serveru, a sloučení s aktuálními
|
||||
// neprovádí aktualizace kanálů ani stažení počtu nepřečtených zpráv
|
||||
QNetworkReply::NetworkError err;
|
||||
QNetworkReply::NetworkError error;
|
||||
RootItem *new_feeds = m_network->getFeedsTree(error).feedsTree();
|
||||
|
||||
if (error == QNetworkReply::NoError) {
|
||||
// We have new feeds, purge old and set new to DB.
|
||||
removeOldFeedTree();
|
||||
|
||||
RootItem *aa = m_network->getFeedsCategories(err).feedsCategories();
|
||||
foreach (RootItem *child, childItems()) {
|
||||
requestItemRemoval(child);
|
||||
}
|
||||
|
||||
clearChildren();
|
||||
|
||||
// Old stuff is gone.
|
||||
storeNewFeedTree(new_feeds);
|
||||
loadFeedTreeFromDatabase();
|
||||
//itemChanged(QList<RootItem*>() << this);
|
||||
}
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::removeOldFeedTree() {
|
||||
// TODO: vymazat kanaly a kategorie.
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::storeNewFeedTree(RootItem *tree_root) {
|
||||
// TODO: ulozit do db.
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::loadFeedTreeFromDatabase() {
|
||||
// TODO: nacist kanaly a kategorie z db
|
||||
}
|
||||
|
@ -66,14 +66,17 @@ class TtRssServiceRoot : public ServiceRoot {
|
||||
|
||||
TtRssNetworkFactory *network() const;
|
||||
|
||||
void saveToDatabase();
|
||||
void loadFromDatabase();
|
||||
void saveAccountDataToDatabase();
|
||||
void updateTitle();
|
||||
|
||||
private slots:
|
||||
void syncIn();
|
||||
|
||||
private:
|
||||
void removeOldFeedTree();
|
||||
void storeNewFeedTree(RootItem *tree_root);
|
||||
void loadFeedTreeFromDatabase();
|
||||
|
||||
QAction *m_actionSyncIn;
|
||||
QList<QAction*> m_serviceMenu;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user