Libksieve

vacationmailactionwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "vacationmailactionwidget.h"
8#include "autocreatescripts/autocreatescriptutil_p.h"
9#include "widgets/abstractselectemaillineedit.h"
10#include "widgets/moveimapfolderwidget.h"
11#include <KPluginFactory>
12#include <QHBoxLayout>
13#include <QStackedWidget>
14
15using namespace KSieveUi;
16
17VacationMailActionWidget::VacationMailActionWidget(QWidget *parent)
18 : QWidget(parent)
19{
20 auto mainLayout = new QHBoxLayout(this);
21 mainLayout->setObjectName(QLatin1StringView("mainlayout"));
22 mainLayout->setContentsMargins({});
23
24 mStackedWidget = new QStackedWidget(this);
25 mStackedWidget->setObjectName(QLatin1StringView("stackedWidget"));
26 mainLayout->addWidget(mStackedWidget);
27
28 mMailActionRecipient = new QWidget(this);
29 mMailActionRecipient->setObjectName(QLatin1StringView("mailActionRecipient"));
30
31 mStackedWidget->addWidget(mMailActionRecipient);
32
33 mMoveImapFolderWidget = AutoCreateScriptUtil::createImapFolderWidget();
34 connect(mMoveImapFolderWidget, &AbstractMoveImapFolderWidget::textChanged, this, &VacationMailActionWidget::wasChanged);
35
36 mMoveImapFolderWidget->setObjectName(QLatin1StringView("moveImapFolderWidget"));
37 mStackedWidget->addWidget(mMoveImapFolderWidget);
38
39 mSelectEmailLineEdit = AutoCreateScriptUtil::createSelectEmailsWidget();
40 connect(mSelectEmailLineEdit, &AbstractSelectEmailLineEdit::valueChanged, this, &VacationMailActionWidget::wasChanged);
41 mSelectEmailLineEdit->setObjectName(QLatin1StringView("selectEmailLineEdit"));
42 mSelectEmailLineEdit->setMultiSelection(false);
43 mStackedWidget->addWidget(mSelectEmailLineEdit);
44
45 mStackedWidget->setCurrentIndex(0);
46 setEnabled(false);
47}
48
49VacationMailActionWidget::~VacationMailActionWidget() = default;
50
51void VacationMailActionWidget::setSieveImapAccountSettings(const KSieveCore::SieveImapAccountSettings &account)
52{
53 mMoveImapFolderWidget->setSieveImapAccountSettings(account);
54}
55
56void VacationMailActionWidget::mailActionChanged(KSieveCore::VacationUtils::MailAction action)
57{
58 bool enable = (action == KSieveCore::VacationUtils::CopyTo || action == KSieveCore::VacationUtils::Sendto);
59 setEnabled(enable);
60 selectMailActionWidget(action);
61}
62
63void VacationMailActionWidget::selectMailActionWidget(KSieveCore::VacationUtils::MailAction action)
64{
65 if (action == KSieveCore::VacationUtils::CopyTo) {
66 mStackedWidget->setCurrentWidget(mMoveImapFolderWidget);
67 } else if (action == KSieveCore::VacationUtils::Sendto) {
68 mStackedWidget->setCurrentWidget(mSelectEmailLineEdit);
69 } else {
70 mStackedWidget->setCurrentWidget(mMailActionRecipient);
71 }
72}
73
74void VacationMailActionWidget::setMailAction(KSieveCore::VacationUtils::MailAction action, const QString &recipient)
75{
76 selectMailActionWidget(action);
77 setText(recipient);
78}
79
80void VacationMailActionWidget::setText(const QString &recipient)
81{
82 if (mStackedWidget->currentWidget() == mMoveImapFolderWidget) {
83 mMoveImapFolderWidget->setText(recipient);
84 } else if (mStackedWidget->currentWidget() == mSelectEmailLineEdit) {
85 mSelectEmailLineEdit->setText(recipient);
86 }
87}
88
89QString VacationMailActionWidget::mailActionRecipient(bool &valid) const
90{
91 if (mStackedWidget->currentWidget() == mMoveImapFolderWidget) {
92 return mMoveImapFolderWidget->text();
93 } else if (mStackedWidget->currentWidget() == mSelectEmailLineEdit) {
94 valid = mSelectEmailLineEdit->isValid();
95 return mSelectEmailLineEdit->text();
96 } else {
97 return {};
98 }
99}
100
101#include "moc_vacationmailactionwidget.cpp"
The SieveImapAccountSettings class.
QWidget * currentWidget() const const
void setCurrentWidget(QWidget *widget)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:09:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.