Commit dfa8a214 authored by Laurent Montel's avatar Laurent Montel 😁

Fix show/hide "new script" menu item

parent a1cb4b73
......@@ -170,7 +170,7 @@ void ManageSieveWidget::slotContextMenuRequested(const QPoint &p)
} else if (!item->parent()) {
// top-levels:
const bool jobsListIsEmpty = mJobs.keys(item).isEmpty();
if (!serverHasError(item) && jobsListIsEmpty) {
if (canAddNewScript(item, jobsListIsEmpty)) {
menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("New Script..."), this, &ManageSieveWidget::slotNewScript);
} else if (!jobsListIsEmpty) { //In Progress
menu.addAction(KStandardGuiItem::cancel().icon(), KStandardGuiItem::cancel().text(), this, &ManageSieveWidget::slotCancelFetch);
......@@ -181,6 +181,25 @@ void ManageSieveWidget::slotContextMenuRequested(const QPoint &p)
}
}
bool ManageSieveWidget::canAddNewScript(QTreeWidgetItem *item, bool jobsListIsEmpty)
{
if (!serverHasError(item) && jobsListIsEmpty) {
if (item->parent()) {
item = item->parent();
}
if (!item) {
return false;
}
if (!mUrls.count(item)) {
return false;
}
return true;
}
return false;
}
void ManageSieveWidget::slotCancelFetch()
{
QTreeWidgetItem *item = d->mTreeView->currentItem();
......
......@@ -104,6 +104,7 @@ private:
SIEVE_SERVER_IMAP_SETTINGS = Qt::UserRole + 4,
SIEVE_SERVER_LIST_SCRIPT = Qt::UserRole + 5
};
bool canAddNewScript(QTreeWidgetItem *item, bool jobsListIsEmpty);
bool serverHasError(QTreeWidgetItem *item) const;
void killAllJobs();
void clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment