Libksieve

sievescriptlistbox.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "sievescriptlistbox.h"
21 #include "sievescriptdescriptiondialog.h"
22 #include "sieveglobalvariablewidget.h"
23 #include "sieveforeverypartwidget.h"
24 #include "sievescriptpage.h"
25 #include "sieveincludewidget.h"
26 #include "sieveeditorgraphicalmodewidget.h"
27 #include <QXmlStreamReader>
28 #include <QHBoxLayout>
29 #include <KMessageBox>
30 #include <KLocalizedString>
31 #include <QInputDialog>
32 #include <QPushButton>
33 #include <QIcon>
34 
35 #include <QVBoxLayout>
36 #include <QListWidget>
37 #include <QPointer>
38 #include <QMenu>
39 #include "libksieve_debug.h"
40 
41 namespace {
42 inline const QString defaultScriptName()
43 {
44  return QStringLiteral("SCRIPTNAME: ");
45 }
46 }
47 
48 using namespace KSieveUi;
49 
50 SieveScriptListItem::SieveScriptListItem(const QString &text, QListWidget *parent)
51  : QListWidgetItem(text, parent)
52 {
53 }
54 
55 SieveScriptListItem::~SieveScriptListItem()
56 {
57 }
58 
59 void SieveScriptListItem::setDescription(const QString &desc)
60 {
61  mDescription = desc;
62 }
63 
64 QString SieveScriptListItem::description() const
65 {
66  return mDescription;
67 }
68 
69 SieveScriptPage *SieveScriptListItem::scriptPage() const
70 {
71  return mScriptPage;
72 }
73 
74 void SieveScriptListItem::setScriptPage(SieveScriptPage *page)
75 {
76  mScriptPage = page;
77 }
78 
79 QString SieveScriptListItem::generatedScript(QStringList &required) const
80 {
81  QString script;
82  if (!mDescription.trimmed().isEmpty()) {
83  const QVector<QStringRef> commentList = mDescription.splitRef(QLatin1Char('\n'));
84  for (const QStringRef &str : commentList) {
85  if (str.isEmpty()) {
86  script += QLatin1Char('\n');
87  } else {
88  script += QLatin1Char('#') + str + QLatin1Char('\n');
89  }
90  }
91  }
92  if (mScriptPage) {
93  mScriptPage->generatedScript(script, required);
94  }
95  return script;
96 }
97 
98 SieveScriptListBox::SieveScriptListBox(const QString &title, QWidget *parent)
99  : QGroupBox(title, parent)
100 {
101  QVBoxLayout *layout = new QVBoxLayout(this);
102  layout->setObjectName(QStringLiteral("layout"));
103  mSieveListScript = new QListWidget(this);
104  mSieveListScript->setObjectName(QStringLiteral("mSieveListScript"));
105  mSieveListScript->setDragDropMode(QAbstractItemView::InternalMove);
106  mSieveListScript->setContextMenuPolicy(Qt::CustomContextMenu);
107  connect(mSieveListScript, &QListWidget::customContextMenuRequested, this, &SieveScriptListBox::slotCustomMenuRequested);
108  layout->addWidget(mSieveListScript);
109 
110  //----------- the first row of buttons
111  QWidget *hb = new QWidget(this);
112  QHBoxLayout *hbHBoxLayout = new QHBoxLayout(hb);
113  hbHBoxLayout->setContentsMargins(0, 0, 0, 0);
114  hbHBoxLayout->setSpacing(4);
115 
116  mBtnTop = new QPushButton(hb);
117  hbHBoxLayout->addWidget(mBtnTop);
118  mBtnTop->setIcon(QIcon::fromTheme(QStringLiteral("go-top")));
119  mBtnTop->setMinimumSize(mBtnTop->sizeHint() * 1.2);
120 
121  mBtnUp = new QPushButton(hb);
122  hbHBoxLayout->addWidget(mBtnUp);
123  mBtnUp->setAutoRepeat(true);
124  mBtnUp->setIcon(QIcon::fromTheme(QStringLiteral("go-up")));
125  mBtnUp->setMinimumSize(mBtnUp->sizeHint() * 1.2);
126  mBtnDown = new QPushButton(hb);
127  hbHBoxLayout->addWidget(mBtnDown);
128  mBtnDown->setAutoRepeat(true);
129  mBtnDown->setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
130  mBtnDown->setMinimumSize(mBtnDown->sizeHint() * 1.2);
131 
132  mBtnBottom = new QPushButton(hb);
133  hbHBoxLayout->addWidget(mBtnBottom);
134  mBtnBottom->setIcon(QIcon::fromTheme(QStringLiteral("go-bottom")));
135  mBtnBottom->setMinimumSize(mBtnBottom->sizeHint() * 1.2);
136 
137  mBtnUp->setToolTip(i18nc("Move selected filter up.", "Up"));
138  mBtnDown->setToolTip(i18nc("Move selected filter down.", "Down"));
139  mBtnTop->setToolTip(i18nc("Move selected filter to the top.", "Top"));
140  mBtnBottom->setToolTip(i18nc("Move selected filter to the bottom.", "Bottom"));
141 
142  layout->addWidget(hb);
143 
144  hb = new QWidget(this);
145  hbHBoxLayout = new QHBoxLayout(hb);
146  hbHBoxLayout->setContentsMargins(0, 0, 0, 0);
147  hbHBoxLayout->setSpacing(4);
148 
149  mBtnNew = new QPushButton(hb);
150  hbHBoxLayout->addWidget(mBtnNew);
151  mBtnNew->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
152  mBtnNew->setToolTip(i18n("New Script"));
153  mBtnNew->setMinimumSize(mBtnNew->sizeHint() * 1.2);
154 
155  mBtnDelete = new QPushButton(hb);
156  hbHBoxLayout->addWidget(mBtnDelete);
157  mBtnDelete->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
158  mBtnDelete->setToolTip(i18n("Delete Script"));
159  mBtnDelete->setMinimumSize(mBtnDelete->sizeHint() * 1.2);
160 
161  mBtnRename = new QPushButton(hb);
162  mBtnRename->setToolTip(i18n("Rename Script"));
163  mBtnRename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
164  mBtnRename->setMinimumSize(mBtnRename->sizeHint() * 1.2);
165  hbHBoxLayout->addWidget(mBtnRename);
166 
167  mBtnDescription = new QPushButton(hb);
168  mBtnDescription->setToolTip(i18n("Edit Script Description"));
169  mBtnDescription->setIcon(QIcon::fromTheme(QStringLiteral("edit-comment")));
170  mBtnDescription->setMinimumSize(mBtnDescription->sizeHint() * 1.2);
171 
172  hbHBoxLayout->addWidget(mBtnDescription);
173 
174  layout->addWidget(hb);
175 
176  connect(mBtnNew, &QPushButton::clicked, this, &SieveScriptListBox::slotNew);
177  connect(mBtnDelete, &QPushButton::clicked, this, &SieveScriptListBox::slotDelete);
178  connect(mBtnRename, &QPushButton::clicked, this, &SieveScriptListBox::slotRename);
179  connect(mBtnDescription, &QPushButton::clicked, this, &SieveScriptListBox::slotEditDescription);
180 
181  connect(mBtnUp, &QPushButton::clicked, this, &SieveScriptListBox::slotUp);
182  connect(mBtnDown, &QPushButton::clicked, this, &SieveScriptListBox::slotDown);
183  connect(mBtnTop, &QPushButton::clicked, this, &SieveScriptListBox::slotTop);
184  connect(mBtnBottom, &QPushButton::clicked, this, &SieveScriptListBox::slotBottom);
185 
186  connect(mSieveListScript, &QListWidget::itemSelectionChanged, this, &SieveScriptListBox::updateButtons);
187  connect(mSieveListScript, &QListWidget::itemActivated, this, &SieveScriptListBox::slotItemActived);
188  connect(mSieveListScript, &QListWidget::itemDoubleClicked, this, &SieveScriptListBox::slotEditDescription);
189  updateButtons();
190 }
191 
192 SieveScriptListBox::~SieveScriptListBox()
193 {
194 }
195 
196 void SieveScriptListBox::slotCustomMenuRequested(const QPoint &pos)
197 {
198  QMenu menu(this);
199  QAction *newScriptAction = menu.addAction(i18nc("@action:inmenu", "New Script"));
200  newScriptAction->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
201  connect(newScriptAction, &QAction::triggered, this, &SieveScriptListBox::slotNew);
202 
203  if (mSieveListScript->itemAt(pos)) {
204  QAction *renameScriptAction = menu.addAction(i18nc("@action:inmenu", "Rename Script"));
205  renameScriptAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
206  connect(renameScriptAction, &QAction::triggered, this, &SieveScriptListBox::slotRename);
207 
208  menu.addSeparator();
209  QAction *deleteScriptAction = menu.addAction(i18nc("@action:inmenu", "Delete Script"));
210  deleteScriptAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
211  connect(deleteScriptAction, &QAction::triggered, this, &SieveScriptListBox::slotDelete);
212  }
213  menu.exec(mapToGlobal(pos));
214 }
215 
216 void SieveScriptListBox::setSieveEditorGraphicalModeWidget(SieveEditorGraphicalModeWidget *graphicalModeWidget)
217 {
218  mSieveGraphicalModeWidget = graphicalModeWidget;
219 }
220 
221 void SieveScriptListBox::slotItemActived(QListWidgetItem *item)
222 {
223  if (item) {
224  SieveScriptListItem *itemScript = static_cast<SieveScriptListItem *>(item);
225  Q_EMIT activatePage(itemScript->scriptPage());
226  }
227 }
228 
229 void SieveScriptListBox::updateButtons()
230 {
231  const int currentIndex = mSieveListScript->currentRow();
232  const bool theFirst = (currentIndex == 0);
233  const int numberOfElement(mSieveListScript->count());
234  const bool theLast = (currentIndex >= numberOfElement - 1);
235 
236  const QList<QListWidgetItem *> lst = mSieveListScript->selectedItems();
237  mBtnDelete->setEnabled(!lst.isEmpty());
238  mBtnRename->setEnabled(lst.count() == 1);
239  mBtnDescription->setEnabled(lst.count() == 1);
240  mBtnBottom->setEnabled(!lst.isEmpty() && !theLast);
241  mBtnTop->setEnabled(!lst.isEmpty() && !theFirst);
242  mBtnDown->setEnabled(!lst.isEmpty() && !theLast);
243  mBtnUp->setEnabled(!lst.isEmpty() && !theFirst);
244 }
245 
246 SieveScriptPage *SieveScriptListBox::createNewScript(const QString &newName, const QString &description)
247 {
248  SieveScriptListItem *item = new SieveScriptListItem(newName, mSieveListScript);
249  item->setDescription(description);
250  SieveScriptPage *page = new SieveScriptPage(mSieveGraphicalModeWidget);
251  page->setListOfIncludeFile(mSieveGraphicalModeWidget->listOfIncludeFile());
252  item->setScriptPage(page);
253  Q_EMIT addNewPage(page);
254  Q_EMIT enableButtonOk(true);
255  mSieveListScript->setCurrentItem(item);
256  updateButtons();
257  return page;
258 }
259 
260 void SieveScriptListBox::slotNew()
261 {
262  const QString newName = QInputDialog::getText(this, i18nc("@title:window", "New Script"), i18n("New script name:"));
263  if (!newName.trimmed().isEmpty()) {
264  createNewScript(newName);
265  Q_EMIT valueChanged();
266  }
267 }
268 
269 void SieveScriptListBox::slotDelete()
270 {
271  QListWidgetItem *item = mSieveListScript->currentItem();
272  if (item) {
273  if (KMessageBox::warningYesNo(this, i18n("Do you want to delete \"%1\" script?", item->text()),
274  i18nc("@title:window", "Delete Script")) == KMessageBox::Yes) {
275  SieveScriptListItem *itemScript = static_cast<SieveScriptListItem *>(item);
276  Q_EMIT removePage(itemScript->scriptPage());
277  delete item;
278  Q_EMIT enableButtonOk(mSieveListScript->count() > 0);
279  updateButtons();
280  Q_EMIT valueChanged();
281  }
282  }
283 }
284 
285 void SieveScriptListBox::slotRename()
286 {
287  QListWidgetItem *item = mSieveListScript->currentItem();
288  if (item) {
289  QString newName = QInputDialog::getText(this, i18nc("@title:window", "Rename Script"), i18n("New name for the script:"), QLineEdit::Normal, item->text());
290  newName = newName.trimmed();
291  if (!newName.isEmpty()) {
292  item->setText(newName);
293  Q_EMIT valueChanged();
294  }
295  }
296 }
297 
298 void SieveScriptListBox::slotEditDescription()
299 {
300  QListWidgetItem *item = mSieveListScript->currentItem();
301  if (item) {
302  SieveScriptListItem *sieveItem = static_cast<SieveScriptListItem *>(item);
303  QPointer<SieveScriptDescriptionDialog> dlg = new SieveScriptDescriptionDialog(this);
304  dlg->setDescription(sieveItem->description());
305  if (dlg->exec()) {
306  sieveItem->setDescription(dlg->description());
307  Q_EMIT valueChanged();
308  }
309  delete dlg;
310  }
311 }
312 
313 void SieveScriptListBox::slotTop()
314 {
315  QListWidgetItem *item = mSieveListScript->currentItem();
316  if (item) {
317  const int currentIndex = mSieveListScript->currentRow();
318  if (currentIndex != 0) {
319  item = mSieveListScript->takeItem(currentIndex);
320  mSieveListScript->insertItem(0, item);
321  mSieveListScript->setCurrentItem(item);
322  Q_EMIT valueChanged();
323  }
324  }
325 }
326 
327 void SieveScriptListBox::slotBottom()
328 {
329  QListWidgetItem *item = mSieveListScript->currentItem();
330  if (item) {
331  const int currentIndex = mSieveListScript->currentRow();
332  if (currentIndex != mSieveListScript->count() - 1) {
333  item = mSieveListScript->takeItem(currentIndex);
334  mSieveListScript->insertItem(mSieveListScript->count(), item);
335  mSieveListScript->setCurrentItem(item);
336  Q_EMIT valueChanged();
337  }
338  }
339 }
340 
341 void SieveScriptListBox::slotDown()
342 {
343  QListWidgetItem *item = mSieveListScript->currentItem();
344  if (item) {
345  const int currentIndex = mSieveListScript->currentRow();
346  if (currentIndex < mSieveListScript->count() - 1) {
347  item = mSieveListScript->takeItem(currentIndex);
348  mSieveListScript->insertItem(currentIndex + 1, item);
349  mSieveListScript->setCurrentItem(item);
350  Q_EMIT valueChanged();
351  }
352  }
353 }
354 
355 void SieveScriptListBox::slotUp()
356 {
357  QListWidgetItem *item = mSieveListScript->currentItem();
358  if (item) {
359  const int currentIndex = mSieveListScript->currentRow();
360  if (currentIndex >= 1) {
361  item = mSieveListScript->takeItem(currentIndex);
362  mSieveListScript->insertItem(currentIndex - 1, item);
363  mSieveListScript->setCurrentItem(item);
364  Q_EMIT valueChanged();
365  }
366  }
367 }
368 
369 QString SieveScriptListBox::generatedScript(QStringList &requireModules) const
370 {
371  QString resultScript;
372  QStringList lstRequires;
373  const int numberOfScripts(mSieveListScript->count());
374  for (int i = 0; i < numberOfScripts; ++i) {
375  SieveScriptListItem *item = static_cast<SieveScriptListItem *>(mSieveListScript->item(i));
376  if (i != 0) {
377  resultScript += QLatin1String("\n\n");
378  }
379  resultScript += QLatin1Char('#') + defaultScriptName() + item->text() + QLatin1Char('\n');
380  resultScript += item->generatedScript(lstRequires);
381  }
382  if (!resultScript.isEmpty()) {
383  resultScript += QLatin1Char('\n');
384  }
385 
386  QStringList endRequires;
387  for (const QString &r : qAsConst(lstRequires)) {
388  if (!endRequires.contains(r)) {
389  endRequires.append(r);
390  requireModules += QStringLiteral("require \"%1\";").arg(r);
391  }
392  }
393 
394  return resultScript;
395 }
396 
397 void SieveScriptListBox::clear()
398 {
399  mScriptNumber = 0;
400  Q_EMIT enableButtonOk(false);
401  //Clear tabpage
402  mSieveListScript->clear();
403  updateButtons();
404 }
405 
406 void SieveScriptListBox::loadScript(const QString &doc, QString &error)
407 {
408  clear();
409  QXmlStreamReader streamReader(doc);
410  if (streamReader.readNextStartElement()) {
411  if (streamReader.name() == QLatin1String("script")) {
412  SieveScriptPage *currentPage = nullptr;
413  ParseSieveScriptTypeBlock typeBlock = TypeUnknown;
414  loadBlock(streamReader, currentPage, typeBlock, error);
415  }
416  }
417 }
418 
419 void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *currentPage, ParseSieveScriptTypeBlock typeBlock, QString &error)
420 {
421  QString scriptName;
422  QString comment;
423  bool hasCreatedAIfBlock = false;
424  bool previousElementWasAComment = false;
425  while (n.readNextStartElement()) {
426  const QStringRef tagName = n.name();
427  //qDebug() <<"SieveScriptListBox::loadBlock tagName " << tagName;
428  if (tagName == QLatin1String("control")) {
429  previousElementWasAComment = false;
430  //Create a new page when before it was "onlyactions"
431  if (typeBlock == TypeBlockAction) {
432  currentPage = nullptr;
433  }
434  if (n.attributes().hasAttribute(QLatin1String("name"))) {
435  const QString controlType = n.attributes().value(QLatin1String("name")).toString();
436  //qCDebug(LIBKSIEVE_LOG)<<" controlType"<<controlType;
437  if (controlType == QLatin1String("if")) {
438  typeBlock = TypeBlockIf;
439  if (!currentPage || hasCreatedAIfBlock) {
440  currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
441  }
442  hasCreatedAIfBlock = true;
443  comment.clear();
444  currentPage->blockIfWidget()->loadScript(n, false, error);
445  } else if (controlType == QLatin1String("elsif")) {
446  typeBlock = TypeBlockElsif;
447  if (!currentPage) {
448  qCDebug(LIBKSIEVE_LOG) << " script is not correct missing if block";
449  currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
450  }
451  SieveScriptBlockWidget *blockWidget = currentPage->addScriptBlock(KSieveUi::SieveWidgetPageAbstract::BlockElsIf);
452  if (blockWidget) {
453  blockWidget->loadScript(n, false, error);
454  }
455  } else if (controlType == QLatin1String("else")) {
456  typeBlock = TypeBlockElse;
457  if (!currentPage) {
458  currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
459  qCDebug(LIBKSIEVE_LOG) << " script is not correct missing if block";
460  }
461  SieveScriptBlockWidget *blockWidget = currentPage->addScriptBlock(KSieveUi::SieveWidgetPageAbstract::BlockElse);
462  if (blockWidget) {
463  blockWidget->loadScript(n, false, error);
464  }
465  //We are sure that we can't have another elsif
466  currentPage = nullptr;
467  } else if (controlType == QLatin1String("foreverypart")) {
468  typeBlock = TypeBlockForeachBlock;
469  if (!currentPage) {
470  currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
471  comment.clear();
472  }
473  if (currentPage->forEveryPartWidget()) {
474  currentPage->forEveryPartWidget()->loadScript(n, error);
475  } else {
476  error += i18n("forEveryPart is not supported by your server") + QLatin1Char('\n');
477  }
478  //TODO verify it.
479 #ifdef QDOMELEMENT_FIXME
480  QDomNode block = e.firstChildElement(QStringLiteral("block")).firstChild();
481  loadBlock(block, currentPage, typeBlock, error);
482 #endif
483  } else if (controlType == QLatin1String("require")) {
484  n.skipCurrentElement();
485  //Nothing. autogenerated
486  } else {
487  qCDebug(LIBKSIEVE_LOG) << " unknown controlType :" << controlType;
488  }
489  }
490  } else if (tagName == QLatin1String("comment")) {
491  previousElementWasAComment = true;
492 #ifdef FIXME_COMMENT
493  if (e.hasAttribute(QStringLiteral("hash"))) {
494  //TODO
495  } else if (e.hasAttribute(QStringLiteral("bracket"))) {
496  //TODO
497  }
498 #endif
499  QString str(n.readElementText());
500  if (str.contains(defaultScriptName())) {
501  scriptName = str.remove(defaultScriptName());
502  } else {
503  if (!comment.isEmpty()) {
504  comment += QLatin1Char('\n');
505  }
506  comment += str;
507  }
508  //qDebug() << " COMMENT " << comment;
509  } else if (tagName == QLatin1String("action")) {
510  previousElementWasAComment = false;
511  if (n.attributes().hasAttribute(QLatin1String("name"))) {
512  const QString actionName = n.attributes().value(QLatin1String("name")).toString();
513  if (actionName == QLatin1String("include")) {
514  if (!currentPage || (typeBlock == TypeBlockIf) || (typeBlock == TypeBlockElse) || (typeBlock == TypeBlockElsif)) {
515  currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
516  comment.clear();
517  }
518  typeBlock = TypeBlockInclude;
519  if (currentPage->includeWidget()) {
520  currentPage->includeWidget()->loadScript(n, error);
521  } else {
522  qCDebug(LIBKSIEVE_LOG) << " include not supported";
523  }
524  } else if (actionName == QLatin1String("global")) {
525  if (!currentPage || (typeBlock == TypeBlockIf) || (typeBlock == TypeBlockElse) || (typeBlock == TypeBlockElsif)) {
526  currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
527  comment.clear();
528  }
529  typeBlock = TypeBlockGlobal;
530  if (currentPage->globalVariableWidget()) {
531  currentPage->globalVariableWidget()->loadScript(n, error);
532  } else {
533  qCDebug(LIBKSIEVE_LOG) << " globalVariable not supported";
534  }
535  } else if (actionName == QLatin1String("set") && (typeBlock == TypeBlockGlobal)) {
536  //FIXME global not global variable.
537  if (currentPage->globalVariableWidget()) {
538  const SieveGlobalVariableActionWidget::VariableElement var = currentPage->globalVariableWidget()->loadSetVariable(n, error);
539  if (var.isValid()) {
540  qCDebug(LIBKSIEVE_LOG) << "It's not a global variable";
541  if ((typeBlock == TypeBlockIf) || (typeBlock == TypeBlockElse) || (typeBlock == TypeBlockElsif)) {
542  currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
543  }
544  typeBlock = TypeBlockAction;
545  comment.clear();
546  currentPage->blockIfWidget()->loadLocalVariable(var);
547  }
548  } else {
549  qCDebug(LIBKSIEVE_LOG) << " set not supported";
550  }
551  } else {
552  if (!currentPage || (typeBlock == TypeBlockIf) || (typeBlock == TypeBlockElse) || (typeBlock == TypeBlockElsif)) {
553  currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
554  }
555  typeBlock = TypeBlockAction;
556  comment.clear();
557  currentPage->blockIfWidget()->loadScript(n, true, error);
558  }
559  }
560  } else if (tagName == QLatin1String("crlf")) {
561  //If it was a comment previously you will create a \n
562  if (previousElementWasAComment) {
563  comment += QLatin1Char('\n');
564  }
565  n.skipCurrentElement();
566  } else {
567  qCDebug(LIBKSIEVE_LOG) << " unknown tagname" << tagName;
568  }
569  }
570 }
571 
572 QString SieveScriptListBox::createUniqName()
573 {
574  const QString pattern = i18n("Script part %1", mScriptNumber);
575  ++mScriptNumber;
576  return pattern;
577 }
QLayout * layout() const const
void customContextMenuRequested(const QPoint &pos)
void triggered(bool checked)
bool readNextStartElement()
void setContentsMargins(int left, int top, int right, int bottom)
QString toString() const const
void setIcon(const QIcon &icon)
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
QPoint mapToGlobal(const QPoint &pos) const const
QStringRef value(const QString &namespaceUri, const QString &name) const const
QString & remove(int position, int n)
CustomContextMenu
void clear()
void skipCurrentElement()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
int count(const T &value) const const
void append(const T &value)
QString pattern(Mode mode=Reading)
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
bool isEmpty() const const
void setObjectName(const QString &name)
bool isEmpty() const const
QString trimmed() const const
void clicked(bool checked)
QPoint pos() const const
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 hasAttribute(const QString &qualifiedName) const const
QString i18n(const char *text, const TYPE &arg...)
QDomNode firstChild() const const
QDomElement firstChildElement(const QString &tagName) const const
QWidget(QWidget *parent, Qt::WindowFlags f)
QXmlStreamAttributes attributes() const const
void itemActivated(QListWidgetItem *item)
QIcon fromTheme(const QString &name)
void itemSelectionChanged()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QStringRef name() const const
QString text() const const
void setSpacing(int spacing)
Q_EMITQ_EMIT
void itemDoubleClicked(QListWidgetItem *item)
void setText(const QString &text)
ButtonCode warningYesNo(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Options(Notify|Dangerous))
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jul 14 2020 23:08:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.