Warning, file /pim/mailcommon/src/widgets/redirectwidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 0006 */ 0007 0008 #include "redirectwidget.h" 0009 #include "kernel/mailkernel.h" 0010 0011 #include <MessageComposer/ComposerLineEdit> 0012 #include <QTreeView> 0013 0014 #include <Akonadi/EmailAddressSelectionDialog> 0015 0016 #include <KLocalizedString> 0017 #include <QHBoxLayout> 0018 #include <QIcon> 0019 #include <QPushButton> 0020 0021 using namespace MailCommon; 0022 0023 RedirectWidget::RedirectWidget(QWidget *parent) 0024 : QWidget(parent) 0025 , mEdit(new MessageComposer::ComposerLineEdit(true)) 0026 { 0027 auto hbox = new QHBoxLayout(this); 0028 hbox->setSpacing(0); 0029 hbox->setContentsMargins({}); 0030 hbox->setAlignment(Qt::AlignRight); 0031 0032 mEdit->setRecentAddressConfig(KernelIf->config().data()); 0033 mEdit->setMinimumWidth(300); 0034 mEdit->setClearButtonEnabled(true); 0035 hbox->addWidget(mEdit); 0036 0037 auto BtnTo = new QPushButton(this); 0038 BtnTo->setIcon(QIcon::fromTheme(QStringLiteral("help-contents"))); 0039 BtnTo->setToolTip(i18n("Use the Address-Selection Dialog")); 0040 BtnTo->setWhatsThis( 0041 i18n("This button opens a separate dialog " 0042 "where you can select recipients out " 0043 "of all available addresses.")); 0044 hbox->addWidget(BtnTo); 0045 connect(BtnTo, &QAbstractButton::clicked, this, &RedirectWidget::slotAddressSelection); 0046 0047 connect(mEdit, &QLineEdit::textChanged, this, &RedirectWidget::addressChanged); 0048 0049 setFocusPolicy(Qt::StrongFocus); 0050 setFocusProxy(mEdit); 0051 } 0052 0053 RedirectWidget::~RedirectWidget() = default; 0054 0055 QString RedirectWidget::resend() 0056 { 0057 mResendStr = mEdit->text(); 0058 return mResendStr; 0059 } 0060 0061 void RedirectWidget::setFocus() 0062 { 0063 mEdit->setFocus(); 0064 } 0065 0066 void RedirectWidget::slotAddressSelection() 0067 { 0068 std::unique_ptr<Akonadi::EmailAddressSelectionDialog> dlg(new Akonadi::EmailAddressSelectionDialog(this)); 0069 0070 dlg->view()->view()->setSelectionMode(QAbstractItemView::MultiSelection); 0071 0072 mResendStr = mEdit->text(); 0073 0074 if (dlg->exec() != QDialog::Rejected && dlg) { 0075 QStringList addresses; 0076 const Akonadi::EmailAddressSelection::List lstAddress = dlg->selectedAddresses(); 0077 addresses.reserve(lstAddress.count()); 0078 for (const Akonadi::EmailAddressSelection &selection : lstAddress) { 0079 addresses << selection.quotedEmail(); 0080 } 0081 0082 if (!mResendStr.isEmpty()) { 0083 addresses.prepend(mResendStr); 0084 } 0085 0086 mEdit->setText(addresses.join(QLatin1StringView(", "))); 0087 mEdit->setModified(true); 0088 } 0089 } 0090 0091 #include "moc_redirectwidget.cpp"