Changeset View
Changeset View
Standalone View
Standalone View
src/person.cpp
Show All 28 Lines | 24 | /** | |||
---|---|---|---|---|---|
29 | @brief | 29 | @brief | ||
30 | Represents a person, by name and email address. | 30 | Represents a person, by name and email address. | ||
31 | 31 | | |||
32 | @author Cornelius Schumacher \<schumacher@kde.org\> | 32 | @author Cornelius Schumacher \<schumacher@kde.org\> | ||
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 <QRegExp> | 38 | #include <QRegExp> | ||
38 | #include <QDataStream> | 39 | #include <QDataStream> | ||
39 | 40 | | |||
40 | using namespace KCalCore; | 41 | using namespace KCalCore; | ||
41 | 42 | | |||
42 | /** | 43 | /** | ||
43 | Private class that helps to provide binary compatibility between releases. | 44 | Private class that helps to provide binary compatibility between releases. | ||
44 | @internal | 45 | @internal | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 91 | { | |||
92 | if (&person == this) { | 93 | if (&person == this) { | ||
93 | return *this; | 94 | return *this; | ||
94 | } | 95 | } | ||
95 | 96 | | |||
96 | *d = *person.d; | 97 | *d = *person.d; | ||
97 | return *this; | 98 | return *this; | ||
98 | } | 99 | } | ||
99 | 100 | | |||
100 | QString Person::fullName() const | 101 | QString KCalCore::fullNameHelper(const QString &name, const QString &email) | ||
101 | { | 102 | { | ||
102 | if (d->mName.isEmpty()) { | 103 | if (name.isEmpty()) { | ||
103 | return d->mEmail; | 104 | return email; | ||
104 | } else { | 105 | } | ||
105 | if (d->mEmail.isEmpty()) { | 106 | if (email.isEmpty()) { | ||
106 | return d->mName; | 107 | return name; | ||
107 | } else { | 108 | } | ||
108 | // Taken from KContacts::Addressee::fullEmail | 109 | // Taken from KContacts::Addressee::fullEmail | ||
109 | QString name = d->mName; | 110 | QString fullName = name; | ||
110 | QRegExp needQuotes(QStringLiteral("[^ 0-9A-Za-z\\x0080-\\xFFFF]")); | 111 | QRegExp needQuotes(QStringLiteral("[^ 0-9A-Za-z\\x0080-\\xFFFF]")); | ||
111 | bool weNeedToQuote = name.indexOf(needQuotes) != -1; | 112 | bool weNeedToQuote = name.indexOf(needQuotes) != -1; | ||
112 | if (weNeedToQuote) { | 113 | if (weNeedToQuote) { | ||
113 | if (name[0] != QLatin1Char('"')) { | 114 | if (fullName[0] != QLatin1Char('"')) { | ||
114 | name.prepend(QLatin1Char('"')); | 115 | fullName.prepend(QLatin1Char('"')); | ||
115 | } | | |||
116 | if (name[ name.length() - 1 ] != QLatin1Char('"')) { | | |||
117 | name.append(QLatin1Char('"')); | | |||
118 | } | 116 | } | ||
117 | if (fullName[ fullName.length() - 1 ] != QLatin1Char('"')) { | ||||
118 | fullName.append(QLatin1Char('"')); | ||||
119 | } | 119 | } | ||
120 | return name + QStringLiteral(" <") + d->mEmail + QLatin1Char('>'); | | |||
121 | } | 120 | } | ||
121 | return fullName + QStringLiteral(" <") + email + QLatin1Char('>'); | ||||
122 | } | 122 | } | ||
123 | | ||||
124 | QString Person::fullName() const | ||||
125 | { | ||||
126 | return fullNameHelper(d->mName, d->mEmail); | ||||
123 | } | 127 | } | ||
124 | 128 | | |||
125 | QString Person::name() const | 129 | QString Person::name() const | ||
126 | { | 130 | { | ||
127 | return d->mName; | 131 | return d->mName; | ||
128 | } | 132 | } | ||
129 | 133 | | |||
130 | QString Person::email() const | 134 | QString Person::email() const | ||
▲ Show 20 Lines • Show All 255 Lines • Show Last 20 Lines |