simplified DB cleanup logic, allow to delete all messages

This commit is contained in:
Martin Rotter 2019-04-09 08:30:34 +02:00
parent 28e42e6403
commit f910e98276
8 changed files with 15 additions and 71 deletions

View File

@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" />
<releases>
<release version="3.5.7" date="2019-04-05"/>
<release version="3.5.7" date="2019-04-09"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -16,30 +16,20 @@ FormDatabaseCleanup::FormDatabaseCleanup(QWidget* parent) : QDialog(parent), m_u
// Set flags and attributes.
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
setWindowIcon(qApp->icons()->fromTheme(QSL("edit-clear")));
connect(m_ui->m_spinDays, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &FormDatabaseCleanup::updateDaysSuffix);
connect(m_ui->m_btnBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &FormDatabaseCleanup::startPurging);
connect(this, &FormDatabaseCleanup::purgeRequested, &m_cleaner, &DatabaseCleaner::purgeDatabaseData);
connect(&m_cleaner, &DatabaseCleaner::purgeStarted, this, &FormDatabaseCleanup::onPurgeStarted);
connect(&m_cleaner, &DatabaseCleaner::purgeProgress, this, &FormDatabaseCleanup::onPurgeProgress);
connect(&m_cleaner, &DatabaseCleaner::purgeFinished, this, &FormDatabaseCleanup::onPurgeFinished);
m_ui->m_spinDays->setValue(DEFAULT_DAYS_TO_DELETE_MSG);
m_ui->m_lblResult->setStatus(WidgetWithStatus::Information, tr("I am ready."), tr("I am ready."));
loadDatabaseInfo();
}
FormDatabaseCleanup::~FormDatabaseCleanup() {
qDebug("Destroying FormDatabaseCleanup instance.");
}
void FormDatabaseCleanup::setCleaner(DatabaseCleaner* cleaner) {
if (m_cleaner != nullptr) {
disconnect(this, 0, m_cleaner, 0);
disconnect(m_cleaner, 0, this, 0);
}
m_cleaner = cleaner;
connect(m_ui->m_btnBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &FormDatabaseCleanup::startPurging);
connect(this, &FormDatabaseCleanup::purgeRequested, m_cleaner, &DatabaseCleaner::purgeDatabaseData);
connect(m_cleaner, &DatabaseCleaner::purgeStarted, this, &FormDatabaseCleanup::onPurgeStarted);
connect(m_cleaner, &DatabaseCleaner::purgeProgress, this, &FormDatabaseCleanup::onPurgeProgress);
connect(m_cleaner, &DatabaseCleaner::purgeFinished, this, &FormDatabaseCleanup::onPurgeFinished);
}
void FormDatabaseCleanup::closeEvent(QCloseEvent* event) {
if (m_ui->m_progressBar->isEnabled()) {
event->ignore();

View File

@ -13,12 +13,8 @@ class FormDatabaseCleanup : public QDialog {
Q_OBJECT
public:
// Constructors.
explicit FormDatabaseCleanup(QWidget* parent = 0);
virtual ~FormDatabaseCleanup();
void setCleaner(DatabaseCleaner* cleaner);
explicit FormDatabaseCleanup(QWidget* parent = nullptr);
virtual ~FormDatabaseCleanup() = default;
protected:
void closeEvent(QCloseEvent* event);
@ -39,7 +35,7 @@ class FormDatabaseCleanup : public QDialog {
private:
QScopedPointer<Ui::FormDatabaseCleanup> m_ui;
DatabaseCleaner* m_cleaner;
DatabaseCleaner m_cleaner;
};
#endif // FORMDATABASECLEANUP_H

View File

@ -35,9 +35,6 @@
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="m_spinDays">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000</number>
</property>

View File

@ -99,7 +99,6 @@ void FormMain::showDbCleanupAssistant() {
if (qApp->feedUpdateLock()->tryLock()) {
FormDatabaseCleanup form(this);
form.setCleaner(qApp->feedReader()->databaseCleaner());
form.exec();
// Reload needed stuff.

View File

@ -22,7 +22,7 @@ class DatabaseCleaner : public QObject {
public:
// Constructors.
explicit DatabaseCleaner(QObject* parent = 0);
explicit DatabaseCleaner(QObject* parent = nullptr);
virtual ~DatabaseCleaner();
signals:

View File

@ -8,7 +8,6 @@
#include "core/messagesmodel.h"
#include "core/messagesproxymodel.h"
#include "miscellaneous/application.h"
#include "miscellaneous/databasecleaner.h"
#include "miscellaneous/mutex.h"
#include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/serviceroot.h"
@ -24,8 +23,7 @@
FeedReader::FeedReader(QObject* parent)
: QObject(parent), m_feedServices(QList<ServiceEntryPoint*>()),
m_autoUpdateTimer(new QTimer(this)), m_feedDownloader(nullptr),
m_dbCleanerThread(nullptr), m_dbCleaner(nullptr) {
m_autoUpdateTimer(new QTimer(this)), m_feedDownloader(nullptr) {
m_feedsModel = new FeedsModel(this);
m_feedsProxyModel = new FeedsProxyModel(m_feedsModel, this);
m_messagesModel = new MessagesModel(this);
@ -133,23 +131,6 @@ bool FeedReader::isFeedUpdateRunning() const {
return m_feedDownloader != nullptr && m_feedDownloader->isUpdateRunning();
}
DatabaseCleaner* FeedReader::databaseCleaner() {
if (m_dbCleaner == nullptr) {
m_dbCleaner = new DatabaseCleaner();
m_dbCleanerThread = new QThread();
// Downloader setup.
qRegisterMetaType<CleanerOrders>("CleanerOrders");
m_dbCleaner->moveToThread(m_dbCleanerThread);
connect(m_dbCleanerThread, SIGNAL(finished()), m_dbCleanerThread, SLOT(deleteLater()));
// Connections are made, start the feed downloader thread.
m_dbCleanerThread->start();
}
return m_dbCleaner;
}
FeedDownloader* FeedReader::feedDownloader() const {
return m_feedDownloader;
}
@ -236,27 +217,12 @@ void FeedReader::quit() {
}
}
if (m_dbCleanerThread != nullptr && m_dbCleanerThread->isRunning()) {
qDebug("Quitting database cleaner thread.");
m_dbCleanerThread->quit();
if (!m_dbCleanerThread->wait(CLOSE_LOCK_TIMEOUT)) {
qCritical("Database cleaner thread is running despite it was told to quit. Terminating it.");
m_dbCleanerThread->terminate();
}
}
// Close workers.
if (m_feedDownloader != nullptr) {
qDebug("Feed downloader exists. Deleting it from memory.");
m_feedDownloader->deleteLater();
}
if (m_dbCleaner != nullptr) {
qDebug("Database cleaner exists. Deleting it from memory.");
m_dbCleaner->deleteLater();
}
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::ClearReadOnExit)).toBool()) {
m_feedsModel->markItemCleared(m_feedsModel->rootItem(), true);
}

View File

@ -15,14 +15,13 @@ class MessagesModel;
class MessagesProxyModel;
class FeedsProxyModel;
class ServiceEntryPoint;
class DatabaseCleaner;
class QTimer;
class FeedReader : public QObject {
Q_OBJECT
public:
explicit FeedReader(QObject* parent = 0);
explicit FeedReader(QObject* parent = nullptr);
virtual ~FeedReader();
// List of all installed "feed service plugins", including obligatory
@ -30,7 +29,6 @@ class FeedReader : public QObject {
QList<ServiceEntryPoint*> feedServices();
// Access to DB cleaner.
DatabaseCleaner* databaseCleaner();
FeedDownloader* feedDownloader() const;
FeedsModel* feedsModel() const;
MessagesModel* messagesModel() const;
@ -84,8 +82,6 @@ class FeedReader : public QObject {
int m_globalAutoUpdateInitialInterval;
int m_globalAutoUpdateRemainingInterval;
FeedDownloader* m_feedDownloader;
QThread* m_dbCleanerThread;
DatabaseCleaner* m_dbCleaner;
};
#endif // FEEDREADER_H