From 8ba6583a8c5f367cc5c44d91ed31578e15b6e327 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sat, 13 Jun 2015 16:17:34 +0200 Subject: [PATCH] Initially fixed #28. --- resources/text/CHANGELOG | 1 + src/gui/feedmessageviewer.cpp | 37 +++++++++++++++++++++++++++++++++-- src/gui/feedmessageviewer.h | 1 + src/gui/feedsview.cpp | 26 ++++++------------------ src/gui/formmain.cpp | 22 ++------------------- src/gui/formmain.ui | 6 +++--- src/gui/formupdate.cpp | 3 +-- 7 files changed, 49 insertions(+), 47 deletions(-) diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index cd9d02bb6..2ed4511a9 100644 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -2,6 +2,7 @@

2.4.1

Added: diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index ab8313c80..52897b2b0 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -263,7 +263,7 @@ void FeedMessageViewer::switchFeedComponentVisibility() { void FeedMessageViewer::updateMessageButtonsAvailability() { bool one_message_selected = m_messagesView->selectionModel()->selectedRows().size() == 1; - bool atleast_one_message_selected = m_messagesView->selectionModel()->selectedRows().size() >= 1; + bool atleast_one_message_selected = !m_messagesView->selectionModel()->selectedRows().isEmpty(); bool recycle_bin_selected = m_messagesView->sourceModel()->loadedSelection().mode() == FeedsSelection::MessagesFromRecycleBin; FormMain *form_main = qApp->mainForm(); @@ -281,6 +281,27 @@ void FeedMessageViewer::updateMessageButtonsAvailability() { // TODO: To samo udělat s feedy, řešit pouze buttony, které se týkají výběru, ale také vzít v potaz, zda zrovna běží update. } +void FeedMessageViewer::updateFeedButtonsAvailability() { + bool critical_action_running = qApp->feedUpdateLock()->isLocked(); + bool feed_selected = !m_feedsView->selectionModel()->selectedRows().isEmpty(); + FormMain *form_main = qApp->mainForm(); + + form_main->m_ui->m_actionAddCategory->setEnabled(!critical_action_running); + form_main->m_ui->m_actionAddFeed->setEnabled(!critical_action_running); + form_main->m_ui->m_actionBackupDatabaseSettings->setEnabled(!critical_action_running); + form_main->m_ui->m_actionCleanupDatabase->setEnabled(!critical_action_running); + form_main->m_ui->m_actionClearSelectedFeeds->setEnabled(feed_selected); + form_main->m_ui->m_actionDeleteSelectedFeedCategory->setEnabled(!critical_action_running && feed_selected); + form_main->m_ui->m_actionEditSelectedFeedCategory->setEnabled(!critical_action_running && feed_selected); + form_main->m_ui->m_actionImportFeeds->setEnabled(!critical_action_running); + form_main->m_ui->m_actionMarkSelectedFeedsAsRead->setEnabled(feed_selected); + form_main->m_ui->m_actionMarkSelectedFeedsAsUnread->setEnabled(feed_selected); + form_main->m_ui->m_actionUpdateAllFeeds->setEnabled(!critical_action_running); + form_main->m_ui->m_actionUpdateSelectedFeeds->setEnabled(!critical_action_running && feed_selected); + form_main->m_ui->m_actionViewSelectedItemsNewspaperMode->setEnabled(feed_selected); + form_main->m_ui->m_menuAddItem->setEnabled(!critical_action_running); +} + void FeedMessageViewer::createConnections() { FormMain *form_main = qApp->mainForm(); @@ -294,6 +315,10 @@ void FeedMessageViewer::createConnections() { connect(m_messagesView, SIGNAL(currentMessagesRemoved()), this, SLOT(updateMessageButtonsAvailability())); connect(m_messagesView, SIGNAL(currentMessagesChanged(QList)), this, SLOT(updateMessageButtonsAvailability())); + connect(m_feedsView, SIGNAL(feedsSelected(FeedsSelection)), this, SLOT(updateFeedButtonsAvailability())); + connect(qApp->feedUpdateLock(), SIGNAL(locked()), this, SLOT(updateFeedButtonsAvailability())); + connect(qApp->feedUpdateLock(), SIGNAL(unlocked()), this, SLOT(updateFeedButtonsAvailability())); + // If user selects feeds, load their messages. connect(m_feedsView, SIGNAL(feedsSelected(FeedsSelection)), m_messagesView, SLOT(loadFeeds(FeedsSelection))); @@ -351,7 +376,7 @@ void FeedMessageViewer::createConnections() { SIGNAL(triggered()), m_feedsView, SLOT(clearSelectedFeeds())); connect(form_main->m_ui->m_actionClearAllFeeds, SIGNAL(triggered()), m_feedsView, SLOT(clearAllFeeds())); - connect(form_main->m_ui->m_actionUpdateSelectedFeedsCategories, + connect(form_main->m_ui->m_actionUpdateSelectedFeeds, SIGNAL(triggered()), m_feedsView, SLOT(updateSelectedFeeds())); connect(form_main->m_ui->m_actionUpdateAllFeeds, SIGNAL(triggered()), m_feedsView, SLOT(updateAllFeeds())); @@ -461,6 +486,7 @@ void FeedMessageViewer::initializeViews() { setTabOrder(m_toolBarMessages, m_messagesBrowser); updateMessageButtonsAvailability(); + updateFeedButtonsAvailability(); } void FeedMessageViewer::showDbCleanupAssistant() { @@ -491,6 +517,13 @@ void FeedMessageViewer::refreshVisualProperties() { } void FeedMessageViewer::updateFeeds(QList feeds) { + if (!qApp->feedUpdateLock()->tryLock()) { + qApp->showGuiMessage(tr("Cannot update all items"), + tr("You cannot update all items because another another critical operation is ongoing."), + QSystemTrayIcon::Warning, qApp->mainForm()); + return; + } + if (m_feedDownloader == NULL) { m_feedDownloader = new FeedDownloader(); m_feedDownloaderThread = new QThread(); diff --git a/src/gui/feedmessageviewer.h b/src/gui/feedmessageviewer.h index 124eb8922..0772a9045 100644 --- a/src/gui/feedmessageviewer.h +++ b/src/gui/feedmessageviewer.h @@ -117,6 +117,7 @@ class FeedMessageViewer : public TabContent { void switchFeedComponentVisibility(); void updateMessageButtonsAvailability(); + void updateFeedButtonsAvailability(); protected: // Initializes some properties of the widget. diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index c16837afa..17218b018 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -167,14 +167,11 @@ void FeedsView::loadExpandedStates() { } void FeedsView::updateAllFeeds() { - if (qApp->feedUpdateLock()->tryLock()) { - emit feedsUpdateRequested(allFeeds()); - } - else { - qApp->showGuiMessage(tr("Cannot update all items"), - tr("You cannot update all items because another another critical operation is ongoing."), - QSystemTrayIcon::Warning, qApp->mainForm()); - } + emit feedsUpdateRequested(allFeeds()); +} + +void FeedsView::updateSelectedFeeds() { + emit feedsUpdateRequested(selectedFeeds()); } void FeedsView::updateAllFeedsOnStartup() { @@ -184,17 +181,6 @@ void FeedsView::updateAllFeedsOnStartup() { } } -void FeedsView::updateSelectedFeeds() { - if (qApp->feedUpdateLock()->tryLock()) { - emit feedsUpdateRequested(selectedFeeds()); - } - else { - qApp->showGuiMessage(tr("Cannot update selected items"), - tr("You cannot update selected items because another critical operation is ongoing."), - QSystemTrayIcon::Warning, qApp->mainForm()); - } -} - void FeedsView::executeNextAutoUpdate() { if (!qApp->feedUpdateLock()->tryLock()) { qDebug("Delaying scheduled feed auto-updates for one minute due to another running update."); @@ -561,7 +547,7 @@ void FeedsView::selectPreviousItem() { void FeedsView::initializeContextMenuCategoriesFeeds() { m_contextMenuCategoriesFeeds = new QMenu(tr("Context menu for feeds"), this); m_contextMenuCategoriesFeeds->addActions(QList() << - qApp->mainForm()->m_ui->m_actionUpdateSelectedFeedsCategories << + qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds << qApp->mainForm()->m_ui->m_actionEditSelectedFeedCategory << qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode << qApp->mainForm()->m_ui->m_actionMarkSelectedFeedsAsRead << diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index be8f39af3..8bfff1d6c 100755 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -122,7 +122,7 @@ QList FormMain::allActions() { actions << m_ui->m_actionSwitchImportanceOfSelectedMessages; actions << m_ui->m_actionDeleteSelectedMessages; actions << m_ui->m_actionUpdateAllFeeds; - actions << m_ui->m_actionUpdateSelectedFeedsCategories; + actions << m_ui->m_actionUpdateSelectedFeeds; actions << m_ui->m_actionEditSelectedFeedCategory; actions << m_ui->m_actionDeleteSelectedFeedCategory; actions << m_ui->m_actionViewSelectedItemsNewspaperMode; @@ -251,7 +251,7 @@ void FormMain::setupIcons() { // Feeds/messages. m_ui->m_menuAddItem->setIcon(icon_theme_factory->fromTheme("item-new")); m_ui->m_actionUpdateAllFeeds->setIcon(icon_theme_factory->fromTheme("item-update-all")); - m_ui->m_actionUpdateSelectedFeedsCategories->setIcon(icon_theme_factory->fromTheme("item-update-selected")); + m_ui->m_actionUpdateSelectedFeeds->setIcon(icon_theme_factory->fromTheme("item-update-selected")); m_ui->m_actionClearSelectedFeeds->setIcon(icon_theme_factory->fromTheme("mail-remove")); m_ui->m_actionClearAllFeeds->setIcon(icon_theme_factory->fromTheme("mail-remove")); m_ui->m_actionDeleteSelectedFeedCategory->setIcon(icon_theme_factory->fromTheme("item-remove")); @@ -450,27 +450,9 @@ void FormMain::showAbout() { } void FormMain::showUpdates() { - if (!qApp->feedUpdateLock()->tryLock()) { - if (SystemTrayIcon::isSystemTrayActivated()) { - qApp->trayIcon()->showMessage(tr("Cannot check for updates"), - tr("You cannot check for updates because feed update is ongoing."), - QSystemTrayIcon::Warning); - } - else { - MessageBox::show(this, - QMessageBox::Warning, - tr("Cannot check for updates"), - tr("You cannot check for updates because feed update is ongoing.")); - } - - return; - } - QPointer form_update = new FormUpdate(this); form_update.data()->exec(); delete form_update.data(); - - qApp->feedUpdateLock()->unlock(); } void FormMain::showWiki() { diff --git a/src/gui/formmain.ui b/src/gui/formmain.ui index ad0641e8c..4e3e6ff49 100755 --- a/src/gui/formmain.ui +++ b/src/gui/formmain.ui @@ -138,7 +138,7 @@ - + @@ -274,12 +274,12 @@ Ctrl+Shift+U - + Update &selected feeds - Ctrl+U + Ctrl+U diff --git a/src/gui/formupdate.cpp b/src/gui/formupdate.cpp index 9cd768518..236eb5785 100755 --- a/src/gui/formupdate.cpp +++ b/src/gui/formupdate.cpp @@ -193,8 +193,7 @@ void FormUpdate::startUpdate() { // via self-update feature. close(); - qDebug("Preparing to launch external installer '%s'.", - qPrintable(QDir::toNativeSeparators(m_updateFilePath))); + qDebug("Preparing to launch external installer '%s'.", qPrintable(QDir::toNativeSeparators(m_updateFilePath))); #if defined(Q_OS_WIN) long exec_result = (long) ShellExecute(NULL,