Akonadi Contacts

mailwidget.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com
5 SPDX-FileCopyrightText: 2016-2020 Laurent Montel <montel.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "mailwidget.h"
11#include "editor/generalinfoeditor/mail/mailtypecombobox.h"
12#include "editor/widgets/preferredlineeditwidget.h"
13#include <KLocalizedString>
14#include <QHBoxLayout>
15#include <QToolButton>
16
17using namespace Akonadi;
18MailWidget::MailWidget(QWidget *parent)
19 : QWidget(parent)
20 , mMailEdit(new PreferredLineEditWidget(this))
21 , mMailType(new Akonadi::MailTypeCombobox(this))
22 , mAddButton(new QToolButton(this))
23 , mRemoveButton(new QToolButton(this))
24{
25 auto layout = new QHBoxLayout(this);
26 layout->setSpacing(0);
27 layout->setContentsMargins({});
28
29 mMailEdit->setTrapReturnKey(true);
30 mMailEdit->setPlaceholderText(i18nc("@info:placeholder", "Add an Email Account"));
31 mMailEdit->setObjectName(QLatin1StringView("mailedit"));
32 layout->addWidget(mMailEdit);
33 connect(mMailEdit, &PreferredLineEditWidget::preferredChanged, this, &MailWidget::slotPreferredChanged);
34
35 mMailType->setObjectName(QLatin1StringView("mailtype"));
36 layout->addWidget(mMailType);
37
38 mAddButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
39 mAddButton->setObjectName(QLatin1StringView("addbutton"));
40 mAddButton->setToolTip(i18nc("@info:tooltip", "Add an Email"));
41 connect(mAddButton, &QToolButton::clicked, this, &MailWidget::slotAddMail);
42 layout->addWidget(mAddButton);
43
44 mRemoveButton->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
45 mRemoveButton->setObjectName(QLatin1StringView("removebutton"));
46 mRemoveButton->setToolTip(i18nc("@info:tooltip", "Remove Email"));
47 connect(mRemoveButton, &QToolButton::clicked, this, &MailWidget::slotRemoveMail);
48 layout->addWidget(mRemoveButton);
49}
50
51MailWidget::~MailWidget() = default;
52
53void MailWidget::slotPreferredChanged()
54{
55 Q_EMIT preferredChanged(this);
56}
57
58void MailWidget::clearWidget()
59{
60 mMailEdit->clear();
61 mEmail = KContacts::Email();
62 mMailType->setCurrentIndex(0);
63}
64
65void MailWidget::updateAddRemoveButton(bool addButtonEnabled)
66{
67 mAddButton->setEnabled(addButtonEnabled);
68}
69
70void MailWidget::setMail(const KContacts::Email &email)
71{
72 mEmail = email;
73 mMailEdit->setText(email.mail());
74 mMailType->setCurrentIndex(mMailType->findData((int)email.type()));
75 setPreferred(email.isPreferred());
76}
77
78KContacts::Email MailWidget::email()
79{
80 mEmail.setEmail(mMailEdit->text());
81 mEmail.setType(KContacts::Email::Type(mMailType->currentData().toInt()));
82 mEmail.setPreferred(mMailEdit->preferred());
83 return mEmail;
84}
85
86void MailWidget::setPreferred(bool b)
87{
88 mMailEdit->setPreferred(b);
89}
90
91void MailWidget::setReadOnly(bool readOnly)
92{
93 mMailEdit->setReadOnly(readOnly);
94 mMailType->setEnabled(!readOnly);
95 mAddButton->setEnabled(!readOnly);
96 mRemoveButton->setEnabled(!readOnly);
97}
98
99void MailWidget::slotAddMail()
100{
101 Q_EMIT addWidget(this);
102}
103
104void MailWidget::slotRemoveMail()
105{
106 Q_EMIT removeWidget(this);
107}
108
109#include "moc_mailwidget.cpp"
bool isPreferred() const
Type type() const
void setType(Type type)
void setPreferred(bool preferred)
virtual void setReadOnly(bool)
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)
void setCurrentIndex(int index)
int findData(const QVariant &data, int role, Qt::MatchFlags flags) const const
QIcon fromTheme(const QString &name)
void clear()
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.