-rw-r--r-- | kabc/address.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp index 5ffe511..6151f9e 100644 --- a/kabc/address.cpp +++ b/kabc/address.cpp | |||
@@ -1,295 +1,322 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 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 | 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, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | //US added kglobal.h | 28 | //US added kglobal.h |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | 30 | ||
31 | #include <kapplication.h> | 31 | #include <kapplication.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | #include <ksimpleconfig.h> | 34 | #include <ksimpleconfig.h> |
35 | #include <kstandarddirs.h> | 35 | #include <kstandarddirs.h> |
36 | 36 | ||
37 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | 38 | ||
39 | #include "address.h" | 39 | #include "address.h" |
40 | 40 | ||
41 | using namespace KABC; | 41 | using namespace KABC; |
42 | 42 | ||
43 | QMap<QString, QString> Address::mISOMap; | 43 | QMap<QString, QString> Address::mISOMap; |
44 | 44 | ||
45 | Address::Address() : | 45 | Address::Address() : |
46 | mEmpty( true ), mType( 0 ) | 46 | mEmpty( true ), mType( 0 ) |
47 | { | 47 | { |
48 | mId = KApplication::randomString( 10 ); | 48 | mId = KApplication::randomString( 10 ); |
49 | } | 49 | } |
50 | 50 | ||
51 | Address::Address( int type ) : | 51 | Address::Address( int type ) : |
52 | mEmpty( true ), mType( type ) | 52 | mEmpty( true ), mType( type ) |
53 | { | 53 | { |
54 | mId = KApplication::randomString( 10 ); | 54 | mId = KApplication::randomString( 10 ); |
55 | } | 55 | } |
56 | 56 | ||
57 | bool Address::operator==( const Address &a ) const | 57 | bool Address::operator==( const Address &a ) const |
58 | { | 58 | { |
59 | if ( mPostOfficeBox != a.mPostOfficeBox ) return false; | 59 | if ( mPostOfficeBox != a.mPostOfficeBox ) return false; |
60 | if ( mExtended != a.mExtended ) return false; | 60 | if ( mExtended != a.mExtended ) return false; |
61 | if ( mStreet != a.mStreet ) return false; | 61 | if ( mStreet != a.mStreet ) return false; |
62 | if ( mLocality != a.mLocality ) return false; | 62 | if ( mLocality != a.mLocality ) return false; |
63 | if ( mRegion != a.mRegion ) return false; | 63 | if ( mRegion != a.mRegion ) return false; |
64 | if ( mPostalCode != a.mPostalCode ) return false; | 64 | if ( mPostalCode != a.mPostalCode ) return false; |
65 | if ( mCountry != a.mCountry ) return false; | 65 | if ( mCountry != a.mCountry ) return false; |
66 | if ( mLabel != a.mLabel ) return false; | 66 | if ( mLabel != a.mLabel ) return false; |
67 | 67 | ||
68 | return true; | 68 | return true; |
69 | } | 69 | } |
70 | 70 | ||
71 | bool Address::operator!=( const Address &a ) const | 71 | bool Address::operator!=( const Address &a ) const |
72 | { | 72 | { |
73 | return !( a == *this ); | 73 | return !( a == *this ); |
74 | } | 74 | } |
75 | 75 | ||
76 | bool Address::isEmpty() const | 76 | bool Address::isEmpty() const |
77 | { | 77 | { |
78 | if ( mPostOfficeBox.isEmpty() && | 78 | if ( mPostOfficeBox.isEmpty() && |
79 | mExtended.isEmpty() && | 79 | mExtended.isEmpty() && |
80 | mStreet.isEmpty() && | 80 | mStreet.isEmpty() && |
81 | mLocality.isEmpty() && | 81 | mLocality.isEmpty() && |
82 | mRegion.isEmpty() && | 82 | mRegion.isEmpty() && |
83 | mPostalCode.isEmpty() && | 83 | mPostalCode.isEmpty() && |
84 | mCountry.isEmpty() && | 84 | mCountry.isEmpty() && |
85 | mLabel.isEmpty() ) { | 85 | mLabel.isEmpty() ) { |
86 | return true; | 86 | return true; |
87 | } | 87 | } |
88 | return false; | 88 | return false; |
89 | } | 89 | } |
90 | 90 | ||
91 | QStringList Address::asList() | 91 | QStringList Address::asList() |
92 | { | 92 | { |
93 | QStringList result; | 93 | QStringList result; |
94 | if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox); | 94 | if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox); |
95 | if ( ! mExtended.isEmpty())result.append(mExtended); | 95 | if ( ! mExtended.isEmpty())result.append(mExtended); |
96 | if ( ! mStreet.isEmpty())result.append(mStreet); | 96 | if ( ! mStreet.isEmpty())result.append(mStreet); |
97 | if ( ! mLocality.isEmpty() )result.append(mLocality); | 97 | if ( ! mLocality.isEmpty() )result.append(mLocality); |
98 | if ( ! mRegion.isEmpty())result.append(mRegion); | 98 | if ( ! mRegion.isEmpty())result.append(mRegion); |
99 | if ( ! mPostalCode.isEmpty())result.append(mPostalCode); | 99 | if ( ! mPostalCode.isEmpty())result.append(mPostalCode); |
100 | if ( ! mCountry.isEmpty())result.append(mCountry); | 100 | if ( ! mCountry.isEmpty())result.append(mCountry); |
101 | if ( ! mLabel.isEmpty() )result.append(mLabel); | 101 | if ( ! mLabel.isEmpty() )result.append(mLabel); |
102 | return result; | 102 | return result; |
103 | } | 103 | } |
104 | |||
105 | bool Address::matchAddress( QRegExp* re ) const | ||
106 | { | ||
107 | |||
108 | #if QT_VERSION >= 0x030000 | ||
109 | if (re->search( mPostOfficeBox ) == 0) return true; | ||
110 | if (re->search( mExtended ) == 0) return true; | ||
111 | if (re->search( mStreet ) == 0) return true; | ||
112 | if (re->search( mLocality ) == 0) return true; | ||
113 | if (re->search( mRegion ) == 0) return true; | ||
114 | if (re->search( mPostalCode ) == 0) return true; | ||
115 | if (re->search( mCountry ) == 0) return true; | ||
116 | if (re->search( mLabel ) == 0) return true; | ||
117 | #else | ||
118 | if (re->match( mPostOfficeBox ) == 0) return true; | ||
119 | if (re->match( mExtended ) == 0) return true; | ||
120 | if (re->match( mStreet ) == 0) return true; | ||
121 | if (re->match( mLocality ) == 0) return true; | ||
122 | if (re->match( mRegion ) == 0) return true; | ||
123 | if (re->match( mPostalCode ) == 0) return true; | ||
124 | if (re->match( mCountry ) == 0) return true; | ||
125 | if (re->match( mLabel ) == 0) return true; | ||
126 | #endif | ||
127 | |||
128 | return false; | ||
129 | } | ||
130 | |||
104 | void Address::clear() | 131 | void Address::clear() |
105 | { | 132 | { |
106 | *this = Address(); | 133 | *this = Address(); |
107 | } | 134 | } |
108 | 135 | ||
109 | void Address::setId( const QString &id ) | 136 | void Address::setId( const QString &id ) |
110 | { | 137 | { |
111 | mEmpty = false; | 138 | mEmpty = false; |
112 | 139 | ||
113 | mId = id; | 140 | mId = id; |
114 | } | 141 | } |
115 | 142 | ||
116 | QString Address::id() const | 143 | QString Address::id() const |
117 | { | 144 | { |
118 | return mId; | 145 | return mId; |
119 | } | 146 | } |
120 | 147 | ||
121 | void Address::setType( int type ) | 148 | void Address::setType( int type ) |
122 | { | 149 | { |
123 | mEmpty = false; | 150 | mEmpty = false; |
124 | 151 | ||
125 | mType = type; | 152 | mType = type; |
126 | } | 153 | } |
127 | 154 | ||
128 | int Address::type() const | 155 | int Address::type() const |
129 | { | 156 | { |
130 | return mType; | 157 | return mType; |
131 | } | 158 | } |
132 | 159 | ||
133 | QString Address::typeLabel() const | 160 | QString Address::typeLabel() const |
134 | { | 161 | { |
135 | QString label; | 162 | QString label; |
136 | bool first = true; | 163 | bool first = true; |
137 | 164 | ||
138 | TypeList list = typeList(); | 165 | TypeList list = typeList(); |
139 | 166 | ||
140 | TypeList::Iterator it; | 167 | TypeList::Iterator it; |
141 | for ( it = list.begin(); it != list.end(); ++it ) { | 168 | for ( it = list.begin(); it != list.end(); ++it ) { |
142 | if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { | 169 | if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { |
143 | label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); | 170 | label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); |
144 | if ( first ) | 171 | if ( first ) |
145 | first = false; | 172 | first = false; |
146 | } | 173 | } |
147 | } | 174 | } |
148 | 175 | ||
149 | return label; | 176 | return label; |
150 | } | 177 | } |
151 | 178 | ||
152 | void Address::setPostOfficeBox( const QString &s ) | 179 | void Address::setPostOfficeBox( const QString &s ) |
153 | { | 180 | { |
154 | mEmpty = false; | 181 | mEmpty = false; |
155 | 182 | ||
156 | mPostOfficeBox = s; | 183 | mPostOfficeBox = s; |
157 | } | 184 | } |
158 | 185 | ||
159 | QString Address::postOfficeBox() const | 186 | QString Address::postOfficeBox() const |
160 | { | 187 | { |
161 | return mPostOfficeBox; | 188 | return mPostOfficeBox; |
162 | } | 189 | } |
163 | 190 | ||
164 | QString Address::postOfficeBoxLabel() | 191 | QString Address::postOfficeBoxLabel() |
165 | { | 192 | { |
166 | return i18n("Post Office Box"); | 193 | return i18n("Post Office Box"); |
167 | } | 194 | } |
168 | 195 | ||
169 | 196 | ||
170 | void Address::setExtended( const QString &s ) | 197 | void Address::setExtended( const QString &s ) |
171 | { | 198 | { |
172 | mEmpty = false; | 199 | mEmpty = false; |
173 | 200 | ||
174 | mExtended = s; | 201 | mExtended = s; |
175 | } | 202 | } |
176 | 203 | ||
177 | QString Address::extended() const | 204 | QString Address::extended() const |
178 | { | 205 | { |
179 | return mExtended; | 206 | return mExtended; |
180 | } | 207 | } |
181 | 208 | ||
182 | QString Address::extendedLabel() | 209 | QString Address::extendedLabel() |
183 | { | 210 | { |
184 | return i18n("Extended Address Information"); | 211 | return i18n("Extended Address Information"); |
185 | } | 212 | } |
186 | 213 | ||
187 | 214 | ||
188 | void Address::setStreet( const QString &s ) | 215 | void Address::setStreet( const QString &s ) |
189 | { | 216 | { |
190 | mEmpty = false; | 217 | mEmpty = false; |
191 | 218 | ||
192 | mStreet = s; | 219 | mStreet = s; |
193 | } | 220 | } |
194 | 221 | ||
195 | QString Address::street() const | 222 | QString Address::street() const |
196 | { | 223 | { |
197 | return mStreet; | 224 | return mStreet; |
198 | } | 225 | } |
199 | 226 | ||
200 | QString Address::streetLabel() | 227 | QString Address::streetLabel() |
201 | { | 228 | { |
202 | return i18n("Street"); | 229 | return i18n("Street"); |
203 | } | 230 | } |
204 | 231 | ||
205 | 232 | ||
206 | void Address::setLocality( const QString &s ) | 233 | void Address::setLocality( const QString &s ) |
207 | { | 234 | { |
208 | mEmpty = false; | 235 | mEmpty = false; |
209 | 236 | ||
210 | mLocality = s; | 237 | mLocality = s; |
211 | } | 238 | } |
212 | 239 | ||
213 | QString Address::locality() const | 240 | QString Address::locality() const |
214 | { | 241 | { |
215 | return mLocality; | 242 | return mLocality; |
216 | } | 243 | } |
217 | 244 | ||
218 | QString Address::localityLabel() | 245 | QString Address::localityLabel() |
219 | { | 246 | { |
220 | return i18n("Locality"); | 247 | return i18n("Locality"); |
221 | } | 248 | } |
222 | 249 | ||
223 | 250 | ||
224 | void Address::setRegion( const QString &s ) | 251 | void Address::setRegion( const QString &s ) |
225 | { | 252 | { |
226 | mEmpty = false; | 253 | mEmpty = false; |
227 | 254 | ||
228 | mRegion = s; | 255 | mRegion = s; |
229 | } | 256 | } |
230 | 257 | ||
231 | QString Address::region() const | 258 | QString Address::region() const |
232 | { | 259 | { |
233 | return mRegion; | 260 | return mRegion; |
234 | } | 261 | } |
235 | 262 | ||
236 | QString Address::regionLabel() | 263 | QString Address::regionLabel() |
237 | { | 264 | { |
238 | return i18n("Region"); | 265 | return i18n("Region"); |
239 | } | 266 | } |
240 | 267 | ||
241 | 268 | ||
242 | void Address::setPostalCode( const QString &s ) | 269 | void Address::setPostalCode( const QString &s ) |
243 | { | 270 | { |
244 | mEmpty = false; | 271 | mEmpty = false; |
245 | 272 | ||
246 | mPostalCode = s; | 273 | mPostalCode = s; |
247 | } | 274 | } |
248 | 275 | ||
249 | QString Address::postalCode() const | 276 | QString Address::postalCode() const |
250 | { | 277 | { |
251 | return mPostalCode; | 278 | return mPostalCode; |
252 | } | 279 | } |
253 | 280 | ||
254 | QString Address::postalCodeLabel() | 281 | QString Address::postalCodeLabel() |
255 | { | 282 | { |
256 | return i18n("Postal Code"); | 283 | return i18n("Postal Code"); |
257 | } | 284 | } |
258 | 285 | ||
259 | 286 | ||
260 | void Address::setCountry( const QString &s ) | 287 | void Address::setCountry( const QString &s ) |
261 | { | 288 | { |
262 | mEmpty = false; | 289 | mEmpty = false; |
263 | 290 | ||
264 | mCountry = s; | 291 | mCountry = s; |
265 | } | 292 | } |
266 | 293 | ||
267 | QString Address::country() const | 294 | QString Address::country() const |
268 | { | 295 | { |
269 | return mCountry; | 296 | return mCountry; |
270 | } | 297 | } |
271 | 298 | ||
272 | QString Address::countryLabel() | 299 | QString Address::countryLabel() |
273 | { | 300 | { |
274 | return i18n("Country"); | 301 | return i18n("Country"); |
275 | } | 302 | } |
276 | 303 | ||
277 | 304 | ||
278 | void Address::setLabel( const QString &s ) | 305 | void Address::setLabel( const QString &s ) |
279 | { | 306 | { |
280 | mEmpty = false; | 307 | mEmpty = false; |
281 | 308 | ||
282 | mLabel = s; | 309 | mLabel = s; |
283 | } | 310 | } |
284 | 311 | ||
285 | QString Address::label() const | 312 | QString Address::label() const |
286 | { | 313 | { |
287 | return mLabel; | 314 | return mLabel; |
288 | } | 315 | } |
289 | 316 | ||
290 | QString Address::labelLabel() | 317 | QString Address::labelLabel() |
291 | { | 318 | { |
292 | return i18n("Delivery Label"); | 319 | return i18n("Delivery Label"); |
293 | } | 320 | } |
294 | 321 | ||
295 | Address::TypeList Address::typeList() | 322 | Address::TypeList Address::typeList() |