1/*
2 This file is part of the KContacts framework.
3 SPDX-FileCopyrightText: 2015-2019 Laurent Montel <montel@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef EMAIL_H
9#define EMAIL_H
10
11#include "kcontacts_export.h"
12
13#include <QMap>
14#include <QMetaType>
15#include <QSharedDataPointer>
16#include <QString>
17
18class EmailTest;
19
20namespace KContacts
21{
22class ParameterMap;
23
24/*!
25 * \qmlvaluetype email
26 * \inqmlmodule org.kde.contacts
27 * \nativetype KContacts::Email
28 *
29 * \brief Class that holds a Email for a contact.
30 */
31
32/*!
33 * \class KContacts::Email
34 * \inheaderfile KContacts/Email
35 * \inmodule KContacts
36 *
37 * \brief Class that holds a Email for a contact.
38 * \since 4.14.5
39 */
40class KCONTACTS_EXPORT Email
41{
42 friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Email &);
43 friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Email &);
44 friend class VCardTool;
45 friend class ::EmailTest;
46
47 Q_GADGET
48
49 /*!
50 * \qmlproperty string email::email
51 */
52
53 /*!
54 * \property KContacts::Email::email
55 */
56 Q_PROPERTY(QString email READ mail WRITE setEmail)
57
58 /*!
59 * \qmlproperty booling email::isValid
60 */
61
62 /*!
63 * \property KContacts::Email::isValid
64 */
65 Q_PROPERTY(bool isValid READ isValid)
66
67 /*!
68 * \qmlproperty enumeration email::type
69 * \qmlenumeratorsfrom KContacts::Email::TypeFlag
70 */
71
72 /*!
73 * \property KContacts::Email::type
74 */
75 Q_PROPERTY(Type type READ type WRITE setType)
76
77 /*!
78 * \qmlproperty bool email::isPreferred
79 */
80
81 /*!
82 * \property KContacts::Email::isPreferred
83 */
84 Q_PROPERTY(bool isPreferred READ isPreferred WRITE setPreferred)
85
86public:
87 /*!
88 * Creates an empty email object.
89 */
90 Email();
91
92 Email(const Email &other);
93
94 /*!
95 */
96 Q_INVOKABLE Email(const QString &mail);
97
98 ~Email();
99
100 /*!
101 */
102 typedef QList<Email> List;
103
104 /*!
105 * Email types.
106 *
107 * \value Unknown No or unknown email type is set
108 * \value Home Personal email
109 * \value Work Work email
110 * \value Other Other email
111 */
112 enum TypeFlag {
113 Unknown = 0,
114 Home = 1,
115 Work = 2,
116 Other = 4,
117 };
118
119 Q_DECLARE_FLAGS(Type, TypeFlag)
120 Q_FLAG(Type)
121
122 /*!
123 *
124 */
125 void setEmail(const QString &mail);
126
127 /*!
128 *
129 */
130 Q_REQUIRED_RESULT QString mail() const;
131
132 /*!
133 *
134 */
135 Q_REQUIRED_RESULT bool isValid() const;
136
137 /*!
138 * Returns the type of the email.
139 * \since 5.12
140 */
141 Type type() const;
142 /*!
143 * Sets the email type.
144 * \since 5.12
145 */
146 void setType(Type type);
147
148 /*!
149 * Returns whether this is the preferred email address.
150 * \since 5.12
151 */
152 bool isPreferred() const;
153 /*!
154 * Sets that this is the preferred email address.
155 * \since 5.12
156 */
157 void setPreferred(bool preferred);
158
159 /*!
160 */
161 Q_REQUIRED_RESULT bool operator==(const Email &other) const;
162
163 /*!
164 */
165 Q_REQUIRED_RESULT bool operator!=(const Email &other) const;
166
167 Email &operator=(const Email &other);
168
169 /*!
170 */
171 Q_REQUIRED_RESULT QString toString() const;
172
173private:
174 void setParams(const ParameterMap &params);
175 Q_REQUIRED_RESULT ParameterMap params() const;
176
177 class Private;
178 QSharedDataPointer<Private> d;
179};
180
181Q_DECLARE_OPERATORS_FOR_FLAGS(Email::Type)
182
183/*!
184 * \relates KContacts::Email
185 */
186KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const Email &object);
187
188/*!
189 * \relates KContacts::Email
190 */
191KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Email &object);
192}
193
194Q_DECLARE_TYPEINFO(KContacts::Email, Q_RELOCATABLE_TYPE);
195
196#endif // EMAIL_H
197

source code of kcontacts/src/email.h