Libksieve

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

KDE's Doxygen guidelines are available online.