-rw-r--r-- | kabc/address.h | 346 |
1 files changed, 346 insertions, 0 deletions
diff --git a/kabc/address.h b/kabc/address.h new file mode 100644 index 0000000..ad132a7 --- a/dev/null +++ b/kabc/address.h | |||
@@ -0,0 +1,346 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #ifndef KABC_ADDRESS_H | ||
29 | #define KABC_ADDRESS_H | ||
30 | |||
31 | #include <qmap.h> | ||
32 | #include <qstring.h> | ||
33 | #include <qvaluelist.h> | ||
34 | |||
35 | // template tags for address formatting localization | ||
36 | #define KABC_FMTTAG_realname QString("%n") | ||
37 | #define KABC_FMTTAG_REALNAME QString("%N") | ||
38 | #define KABC_FMTTAG_company QString("%cm") | ||
39 | #define KABC_FMTTAG_COMPANY QString("%CM") | ||
40 | #define KABC_FMTTAG_pobox QString("%p") | ||
41 | #define KABC_FMTTAG_street QString("%s") | ||
42 | #define KABC_FMTTAG_STREET QString("%S") | ||
43 | #define KABC_FMTTAG_zipcode QString("%z") | ||
44 | #define KABC_FMTTAG_location QString("%l") | ||
45 | #define KABC_FMTTAG_LOCATION QString("%L") | ||
46 | #define KABC_FMTTAG_region QString("%r") | ||
47 | #define KABC_FMTTAG_REGION QString("%R") | ||
48 | #define KABC_FMTTAG_newline QString("\\n") | ||
49 | #define KABC_FMTTAG_condcomma QString("%,") | ||
50 | #define KABC_FMTTAG_condwhite QString("%w") | ||
51 | #define KABC_FMTTAG_purgeempty QString("%0") | ||
52 | |||
53 | namespace KABC { | ||
54 | |||
55 | /** | ||
56 | @short Postal address information. | ||
57 | |||
58 | This class represents information about a postal address. | ||
59 | */ | ||
60 | class Address | ||
61 | { | ||
62 | friend QDataStream &operator<<( QDataStream &, const Address & ); | ||
63 | friend QDataStream &operator>>( QDataStream &, Address & ); | ||
64 | |||
65 | public: | ||
66 | /** | ||
67 | List of addresses. | ||
68 | */ | ||
69 | typedef QValueList<Address> List; | ||
70 | typedef QValueList<int> TypeList; | ||
71 | |||
72 | /** | ||
73 | Address types: | ||
74 | |||
75 | @li @p Dom - domestic | ||
76 | @li @p Intl - international | ||
77 | @li @p Postal - postal | ||
78 | @li @p Parcel - parcel | ||
79 | @li @p Home - home address | ||
80 | @li @p Work - address at work | ||
81 | @li @p Pref - preferred address | ||
82 | */ | ||
83 | enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32, | ||
84 | Pref = 64 }; | ||
85 | |||
86 | /** | ||
87 | Constructor that creates an empty Address, which is initialized | ||
88 | with a unique id (see @ref id()). | ||
89 | */ | ||
90 | Address(); | ||
91 | |||
92 | /** | ||
93 | This is like @ref Address() just above, with the difference | ||
94 | that you can specify the type. | ||
95 | */ | ||
96 | Address( int ); | ||
97 | |||
98 | bool operator==( const Address & ) const; | ||
99 | bool operator!=( const Address & ) const; | ||
100 | |||
101 | /** | ||
102 | Returns true, if the address is empty. | ||
103 | */ | ||
104 | bool isEmpty() const; | ||
105 | |||
106 | /** | ||
107 | Clears all entries of the address. | ||
108 | */ | ||
109 | void clear(); | ||
110 | |||
111 | /** | ||
112 | Sets the unique id. | ||
113 | */ | ||
114 | void setId( const QString & ); | ||
115 | |||
116 | /* | ||
117 | Returns the unique id. | ||
118 | */ | ||
119 | QString id() const; | ||
120 | |||
121 | /** | ||
122 | Sets the type of address. See enum for definiton of types. | ||
123 | |||
124 | @param type type, can be a bitwise or of multiple types. | ||
125 | */ | ||
126 | void setType( int type ); | ||
127 | |||
128 | /** | ||
129 | Returns the type of address. Can be a bitwise or of multiple types. | ||
130 | */ | ||
131 | int type() const; | ||
132 | |||
133 | /** | ||
134 | Returns a translated string of all types the address has. | ||
135 | */ | ||
136 | QString typeLabel() const; | ||
137 | |||
138 | /** | ||
139 | Sets the post office box. | ||
140 | */ | ||
141 | void setPostOfficeBox( const QString & ); | ||
142 | |||
143 | /** | ||
144 | Returns the post office box. | ||
145 | */ | ||
146 | QString postOfficeBox() const; | ||
147 | |||
148 | /** | ||
149 | Returns the translated label for post office box field. | ||
150 | */ | ||
151 | static QString postOfficeBoxLabel(); | ||
152 | |||
153 | /** | ||
154 | Sets the extended address information. | ||
155 | */ | ||
156 | void setExtended( const QString & ); | ||
157 | |||
158 | /** | ||
159 | Returns the extended address information. | ||
160 | */ | ||
161 | QString extended() const; | ||
162 | |||
163 | /** | ||
164 | Returns the translated label for extended field. | ||
165 | */ | ||
166 | static QString extendedLabel(); | ||
167 | |||
168 | /** | ||
169 | Sets the street (including number). | ||
170 | */ | ||
171 | void setStreet( const QString & ); | ||
172 | |||
173 | /** | ||
174 | Returns the street. | ||
175 | */ | ||
176 | QString street() const; | ||
177 | |||
178 | /** | ||
179 | Returns the translated label for street field. | ||
180 | */ | ||
181 | static QString streetLabel(); | ||
182 | |||
183 | /** | ||
184 | Sets the locality, e.g. city. | ||
185 | */ | ||
186 | void setLocality( const QString & ); | ||
187 | |||
188 | /** | ||
189 | Returns the locality. | ||
190 | */ | ||
191 | QString locality() const; | ||
192 | |||
193 | /** | ||
194 | Returns the translated label for locality field. | ||
195 | */ | ||
196 | static QString localityLabel(); | ||
197 | |||
198 | /** | ||
199 | Sets the region, e.g. state. | ||
200 | */ | ||
201 | void setRegion( const QString & ); | ||
202 | |||
203 | /** | ||
204 | Returns the region. | ||
205 | */ | ||
206 | QString region() const; | ||
207 | |||
208 | /** | ||
209 | Returns the translated label for region field. | ||
210 | */ | ||
211 | static QString regionLabel(); | ||
212 | |||
213 | /** | ||
214 | Sets the postal code. | ||
215 | */ | ||
216 | void setPostalCode( const QString & ); | ||
217 | |||
218 | /** | ||
219 | Returns the postal code. | ||
220 | */ | ||
221 | QString postalCode() const; | ||
222 | |||
223 | /** | ||
224 | Returns the translated label for postal code field. | ||
225 | */ | ||
226 | static QString postalCodeLabel(); | ||
227 | |||
228 | /** | ||
229 | Sets the country. | ||
230 | */ | ||
231 | void setCountry( const QString & ); | ||
232 | |||
233 | /** | ||
234 | Returns the country. | ||
235 | */ | ||
236 | QString country() const; | ||
237 | |||
238 | /** | ||
239 | Returns the translated label for country field. | ||
240 | */ | ||
241 | static QString countryLabel(); | ||
242 | |||
243 | /** | ||
244 | Sets the delivery label. This is the literal text to be used as label. | ||
245 | */ | ||
246 | void setLabel( const QString & ); | ||
247 | |||
248 | /** | ||
249 | Returns the delivery label. | ||
250 | */ | ||
251 | QString label() const; | ||
252 | |||
253 | /** | ||
254 | Returns the translated label for delivery label field. | ||
255 | */ | ||
256 | static QString labelLabel(); | ||
257 | |||
258 | /** | ||
259 | Returns the list of available types. | ||
260 | */ | ||
261 | static TypeList typeList(); | ||
262 | |||
263 | /** | ||
264 | Returns the translated label for a special type. | ||
265 | */ | ||
266 | static QString typeLabel( int type ); | ||
267 | |||
268 | /** | ||
269 | Used for debug output. | ||
270 | */ | ||
271 | void dump() const; | ||
272 | |||
273 | /** | ||
274 | Returns this address formatted according to the country-specific | ||
275 | address formatting rules. The formatting rules applied depend on | ||
276 | either the addresses {@link #country country} field, or (if the | ||
277 | latter is empty) on the system country setting. If companyName is | ||
278 | provided, an available business address format will be preferred. | ||
279 | |||
280 | @param realName the formatted name of the contact | ||
281 | @param orgaName the name of the organization or company | ||
282 | @return the formatted address (containing newline characters) | ||
283 | */ | ||
284 | QString formattedAddress( const QString &realName=QString::null | ||
285 | , const QString &orgaName=QString::null ) const; | ||
286 | |||
287 | /** | ||
288 | Returns ISO code for a localized country name. Only localized country | ||
289 | names will be understood. This might be replaced by a KLocale method in | ||
290 | the future. | ||
291 | @param cname name of the country | ||
292 | @return two digit ISO code | ||
293 | */ | ||
294 | static QString countryToISO( const QString &cname ); | ||
295 | |||
296 | /** | ||
297 | Returns a localized country name for a ISO code. | ||
298 | This might be replaced by a KLocale method in the future. | ||
299 | @param ISOname two digit ISO code | ||
300 | @return localized name of the country | ||
301 | @since 3.2 | ||
302 | */ | ||
303 | static QString ISOtoCountry( const QString &ISOname ); | ||
304 | |||
305 | private: | ||
306 | /** | ||
307 | Parses a snippet of an address template | ||
308 | @param tsection the template string to be parsed | ||
309 | @param result QString reference in which the result will be stored | ||
310 | @return true if at least one tag evaluated positively, else false | ||
311 | */ | ||
312 | bool parseAddressTemplateSection( const QString &tsection | ||
313 | , QString &result | ||
314 | , const QString &realName | ||
315 | , const QString &orgaName ) const; | ||
316 | |||
317 | /** | ||
318 | Finds the balanced closing bracket starting from the opening bracket at | ||
319 | pos in tsection. | ||
320 | @return position of closing bracket, -1 for unbalanced brackets | ||
321 | */ | ||
322 | int findBalancedBracket( const QString &tsection, int pos ) const; | ||
323 | |||
324 | bool mEmpty; | ||
325 | |||
326 | QString mId; | ||
327 | int mType; | ||
328 | |||
329 | QString mPostOfficeBox; | ||
330 | QString mExtended; | ||
331 | QString mStreet; | ||
332 | QString mLocality; | ||
333 | QString mRegion; | ||
334 | QString mPostalCode; | ||
335 | QString mCountry; | ||
336 | QString mLabel; | ||
337 | |||
338 | static QMap<QString, QString> mISOMap; | ||
339 | }; | ||
340 | |||
341 | QDataStream &operator<<( QDataStream &, const Address & ); | ||
342 | QDataStream &operator>>( QDataStream &, Address & ); | ||
343 | |||
344 | } | ||
345 | |||
346 | #endif | ||