Mailcommon

redirectwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
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
21using namespace MailCommon;
22
23RedirectWidget::RedirectWidget(QWidget *parent)
24 : QWidget(parent)
25 , mEdit(new MessageComposer::ComposerLineEdit(true, this))
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
49 setFocusPolicy(Qt::StrongFocus);
50 setFocusProxy(mEdit);
51}
52
53RedirectWidget::~RedirectWidget() = default;
54
55QString RedirectWidget::resend()
56{
57 mResendStr = mEdit->text();
58 return mResendStr;
59}
60
61void RedirectWidget::forceFocus()
62{
63 mEdit->setFocus();
64}
65
66void 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(QLatin1StringView(", ")));
87 mEdit->setModified(true);
88 }
89}
90
91#include "moc_redirectwidget.cpp"
QString i18n(const char *text, const TYPE &arg...)
The filter dialog.
void clicked(bool checked)
QIcon fromTheme(const QString &name)
void textChanged(const QString &text)
qsizetype count() const const
void prepend(parameter_type value)
void reserve(qsizetype size)
bool isEmpty() const const
QString join(QChar separator) const const
AlignRight
StrongFocus
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:50:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.