From efd4ab8014deef05e68f07d33991c4772a4a27ec Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 15 Aug 2016 13:53:38 +0200 Subject: [PATCH] Refactoring, now almost everything probably works. --- src/gui/dialogs/formdatabasecleanup.cpp | 2 +- src/gui/dialogs/formmain.cpp | 152 ++++++++++++++++++++++-- src/gui/dialogs/formmain.h | 3 + src/gui/feedmessageviewer.cpp | 140 +--------------------- src/gui/feedmessageviewer.h | 3 - src/gui/tabwidget.cpp | 8 ++ src/miscellaneous/application.cpp | 6 +- src/miscellaneous/feedreader.cpp | 5 +- src/miscellaneous/feedreader.h | 6 +- 9 files changed, 168 insertions(+), 157 deletions(-) diff --git a/src/gui/dialogs/formdatabasecleanup.cpp b/src/gui/dialogs/formdatabasecleanup.cpp index 6d0422276..6a58c3767 100755 --- a/src/gui/dialogs/formdatabasecleanup.cpp +++ b/src/gui/dialogs/formdatabasecleanup.cpp @@ -31,7 +31,7 @@ FormDatabaseCleanup::FormDatabaseCleanup(QWidget *parent) : QDialog(parent), m_u setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint); setWindowIcon(qApp->icons()->fromTheme(QSL("edit-clear"))); - connect(m_ui->m_spinDays, SIGNAL(valueChanged(int)), this, SLOT(updateDaysSuffix(int))); + connect(m_ui->m_spinDays, static_cast(&QSpinBox::valueChanged), this, &FormDatabaseCleanup::updateDaysSuffix); 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(); diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index a2969f2e8..41c0f5480 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -34,6 +34,8 @@ #include "gui/messagesview.h" #include "gui/feedmessageviewer.h" #include "gui/plaintoolbutton.h" +#include "gui/feedstoolbar.h" +#include "gui/messagestoolbar.h" #include "gui/dialogs/formabout.h" #include "gui/dialogs/formsettings.h" #include "gui/dialogs/formupdate.h" @@ -63,22 +65,27 @@ FormMain::FormMain(QWidget *parent, Qt::WindowFlags f) m_ui->setupUi(this); qApp->setMainForm(this); + // Add these actions to the list of actions of the main window. + // This allows to use actions via shortcuts + // even if main menu is not visible. + addActions(allActions()); + m_statusBar = new StatusBar(this); setStatusBar(m_statusBar); // Prepare main window and tabs. prepareMenus(); + // Prepare tabs. + //m_ui->m_tabWidget->initializeTabs(); + tabWidget()->feedMessageViewer()->feedsToolBar()->loadChangeableActions(); + tabWidget()->feedMessageViewer()->messagesToolBar()->loadChangeableActions(); + // Establish connections. createConnections(); - // Add these actions to the list of actions of the main window. - // This allows to use actions via shortcuts - // even if main menu is not visible. - addActions(allActions()); - - // Prepare tabs. - m_ui->m_tabWidget->initializeTabs(); + updateMessageButtonsAvailability(); + updateFeedButtonsAvailability(); // Setup some appearance of the window. setupIcons(); @@ -323,8 +330,12 @@ void FormMain::updateAccountsMenu() { m_ui->m_menuAccounts->addAction(m_ui->m_actionServiceDelete); } +void FormMain::onFeedUpdatesFinished(FeedDownloadResults results) { + statusBar()->clearProgressFeeds(); +} + void FormMain::onFeedUpdatesStarted() { - m_ui->m_actionStopRunningItemsUpdate->setEnabled(false); + m_ui->m_actionStopRunningItemsUpdate->setEnabled(true); statusBar()->showProgressFeeds(0, tr("Feed update started")); } @@ -334,8 +345,51 @@ void FormMain::onFeedUpdatesProgress(const Feed *feed, int current, int total) { tr("Updated feed '%1'").arg(feed->title())); } -void FormMain::onFeedUpdatesFinished(FeedDownloadResults results) { - statusBar()->clearProgressFeeds(); +void FormMain::updateMessageButtonsAvailability() { + const bool one_message_selected = tabWidget()->feedMessageViewer()->messagesView()->selectionModel()->selectedRows().size() == 1; + const bool atleast_one_message_selected = !tabWidget()->feedMessageViewer()->messagesView()->selectionModel()->selectedRows().isEmpty(); + const bool bin_loaded = tabWidget()->feedMessageViewer()->messagesView()->sourceModel()->loadedItem() != nullptr && tabWidget()->feedMessageViewer()->messagesView()->sourceModel()->loadedItem()->kind() == RootItemKind::Bin; + + m_ui->m_actionDeleteSelectedMessages->setEnabled(atleast_one_message_selected); + m_ui->m_actionRestoreSelectedMessages->setEnabled(atleast_one_message_selected && bin_loaded); + m_ui->m_actionMarkSelectedMessagesAsRead->setEnabled(atleast_one_message_selected); + m_ui->m_actionMarkSelectedMessagesAsUnread->setEnabled(atleast_one_message_selected); + m_ui->m_actionOpenSelectedMessagesInternally->setEnabled(atleast_one_message_selected); + m_ui->m_actionOpenSelectedSourceArticlesExternally->setEnabled(atleast_one_message_selected); + m_ui->m_actionSendMessageViaEmail->setEnabled(one_message_selected); + m_ui->m_actionSwitchImportanceOfSelectedMessages->setEnabled(atleast_one_message_selected); +} + +void FormMain::updateFeedButtonsAvailability() { + const bool is_update_running = qApp->feedReader()->isFeedUpdateRunning(); + const bool critical_action_running = qApp->feedUpdateLock()->isLocked(); + const RootItem *selected_item = tabWidget()->feedMessageViewer()->feedsView()->selectedItem(); + const bool anything_selected = selected_item != nullptr; + const bool feed_selected = anything_selected && selected_item->kind() == RootItemKind::Feed; + const bool category_selected = anything_selected && selected_item->kind() == RootItemKind::Category; + const bool service_selected = anything_selected && selected_item->kind() == RootItemKind::ServiceRoot; + + m_ui->m_actionStopRunningItemsUpdate->setEnabled(is_update_running); + m_ui->m_actionBackupDatabaseSettings->setEnabled(!critical_action_running); + m_ui->m_actionCleanupDatabase->setEnabled(!critical_action_running); + m_ui->m_actionClearSelectedItems->setEnabled(anything_selected); + m_ui->m_actionDeleteSelectedItem->setEnabled(!critical_action_running && anything_selected); + m_ui->m_actionEditSelectedItem->setEnabled(!critical_action_running && anything_selected); + m_ui->m_actionMarkSelectedItemsAsRead->setEnabled(anything_selected); + m_ui->m_actionMarkSelectedItemsAsUnread->setEnabled(anything_selected); + m_ui->m_actionUpdateAllItems->setEnabled(!critical_action_running); + m_ui->m_actionUpdateSelectedItems->setEnabled(!critical_action_running && (feed_selected || category_selected || service_selected)); + m_ui->m_actionViewSelectedItemsNewspaperMode->setEnabled(anything_selected); + m_ui->m_actionExpandCollapseItem->setEnabled(anything_selected); + + m_ui->m_actionServiceDelete->setEnabled(service_selected); + m_ui->m_actionServiceEdit->setEnabled(service_selected); + m_ui->m_actionAddFeedIntoSelectedAccount->setEnabled(anything_selected); + m_ui->m_actionAddCategoryIntoSelectedAccount->setEnabled(anything_selected); + + m_ui->m_menuAddItem->setEnabled(!critical_action_running); + m_ui->m_menuAccounts->setEnabled(!critical_action_running); + m_ui->m_menuRecycleBin->setEnabled(!critical_action_running); } void FormMain::switchVisibility(bool force_hide) { @@ -543,6 +597,84 @@ void FormMain::createConnections() { connect(m_ui->m_actionTabsCloseAllExceptCurrent, &QAction::triggered, m_ui->m_tabWidget, &TabWidget::closeAllTabsExceptCurrent); connect(m_ui->m_actionTabsCloseAll, &QAction::triggered, m_ui->m_tabWidget, &TabWidget::closeAllTabs); connect(m_ui->m_actionTabNewWebBrowser, &QAction::triggered, m_ui->m_tabWidget, &TabWidget::addEmptyBrowser); + + connect(tabWidget()->feedMessageViewer()->feedsView(), &FeedsView::itemSelected, this, &FormMain::updateFeedButtonsAvailability); + connect(qApp->feedUpdateLock(), &Mutex::locked, this, &FormMain::updateFeedButtonsAvailability); + connect(qApp->feedUpdateLock(), &Mutex::unlocked, this, &FormMain::updateFeedButtonsAvailability); + + connect(qApp->feedReader(), &FeedReader::feedUpdatesStarted, this, &FormMain::onFeedUpdatesStarted); + connect(qApp->feedReader(), &FeedReader::feedUpdatesProgress, this, &FormMain::onFeedUpdatesProgress); + connect(qApp->feedReader(), &FeedReader::feedUpdatesFinished, this, &FormMain::onFeedUpdatesFinished); + + // Toolbar forwardings. + connect(m_ui->m_actionAddFeedIntoSelectedAccount, SIGNAL(triggered()), + tabWidget()->feedMessageViewer()->feedsView(), SLOT(addFeedIntoSelectedAccount())); + connect(m_ui->m_actionAddCategoryIntoSelectedAccount, SIGNAL(triggered()), + tabWidget()->feedMessageViewer()->feedsView(), SLOT(addCategoryIntoSelectedAccount())); + connect(m_ui->m_actionSwitchImportanceOfSelectedMessages, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(switchSelectedMessagesImportance())); + connect(m_ui->m_actionDeleteSelectedMessages, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(deleteSelectedMessages())); + connect(m_ui->m_actionMarkSelectedMessagesAsRead, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(markSelectedMessagesRead())); + connect(m_ui->m_actionMarkSelectedMessagesAsUnread, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(markSelectedMessagesUnread())); + connect(m_ui->m_actionOpenSelectedSourceArticlesExternally, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(openSelectedSourceMessagesExternally())); + connect(m_ui->m_actionOpenSelectedMessagesInternally, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(openSelectedMessagesInternally())); + connect(m_ui->m_actionSendMessageViaEmail, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(sendSelectedMessageViaEmail())); + connect(m_ui->m_actionMarkAllItemsRead, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(markAllItemsRead())); + connect(m_ui->m_actionMarkSelectedItemsAsRead, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(markSelectedItemRead())); + connect(m_ui->m_actionExpandCollapseItem, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(expandCollapseCurrentItem())); + connect(m_ui->m_actionMarkSelectedItemsAsUnread, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(markSelectedItemUnread())); + connect(m_ui->m_actionClearSelectedItems, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(clearSelectedFeeds())); + connect(m_ui->m_actionClearAllItems, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(clearAllFeeds())); + connect(m_ui->m_actionUpdateSelectedItems, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(updateSelectedItems())); + connect(m_ui->m_actionUpdateAllItems, + SIGNAL(triggered()), qApp->feedReader(), SLOT(updateAllFeeds())); + connect(m_ui->m_actionStopRunningItemsUpdate, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), SLOT(stopRunningFeedUpdate())); + connect(m_ui->m_actionEditSelectedItem, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(editSelectedItem())); + connect(m_ui->m_actionViewSelectedItemsNewspaperMode, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(openSelectedItemsInNewspaperMode())); + connect(m_ui->m_actionDeleteSelectedItem, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(deleteSelectedItem())); + connect(m_ui->m_actionSwitchFeedsList, + SIGNAL(triggered()), this, SLOT(switchFeedComponentVisibility())); + connect(m_ui->m_actionSelectNextItem, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(selectNextItem())); + connect(m_ui->m_actionSwitchToolBars, + SIGNAL(toggled(bool)), this, SLOT(setToolBarsEnabled(bool))); + connect(m_ui->m_actionSwitchListHeaders, + SIGNAL(toggled(bool)), this, SLOT(setListHeadersEnabled(bool))); + connect(m_ui->m_actionSelectPreviousItem, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->feedsView(), SLOT(selectPreviousItem())); + connect(m_ui->m_actionSelectNextMessage, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(selectNextItem())); + connect(m_ui->m_actionSelectNextUnreadMessage, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(selectNextUnreadItem())); + connect(m_ui->m_actionSelectPreviousMessage, + SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(selectPreviousItem())); + connect(m_ui->m_actionSwitchMessageListOrientation, SIGNAL(triggered()), + this, SLOT(switchMessageSplitterOrientation())); + connect(m_ui->m_actionShowOnlyUnreadItems, SIGNAL(toggled(bool)), + this, SLOT(toggleShowOnlyUnreadFeeds())); + connect(m_ui->m_actionRestoreSelectedMessages, SIGNAL(triggered()), + tabWidget()->feedMessageViewer()->messagesView(), SLOT(restoreSelectedMessages())); + connect(m_ui->m_actionRestoreAllRecycleBins, SIGNAL(triggered()), + tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), SLOT(restoreAllBins())); + connect(m_ui->m_actionEmptyAllRecycleBins, SIGNAL(triggered()), + tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), SLOT(emptyAllBins())); } void FormMain::backupDatabaseSettings() { diff --git a/src/gui/dialogs/formmain.h b/src/gui/dialogs/formmain.h index f04951027..479c6d836 100755 --- a/src/gui/dialogs/formmain.h +++ b/src/gui/dialogs/formmain.h @@ -78,6 +78,9 @@ class FormMain : public QMainWindow { void updateRecycleBinMenu(); void updateAccountsMenu(); + void updateMessageButtonsAvailability(); + void updateFeedButtonsAvailability(); + void onFeedUpdatesStarted(); void onFeedUpdatesProgress(const Feed *feed, int current, int total); void onFeedUpdatesFinished(FeedDownloadResults results); diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 0e7a98637..86edcc302 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -192,60 +192,7 @@ void FeedMessageViewer::toggleShowOnlyUnreadFeeds() { } } -void FeedMessageViewer::updateMessageButtonsAvailability() { - const bool one_message_selected = m_messagesView->selectionModel()->selectedRows().size() == 1; - const bool atleast_one_message_selected = !m_messagesView->selectionModel()->selectedRows().isEmpty(); - const bool bin_loaded = m_messagesView->sourceModel()->loadedItem() != nullptr && m_messagesView->sourceModel()->loadedItem()->kind() == RootItemKind::Bin; - const FormMain *form_main = qApp->mainForm(); - - form_main->m_ui->m_actionDeleteSelectedMessages->setEnabled(atleast_one_message_selected); - form_main->m_ui->m_actionRestoreSelectedMessages->setEnabled(atleast_one_message_selected && bin_loaded); - form_main->m_ui->m_actionMarkSelectedMessagesAsRead->setEnabled(atleast_one_message_selected); - form_main->m_ui->m_actionMarkSelectedMessagesAsUnread->setEnabled(atleast_one_message_selected); - form_main->m_ui->m_actionOpenSelectedMessagesInternally->setEnabled(atleast_one_message_selected); - form_main->m_ui->m_actionOpenSelectedSourceArticlesExternally->setEnabled(atleast_one_message_selected); - form_main->m_ui->m_actionSendMessageViaEmail->setEnabled(one_message_selected); - form_main->m_ui->m_actionSwitchImportanceOfSelectedMessages->setEnabled(atleast_one_message_selected); -} - -void FeedMessageViewer::updateFeedButtonsAvailability() { - const bool is_update_running = qApp->feedReader()->isFeedUpdateRunning(); - const bool critical_action_running = qApp->feedUpdateLock()->isLocked(); - const RootItem *selected_item = feedsView()->selectedItem(); - const bool anything_selected = selected_item != nullptr; - const bool feed_selected = anything_selected && selected_item->kind() == RootItemKind::Feed; - const bool category_selected = anything_selected && selected_item->kind() == RootItemKind::Category; - const bool service_selected = anything_selected && selected_item->kind() == RootItemKind::ServiceRoot; - const FormMain *form_main = qApp->mainForm(); - - // TODO: přesunou do form main. - - form_main->m_ui->m_actionStopRunningItemsUpdate->setEnabled(is_update_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_actionClearSelectedItems->setEnabled(anything_selected); - form_main->m_ui->m_actionDeleteSelectedItem->setEnabled(!critical_action_running && anything_selected); - form_main->m_ui->m_actionEditSelectedItem->setEnabled(!critical_action_running && anything_selected); - form_main->m_ui->m_actionMarkSelectedItemsAsRead->setEnabled(anything_selected); - form_main->m_ui->m_actionMarkSelectedItemsAsUnread->setEnabled(anything_selected); - form_main->m_ui->m_actionUpdateAllItems->setEnabled(!critical_action_running); - form_main->m_ui->m_actionUpdateSelectedItems->setEnabled(!critical_action_running && (feed_selected || category_selected || service_selected)); - form_main->m_ui->m_actionViewSelectedItemsNewspaperMode->setEnabled(anything_selected); - form_main->m_ui->m_actionExpandCollapseItem->setEnabled(anything_selected); - - form_main->m_ui->m_actionServiceDelete->setEnabled(service_selected); - form_main->m_ui->m_actionServiceEdit->setEnabled(service_selected); - form_main->m_ui->m_actionAddFeedIntoSelectedAccount->setEnabled(anything_selected); - form_main->m_ui->m_actionAddCategoryIntoSelectedAccount->setEnabled(anything_selected); - - form_main->m_ui->m_menuAddItem->setEnabled(!critical_action_running); - form_main->m_ui->m_menuAccounts->setEnabled(!critical_action_running); - form_main->m_ui->m_menuRecycleBin->setEnabled(!critical_action_running); -} - void FeedMessageViewer::createConnections() { - const FormMain *form_main = qApp->mainForm(); - // Filtering & searching. connect(m_toolBarMessages, SIGNAL(messageSearchPatternChanged(QString)), m_messagesView, SLOT(searchMessages(QString))); connect(m_toolBarMessages, SIGNAL(messageFilterChanged(MessagesModel::MessageHighlighter)), m_messagesView, SLOT(filterMessages(MessagesModel::MessageHighlighter))); @@ -259,10 +206,6 @@ void FeedMessageViewer::createConnections() { m_messagesView->sourceModel(), SLOT(setMessageReadById(int,RootItem::ReadStatus))); connect(m_messagesBrowser, SIGNAL(markMessageImportant(int,RootItem::Importance)), m_messagesView->sourceModel(), SLOT(setMessageImportantById(int,RootItem::Importance))); - - connect(m_feedsView, SIGNAL(itemSelected(RootItem*)), 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(itemSelected(RootItem*)), m_messagesView, SLOT(loadItem(RootItem*))); @@ -272,83 +215,6 @@ void FeedMessageViewer::createConnections() { connect(m_feedsView->sourceModel(), SIGNAL(reloadMessageListRequested(bool)), m_messagesView, SLOT(reloadSelections(bool))); connect(m_feedsView->sourceModel(), SIGNAL(feedsUpdateFinished()), this, SLOT(onFeedsUpdateFinished())); - connect(m_feedsView->sourceModel(), SIGNAL(feedsUpdateStarted()), this, SLOT(onFeedsUpdateStarted())); - - // Message openers. - connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(RootItem*,QList)), - qApp->mainForm()->tabWidget(), SLOT(addNewspaperView(RootItem*,QList))); - connect(m_feedsView, SIGNAL(openMessagesInNewspaperView(RootItem*,QList)), - qApp->mainForm()->tabWidget(), SLOT(addNewspaperView(RootItem*,QList))); - - // Toolbar forwardings. - connect(form_main->m_ui->m_actionAddFeedIntoSelectedAccount, SIGNAL(triggered()), - m_feedsView, SLOT(addFeedIntoSelectedAccount())); - connect(form_main->m_ui->m_actionAddCategoryIntoSelectedAccount, SIGNAL(triggered()), - m_feedsView, SLOT(addCategoryIntoSelectedAccount())); - connect(form_main->m_ui->m_actionSwitchImportanceOfSelectedMessages, - SIGNAL(triggered()), m_messagesView, SLOT(switchSelectedMessagesImportance())); - connect(form_main->m_ui->m_actionDeleteSelectedMessages, - SIGNAL(triggered()), m_messagesView, SLOT(deleteSelectedMessages())); - connect(form_main->m_ui->m_actionMarkSelectedMessagesAsRead, - SIGNAL(triggered()), m_messagesView, SLOT(markSelectedMessagesRead())); - connect(form_main->m_ui->m_actionMarkSelectedMessagesAsUnread, - SIGNAL(triggered()), m_messagesView, SLOT(markSelectedMessagesUnread())); - connect(form_main->m_ui->m_actionOpenSelectedSourceArticlesExternally, - SIGNAL(triggered()), m_messagesView, SLOT(openSelectedSourceMessagesExternally())); - connect(form_main->m_ui->m_actionOpenSelectedMessagesInternally, - SIGNAL(triggered()), m_messagesView, SLOT(openSelectedMessagesInternally())); - connect(form_main->m_ui->m_actionSendMessageViaEmail, - SIGNAL(triggered()), m_messagesView, SLOT(sendSelectedMessageViaEmail())); - connect(form_main->m_ui->m_actionMarkAllItemsRead, - SIGNAL(triggered()), m_feedsView, SLOT(markAllItemsRead())); - connect(form_main->m_ui->m_actionMarkSelectedItemsAsRead, - SIGNAL(triggered()), m_feedsView, SLOT(markSelectedItemRead())); - connect(form_main->m_ui->m_actionExpandCollapseItem, - SIGNAL(triggered()), m_feedsView, SLOT(expandCollapseCurrentItem())); - connect(form_main->m_ui->m_actionMarkSelectedItemsAsUnread, - SIGNAL(triggered()), m_feedsView, SLOT(markSelectedItemUnread())); - connect(form_main->m_ui->m_actionClearSelectedItems, - SIGNAL(triggered()), m_feedsView, SLOT(clearSelectedFeeds())); - connect(form_main->m_ui->m_actionClearAllItems, - SIGNAL(triggered()), m_feedsView, SLOT(clearAllFeeds())); - connect(form_main->m_ui->m_actionUpdateSelectedItems, - SIGNAL(triggered()), m_feedsView, SLOT(updateSelectedItems())); - connect(form_main->m_ui->m_actionUpdateAllItems, - SIGNAL(triggered()), qApp->feedReader(), SLOT(updateAllFeeds())); - connect(form_main->m_ui->m_actionStopRunningItemsUpdate, - SIGNAL(triggered()), m_feedsView->sourceModel(), SLOT(stopRunningFeedUpdate())); - connect(form_main->m_ui->m_actionEditSelectedItem, - SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem())); - connect(form_main->m_ui->m_actionViewSelectedItemsNewspaperMode, - SIGNAL(triggered()), m_feedsView, SLOT(openSelectedItemsInNewspaperMode())); - connect(form_main->m_ui->m_actionDeleteSelectedItem, - SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItem())); - connect(form_main->m_ui->m_actionSwitchFeedsList, - SIGNAL(triggered()), this, SLOT(switchFeedComponentVisibility())); - connect(form_main->m_ui->m_actionSelectNextItem, - SIGNAL(triggered()), m_feedsView, SLOT(selectNextItem())); - connect(form_main->m_ui->m_actionSwitchToolBars, - SIGNAL(toggled(bool)), this, SLOT(setToolBarsEnabled(bool))); - connect(form_main->m_ui->m_actionSwitchListHeaders, - SIGNAL(toggled(bool)), this, SLOT(setListHeadersEnabled(bool))); - connect(form_main->m_ui->m_actionSelectPreviousItem, - SIGNAL(triggered()), m_feedsView, SLOT(selectPreviousItem())); - connect(form_main->m_ui->m_actionSelectNextMessage, - SIGNAL(triggered()), m_messagesView, SLOT(selectNextItem())); - connect(form_main->m_ui->m_actionSelectNextUnreadMessage, - SIGNAL(triggered()), m_messagesView, SLOT(selectNextUnreadItem())); - connect(form_main->m_ui->m_actionSelectPreviousMessage, - SIGNAL(triggered()), m_messagesView, SLOT(selectPreviousItem())); - connect(form_main->m_ui->m_actionSwitchMessageListOrientation, SIGNAL(triggered()), - this, SLOT(switchMessageSplitterOrientation())); - connect(form_main->m_ui->m_actionShowOnlyUnreadItems, SIGNAL(toggled(bool)), - this, SLOT(toggleShowOnlyUnreadFeeds())); - connect(form_main->m_ui->m_actionRestoreSelectedMessages, SIGNAL(triggered()), - m_messagesView, SLOT(restoreSelectedMessages())); - connect(form_main->m_ui->m_actionRestoreAllRecycleBins, SIGNAL(triggered()), - m_feedsView->sourceModel(), SLOT(restoreAllBins())); - connect(form_main->m_ui->m_actionEmptyAllRecycleBins, SIGNAL(triggered()), - m_feedsView->sourceModel(), SLOT(emptyAllBins())); } void FeedMessageViewer::initialize() { @@ -356,11 +222,12 @@ void FeedMessageViewer::initialize() { m_toolBarFeeds->setFloatable(false); m_toolBarFeeds->setMovable(false); m_toolBarFeeds->setAllowedAreas(Qt::TopToolBarArea); - m_toolBarFeeds->loadChangeableActions(); m_toolBarMessages->setFloatable(false); m_toolBarMessages->setMovable(false); m_toolBarMessages->setAllowedAreas(Qt::TopToolBarArea); + + m_toolBarFeeds->loadChangeableActions(); m_toolBarMessages->loadChangeableActions(); m_messagesBrowser->clear(); @@ -422,9 +289,6 @@ void FeedMessageViewer::initializeViews() { setTabOrder(m_messagesView, m_toolBarFeeds); setTabOrder(m_toolBarFeeds, m_toolBarMessages); setTabOrder(m_toolBarMessages, m_messagesBrowser); - - updateMessageButtonsAvailability(); - updateFeedButtonsAvailability(); } void FeedMessageViewer::refreshVisualProperties() { diff --git a/src/gui/feedmessageviewer.h b/src/gui/feedmessageviewer.h index 5dc0cf60c..587802352 100755 --- a/src/gui/feedmessageviewer.h +++ b/src/gui/feedmessageviewer.h @@ -83,9 +83,6 @@ class FeedMessageViewer : public TabContent { // Toggles displayed feeds. void toggleShowOnlyUnreadFeeds(); - void updateMessageButtonsAvailability(); - void updateFeedButtonsAvailability(); - protected: // Initializes some properties of the widget. void initialize(); diff --git a/src/gui/tabwidget.cpp b/src/gui/tabwidget.cpp index b1fc19111..8c91c6084 100755 --- a/src/gui/tabwidget.cpp +++ b/src/gui/tabwidget.cpp @@ -23,6 +23,8 @@ #include "miscellaneous/textfactory.h" #include "miscellaneous/iconfactory.h" #include "gui/tabbar.h" +#include "gui/messagesview.h" +#include "gui/feedsview.h" #include "gui/feedmessageviewer.h" #include "gui/webbrowser.h" #include "gui/plaintoolbutton.h" @@ -35,6 +37,7 @@ TabWidget::TabWidget(QWidget *parent) : QTabWidget(parent), m_menuMain(nullptr) { setTabBar(new TabBar(this)); setupMainMenuButton(); + initializeTabs(); createConnections(); } @@ -133,6 +136,11 @@ void TabWidget::createConnections() { connect(tabBar(), SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); connect(tabBar(), SIGNAL(emptySpaceDoubleClicked()), this, SLOT(addEmptyBrowser())); connect(tabBar(), SIGNAL(tabMoved(int,int)), this, SLOT(fixContentsAfterMove(int,int))); + + connect(feedMessageViewer()->messagesView(), SIGNAL(openMessagesInNewspaperView(RootItem*,QList)), + this, SLOT(addNewspaperView(RootItem*,QList))); + connect(feedMessageViewer()->feedsView(), SIGNAL(openMessagesInNewspaperView(RootItem*,QList)), + this, SLOT(addNewspaperView(RootItem*,QList))); } void TabWidget::initializeTabs() { diff --git a/src/miscellaneous/application.cpp b/src/miscellaneous/application.cpp index 927be1034..588668eaf 100755 --- a/src/miscellaneous/application.cpp +++ b/src/miscellaneous/application.cpp @@ -127,9 +127,9 @@ void Application::eliminateFirstRun(const QString &version) { void Application::setFeedReader(FeedReader *feed_reader) { m_feedReader = feed_reader; - connect(m_feedReader->feedDownloader(), &FeedDownloader::updateStarted, this, &Application::onFeedUpdatesStarted); - connect(m_feedReader->feedDownloader(), &FeedDownloader::updateProgress, this, &Application::onFeedUpdatesProgress); - connect(m_feedReader->feedDownloader(), &FeedDownloader::updateFinished, this, &Application::onFeedUpdatesFinished); + connect(m_feedReader, &FeedReader::feedUpdatesStarted, this, &Application::onFeedUpdatesStarted); + connect(m_feedReader, &FeedReader::feedUpdatesProgress, this, &Application::onFeedUpdatesProgress); + connect(m_feedReader, &FeedReader::feedUpdatesFinished, this, &Application::onFeedUpdatesFinished); } IconFactory *Application::icons() { diff --git a/src/miscellaneous/feedreader.cpp b/src/miscellaneous/feedreader.cpp index 4387590a8..faaf2cdd2 100755 --- a/src/miscellaneous/feedreader.cpp +++ b/src/miscellaneous/feedreader.cpp @@ -38,7 +38,6 @@ FeedReader::FeedReader(QObject *parent) : QObject(parent), m_feedServices(QList()), m_autoUpdateTimer(new QTimer(this)), m_feedDownloaderThread(nullptr), m_feedDownloader(nullptr), m_dbCleanerThread(nullptr), m_dbCleaner(nullptr) { - m_feedDownloader = new FeedDownloader(this); m_feedsModel = new FeedsModel(this); m_feedsProxyModel = new FeedsProxyModel(m_feedsModel, this); m_messagesModel = new MessagesModel(this); @@ -83,6 +82,10 @@ void FeedReader::updateFeeds(const QList &feeds) { connect(this, &FeedReader::feedsUpdateRequested, m_feedDownloader, &FeedDownloader::updateFeeds); connect(m_feedDownloaderThread, &QThread::finished, m_feedDownloaderThread, &QThread::deleteLater); + connect(m_feedDownloader, &FeedDownloader::updateFinished, this, &FeedReader::feedUpdatesFinished); + connect(m_feedDownloader, &FeedDownloader::updateProgress, this, &FeedReader::feedUpdatesProgress); + connect(m_feedDownloader, &FeedDownloader::updateStarted, this, &FeedReader::feedUpdatesStarted); + // Connections are made, start the feed downloader thread. m_feedDownloaderThread->start(); } diff --git a/src/miscellaneous/feedreader.h b/src/miscellaneous/feedreader.h index f0f37febb..afdb22a0e 100755 --- a/src/miscellaneous/feedreader.h +++ b/src/miscellaneous/feedreader.h @@ -21,9 +21,9 @@ #include #include "services/abstract/feed.h" +#include "core/feeddownloader.h" -class FeedDownloader; class FeedsModel; class MessagesModel; class MessagesProxyModel; @@ -78,6 +78,10 @@ class FeedReader : public QObject { // Emitted when model requests update of some feeds. void feedsUpdateRequested(QList feeds); + void feedUpdatesStarted(); + void feedUpdatesFinished(FeedDownloadResults updated_feeds); + void feedUpdatesProgress(const Feed *feed, int current, int total); + private: QList m_feedServices;