Refactoring.
This commit is contained in:
parent
b62dcd2926
commit
7a42e2d7a1
|
@ -61,7 +61,7 @@ void FeedDownloader::updateFeeds(const QList<Feed*> &feeds) {
|
||||||
m_feedsTotalCount = m_feedsToUpdate;
|
m_feedsTotalCount = m_feedsToUpdate;
|
||||||
|
|
||||||
// Job starts now.
|
// Job starts now.
|
||||||
emit started();
|
emit updateStarted();
|
||||||
|
|
||||||
for (int i = 0; i < m_feedsTotalCount; i++) {
|
for (int i = 0; i < m_feedsTotalCount; i++) {
|
||||||
if (m_stopUpdate) {
|
if (m_stopUpdate) {
|
||||||
|
@ -101,9 +101,8 @@ void FeedDownloader::oneFeedUpdateFinished(const QList<Message> &messages) {
|
||||||
m_feedsUpdating--;
|
m_feedsUpdating--;
|
||||||
|
|
||||||
// Now make sure, that messages are actually stored to SQL in a locked state.
|
// Now make sure, that messages are actually stored to SQL in a locked state.
|
||||||
|
|
||||||
qDebug().nospace() << "Saving messages of feed "
|
qDebug().nospace() << "Saving messages of feed "
|
||||||
<< feed->customId() << " in thread: \'"
|
<< feed->id() << " in thread: \'"
|
||||||
<< QThread::currentThreadId() << "\'.";
|
<< QThread::currentThreadId() << "\'.";
|
||||||
|
|
||||||
int updated_messages = messages.isEmpty() ? 0 : feed->updateMessages(messages);
|
int updated_messages = messages.isEmpty() ? 0 : feed->updateMessages(messages);
|
||||||
|
@ -113,7 +112,7 @@ void FeedDownloader::oneFeedUpdateFinished(const QList<Message> &messages) {
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug("Made progress in feed updates, total feeds count %d/%d (id of feed is %d).", m_feedsUpdated, m_feedsTotalCount, feed->id());
|
qDebug("Made progress in feed updates, total feeds count %d/%d (id of feed is %d).", m_feedsUpdated, m_feedsTotalCount, feed->id());
|
||||||
emit progress(feed, m_feedsUpdated, m_feedsTotalCount);
|
emit updateProgress(feed, m_feedsUpdated, m_feedsTotalCount);
|
||||||
|
|
||||||
if (m_feedsToUpdate <= 0 && m_feedsUpdating <= 0) {
|
if (m_feedsToUpdate <= 0 && m_feedsUpdating <= 0) {
|
||||||
finalizeUpdate();
|
finalizeUpdate();
|
||||||
|
@ -132,7 +131,7 @@ void FeedDownloader::finalizeUpdate() {
|
||||||
// NOTE: This means that now "update lock" can be unlocked
|
// NOTE: This means that now "update lock" can be unlocked
|
||||||
// and feeds can be added/edited/deleted and application
|
// and feeds can be added/edited/deleted and application
|
||||||
// can eventually quit.
|
// can eventually quit.
|
||||||
emit finished(m_results);
|
emit updateFinished(m_results);
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedDownloadResults::FeedDownloadResults() : m_updatedFeeds(QList<QPair<QString,int> >()) {
|
FeedDownloadResults::FeedDownloadResults() : m_updatedFeeds(QList<QPair<QString,int> >()) {
|
||||||
|
|
|
@ -76,17 +76,17 @@ class FeedDownloader : public QObject {
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// Emitted if feed updates started.
|
// Emitted if feed updates started.
|
||||||
void started();
|
void updateStarted();
|
||||||
|
|
||||||
// Emitted if all items from update queue are
|
// Emitted if all items from update queue are
|
||||||
// processed.
|
// processed.
|
||||||
void finished(FeedDownloadResults updated_feeds);
|
void updateFinished(FeedDownloadResults updated_feeds);
|
||||||
|
|
||||||
// Emitted if any item is processed.
|
// Emitted if any item is processed.
|
||||||
// "Current" number indicates count of processed feeds
|
// "Current" number indicates count of processed feeds
|
||||||
// and "total" number indicates total number of feeds
|
// and "total" number indicates total number of feeds
|
||||||
// which were in the initial queue.
|
// which were in the initial queue.
|
||||||
void progress(const Feed *feed, int current, int total);
|
void updateProgress(const Feed *feed, int current, int total);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void finalizeUpdate();
|
void finalizeUpdate();
|
||||||
|
|
|
@ -76,12 +76,6 @@ FeedsModel::~FeedsModel() {
|
||||||
delete m_rootItem;
|
delete m_rootItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsModel::quit() {
|
|
||||||
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::ClearReadOnExit)).toBool()) {
|
|
||||||
markItemCleared(m_rootItem, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void FeedsModel::onFeedUpdatesStarted() {
|
void FeedsModel::onFeedUpdatesStarted() {
|
||||||
//: Text display in status bar when feed update is started.
|
//: Text display in status bar when feed update is started.
|
||||||
|
|
|
@ -117,9 +117,6 @@ class FeedsModel : public QAbstractItemModel {
|
||||||
// Loads feed/categories from the database.
|
// Loads feed/categories from the database.
|
||||||
void loadActivatedServiceAccounts();
|
void loadActivatedServiceAccounts();
|
||||||
|
|
||||||
// Does necessary job before quitting this component.
|
|
||||||
void quit();
|
|
||||||
|
|
||||||
// Reloads counts of all feeds/categories/whatever in the model.
|
// Reloads counts of all feeds/categories/whatever in the model.
|
||||||
void reloadCountsOfWholeModel();
|
void reloadCountsOfWholeModel();
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,13 @@
|
||||||
#include "gui/systemtrayicon.h"
|
#include "gui/systemtrayicon.h"
|
||||||
#include "gui/tabbar.h"
|
#include "gui/tabbar.h"
|
||||||
#include "gui/statusbar.h"
|
#include "gui/statusbar.h"
|
||||||
|
#include "gui/messagesview.h"
|
||||||
#include "gui/feedmessageviewer.h"
|
#include "gui/feedmessageviewer.h"
|
||||||
#include "gui/plaintoolbutton.h"
|
#include "gui/plaintoolbutton.h"
|
||||||
#include "gui/dialogs/formabout.h"
|
#include "gui/dialogs/formabout.h"
|
||||||
#include "gui/dialogs/formsettings.h"
|
#include "gui/dialogs/formsettings.h"
|
||||||
#include "gui/dialogs/formupdate.h"
|
#include "gui/dialogs/formupdate.h"
|
||||||
|
#include "gui/dialogs/formdatabasecleanup.h"
|
||||||
#include "gui/dialogs/formbackupdatabasesettings.h"
|
#include "gui/dialogs/formbackupdatabasesettings.h"
|
||||||
#include "gui/dialogs/formrestoredatabasesettings.h"
|
#include "gui/dialogs/formrestoredatabasesettings.h"
|
||||||
#include "gui/dialogs/formaddaccount.h"
|
#include "gui/dialogs/formaddaccount.h"
|
||||||
|
@ -89,6 +91,24 @@ FormMain::~FormMain() {
|
||||||
qDebug("Destroying FormMain instance.");
|
qDebug("Destroying FormMain instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FormMain::showDbCleanupAssistant() {
|
||||||
|
if (qApp->feedUpdateLock()->tryLock()) {
|
||||||
|
QScopedPointer<FormDatabaseCleanup> form_pointer(new FormDatabaseCleanup(this));
|
||||||
|
form_pointer.data()->setCleaner(qApp->feedReader()->databaseCleaner());
|
||||||
|
form_pointer.data()->exec();
|
||||||
|
|
||||||
|
qApp->feedUpdateLock()->unlock();
|
||||||
|
|
||||||
|
tabWidget()->feedMessageViewer()->messagesView()->reloadSelections(false);
|
||||||
|
qApp->feedReader()->feedsModel()->reloadCountsOfWholeModel();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qApp->showGuiMessage(tr("Cannot cleanup database"),
|
||||||
|
tr("Cannot cleanup database, because another critical action is running."),
|
||||||
|
QSystemTrayIcon::Warning, qApp->mainFormWidget(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QList<QAction*> FormMain::allActions() const {
|
QList<QAction*> FormMain::allActions() const {
|
||||||
QList<QAction*> actions;
|
QList<QAction*> actions;
|
||||||
|
|
||||||
|
@ -495,6 +515,8 @@ void FormMain::createConnections() {
|
||||||
connect(m_ui->m_actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
|
connect(m_ui->m_actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
|
||||||
connect(m_ui->m_actionDownloadManager, SIGNAL(triggered()), m_ui->m_tabWidget, SLOT(showDownloadManager()));
|
connect(m_ui->m_actionDownloadManager, SIGNAL(triggered()), m_ui->m_tabWidget, SLOT(showDownloadManager()));
|
||||||
|
|
||||||
|
connect(m_ui->m_actionCleanupDatabase, SIGNAL(triggered()), this, SLOT(showDbCleanupAssistant()));
|
||||||
|
|
||||||
// Menu "Help" connections.
|
// Menu "Help" connections.
|
||||||
connect(m_ui->m_actionAboutGuard, SIGNAL(triggered()), this, SLOT(showAbout()));
|
connect(m_ui->m_actionAboutGuard, SIGNAL(triggered()), this, SLOT(showAbout()));
|
||||||
connect(m_ui->m_actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(showUpdates()));
|
connect(m_ui->m_actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(showUpdates()));
|
||||||
|
|
|
@ -86,6 +86,7 @@ class FormMain : public QMainWindow {
|
||||||
void showUpdates();
|
void showUpdates();
|
||||||
void showWiki();
|
void showWiki();
|
||||||
void showAddAccountDialog();
|
void showAddAccountDialog();
|
||||||
|
void showDbCleanupAssistant();
|
||||||
void reportABug();
|
void reportABug();
|
||||||
void donate();
|
void donate();
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,26 @@ FeedMessageViewer::~FeedMessageViewer() {
|
||||||
qDebug("Destroying FeedMessageViewer instance.");
|
qDebug("Destroying FeedMessageViewer instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebBrowser *FeedMessageViewer::webBrowser() const {
|
||||||
|
return m_messagesBrowser;
|
||||||
|
}
|
||||||
|
|
||||||
|
FeedsView *FeedMessageViewer::feedsView() const {
|
||||||
|
return m_feedsView;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesView *FeedMessageViewer::messagesView() const {
|
||||||
|
return m_messagesView;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesToolBar *FeedMessageViewer::messagesToolBar() const {
|
||||||
|
return m_toolBarMessages;
|
||||||
|
}
|
||||||
|
|
||||||
|
FeedsToolBar *FeedMessageViewer::feedsToolBar() const {
|
||||||
|
return m_toolBarFeeds;
|
||||||
|
}
|
||||||
|
|
||||||
void FeedMessageViewer::saveSize() {
|
void FeedMessageViewer::saveSize() {
|
||||||
Settings *settings = qApp->settings();
|
Settings *settings = qApp->settings();
|
||||||
|
|
||||||
|
@ -121,11 +141,6 @@ void FeedMessageViewer::loadMessageViewerFonts() {
|
||||||
m_messagesBrowser->reloadFontSettings();
|
m_messagesBrowser->reloadFontSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedMessageViewer::quit() {
|
|
||||||
// Quit the feeds model (stops auto-update timer etc.).
|
|
||||||
m_feedsView->sourceModel()->quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FeedMessageViewer::areToolBarsEnabled() const {
|
bool FeedMessageViewer::areToolBarsEnabled() const {
|
||||||
return m_toolBarsEnabled;
|
return m_toolBarsEnabled;
|
||||||
}
|
}
|
||||||
|
@ -270,8 +285,6 @@ void FeedMessageViewer::createConnections() {
|
||||||
m_feedsView, SLOT(addFeedIntoSelectedAccount()));
|
m_feedsView, SLOT(addFeedIntoSelectedAccount()));
|
||||||
connect(form_main->m_ui->m_actionAddCategoryIntoSelectedAccount, SIGNAL(triggered()),
|
connect(form_main->m_ui->m_actionAddCategoryIntoSelectedAccount, SIGNAL(triggered()),
|
||||||
m_feedsView, SLOT(addCategoryIntoSelectedAccount()));
|
m_feedsView, SLOT(addCategoryIntoSelectedAccount()));
|
||||||
connect(form_main->m_ui->m_actionCleanupDatabase,
|
|
||||||
SIGNAL(triggered()), this, SLOT(showDbCleanupAssistant()));
|
|
||||||
connect(form_main->m_ui->m_actionSwitchImportanceOfSelectedMessages,
|
connect(form_main->m_ui->m_actionSwitchImportanceOfSelectedMessages,
|
||||||
SIGNAL(triggered()), m_messagesView, SLOT(switchSelectedMessagesImportance()));
|
SIGNAL(triggered()), m_messagesView, SLOT(switchSelectedMessagesImportance()));
|
||||||
connect(form_main->m_ui->m_actionDeleteSelectedMessages,
|
connect(form_main->m_ui->m_actionDeleteSelectedMessages,
|
||||||
|
@ -414,24 +427,6 @@ void FeedMessageViewer::initializeViews() {
|
||||||
updateFeedButtonsAvailability();
|
updateFeedButtonsAvailability();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedMessageViewer::showDbCleanupAssistant() {
|
|
||||||
if (qApp->feedUpdateLock()->tryLock()) {
|
|
||||||
QScopedPointer<FormDatabaseCleanup> form_pointer(new FormDatabaseCleanup(this));
|
|
||||||
form_pointer.data()->setCleaner(qApp->feedReader()->databaseCleaner());
|
|
||||||
form_pointer.data()->exec();
|
|
||||||
|
|
||||||
qApp->feedUpdateLock()->unlock();
|
|
||||||
|
|
||||||
m_messagesView->reloadSelections(false);
|
|
||||||
m_feedsView->sourceModel()->reloadCountsOfWholeModel();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qApp->showGuiMessage(tr("Cannot cleanup database"),
|
|
||||||
tr("Cannot cleanup database, because another critical action is running."),
|
|
||||||
QSystemTrayIcon::Warning, qApp->mainFormWidget(), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FeedMessageViewer::refreshVisualProperties() {
|
void FeedMessageViewer::refreshVisualProperties() {
|
||||||
const Qt::ToolButtonStyle button_style = static_cast<Qt::ToolButtonStyle>(qApp->settings()->value(GROUP(GUI),
|
const Qt::ToolButtonStyle button_style = static_cast<Qt::ToolButtonStyle>(qApp->settings()->value(GROUP(GUI),
|
||||||
SETTING(GUI::ToolbarStyle)).toInt());
|
SETTING(GUI::ToolbarStyle)).toInt());
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "gui/tabcontent.h"
|
#include "gui/tabcontent.h"
|
||||||
|
|
||||||
#include "core/messagesmodel.h"
|
#include "core/messagesmodel.h"
|
||||||
#include "core/feeddownloader.h"
|
|
||||||
|
|
||||||
#include <QTextBrowser>
|
#include <QTextBrowser>
|
||||||
|
|
||||||
|
@ -45,28 +44,16 @@ class FeedMessageViewer : public TabContent {
|
||||||
explicit FeedMessageViewer(QWidget *parent = 0);
|
explicit FeedMessageViewer(QWidget *parent = 0);
|
||||||
virtual ~FeedMessageViewer();
|
virtual ~FeedMessageViewer();
|
||||||
|
|
||||||
// WebBrowser getter from TabContent interface.
|
WebBrowser *webBrowser() const;
|
||||||
inline WebBrowser *webBrowser() const {
|
FeedsView *feedsView() const;
|
||||||
return m_messagesBrowser;
|
MessagesView *messagesView() const;
|
||||||
}
|
MessagesToolBar *messagesToolBar() const;
|
||||||
|
FeedsToolBar *feedsToolBar() const;
|
||||||
|
|
||||||
// FeedsView getter.
|
bool areToolBarsEnabled() const;
|
||||||
inline FeedsView *feedsView() const {
|
bool areListHeadersEnabled() const;
|
||||||
return m_feedsView;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline MessagesView *messagesView() const {
|
|
||||||
return m_messagesView;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline MessagesToolBar *messagesToolBar() const {
|
|
||||||
return m_toolBarMessages;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline FeedsToolBar *feedsToolBar() const {
|
|
||||||
return m_toolBarFeeds;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
// Loads/saves sizes and states of ALL
|
// Loads/saves sizes and states of ALL
|
||||||
// underlying widgets, this contains primarily
|
// underlying widgets, this contains primarily
|
||||||
// splitters, toolbar and views.
|
// splitters, toolbar and views.
|
||||||
|
@ -75,14 +62,6 @@ class FeedMessageViewer : public TabContent {
|
||||||
|
|
||||||
void loadMessageViewerFonts();
|
void loadMessageViewerFonts();
|
||||||
|
|
||||||
// Destroys worker/feed downloader thread and
|
|
||||||
// stops any child widgets/workers.
|
|
||||||
void quit();
|
|
||||||
|
|
||||||
bool areToolBarsEnabled() const;
|
|
||||||
bool areListHeadersEnabled() const;
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
// Switches orientation horizontal/vertical.
|
// Switches orientation horizontal/vertical.
|
||||||
void switchMessageSplitterOrientation();
|
void switchMessageSplitterOrientation();
|
||||||
|
|
||||||
|
@ -90,9 +69,6 @@ class FeedMessageViewer : public TabContent {
|
||||||
void setToolBarsEnabled(bool enable);
|
void setToolBarsEnabled(bool enable);
|
||||||
void setListHeadersEnabled(bool enable);
|
void setListHeadersEnabled(bool enable);
|
||||||
|
|
||||||
// Runs "cleanup" of the database.
|
|
||||||
void showDbCleanupAssistant();
|
|
||||||
|
|
||||||
// Reloads some changeable visual settings.
|
// Reloads some changeable visual settings.
|
||||||
void refreshVisualProperties();
|
void refreshVisualProperties();
|
||||||
|
|
||||||
|
|
|
@ -317,7 +317,8 @@ void Application::onAboutToQuit() {
|
||||||
system()->removeTrolltechJunkRegistryKeys();
|
system()->removeTrolltechJunkRegistryKeys();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mainForm()->tabWidget()->feedMessageViewer()->quit();
|
qApp->feedReader()->stop();
|
||||||
|
|
||||||
database()->saveDatabase();
|
database()->saveDatabase();
|
||||||
mainForm()->saveSize();
|
mainForm()->saveSize();
|
||||||
|
|
||||||
|
|
|
@ -232,6 +232,10 @@ void FeedReader::stop() {
|
||||||
qDebug("Database cleaner exists. Deleting it from memory.");
|
qDebug("Database cleaner exists. Deleting it from memory.");
|
||||||
m_dbCleaner->deleteLater();
|
m_dbCleaner->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::ClearReadOnExit)).toBool()) {
|
||||||
|
m_feedsModel->markItemCleared(m_feedsModel->rootItem(), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagesProxyModel *FeedReader::messagesProxyModel() const {
|
MessagesProxyModel *FeedReader::messagesProxyModel() const {
|
||||||
|
|
Loading…
Reference in New Issue