Libksieve

managesievewidget.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-only
5*/
6
7#include "managesievewidget.h"
8#include "libksieveui_debug.h"
9#include "managescriptsjob/renamescriptjob.h"
10#include "managesievetreeview.h"
11#include "widgets/sievetreewidgetitem.h"
12
13#include "kmanagesieve/sievejob.h"
14#include "managescriptsjob/generateglobalscriptjob.h"
15#include "managescriptsjob/parseuserscriptjob.h"
16#include <PimCommon/NetworkManager>
17
18#include <KSieveCore/Util>
19
20#include <KLocalizedString>
21#include <KMessageBox>
22#include <KStandardGuiItem>
23#include <QInputDialog>
24
25#include <QHBoxLayout>
26#include <QMenu>
27#include <QMetaType>
28#include <QTimer>
29// #define USE_RENAME_SIEVE_METHOD 1
30using namespace KSieveUi;
31Q_DECLARE_METATYPE(QTreeWidgetItem *)
32
33class KSieveUi::ManageSieveWidgetPrivate
34{
35public:
36 ManageSieveWidgetPrivate()
37 : mClearAll(false)
38 , mBlockSignal(false)
39 {
40 }
41
42 ~ManageSieveWidgetPrivate() = default;
43
44 // Maps top-level items to their child which has the radio button selection
46 ManageSieveTreeView *mTreeView = nullptr;
47 bool mClearAll : 1;
48 bool mBlockSignal : 1;
49};
50
51ManageSieveWidget::ManageSieveWidget(QWidget *parent)
52 : QWidget(parent)
53 , d(new KSieveUi::ManageSieveWidgetPrivate)
54{
55 auto lay = new QHBoxLayout(this);
56 lay->setContentsMargins({});
57
58 d->mTreeView = new ManageSieveTreeView(this);
59#ifndef QT_NO_CONTEXTMENU
60 connect(d->mTreeView, &ManageSieveTreeView::customContextMenuRequested, this, &ManageSieveWidget::slotContextMenuRequested);
61#endif
62 connect(d->mTreeView, &ManageSieveTreeView::itemDoubleClicked, this, &ManageSieveWidget::slotDoubleClicked);
63 connect(d->mTreeView, &ManageSieveTreeView::itemSelectionChanged, this, &ManageSieveWidget::slotUpdateButtons);
64 connect(d->mTreeView, &ManageSieveTreeView::itemChanged, this, &ManageSieveWidget::slotItemChanged);
65 connect(this, &ManageSieveWidget::updateSieveSettingsDone, this, &ManageSieveWidget::updateSieveSettingsFinished);
66
67 connect(PimCommon::NetworkManager::self(), &PimCommon::NetworkManager::networkStatusChanged, this, &ManageSieveWidget::slotSystemNetworkOnlineStateChanged);
68 lay->addWidget(d->mTreeView);
69 QTimer::singleShot(0, this, &ManageSieveWidget::slotCheckNetworkStatus);
70}
71
72ManageSieveWidget::~ManageSieveWidget()
73{
74 disconnect(d->mTreeView, &ManageSieveTreeView::itemSelectionChanged, this, &ManageSieveWidget::slotUpdateButtons);
75 clear();
76}
77
78void ManageSieveWidget::slotCheckNetworkStatus()
79{
80 slotSystemNetworkOnlineStateChanged(PimCommon::NetworkManager::self()->isOnline());
81}
82
83void ManageSieveWidget::slotSystemNetworkOnlineStateChanged(bool state)
84{
85 if (state) {
86 d->mTreeView->setEnabled(true);
87 slotRefresh();
88 } else {
89 d->mTreeView->setEnabled(false);
90 d->mTreeView->setNetworkDown(false);
91 }
92}
93
94ManageSieveTreeView *ManageSieveWidget::treeView() const
95{
96 return d->mTreeView;
97}
98
99void ManageSieveWidget::killAllJobs()
100{
101 d->mClearAll = true;
103 while (it != mJobs.constEnd()) {
104 it.key()->kill();
105 ++it;
106 }
107 d->mClearAll = false;
108 mJobs.clear();
109}
110
111bool ManageSieveWidget::serverHasError(QTreeWidgetItem *item) const
112{
113 const QVariant variant = item->data(0, SIEVE_SERVER_ERROR);
114 if (variant.isValid() && variant.toBool() == true) {
115 return true;
116 }
117 return false;
118}
119
120void ManageSieveWidget::slotItemChanged(QTreeWidgetItem *item, int col)
121{
122 if (!item || d->mBlockSignal || (col != 0)) {
123 return;
124 }
125 if (!isFileNameItem(item)) {
126 return;
127 }
128 QTreeWidgetItem *parent = item->parent();
129 if ((d->mSelectedItems[parent] != item) && itemIsActived(item)) {
130 d->mSelectedItems[parent] = item;
131 changeActiveScript(parent, true);
132 } else {
133 d->mSelectedItems[parent] = item;
134 changeActiveScript(parent, false);
135 }
136}
137
138void ManageSieveWidget::slotContextMenuRequested(const QPoint &p)
139{
140 QTreeWidgetItem *item = d->mTreeView->itemAt(p);
141 if (!item) {
142 return;
143 }
144 QMenu menu;
145 if (isFileNameItem(item)) {
146 // script items:
147 menu.addAction(i18n("Edit Script…"), this, &ManageSieveWidget::slotEditScript);
148 menu.addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18n("Rename Script…"), this, &ManageSieveWidget::slotRenameScript);
149 menu.addSeparator();
150 menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("Delete Script"), this, &ManageSieveWidget::slotDeleteScript);
151 if (itemIsActived(item)) {
152 menu.addSeparator();
153 menu.addAction(i18n("Deactivate Script"), this, &ManageSieveWidget::slotDeactivateScript);
154 }
155 } else if (!item->parent()) {
156 // top-levels:
157 const bool jobsListIsEmpty = mJobs.keys(item).isEmpty();
158 if (canAddNewScript(item, jobsListIsEmpty)) {
159 menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("New Script…"), this, &ManageSieveWidget::slotNewScript);
160 } else if (!jobsListIsEmpty) { // In Progress
161 menu.addAction(KStandardGuiItem::cancel().icon(), KStandardGuiItem::cancel().text(), this, &ManageSieveWidget::slotCancelFetch);
162 }
163 }
164 if (!menu.actions().isEmpty()) {
165 menu.exec(d->mTreeView->viewport()->mapToGlobal(p));
166 }
167}
168
169bool ManageSieveWidget::canAddNewScript(QTreeWidgetItem *item, bool jobsListIsEmpty)
170{
171 if (!serverHasError(item) && jobsListIsEmpty) {
172 if (item->parent()) {
173 item = item->parent();
174 }
175 if (!item) {
176 return false;
177 }
178
179 if (!mUrls.contains(item)) {
180 return false;
181 }
182 return true;
183 }
184 return false;
185}
186
187void ManageSieveWidget::slotCancelFetch()
188{
189 QTreeWidgetItem *item = d->mTreeView->currentItem();
190 if (item) {
191 const QList<KManageSieve::SieveJob *> jobs = mJobs.keys(item);
192 for (KManageSieve::SieveJob *job : jobs) {
193 job->kill(KJob::EmitResult);
194 }
195 } else {
196 qCWarning(LIBKSIEVEUI_LOG) << "ManageSieveWidget::slotCancelFetch(): item is not selected";
197 }
198}
199
200void ManageSieveWidget::slotNewScript()
201{
202 QTreeWidgetItem *currentItem = d->mTreeView->currentItem();
203 if (!currentItem) {
204 return;
205 }
206 if (currentItem->parent()) {
207 currentItem = currentItem->parent();
208 }
209 if (!currentItem) {
210 return;
211 }
212
213 if (!mUrls.contains(currentItem)) {
214 return;
215 }
216
217 QUrl u = mUrls[currentItem];
218 if (u.isEmpty()) {
219 return;
220 }
221
222 bool ok = false;
223 QString name =
224 QInputDialog::getText(this, i18n("New Sieve Script"), i18n("Please enter a name for the new Sieve script:"), QLineEdit::Normal, i18n("unnamed"), &ok);
225 name = name.trimmed();
226 if (!ok || name.isEmpty()) {
227 if (ok && name.isEmpty()) {
228 KMessageBox::error(this, i18n("Empty name is not a valid name"), i18nc("@title:window", "New Script"));
229 }
230 return;
231 }
232
234 KMessageBox::error(this, i18n("You cannot use protected name."), i18nc("@title:window", "New Script"));
235 return;
236 }
237
239 u.setPath(u.path() + QLatin1Char('/') + name);
240
241 QTreeWidgetItem *parentItem = currentItem;
242 if (parentItem) {
243 const int numberOfElement(parentItem->childCount());
244 for (int i = 0; i < numberOfElement; ++i) {
245 if (parentItem->child(i)->text(0) == name) {
246 KMessageBox::error(this, i18n("Script name already used \"%1\".", name), i18nc("@title:window", "New Script"));
247 return;
248 }
249 }
250 }
251
252 const QStringList currentCapabilities = currentItem->data(0, SIEVE_SERVER_CAPABILITIES).toStringList();
253 const auto sieveimapaccountsettings = currentItem->data(0, SIEVE_SERVER_IMAP_SETTINGS).value<KSieveCore::SieveImapAccountSettings>();
254 const QStringList listscript = currentItem->data(0, SIEVE_SERVER_LIST_SCRIPT).toStringList();
255
256 d->mBlockSignal = true;
257 auto newItem = new QTreeWidgetItem(currentItem);
258 newItem->setFlags(newItem->flags() & (Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable));
259 newItem->setText(0, name);
260 newItem->setCheckState(0, Qt::Unchecked);
261 d->mBlockSignal = false;
262
263 ScriptInfo info;
264 info.currentCapabilities = currentCapabilities;
265 info.currentUrl = u;
266 info.sieveImapAccountSettings = sieveimapaccountsettings;
267 info.scriptList = listscript;
268
269 Q_EMIT newScript(info);
270}
271
272void ManageSieveWidget::slotEditScript()
273{
274 QTreeWidgetItem *currentItem = d->mTreeView->currentItem();
275 if (!isFileNameItem(currentItem)) {
276 return;
277 }
278 QTreeWidgetItem *parent = currentItem->parent();
279 if (!mUrls.contains(parent)) {
280 return;
281 }
282 QUrl url = mUrls[parent];
283 if (url.isEmpty()) {
284 return;
285 }
287 url.setPath(url.path() + QLatin1Char('/') + currentItem->text(0));
288 const auto sieveimapaccountsettings = parent->data(0, SIEVE_SERVER_IMAP_SETTINGS).value<KSieveCore::SieveImapAccountSettings>();
289 const QStringList currentCapabilities = parent->data(0, SIEVE_SERVER_CAPABILITIES).toStringList();
290 const QStringList listscript = parent->data(0, SIEVE_SERVER_LIST_SCRIPT).toStringList();
291
292 ScriptInfo info;
293 info.currentCapabilities = currentCapabilities;
294 info.currentUrl = url;
295 info.sieveImapAccountSettings = sieveimapaccountsettings;
296 info.scriptList = listscript;
297
298 Q_EMIT editScript(info);
299}
300
301void ManageSieveWidget::slotDeactivateScript()
302{
303 QTreeWidgetItem *item = d->mTreeView->currentItem();
304 if (!isFileNameItem(item)) {
305 return;
306 }
307 QTreeWidgetItem *parent = item->parent();
308 if (itemIsActived(item)) {
309 d->mSelectedItems[parent] = item;
310 changeActiveScript(parent, false);
311 }
312}
313
314bool ManageSieveWidget::updateGlobalScript(QTreeWidgetItem *item, const QUrl &u)
315{
316 if (item->data(0, SIEVE_SERVER_MODE).toInt() == Kep14EditorMode) {
317 QStringList activeScripts;
318 for (int i = 0; i < item->childCount(); ++i) {
319 QTreeWidgetItem *j = item->child(i);
320 if (itemIsActived(j)) {
321 activeScripts << j->text(0);
322 }
323 }
324 auto job = new KSieveCore::GenerateGlobalScriptJob(u);
325 job->addUserActiveScripts(activeScripts);
326 job->setForceActivateUserScript(true);
327 connect(job, &KSieveCore::GenerateGlobalScriptJob::success, this, &ManageSieveWidget::slotRefresh);
328 connect(job, &KSieveCore::GenerateGlobalScriptJob::error, this, &ManageSieveWidget::slotGenerateGlobalScriptError);
329 job->start();
330 return true;
331 }
332 return false;
333}
334
335void ManageSieveWidget::changeActiveScript(QTreeWidgetItem *item, bool activate, bool deleteScript)
336{
337 if (!item) {
338 return;
339 }
340 if (!mUrls.contains(item)) {
341 return;
342 }
343 if (!d->mSelectedItems.contains(item)) {
344 return;
345 }
346 QUrl u = mUrls[item];
347 if (u.isEmpty()) {
348 return;
349 }
350 if (updateGlobalScript(item, u)) {
351 return;
352 }
353
354 QTreeWidgetItem *selected = d->mSelectedItems[item];
355 if (!selected) {
356 return;
357 }
359 u.setPath(u.path() + QLatin1Char('/') + selected->text(0));
360
361 KManageSieve::SieveJob *job = nullptr;
362 if (activate) {
364 } else {
366 }
367 d->mBlockSignal = true;
368 connect(job, &KManageSieve::SieveJob::result, this, [this, u, deleteScript]() {
369 slotRefresh();
370 if (deleteScript) {
372 connect(job, &KManageSieve::SieveJob::result, this, &ManageSieveWidget::slotDeleteResult);
373 Q_EMIT scriptDeleted(u);
374 }
375 });
376}
377
378void ManageSieveWidget::slotGenerateGlobalScriptError(const QString &errorStr)
379{
380 qCWarning(LIBKSIEVEUI_LOG) << "MManageSieveWidget::slotGenerateGlobalScriptError: error: " << errorStr;
381 slotRefresh();
382}
383
384bool ManageSieveWidget::itemIsActived(QTreeWidgetItem *item) const
385{
386 Q_ASSERT(item && item->parent());
387 return item->checkState(0) == Qt::Checked;
388}
389
390bool ManageSieveWidget::isFileNameItem(QTreeWidgetItem *item) const
391{
392 if (!item || !item->parent()) {
393 return false;
394 }
395 return item->flags() & Qt::ItemIsEnabled;
396}
397
398void ManageSieveWidget::clear()
399{
400 killAllJobs();
401 d->mSelectedItems.clear();
402 mUrls.clear();
403 d->mTreeView->clear();
404}
405
406void ManageSieveWidget::slotRenameScript()
407{
408 QTreeWidgetItem *currentItem = d->mTreeView->currentItem();
409 if (!isFileNameItem(currentItem)) {
410 return;
411 }
412 QTreeWidgetItem *parent = currentItem->parent();
413 if (!parent) {
414 return;
415 }
416
417 if (!mUrls.contains(parent)) {
418 return;
419 }
420
421 QUrl u = mUrls[parent];
422 if (u.isEmpty()) {
423 return;
424 }
425
426 const QString newName = QInputDialog::getText(this, i18n("Rename Script"), i18n("Script Name:"), QLineEdit::Normal, currentItem->text(0));
427 if (newName.trimmed().isEmpty()) {
428 return;
429 }
430
431 if (newName == currentItem->text(0)) {
432 return;
433 }
434
436 u.setPath(u.path() + QLatin1Char('/') + currentItem->text(0));
437#ifdef USE_RENAME_SIEVE_METHOD
439 connect(job, &KManageSieve::SieveJob::result, this, &ManageSieveWidget::slotRenameResult);
440#else
441 auto job = new KSieveCore::RenameScriptJob(this);
442 job->setOldUrl(u);
443 job->setIsActive(itemIsActived(currentItem));
444 job->setNewName(newName);
445 connect(job, &KSieveCore::RenameScriptJob::finished, this, &ManageSieveWidget::slotRenameFinished);
446 job->start();
447#endif
448}
449
450void ManageSieveWidget::slotRenameFinished(const QUrl &oldUrl, const QUrl &newUrl, const QString &errorStr, bool success)
451{
452 qCDebug(LIBKSIEVEUI_LOG) << " void ManageSieveWidget::slotRenameResult(KManageSieve::SieveJob *job, bool success)" << success;
453 if (!success) {
454 KMessageBox::error(this, errorStr, i18n("Rename Script"));
455 } else {
456 Q_EMIT scriptRenamed(oldUrl, newUrl);
457 }
458 slotRefresh();
459}
460
461void ManageSieveWidget::slotRenameResult(KManageSieve::SieveJob *job, bool success)
462{
463 Q_UNUSED(job)
464 qCDebug(LIBKSIEVEUI_LOG) << " void ManageSieveWidget::slotRenameResult(KManageSieve::SieveJob *job, bool success)" << success;
465 slotRefresh();
466}
467
468void ManageSieveWidget::slotDeleteScript()
469{
470 QTreeWidgetItem *currentItem = d->mTreeView->currentItem();
471 if (!isFileNameItem(currentItem)) {
472 return;
473 }
474
475 QTreeWidgetItem *parent = currentItem->parent();
476 if (!parent) {
477 return;
478 }
479
480 if (!mUrls.contains(parent)) {
481 return;
482 }
483
484 QUrl u = mUrls[parent];
485 if (u.isEmpty()) {
486 return;
487 }
488
490 i18n("Really delete script \"%1\" from the server?", currentItem->text(0)),
491 i18nc("@title:window", "Delete Sieve Script Confirmation"),
494 return;
495 }
496
498 u.setPath(u.path() + QLatin1Char('/') + currentItem->text(0));
499
501 connect(job, &KManageSieve::SieveJob::result, this, &ManageSieveWidget::slotDeleteResult);
502 Q_EMIT scriptDeleted(u);
503}
504
505void ManageSieveWidget::slotDeleteResult(KManageSieve::SieveJob *job, bool success)
506{
507 if (!success) {
509 i18n("Deleting the script failed.\n"
510 "The server responded:\n%1",
511 job->errorString()),
512 i18nc("@title:window", "Sieve Error"));
513 }
514 slotRefresh();
515}
516
517void ManageSieveWidget::slotRefresh()
518{
519 d->mBlockSignal = true;
520 updateSieveSettings();
521}
522
523void ManageSieveWidget::updateSieveSettingsFinished()
524{
525 clear();
526 const bool noImapFound = refreshList();
527 slotUpdateButtons();
528 d->mTreeView->setNoImapFound(noImapFound);
529 if (!noImapFound) {
530 d->mBlockSignal = false;
531 }
532 Q_EMIT serverSieveFound(!noImapFound);
533}
534
535void ManageSieveWidget::slotUpdateButtons()
536{
537 Q_EMIT updateButtons(d->mTreeView->currentItem());
538}
539
540void ManageSieveWidget::slotGotList(KManageSieve::SieveJob *job, bool success, const QStringList &listScript, const QString &activeScript)
541{
542 // qCDebug(LIBKSIEVEUI_LOG) << "void ManageSieveWidget::slotGotList(KManageSieve::SieveJob *job, bool success, const QStringList &listScript, const QString
543 // &activeScript) success: " << success
544 // << " listScript" << listScript;
545 if (d->mClearAll) {
546 return;
547 }
548 // qCDebug(LIBKSIEVEUI_LOG) << " After mClear All";
549 QTreeWidgetItem *parent = mJobs[job];
550 // qCDebug(LIBKSIEVEUI_LOG) << " parent " << parent;
551 if (!parent) {
552 return;
553 }
554 (static_cast<SieveTreeWidgetItem *>(parent))->stopAnimation();
555
556 mJobs.remove(job);
557 if (!success) {
558 d->mBlockSignal = false;
559 parent->setData(0, SIEVE_SERVER_ERROR, true);
560 auto item = new QTreeWidgetItem(parent);
561 item->setText(0, i18n("Failed to fetch the list of scripts"));
562 item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
563 d->mTreeView->expandItem(parent);
564 return;
565 }
566
567 d->mBlockSignal = true; // don't trigger slotItemChanged
568 for (const QString &script : listScript) {
569 // Hide protected name.
571 continue;
572 }
573 auto item = new QTreeWidgetItem(parent);
575
576 item->setText(0, script);
577 const bool isActive = (script == activeScript);
578 item->setCheckState(0, isActive ? Qt::Checked : Qt::Unchecked);
579 if (isActive) {
580 d->mSelectedItems[parent] = item;
581 }
582 }
583 d->mBlockSignal = false;
584
585 QStringList sieveCapabilities = job->sieveCapabilities();
586 sieveCapabilities.sort();
587 bool hasKep14EditorMode = KSieveCore::Util::hasKep14Support(sieveCapabilities, listScript, activeScript);
588 if (hasKep14EditorMode) {
589 QUrl u = mUrls[parent];
591 u.setPath(u.path() + QLatin1Char('/') + QStringLiteral("USER"));
592 auto parseJob = new KSieveCore::ParseUserScriptJob(u, this);
593 parseJob->setAutoDelete(true);
594 parseJob->setProperty("parentItem", QVariant::fromValue<QTreeWidgetItem *>(parent));
595 connect(parseJob, &KSieveCore::ParseUserScriptJob::finished, this, &ManageSieveWidget::setActiveScripts);
596 parseJob->start();
597 (static_cast<SieveTreeWidgetItem *>(parent))->startAnimation();
598 } else if (KSieveCore::Util::hasKep14CapabilitySupport(sieveCapabilities)) { // We don't have user script but server support kep14
599 hasKep14EditorMode = true;
600 }
601
602 parent->setData(0, SIEVE_SERVER_CAPABILITIES, sieveCapabilities);
603 parent->setData(0, SIEVE_SERVER_ERROR, false);
604 parent->setData(0, SIEVE_SERVER_MODE, hasKep14EditorMode ? Kep14EditorMode : NormalEditorMode);
605 parent->setData(0,
606 SIEVE_SERVER_IMAP_SETTINGS,
607 QVariant::fromValue(job->property("sieveimapaccountsettings").value<KSieveCore::SieveImapAccountSettings>()));
608 parent->setData(0, SIEVE_SERVER_LIST_SCRIPT, listScript);
609 d->mTreeView->expandItem(parent);
610}
611
612void ManageSieveWidget::setActiveScripts(KSieveCore::ParseUserScriptJob *job)
613{
614 auto *parent = job->property("parentItem").value<QTreeWidgetItem *>();
615 if (!parent) {
616 return;
617 }
618 (static_cast<SieveTreeWidgetItem *>(parent))->stopAnimation();
619
620 if (!job->error().isEmpty()) {
621 qCWarning(LIBKSIEVEUI_LOG) << job->error();
622 return;
623 }
624
625 d->mBlockSignal = true; // don't trigger slotItemChanged
626 const QStringList activeScriptList = job->activeScriptList();
627 QStringList scriptOrder = activeScriptList;
629
630 const int children = parent->childCount();
631 for (int i = 0; i < children; ++i) {
632 QTreeWidgetItem *item = parent->takeChild(0);
633 scriptMap.insert(item->text(0), item);
634 const bool isActive = activeScriptList.contains(item->text(0));
635 item->setCheckState(0, isActive ? Qt::Checked : Qt::Unchecked);
636 if (!isActive) {
637 scriptOrder << item->text(0);
638 }
639 }
640
641 for (const QString &scriptName : std::as_const(scriptOrder)) {
642 parent->addChild(scriptMap[scriptName]);
643 }
644
645 d->mBlockSignal = false;
646}
647
648void ManageSieveWidget::slotDoubleClicked(QTreeWidgetItem *item)
649{
650 if (!isFileNameItem(item)) {
651 return;
652 }
653 slotEditScript();
654}
655
656void ManageSieveWidget::enableDisableActions(bool &newScriptAction, bool &editScriptAction, bool &deleteScriptAction, bool &desactivateScriptAction)
657{
658 QTreeWidgetItem *item = d->mTreeView->currentItem();
659
660 bool enabled = true;
661 if (!item) {
662 enabled = false;
663 } else if (!item->parent() && !mUrls.contains(item)) {
664 enabled = false;
665 }
666
667 if (!enabled) {
668 newScriptAction = false;
669 editScriptAction = false;
670 deleteScriptAction = false;
671 desactivateScriptAction = false;
672 } else {
673 if (serverHasError(item) || !mJobs.keys(item).isEmpty()) {
674 newScriptAction = false;
675 } else {
676 newScriptAction = mUrls.contains(item);
677 }
678 enabled = isFileNameItem(item);
679 editScriptAction = enabled;
680 deleteScriptAction = enabled;
681 desactivateScriptAction = enabled && itemIsActived(item);
682 }
683}
684
685#include "moc_managesievewidget.cpp"
A job to manage sieve scripts.
Definition sievejob.h:31
static SieveJob * deactivate(const QUrl &url)
Deactivates the script with the given sieve url.
Definition sievejob.cpp:340
QString errorString() const
A human-readable error message.
Definition sievejob.cpp:268
void result(KManageSieve::SieveJob *job, bool success, const QString &script, bool active)
This signal is emitted for all kind of jobs when they have finished.
QStringList sieveCapabilities() const
Returns the sieve capabilities of the IMAP server.
Definition sievejob.cpp:254
static SieveJob * del(const QUrl &url)
Deletes the script with the given sieve url.
Definition sievejob.cpp:327
static SieveJob * rename(const QUrl &url, const QString &newName)
Rename the script with the given sieve url and new name newName.
Definition sievejob.cpp:352
static SieveJob * activate(const QUrl &url)
Activates the script with the given sieve url.
Definition sievejob.cpp:380
The RenameScriptJob class.
The SieveImapAccountSettings class.
The ManageSieveTreeView class.
The SieveTreeWidgetItem class.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
ButtonCode warningContinueCancel(QWidget *parent, const QString &text, const QString &title=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
KSIEVECORE_EXPORT bool hasKep14Support(const QStringList &sieveCapabilities, const QStringList &availableScripts, const QString &activeScript)
Checks if a server has KEP:14 support.
Definition util.cpp:63
KSIEVECORE_EXPORT bool isKep14ProtectedName(const QString &scriptName)
Is the given scriptName a protected KEP:14 name, that a normal user should not touch directly.
Definition util.cpp:94
QString name(StandardAction id)
KGuiItem cancel()
KGuiItem del()
QIcon fromTheme(const QString &name)
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
bool isEmpty() const const
void clear()
const_iterator constBegin() const const
const_iterator constEnd() const const
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
QList< Key > keys() const const
size_type remove(const Key &key)
QAction * addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut)
QAction * addSeparator()
QAction * exec()
Q_EMITQ_EMIT
const QObjectList & children() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QObject * parent() const const
QVariant property(const char *name) const const
bool isEmpty() const const
QString trimmed() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
void sort(Qt::CaseSensitivity cs)
Unchecked
ItemIsUserCheckable
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void itemSelectionChanged()
Qt::CheckState checkState(int column) const const
QTreeWidgetItem * child(int index) const const
int childCount() const const
virtual QVariant data(int column, int role) const const
Qt::ItemFlags flags() const const
QTreeWidgetItem * parent() const const
void setCheckState(int column, Qt::CheckState state)
void setFlags(Qt::ItemFlags flags)
void setText(int column, const QString &text)
QString text(int column) const const
RemoveFilename
QUrl adjusted(FormattingOptions options) const const
bool isEmpty() const const
QString path(ComponentFormattingOptions options) const const
void setPath(const QString &path, ParsingMode mode)
QVariant fromValue(T &&value)
bool isValid() const const
bool toBool() const const
int toInt(bool *ok) const const
QStringList toStringList() const const
T value() const const
QList< QAction * > actions() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.