Libksieve

vacationmailactionwidget.cpp
1 /*
2  Copyright (C) 2017-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "vacationmailactionwidget.h"
21 #include "widgets/moveimapfolderwidget.h"
22 #include "widgets/abstractselectemaillineedit.h"
23 #include "autocreatescripts/autocreatescriptutil_p.h"
24 #include <QStackedWidget>
25 #include <QHBoxLayout>
26 #include <KPluginLoader>
27 #include <KPluginFactory>
28 
29 using namespace KSieveUi;
30 
31 VacationMailActionWidget::VacationMailActionWidget(QWidget *parent)
32  : QWidget(parent)
33 {
34  QHBoxLayout *mainLayout = new QHBoxLayout(this);
35  mainLayout->setObjectName(QStringLiteral("mainlayout"));
36  mainLayout->setContentsMargins(0, 0, 0, 0);
37 
38  mStackedWidget = new QStackedWidget(this);
39  mStackedWidget->setObjectName(QStringLiteral("stackedWidget"));
40  mainLayout->addWidget(mStackedWidget);
41 
42  mMailActionRecipient = new QWidget(this);
43  mMailActionRecipient->setObjectName(QStringLiteral("mailActionRecipient"));
44 
45  mStackedWidget->addWidget(mMailActionRecipient);
46 
47  mMoveImapFolderWidget = AutoCreateScriptUtil::createImapFolderWidget();
48  connect(mMoveImapFolderWidget, &AbstractMoveImapFolderWidget::textChanged, this, &VacationMailActionWidget::wasChanged);
49 
50  mMoveImapFolderWidget->setObjectName(QStringLiteral("moveImapFolderWidget"));
51  mStackedWidget->addWidget(mMoveImapFolderWidget);
52 
53  mSelectEmailLineEdit = AutoCreateScriptUtil::createSelectEmailsWidget();
54  connect(mSelectEmailLineEdit, &AbstractSelectEmailLineEdit::valueChanged, this, &VacationMailActionWidget::wasChanged);
55  mSelectEmailLineEdit->setObjectName(QStringLiteral("selectEmailLineEdit"));
56  mSelectEmailLineEdit->setMultiSelection(false);
57  mStackedWidget->addWidget(mSelectEmailLineEdit);
58 
59  mStackedWidget->setCurrentIndex(0);
60  setEnabled(false);
61 }
62 
63 VacationMailActionWidget::~VacationMailActionWidget()
64 {
65 }
66 
67 void VacationMailActionWidget::setSieveImapAccountSettings(const KSieveUi::SieveImapAccountSettings &account)
68 {
69  mMoveImapFolderWidget->setSieveImapAccountSettings(account);
70 }
71 
72 void VacationMailActionWidget::mailActionChanged(KSieveUi::VacationUtils::MailAction action)
73 {
74  bool enable = (action == VacationUtils::CopyTo || action == VacationUtils::Sendto);
75  setEnabled(enable);
76  selectMailActionWidget(action);
77 }
78 
79 void VacationMailActionWidget::selectMailActionWidget(VacationUtils::MailAction action)
80 {
81  if (action == VacationUtils::CopyTo) {
82  mStackedWidget->setCurrentWidget(mMoveImapFolderWidget);
83  } else if (action == VacationUtils::Sendto) {
84  mStackedWidget->setCurrentWidget(mSelectEmailLineEdit);
85  } else {
86  mStackedWidget->setCurrentWidget(mMailActionRecipient);
87  }
88 }
89 
90 void VacationMailActionWidget::setMailAction(VacationUtils::MailAction action, const QString &recipient)
91 {
92  selectMailActionWidget(action);
93  setText(recipient);
94 }
95 
96 void VacationMailActionWidget::setText(const QString &recipient)
97 {
98  if (mStackedWidget->currentWidget() == mMoveImapFolderWidget) {
99  mMoveImapFolderWidget->setText(recipient);
100  } else if (mStackedWidget->currentWidget() == mSelectEmailLineEdit) {
101  mSelectEmailLineEdit->setText(recipient);
102  }
103 }
104 
105 QString VacationMailActionWidget::mailActionRecipient(bool &valid) const
106 {
107  if (mStackedWidget->currentWidget() == mMoveImapFolderWidget) {
108  return mMoveImapFolderWidget->text();
109  } else if (mStackedWidget->currentWidget() == mSelectEmailLineEdit) {
110  valid = mSelectEmailLineEdit->isValid();
111  return mSelectEmailLineEdit->text();
112  } else {
113  return QString();
114  }
115 }
void setContentsMargins(int left, int top, int right, int bottom)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setObjectName(const QString &name)
The SieveImapAccountSettings class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jul 14 2020 23:08:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.