fix #465
This commit is contained in:
parent
b05484b57d
commit
4476dcf811
7 changed files with 37 additions and 21 deletions
|
@ -1524,7 +1524,10 @@ bool DatabaseQueries::deleteAccount(const QSqlDatabase& db, int account_id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseQueries::deleteAccountData(const QSqlDatabase& db, int account_id, bool delete_messages_too) {
|
bool DatabaseQueries::deleteAccountData(const QSqlDatabase& db,
|
||||||
|
int account_id,
|
||||||
|
bool delete_messages_too,
|
||||||
|
bool delete_labels_too) {
|
||||||
bool result = true;
|
bool result = true;
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
|
|
||||||
|
@ -1545,15 +1548,16 @@ bool DatabaseQueries::deleteAccountData(const QSqlDatabase& db, int account_id,
|
||||||
result &= q.exec();
|
result &= q.exec();
|
||||||
|
|
||||||
if (delete_messages_too) {
|
if (delete_messages_too) {
|
||||||
// If we delete message, make sure to delete message/label assignments too.
|
|
||||||
q.prepare(QSL("DELETE FROM LabelsInMessages WHERE account_id = :account_id;"));
|
q.prepare(QSL("DELETE FROM LabelsInMessages WHERE account_id = :account_id;"));
|
||||||
q.bindValue(QSL(":account_id"), account_id);
|
q.bindValue(QSL(":account_id"), account_id);
|
||||||
result &= q.exec();
|
result &= q.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
q.prepare(QSL("DELETE FROM Labels WHERE account_id = :account_id;"));
|
if (delete_labels_too) {
|
||||||
q.bindValue(QSL(":account_id"), account_id);
|
q.prepare(QSL("DELETE FROM Labels WHERE account_id = :account_id;"));
|
||||||
result &= q.exec();
|
q.bindValue(QSL(":account_id"), account_id);
|
||||||
|
result &= q.exec();
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ class DatabaseQueries {
|
||||||
static QPair<int, int> updateMessages(QSqlDatabase db, const QList<Message>& messages,
|
static QPair<int, int> updateMessages(QSqlDatabase db, const QList<Message>& messages,
|
||||||
Feed* feed, bool force_update, bool* ok = nullptr);
|
Feed* feed, bool force_update, bool* ok = nullptr);
|
||||||
static bool deleteAccount(const QSqlDatabase& db, int account_id);
|
static bool deleteAccount(const QSqlDatabase& db, int account_id);
|
||||||
static bool deleteAccountData(const QSqlDatabase& db, int account_id, bool delete_messages_too);
|
static bool deleteAccountData(const QSqlDatabase& db, int account_id, bool delete_messages_too, bool delete_labels_too);
|
||||||
static bool cleanLabelledMessages(const QSqlDatabase& db, bool clean_read_only, Label* label);
|
static bool cleanLabelledMessages(const QSqlDatabase& db, bool clean_read_only, Label* label);
|
||||||
static bool cleanImportantMessages(const QSqlDatabase& db, bool clean_read_only, int account_id);
|
static bool cleanImportantMessages(const QSqlDatabase& db, bool clean_read_only, int account_id);
|
||||||
static bool cleanUnreadMessages(const QSqlDatabase& db, int account_id);
|
static bool cleanUnreadMessages(const QSqlDatabase& db, int account_id);
|
||||||
|
|
|
@ -167,10 +167,10 @@ bool ServiceRoot::canBeDeleted() const {
|
||||||
|
|
||||||
void ServiceRoot::completelyRemoveAllData() {
|
void ServiceRoot::completelyRemoveAllData() {
|
||||||
// Purge old data from SQL and clean all model items.
|
// Purge old data from SQL and clean all model items.
|
||||||
cleanAllItemsFromModel();
|
cleanAllItemsFromModel(true);
|
||||||
removeOldAccountFromDatabase(true);
|
removeOldAccountFromDatabase(true, true);
|
||||||
updateCounts(true);
|
updateCounts(true);
|
||||||
itemChanged(QList<RootItem*>() << this);
|
itemChanged({ this });
|
||||||
requestReloadMessageList(true);
|
requestReloadMessageList(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,13 +188,16 @@ QIcon ServiceRoot::feedIconForMessage(const QString& feed_custom_id) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceRoot::removeOldAccountFromDatabase(bool including_messages) {
|
void ServiceRoot::removeOldAccountFromDatabase(bool delete_messages_too, bool delete_labels_too) {
|
||||||
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
|
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
|
||||||
|
|
||||||
DatabaseQueries::deleteAccountData(database, accountId(), including_messages);
|
DatabaseQueries::deleteAccountData(database,
|
||||||
|
accountId(),
|
||||||
|
delete_messages_too,
|
||||||
|
delete_labels_too);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceRoot::cleanAllItemsFromModel() {
|
void ServiceRoot::cleanAllItemsFromModel(bool clean_labels_too) {
|
||||||
auto chi = childItems();
|
auto chi = childItems();
|
||||||
|
|
||||||
for (RootItem* top_level_item : qAsConst(chi)) {
|
for (RootItem* top_level_item : qAsConst(chi)) {
|
||||||
|
@ -206,7 +209,7 @@ void ServiceRoot::cleanAllItemsFromModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (labelsNode() != nullptr) {
|
if (labelsNode() != nullptr && clean_labels_too) {
|
||||||
auto lbl_chi = labelsNode()->childItems();
|
auto lbl_chi = labelsNode()->childItems();
|
||||||
|
|
||||||
for (RootItem* lbl : qAsConst(lbl_chi)) {
|
for (RootItem* lbl : qAsConst(lbl_chi)) {
|
||||||
|
@ -425,8 +428,13 @@ void ServiceRoot::syncIn() {
|
||||||
auto feed_custom_data = storeCustomFeedsData();
|
auto feed_custom_data = storeCustomFeedsData();
|
||||||
|
|
||||||
// Remove from feeds model, then from SQL but leave messages intact.
|
// Remove from feeds model, then from SQL but leave messages intact.
|
||||||
cleanAllItemsFromModel();
|
bool uses_remote_labels = (supportedLabelOperations() & LabelOperation::Synchronised) == LabelOperation::Synchronised;
|
||||||
removeOldAccountFromDatabase(false);
|
|
||||||
|
// Remove stuff.
|
||||||
|
cleanAllItemsFromModel(uses_remote_labels);
|
||||||
|
removeOldAccountFromDatabase(false, uses_remote_labels);
|
||||||
|
|
||||||
|
// Restore some local settings to feeds etc.
|
||||||
restoreCustomFeedsData(feed_custom_data, new_tree->getHashedSubTreeFeeds());
|
restoreCustomFeedsData(feed_custom_data, new_tree->getHashedSubTreeFeeds());
|
||||||
|
|
||||||
// Model is clean, now store new tree into DB and
|
// Model is clean, now store new tree into DB and
|
||||||
|
|
|
@ -33,7 +33,11 @@ class ServiceRoot : public RootItem {
|
||||||
enum class LabelOperation {
|
enum class LabelOperation {
|
||||||
Adding = 1,
|
Adding = 1,
|
||||||
Editing = 2,
|
Editing = 2,
|
||||||
Deleting = 4
|
Deleting = 4,
|
||||||
|
|
||||||
|
// NOTE: Service fetches list of labels from remote source
|
||||||
|
// and does not use local offline labels.
|
||||||
|
Synchronised = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class BagOfMessages {
|
enum class BagOfMessages {
|
||||||
|
@ -226,9 +230,9 @@ class ServiceRoot : public RootItem {
|
||||||
|
|
||||||
// Removes all messages/categories/feeds which are
|
// Removes all messages/categories/feeds which are
|
||||||
// associated with this account.
|
// associated with this account.
|
||||||
void removeOldAccountFromDatabase(bool including_messages);
|
void removeOldAccountFromDatabase(bool delete_messages_too, bool delete_labels_too);
|
||||||
void storeNewFeedTree(RootItem* root);
|
void storeNewFeedTree(RootItem* root);
|
||||||
void cleanAllItemsFromModel();
|
void cleanAllItemsFromModel(bool clean_labels_too);
|
||||||
void appendCommonNodes();
|
void appendCommonNodes();
|
||||||
|
|
||||||
// Removes messages which do not belong to any
|
// Removes messages which do not belong to any
|
||||||
|
|
|
@ -233,7 +233,7 @@ void FeedlyServiceRoot::saveAllCachedData(bool ignore_errors) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceRoot::LabelOperation FeedlyServiceRoot::supportedLabelOperations() const {
|
ServiceRoot::LabelOperation FeedlyServiceRoot::supportedLabelOperations() const {
|
||||||
return LabelOperation(0);
|
return ServiceRoot::LabelOperation::Synchronised;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedlyServiceRoot::updateTitle() {
|
void FeedlyServiceRoot::updateTitle() {
|
||||||
|
|
|
@ -257,7 +257,7 @@ void GreaderServiceRoot::saveAllCachedData(bool ignore_errors) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceRoot::LabelOperation GreaderServiceRoot::supportedLabelOperations() const {
|
ServiceRoot::LabelOperation GreaderServiceRoot::supportedLabelOperations() const {
|
||||||
return LabelOperation(0);
|
return ServiceRoot::LabelOperation::Synchronised;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GreaderServiceRoot::updateTitleIcon() {
|
void GreaderServiceRoot::updateTitleIcon() {
|
||||||
|
|
|
@ -34,7 +34,7 @@ TtRssServiceRoot::~TtRssServiceRoot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceRoot::LabelOperation TtRssServiceRoot::supportedLabelOperations() const {
|
ServiceRoot::LabelOperation TtRssServiceRoot::supportedLabelOperations() const {
|
||||||
return ServiceRoot::LabelOperation(0);
|
return ServiceRoot::LabelOperation::Synchronised;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TtRssServiceRoot::start(bool freshly_activated) {
|
void TtRssServiceRoot::start(bool freshly_activated) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue