Libksieve

vacationmanager.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "vacationmanager.h"
19 #include "ksieveui/vacation/multiimapvacationmanager.h"
20 #include "ksieveui/vacation/multiimapvacationdialog.h"
21 #include "ksieveui/vacation/vacationcreatescriptjob.h"
22 
23 #include <QWidget>
24 #include <QPointer>
25 #include <KLocalizedString>
26 #include <KMessageBox>
27 
28 using namespace KSieveUi;
29 
30 class KSieveUi::VacationManagerPrivate
31 {
32 public:
33  VacationManagerPrivate(QWidget *parent)
34  : mWidget(parent)
35  {
36  }
37 
38  QWidget *mWidget = nullptr;
39  QPointer<KSieveUi::MultiImapVacationDialog> mMultiImapVacationDialog = nullptr;
40  QPointer<KSieveUi::MultiImapVacationManager> mCheckVacation = nullptr;
41  bool mQuestionAsked = false;
42 };
43 
44 VacationManager::VacationManager(SieveImapPasswordProvider *passwordProvider, QWidget *parent)
45  : QObject(parent)
46  , d(new KSieveUi::VacationManagerPrivate(parent))
47 {
48  d->mCheckVacation = new KSieveUi::MultiImapVacationManager(passwordProvider, this);
49  connect(d->mCheckVacation.data(), &KSieveUi::MultiImapVacationManager::scriptActive, this, &VacationManager::slotUpdateVacationScriptStatus);
50 }
51 
52 VacationManager::~VacationManager()
53 {
54  delete d;
55 }
56 
57 void VacationManager::checkVacation()
58 {
59  d->mCheckVacation->checkVacation();
60 }
61 
62 void VacationManager::slotUpdateVacationScriptStatus(bool active, const QString &serverName)
63 {
64  Q_EMIT updateVacationScriptStatus(active, serverName);
65  if (active) {
66  if (!d->mQuestionAsked) {
67  d->mQuestionAsked = true;
68  if (KMessageBox::questionYesNo(nullptr, i18n("There is still an active out-of-office reply configured.\n"
69  "Do you want to edit it?"), i18n("Out-of-office reply still active"),
70  KGuiItem(i18n("Edit"), QStringLiteral("document-properties")),
71  KGuiItem(i18n("Ignore"), QStringLiteral("dialog-cancel")))
72  == KMessageBox::Yes) {
73  slotEditVacation(serverName);
74  }
75  }
76  }
77 }
78 
79 void VacationManager::slotEditVacation(const QString &serverName)
80 {
81  if (d->mMultiImapVacationDialog) {
82  d->mMultiImapVacationDialog->raise();
83  d->mMultiImapVacationDialog->activateWindow();
84  } else {
85  d->mMultiImapVacationDialog = new KSieveUi::MultiImapVacationDialog(d->mCheckVacation, d->mWidget);
86  connect(d->mMultiImapVacationDialog.data(), &KSieveUi::MultiImapVacationDialog::okClicked, this, &VacationManager::slotDialogOk);
87  connect(d->mMultiImapVacationDialog.data(), &KSieveUi::MultiImapVacationDialog::cancelClicked, this, &VacationManager::slotDialogCanceled);
88  }
89  d->mMultiImapVacationDialog->show();
90 
91  if (!serverName.isEmpty()) {
92  d->mMultiImapVacationDialog->switchToServerNamePage(serverName);
93  }
94 }
95 
96 void VacationManager::slotDialogCanceled()
97 {
98  if (d->mMultiImapVacationDialog->isVisible()) {
99  d->mMultiImapVacationDialog->hide();
100  }
101 
102  d->mMultiImapVacationDialog->deleteLater();
103  d->mMultiImapVacationDialog = nullptr;
104 }
105 
106 void VacationManager::slotDialogOk()
107 {
108  const QVector<KSieveUi::VacationCreateScriptJob *> listJob = d->mMultiImapVacationDialog->listCreateJob();
109  for (KSieveUi::VacationCreateScriptJob *job : listJob) {
110  connect(job, &VacationCreateScriptJob::scriptActive, this, &VacationManager::updateVacationScriptStatus);
111  job->setKep14Support(d->mCheckVacation->kep14Support(job->serverName()));
112  job->start();
113  }
114  if (d->mMultiImapVacationDialog->isVisible()) {
115  d->mMultiImapVacationDialog->hide();
116  }
117 
118  d->mMultiImapVacationDialog->deleteLater();
119 
120  d->mMultiImapVacationDialog = nullptr;
121 }
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-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.