Mailcommon

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

KDE's Doxygen guidelines are available online.