Akonadi Contacts

emailaddressrequester.cpp
1/*
2 SPDX-FileCopyrightText: 2001 Marc Mutz <mutz@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "emailaddressrequester.h"
8
9#include "emailaddressselectiondialog.h"
10#include <KLineEdit>
11#include <KLocalizedString>
12#include <QIcon>
13
14#include <QHBoxLayout>
15#include <QPushButton>
16#include <QTreeView>
17
18using namespace Akonadi;
19
20class Akonadi::EmailAddressRequesterPrivate
21{
22public:
23 explicit EmailAddressRequesterPrivate(EmailAddressRequester *qq)
24 : q(qq)
25 {
26 }
27
28 void slotAddressBook();
29
30 EmailAddressRequester *const q;
31 KLineEdit *mLineEdit = nullptr;
32};
33
34void EmailAddressRequesterPrivate::slotAddressBook()
35{
37 dlg->view()->view()->setSelectionMode(QAbstractItemView::MultiSelection);
38 if (!dlg->exec()) {
39 delete dlg;
40 return;
41 }
42
43 QStringList addressList;
44 const auto selectedAddresses = dlg->selectedAddresses();
45 addressList.reserve(selectedAddresses.size());
46 for (const Akonadi::EmailAddressSelection &selection : selectedAddresses) {
47 addressList << selection.quotedEmail();
48 }
49
50 QString text = mLineEdit->text().trimmed();
51
52 if (!text.isEmpty()) {
53 if (!text.endsWith(QLatin1Char(','))) {
54 text += QLatin1StringView(", ");
55 } else {
56 text += QLatin1Char(' ');
57 }
58 }
59
60 mLineEdit->setText(text + addressList.join(QLatin1Char(',')));
61 delete dlg;
62}
63
65 : QWidget(parent)
66 , d(new EmailAddressRequesterPrivate(this))
67{
68 auto layout = new QHBoxLayout(this);
71
72 d->mLineEdit = new KLineEdit(this);
73 d->mLineEdit->setClearButtonEnabled(true);
74 d->mLineEdit->setTrapReturnKey(true);
75 layout->addWidget(d->mLineEdit, 1);
76
77 auto button = new QPushButton(this);
78 button->setIcon(QIcon::fromTheme(QStringLiteral("help-contents")));
79 button->setFixedHeight(d->mLineEdit->sizeHint().height());
80 button->setToolTip(i18nc("@info:tooltip", "Open Address Book"));
81 layout->addWidget(button);
82
83 connect(button, &QPushButton::clicked, this, [this]() {
84 d->slotAddressBook();
85 });
87}
88
90
92{
93 d->mLineEdit->clear();
94}
95
97{
98 d->mLineEdit->setText(text);
99}
100
101QString EmailAddressRequester::text() const
102{
103 return d->mLineEdit->text();
104}
105
107{
108 return d->mLineEdit;
109}
110
111#include "moc_emailaddressrequester.cpp"
A widget to input one or more email addresses.
void clear()
Clears the text of the email address requester.
EmailAddressRequester(QWidget *parent=nullptr)
Creates a new email address requester.
void setText(const QString &text)
Sets the text of the email address requester.
~EmailAddressRequester() override
Destroys the email address requester.
KLineEdit * lineEdit() const
Returns the line edit that is used by the email address requester.
void textChanged()
This signal is emitted whenever the text of the email address requester has been changed.
A dialog to select email addresses from Akonadi.
An selection of an email address and corresponding name.
virtual void setText(const QString &)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
void clicked(bool checked)
QIcon fromTheme(const QString &name)
void addWidget(QWidget *w)
void setContentsMargins(const QMargins &margins)
virtual void setSpacing(int)
void textChanged(const QString &text)
void reserve(qsizetype size)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString join(QChar separator) const const
QLayout * layout() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.