Avoid creating unnecessary event loops

The `exec()` method will create another event loop and transfer
control over there which might introduce unexpected bugs.
This commit is contained in:
Chocobo1
2019-06-03 15:10:19 +08:00
parent 206bb018dd
commit 3748b995ff
22 changed files with 509 additions and 476 deletions

View File

@@ -468,37 +468,36 @@ void AutomatedRssDownloader::on_importBtn_clicked()
void AutomatedRssDownloader::displayRulesListMenu()
{
QMenu menu;
QAction *addAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-add"), tr("Add new rule..."));
QAction *delAct = nullptr;
QAction *renameAct = nullptr;
QAction *clearAct = nullptr;
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
const QAction *addAct = menu->addAction(GuiIconProvider::instance()->getIcon("list-add"), tr("Add new rule..."));
connect(addAct, &QAction::triggered, this, &AutomatedRssDownloader::on_addRuleBtn_clicked);
const QList<QListWidgetItem *> selection = m_ui->listRules->selectedItems();
if (!selection.isEmpty()) {
if (selection.count() == 1) {
delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete rule"));
menu.addSeparator();
renameAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename rule..."));
const QAction *delAct = menu->addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete rule"));
connect(delAct, &QAction::triggered, this, &AutomatedRssDownloader::on_removeRuleBtn_clicked);
menu->addSeparator();
const QAction *renameAct = menu->addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename rule..."));
connect(renameAct, &QAction::triggered, this, &AutomatedRssDownloader::renameSelectedRule);
}
else {
delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete selected rules"));
const QAction *delAct = menu->addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Delete selected rules"));
connect(delAct, &QAction::triggered, this, &AutomatedRssDownloader::on_removeRuleBtn_clicked);
}
menu.addSeparator();
clearAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-clear"), tr("Clear downloaded episodes..."));
menu->addSeparator();
const QAction *clearAct = menu->addAction(GuiIconProvider::instance()->getIcon("edit-clear"), tr("Clear downloaded episodes..."));
connect(clearAct, &QAction::triggered, this, &AutomatedRssDownloader::clearSelectedRuleDownloadedEpisodeList);
}
QAction *act = menu.exec(QCursor::pos());
if (!act) return;
if (act == addAct)
on_addRuleBtn_clicked();
else if (act == delAct)
on_removeRuleBtn_clicked();
else if (act == renameAct)
renameSelectedRule();
else if (act == clearAct)
clearSelectedRuleDownloadedEpisodeList();
menu->popup(QCursor::pos());
}
void AutomatedRssDownloader::renameSelectedRule()

View File

@@ -147,38 +147,45 @@ void RSSWidget::displayRSSListMenu(const QPoint &pos)
if (!m_feedListWidget->indexAt(pos).isValid())
// No item under the mouse, clear selection
m_feedListWidget->clearSelection();
QMenu myRSSListMenu(this);
QList<QTreeWidgetItem *> selectedItems = m_feedListWidget->selectedItems();
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
const QList<QTreeWidgetItem *> selectedItems = m_feedListWidget->selectedItems();
if (!selectedItems.isEmpty()) {
myRSSListMenu.addAction(m_ui->actionUpdate);
myRSSListMenu.addAction(m_ui->actionMarkItemsRead);
myRSSListMenu.addSeparator();
menu->addAction(m_ui->actionUpdate);
menu->addAction(m_ui->actionMarkItemsRead);
menu->addSeparator();
if (selectedItems.size() == 1) {
if (selectedItems.first() != m_feedListWidget->stickyUnreadItem()) {
myRSSListMenu.addAction(m_ui->actionRename);
myRSSListMenu.addAction(m_ui->actionDelete);
myRSSListMenu.addSeparator();
menu->addAction(m_ui->actionRename);
menu->addAction(m_ui->actionDelete);
menu->addSeparator();
if (m_feedListWidget->isFolder(selectedItems.first()))
myRSSListMenu.addAction(m_ui->actionNewFolder);
menu->addAction(m_ui->actionNewFolder);
}
}
else {
myRSSListMenu.addAction(m_ui->actionDelete);
myRSSListMenu.addSeparator();
menu->addAction(m_ui->actionDelete);
menu->addSeparator();
}
myRSSListMenu.addAction(m_ui->actionNewSubscription);
menu->addAction(m_ui->actionNewSubscription);
if (m_feedListWidget->isFeed(selectedItems.first())) {
myRSSListMenu.addSeparator();
myRSSListMenu.addAction(m_ui->actionCopyFeedURL);
menu->addSeparator();
menu->addAction(m_ui->actionCopyFeedURL);
}
}
else {
myRSSListMenu.addAction(m_ui->actionNewSubscription);
myRSSListMenu.addAction(m_ui->actionNewFolder);
myRSSListMenu.addSeparator();
myRSSListMenu.addAction(m_ui->actionUpdateAllFeeds);
menu->addAction(m_ui->actionNewSubscription);
menu->addAction(m_ui->actionNewFolder);
menu->addSeparator();
menu->addAction(m_ui->actionUpdateAllFeeds);
}
myRSSListMenu.exec(QCursor::pos());
menu->popup(QCursor::pos());
}
void RSSWidget::displayItemsListMenu(const QPoint &)
@@ -197,13 +204,16 @@ void RSSWidget::displayItemsListMenu(const QPoint &)
break;
}
QMenu myItemListMenu(this);
QMenu *myItemListMenu = new QMenu(this);
myItemListMenu->setAttribute(Qt::WA_DeleteOnClose);
if (hasTorrent)
myItemListMenu.addAction(m_ui->actionDownloadTorrent);
myItemListMenu->addAction(m_ui->actionDownloadTorrent);
if (hasLink)
myItemListMenu.addAction(m_ui->actionOpenNewsURL);
if (hasTorrent || hasLink)
myItemListMenu.exec(QCursor::pos());
myItemListMenu->addAction(m_ui->actionOpenNewsURL);
if (!myItemListMenu->isEmpty())
myItemListMenu->popup(QCursor::pos());
}
void RSSWidget::askNewFolder()
@@ -516,7 +526,9 @@ void RSSWidget::updateRefreshInterval(uint val)
void RSSWidget::on_rssDownloaderBtn_clicked()
{
AutomatedRssDownloader(this).exec();
auto *downloader = new AutomatedRssDownloader(this);
downloader->setAttribute(Qt::WA_DeleteOnClose);
downloader->open();
}
void RSSWidget::handleSessionProcessingStateChanged(bool enabled)