Libksieve

sieveeditortextmodewidget.cpp
1 /* Copyright (C) 2013-2020 Laurent Montel <[email protected]>
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Library General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public License
14  * along with this library; see the file COPYING.LIB. If not, write to
15  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  * Boston, MA 02110-1301, USA.
17  */
18 
19 #include "sieveeditortextmodewidget.h"
20 #include "templates/sievetemplatewidget.h"
21 #include "autocreatescripts/autocreatescriptdialog.h"
22 #include "editor/sievetextedit.h"
23 #include "editor/warningwidget/sieveeditorwarning.h"
24 #include "editor/warningwidget/sieveeditorparsingmissingfeaturewarning.h"
25 #include "editor/sieveeditortabwidget.h"
26 #include "sievescriptdebugger/sievescriptdebuggerdialog.h"
27 
28 #include "scriptsparsing/xmlprintingscriptbuilder.h"
29 #include "scriptsparsing/parsingresultdialog.h"
30 
31 #include <KPIMTextEdit/PlainTextEditFindBar>
32 #include <KPIMTextEdit/PlainTextEditorWidget>
33 #include <KPIMTextEdit/TextToSpeechWidget>
34 #include <KPIMTextEdit/TextGotoLineWidget>
35 #include "KSplitterCollapserButton"
36 #include "webengine/sieveeditorhelphtmlwidget.h"
37 #include <KPIMTextEdit/SlideContainer>
38 
39 #include <ksieve/parser.h>
40 #include <ksieve/error.h>
41 #include <ksieve/scriptbuilder.h>
42 
43 #include <KLocalizedString>
44 #include <KSharedConfig>
45 #include <KConfigGroup>
46 #include <KMessageBox>
47 
48 #include <QSplitter>
49 #include <QShortcut>
50 #include <QPointer>
51 #include <QPushButton>
52 #include <QVBoxLayout>
53 #include <QPrinter>
54 #include <QPrintDialog>
55 #include <PimCommon/KPimPrintPreviewDialog>
56 
57 #include <errno.h>
58 #include <memory>
59 
60 using namespace KSieveUi;
61 
62 SieveEditorTextModeWidget::SieveEditorTextModeWidget(QWidget *parent)
63  : SieveEditorAbstractWidget(parent)
64 {
65  QVBoxLayout *lay = new QVBoxLayout(this);
66  lay->setContentsMargins(0, 0, 0, 0);
67 
68  mMainSplitter = new QSplitter;
69  mMainSplitter->setOrientation(Qt::Vertical);
70  lay->addWidget(mMainSplitter);
71 
72  mTemplateSplitter = new QSplitter;
73  mTemplateSplitter->setOrientation(Qt::Horizontal);
74  //
75  mSieveTemplateWidget = new SieveTemplateWidget(i18n("Sieve Template:"));
76 
77  QWidget *textEditWidget = new QWidget;
78  QVBoxLayout *textEditLayout = new QVBoxLayout;
79  textEditLayout->setContentsMargins(0, 0, 0, 0);
80 
81  mEditorWidget = new QWidget;
82  QVBoxLayout *editorWidgetLayout = new QVBoxLayout;
83  editorWidgetLayout->setContentsMargins(0, 0, 0, 0);
84  mEditorWidget->setLayout(editorWidgetLayout);
85 
86  mTabWidget = new SieveEditorTabWidget;
87  connect(mTabWidget, &SieveEditorTabWidget::currentChanged, this, &SieveEditorTextModeWidget::sieveEditorTabCurrentChanged);
88  connect(mTabWidget, &SieveEditorTabWidget::copyAvailable, this, &SieveEditorTextModeWidget::copyAvailable);
89  mTextToSpeechWidget = new KPIMTextEdit::TextToSpeechWidget(this);
90  editorWidgetLayout->addWidget(mTextToSpeechWidget);
91 
92  mTextEdit = new SieveTextEdit;
93  editorWidgetLayout->addWidget(mTextEdit);
94  connect(mTextEdit, &SieveTextEdit::textChanged, this, &SieveEditorTextModeWidget::valueChanged);
95  mTabWidget->addTab(mEditorWidget, i18n("Editor"));
96  mTabWidget->tabBar()->hide();
97  textEditLayout->addWidget(mTabWidget);
98  connect(mTextEdit, &SieveTextEdit::openHelp, mTabWidget, &SieveEditorTabWidget::slotAddHelpPage);
99  connect(mTextEdit, &SieveTextEdit::say, mTextToSpeechWidget, &KPIMTextEdit::TextToSpeechWidget::say);
100  connect(mTextEdit, &SieveTextEdit::editRule, this, &SieveEditorTextModeWidget::slotEditRule);
101  connect(mTextEdit, &SieveTextEdit::insertRule, this, &SieveEditorTextModeWidget::slotInsertRule);
102 
103  mGotoLineSliderContainer = new KPIMTextEdit::SlideContainer(this);
104  mGoToLine = new KPIMTextEdit::TextGoToLineWidget;
105  mGoToLine->hide();
106  mGotoLineSliderContainer->setContent(mGoToLine);
107  editorWidgetLayout->addWidget(mGotoLineSliderContainer);
108  connect(mGoToLine, &KPIMTextEdit::TextGoToLineWidget::hideGotoLine, mGotoLineSliderContainer, &KPIMTextEdit::SlideContainer::slideOut);
109 
110  connect(mGoToLine, &KPIMTextEdit::TextGoToLineWidget::moveToLine, this, &SieveEditorTextModeWidget::slotGoToLine);
111  connect(mTextEdit, &SieveTextEdit::blockCountChanged, mGoToLine, &KPIMTextEdit::TextGoToLineWidget::slotBlockCountChanged);
112 
113  mSliderContainer = new KPIMTextEdit::SlideContainer(this);
114  mFindBar = new KPIMTextEdit::PlainTextEditFindBar(mTextEdit, textEditWidget);
115  mFindBar->setHideWhenClose(false);
116  connect(mFindBar, &KPIMTextEdit::TextEditFindBarBase::hideFindBar, mSliderContainer, &KPIMTextEdit::SlideContainer::slideOut);
117  connect(mFindBar, &KPIMTextEdit::TextEditFindBarBase::displayMessageIndicator, mTextEdit, &KPIMTextEdit::PlainTextEditor::slotDisplayMessageIndicator);
118  mSliderContainer->setContent(mFindBar);
119  editorWidgetLayout->addWidget(mSliderContainer);
120 
121  mSieveEditorWarning = new SieveEditorWarning;
122  editorWidgetLayout->addWidget(mSieveEditorWarning);
123 
124  mSieveParsingWarning = new SieveEditorParsingMissingFeatureWarning(SieveEditorParsingMissingFeatureWarning::TextEditor);
125  connect(mSieveParsingWarning, &SieveEditorParsingMissingFeatureWarning::switchToGraphicalMode, this, &SieveEditorTextModeWidget::switchToGraphicalMode);
126  editorWidgetLayout->addWidget(mSieveParsingWarning);
127 
128  textEditWidget->setLayout(textEditLayout);
129 
130  mTemplateSplitter->addWidget(textEditWidget);
131  mTemplateSplitter->addWidget(mSieveTemplateWidget);
132  mTemplateSplitter->setCollapsible(0, false);
133  new KSplitterCollapserButton(mSieveTemplateWidget, mTemplateSplitter);
134 
135  connect(mSieveTemplateWidget, &SieveTemplateWidget::insertTemplate, mTextEdit, &SieveTextEdit::insertPlainText);
136 
137  //
138  connect(mTextEdit, &SieveTextEdit::findText, this, &SieveEditorTextModeWidget::slotFind);
139  connect(mTextEdit, &SieveTextEdit::replaceText, this, &SieveEditorTextModeWidget::slotReplace);
140 
141  mDebugTextEdit = new KPIMTextEdit::PlainTextEditorWidget;
142  mDebugTextEdit->editor()->setSearchSupport(false);
143  mDebugTextEdit->editor()->setReadOnly(true);
144  mDebugTextEdit->editor()->setPlaceholderText(i18n("Show result from \"check syntax\""));
145  mMainSplitter->addWidget(mTemplateSplitter);
146  mMainSplitter->addWidget(mDebugTextEdit);
147  mMainSplitter->setChildrenCollapsible(false);
148 
149  connect(mTextEdit, &SieveTextEdit::textChanged, this, &SieveEditorTextModeWidget::slotTextChanged);
150  connect(mTextEdit, &SieveTextEdit::undoAvailable, this, &SieveEditorTextModeWidget::undoAvailable);
151  connect(mTextEdit, &SieveTextEdit::redoAvailable, this, &SieveEditorTextModeWidget::redoAvailable);
152  connect(mTextEdit, &SieveTextEdit::copyAvailable, this, &SieveEditorTextModeWidget::copyAvailable);
153  readConfig();
154 
155  mTextEdit->setFocus();
156 }
157 
158 SieveEditorTextModeWidget::~SieveEditorTextModeWidget()
159 {
160  disconnect(mTextEdit, &SieveTextEdit::textChanged, this, &SieveEditorTextModeWidget::slotTextChanged);
161  disconnect(mTextEdit, &SieveTextEdit::textChanged, this, &SieveEditorTextModeWidget::valueChanged);
162  writeConfig();
163 }
164 
165 void SieveEditorTextModeWidget::writeConfig()
166 {
167  KConfigGroup group(KSharedConfig::openConfig(), "SieveEditor");
168  group.writeEntry("mainSplitter", mMainSplitter->sizes());
169  group.writeEntry("templateSplitter", mTemplateSplitter->sizes());
170 }
171 
172 QStringList SieveEditorTextModeWidget::sieveCapabilities() const
173 {
174  return mSieveCapabilities;
175 }
176 
177 SieveEditorTabWidget *SieveEditorTextModeWidget::tabWidget() const
178 {
179  return mTabWidget;
180 }
181 
182 void SieveEditorTextModeWidget::readConfig()
183 {
184  KConfigGroup group(KSharedConfig::openConfig(), "SieveEditor");
185  const QList<int> size = {400, 100};
186 
187  mMainSplitter->setSizes(group.readEntry("mainSplitter", size));
188  mTemplateSplitter->setSizes(group.readEntry("templateSplitter", size));
189 }
190 
191 void SieveEditorTextModeWidget::slotGoToLine(int line)
192 {
193  if (line > 0) {
194  QTextCursor cursor = mTextEdit->textCursor();
195  cursor.beginEditBlock();
196  cursor.movePosition(QTextCursor::Start);
197  cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, (line - 1));
198  cursor.endEditBlock();
199  mTextEdit->setTextCursor(cursor);
200  mTextEdit->setFocus();
201  }
202 }
203 
204 void SieveEditorTextModeWidget::slotShowGoToLine()
205 {
206  mGoToLine->setMaximumLineCount(mTextEdit->document()->blockCount());
207  mGotoLineSliderContainer->slideIn();
208  mGoToLine->goToLine();
209 }
210 
211 void SieveEditorTextModeWidget::generateXml()
212 {
213  const QByteArray script = mTextEdit->toPlainText().toUtf8();
214  KSieve::Parser parser(script.begin(),
215  script.begin() + script.length());
216  KSieveUi::XMLPrintingScriptBuilder psb(2);
217  parser.setScriptBuilder(&psb);
218  const bool result = parser.parse();
219  QPointer<ParsingResultDialog> dlg = new ParsingResultDialog(this);
220  if (result) {
221  dlg->setResultParsing(psb.result());
222  } else {
223  dlg->setResultParsing(i18n("Error during parsing"));
224  }
225  dlg->exec();
226  delete dlg;
227 }
228 
229 void SieveEditorTextModeWidget::slotEditRule(const QString &selectedText)
230 {
231  const QByteArray script = selectedText.toUtf8();
232  KSieve::Parser parser(script.begin(),
233  script.begin() + script.length());
234  KSieveUi::XMLPrintingScriptBuilder psb(2);
235  parser.setScriptBuilder(&psb);
236  const bool result = parser.parse();
237  if (result) {
239  dlg->setSieveCapabilities(mSieveCapabilities);
240  dlg->setSieveImapAccountSettings(mSieveImapAccountSettings);
241  dlg->setListOfIncludeFile(mListOfIncludeFile);
242  QString error;
243  //qDebug() << " psb.result()" << psb.result();
244  dlg->loadScript(psb.result(), error);
245  if (dlg->exec()) {
246  QStringList requireModules;
247  const QString newScript = dlg->script(requireModules);
248  const QStringList needToAddRequire = insertNecessaryRequires(requireModules);
249  mTextEdit->insertPlainText(newScript);
250  insertRequires(needToAddRequire);
251  }
252  delete dlg;
253  } else {
254  KMessageBox::error(this, i18n("Selected text is not a full sieve script"), i18n("Parsing error"));
255  }
256 }
257 
258 void SieveEditorTextModeWidget::insertRequires(const QStringList &needToAddRequire)
259 {
260  if (!needToAddRequire.isEmpty()) {
261  QTextCursor textCursor = mTextEdit->textCursor();
262  textCursor.movePosition(QTextCursor::MoveOperation::Start);
263  textCursor.insertText(needToAddRequire.join(QLatin1Char('\n')) + QLatin1Char('\n'));
264  }
265 }
266 
267 QStringList SieveEditorTextModeWidget::insertNecessaryRequires(const QStringList &requireModules)
268 {
269  QStringList needToAddRequire;
270  const QString plainText = mTextEdit->toPlainText();
271  for (const QString &module : qAsConst(requireModules)) {
272  if (!plainText.contains(module)) {
273  needToAddRequire.append(module);
274  }
275  }
276  return needToAddRequire;
277 }
278 
279 void SieveEditorTextModeWidget::slotInsertRule()
280 {
282  dlg->setSieveCapabilities(mSieveCapabilities);
283  dlg->setSieveImapAccountSettings(mSieveImapAccountSettings);
284  dlg->setListOfIncludeFile(mListOfIncludeFile);
285  if (dlg->exec()) {
286  QStringList requireModules;
287  const QString newScript = dlg->script(requireModules);
288  const QStringList needToAddRequire = insertNecessaryRequires(requireModules);
289  mTextEdit->insertPlainText(newScript);
290  insertRequires(needToAddRequire);
291  }
292  delete dlg;
293 }
294 
295 void SieveEditorTextModeWidget::createRulesGraphically()
296 {
298  dlg->setSieveCapabilities(mSieveCapabilities);
299  dlg->setSieveImapAccountSettings(mSieveImapAccountSettings);
300  dlg->setListOfIncludeFile(mListOfIncludeFile);
301  if (dlg->exec()) {
302  QStringList requireModules;
303  const QString script = dlg->script(requireModules);
304  const QStringList needToAddRequire = insertNecessaryRequires(requireModules);
305  QString newPlainText = mTextEdit->toPlainText() + script;
306  if (!needToAddRequire.isEmpty()) {
307  newPlainText.prepend(requireModules.join(QLatin1Char('\n')) + QLatin1Char('\n'));
308  }
309  mTextEdit->selectAll();
310 
311  mTextEdit->insertPlainText(newPlainText);
312  }
313  delete dlg;
314 }
315 
316 void SieveEditorTextModeWidget::find()
317 {
318  slotFind();
319 }
320 
321 void SieveEditorTextModeWidget::replace()
322 {
323  slotReplace();
324 }
325 
326 void SieveEditorTextModeWidget::undo()
327 {
328  const QWidget *w = mTabWidget->currentWidget();
329  if (w == mEditorWidget) {
330  mTextEdit->undo();
331  }
332 }
333 
334 void SieveEditorTextModeWidget::redo()
335 {
336  const QWidget *w = mTabWidget->currentWidget();
337  if (w == mEditorWidget) {
338  mTextEdit->redo();
339  }
340 }
341 
342 void SieveEditorTextModeWidget::paste()
343 {
344  const QWidget *w = mTabWidget->currentWidget();
345  if (w == mEditorWidget) {
346  mTextEdit->paste();
347  }
348 }
349 
350 void SieveEditorTextModeWidget::cut()
351 {
352  const QWidget *w = mTabWidget->currentWidget();
353  if (w == mEditorWidget) {
354  mTextEdit->cut();
355  }
356 }
357 
358 void SieveEditorTextModeWidget::copy()
359 {
360  QWidget *w = mTabWidget->currentWidget();
361  if (w == mEditorWidget) {
362  mTextEdit->copy();
363  } else if (SieveEditorHelpHtmlWidget *page = qobject_cast<SieveEditorHelpHtmlWidget *>(w)) {
364  page->copy();
365  }
366 }
367 
368 void SieveEditorTextModeWidget::selectAll()
369 {
370  QWidget *w = mTabWidget->currentWidget();
371  if (w == mEditorWidget) {
372  mTextEdit->selectAll();
373  } else if (SieveEditorHelpHtmlWidget *page = qobject_cast<SieveEditorHelpHtmlWidget *>(w)) {
374  page->selectAll();
375  }
376 }
377 
378 bool SieveEditorTextModeWidget::isUndoAvailable() const
379 {
380  const QWidget *w = mTabWidget->currentWidget();
381  if (w == mEditorWidget) {
382  return mTextEdit->document()->isUndoAvailable();
383  }
384  return false;
385 }
386 
387 bool SieveEditorTextModeWidget::isRedoAvailable() const
388 {
389  const QWidget *w = mTabWidget->currentWidget();
390  if (w == mEditorWidget) {
391  return mTextEdit->document()->isRedoAvailable();
392  }
393  return false;
394 }
395 
396 bool SieveEditorTextModeWidget::hasSelection() const
397 {
398  QWidget *w = mTabWidget->currentWidget();
399  if (w == mEditorWidget) {
400  return mTextEdit->textCursor().hasSelection();
401  } else if (SieveEditorHelpHtmlWidget *page = qobject_cast<SieveEditorHelpHtmlWidget *>(w)) {
402  return page->hasSelection();
403  }
404  return false;
405 }
406 
407 void SieveEditorTextModeWidget::zoomIn()
408 {
409  QWidget *w = mTabWidget->currentWidget();
410  if (w == mEditorWidget) {
411  mTextEdit->zoomIn();
412  } else if (SieveEditorHelpHtmlWidget *page = qobject_cast<SieveEditorHelpHtmlWidget *>(w)) {
413  page->zoomIn();
414  }
415 }
416 
417 void SieveEditorTextModeWidget::zoomOut()
418 {
419  QWidget *w = mTabWidget->currentWidget();
420  if (w == mEditorWidget) {
421  mTextEdit->zoomOut();
422  } else if (SieveEditorHelpHtmlWidget *page = qobject_cast<SieveEditorHelpHtmlWidget *>(w)) {
423  page->zoomOut();
424  }
425 }
426 
427 bool SieveEditorTextModeWidget::isWordWrap() const
428 {
429  return mTextEdit->isWordWrap();
430 }
431 
432 void SieveEditorTextModeWidget::print()
433 {
434  const QWidget *w = mTabWidget->currentWidget();
435  if (w == mEditorWidget) {
436  QPrinter printer;
437 
438  std::unique_ptr<QPrintDialog> dlg(new QPrintDialog(&printer));
439 
440  bool restoreSpellCheck = mTextEdit->checkSpellingEnabled();
441  mTextEdit->setCheckSpellingEnabled(false);
442  if (dlg && dlg->exec() == QDialog::Accepted) {
443  mTextEdit->print(&printer);
444  }
445  mTextEdit->setCheckSpellingEnabled(restoreSpellCheck);
446  }
447 }
448 
449 void SieveEditorTextModeWidget::printPreview()
450 {
451  const QWidget *w = mTabWidget->currentWidget();
452  if (w == mEditorWidget) {
453  bool restoreSpellCheck = mTextEdit->checkSpellingEnabled();
454  mTextEdit->setCheckSpellingEnabled(false);
456  connect(previewdlg.data(), &QPrintPreviewDialog::paintRequested, this, [this](QPrinter *printer) {
457  mTextEdit->print(printer);
458  });
459  previewdlg->exec();
460  delete previewdlg;
461  mTextEdit->setCheckSpellingEnabled(restoreSpellCheck);
462  }
463 }
464 
465 void SieveEditorTextModeWidget::wordWrap(bool state)
466 {
467  mTextEdit->wordWrap(state);
468 }
469 
470 void SieveEditorTextModeWidget::zoomReset()
471 {
472  QWidget *w = mTabWidget->currentWidget();
473  if (w == mEditorWidget) {
474  mTextEdit->slotZoomReset();
475  } else if (SieveEditorHelpHtmlWidget *page = qobject_cast<SieveEditorHelpHtmlWidget *>(w)) {
476  page->resetZoom();
477  }
478 }
479 
480 void SieveEditorTextModeWidget::slotFind()
481 {
482  QWidget *w = mTabWidget->currentWidget();
483  if (w == mEditorWidget) {
484  if (mTextEdit->textCursor().hasSelection()) {
485  mFindBar->setText(mTextEdit->textCursor().selectedText());
486  }
487  mTextEdit->moveCursor(QTextCursor::Start);
488  mFindBar->showFind();
489  mSliderContainer->slideIn();
490  mFindBar->focusAndSetCursor();
491  } else if (SieveEditorHelpHtmlWidget *page = qobject_cast<SieveEditorHelpHtmlWidget *>(w)) {
492  page->find();
493  }
494 }
495 
496 void SieveEditorTextModeWidget::slotReplace()
497 {
498  if (mTextEdit->textCursor().hasSelection()) {
499  mFindBar->setText(mTextEdit->textCursor().selectedText());
500  }
501  mFindBar->showReplace();
502  mSliderContainer->slideIn();
503  mFindBar->focusAndSetCursor();
504 }
505 
506 QString SieveEditorTextModeWidget::currentscript()
507 {
508  return mTextEdit->toPlainText();
509 }
510 
511 void SieveEditorTextModeWidget::setImportScript(const QString &script)
512 {
513  mTextEdit->selectAll();
514  mTextEdit->insertPlainText(script);
515 }
516 
517 void SieveEditorTextModeWidget::slotTextChanged()
518 {
519  const bool enabled = !script().isEmpty();
520  Q_EMIT enableButtonOk(enabled);
521 }
522 
523 QString SieveEditorTextModeWidget::script() const
524 {
525  return mTextEdit->toPlainText();
526 }
527 
528 void SieveEditorTextModeWidget::setScript(const QString &script, bool clearUndoRedo)
529 {
530  if (clearUndoRedo) {
531  mTextEdit->setPlainText(script);
532  } else {
533  mTextEdit->selectAll();
534  mTextEdit->insertPlainText(script);
535  }
536 }
537 
538 void SieveEditorTextModeWidget::setDebugScript(const QString &debug)
539 {
540  mDebugTextEdit->editor()->clear();
541  mDebugTextEdit->editor()->appendHtml(debug);
542 }
543 
544 void SieveEditorTextModeWidget::setListOfIncludeFile(const QStringList &listOfIncludeFile)
545 {
546  mListOfIncludeFile = listOfIncludeFile;
547 }
548 
549 void SieveEditorTextModeWidget::setSieveCapabilities(const QStringList &capabilities)
550 {
551  mSieveCapabilities = capabilities;
552  mTextEdit->setSieveCapabilities(mSieveCapabilities);
553  mSieveTemplateWidget->setSieveCapabilities(mSieveCapabilities);
554 }
555 
556 void SieveEditorTextModeWidget::showEditorWarning()
557 {
558  mSieveEditorWarning->animatedShow();
559 }
560 
561 void SieveEditorTextModeWidget::hideEditorWarning()
562 {
563  mSieveEditorWarning->animatedHide();
564  mSieveParsingWarning->animatedHide();
565 }
566 
567 void SieveEditorTextModeWidget::showParsingEditorWarning()
568 {
569  mSieveParsingWarning->animatedShow();
570 }
571 
572 void SieveEditorTextModeWidget::setParsingEditorWarningError(const QString &script, const QString &error)
573 {
574  mSieveParsingWarning->setErrors(script, error);
575 }
576 
577 void SieveEditorTextModeWidget::checkSpelling()
578 {
579  mTextEdit->slotCheckSpelling();
580 }
581 
582 void SieveEditorTextModeWidget::comment()
583 {
584  mTextEdit->comment();
585 }
586 
587 void SieveEditorTextModeWidget::uncomment()
588 {
589  mTextEdit->uncomment();
590 }
591 
592 void SieveEditorTextModeWidget::setReadOnly(bool b)
593 {
594  mTextEdit->setReadOnly(b);
595 }
596 
597 void SieveEditorTextModeWidget::upperCase()
598 {
599  mTextEdit->upperCase();
600 }
601 
602 void SieveEditorTextModeWidget::lowerCase()
603 {
604  mTextEdit->lowerCase();
605 }
606 
607 void SieveEditorTextModeWidget::sentenceCase()
608 {
609  mTextEdit->sentenceCase();
610 }
611 
612 void SieveEditorTextModeWidget::reverseCase()
613 {
614  mTextEdit->reverseCase();
615 }
616 
617 QString SieveEditorTextModeWidget::currentHelpTitle() const
618 {
619  return mTabWidget->currentHelpTitle();
620 }
621 
622 QUrl SieveEditorTextModeWidget::currentHelpUrl() const
623 {
624  return mTabWidget->currentHelpUrl();
625 }
626 
627 void SieveEditorTextModeWidget::openBookmarkUrl(const QUrl &url)
628 {
629  mTabWidget->slotAddHelpPage(url);
630 }
631 
632 void SieveEditorTextModeWidget::debugSieveScript()
633 {
634  QPointer<KSieveUi::SieveScriptDebuggerDialog> dlg = new KSieveUi::SieveScriptDebuggerDialog(this);
635  dlg->setScript(mTextEdit->toPlainText());
636  if (dlg->exec()) {
637  const QString script = dlg->script();
638  mTextEdit->selectAll();
639  mTextEdit->insertPlainText(script);
640  }
641  delete dlg;
642 }
643 
644 bool SieveEditorTextModeWidget::isTextEditor() const
645 {
646  const QWidget *w = mTabWidget->currentWidget();
647  return w == mEditorWidget;
648 }
649 
650 bool SieveEditorTextModeWidget::printSupportEnabled() const
651 {
652  return isTextEditor();
653 }
void redoAvailable(bool available)
void copyAvailable(bool yes)
void setContentsMargins(int left, int top, int right, int bottom)
T * data() const const
QCursor cursor() const const
void textChanged()
QString & prepend(QChar ch)
The AutoCreateScriptDialog class.
QString join(const QString &separator) const const
int length() const const
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
The SieveTextEdit class.
Definition: sievetextedit.h:33
bool movePosition(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode, int n)
void setOrientation(Qt::Orientation)
void clear()
QSize size() const const
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void append(const T &value)
void setLayout(QLayout *layout)
void insertPlainText(const QString &text)
void undoAvailable(bool available)
void endEditBlock()
void insertText(const QString &text)
bool isEmpty() const const
void currentChanged(int index)
bool isEmpty() const const
void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
QByteArray::iterator begin()
void hide()
void blockCountChanged(int newBlockCount)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
void beginEditBlock()
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QString i18n(const char *text, const TYPE &arg...)
void readConfig()
QWidget * find(WId id)
QWidget(QWidget *parent, Qt::WindowFlags f)
The SieveEditorTabWidget class.
void paintRequested(QPrinter *printer)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Parser for the Sieve grammar.
Definition: ksieve/parser.h:45
Q_EMITQ_EMIT
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 1 2020 23:08:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.