|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include "qmessageaddress.h" |
|
42 #include "qmessageaddress_p.h" |
|
43 #include "addresshelper_p.h" |
|
44 |
|
45 QTM_BEGIN_NAMESPACE |
|
46 |
|
47 /*! |
|
48 \class QMessageAddress |
|
49 |
|
50 \preliminary |
|
51 \brief The QMessageAddress class provides an interface for a message address. |
|
52 |
|
53 \ingroup messaging |
|
54 |
|
55 A message address consists of a recipient string and a type. |
|
56 */ |
|
57 |
|
58 /*! |
|
59 \enum QMessageAddress::Type |
|
60 |
|
61 This enum type is used to describe the type of a message address. |
|
62 |
|
63 \value System A system address. |
|
64 \value Phone A telephony address. |
|
65 \value Email An Email, Internet Message Format address. |
|
66 \value Xmpp An XMPP, Extensible Messaging and Presence Protocol address. |
|
67 |
|
68 \sa type(), setType() |
|
69 */ |
|
70 |
|
71 /*! |
|
72 Constructs an empty message address. |
|
73 */ |
|
74 QMessageAddress::QMessageAddress() |
|
75 : d_ptr(new QMessageAddressPrivate(this)) |
|
76 { |
|
77 d_ptr->type = QMessageAddress::System; |
|
78 } |
|
79 |
|
80 /*! |
|
81 Constructs a message address with the type \a type and the recipient address \a recipient. |
|
82 */ |
|
83 QMessageAddress::QMessageAddress(Type type, const QString &recipient) |
|
84 : d_ptr(new QMessageAddressPrivate(this)) |
|
85 { |
|
86 d_ptr->type = type; |
|
87 d_ptr->recipient = recipient; |
|
88 } |
|
89 |
|
90 /*! |
|
91 Constructs a copy of \a other. |
|
92 */ |
|
93 QMessageAddress::QMessageAddress(const QMessageAddress &other) |
|
94 : d_ptr(new QMessageAddressPrivate(this)) |
|
95 { |
|
96 this->operator=(other); |
|
97 } |
|
98 |
|
99 /*! \internal */ |
|
100 QMessageAddress& QMessageAddress::operator=(const QMessageAddress& other) |
|
101 { |
|
102 if (&other != this) { |
|
103 d_ptr->recipient = other.d_ptr->recipient; |
|
104 d_ptr->type = other.d_ptr->type; |
|
105 } |
|
106 |
|
107 return *this; |
|
108 } |
|
109 |
|
110 /*! |
|
111 Destroys the message address. |
|
112 */ |
|
113 QMessageAddress::~QMessageAddress() |
|
114 { |
|
115 delete d_ptr; |
|
116 d_ptr = 0; |
|
117 } |
|
118 |
|
119 /*! \internal */ |
|
120 bool QMessageAddress::operator==(const QMessageAddress& other) const |
|
121 { |
|
122 return ((d_ptr->type == other.d_ptr->type) && (d_ptr->recipient == other.d_ptr->recipient)); |
|
123 } |
|
124 |
|
125 /*! \internal */ |
|
126 bool QMessageAddress::operator!=(const QMessageAddress& other) const |
|
127 { |
|
128 return !operator==(other); |
|
129 } |
|
130 |
|
131 /*! |
|
132 Returns the recipient. |
|
133 |
|
134 \sa setRecipient() |
|
135 */ |
|
136 QString QMessageAddress::recipient() const |
|
137 { |
|
138 return d_ptr->recipient; |
|
139 } |
|
140 |
|
141 /*! |
|
142 Sets the recipient to \a recipient. |
|
143 |
|
144 \sa recipient() |
|
145 */ |
|
146 void QMessageAddress::setRecipient(const QString &recipient) |
|
147 { |
|
148 d_ptr->recipient = recipient; |
|
149 } |
|
150 |
|
151 /*! |
|
152 Returns the type of the message address. |
|
153 |
|
154 \sa setType() |
|
155 */ |
|
156 QMessageAddress::Type QMessageAddress::type() const |
|
157 { |
|
158 return d_ptr->type; |
|
159 } |
|
160 |
|
161 /*! |
|
162 Sets the type of the message address to \a type. |
|
163 |
|
164 \sa type() |
|
165 */ |
|
166 void QMessageAddress::setType(Type type) |
|
167 { |
|
168 d_ptr->type = type; |
|
169 } |
|
170 |
|
171 /*! |
|
172 Parses an email address into name, address and suffix parts. |
|
173 |
|
174 * \a name is set to the name part of the email address. |
|
175 * \a address is set to the address part of the email address. |
|
176 * \a suffix is set to the suffix part of the email address. |
|
177 |
|
178 If the starting delimeter between the name and address part of the email address is found |
|
179 then * \a startDelimeterFound is set to true; otherwise * \a startDelimeterFound is set to false; |
|
180 |
|
181 If the starting delimeter is not found, then the parsing is ambiguous and both * \a name and |
|
182 * \a address will be set to the input \a emailAddress. |
|
183 |
|
184 If the ending delimeter of the address part of the email address is found |
|
185 then * \a endDelimeterFound is set to true; otherwise * \a endDelimeterFound is set to false; |
|
186 |
|
187 */ |
|
188 void QMessageAddress::parseEmailAddress(const QString &emailAddress, QString *name, QString *address, QString *suffix, bool *startDelimeterFound, bool *endDelimeterFound) |
|
189 { |
|
190 QString *aName(name); |
|
191 QString strName; |
|
192 if (!aName) |
|
193 aName = &strName; |
|
194 |
|
195 QString *aAddress(address); |
|
196 QString strAddress; |
|
197 if (!aAddress) |
|
198 aAddress = &strAddress; |
|
199 |
|
200 QString *aSuffix(suffix); |
|
201 QString strSuffix; |
|
202 if (!aSuffix) |
|
203 aSuffix = &strSuffix; |
|
204 |
|
205 bool *aStartDelimeterFound(startDelimeterFound); |
|
206 bool ignored1; |
|
207 if (!aStartDelimeterFound) |
|
208 aStartDelimeterFound = &ignored1; |
|
209 |
|
210 bool *aEndDelimeterFound(endDelimeterFound); |
|
211 bool ignored2; |
|
212 if (!aEndDelimeterFound) |
|
213 aEndDelimeterFound = &ignored2; |
|
214 |
|
215 QString emailAddressCopy(emailAddress); |
|
216 qParseMailbox(emailAddressCopy, *aName, *aAddress, *aSuffix, *aStartDelimeterFound, *aEndDelimeterFound); |
|
217 } |
|
218 |
|
219 /*! \typedef QMessageAddressList |
|
220 |
|
221 Qt-style synonym for QList<QMessageAddress> |
|
222 */ |
|
223 |
|
224 QTM_END_NAMESPACE |