File indexing completed on 2024-03-24 03:55:38
0001 /* 0002 This file is part of the kcalcore library. 0003 0004 SPDX-FileCopyrightText: 2001-2003 Cornelius Schumacher <schumacher@kde.org> 0005 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 /** 0010 @file 0011 This file is part of the API for handling calendar data and 0012 defines the Person class. 0013 0014 @author Cornelius Schumacher \<schumacher@kde.org\> 0015 @author Reinhold Kainhofer \<reinhold@kainhofer.com\> 0016 */ 0017 0018 #ifndef KCALCORE_PERSON_H 0019 #define KCALCORE_PERSON_H 0020 0021 #include "kcalendarcore_export.h" 0022 0023 #include <QHash> 0024 #include <QMetaType> 0025 #include <QSharedDataPointer> 0026 #include <QString> 0027 0028 namespace KCalendarCore 0029 { 0030 /** 0031 @brief 0032 Represents a person, by name and email address. 0033 0034 This class represents a person, with a name and an email address. 0035 It supports the "FirstName LastName\ <mail@domain\>" format. 0036 */ 0037 class KCALENDARCORE_EXPORT Person 0038 { 0039 Q_GADGET 0040 Q_PROPERTY(bool isEmpty READ isEmpty) 0041 Q_PROPERTY(QString fullName READ fullName) 0042 Q_PROPERTY(QString name READ name WRITE setName) 0043 Q_PROPERTY(QString email READ email WRITE setEmail) 0044 0045 public: 0046 /** 0047 List of persons. 0048 */ 0049 typedef QList<Person> List; 0050 0051 /** 0052 Constructs a blank person. 0053 */ 0054 Person(); 0055 0056 /** 0057 Constructs a person with name and email address taken from @p fullName. 0058 0059 @param fullName is the name and email of the person in the form 0060 "FirstName LastName \<mail@domain\>". 0061 @return A Person object. 0062 */ 0063 static Person fromFullName(const QString &fullName); 0064 0065 /** 0066 Constructs a person with the name @p name and email address @p email. 0067 0068 @param name is the name of this person. 0069 @param email is the email address of this person. 0070 */ 0071 Person(const QString &name, const QString &email); 0072 0073 /** 0074 Constructs a person as a copy of another person object. 0075 @param person is the person to copy. 0076 */ 0077 Person(const Person &person); 0078 0079 /** 0080 Destroys a person. 0081 */ 0082 virtual ~Person(); 0083 0084 /** 0085 Returns true if the person name and email address are empty. 0086 */ 0087 Q_REQUIRED_RESULT bool isEmpty() const; 0088 0089 /** 0090 Returns the full name of this person. 0091 @return A QString containing the person's full name in the form 0092 "FirstName LastName \<mail@domain\>". 0093 */ 0094 Q_REQUIRED_RESULT QString fullName() const; 0095 0096 /** 0097 Sets the name of the person to @p name. 0098 0099 @param name is the name of this person. 0100 0101 @see name() 0102 */ 0103 void setName(const QString &name); 0104 0105 /** 0106 Returns the person name string. 0107 0108 @see setName() 0109 */ 0110 Q_REQUIRED_RESULT QString name() const; 0111 0112 /** 0113 Sets the email address for this person to @p email. 0114 0115 @param email is the email address for this person. 0116 0117 @see email() 0118 */ 0119 void setEmail(const QString &email); 0120 0121 /** 0122 Returns the email address for this person. 0123 @return A QString containing the person's email address. 0124 @see setEmail() 0125 */ 0126 Q_REQUIRED_RESULT QString email() const; 0127 0128 /** 0129 Returns true if person's email address is valid. 0130 Simple email validity check, test that there: 0131 * is at least one @ 0132 * is at least one character in the local part 0133 * is at least one dot in the domain part 0134 * is at least four characters in the domain (assuming that no-one has an address at the tld, 0135 that the tld is at least 2 chars) 0136 0137 @param email is the email address to validate 0138 */ 0139 Q_REQUIRED_RESULT static bool isValidEmail(const QString &email); 0140 0141 /** 0142 Compares this with @p person for equality. 0143 0144 @param person is the person to compare. 0145 */ 0146 bool operator==(const Person &person) const; 0147 0148 /** 0149 Compares this with @p person for non-equality. 0150 0151 @param person is the person to compare. 0152 */ 0153 bool operator!=(const Person &person) const; 0154 0155 /** 0156 Sets this person equal to @p person. 0157 0158 @param person is the person to copy. 0159 */ 0160 Person &operator=(const Person &person); 0161 0162 private: 0163 //@cond PRIVATE 0164 class Private; 0165 QSharedDataPointer<Private> d; 0166 //@endcond 0167 0168 friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalendarCore::Person &person); 0169 friend KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &s, KCalendarCore::Person &person); 0170 }; 0171 0172 /** 0173 Serializes the @p person object into the @p stream. 0174 */ 0175 KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &stream, const KCalendarCore::Person &person); 0176 0177 /** 0178 Initializes the @p person object from the @p stream. 0179 */ 0180 KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KCalendarCore::Person &person); 0181 0182 /** 0183 Return a hash value for a Person argument. 0184 @param key is a Person. 0185 */ 0186 KCALENDARCORE_EXPORT size_t qHash(const KCalendarCore::Person &key, size_t seed = 0); 0187 0188 } 0189 0190 //@cond PRIVATE 0191 Q_DECLARE_TYPEINFO(KCalendarCore::Person, Q_RELOCATABLE_TYPE); 0192 Q_DECLARE_METATYPE(KCalendarCore::Person) 0193 //@endcond 0194 0195 #endif