Libksieve

vacationmailactionwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2017-2021 Laurent Montel <[email protected]>
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 <KPluginLoader>
13 #include <QHBoxLayout>
14 #include <QStackedWidget>
15 
16 using namespace KSieveUi;
17 
18 VacationMailActionWidget::VacationMailActionWidget(QWidget *parent)
19  : QWidget(parent)
20 {
21  auto mainLayout = new QHBoxLayout(this);
22  mainLayout->setObjectName(QStringLiteral("mainlayout"));
23  mainLayout->setContentsMargins({});
24 
25  mStackedWidget = new QStackedWidget(this);
26  mStackedWidget->setObjectName(QStringLiteral("stackedWidget"));
27  mainLayout->addWidget(mStackedWidget);
28 
29  mMailActionRecipient = new QWidget(this);
30  mMailActionRecipient->setObjectName(QStringLiteral("mailActionRecipient"));
31 
32  mStackedWidget->addWidget(mMailActionRecipient);
33 
34  mMoveImapFolderWidget = AutoCreateScriptUtil::createImapFolderWidget();
35  connect(mMoveImapFolderWidget, &AbstractMoveImapFolderWidget::textChanged, this, &VacationMailActionWidget::wasChanged);
36 
37  mMoveImapFolderWidget->setObjectName(QStringLiteral("moveImapFolderWidget"));
38  mStackedWidget->addWidget(mMoveImapFolderWidget);
39 
40  mSelectEmailLineEdit = AutoCreateScriptUtil::createSelectEmailsWidget();
41  connect(mSelectEmailLineEdit, &AbstractSelectEmailLineEdit::valueChanged, this, &VacationMailActionWidget::wasChanged);
42  mSelectEmailLineEdit->setObjectName(QStringLiteral("selectEmailLineEdit"));
43  mSelectEmailLineEdit->setMultiSelection(false);
44  mStackedWidget->addWidget(mSelectEmailLineEdit);
45 
46  mStackedWidget->setCurrentIndex(0);
47  setEnabled(false);
48 }
49 
50 VacationMailActionWidget::~VacationMailActionWidget()
51 {
52 }
53 
54 void VacationMailActionWidget::setSieveImapAccountSettings(const KSieveUi::SieveImapAccountSettings &account)
55 {
56  mMoveImapFolderWidget->setSieveImapAccountSettings(account);
57 }
58 
59 void VacationMailActionWidget::mailActionChanged(KSieveUi::VacationUtils::MailAction action)
60 {
61  bool enable = (action == VacationUtils::CopyTo || action == VacationUtils::Sendto);
62  setEnabled(enable);
63  selectMailActionWidget(action);
64 }
65 
66 void VacationMailActionWidget::selectMailActionWidget(VacationUtils::MailAction action)
67 {
68  if (action == VacationUtils::CopyTo) {
69  mStackedWidget->setCurrentWidget(mMoveImapFolderWidget);
70  } else if (action == VacationUtils::Sendto) {
71  mStackedWidget->setCurrentWidget(mSelectEmailLineEdit);
72  } else {
73  mStackedWidget->setCurrentWidget(mMailActionRecipient);
74  }
75 }
76 
77 void VacationMailActionWidget::setMailAction(VacationUtils::MailAction action, const QString &recipient)
78 {
79  selectMailActionWidget(action);
80  setText(recipient);
81 }
82 
83 void VacationMailActionWidget::setText(const QString &recipient)
84 {
85  if (mStackedWidget->currentWidget() == mMoveImapFolderWidget) {
86  mMoveImapFolderWidget->setText(recipient);
87  } else if (mStackedWidget->currentWidget() == mSelectEmailLineEdit) {
88  mSelectEmailLineEdit->setText(recipient);
89  }
90 }
91 
92 QString VacationMailActionWidget::mailActionRecipient(bool &valid) const
93 {
94  if (mStackedWidget->currentWidget() == mMoveImapFolderWidget) {
95  return mMoveImapFolderWidget->text();
96  } else if (mStackedWidget->currentWidget() == mSelectEmailLineEdit) {
97  valid = mSelectEmailLineEdit->isValid();
98  return mSelectEmailLineEdit->text();
99  } else {
100  return QString();
101  }
102 }
The SieveImapAccountSettings class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 11 2021 23:09:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.