mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-30 17:15:01 +01:00
Refactored DB cleaner.
This commit is contained in:
parent
ef20ea9774
commit
7ea94ef42f
@ -24,6 +24,7 @@
|
||||
#include "services/standard/standardserviceroot.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "miscellaneous/databasefactory.h"
|
||||
#include "miscellaneous/databasecleaner.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "miscellaneous/mutex.h"
|
||||
#include "gui/messagebox.h"
|
||||
@ -44,7 +45,9 @@
|
||||
|
||||
|
||||
FeedsModel::FeedsModel(QObject *parent)
|
||||
: QAbstractItemModel(parent), m_autoUpdateTimer(new QTimer(this)), m_feedDownloaderThread(NULL), m_feedDownloader(NULL) {
|
||||
: QAbstractItemModel(parent), m_autoUpdateTimer(new QTimer(this)),
|
||||
m_feedDownloaderThread(NULL), m_feedDownloader(NULL),
|
||||
m_dbCleanerThread(NULL), m_dbCleaner(NULL) {
|
||||
setObjectName(QSL("FeedsModel"));
|
||||
|
||||
// Create root item.
|
||||
@ -98,12 +101,27 @@ void FeedsModel::quit() {
|
||||
}
|
||||
}
|
||||
|
||||
if (m_dbCleanerThread != NULL && 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 != NULL) {
|
||||
qDebug("Feed downloader exists. Deleting it from memory.");
|
||||
m_feedDownloader->deleteLater();
|
||||
}
|
||||
|
||||
if (m_dbCleaner != NULL) {
|
||||
qDebug("Database cleaner exists. Deleting it from memory.");
|
||||
m_dbCleaner->deleteLater();
|
||||
}
|
||||
|
||||
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::ClearReadOnExit)).toBool()) {
|
||||
markItemCleared(m_rootItem, true);
|
||||
}
|
||||
@ -167,6 +185,24 @@ void FeedsModel::updateAllFeeds() {
|
||||
updateFeeds(m_rootItem->getSubTreeFeeds());
|
||||
}
|
||||
|
||||
|
||||
DatabaseCleaner *FeedsModel::databaseCleaner() {
|
||||
if (m_dbCleaner == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
void FeedsModel::executeNextAutoUpdate() {
|
||||
if (!qApp->feedUpdateLock()->tryLock()) {
|
||||
qDebug("Delaying scheduled feed auto-updates for one minute due to another running update.");
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "core/rootitem.h"
|
||||
#include "core/feeddownloader.h"
|
||||
|
||||
|
||||
class DatabaseCleaner;
|
||||
class Category;
|
||||
class Feed;
|
||||
class ServiceRoot;
|
||||
@ -139,6 +139,8 @@ class FeedsModel : public QAbstractItemModel {
|
||||
// Schedules all feeds from all accounts for update.
|
||||
void updateAllFeeds();
|
||||
|
||||
DatabaseCleaner *databaseCleaner();
|
||||
|
||||
// Adds given service root account.
|
||||
bool addServiceAccount(ServiceRoot *root);
|
||||
|
||||
@ -209,6 +211,9 @@ class FeedsModel : public QAbstractItemModel {
|
||||
|
||||
QThread *m_feedDownloaderThread;
|
||||
FeedDownloader *m_feedDownloader;
|
||||
|
||||
QThread *m_dbCleanerThread;
|
||||
DatabaseCleaner *m_dbCleaner;
|
||||
};
|
||||
|
||||
#endif // FEEDSMODEL_H
|
||||
|
@ -64,9 +64,7 @@ FeedMessageViewer::FeedMessageViewer(QWidget *parent)
|
||||
m_toolBarMessages(new MessagesToolBar(tr("Toolbar for messages"), this)),
|
||||
m_messagesView(new MessagesView(this)),
|
||||
m_feedsView(new FeedsView(this)),
|
||||
m_messagesBrowser(new WebBrowser(this)),
|
||||
m_dbCleanerThread(NULL),
|
||||
m_dbCleaner(NULL) {
|
||||
m_messagesBrowser(new WebBrowser(this)) {
|
||||
initialize();
|
||||
initializeViews();
|
||||
loadMessageViewerFonts();
|
||||
@ -77,23 +75,6 @@ FeedMessageViewer::~FeedMessageViewer() {
|
||||
qDebug("Destroying FeedMessageViewer instance.");
|
||||
}
|
||||
|
||||
DatabaseCleaner *FeedMessageViewer::databaseCleaner() {
|
||||
if (m_dbCleaner == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
void FeedMessageViewer::saveSize() {
|
||||
Settings *settings = qApp->settings();
|
||||
|
||||
@ -148,21 +129,7 @@ void FeedMessageViewer::loadMessageViewerFonts() {
|
||||
void FeedMessageViewer::quit() {
|
||||
// Quit the feeds model (stops auto-update timer etc.).
|
||||
m_feedsView->sourceModel()->quit();
|
||||
|
||||
if (m_dbCleanerThread != NULL && 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();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_dbCleaner != NULL) {
|
||||
qDebug("Database cleaner exists. Deleting it from memory.");
|
||||
m_dbCleaner->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool FeedMessageViewer::areToolBarsEnabled() const {
|
||||
@ -428,7 +395,7 @@ void FeedMessageViewer::initializeViews() {
|
||||
void FeedMessageViewer::showDbCleanupAssistant() {
|
||||
if (qApp->feedUpdateLock()->tryLock()) {
|
||||
QPointer<FormDatabaseCleanup> form_pointer = new FormDatabaseCleanup(this);
|
||||
form_pointer.data()->setCleaner(databaseCleaner());
|
||||
form_pointer.data()->setCleaner(m_feedsView->sourceModel()->databaseCleaner());
|
||||
form_pointer.data()->exec();
|
||||
|
||||
delete form_pointer.data();
|
||||
|
@ -29,7 +29,6 @@ class MessagesView;
|
||||
class MessagesToolBar;
|
||||
class FeedsToolBar;
|
||||
class FeedsView;
|
||||
class DatabaseCleaner;
|
||||
class StandardFeed;
|
||||
class QToolBar;
|
||||
class QSplitter;
|
||||
@ -65,8 +64,6 @@ class FeedMessageViewer : public TabContent {
|
||||
return m_toolBarFeeds;
|
||||
}
|
||||
|
||||
DatabaseCleaner *databaseCleaner();
|
||||
|
||||
// Loads/saves sizes and states of ALL
|
||||
// underlying widgets, this contains primarily
|
||||
// splitters, toolbar and views.
|
||||
@ -134,9 +131,6 @@ class FeedMessageViewer : public TabContent {
|
||||
QWidget *m_feedsWidget;
|
||||
QWidget *m_messagesWidget;
|
||||
WebBrowser *m_messagesBrowser;
|
||||
|
||||
QThread *m_dbCleanerThread;
|
||||
DatabaseCleaner *m_dbCleaner;
|
||||
};
|
||||
|
||||
#endif // FEEDMESSAGEVIEWER_H
|
||||
|
@ -349,9 +349,6 @@ void MessagesView::setSelectedMessagesReadStatus(RootItem::ReadStatus read) {
|
||||
m_batchUnreadSwitch = false;
|
||||
}
|
||||
|
||||
|
||||
// TODO: restore messages je uplně stejně jako tahle fce
|
||||
// akorat se vola jina metoda na source modelu.
|
||||
void MessagesView::deleteSelectedMessages() {
|
||||
QModelIndex current_index = selectionModel()->currentIndex();
|
||||
|
||||
@ -409,7 +406,7 @@ void MessagesView::reselectIndexes(const QModelIndexList &indexes) {
|
||||
QItemSelection selection;
|
||||
|
||||
foreach (const QModelIndex &index, indexes) {
|
||||
// TODO: THIS IS very slow. Try to select 4000 messages and hit "mark as read" button.
|
||||
// FIXME: THIS IS very slow. Try to select 4000 messages and hit "mark as read" button.
|
||||
selection.merge(QItemSelection(index, index), QItemSelectionModel::Select);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user