-rw-r--r-- | kabc/address.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp index c820a6c..5ffe511 100644 --- a/kabc/address.cpp +++ b/kabc/address.cpp | |||
@@ -1,282 +1,295 @@ | |||
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() | ||
92 | { | ||
93 | QStringList result; | ||
94 | if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox); | ||
95 | if ( ! mExtended.isEmpty())result.append(mExtended); | ||
96 | if ( ! mStreet.isEmpty())result.append(mStreet); | ||
97 | if ( ! mLocality.isEmpty() )result.append(mLocality); | ||
98 | if ( ! mRegion.isEmpty())result.append(mRegion); | ||
99 | if ( ! mPostalCode.isEmpty())result.append(mPostalCode); | ||
100 | if ( ! mCountry.isEmpty())result.append(mCountry); | ||
101 | if ( ! mLabel.isEmpty() )result.append(mLabel); | ||
102 | return result; | ||
103 | } | ||
91 | void Address::clear() | 104 | void Address::clear() |
92 | { | 105 | { |
93 | *this = Address(); | 106 | *this = Address(); |
94 | } | 107 | } |
95 | 108 | ||
96 | void Address::setId( const QString &id ) | 109 | void Address::setId( const QString &id ) |
97 | { | 110 | { |
98 | mEmpty = false; | 111 | mEmpty = false; |
99 | 112 | ||
100 | mId = id; | 113 | mId = id; |
101 | } | 114 | } |
102 | 115 | ||
103 | QString Address::id() const | 116 | QString Address::id() const |
104 | { | 117 | { |
105 | return mId; | 118 | return mId; |
106 | } | 119 | } |
107 | 120 | ||
108 | void Address::setType( int type ) | 121 | void Address::setType( int type ) |
109 | { | 122 | { |
110 | mEmpty = false; | 123 | mEmpty = false; |
111 | 124 | ||
112 | mType = type; | 125 | mType = type; |
113 | } | 126 | } |
114 | 127 | ||
115 | int Address::type() const | 128 | int Address::type() const |
116 | { | 129 | { |
117 | return mType; | 130 | return mType; |
118 | } | 131 | } |
119 | 132 | ||
120 | QString Address::typeLabel() const | 133 | QString Address::typeLabel() const |
121 | { | 134 | { |
122 | QString label; | 135 | QString label; |
123 | bool first = true; | 136 | bool first = true; |
124 | 137 | ||
125 | TypeList list = typeList(); | 138 | TypeList list = typeList(); |
126 | 139 | ||
127 | TypeList::Iterator it; | 140 | TypeList::Iterator it; |
128 | for ( it = list.begin(); it != list.end(); ++it ) { | 141 | for ( it = list.begin(); it != list.end(); ++it ) { |
129 | if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { | 142 | if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { |
130 | label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); | 143 | label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); |
131 | if ( first ) | 144 | if ( first ) |
132 | first = false; | 145 | first = false; |
133 | } | 146 | } |
134 | } | 147 | } |
135 | 148 | ||
136 | return label; | 149 | return label; |
137 | } | 150 | } |
138 | 151 | ||
139 | void Address::setPostOfficeBox( const QString &s ) | 152 | void Address::setPostOfficeBox( const QString &s ) |
140 | { | 153 | { |
141 | mEmpty = false; | 154 | mEmpty = false; |
142 | 155 | ||
143 | mPostOfficeBox = s; | 156 | mPostOfficeBox = s; |
144 | } | 157 | } |
145 | 158 | ||
146 | QString Address::postOfficeBox() const | 159 | QString Address::postOfficeBox() const |
147 | { | 160 | { |
148 | return mPostOfficeBox; | 161 | return mPostOfficeBox; |
149 | } | 162 | } |
150 | 163 | ||
151 | QString Address::postOfficeBoxLabel() | 164 | QString Address::postOfficeBoxLabel() |
152 | { | 165 | { |
153 | return i18n("Post Office Box"); | 166 | return i18n("Post Office Box"); |
154 | } | 167 | } |
155 | 168 | ||
156 | 169 | ||
157 | void Address::setExtended( const QString &s ) | 170 | void Address::setExtended( const QString &s ) |
158 | { | 171 | { |
159 | mEmpty = false; | 172 | mEmpty = false; |
160 | 173 | ||
161 | mExtended = s; | 174 | mExtended = s; |
162 | } | 175 | } |
163 | 176 | ||
164 | QString Address::extended() const | 177 | QString Address::extended() const |
165 | { | 178 | { |
166 | return mExtended; | 179 | return mExtended; |
167 | } | 180 | } |
168 | 181 | ||
169 | QString Address::extendedLabel() | 182 | QString Address::extendedLabel() |
170 | { | 183 | { |
171 | return i18n("Extended Address Information"); | 184 | return i18n("Extended Address Information"); |
172 | } | 185 | } |
173 | 186 | ||
174 | 187 | ||
175 | void Address::setStreet( const QString &s ) | 188 | void Address::setStreet( const QString &s ) |
176 | { | 189 | { |
177 | mEmpty = false; | 190 | mEmpty = false; |
178 | 191 | ||
179 | mStreet = s; | 192 | mStreet = s; |
180 | } | 193 | } |
181 | 194 | ||
182 | QString Address::street() const | 195 | QString Address::street() const |
183 | { | 196 | { |
184 | return mStreet; | 197 | return mStreet; |
185 | } | 198 | } |
186 | 199 | ||
187 | QString Address::streetLabel() | 200 | QString Address::streetLabel() |
188 | { | 201 | { |
189 | return i18n("Street"); | 202 | return i18n("Street"); |
190 | } | 203 | } |
191 | 204 | ||
192 | 205 | ||
193 | void Address::setLocality( const QString &s ) | 206 | void Address::setLocality( const QString &s ) |
194 | { | 207 | { |
195 | mEmpty = false; | 208 | mEmpty = false; |
196 | 209 | ||
197 | mLocality = s; | 210 | mLocality = s; |
198 | } | 211 | } |
199 | 212 | ||
200 | QString Address::locality() const | 213 | QString Address::locality() const |
201 | { | 214 | { |
202 | return mLocality; | 215 | return mLocality; |
203 | } | 216 | } |
204 | 217 | ||
205 | QString Address::localityLabel() | 218 | QString Address::localityLabel() |
206 | { | 219 | { |
207 | return i18n("Locality"); | 220 | return i18n("Locality"); |
208 | } | 221 | } |
209 | 222 | ||
210 | 223 | ||
211 | void Address::setRegion( const QString &s ) | 224 | void Address::setRegion( const QString &s ) |
212 | { | 225 | { |
213 | mEmpty = false; | 226 | mEmpty = false; |
214 | 227 | ||
215 | mRegion = s; | 228 | mRegion = s; |
216 | } | 229 | } |
217 | 230 | ||
218 | QString Address::region() const | 231 | QString Address::region() const |
219 | { | 232 | { |
220 | return mRegion; | 233 | return mRegion; |
221 | } | 234 | } |
222 | 235 | ||
223 | QString Address::regionLabel() | 236 | QString Address::regionLabel() |
224 | { | 237 | { |
225 | return i18n("Region"); | 238 | return i18n("Region"); |
226 | } | 239 | } |
227 | 240 | ||
228 | 241 | ||
229 | void Address::setPostalCode( const QString &s ) | 242 | void Address::setPostalCode( const QString &s ) |
230 | { | 243 | { |
231 | mEmpty = false; | 244 | mEmpty = false; |
232 | 245 | ||
233 | mPostalCode = s; | 246 | mPostalCode = s; |
234 | } | 247 | } |
235 | 248 | ||
236 | QString Address::postalCode() const | 249 | QString Address::postalCode() const |
237 | { | 250 | { |
238 | return mPostalCode; | 251 | return mPostalCode; |
239 | } | 252 | } |
240 | 253 | ||
241 | QString Address::postalCodeLabel() | 254 | QString Address::postalCodeLabel() |
242 | { | 255 | { |
243 | return i18n("Postal Code"); | 256 | return i18n("Postal Code"); |
244 | } | 257 | } |
245 | 258 | ||
246 | 259 | ||
247 | void Address::setCountry( const QString &s ) | 260 | void Address::setCountry( const QString &s ) |
248 | { | 261 | { |
249 | mEmpty = false; | 262 | mEmpty = false; |
250 | 263 | ||
251 | mCountry = s; | 264 | mCountry = s; |
252 | } | 265 | } |
253 | 266 | ||
254 | QString Address::country() const | 267 | QString Address::country() const |
255 | { | 268 | { |
256 | return mCountry; | 269 | return mCountry; |
257 | } | 270 | } |
258 | 271 | ||
259 | QString Address::countryLabel() | 272 | QString Address::countryLabel() |
260 | { | 273 | { |
261 | return i18n("Country"); | 274 | return i18n("Country"); |
262 | } | 275 | } |
263 | 276 | ||
264 | 277 | ||
265 | void Address::setLabel( const QString &s ) | 278 | void Address::setLabel( const QString &s ) |
266 | { | 279 | { |
267 | mEmpty = false; | 280 | mEmpty = false; |
268 | 281 | ||
269 | mLabel = s; | 282 | mLabel = s; |
270 | } | 283 | } |
271 | 284 | ||
272 | QString Address::label() const | 285 | QString Address::label() const |
273 | { | 286 | { |
274 | return mLabel; | 287 | return mLabel; |
275 | } | 288 | } |
276 | 289 | ||
277 | QString Address::labelLabel() | 290 | QString Address::labelLabel() |
278 | { | 291 | { |
279 | return i18n("Delivery Label"); | 292 | return i18n("Delivery Label"); |
280 | } | 293 | } |
281 | 294 | ||
282 | Address::TypeList Address::typeList() | 295 | Address::TypeList Address::typeList() |