Libksieve

vacationmanager.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-only
5*/
6
7#include "vacationmanager.h"
8#include "ksieveui/vacation/multiimapvacationdialog.h"
9#include <KSieveCore/MultiImapVacationManager>
10#include <KSieveCore/VacationCreateScriptJob>
11
12#include <KLocalizedString>
13#include <KMessageBox>
14#include <QPointer>
15#include <QWidget>
16
17using namespace KSieveUi;
18
19class KSieveUi::VacationManagerPrivate
20{
21public:
22 VacationManagerPrivate(QWidget *parent)
23 : mWidget(parent)
24 {
25 }
26
27 QWidget *const mWidget;
28 QPointer<KSieveUi::MultiImapVacationDialog> mMultiImapVacationDialog = nullptr;
30 bool mQuestionAsked = false;
31};
32
33VacationManager::VacationManager(KSieveCore::SieveImapPasswordProvider *passwordProvider, QWidget *parent)
34 : QObject(parent)
35 , d(new KSieveUi::VacationManagerPrivate(parent))
36{
37 d->mCheckVacation = new KSieveCore::MultiImapVacationManager(passwordProvider, this);
38 connect(d->mCheckVacation.data(), &KSieveCore::MultiImapVacationManager::scriptActive, this, &VacationManager::slotUpdateVacationScriptStatus);
39}
40
41VacationManager::~VacationManager() = default;
42
43void VacationManager::checkVacation()
44{
45 d->mCheckVacation->checkVacation();
46}
47
48void 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;
55 i18n("There is still an active out-of-office reply configured.\n"
56 "Do you want to edit it?"),
57 i18nc("@title:window", "Out-of-office reply still active"),
58 KGuiItem(i18nc("@action:button", "Edit"), QStringLiteral("document-properties")),
59 KGuiItem(i18nc("@action:button", "Ignore"), QStringLiteral("dialog-cancel")))
60 == KMessageBox::ButtonCode::PrimaryAction) {
61 slotEditVacation(serverName);
62 }
63 }
64 }
65}
66
67void 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
84void VacationManager::slotDialogCanceled()
85{
86 if (d->mMultiImapVacationDialog->isVisible()) {
87 d->mMultiImapVacationDialog->hide();
88 }
89
90 d->mMultiImapVacationDialog->deleteLater();
91 d->mMultiImapVacationDialog = nullptr;
92}
93
94void VacationManager::slotDialogOk()
95{
96 const QList<KSieveCore::VacationCreateScriptJob *> listJob = d->mMultiImapVacationDialog->listCreateJob();
97 for (KSieveCore::VacationCreateScriptJob *job : listJob) {
98 connect(job, &KSieveCore::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}
110
111#include "moc_vacationmanager.cpp"
The MultiImapVacationManager class.
The SieveImapPasswordProvider class.
The MultiImapVacationDialog class.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
ButtonCode questionTwoActions(QWidget *parent, const QString &text, const QString &title, const KGuiItem &primaryAction, const KGuiItem &secondaryAction, const QString &dontAskAgainName=QString(), Options options=Notify)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.