File indexing completed on 2024-03-24 03:56:20

0001 /*
0002     This file is part of the KContacts framework.
0003     SPDX-FileCopyrightText: 2015-2019 Laurent Montel <montel@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef EMAIL_H
0009 #define EMAIL_H
0010 
0011 #include "kcontacts_export.h"
0012 
0013 #include <QMap>
0014 #include <QMetaType>
0015 #include <QSharedDataPointer>
0016 #include <QString>
0017 
0018 class EmailTest;
0019 
0020 namespace KContacts
0021 {
0022 class ParameterMap;
0023 
0024 /** @short Class that holds a Email for a contact.
0025  *  @since 4.14.5
0026  */
0027 class KCONTACTS_EXPORT Email
0028 {
0029     friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Email &);
0030     friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Email &);
0031     friend class VCardTool;
0032     friend class ::EmailTest;
0033 
0034     Q_GADGET
0035     Q_PROPERTY(QString email READ mail WRITE setEmail)
0036     Q_PROPERTY(bool isValid READ isValid)
0037     Q_PROPERTY(Type type READ type WRITE setType)
0038     Q_PROPERTY(bool isPreferred READ isPreferred WRITE setPreferred)
0039 
0040 public:
0041     /**
0042      * Creates an empty email object.
0043      */
0044     Email();
0045     Email(const Email &other);
0046     Email(const QString &mail);
0047 
0048     ~Email();
0049 
0050     typedef QList<Email> List;
0051 
0052     /**
0053      * Email types.
0054      * @see Type
0055      */
0056     enum TypeFlag {
0057         Unknown = 0, /**< No or unknown email type is set. */
0058         Home = 1, /**< Personal email. */
0059         Work = 2, /**< Work email. */
0060         Other = 4, /**< Other email. */
0061     };
0062 
0063     /**
0064      * Stores a combination of #TypeFlag values.
0065      */
0066     Q_DECLARE_FLAGS(Type, TypeFlag)
0067     Q_FLAG(Type)
0068 
0069     void setEmail(const QString &mail);
0070     Q_REQUIRED_RESULT QString mail() const;
0071 
0072     Q_REQUIRED_RESULT bool isValid() const;
0073 
0074     /**
0075      * Returns the type of the email.
0076      * @since 5.12
0077      */
0078     Type type() const;
0079     /**
0080      * Sets the email type.
0081      * @since 5.12
0082      */
0083     void setType(Type type);
0084 
0085     /**
0086      * Returns whether this is the preferred email address.
0087      * @since 5.12
0088      */
0089     bool isPreferred() const;
0090     /**
0091      * Sets that this is the preferred email address.
0092      * @since 5.12
0093      */
0094     void setPreferred(bool preferred);
0095 
0096     Q_REQUIRED_RESULT bool operator==(const Email &other) const;
0097     Q_REQUIRED_RESULT bool operator!=(const Email &other) const;
0098 
0099     Email &operator=(const Email &other);
0100 
0101     Q_REQUIRED_RESULT QString toString() const;
0102 
0103 private:
0104     void setParams(const ParameterMap &params);
0105     Q_REQUIRED_RESULT ParameterMap params() const;
0106 
0107     class Private;
0108     QSharedDataPointer<Private> d;
0109 };
0110 
0111 Q_DECLARE_OPERATORS_FOR_FLAGS(Email::Type)
0112 
0113 KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const Email &object);
0114 
0115 KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Email &object);
0116 }
0117 
0118 Q_DECLARE_TYPEINFO(KContacts::Email, Q_RELOCATABLE_TYPE);
0119 
0120 #endif // EMAIL_H