Changeset View
Changeset View
Standalone View
Standalone View
src/person.cpp
Show All 32 Lines | 24 | /** | |||
---|---|---|---|---|---|
33 | @author Reinhold Kainhofer \<reinhold@kainhofer.com\> | 33 | @author Reinhold Kainhofer \<reinhold@kainhofer.com\> | ||
34 | */ | 34 | */ | ||
35 | 35 | | |||
36 | #include "person.h" | 36 | #include "person.h" | ||
37 | #include "person_p.h" | 37 | #include "person_p.h" | ||
38 | #include <QRegExp> | 38 | #include <QRegExp> | ||
39 | #include <QDataStream> | 39 | #include <QDataStream> | ||
40 | 40 | | |||
41 | using namespace KCalCore; | 41 | using namespace KCalendarCore; | ||
42 | 42 | | |||
43 | /** | 43 | /** | ||
44 | Private class that helps to provide binary compatibility between releases. | 44 | Private class that helps to provide binary compatibility between releases. | ||
45 | @internal | 45 | @internal | ||
46 | */ | 46 | */ | ||
47 | //@cond PRIVATE | 47 | //@cond PRIVATE | ||
48 | class Q_DECL_HIDDEN KCalCore::Person::Private : public QSharedData | 48 | class Q_DECL_HIDDEN KCalendarCore::Person::Private : public QSharedData | ||
49 | { | 49 | { | ||
50 | public: | 50 | public: | ||
51 | QString mName; // person name | 51 | QString mName; // person name | ||
52 | QString mEmail; // person email address | 52 | QString mEmail; // person email address | ||
53 | }; | 53 | }; | ||
54 | //@endcond | 54 | //@endcond | ||
55 | 55 | | |||
56 | Person::Person() : d(new KCalCore::Person::Private) | 56 | Person::Person() : d(new KCalendarCore::Person::Private) | ||
57 | { | 57 | { | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | Person::Person(const QString &name, const QString &email) | 60 | Person::Person(const QString &name, const QString &email) | ||
61 | : d(new KCalCore::Person::Private) | 61 | : d(new KCalendarCore::Person::Private) | ||
62 | { | 62 | { | ||
63 | d->mName = name; | 63 | d->mName = name; | ||
64 | d->mEmail = email; | 64 | d->mEmail = email; | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | Person::Person(const Person &person) | 67 | Person::Person(const Person &person) | ||
68 | : d(person.d) | 68 | : d(person.d) | ||
69 | { | 69 | { | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | Person::~Person() = default; | 72 | Person::~Person() = default; | ||
73 | 73 | | |||
74 | bool KCalCore::Person::operator==(const Person &person) const | 74 | bool KCalendarCore::Person::operator==(const Person &person) const | ||
75 | { | 75 | { | ||
76 | return | 76 | return | ||
77 | d->mName == person.d->mName && | 77 | d->mName == person.d->mName && | ||
78 | d->mEmail == person.d->mEmail; | 78 | d->mEmail == person.d->mEmail; | ||
79 | } | 79 | } | ||
80 | 80 | | |||
81 | bool KCalCore::Person::operator!=(const Person &person) const | 81 | bool KCalendarCore::Person::operator!=(const Person &person) const | ||
82 | { | 82 | { | ||
83 | return !(*this == person); | 83 | return !(*this == person); | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | Person &KCalCore::Person::operator=(const Person &person) | 86 | Person &KCalendarCore::Person::operator=(const Person &person) | ||
87 | { | 87 | { | ||
88 | // check for self assignment | 88 | // check for self assignment | ||
89 | if (&person == this) { | 89 | if (&person == this) { | ||
90 | return *this; | 90 | return *this; | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | d = person.d; | 93 | d = person.d; | ||
94 | return *this; | 94 | return *this; | ||
95 | } | 95 | } | ||
96 | 96 | | |||
97 | QString KCalCore::fullNameHelper(const QString &name, const QString &email) | 97 | QString KCalendarCore::fullNameHelper(const QString &name, const QString &email) | ||
98 | { | 98 | { | ||
99 | if (name.isEmpty()) { | 99 | if (name.isEmpty()) { | ||
100 | return email; | 100 | return email; | ||
101 | } | 101 | } | ||
102 | if (email.isEmpty()) { | 102 | if (email.isEmpty()) { | ||
103 | return name; | 103 | return name; | ||
104 | } | 104 | } | ||
105 | // Taken from KContacts::Addressee::fullEmail | 105 | // Taken from KContacts::Addressee::fullEmail | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
152 | } | 152 | } | ||
153 | 153 | | |||
154 | bool Person::isValidEmail(const QString &email) | 154 | bool Person::isValidEmail(const QString &email) | ||
155 | { | 155 | { | ||
156 | const int pos = email.lastIndexOf(QLatin1Char('@')); | 156 | const int pos = email.lastIndexOf(QLatin1Char('@')); | ||
157 | return (pos > 0) && (email.lastIndexOf(QLatin1Char('.')) > pos) && ((email.length() - pos) > 4); | 157 | return (pos > 0) && (email.lastIndexOf(QLatin1Char('.')) > pos) && ((email.length() - pos) > 4); | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | uint KCalCore::qHash(const KCalCore::Person &key) | 160 | uint KCalendarCore::qHash(const KCalendarCore::Person &key) | ||
161 | { | 161 | { | ||
162 | return qHash(key.fullName()); | 162 | return qHash(key.fullName()); | ||
163 | } | 163 | } | ||
164 | 164 | | |||
165 | QDataStream &KCalCore::operator<<(QDataStream &stream, const KCalCore::Person &person) | 165 | QDataStream &KCalendarCore::operator<<(QDataStream &stream, const KCalendarCore::Person &person) | ||
166 | { | 166 | { | ||
167 | return stream | 167 | return stream | ||
168 | << person.d->mName | 168 | << person.d->mName | ||
169 | << person.d->mEmail | 169 | << person.d->mEmail | ||
170 | << (int)(0); | 170 | << (int)(0); | ||
171 | } | 171 | } | ||
172 | 172 | | |||
173 | QDataStream &KCalCore::operator>>(QDataStream &stream, Person &person) | 173 | QDataStream &KCalendarCore::operator>>(QDataStream &stream, Person &person) | ||
174 | { | 174 | { | ||
175 | int count; | 175 | int count; | ||
176 | stream >> person.d->mName >> person.d->mEmail >> count; | 176 | stream >> person.d->mName >> person.d->mEmail >> count; | ||
177 | return stream; | 177 | return stream; | ||
178 | } | 178 | } | ||
179 | 179 | | |||
180 | // The following function was lifted directly from KPIMUtils | 180 | // The following function was lifted directly from KPIMUtils | ||
181 | // in order to eliminate the dependency on that library. | 181 | // in order to eliminate the dependency on that library. | ||
▲ Show 20 Lines • Show All 199 Lines • Show Last 20 Lines |