Mailcommon

redirectdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2003 Andreas Gungl <a.gungl@gmx.de>
3 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-only
6*/
7
8#include "redirectdialog.h"
9#include "kernel/mailkernel.h"
10
11#include "redirectwidget.h"
12
13#include <KIdentityManagementCore/Identity>
14#include <KIdentityManagementWidgets/IdentityCombo>
15
16#include <MailTransport/TransportComboBox>
17
18#include <KLocalizedString>
19#include <KMessageBox>
20
21#include <KGuiItem>
22#include <QDialogButtonBox>
23#include <QFormLayout>
24#include <QLabel>
25#include <QPushButton>
26#include <QTreeView>
27#include <QVBoxLayout>
28
29using namespace MailCommon;
30
31class Q_DECL_HIDDEN RedirectDialog::RedirectDialogPrivate
32{
33public:
34 RedirectDialogPrivate(RedirectDialog *qq, RedirectDialog::SendMode mode)
35 : q(qq)
36 , mSendMode(mode)
37 {
38 }
39
40 enum TypeAddress {
41 ResendTo,
42 ResendCc,
43 ResendBcc,
44 };
45
46 void slotUser1();
47 void slotUser2();
48 void slotAddressChanged(const QString &);
49 [[nodiscard]] QString redirectLabelType(TypeAddress type) const;
50 RedirectDialog *const q = nullptr;
51 RedirectWidget *mEditTo = nullptr;
52 RedirectWidget *mEditCc = nullptr;
53 RedirectWidget *mEditBcc = nullptr;
54
56 KIdentityManagementWidgets::IdentityCombo *mComboboxIdentity = nullptr;
57 MailTransport::TransportComboBox *mTransportCombobox = nullptr;
58 QPushButton *mUser1Button = nullptr;
59 QPushButton *mUser2Button = nullptr;
60};
61
62QString RedirectDialog::RedirectDialogPrivate::redirectLabelType(TypeAddress type) const
63{
65 switch (type) {
66 case ResendTo:
67 label = i18n("Resend-To:");
68 break;
69 case ResendCc:
70 label = i18n("Resend-Cc:");
71 break;
72 case ResendBcc:
73 label = i18n("Resend-Bcc:");
74 break;
75 }
76 return label;
77}
78
79void RedirectDialog::RedirectDialogPrivate::slotUser1()
80{
81 mSendMode = RedirectDialog::SendNow;
82 q->accept();
83}
84
85void RedirectDialog::RedirectDialogPrivate::slotUser2()
86{
87 mSendMode = RedirectDialog::SendLater;
88 q->accept();
89}
90
91void RedirectDialog::RedirectDialogPrivate::slotAddressChanged(const QString &text)
92{
93 const bool textIsNotEmpty(!text.trimmed().isEmpty());
94 mUser1Button->setEnabled(textIsNotEmpty);
95 mUser2Button->setEnabled(textIsNotEmpty);
96}
97
100 , d(new RedirectDialogPrivate(this, mode))
101{
102 setWindowTitle(i18nc("@title:window", "Redirect Message"));
103 auto topLayout = new QVBoxLayout(this);
104 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, this);
105 d->mUser1Button = new QPushButton(this);
106 buttonBox->addButton(d->mUser1Button, QDialogButtonBox::ActionRole);
107 d->mUser2Button = new QPushButton(this);
108 buttonBox->addButton(d->mUser2Button, QDialogButtonBox::ActionRole);
110 if (mode == SendNow) {
111 d->mUser1Button->setDefault(true);
112 } else {
113 d->mUser2Button->setDefault(true);
114 }
115
116 auto mainWidget = new QWidget(this);
117 topLayout->addWidget(mainWidget);
118 topLayout->addWidget(buttonBox);
119
120 auto mainLayout = new QVBoxLayout;
121 mainWidget->setLayout(mainLayout);
122 mainLayout->setContentsMargins({});
123 auto LabelTo = new QLabel(i18nc("@label:textbox", "Select the recipient addresses to redirect to:"), this);
124 mainLayout->addWidget(LabelTo);
125
126 auto formLayout = new QFormLayout;
127 // Combo boxes look better when they are the same size as other full width fields.
129 // This is set to zero to avoid double margins between the
130 // three address fields, due to their address selection buttons.
131 formLayout->setVerticalSpacing(0);
132 mainLayout->addLayout(formLayout);
133
134 d->mEditTo = new RedirectWidget(this);
135 formLayout->addRow(d->redirectLabelType(RedirectDialog::RedirectDialogPrivate::ResendTo), d->mEditTo);
136
137 connect(d->mEditTo, &RedirectWidget::addressChanged, this, [this](const QString &str) {
138 d->slotAddressChanged(str);
139 });
140
141 d->mEditCc = new RedirectWidget(this);
142 formLayout->addRow(d->redirectLabelType(RedirectDialog::RedirectDialogPrivate::ResendCc), d->mEditCc);
143 d->mEditBcc = new RedirectWidget(this);
144 formLayout->addRow(d->redirectLabelType(RedirectDialog::RedirectDialogPrivate::ResendBcc), d->mEditBcc);
145 d->mEditTo->forceFocus();
146
147 // Because the form layout vertical spacing was set to zero above,
148 // it is necessary to explicitly add spacing between the combo boxes.
149 // The layout default spacing is copied from the main layout.
150 formLayout->addItem(new QSpacerItem(1, mainLayout->spacing(), QSizePolicy::Fixed, QSizePolicy::Fixed));
151 d->mComboboxIdentity = new KIdentityManagementWidgets::IdentityCombo(KernelIf->identityManager());
152 formLayout->addRow(i18n("Identity:"), d->mComboboxIdentity);
153
154 formLayout->addItem(new QSpacerItem(1, mainLayout->spacing(), QSizePolicy::Fixed, QSizePolicy::Fixed));
155 d->mTransportCombobox = new MailTransport::TransportComboBox;
156 formLayout->addRow(i18n("Transport:"), d->mTransportCombobox);
157
158 KGuiItem::assign(d->mUser1Button, KGuiItem(i18nc("@action:button", "&Send Now"), QIcon::fromTheme(QStringLiteral("mail-send"))));
159 KGuiItem::assign(d->mUser2Button, KGuiItem(i18nc("@action:button", "Send &Later"), QIcon::fromTheme(QStringLiteral("mail-queue"))));
160 connect(d->mUser1Button, &QPushButton::clicked, this, [this]() {
161 d->slotUser1();
162 });
163 connect(d->mUser2Button, &QPushButton::clicked, this, [this]() {
164 d->slotUser2();
165 });
166
167 d->mUser1Button->setEnabled(false);
168 d->mUser2Button->setEnabled(false);
169}
170
172
174{
175 return d->mEditTo->resend();
176}
177
178QString RedirectDialog::cc() const
179{
180 return d->mEditCc->resend();
181}
182
183QString RedirectDialog::bcc() const
184{
185 return d->mEditBcc->resend();
186}
187
189{
190 return d->mSendMode;
191}
192
193int RedirectDialog::transportId() const
194{
195 return d->mTransportCombobox->currentTransportId();
196}
197
198int RedirectDialog::identity() const
199{
200 return static_cast<int>(d->mComboboxIdentity->currentIdentity());
201}
202
203void RedirectDialog::accept()
204{
205 const QString editTo = d->mEditTo->resend();
206 if (editTo.isEmpty()) {
207 KMessageBox::error(this, i18n("You cannot redirect the message without an address."), i18n("Empty Redirection Address"));
208 } else {
210 }
211}
212
213#include "moc_redirectdialog.cpp"
static void assign(QPushButton *button, const KGuiItem &item)
A dialog to request information about message redirection from the user.
QString to() const
Returns the addresses for the redirection.
~RedirectDialog() override
Destroys the redirect dialog.
SendMode sendMode() const
Returns the send mode.
RedirectDialog(SendMode mode=SendNow, QWidget *parent=nullptr)
Creates a new redirect dialog.
SendMode
Describes the send mode.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QString label(StandardShortcut id)
The filter dialog.
void clicked(bool checked)
virtual void done(int r)
virtual void reject()
void setFieldGrowthPolicy(FieldGrowthPolicy policy)
QIcon fromTheme(const QString &name)
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
bool isEmpty() const const
QString trimmed() const const
QWidget(QWidget *parent, Qt::WindowFlags f)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:53:26 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.