From 0102721ec241ad9f3400fcad4b62b4d86166c8e3 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sun, 2 Feb 2014 12:34:32 +0100 Subject: [PATCH] Some refactoring and little cleanups. --- src/core/basenetworkaccessmanager.cpp | 4 +-- src/gui/feedmessageviewer.cpp | 46 +++------------------------ src/gui/feedmessageviewer.h | 12 ++----- src/gui/feedsview.cpp | 38 ++++++++++++++++++++++ src/gui/feedsview.h | 7 ++++ src/gui/formmain.cpp | 2 -- 6 files changed, 53 insertions(+), 56 deletions(-) diff --git a/src/core/basenetworkaccessmanager.cpp b/src/core/basenetworkaccessmanager.cpp index 3fbbed4e1..18a396083 100644 --- a/src/core/basenetworkaccessmanager.cpp +++ b/src/core/basenetworkaccessmanager.cpp @@ -16,8 +16,6 @@ BaseNetworkAccessManager::~BaseNetworkAccessManager() { } void BaseNetworkAccessManager::loadSettings() { - qDebug("Settings of BaseNetworkAccessManager changed."); - QNetworkProxy new_proxy; QNetworkProxy::ProxyType selected_proxy_type = static_cast(Settings::instance()->value(APP_CFG_PROXY, "proxy_type", @@ -42,6 +40,8 @@ void BaseNetworkAccessManager::loadSettings() { new_proxy.setPassword(settings->value(APP_CFG_PROXY, "password").toString()); setProxy(new_proxy); + + qDebug("Settings of BaseNetworkAccessManager loaded."); } QNetworkReply *BaseNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 186054358..cf9ea99b0 100644 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -93,48 +93,10 @@ void FeedMessageViewer::quitDownloader() { qDebug("Quitting feed downloader thread."); m_feedDownloaderThread->quit(); - qDebug("Feed downloader thread aborted."); + qDebug("Feed downloader thread aborted. Deleting it from memory."); m_feedDownloader->deleteLater(); } -void FeedMessageViewer::updateSelectedFeeds() { - if (SystemFactory::instance()->applicationCloseLock()->tryLock()) { - emit feedsUpdateRequested(m_feedsView->selectedFeeds()); - } - else { - if (SystemTrayIcon::isSystemTrayActivated()) { - SystemTrayIcon::instance()->showMessage(tr("Cannot update selected items"), - tr("You cannot update selected items because another feed update is ongoing."), - QSystemTrayIcon::Warning); - } - else { - MessageBox::show(this, - QMessageBox::Warning, - tr("Cannot update selected items"), - tr("You cannot update selected items because another feed update is ongoing.")); - } - } -} - -void FeedMessageViewer::updateAllFeeds() { - if (SystemFactory::instance()->applicationCloseLock()->tryLock()) { - emit feedsUpdateRequested(m_feedsView->allFeeds()); - } - else { - if (SystemTrayIcon::isSystemTrayActivated()) { - SystemTrayIcon::instance()->showMessage(tr("Cannot update all items"), - tr("You cannot update all items because another feed update is ongoing."), - QSystemTrayIcon::Warning); - } - else { - MessageBox::show(this, - QMessageBox::Warning, - tr("Cannot update all items"), - tr("You cannot update all items because another feed update is ongoing.")); - } - } -} - void FeedMessageViewer::updateCountsOfMessages(int unread_messages, int total_messages) { Q_UNUSED(total_messages) @@ -196,7 +158,7 @@ void FeedMessageViewer::createConnections() { // Downloader connections. connect(m_feedDownloaderThread, SIGNAL(finished()), m_feedDownloaderThread, SLOT(deleteLater())); - connect(this, SIGNAL(feedsUpdateRequested(QList)), + connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList)), m_feedDownloader, SLOT(updateFeeds(QList))); connect(m_feedDownloader, SIGNAL(finished()), this, SLOT(onFeedUpdatesFinished())); @@ -229,9 +191,9 @@ void FeedMessageViewer::createConnections() { connect(FormMain::instance()->m_ui->m_actionClearFeeds, SIGNAL(triggered()), m_feedsView, SLOT(clearSelectedFeeds())); connect(FormMain::instance()->m_ui->m_actionUpdateSelectedFeedsCategories, - SIGNAL(triggered()), this, SLOT(updateSelectedFeeds())); + SIGNAL(triggered()), m_feedsView, SLOT(updateSelectedFeeds())); connect(FormMain::instance()->m_ui->m_actionUpdateAllFeeds, - SIGNAL(triggered()), this, SLOT(updateAllFeeds())); + SIGNAL(triggered()), m_feedsView, SLOT(updateAllFeeds())); connect(FormMain::instance()->m_ui->m_actionAddStandardCategory, SIGNAL(triggered()), m_feedsView, SLOT(addNewStandardCategory())); connect(FormMain::instance()->m_ui->m_actionAddStandardFeed, diff --git a/src/gui/feedmessageviewer.h b/src/gui/feedmessageviewer.h index b1b410fe7..45b4d510e 100644 --- a/src/gui/feedmessageviewer.h +++ b/src/gui/feedmessageviewer.h @@ -7,13 +7,13 @@ class WebBrowser; -class FeedsView; class MessagesView; +class FeedsView; class FeedDownloader; +class FeedsModelFeed; class QToolBar; class QSplitter; class QProgressBar; -class FeedsModelFeed; class FeedMessageViewer : public TabContent { Q_OBJECT @@ -42,11 +42,6 @@ class FeedMessageViewer : public TabContent { // Destroys worker/feed downloader thread. void quitDownloader(); - public slots: - // Feed updating. - void updateSelectedFeeds(); - void updateAllFeeds(); - protected slots: // Updates counts of messages for example in tray icon. void updateCountsOfMessages(int unread_messages, int total_messages); @@ -66,9 +61,6 @@ class FeedMessageViewer : public TabContent { // Sets up connections. void createConnections(); - signals: - void feedsUpdateRequested(QList); - private: QToolBar *m_toolBar; diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index b8318bb20..52fcc2273 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -64,6 +64,44 @@ FeedsModelFeed *FeedsView::isCurrentIndexFeed() const { return m_sourceModel->feedForIndex(current_mapped); } +void FeedsView::updateAllFeeds() { + if (SystemFactory::instance()->applicationCloseLock()->tryLock()) { + emit feedsUpdateRequested(allFeeds()); + } + else { + if (SystemTrayIcon::isSystemTrayActivated()) { + SystemTrayIcon::instance()->showMessage(tr("Cannot update all items"), + tr("You cannot update all items because another feed update is ongoing."), + QSystemTrayIcon::Warning); + } + else { + MessageBox::show(this, + QMessageBox::Warning, + tr("Cannot update all items"), + tr("You cannot update all items because another feed update is ongoing.")); + } + } +} + +void FeedsView::updateSelectedFeeds() { + if (SystemFactory::instance()->applicationCloseLock()->tryLock()) { + emit feedsUpdateRequested(selectedFeeds()); + } + else { + if (SystemTrayIcon::isSystemTrayActivated()) { + SystemTrayIcon::instance()->showMessage(tr("Cannot update selected items"), + tr("You cannot update selected items because another feed update is ongoing."), + QSystemTrayIcon::Warning); + } + else { + MessageBox::show(this, + QMessageBox::Warning, + tr("Cannot update selected items"), + tr("You cannot update selected items because another feed update is ongoing.")); + } + } +} + void FeedsView::setSelectedFeedsClearStatus(int clear) { m_sourceModel->markFeedsDeleted(selectedFeeds(), clear); updateCountsOfSelectedFeeds(); diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 99219d3d0..de28a59e8 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -41,6 +41,10 @@ class FeedsView : public QTreeView { FeedsModelFeed *isCurrentIndexFeed() const; public slots: + // Feed updating. + void updateAllFeeds(); + void updateSelectedFeeds(); + // Feed read/unread manipulators. void markSelectedFeedsReadStatus(int read); void markSelectedFeedsRead(); @@ -102,6 +106,9 @@ class FeedsView : public QTreeView { void contextMenuEvent(QContextMenuEvent *event); signals: + // Emitted if user/application requested updating of some feeds. + void feedsUpdateRequested(const QList feeds); + // Emitted if counts of messages are changed. void feedCountsChanged(int unread_messages, int total_messages); diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index 92a9d3fd3..68b4b3777 100755 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -189,9 +189,7 @@ void FormMain::onAboutToQuit() { qDebug("Cleaning up resources and saving application state."); m_ui->m_tabWidget->feedMessageViewer()->quitDownloader(); - DatabaseFactory::instance()->saveMemoryDatabase(); - saveSize(); }