Mailcommon

redirectwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 
6 */
7 
8 #include "redirectwidget.h"
9 #include "kernel/mailkernel.h"
10 
11 #include <MessageComposer/ComposerLineEdit>
12 #include <QTreeView>
13 
14 #include <Akonadi/EmailAddressSelectionDialog>
15 
16 #include <KLocalizedString>
17 #include <QHBoxLayout>
18 #include <QIcon>
19 #include <QPushButton>
20 
21 using namespace MailCommon;
22 
23 RedirectWidget::RedirectWidget(QWidget *parent)
24  : QWidget(parent)
25  , mEdit(new MessageComposer::ComposerLineEdit(true))
26 {
27  auto hbox = new QHBoxLayout(this);
28  hbox->setSpacing(0);
29  hbox->setContentsMargins({});
30  hbox->setAlignment(Qt::AlignRight);
31 
32  mEdit->setRecentAddressConfig(KernelIf->config().data());
33  mEdit->setMinimumWidth(300);
34  mEdit->setClearButtonEnabled(true);
35  hbox->addWidget(mEdit);
36 
37  auto BtnTo = new QPushButton(this);
38  BtnTo->setIcon(QIcon::fromTheme(QStringLiteral("help-contents")));
39  BtnTo->setToolTip(i18n("Use the Address-Selection Dialog"));
40  BtnTo->setWhatsThis(
41  i18n("This button opens a separate dialog "
42  "where you can select recipients out "
43  "of all available addresses."));
44  hbox->addWidget(BtnTo);
45  connect(BtnTo, &QAbstractButton::clicked, this, &RedirectWidget::slotAddressSelection);
46 
47  connect(mEdit, &QLineEdit::textChanged, this, &RedirectWidget::addressChanged);
48 
50  setFocusProxy(mEdit);
51 }
52 
53 RedirectWidget::~RedirectWidget() = default;
54 
55 QString RedirectWidget::resend()
56 {
57  mResendStr = mEdit->text();
58  return mResendStr;
59 }
60 
61 void RedirectWidget::setFocus()
62 {
63  mEdit->setFocus();
64 }
65 
66 void RedirectWidget::slotAddressSelection()
67 {
68  std::unique_ptr<Akonadi::EmailAddressSelectionDialog> dlg(new Akonadi::EmailAddressSelectionDialog(this));
69 
70  dlg->view()->view()->setSelectionMode(QAbstractItemView::MultiSelection);
71 
72  mResendStr = mEdit->text();
73 
74  if (dlg->exec() != QDialog::Rejected && dlg) {
75  QStringList addresses;
76  const Akonadi::EmailAddressSelection::List lstAddress = dlg->selectedAddresses();
77  addresses.reserve(lstAddress.count());
78  for (const Akonadi::EmailAddressSelection &selection : lstAddress) {
79  addresses << selection.quotedEmail();
80  }
81 
82  if (!mResendStr.isEmpty()) {
83  addresses.prepend(mResendStr);
84  }
85 
86  mEdit->setText(addresses.join(QLatin1String(", ")));
87  mEdit->setModified(true);
88  }
89 }
AlignRight
void setFocusPolicy(Qt::FocusPolicy policy)
void clicked(bool checked)
QIcon fromTheme(const QString &name)
void setFocusProxy(QWidget *w)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void reserve(int alloc)
void prepend(const T &value)
QString i18n(const char *text, const TYPE &arg...)
void textChanged(const QString &text)
QString join(const QString &separator) const const
int count(const T &value) const const
StrongFocus
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.