Old data of TT-RSS account are now purged when credentials are changed and new data are synced.
This commit is contained in:
parent
bb9b251acd
commit
a502af9437
@ -139,10 +139,13 @@ void FormEditAccount::performTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FormEditAccount::onClickedOk() {
|
void FormEditAccount::onClickedOk() {
|
||||||
|
bool editing_account = true;
|
||||||
|
|
||||||
if (m_editableRoot == NULL) {
|
if (m_editableRoot == NULL) {
|
||||||
// We want to confirm newly created account.
|
// We want to confirm newly created account.
|
||||||
// So save new account into DB, setup its properties.
|
// So save new account into DB, setup its properties.
|
||||||
m_editableRoot = new TtRssServiceRoot();
|
m_editableRoot = new TtRssServiceRoot();
|
||||||
|
editing_account = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_editableRoot->network()->setUrl(m_ui->m_txtUrl->lineEdit()->text());
|
m_editableRoot->network()->setUrl(m_ui->m_txtUrl->lineEdit()->text());
|
||||||
@ -150,6 +153,11 @@ void FormEditAccount::onClickedOk() {
|
|||||||
m_editableRoot->network()->setPassword(m_ui->m_txtPassword->lineEdit()->text());
|
m_editableRoot->network()->setPassword(m_ui->m_txtPassword->lineEdit()->text());
|
||||||
m_editableRoot->saveAccountDataToDatabase();
|
m_editableRoot->saveAccountDataToDatabase();
|
||||||
|
|
||||||
|
if (editing_account) {
|
||||||
|
m_editableRoot->completelyRemoveAllData();
|
||||||
|
m_editableRoot->syncIn();
|
||||||
|
}
|
||||||
|
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,8 @@
|
|||||||
|
|
||||||
|
|
||||||
TtRssNetworkFactory::TtRssNetworkFactory()
|
TtRssNetworkFactory::TtRssNetworkFactory()
|
||||||
: m_url(QString()), m_username(QString()), m_password(QString()), m_sessionId(QString()) {
|
: m_url(QString()), m_username(QString()), m_password(QString()), m_sessionId(QString()),
|
||||||
|
m_lastLoginTime(QDateTime()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TtRssNetworkFactory::~TtRssNetworkFactory() {
|
TtRssNetworkFactory::~TtRssNetworkFactory() {
|
||||||
@ -61,6 +62,10 @@ void TtRssNetworkFactory::setPassword(const QString &password) {
|
|||||||
m_password = password;
|
m_password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDateTime TtRssNetworkFactory::lastLoginTime() const {
|
||||||
|
return m_lastLoginTime;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: ukazky
|
// TODO: ukazky
|
||||||
|
|
||||||
/* ukazky
|
/* ukazky
|
||||||
@ -86,6 +91,7 @@ TtRssLoginResponse TtRssNetworkFactory::login(QNetworkReply::NetworkError &error
|
|||||||
|
|
||||||
if (network_reply.first == QNetworkReply::NoError) {
|
if (network_reply.first == QNetworkReply::NoError) {
|
||||||
m_sessionId = login_response.sessionId();
|
m_sessionId = login_response.sessionId();
|
||||||
|
m_lastLoginTime = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
error = network_reply.first;
|
error = network_reply.first;
|
||||||
|
@ -88,6 +88,9 @@ class TtRssNetworkFactory {
|
|||||||
QString password() const;
|
QString password() const;
|
||||||
void setPassword(const QString &password);
|
void setPassword(const QString &password);
|
||||||
|
|
||||||
|
// Metadata.
|
||||||
|
QDateTime lastLoginTime() const;
|
||||||
|
|
||||||
// Operations.
|
// Operations.
|
||||||
|
|
||||||
// Logs user in.
|
// Logs user in.
|
||||||
@ -109,6 +112,7 @@ class TtRssNetworkFactory {
|
|||||||
QString m_username;
|
QString m_username;
|
||||||
QString m_password;
|
QString m_password;
|
||||||
QString m_sessionId;
|
QString m_sessionId;
|
||||||
|
QDateTime m_lastLoginTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TTRSSNETWORKFACTORY_H
|
#endif // TTRSSNETWORKFACTORY_H
|
||||||
|
@ -282,6 +282,15 @@ void TtRssServiceRoot::updateTitle() {
|
|||||||
setTitle(m_network->username() + QL1S("@") + host);
|
setTitle(m_network->username() + QL1S("@") + host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TtRssServiceRoot::completelyRemoveAllData() {
|
||||||
|
// Purge old data from SQL and clean all model items.
|
||||||
|
removeOldFeedTree(true);
|
||||||
|
cleanAllItems();
|
||||||
|
updateCounts(true);
|
||||||
|
itemChanged(QList<RootItem*>() << this);
|
||||||
|
requestReloadMessageList(true);
|
||||||
|
}
|
||||||
|
|
||||||
void TtRssServiceRoot::syncIn() {
|
void TtRssServiceRoot::syncIn() {
|
||||||
QNetworkReply::NetworkError err;
|
QNetworkReply::NetworkError err;
|
||||||
TtRssGetFeedsCategoriesResponse feed_cats_response = m_network->getFeedsCategories(err);
|
TtRssGetFeedsCategoriesResponse feed_cats_response = m_network->getFeedsCategories(err);
|
||||||
@ -290,7 +299,7 @@ void TtRssServiceRoot::syncIn() {
|
|||||||
RootItem *new_tree = feed_cats_response.feedsCategories(true, m_network->url());
|
RootItem *new_tree = feed_cats_response.feedsCategories(true, m_network->url());
|
||||||
|
|
||||||
// Purge old data from SQL and clean all model items.
|
// Purge old data from SQL and clean all model items.
|
||||||
removeOldFeedTree();
|
removeOldFeedTree(true);
|
||||||
cleanAllItems();
|
cleanAllItems();
|
||||||
|
|
||||||
// Model is clean, now store new tree into DB and
|
// Model is clean, now store new tree into DB and
|
||||||
@ -326,7 +335,7 @@ QStringList TtRssServiceRoot::textualFeedIds(const QList<Feed*> &feeds) {
|
|||||||
return stringy_ids;
|
return stringy_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TtRssServiceRoot::removeOldFeedTree() {
|
void TtRssServiceRoot::removeOldFeedTree(bool including_messages) {
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
QSqlQuery query(database);
|
QSqlQuery query(database);
|
||||||
query.setForwardOnly(true);
|
query.setForwardOnly(true);
|
||||||
@ -338,6 +347,12 @@ void TtRssServiceRoot::removeOldFeedTree() {
|
|||||||
query.prepare(QSL("DELETE FROM Categories WHERE account_id = :account_id;"));
|
query.prepare(QSL("DELETE FROM Categories WHERE account_id = :account_id;"));
|
||||||
query.bindValue(QSL(":account_id"), accountId());
|
query.bindValue(QSL(":account_id"), accountId());
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
|
if (including_messages) {
|
||||||
|
query.prepare(QSL("DELETE FROM Messages WHERE account_id = :account_id;"));
|
||||||
|
query.bindValue(QSL(":account_id"), accountId());
|
||||||
|
query.exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TtRssServiceRoot::cleanAllItems() {
|
void TtRssServiceRoot::cleanAllItems() {
|
||||||
|
@ -71,7 +71,9 @@ class TtRssServiceRoot : public ServiceRoot {
|
|||||||
void saveAccountDataToDatabase();
|
void saveAccountDataToDatabase();
|
||||||
void updateTitle();
|
void updateTitle();
|
||||||
|
|
||||||
private slots:
|
void completelyRemoveAllData();
|
||||||
|
|
||||||
|
public slots:
|
||||||
void syncIn();
|
void syncIn();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -79,7 +81,7 @@ class TtRssServiceRoot : public ServiceRoot {
|
|||||||
// which are suitable as IN clause for SQL queries.
|
// which are suitable as IN clause for SQL queries.
|
||||||
QStringList textualFeedIds(const QList<Feed*> &feeds);
|
QStringList textualFeedIds(const QList<Feed*> &feeds);
|
||||||
|
|
||||||
void removeOldFeedTree();
|
void removeOldFeedTree(bool including_messages);
|
||||||
void cleanAllItems();
|
void cleanAllItems();
|
||||||
void storeNewFeedTree(RootItem *root);
|
void storeNewFeedTree(RootItem *root);
|
||||||
void loadFromDatabase();
|
void loadFromDatabase();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user