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, [email protected]
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 <KLocalizedString>
12 #include <QHBoxLayout>
13 #include <QToolButton>
14 #include <editor/generalinfoeditor/mail/mailtypecombobox.h>
15 #include <editor/widgets/preferredlineeditwidget.h>
16 
17 using namespace ContactEditor;
18 MailWidget::MailWidget(QWidget *parent)
19  : QWidget(parent)
20 {
21  auto layout = new QHBoxLayout(this);
22  layout->setSpacing(0);
23  layout->setContentsMargins(0, 0, 0, 0);
24 
25  mMailEdit = new PreferredLineEditWidget(this);
26  mMailEdit->setTrapReturnKey(true);
27  mMailEdit->setPlaceholderText(i18n("Add an Email Account"));
28  mMailEdit->setObjectName(QStringLiteral("mailedit"));
29  layout->addWidget(mMailEdit);
30  connect(mMailEdit, &PreferredLineEditWidget::preferredChanged, this, &MailWidget::slotPreferredChanged);
31 
32  mMailType = new ContactEditor::MailTypeCombobox(this);
33  mMailType->setObjectName(QStringLiteral("mailtype"));
34  layout->addWidget(mMailType);
35 
36  mAddButton = new QToolButton(this);
37  mAddButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
38  mAddButton->setObjectName(QStringLiteral("addbutton"));
39  mAddButton->setToolTip(i18n("Add an Email"));
40  connect(mAddButton, &QToolButton::clicked, this, &MailWidget::slotAddMail);
41  layout->addWidget(mAddButton);
42 
43  mRemoveButton = new QToolButton(this);
44  mRemoveButton->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
45  mRemoveButton->setObjectName(QStringLiteral("removebutton"));
46  mRemoveButton->setToolTip(i18n("Remove Email"));
47  connect(mRemoveButton, &QToolButton::clicked, this, &MailWidget::slotRemoveMail);
48  layout->addWidget(mRemoveButton);
49 }
50 
51 MailWidget::~MailWidget()
52 {
53 }
54 
55 void MailWidget::slotPreferredChanged()
56 {
57  Q_EMIT preferredChanged(this);
58 }
59 
60 void MailWidget::clearWidget()
61 {
62  mMailEdit->clear();
63  mEmail = KContacts::Email();
64  mMailType->setCurrentIndex(0);
65 }
66 
67 void MailWidget::updateAddRemoveButton(bool addButtonEnabled)
68 {
69  mAddButton->setEnabled(addButtonEnabled);
70 }
71 
72 void MailWidget::setMail(const KContacts::Email &email)
73 {
74  mEmail = email;
75  mMailEdit->setText(email.mail());
76  mMailType->setCurrentIndex(mMailType->findData((int)email.type()));
77  setPreferred(email.isPreferred());
78 }
79 
80 KContacts::Email MailWidget::email()
81 {
82  mEmail.setEmail(mMailEdit->text());
83  mEmail.setType(KContacts::Email::Type(mMailType->currentData().toInt()));
84  mEmail.setPreferred(mMailEdit->preferred());
85  return mEmail;
86 }
87 
88 void MailWidget::setPreferred(bool b)
89 {
90  mMailEdit->setPreferred(b);
91 }
92 
93 void MailWidget::setReadOnly(bool readOnly)
94 {
95  mMailEdit->setReadOnly(readOnly);
96  mMailType->setEnabled(!readOnly);
97  mAddButton->setEnabled(!readOnly);
98  mRemoveButton->setEnabled(!readOnly);
99 }
100 
101 void MailWidget::slotAddMail()
102 {
103  Q_EMIT addWidget(this);
104 }
105 
106 void MailWidget::slotRemoveMail()
107 {
108  Q_EMIT removeWidget(this);
109 }
void setType(Type type)
Type type() const
bool isPreferred() const
void clicked(bool checked)
QString i18n(const char *text, const TYPE &arg...)
QIcon fromTheme(const QString &name)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Jun 18 2021 23:08:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.