mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-06 20:33:38 +01:00
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() {
|
||||
bool editing_account = true;
|
||||
|
||||
if (m_editableRoot == NULL) {
|
||||
// We want to confirm newly created account.
|
||||
// So save new account into DB, setup its properties.
|
||||
m_editableRoot = new TtRssServiceRoot();
|
||||
editing_account = false;
|
||||
}
|
||||
|
||||
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->saveAccountDataToDatabase();
|
||||
|
||||
if (editing_account) {
|
||||
m_editableRoot->completelyRemoveAllData();
|
||||
m_editableRoot->syncIn();
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,8 @@
|
||||
|
||||
|
||||
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() {
|
||||
@ -61,6 +62,10 @@ void TtRssNetworkFactory::setPassword(const QString &password) {
|
||||
m_password = password;
|
||||
}
|
||||
|
||||
QDateTime TtRssNetworkFactory::lastLoginTime() const {
|
||||
return m_lastLoginTime;
|
||||
}
|
||||
|
||||
// TODO: ukazky
|
||||
|
||||
/* ukazky
|
||||
@ -86,6 +91,7 @@ TtRssLoginResponse TtRssNetworkFactory::login(QNetworkReply::NetworkError &error
|
||||
|
||||
if (network_reply.first == QNetworkReply::NoError) {
|
||||
m_sessionId = login_response.sessionId();
|
||||
m_lastLoginTime = QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
error = network_reply.first;
|
||||
|
@ -88,6 +88,9 @@ class TtRssNetworkFactory {
|
||||
QString password() const;
|
||||
void setPassword(const QString &password);
|
||||
|
||||
// Metadata.
|
||||
QDateTime lastLoginTime() const;
|
||||
|
||||
// Operations.
|
||||
|
||||
// Logs user in.
|
||||
@ -109,6 +112,7 @@ class TtRssNetworkFactory {
|
||||
QString m_username;
|
||||
QString m_password;
|
||||
QString m_sessionId;
|
||||
QDateTime m_lastLoginTime;
|
||||
};
|
||||
|
||||
#endif // TTRSSNETWORKFACTORY_H
|
||||
|
@ -282,6 +282,15 @@ void TtRssServiceRoot::updateTitle() {
|
||||
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() {
|
||||
QNetworkReply::NetworkError 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());
|
||||
|
||||
// Purge old data from SQL and clean all model items.
|
||||
removeOldFeedTree();
|
||||
removeOldFeedTree(true);
|
||||
cleanAllItems();
|
||||
|
||||
// Model is clean, now store new tree into DB and
|
||||
@ -326,7 +335,7 @@ QStringList TtRssServiceRoot::textualFeedIds(const QList<Feed*> &feeds) {
|
||||
return stringy_ids;
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::removeOldFeedTree() {
|
||||
void TtRssServiceRoot::removeOldFeedTree(bool including_messages) {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
query.setForwardOnly(true);
|
||||
@ -338,6 +347,12 @@ void TtRssServiceRoot::removeOldFeedTree() {
|
||||
query.prepare(QSL("DELETE FROM Categories WHERE account_id = :account_id;"));
|
||||
query.bindValue(QSL(":account_id"), accountId());
|
||||
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() {
|
||||
|
@ -71,7 +71,9 @@ class TtRssServiceRoot : public ServiceRoot {
|
||||
void saveAccountDataToDatabase();
|
||||
void updateTitle();
|
||||
|
||||
private slots:
|
||||
void completelyRemoveAllData();
|
||||
|
||||
public slots:
|
||||
void syncIn();
|
||||
|
||||
private:
|
||||
@ -79,7 +81,7 @@ class TtRssServiceRoot : public ServiceRoot {
|
||||
// which are suitable as IN clause for SQL queries.
|
||||
QStringList textualFeedIds(const QList<Feed*> &feeds);
|
||||
|
||||
void removeOldFeedTree();
|
||||
void removeOldFeedTree(bool including_messages);
|
||||
void cleanAllItems();
|
||||
void storeNewFeedTree(RootItem *root);
|
||||
void loadFromDatabase();
|
||||
|
Loading…
x
Reference in New Issue
Block a user