Refactored recycle bin.
This commit is contained in:
parent
2fb97342ee
commit
724e433786
5 changed files with 77 additions and 68 deletions
|
@ -19,6 +19,9 @@
|
|||
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "services/abstract/serviceroot.h"
|
||||
|
||||
#include <QSqlQuery>
|
||||
|
||||
|
||||
RecycleBin::RecycleBin(RootItem *parent_item) : RootItem(parent_item) {
|
||||
|
@ -41,3 +44,73 @@ QVariant RecycleBin::data(int column, int role) const {
|
|||
return RootItem::data(column, role);
|
||||
}
|
||||
}
|
||||
|
||||
bool RecycleBin::empty() {
|
||||
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
if (!db_handle.transaction()) {
|
||||
qWarning("Starting transaction for recycle bin emptying.");
|
||||
return false;
|
||||
}
|
||||
|
||||
ServiceRoot *parent_root = getParentServiceRoot();
|
||||
QSqlQuery query_empty_bin(db_handle);
|
||||
|
||||
query_empty_bin.setForwardOnly(true);
|
||||
query_empty_bin.prepare(QSL("UPDATE Messages SET is_pdeleted = 1 WHERE is_deleted = 1 AND account_id = :account_id;"));
|
||||
query_empty_bin.bindValue(QSL(":account_id"), parent_root->accountId());
|
||||
|
||||
if (!query_empty_bin.exec()) {
|
||||
qWarning("Query execution failed for recycle bin emptying.");
|
||||
|
||||
db_handle.rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Commit changes.
|
||||
if (db_handle.commit()) {
|
||||
updateCounts(true);
|
||||
parent_root->itemChanged(QList<RootItem*>() << this);
|
||||
parent_root->requestReloadMessageList(true);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return db_handle.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
bool RecycleBin::restore() {
|
||||
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
if (!db_handle.transaction()) {
|
||||
qWarning("Starting transaction for recycle bin restoring.");
|
||||
return false;
|
||||
}
|
||||
|
||||
ServiceRoot *parent_root = getParentServiceRoot();
|
||||
QSqlQuery query_empty_bin(db_handle);
|
||||
|
||||
query_empty_bin.setForwardOnly(true);
|
||||
query_empty_bin.prepare("UPDATE Messages SET is_deleted = 0 "
|
||||
"WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;");
|
||||
query_empty_bin.bindValue(QSL(":account_id"), parent_root->accountId());
|
||||
|
||||
if (!query_empty_bin.exec()) {
|
||||
qWarning("Query execution failed for recycle bin restoring.");
|
||||
|
||||
db_handle.rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Commit changes.
|
||||
if (db_handle.commit()) {
|
||||
parent_root->updateCounts(true);
|
||||
parent_root->itemChanged(parent_root->getSubTree());
|
||||
parent_root->requestReloadMessageList(true);
|
||||
parent_root->requestFeedReadFilterReload();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return db_handle.rollback();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@ class RecycleBin : public RootItem {
|
|||
// Empties the bin - removes all messages from it (does not remove
|
||||
// them from DB, just permanently hide them, so that they are not
|
||||
// re-downloaded).
|
||||
virtual bool empty() = 0;
|
||||
virtual bool empty();
|
||||
|
||||
// Performs complete restoration of all messages contained in the bin
|
||||
virtual bool restore() = 0;
|
||||
virtual bool restore();
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Members to override. */
|
||||
|
|
|
@ -50,11 +50,11 @@ bool StandardRecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
|
|||
}
|
||||
|
||||
bool StandardRecycleBin::empty() {
|
||||
return serviceRoot()->emptyBin();
|
||||
return RecycleBin::empty();
|
||||
}
|
||||
|
||||
bool StandardRecycleBin::restore() {
|
||||
return serviceRoot()->restoreBin();
|
||||
return RecycleBin::restore();
|
||||
}
|
||||
|
||||
void StandardRecycleBin::updateCounts(bool update_total_count) {
|
||||
|
|
|
@ -268,67 +268,6 @@ bool StandardServiceRoot::cleanFeeds(QList<Feed*> items, bool clean_read_only) {
|
|||
}
|
||||
}
|
||||
|
||||
bool StandardServiceRoot::restoreBin() {
|
||||
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
if (!db_handle.transaction()) {
|
||||
qWarning("Starting transaction for recycle bin restoring.");
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlQuery query_empty_bin(db_handle);
|
||||
query_empty_bin.setForwardOnly(true);
|
||||
|
||||
if (!query_empty_bin.exec(QString("UPDATE Messages SET is_deleted = 0 WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = %1;").arg(accountId()))) {
|
||||
qWarning("Query execution failed for recycle bin restoring.");
|
||||
|
||||
db_handle.rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Commit changes.
|
||||
if (db_handle.commit()) {
|
||||
updateCounts(true);
|
||||
itemChanged(getSubTree());
|
||||
requestReloadMessageList(true);
|
||||
requestFeedReadFilterReload();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return db_handle.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
bool StandardServiceRoot::emptyBin() {
|
||||
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
if (!db_handle.transaction()) {
|
||||
qWarning("Starting transaction for recycle bin emptying.");
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlQuery query_empty_bin(db_handle);
|
||||
query_empty_bin.setForwardOnly(true);
|
||||
|
||||
if (!query_empty_bin.exec(QString("UPDATE Messages SET is_pdeleted = 1 WHERE is_deleted = 1 AND account_id = %1;").arg(accountId()))) {
|
||||
qWarning("Query execution failed for recycle bin emptying.");
|
||||
|
||||
db_handle.rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Commit changes.
|
||||
if (db_handle.commit()) {
|
||||
m_recycleBin->updateCounts(true);
|
||||
itemChanged(QList<RootItem*>() << m_recycleBin);
|
||||
requestReloadMessageList(true);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return db_handle.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
void StandardServiceRoot::loadFromDatabase(){
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
Assignment categories;
|
||||
|
|
|
@ -95,9 +95,6 @@ class StandardServiceRoot : public ServiceRoot {
|
|||
bool markRecycleBinReadUnread(ReadStatus read);
|
||||
bool cleanFeeds(QList<Feed*> items, bool clean_read_only);
|
||||
|
||||
bool restoreBin();
|
||||
bool emptyBin();
|
||||
|
||||
void loadFromDatabase();
|
||||
|
||||
public slots:
|
||||
|
|
Loading…
Add table
Reference in a new issue