Libksieve

vacationmanager.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #include "vacationmanager.h"
8 #include "ksieveui/vacation/multiimapvacationdialog.h"
9 #include "ksieveui/vacation/multiimapvacationmanager.h"
10 #include "ksieveui/vacation/vacationcreatescriptjob.h"
11 
12 #include <KLocalizedString>
13 #include <KMessageBox>
14 #include <QPointer>
15 #include <QWidget>
16 
17 using namespace KSieveUi;
18 
19 class KSieveUi::VacationManagerPrivate
20 {
21 public:
22  VacationManagerPrivate(QWidget *parent)
23  : mWidget(parent)
24  {
25  }
26 
27  QWidget *const mWidget;
28  QPointer<KSieveUi::MultiImapVacationDialog> mMultiImapVacationDialog = nullptr;
29  QPointer<KSieveUi::MultiImapVacationManager> mCheckVacation = nullptr;
30  bool mQuestionAsked = false;
31 };
32 
33 VacationManager::VacationManager(SieveImapPasswordProvider *passwordProvider, QWidget *parent)
34  : QObject(parent)
35  , d(new KSieveUi::VacationManagerPrivate(parent))
36 {
37  d->mCheckVacation = new KSieveUi::MultiImapVacationManager(passwordProvider, this);
38  connect(d->mCheckVacation.data(), &KSieveUi::MultiImapVacationManager::scriptActive, this, &VacationManager::slotUpdateVacationScriptStatus);
39 }
40 
41 VacationManager::~VacationManager() = default;
42 
43 void VacationManager::checkVacation()
44 {
45  d->mCheckVacation->checkVacation();
46 }
47 
48 void VacationManager::slotUpdateVacationScriptStatus(bool active, const QString &serverName)
49 {
50  Q_EMIT updateVacationScriptStatus(active, serverName);
51  if (active) {
52  if (!d->mQuestionAsked) {
53  d->mQuestionAsked = true;
54  if (KMessageBox::questionYesNo(nullptr,
55  i18n("There is still an active out-of-office reply configured.\n"
56  "Do you want to edit it?"),
57  i18n("Out-of-office reply still active"),
58  KGuiItem(i18n("Edit"), QStringLiteral("document-properties")),
59  KGuiItem(i18n("Ignore"), QStringLiteral("dialog-cancel")))
60  == KMessageBox::Yes) {
61  slotEditVacation(serverName);
62  }
63  }
64  }
65 }
66 
67 void VacationManager::slotEditVacation(const QString &serverName)
68 {
69  if (d->mMultiImapVacationDialog) {
70  d->mMultiImapVacationDialog->raise();
71  d->mMultiImapVacationDialog->activateWindow();
72  } else {
73  d->mMultiImapVacationDialog = new KSieveUi::MultiImapVacationDialog(d->mCheckVacation, d->mWidget);
74  connect(d->mMultiImapVacationDialog.data(), &KSieveUi::MultiImapVacationDialog::okClicked, this, &VacationManager::slotDialogOk);
75  connect(d->mMultiImapVacationDialog.data(), &KSieveUi::MultiImapVacationDialog::cancelClicked, this, &VacationManager::slotDialogCanceled);
76  }
77  d->mMultiImapVacationDialog->show();
78 
79  if (!serverName.isEmpty()) {
80  d->mMultiImapVacationDialog->switchToServerNamePage(serverName);
81  }
82 }
83 
84 void VacationManager::slotDialogCanceled()
85 {
86  if (d->mMultiImapVacationDialog->isVisible()) {
87  d->mMultiImapVacationDialog->hide();
88  }
89 
90  d->mMultiImapVacationDialog->deleteLater();
91  d->mMultiImapVacationDialog = nullptr;
92 }
93 
94 void VacationManager::slotDialogOk()
95 {
96  const QVector<KSieveUi::VacationCreateScriptJob *> listJob = d->mMultiImapVacationDialog->listCreateJob();
97  for (KSieveUi::VacationCreateScriptJob *job : listJob) {
98  connect(job, &VacationCreateScriptJob::scriptActive, this, &VacationManager::updateVacationScriptStatus);
99  job->setKep14Support(d->mCheckVacation->kep14Support(job->serverName()));
100  job->start();
101  }
102  if (d->mMultiImapVacationDialog->isVisible()) {
103  d->mMultiImapVacationDialog->hide();
104  }
105 
106  d->mMultiImapVacationDialog->deleteLater();
107 
108  d->mMultiImapVacationDialog = nullptr;
109 }
The MultiImapVacationManager class.
The SieveImapPasswordProvider class.
bool isEmpty() const const
ButtonCode questionYesNo(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=Notify)
QString i18n(const char *text, const TYPE &arg...)
The MultiImapVacationDialog class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.