author | zautrix <zautrix> | 2005-01-17 12:18:59 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-17 12:18:59 (UTC) |
commit | 6b166ece0a576e9be9c71a61fab5424d75a9301f (patch) (unidiff) | |
tree | b88bf3e82cafc0ac279eb46b8ebc61f112083032 /kabc | |
parent | 376ffdba71ab4d7d7988229f38678394a54e5576 (diff) | |
download | kdepimpi-6b166ece0a576e9be9c71a61fab5424d75a9301f.zip kdepimpi-6b166ece0a576e9be9c71a61fab5424d75a9301f.tar.gz kdepimpi-6b166ece0a576e9be9c71a61fab5424d75a9301f.tar.bz2 |
many AB fixes
-rw-r--r-- | kabc/addressbook.cpp | 9 | ||||
-rw-r--r-- | kabc/addressee.cpp | 8 | ||||
-rw-r--r-- | kabc/secrecy.h | 2 | ||||
-rw-r--r-- | kabc/vcard/VCardv.cpp | 2 |
4 files changed, 15 insertions, 6 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 8487ff3..4de7da2 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,1259 +1,1266 @@ | |||
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 | 28 | /*US |
29 | 29 | ||
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | 33 | ||
34 | #include <kapplication.h> | 34 | #include <kapplication.h> |
35 | #include <kinstance.h> | 35 | #include <kinstance.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | 37 | ||
38 | #include "errorhandler.h" | 38 | #include "errorhandler.h" |
39 | */ | 39 | */ |
40 | #include <qptrlist.h> | 40 | #include <qptrlist.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qfile.h> | 42 | #include <qfile.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | 44 | ||
45 | #include <kglobal.h> | 45 | #include <kglobal.h> |
46 | #include <klocale.h> | 46 | #include <klocale.h> |
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | #include <kdebug.h> | 48 | #include <kdebug.h> |
49 | #include <libkcal/syncdefines.h> | 49 | #include <libkcal/syncdefines.h> |
50 | #include <libkdepim/phoneaccess.h> | 50 | #include <libkdepim/phoneaccess.h> |
51 | #include "addressbook.h" | 51 | #include "addressbook.h" |
52 | #include "resource.h" | 52 | #include "resource.h" |
53 | #include "vcardconverter.h" | 53 | #include "vcardconverter.h" |
54 | #include "vcardparser/vcardtool.h" | 54 | #include "vcardparser/vcardtool.h" |
55 | 55 | ||
56 | //US #include "addressbook.moc" | 56 | //US #include "addressbook.moc" |
57 | 57 | ||
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | 59 | ||
60 | struct AddressBook::AddressBookData | 60 | struct AddressBook::AddressBookData |
61 | { | 61 | { |
62 | Addressee::List mAddressees; | 62 | Addressee::List mAddressees; |
63 | Addressee::List mRemovedAddressees; | 63 | Addressee::List mRemovedAddressees; |
64 | Field::List mAllFields; | 64 | Field::List mAllFields; |
65 | KConfig *mConfig; | 65 | KConfig *mConfig; |
66 | KRES::Manager<Resource> *mManager; | 66 | KRES::Manager<Resource> *mManager; |
67 | //US ErrorHandler *mErrorHandler; | 67 | //US ErrorHandler *mErrorHandler; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | struct AddressBook::Iterator::IteratorData | 70 | struct AddressBook::Iterator::IteratorData |
71 | { | 71 | { |
72 | Addressee::List::Iterator mIt; | 72 | Addressee::List::Iterator mIt; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | struct AddressBook::ConstIterator::ConstIteratorData | 75 | struct AddressBook::ConstIterator::ConstIteratorData |
76 | { | 76 | { |
77 | Addressee::List::ConstIterator mIt; | 77 | Addressee::List::ConstIterator mIt; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | AddressBook::Iterator::Iterator() | 80 | AddressBook::Iterator::Iterator() |
81 | { | 81 | { |
82 | d = new IteratorData; | 82 | d = new IteratorData; |
83 | } | 83 | } |
84 | 84 | ||
85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
86 | { | 86 | { |
87 | d = new IteratorData; | 87 | d = new IteratorData; |
88 | d->mIt = i.d->mIt; | 88 | d->mIt = i.d->mIt; |
89 | } | 89 | } |
90 | 90 | ||
91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
92 | { | 92 | { |
93 | if( this == &i ) return *this; // guard against self assignment | 93 | if( this == &i ) return *this; // guard against self assignment |
94 | delete d; // delete the old data the Iterator was completely constructed before | 94 | delete d; // delete the old data the Iterator was completely constructed before |
95 | d = new IteratorData; | 95 | d = new IteratorData; |
96 | d->mIt = i.d->mIt; | 96 | d->mIt = i.d->mIt; |
97 | return *this; | 97 | return *this; |
98 | } | 98 | } |
99 | 99 | ||
100 | AddressBook::Iterator::~Iterator() | 100 | AddressBook::Iterator::~Iterator() |
101 | { | 101 | { |
102 | delete d; | 102 | delete d; |
103 | } | 103 | } |
104 | 104 | ||
105 | const Addressee &AddressBook::Iterator::operator*() const | 105 | const Addressee &AddressBook::Iterator::operator*() const |
106 | { | 106 | { |
107 | return *(d->mIt); | 107 | return *(d->mIt); |
108 | } | 108 | } |
109 | 109 | ||
110 | Addressee &AddressBook::Iterator::operator*() | 110 | Addressee &AddressBook::Iterator::operator*() |
111 | { | 111 | { |
112 | return *(d->mIt); | 112 | return *(d->mIt); |
113 | } | 113 | } |
114 | 114 | ||
115 | Addressee *AddressBook::Iterator::operator->() | 115 | Addressee *AddressBook::Iterator::operator->() |
116 | { | 116 | { |
117 | return &(*(d->mIt)); | 117 | return &(*(d->mIt)); |
118 | } | 118 | } |
119 | 119 | ||
120 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 120 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
121 | { | 121 | { |
122 | (d->mIt)++; | 122 | (d->mIt)++; |
123 | return *this; | 123 | return *this; |
124 | } | 124 | } |
125 | 125 | ||
126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
127 | { | 127 | { |
128 | (d->mIt)++; | 128 | (d->mIt)++; |
129 | return *this; | 129 | return *this; |
130 | } | 130 | } |
131 | 131 | ||
132 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 132 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
133 | { | 133 | { |
134 | (d->mIt)--; | 134 | (d->mIt)--; |
135 | return *this; | 135 | return *this; |
136 | } | 136 | } |
137 | 137 | ||
138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
139 | { | 139 | { |
140 | (d->mIt)--; | 140 | (d->mIt)--; |
141 | return *this; | 141 | return *this; |
142 | } | 142 | } |
143 | 143 | ||
144 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 144 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
145 | { | 145 | { |
146 | return ( d->mIt == it.d->mIt ); | 146 | return ( d->mIt == it.d->mIt ); |
147 | } | 147 | } |
148 | 148 | ||
149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
150 | { | 150 | { |
151 | return ( d->mIt != it.d->mIt ); | 151 | return ( d->mIt != it.d->mIt ); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | AddressBook::ConstIterator::ConstIterator() | 155 | AddressBook::ConstIterator::ConstIterator() |
156 | { | 156 | { |
157 | d = new ConstIteratorData; | 157 | d = new ConstIteratorData; |
158 | } | 158 | } |
159 | 159 | ||
160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
161 | { | 161 | { |
162 | d = new ConstIteratorData; | 162 | d = new ConstIteratorData; |
163 | d->mIt = i.d->mIt; | 163 | d->mIt = i.d->mIt; |
164 | } | 164 | } |
165 | 165 | ||
166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
167 | { | 167 | { |
168 | if( this == &i ) return *this; // guard for self assignment | 168 | if( this == &i ) return *this; // guard for self assignment |
169 | delete d; // delete the old data because the Iterator was really constructed before | 169 | delete d; // delete the old data because the Iterator was really constructed before |
170 | d = new ConstIteratorData; | 170 | d = new ConstIteratorData; |
171 | d->mIt = i.d->mIt; | 171 | d->mIt = i.d->mIt; |
172 | return *this; | 172 | return *this; |
173 | } | 173 | } |
174 | 174 | ||
175 | AddressBook::ConstIterator::~ConstIterator() | 175 | AddressBook::ConstIterator::~ConstIterator() |
176 | { | 176 | { |
177 | delete d; | 177 | delete d; |
178 | } | 178 | } |
179 | 179 | ||
180 | const Addressee &AddressBook::ConstIterator::operator*() const | 180 | const Addressee &AddressBook::ConstIterator::operator*() const |
181 | { | 181 | { |
182 | return *(d->mIt); | 182 | return *(d->mIt); |
183 | } | 183 | } |
184 | 184 | ||
185 | const Addressee* AddressBook::ConstIterator::operator->() const | 185 | const Addressee* AddressBook::ConstIterator::operator->() const |
186 | { | 186 | { |
187 | return &(*(d->mIt)); | 187 | return &(*(d->mIt)); |
188 | } | 188 | } |
189 | 189 | ||
190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
191 | { | 191 | { |
192 | (d->mIt)++; | 192 | (d->mIt)++; |
193 | return *this; | 193 | return *this; |
194 | } | 194 | } |
195 | 195 | ||
196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
197 | { | 197 | { |
198 | (d->mIt)++; | 198 | (d->mIt)++; |
199 | return *this; | 199 | return *this; |
200 | } | 200 | } |
201 | 201 | ||
202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
203 | { | 203 | { |
204 | (d->mIt)--; | 204 | (d->mIt)--; |
205 | return *this; | 205 | return *this; |
206 | } | 206 | } |
207 | 207 | ||
208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
209 | { | 209 | { |
210 | (d->mIt)--; | 210 | (d->mIt)--; |
211 | return *this; | 211 | return *this; |
212 | } | 212 | } |
213 | 213 | ||
214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
215 | { | 215 | { |
216 | return ( d->mIt == it.d->mIt ); | 216 | return ( d->mIt == it.d->mIt ); |
217 | } | 217 | } |
218 | 218 | ||
219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
220 | { | 220 | { |
221 | return ( d->mIt != it.d->mIt ); | 221 | return ( d->mIt != it.d->mIt ); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | AddressBook::AddressBook() | 225 | AddressBook::AddressBook() |
226 | { | 226 | { |
227 | init(0, "contact"); | 227 | init(0, "contact"); |
228 | } | 228 | } |
229 | 229 | ||
230 | AddressBook::AddressBook( const QString &config ) | 230 | AddressBook::AddressBook( const QString &config ) |
231 | { | 231 | { |
232 | init(config, "contact"); | 232 | init(config, "contact"); |
233 | } | 233 | } |
234 | 234 | ||
235 | AddressBook::AddressBook( const QString &config, const QString &family ) | 235 | AddressBook::AddressBook( const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | init(config, family); | 237 | init(config, family); |
238 | 238 | ||
239 | } | 239 | } |
240 | 240 | ||
241 | // the default family is "contact" | 241 | // the default family is "contact" |
242 | void AddressBook::init(const QString &config, const QString &family ) | 242 | void AddressBook::init(const QString &config, const QString &family ) |
243 | { | 243 | { |
244 | blockLSEchange = false; | 244 | blockLSEchange = false; |
245 | d = new AddressBookData; | 245 | d = new AddressBookData; |
246 | QString fami = family; | 246 | QString fami = family; |
247 | if (config != 0) { | 247 | if (config != 0) { |
248 | if ( family == "syncContact" ) { | 248 | if ( family == "syncContact" ) { |
249 | qDebug("creating sync config "); | 249 | qDebug("creating sync config "); |
250 | fami = "contact"; | 250 | fami = "contact"; |
251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
252 | con->setGroup( "General" ); | 252 | con->setGroup( "General" ); |
253 | con->writeEntry( "ResourceKeys", QString("sync") ); | 253 | con->writeEntry( "ResourceKeys", QString("sync") ); |
254 | con->writeEntry( "Standard", QString("sync") ); | 254 | con->writeEntry( "Standard", QString("sync") ); |
255 | con->setGroup( "Resource_sync" ); | 255 | con->setGroup( "Resource_sync" ); |
256 | con->writeEntry( "FileName", config ); | 256 | con->writeEntry( "FileName", config ); |
257 | con->writeEntry( "FileFormat", QString("vcard") ); | 257 | con->writeEntry( "FileFormat", QString("vcard") ); |
258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
259 | con->writeEntry( "ResourceName", QString("sync_res") ); | 259 | con->writeEntry( "ResourceName", QString("sync_res") ); |
260 | if ( config.right(4) == ".xml" ) | 260 | if ( config.right(4) == ".xml" ) |
261 | con->writeEntry( "ResourceType", QString("qtopia") ); | 261 | con->writeEntry( "ResourceType", QString("qtopia") ); |
262 | else if ( config == "sharp" ) { | 262 | else if ( config == "sharp" ) { |
263 | con->writeEntry( "ResourceType", QString("sharp") ); | 263 | con->writeEntry( "ResourceType", QString("sharp") ); |
264 | } else { | 264 | } else { |
265 | con->writeEntry( "ResourceType", QString("file") ); | 265 | con->writeEntry( "ResourceType", QString("file") ); |
266 | } | 266 | } |
267 | //con->sync(); | 267 | //con->sync(); |
268 | d->mConfig = con; | 268 | d->mConfig = con; |
269 | } | 269 | } |
270 | else | 270 | else |
271 | d->mConfig = new KConfig( locateLocal("config", config) ); | 271 | d->mConfig = new KConfig( locateLocal("config", config) ); |
272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
273 | } | 273 | } |
274 | else { | 274 | else { |
275 | d->mConfig = 0; | 275 | d->mConfig = 0; |
276 | // qDebug("AddressBook::init 1 config=0"); | 276 | // qDebug("AddressBook::init 1 config=0"); |
277 | } | 277 | } |
278 | 278 | ||
279 | //US d->mErrorHandler = 0; | 279 | //US d->mErrorHandler = 0; |
280 | d->mManager = new KRES::Manager<Resource>( fami ); | 280 | d->mManager = new KRES::Manager<Resource>( fami ); |
281 | d->mManager->readConfig( d->mConfig ); | 281 | d->mManager->readConfig( d->mConfig ); |
282 | if ( family == "syncContact" ) { | 282 | if ( family == "syncContact" ) { |
283 | KRES::Manager<Resource> *manager = d->mManager; | 283 | KRES::Manager<Resource> *manager = d->mManager; |
284 | KRES::Manager<Resource>::ActiveIterator it; | 284 | KRES::Manager<Resource>::ActiveIterator it; |
285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
286 | (*it)->setAddressBook( this ); | 286 | (*it)->setAddressBook( this ); |
287 | if ( !(*it)->open() ) | 287 | if ( !(*it)->open() ) |
288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
289 | } | 289 | } |
290 | Resource *res = standardResource(); | 290 | Resource *res = standardResource(); |
291 | if ( !res ) { | 291 | if ( !res ) { |
292 | qDebug("ERROR: no standard resource"); | 292 | qDebug("ERROR: no standard resource"); |
293 | res = manager->createResource( "file" ); | 293 | res = manager->createResource( "file" ); |
294 | if ( res ) | 294 | if ( res ) |
295 | { | 295 | { |
296 | addResource( res ); | 296 | addResource( res ); |
297 | } | 297 | } |
298 | else | 298 | else |
299 | qDebug(" No resource available!!!"); | 299 | qDebug(" No resource available!!!"); |
300 | } | 300 | } |
301 | setStandardResource( res ); | 301 | setStandardResource( res ); |
302 | manager->writeConfig(); | 302 | manager->writeConfig(); |
303 | } | 303 | } |
304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
305 | "X-Department", "KADDRESSBOOK" ); | 305 | "X-Department", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
307 | "X-Profession", "KADDRESSBOOK" ); | 307 | "X-Profession", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
309 | "X-AssistantsName", "KADDRESSBOOK" ); | 309 | "X-AssistantsName", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
311 | "X-ManagersName", "KADDRESSBOOK" ); | 311 | "X-ManagersName", "KADDRESSBOOK" ); |
312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
313 | "X-SpousesName", "KADDRESSBOOK" ); | 313 | "X-SpousesName", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
315 | "X-Office", "KADDRESSBOOK" ); | 315 | "X-Office", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
317 | "X-IMAddress", "KADDRESSBOOK" ); | 317 | "X-IMAddress", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
319 | "X-Anniversary", "KADDRESSBOOK" ); | 319 | "X-Anniversary", "KADDRESSBOOK" ); |
320 | 320 | ||
321 | //US added this field to become compatible with Opie/qtopia addressbook | 321 | //US added this field to become compatible with Opie/qtopia addressbook |
322 | // values can be "female" or "male" or "". An empty field represents undefined. | 322 | // values can be "female" or "male" or "". An empty field represents undefined. |
323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
324 | "X-Gender", "KADDRESSBOOK" ); | 324 | "X-Gender", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
326 | "X-Children", "KADDRESSBOOK" ); | 326 | "X-Children", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
330 | "X-ExternalID", "KADDRESSBOOK" ); | 330 | "X-ExternalID", "KADDRESSBOOK" ); |
331 | } | 331 | } |
332 | 332 | ||
333 | AddressBook::~AddressBook() | 333 | AddressBook::~AddressBook() |
334 | { | 334 | { |
335 | delete d->mConfig; d->mConfig = 0; | 335 | delete d->mConfig; d->mConfig = 0; |
336 | delete d->mManager; d->mManager = 0; | 336 | delete d->mManager; d->mManager = 0; |
337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
338 | delete d; d = 0; | 338 | delete d; d = 0; |
339 | } | 339 | } |
340 | 340 | ||
341 | bool AddressBook::load() | 341 | bool AddressBook::load() |
342 | { | 342 | { |
343 | 343 | ||
344 | clear(); | 344 | clear(); |
345 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 346 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 350 | ok = false; |
351 | } else { | 351 | } else { |
352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); | 352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); |
353 | } | 353 | } |
354 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
355 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
357 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
359 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
360 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
361 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | blockLSEchange = true; | 364 | blockLSEchange = true; |
365 | return ok; | 365 | return ok; |
366 | } | 366 | } |
367 | 367 | ||
368 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
369 | { | 369 | { |
370 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
371 | 371 | ||
372 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
373 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
374 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
375 | } | 375 | } |
376 | 376 | ||
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | // exports all Addressees, which are syncable | 379 | // exports all Addressees, which are syncable |
380 | void AddressBook::export2File( QString fileName ) | 380 | void AddressBook::export2File( QString fileName ) |
381 | { | 381 | { |
382 | 382 | ||
383 | QFile outFile( fileName ); | 383 | QFile outFile( fileName ); |
384 | if ( !outFile.open( IO_WriteOnly ) ) { | 384 | if ( !outFile.open( IO_WriteOnly ) ) { |
385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
386 | KMessageBox::error( 0, text.arg( fileName ) ); | 386 | KMessageBox::error( 0, text.arg( fileName ) ); |
387 | return ; | 387 | return ; |
388 | } | 388 | } |
389 | QTextStream t( &outFile ); | 389 | QTextStream t( &outFile ); |
390 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 390 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
391 | Iterator it; | 391 | Iterator it; |
392 | KABC::VCardConverter::Version version; | 392 | KABC::VCardConverter::Version version; |
393 | version = KABC::VCardConverter::v3_0; | 393 | version = KABC::VCardConverter::v3_0; |
394 | for ( it = begin(); it != end(); ++it ) { | 394 | for ( it = begin(); it != end(); ++it ) { |
395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { | 395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { |
396 | if ( !(*it).IDStr().isEmpty() ) { | 396 | if ( !(*it).IDStr().isEmpty() ) { |
397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
398 | } | 398 | } |
399 | KABC::VCardConverter converter; | 399 | KABC::VCardConverter converter; |
400 | QString vcard; | 400 | QString vcard; |
401 | //Resource *resource() const; | 401 | //Resource *resource() const; |
402 | converter.addresseeToVCard( *it, vcard, version ); | 402 | converter.addresseeToVCard( *it, vcard, version ); |
403 | t << vcard << "\r\n"; | 403 | t << vcard << "\r\n"; |
404 | } | 404 | } |
405 | } | 405 | } |
406 | t << "\r\n\r\n"; | 406 | t << "\r\n\r\n"; |
407 | outFile.close(); | 407 | outFile.close(); |
408 | } | 408 | } |
409 | // if QStringList uids is empty, all are exported | 409 | // if QStringList uids is empty, all are exported |
410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | 410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) |
411 | { | 411 | { |
412 | KABC::VCardConverter converter; | 412 | KABC::VCardConverter converter; |
413 | QString datastream; | 413 | QString datastream; |
414 | Iterator it; | 414 | Iterator it; |
415 | bool all = uids.isEmpty(); | 415 | bool all = uids.isEmpty(); |
416 | for ( it = begin(); it != end(); ++it ) { | 416 | for ( it = begin(); it != end(); ++it ) { |
417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
418 | if ( ! all ) { | 418 | if ( ! all ) { |
419 | if ( ! ( uids.contains((*it).uid() ) )) | 419 | if ( ! ( uids.contains((*it).uid() ) )) |
420 | continue; | 420 | continue; |
421 | } | 421 | } |
422 | KABC::Addressee a = ( *it ); | 422 | KABC::Addressee a = ( *it ); |
423 | if ( a.isEmpty() ) | 423 | if ( a.isEmpty() ) |
424 | continue; | 424 | continue; |
425 | if ( all && a.resource() && !a.resource()->includeInSync() ) | 425 | if ( all && a.resource() && !a.resource()->includeInSync() ) |
426 | continue; | 426 | continue; |
427 | a.simplifyEmails(); | 427 | a.simplifyEmails(); |
428 | a.simplifyPhoneNumbers(); | 428 | a.simplifyPhoneNumbers(); |
429 | a.simplifyPhoneNumberTypes(); | 429 | a.simplifyPhoneNumberTypes(); |
430 | a.simplifyAddresses(); | 430 | a.simplifyAddresses(); |
431 | 431 | ||
432 | QString vcard; | 432 | QString vcard; |
433 | QString vcardnew; | 433 | QString vcardnew; |
434 | converter.addresseeToVCard( a, vcard ); | 434 | converter.addresseeToVCard( a, vcard ); |
435 | int start = 0; | 435 | int start = 0; |
436 | int next; | 436 | int next; |
437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
438 | int semi = vcard.find(";", next); | 438 | int semi = vcard.find(";", next); |
439 | int dopp = vcard.find(":", next); | 439 | int dopp = vcard.find(":", next); |
440 | int sep; | 440 | int sep; |
441 | if ( semi < dopp && semi >= 0 ) | 441 | if ( semi < dopp && semi >= 0 ) |
442 | sep = semi ; | 442 | sep = semi ; |
443 | else | 443 | else |
444 | sep = dopp; | 444 | sep = dopp; |
445 | vcardnew +=vcard.mid( start, next - start); | 445 | vcardnew +=vcard.mid( start, next - start); |
446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); | 446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); |
447 | start = sep; | 447 | start = sep; |
448 | } | 448 | } |
449 | vcardnew += vcard.mid( start,vcard.length() ); | 449 | vcardnew += vcard.mid( start,vcard.length() ); |
450 | vcard = ""; | 450 | vcard = ""; |
451 | start = 0; | 451 | start = 0; |
452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | 452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { |
453 | int sep = vcardnew.find(":", next); | 453 | int sep = vcardnew.find(":", next); |
454 | vcard +=vcardnew.mid( start, next - start+3); | 454 | vcard +=vcardnew.mid( start, next - start+3); |
455 | start = sep; | 455 | start = sep; |
456 | } | 456 | } |
457 | vcard += vcardnew.mid( start,vcardnew.length() ); | 457 | vcard += vcardnew.mid( start,vcardnew.length() ); |
458 | vcard.replace ( QRegExp(";;;") , "" ); | 458 | vcard.replace ( QRegExp(";;;") , "" ); |
459 | vcard.replace ( QRegExp(";;") , "" ); | 459 | vcard.replace ( QRegExp(";;") , "" ); |
460 | datastream += vcard; | 460 | datastream += vcard; |
461 | 461 | ||
462 | } | 462 | } |
463 | 463 | ||
464 | QFile outFile(fileName); | 464 | QFile outFile(fileName); |
465 | if ( outFile.open(IO_WriteOnly) ) { | 465 | if ( outFile.open(IO_WriteOnly) ) { |
466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
467 | QTextStream t( &outFile ); // use a text stream | 467 | QTextStream t( &outFile ); // use a text stream |
468 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 468 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
469 | t <<datastream; | 469 | t <<datastream; |
470 | t << "\r\n\r\n"; | 470 | t << "\r\n\r\n"; |
471 | outFile.close(); | 471 | outFile.close(); |
472 | 472 | ||
473 | } else { | 473 | } else { |
474 | qDebug("Error open temp file "); | 474 | qDebug("Error open temp file "); |
475 | return false; | 475 | return false; |
476 | } | 476 | } |
477 | return true; | 477 | return true; |
478 | 478 | ||
479 | } | 479 | } |
480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
481 | { | 481 | { |
482 | 482 | ||
483 | if ( removeOld ) | 483 | if ( removeOld ) |
484 | setUntagged( true ); | 484 | setUntagged( true ); |
485 | KABC::Addressee::List list; | 485 | KABC::Addressee::List list; |
486 | QFile file( fileName ); | 486 | QFile file( fileName ); |
487 | file.open( IO_ReadOnly ); | 487 | file.open( IO_ReadOnly ); |
488 | QByteArray rawData = file.readAll(); | 488 | QByteArray rawData = file.readAll(); |
489 | file.close(); | 489 | file.close(); |
490 | QString data; | 490 | QString data; |
491 | if ( replaceLabel ) { | 491 | if ( replaceLabel ) { |
492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
493 | data.replace ( QRegExp("LABEL") , "ADR" ); | 493 | data.replace ( QRegExp("LABEL") , "ADR" ); |
494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
495 | } else | 495 | } else |
496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
497 | KABC::VCardTool tool; | 497 | KABC::VCardTool tool; |
498 | list = tool.parseVCards( data ); | 498 | list = tool.parseVCards( data ); |
499 | KABC::Addressee::List::Iterator it; | 499 | KABC::Addressee::List::Iterator it; |
500 | for ( it = list.begin(); it != list.end(); ++it ) { | 500 | for ( it = list.begin(); it != list.end(); ++it ) { |
501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
502 | if ( !id.isEmpty() ) | 502 | if ( !id.isEmpty() ) |
503 | (*it).setIDStr(id ); | 503 | (*it).setIDStr(id ); |
504 | (*it).setResource( 0 ); | 504 | (*it).setResource( 0 ); |
505 | if ( replaceLabel ) | 505 | if ( replaceLabel ) |
506 | (*it).removeVoice(); | 506 | (*it).removeVoice(); |
507 | if ( removeOld ) | 507 | if ( removeOld ) |
508 | (*it).setTagged( true ); | 508 | (*it).setTagged( true ); |
509 | insertAddressee( (*it), false, true ); | 509 | insertAddressee( (*it), false, true ); |
510 | } | 510 | } |
511 | if ( removeOld ) | 511 | if ( removeOld ) |
512 | removeUntagged(); | 512 | removeUntagged(); |
513 | return list.count(); | 513 | return list.count(); |
514 | } | 514 | } |
515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) |
516 | { | 516 | { |
517 | Iterator ait; | 517 | Iterator ait; |
518 | for ( ait = begin(); ait != end(); ++ait ) { | 518 | for ( ait = begin(); ait != end(); ++ait ) { |
519 | if ( setNonSyncTagged ) { | 519 | if ( setNonSyncTagged ) { |
520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | 520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { |
521 | (*ait).setTagged( true ); | 521 | (*ait).setTagged( true ); |
522 | } else | 522 | } else |
523 | (*ait).setTagged( false ); | 523 | (*ait).setTagged( false ); |
524 | } else | 524 | } else |
525 | (*ait).setTagged( false ); | 525 | (*ait).setTagged( false ); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | void AddressBook::removeUntagged() | 528 | void AddressBook::removeUntagged() |
529 | { | 529 | { |
530 | Iterator ait; | 530 | Iterator ait; |
531 | bool todelete = false; | 531 | bool todelete = false; |
532 | Iterator todel; | 532 | Iterator todel; |
533 | for ( ait = begin(); ait != end(); ++ait ) { | 533 | for ( ait = begin(); ait != end(); ++ait ) { |
534 | if ( todelete ) | 534 | if ( todelete ) |
535 | removeAddressee( todel ); | 535 | removeAddressee( todel ); |
536 | if (!(*ait).tagged()) { | 536 | if (!(*ait).tagged()) { |
537 | todelete = true; | 537 | todelete = true; |
538 | todel = ait; | 538 | todel = ait; |
539 | } else | 539 | } else |
540 | todelete = false; | 540 | todelete = false; |
541 | } | 541 | } |
542 | if ( todelete ) | 542 | if ( todelete ) |
543 | removeAddressee( todel ); | 543 | removeAddressee( todel ); |
544 | deleteRemovedAddressees(); | 544 | deleteRemovedAddressees(); |
545 | } | 545 | } |
546 | void AddressBook::smplifyAddressees() | 546 | void AddressBook::smplifyAddressees() |
547 | { | 547 | { |
548 | Iterator ait; | 548 | Iterator ait; |
549 | for ( ait = begin(); ait != end(); ++ait ) { | 549 | for ( ait = begin(); ait != end(); ++ait ) { |
550 | (*ait).simplifyEmails(); | 550 | (*ait).simplifyEmails(); |
551 | (*ait).simplifyPhoneNumbers(); | 551 | (*ait).simplifyPhoneNumbers(); |
552 | (*ait).simplifyPhoneNumberTypes(); | 552 | (*ait).simplifyPhoneNumberTypes(); |
553 | (*ait).simplifyAddresses(); | 553 | (*ait).simplifyAddresses(); |
554 | } | 554 | } |
555 | } | 555 | } |
556 | void AddressBook::removeSyncInfo( QString syncProfile) | 556 | void AddressBook::removeSyncInfo( QString syncProfile) |
557 | { | 557 | { |
558 | Iterator ait; | 558 | Iterator ait; |
559 | for ( ait = begin(); ait != end(); ++ait ) { | 559 | for ( ait = begin(); ait != end(); ++ait ) { |
560 | (*ait).removeID( syncProfile ); | 560 | (*ait).removeID( syncProfile ); |
561 | } | 561 | } |
562 | if ( syncProfile.isEmpty() ) { | 562 | if ( syncProfile.isEmpty() ) { |
563 | Iterator it = begin(); | 563 | Iterator it = begin(); |
564 | Iterator it2 ; | 564 | Iterator it2 ; |
565 | while ( it != end() ) { | 565 | while ( it != end() ) { |
566 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 566 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
567 | it2 = it; | 567 | it2 = it; |
568 | //qDebug("removing %s ",(*it).uid().latin1() ); | 568 | //qDebug("removing %s ",(*it).uid().latin1() ); |
569 | ++it; | 569 | ++it; |
570 | removeAddressee( it2 ); | 570 | removeAddressee( it2 ); |
571 | } else { | 571 | } else { |
572 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 572 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
573 | ++it; | 573 | ++it; |
574 | } | 574 | } |
575 | } | 575 | } |
576 | } else { | 576 | } else { |
577 | Addressee lse; | 577 | Addressee lse; |
578 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); | 578 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); |
579 | if ( ! lse.isEmpty() ) | 579 | if ( ! lse.isEmpty() ) |
580 | removeAddressee( lse ); | 580 | removeAddressee( lse ); |
581 | } | 581 | } |
582 | 582 | ||
583 | } | 583 | } |
584 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 584 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
585 | { | 585 | { |
586 | Iterator ait; | 586 | Iterator ait; |
587 | for ( ait = begin(); ait != end(); ++ait ) { | 587 | for ( ait = begin(); ait != end(); ++ait ) { |
588 | QString id = (*ait).IDStr(); | 588 | QString id = (*ait).IDStr(); |
589 | (*ait).setIDStr( ":"); | 589 | (*ait).setIDStr( ":"); |
590 | (*ait).setExternalUID( id ); | 590 | (*ait).setExternalUID( id ); |
591 | (*ait).setOriginalExternalUID( id ); | 591 | (*ait).setOriginalExternalUID( id ); |
592 | if ( isPreSync ) | 592 | if ( isPreSync ) |
593 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 593 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
594 | else { | 594 | else { |
595 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 595 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
596 | (*ait).setID( currentSyncDevice,id ); | 596 | (*ait).setID( currentSyncDevice,id ); |
597 | 597 | ||
598 | } | 598 | } |
599 | } | 599 | } |
600 | } | 600 | } |
601 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 601 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
602 | { | 602 | { |
603 | 603 | ||
604 | setUntagged(); | 604 | setUntagged(); |
605 | KABC::Addressee::List list; | 605 | KABC::Addressee::List list; |
606 | QFile file( fileName ); | 606 | QFile file( fileName ); |
607 | file.open( IO_ReadOnly ); | 607 | file.open( IO_ReadOnly ); |
608 | QByteArray rawData = file.readAll(); | 608 | QByteArray rawData = file.readAll(); |
609 | file.close(); | 609 | file.close(); |
610 | QString data; | 610 | QString data; |
611 | 611 | ||
612 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 612 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
613 | KABC::VCardTool tool; | 613 | KABC::VCardTool tool; |
614 | list = tool.parseVCards( data ); | 614 | list = tool.parseVCards( data ); |
615 | KABC::Addressee::List::Iterator it; | 615 | KABC::Addressee::List::Iterator it; |
616 | for ( it = list.begin(); it != list.end(); ++it ) { | 616 | for ( it = list.begin(); it != list.end(); ++it ) { |
617 | Iterator ait; | 617 | Iterator ait; |
618 | for ( ait = begin(); ait != end(); ++ait ) { | 618 | for ( ait = begin(); ait != end(); ++ait ) { |
619 | if ( !(*ait).tagged() ) { | 619 | if ( !(*ait).tagged() ) { |
620 | if ( (*ait).containsAdr(*it)) { | 620 | if ( (*ait).containsAdr(*it)) { |
621 | (*ait).setTagged(true); | 621 | (*ait).setTagged(true); |
622 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 622 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
623 | (*it).setIDStr( ":"); | 623 | (*it).setIDStr( ":"); |
624 | (*it).setID( currentSyncDevice,id ); | 624 | (*it).setID( currentSyncDevice,id ); |
625 | (*it).setExternalUID( id ); | 625 | (*it).setExternalUID( id ); |
626 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 626 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
627 | (*it).setUid( ( (*ait).uid() )); | 627 | (*it).setUid( ( (*ait).uid() )); |
628 | break; | 628 | break; |
629 | } | 629 | } |
630 | } | 630 | } |
631 | 631 | ||
632 | } | 632 | } |
633 | if ( ait == end() ) | 633 | if ( ait == end() ) |
634 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 634 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
635 | } | 635 | } |
636 | clear(); | 636 | clear(); |
637 | for ( it = list.begin(); it != list.end(); ++it ) { | 637 | for ( it = list.begin(); it != list.end(); ++it ) { |
638 | insertAddressee( (*it) ); | 638 | insertAddressee( (*it) ); |
639 | } | 639 | } |
640 | } | 640 | } |
641 | 641 | ||
642 | bool AddressBook::saveABphone( QString fileName ) | 642 | bool AddressBook::saveABphone( QString fileName ) |
643 | { | 643 | { |
644 | //smplifyAddressees(); | 644 | //smplifyAddressees(); |
645 | qDebug("saveABphone:: saving AB... "); | 645 | qDebug("saveABphone:: saving AB... "); |
646 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 646 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
647 | return false; | 647 | return false; |
648 | qDebug("saveABphone:: writing to phone... "); | 648 | qDebug("saveABphone:: writing to phone... "); |
649 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 649 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
650 | return false; | 650 | return false; |
651 | } | 651 | } |
652 | qDebug("saveABphone:: re-reading from phone... "); | 652 | qDebug("saveABphone:: re-reading from phone... "); |
653 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 653 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
654 | return false; | 654 | return false; |
655 | } | 655 | } |
656 | return true; | 656 | return true; |
657 | } | 657 | } |
658 | bool AddressBook::saveAB() | 658 | bool AddressBook::saveAB() |
659 | { | 659 | { |
660 | bool ok = true; | 660 | bool ok = true; |
661 | 661 | ||
662 | deleteRemovedAddressees(); | 662 | deleteRemovedAddressees(); |
663 | Iterator ait; | 663 | Iterator ait; |
664 | for ( ait = begin(); ait != end(); ++ait ) { | 664 | for ( ait = begin(); ait != end(); ++ait ) { |
665 | if ( !(*ait).IDStr().isEmpty() ) { | 665 | if ( !(*ait).IDStr().isEmpty() ) { |
666 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 666 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
667 | } | 667 | } |
668 | } | 668 | } |
669 | KRES::Manager<Resource>::ActiveIterator it; | 669 | KRES::Manager<Resource>::ActiveIterator it; |
670 | KRES::Manager<Resource> *manager = d->mManager; | 670 | KRES::Manager<Resource> *manager = d->mManager; |
671 | qDebug("SaveAB::saving..." ); | 671 | qDebug("SaveAB::saving..." ); |
672 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 672 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
673 | qDebug("SaveAB::checking resource..." ); | 673 | qDebug("SaveAB::checking resource..." ); |
674 | if ( (*it)->readOnly() ) | 674 | if ( (*it)->readOnly() ) |
675 | qDebug("resource is readonly." ); | 675 | qDebug("resource is readonly." ); |
676 | if ( (*it)->isOpen() ) | 676 | if ( (*it)->isOpen() ) |
677 | qDebug("resource is open" ); | 677 | qDebug("resource is open" ); |
678 | 678 | ||
679 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 679 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
680 | Ticket *ticket = requestSaveTicket( *it ); | 680 | Ticket *ticket = requestSaveTicket( *it ); |
681 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 681 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
682 | if ( !ticket ) { | 682 | if ( !ticket ) { |
683 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 683 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
684 | .arg( (*it)->resourceName() ) ); | 684 | .arg( (*it)->resourceName() ) ); |
685 | return false; | 685 | return false; |
686 | } | 686 | } |
687 | 687 | ||
688 | //if ( !save( ticket ) ) | 688 | //if ( !save( ticket ) ) |
689 | if ( ticket->resource() ) { | 689 | if ( ticket->resource() ) { |
690 | QString name = ticket->resource()->resourceName(); | 690 | QString name = ticket->resource()->resourceName(); |
691 | if ( ! ticket->resource()->save( ticket ) ) | 691 | if ( ! ticket->resource()->save( ticket ) ) |
692 | ok = false; | 692 | ok = false; |
693 | else | 693 | else |
694 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); | 694 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
695 | 695 | ||
696 | } else | 696 | } else |
697 | ok = false; | 697 | ok = false; |
698 | 698 | ||
699 | } | 699 | } |
700 | } | 700 | } |
701 | return ok; | 701 | return ok; |
702 | } | 702 | } |
703 | 703 | ||
704 | AddressBook::Iterator AddressBook::begin() | 704 | AddressBook::Iterator AddressBook::begin() |
705 | { | 705 | { |
706 | Iterator it = Iterator(); | 706 | Iterator it = Iterator(); |
707 | it.d->mIt = d->mAddressees.begin(); | 707 | it.d->mIt = d->mAddressees.begin(); |
708 | return it; | 708 | return it; |
709 | } | 709 | } |
710 | 710 | ||
711 | AddressBook::ConstIterator AddressBook::begin() const | 711 | AddressBook::ConstIterator AddressBook::begin() const |
712 | { | 712 | { |
713 | ConstIterator it = ConstIterator(); | 713 | ConstIterator it = ConstIterator(); |
714 | it.d->mIt = d->mAddressees.begin(); | 714 | it.d->mIt = d->mAddressees.begin(); |
715 | return it; | 715 | return it; |
716 | } | 716 | } |
717 | 717 | ||
718 | AddressBook::Iterator AddressBook::end() | 718 | AddressBook::Iterator AddressBook::end() |
719 | { | 719 | { |
720 | Iterator it = Iterator(); | 720 | Iterator it = Iterator(); |
721 | it.d->mIt = d->mAddressees.end(); | 721 | it.d->mIt = d->mAddressees.end(); |
722 | return it; | 722 | return it; |
723 | } | 723 | } |
724 | 724 | ||
725 | AddressBook::ConstIterator AddressBook::end() const | 725 | AddressBook::ConstIterator AddressBook::end() const |
726 | { | 726 | { |
727 | ConstIterator it = ConstIterator(); | 727 | ConstIterator it = ConstIterator(); |
728 | it.d->mIt = d->mAddressees.end(); | 728 | it.d->mIt = d->mAddressees.end(); |
729 | return it; | 729 | return it; |
730 | } | 730 | } |
731 | 731 | ||
732 | void AddressBook::clear() | 732 | void AddressBook::clear() |
733 | { | 733 | { |
734 | d->mAddressees.clear(); | 734 | d->mAddressees.clear(); |
735 | } | 735 | } |
736 | 736 | ||
737 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 737 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
738 | { | 738 | { |
739 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 739 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
740 | 740 | ||
741 | if ( !resource ) | 741 | if ( !resource ) |
742 | { | 742 | { |
743 | qDebug("AddressBook::requestSaveTicket no resource" ); | 743 | qDebug("AddressBook::requestSaveTicket no resource" ); |
744 | resource = standardResource(); | 744 | resource = standardResource(); |
745 | } | 745 | } |
746 | 746 | ||
747 | KRES::Manager<Resource>::ActiveIterator it; | 747 | KRES::Manager<Resource>::ActiveIterator it; |
748 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 748 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
749 | if ( (*it) == resource ) { | 749 | if ( (*it) == resource ) { |
750 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 750 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
751 | return 0; | 751 | return 0; |
752 | else | 752 | else |
753 | return (*it)->requestSaveTicket(); | 753 | return (*it)->requestSaveTicket(); |
754 | } | 754 | } |
755 | } | 755 | } |
756 | 756 | ||
757 | return 0; | 757 | return 0; |
758 | } | 758 | } |
759 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 759 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
760 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 760 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
761 | { | 761 | { |
762 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 762 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
763 | //qDebug("block insert "); | 763 | //qDebug("block insert "); |
764 | return; | 764 | return; |
765 | } | 765 | } |
766 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 766 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
767 | bool found = false; | 767 | bool found = false; |
768 | Addressee::List::Iterator it; | 768 | Addressee::List::Iterator it; |
769 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 769 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
770 | if ( a.uid() == (*it).uid() ) { | 770 | if ( a.uid() == (*it).uid() ) { |
771 | 771 | ||
772 | bool changed = false; | 772 | bool changed = false; |
773 | Addressee addr = a; | 773 | Addressee addr = a; |
774 | if ( addr != (*it) ) | 774 | if ( addr != (*it) ) |
775 | changed = true; | 775 | changed = true; |
776 | 776 | ||
777 | if ( takeResource ) { | 777 | if ( takeResource ) { |
778 | Resource * res = (*it).resource(); | 778 | Resource * res = (*it).resource(); |
779 | (*it) = a; | 779 | (*it) = a; |
780 | (*it).setResource( res ); | 780 | (*it).setResource( res ); |
781 | } else { | 781 | } else { |
782 | (*it) = a; | 782 | (*it) = a; |
783 | if ( (*it).resource() == 0 ) | 783 | if ( (*it).resource() == 0 ) |
784 | (*it).setResource( standardResource() ); | 784 | (*it).setResource( standardResource() ); |
785 | } | 785 | } |
786 | if ( changed ) { | 786 | if ( changed ) { |
787 | if ( setRev ) { | 787 | if ( setRev ) { |
788 | (*it).setRevision( QDateTime::currentDateTime() ); | 788 | (*it).setRevision( QDateTime::currentDateTime() ); |
789 | } | 789 | } |
790 | (*it).setChanged( true ); | 790 | (*it).setChanged( true ); |
791 | } | 791 | } |
792 | 792 | ||
793 | found = true; | 793 | found = true; |
794 | } else { | 794 | } else { |
795 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 795 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
796 | QString name = (*it).uid().mid( 19 ); | 796 | QString name = (*it).uid().mid( 19 ); |
797 | Addressee b = a; | 797 | Addressee b = a; |
798 | QString id = b.getID( name ); | 798 | QString id = b.getID( name ); |
799 | if ( ! id.isEmpty() ) { | 799 | if ( ! id.isEmpty() ) { |
800 | QString des = (*it).note(); | 800 | QString des = (*it).note(); |
801 | int startN; | 801 | int startN; |
802 | if( (startN = des.find( id ) ) >= 0 ) { | 802 | if( (startN = des.find( id ) ) >= 0 ) { |
803 | int endN = des.find( ",", startN+1 ); | 803 | int endN = des.find( ",", startN+1 ); |
804 | des = des.left( startN ) + des.mid( endN+1 ); | 804 | des = des.left( startN ) + des.mid( endN+1 ); |
805 | (*it).setNote( des ); | 805 | (*it).setNote( des ); |
806 | } | 806 | } |
807 | } | 807 | } |
808 | } | 808 | } |
809 | } | 809 | } |
810 | } | 810 | } |
811 | if ( found ) | 811 | if ( found ) |
812 | return; | 812 | return; |
813 | 813 | ||
814 | d->mAddressees.append( a ); | 814 | d->mAddressees.append( a ); |
815 | Addressee& addr = d->mAddressees.last(); | 815 | Addressee& addr = d->mAddressees.last(); |
816 | if ( addr.resource() == 0 ) | 816 | if ( addr.resource() == 0 ) |
817 | addr.setResource( standardResource() ); | 817 | addr.setResource( standardResource() ); |
818 | addr.setChanged( true ); | 818 | addr.setChanged( true ); |
819 | } | 819 | } |
820 | 820 | ||
821 | void AddressBook::removeAddressee( const Addressee &a ) | 821 | void AddressBook::removeAddressee( const Addressee &a ) |
822 | { | 822 | { |
823 | Iterator it; | 823 | Iterator it; |
824 | Iterator it2; | 824 | Iterator it2; |
825 | bool found = false; | 825 | bool found = false; |
826 | for ( it = begin(); it != end(); ++it ) { | 826 | for ( it = begin(); it != end(); ++it ) { |
827 | if ( a.uid() == (*it).uid() ) { | 827 | if ( a.uid() == (*it).uid() ) { |
828 | found = true; | 828 | found = true; |
829 | it2 = it; | 829 | it2 = it; |
830 | } else { | 830 | } else { |
831 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 831 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
832 | QString name = (*it).uid().mid( 19 ); | 832 | QString name = (*it).uid().mid( 19 ); |
833 | Addressee b = a; | 833 | Addressee b = a; |
834 | QString id = b.getID( name ); | 834 | QString id = b.getID( name ); |
835 | if ( ! id.isEmpty() ) { | 835 | if ( ! id.isEmpty() ) { |
836 | QString des = (*it).note(); | 836 | QString des = (*it).note(); |
837 | if( des.find( id ) < 0 ) { | 837 | if( des.find( id ) < 0 ) { |
838 | des += id + ","; | 838 | des += id + ","; |
839 | (*it).setNote( des ); | 839 | (*it).setNote( des ); |
840 | } | 840 | } |
841 | } | 841 | } |
842 | } | 842 | } |
843 | 843 | ||
844 | } | 844 | } |
845 | } | 845 | } |
846 | 846 | ||
847 | if ( found ) | 847 | if ( found ) |
848 | removeAddressee( it2 ); | 848 | removeAddressee( it2 ); |
849 | 849 | ||
850 | } | 850 | } |
851 | 851 | ||
852 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 852 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
853 | { | 853 | { |
854 | Iterator it = begin(); | 854 | Iterator it = begin(); |
855 | Iterator it2 ; | 855 | Iterator it2 ; |
856 | QDateTime dt ( QDate( 2003,1,1) ); | 856 | QDateTime dt ( QDate( 2003,1,1) ); |
857 | while ( it != end() ) { | 857 | while ( it != end() ) { |
858 | (*it).setRevision( dt ); | 858 | (*it).setRevision( dt ); |
859 | if (( *it).IDStr() != "changed" ) { | 859 | if (( *it).IDStr() != "changed" ) { |
860 | // "changed" is used for tagging changed addressees when syncing with KDE or OL | 860 | // "changed" is used for tagging changed addressees when syncing with KDE or OL |
861 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 861 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
862 | (*it).setIDStr(":"); | 862 | (*it).setIDStr(":"); |
863 | } | 863 | } |
864 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 864 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
865 | it2 = it; | 865 | it2 = it; |
866 | //qDebug("removing %s ",(*it).uid().latin1() ); | 866 | //qDebug("removing %s ",(*it).uid().latin1() ); |
867 | ++it; | 867 | ++it; |
868 | removeAddressee( it2 ); | 868 | removeAddressee( it2 ); |
869 | } else { | 869 | } else { |
870 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 870 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
871 | if ( removeDeleted ) { | 871 | if ( removeDeleted ) { |
872 | // we have no postprocessing in the resource, we have to do it here | 872 | // we have no postprocessing in the resource, we have to do it here |
873 | // we have to compute csum for all, because it could be the first sync | 873 | // we have to compute csum for all, because it could be the first sync |
874 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 874 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
875 | } | 875 | } |
876 | ++it; | 876 | ++it; |
877 | } | 877 | } |
878 | } | 878 | } |
879 | deleteRemovedAddressees(); | 879 | deleteRemovedAddressees(); |
880 | } | 880 | } |
881 | 881 | ||
882 | void AddressBook::removeAddressee( const Iterator &it ) | 882 | void AddressBook::removeAddressee( const Iterator &it ) |
883 | { | 883 | { |
884 | d->mRemovedAddressees.append( (*it) ); | 884 | d->mRemovedAddressees.append( (*it) ); |
885 | d->mAddressees.remove( it.d->mIt ); | 885 | d->mAddressees.remove( it.d->mIt ); |
886 | } | 886 | } |
887 | 887 | ||
888 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 888 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
889 | { | 889 | { |
890 | Iterator it; | 890 | Iterator it; |
891 | for ( it = begin(); it != end(); ++it ) { | 891 | for ( it = begin(); it != end(); ++it ) { |
892 | if ( a.uid() == (*it).uid() ) { | 892 | if ( a.uid() == (*it).uid() ) { |
893 | return it; | 893 | return it; |
894 | } | 894 | } |
895 | } | 895 | } |
896 | return end(); | 896 | return end(); |
897 | } | 897 | } |
898 | 898 | ||
899 | Addressee AddressBook::findByUid( const QString &uid ) | 899 | Addressee AddressBook::findByUid( const QString &uid ) |
900 | { | 900 | { |
901 | Iterator it; | 901 | Iterator it; |
902 | for ( it = begin(); it != end(); ++it ) { | 902 | for ( it = begin(); it != end(); ++it ) { |
903 | if ( uid == (*it).uid() ) { | 903 | if ( uid == (*it).uid() ) { |
904 | return *it; | 904 | return *it; |
905 | } | 905 | } |
906 | } | 906 | } |
907 | return Addressee(); | 907 | return Addressee(); |
908 | } | 908 | } |
909 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 909 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
910 | { | 910 | { |
911 | //qDebug("AddressBook::preExternSync "); | 911 | //qDebug("AddressBook::preExternSync "); |
912 | AddressBook::Iterator it; | 912 | AddressBook::Iterator it; |
913 | for ( it = begin(); it != end(); ++it ) { | 913 | for ( it = begin(); it != end(); ++it ) { |
914 | (*it).setID( csd, (*it).externalUID() ); | 914 | (*it).setID( csd, (*it).externalUID() ); |
915 | (*it).computeCsum( csd ); | 915 | (*it).computeCsum( csd ); |
916 | } | 916 | } |
917 | mergeAB( aBook ,csd, isSubset ); | 917 | mergeAB( aBook ,csd, isSubset ); |
918 | } | 918 | } |
919 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) | 919 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) |
920 | { | 920 | { |
921 | //qDebug("AddressBook::postExternSync "); | 921 | //qDebug("AddressBook::postExternSync "); |
922 | AddressBook::Iterator it; | 922 | AddressBook::Iterator it; |
923 | int foundEmpty = 0; | ||
923 | for ( it = begin(); it != end(); ++it ) { | 924 | for ( it = begin(); it != end(); ++it ) { |
924 | //qDebug("check uid %s ", (*it).uid().latin1() ); | 925 | //qDebug("check uid %s ", (*it).uid().latin1() ); |
925 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 926 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
926 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM || | 927 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM || |
927 | (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { | 928 | (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { |
928 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 929 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
929 | if ( ad.isEmpty() ) { | 930 | if ( ad.isEmpty() ) { |
930 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 931 | ++foundEmpty; |
932 | //qDebug("postExternSync:addressee is empty: %s ", (*it).uid().latin1()); | ||
933 | //qDebug("-- formatted name %s ",(*it).formattedName().latin1() ); | ||
931 | } else { | 934 | } else { |
932 | (*it).setIDStr(":"); | 935 | (*it).setIDStr(":"); |
933 | if ( setID ) { | 936 | if ( setID ) { |
934 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 937 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
935 | ad.setID( csd, (*it).externalUID() ); | 938 | ad.setID( csd, (*it).externalUID() ); |
936 | } else | 939 | } else |
937 | ad.setID( csd, (*it).uid() ); | 940 | ad.setID( csd, (*it).uid() ); |
938 | (*it).computeCsum( csd ); | 941 | (*it).computeCsum( csd ); |
939 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 942 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
940 | //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); | 943 | //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); |
941 | aBook->insertAddressee( ad , false); | 944 | aBook->insertAddressee( ad , false); |
942 | } | 945 | } |
943 | } | 946 | } |
944 | } | 947 | } |
948 | if ( foundEmpty ) { | ||
949 | qDebug("postExternSync:%d empty addressees found:\n probably filtered out by incoming sync filter.",foundEmpty ); | ||
950 | } | ||
951 | |||
945 | } | 952 | } |
946 | 953 | ||
947 | bool AddressBook::containsExternalUid( const QString& uid ) | 954 | bool AddressBook::containsExternalUid( const QString& uid ) |
948 | { | 955 | { |
949 | Iterator it; | 956 | Iterator it; |
950 | for ( it = begin(); it != end(); ++it ) { | 957 | for ( it = begin(); it != end(); ++it ) { |
951 | if ( uid == (*it).externalUID( ) ) | 958 | if ( uid == (*it).externalUID( ) ) |
952 | return true; | 959 | return true; |
953 | } | 960 | } |
954 | return false; | 961 | return false; |
955 | } | 962 | } |
956 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 963 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
957 | { | 964 | { |
958 | Iterator it; | 965 | Iterator it; |
959 | for ( it = begin(); it != end(); ++it ) { | 966 | for ( it = begin(); it != end(); ++it ) { |
960 | if ( uid == (*it).getID( profile ) ) | 967 | if ( uid == (*it).getID( profile ) ) |
961 | return (*it); | 968 | return (*it); |
962 | } | 969 | } |
963 | return Addressee(); | 970 | return Addressee(); |
964 | } | 971 | } |
965 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 972 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
966 | { | 973 | { |
967 | Iterator it; | 974 | Iterator it; |
968 | Addressee ad; | 975 | Addressee ad; |
969 | for ( it = begin(); it != end(); ++it ) { | 976 | for ( it = begin(); it != end(); ++it ) { |
970 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 977 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
971 | if ( !ad.isEmpty() ) { | 978 | if ( !ad.isEmpty() ) { |
972 | (*it).mergeContact( ad ,isSubset); | 979 | (*it).mergeContact( ad ,isSubset); |
973 | } | 980 | } |
974 | } | 981 | } |
975 | #if 0 | 982 | #if 0 |
976 | // test only | 983 | // test only |
977 | for ( it = begin(); it != end(); ++it ) { | 984 | for ( it = begin(); it != end(); ++it ) { |
978 | 985 | ||
979 | qDebug("uid %s ", (*it).uid().latin1()); | 986 | qDebug("uid %s ", (*it).uid().latin1()); |
980 | } | 987 | } |
981 | #endif | 988 | #endif |
982 | } | 989 | } |
983 | 990 | ||
984 | #if 0 | 991 | #if 0 |
985 | Addressee::List AddressBook::getExternLastSyncAddressees() | 992 | Addressee::List AddressBook::getExternLastSyncAddressees() |
986 | { | 993 | { |
987 | Addressee::List results; | 994 | Addressee::List results; |
988 | 995 | ||
989 | Iterator it; | 996 | Iterator it; |
990 | for ( it = begin(); it != end(); ++it ) { | 997 | for ( it = begin(); it != end(); ++it ) { |
991 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 998 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
992 | if ( (*it).familyName().left(4) == "!E: " ) | 999 | if ( (*it).familyName().left(4) == "!E: " ) |
993 | results.append( *it ); | 1000 | results.append( *it ); |
994 | } | 1001 | } |
995 | } | 1002 | } |
996 | 1003 | ||
997 | return results; | 1004 | return results; |
998 | } | 1005 | } |
999 | #endif | 1006 | #endif |
1000 | void AddressBook::resetTempSyncStat() | 1007 | void AddressBook::resetTempSyncStat() |
1001 | { | 1008 | { |
1002 | Iterator it; | 1009 | Iterator it; |
1003 | for ( it = begin(); it != end(); ++it ) { | 1010 | for ( it = begin(); it != end(); ++it ) { |
1004 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 1011 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
1005 | } | 1012 | } |
1006 | 1013 | ||
1007 | } | 1014 | } |
1008 | 1015 | ||
1009 | QStringList AddressBook:: uidList() | 1016 | QStringList AddressBook:: uidList() |
1010 | { | 1017 | { |
1011 | QStringList results; | 1018 | QStringList results; |
1012 | Iterator it; | 1019 | Iterator it; |
1013 | for ( it = begin(); it != end(); ++it ) { | 1020 | for ( it = begin(); it != end(); ++it ) { |
1014 | results.append( (*it).uid() ); | 1021 | results.append( (*it).uid() ); |
1015 | } | 1022 | } |
1016 | return results; | 1023 | return results; |
1017 | } | 1024 | } |
1018 | 1025 | ||
1019 | 1026 | ||
1020 | Addressee::List AddressBook::allAddressees() | 1027 | Addressee::List AddressBook::allAddressees() |
1021 | { | 1028 | { |
1022 | return d->mAddressees; | 1029 | return d->mAddressees; |
1023 | 1030 | ||
1024 | } | 1031 | } |
1025 | 1032 | ||
1026 | Addressee::List AddressBook::findByName( const QString &name ) | 1033 | Addressee::List AddressBook::findByName( const QString &name ) |
1027 | { | 1034 | { |
1028 | Addressee::List results; | 1035 | Addressee::List results; |
1029 | 1036 | ||
1030 | Iterator it; | 1037 | Iterator it; |
1031 | for ( it = begin(); it != end(); ++it ) { | 1038 | for ( it = begin(); it != end(); ++it ) { |
1032 | if ( name == (*it).realName() ) { | 1039 | if ( name == (*it).realName() ) { |
1033 | results.append( *it ); | 1040 | results.append( *it ); |
1034 | } | 1041 | } |
1035 | } | 1042 | } |
1036 | 1043 | ||
1037 | return results; | 1044 | return results; |
1038 | } | 1045 | } |
1039 | 1046 | ||
1040 | Addressee::List AddressBook::findByEmail( const QString &email ) | 1047 | Addressee::List AddressBook::findByEmail( const QString &email ) |
1041 | { | 1048 | { |
1042 | Addressee::List results; | 1049 | Addressee::List results; |
1043 | QStringList mailList; | 1050 | QStringList mailList; |
1044 | 1051 | ||
1045 | Iterator it; | 1052 | Iterator it; |
1046 | for ( it = begin(); it != end(); ++it ) { | 1053 | for ( it = begin(); it != end(); ++it ) { |
1047 | mailList = (*it).emails(); | 1054 | mailList = (*it).emails(); |
1048 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 1055 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
1049 | if ( email == (*ite) ) { | 1056 | if ( email == (*ite) ) { |
1050 | results.append( *it ); | 1057 | results.append( *it ); |
1051 | } | 1058 | } |
1052 | } | 1059 | } |
1053 | } | 1060 | } |
1054 | 1061 | ||
1055 | return results; | 1062 | return results; |
1056 | } | 1063 | } |
1057 | 1064 | ||
1058 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1065 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1059 | { | 1066 | { |
1060 | Addressee::List results; | 1067 | Addressee::List results; |
1061 | 1068 | ||
1062 | Iterator it; | 1069 | Iterator it; |
1063 | for ( it = begin(); it != end(); ++it ) { | 1070 | for ( it = begin(); it != end(); ++it ) { |
1064 | if ( (*it).hasCategory( category) ) { | 1071 | if ( (*it).hasCategory( category) ) { |
1065 | results.append( *it ); | 1072 | results.append( *it ); |
1066 | } | 1073 | } |
1067 | } | 1074 | } |
1068 | 1075 | ||
1069 | return results; | 1076 | return results; |
1070 | } | 1077 | } |
1071 | 1078 | ||
1072 | void AddressBook::dump() const | 1079 | void AddressBook::dump() const |
1073 | { | 1080 | { |
1074 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1081 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1075 | 1082 | ||
1076 | ConstIterator it; | 1083 | ConstIterator it; |
1077 | for( it = begin(); it != end(); ++it ) { | 1084 | for( it = begin(); it != end(); ++it ) { |
1078 | (*it).dump(); | 1085 | (*it).dump(); |
1079 | } | 1086 | } |
1080 | 1087 | ||
1081 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1088 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1082 | } | 1089 | } |
1083 | 1090 | ||
1084 | QString AddressBook::identifier() | 1091 | QString AddressBook::identifier() |
1085 | { | 1092 | { |
1086 | QStringList identifier; | 1093 | QStringList identifier; |
1087 | 1094 | ||
1088 | 1095 | ||
1089 | KRES::Manager<Resource>::ActiveIterator it; | 1096 | KRES::Manager<Resource>::ActiveIterator it; |
1090 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1097 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1091 | if ( !(*it)->identifier().isEmpty() ) | 1098 | if ( !(*it)->identifier().isEmpty() ) |
1092 | identifier.append( (*it)->identifier() ); | 1099 | identifier.append( (*it)->identifier() ); |
1093 | } | 1100 | } |
1094 | 1101 | ||
1095 | return identifier.join( ":" ); | 1102 | return identifier.join( ":" ); |
1096 | } | 1103 | } |
1097 | 1104 | ||
1098 | Field::List AddressBook::fields( int category ) | 1105 | Field::List AddressBook::fields( int category ) |
1099 | { | 1106 | { |
1100 | if ( d->mAllFields.isEmpty() ) { | 1107 | if ( d->mAllFields.isEmpty() ) { |
1101 | d->mAllFields = Field::allFields(); | 1108 | d->mAllFields = Field::allFields(); |
1102 | } | 1109 | } |
1103 | 1110 | ||
1104 | if ( category == Field::All ) return d->mAllFields; | 1111 | if ( category == Field::All ) return d->mAllFields; |
1105 | 1112 | ||
1106 | Field::List result; | 1113 | Field::List result; |
1107 | Field::List::ConstIterator it; | 1114 | Field::List::ConstIterator it; |
1108 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1115 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1109 | if ( (*it)->category() & category ) result.append( *it ); | 1116 | if ( (*it)->category() & category ) result.append( *it ); |
1110 | } | 1117 | } |
1111 | 1118 | ||
1112 | return result; | 1119 | return result; |
1113 | } | 1120 | } |
1114 | 1121 | ||
1115 | bool AddressBook::addCustomField( const QString &label, int category, | 1122 | bool AddressBook::addCustomField( const QString &label, int category, |
1116 | const QString &key, const QString &app ) | 1123 | const QString &key, const QString &app ) |
1117 | { | 1124 | { |
1118 | if ( d->mAllFields.isEmpty() ) { | 1125 | if ( d->mAllFields.isEmpty() ) { |
1119 | d->mAllFields = Field::allFields(); | 1126 | d->mAllFields = Field::allFields(); |
1120 | } | 1127 | } |
1121 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1128 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1122 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1129 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1123 | 1130 | ||
1124 | QString k = key.isNull() ? label : key; | 1131 | QString k = key.isNull() ? label : key; |
1125 | 1132 | ||
1126 | Field *field = Field::createCustomField( label, category, k, a ); | 1133 | Field *field = Field::createCustomField( label, category, k, a ); |
1127 | 1134 | ||
1128 | if ( !field ) return false; | 1135 | if ( !field ) return false; |
1129 | 1136 | ||
1130 | d->mAllFields.append( field ); | 1137 | d->mAllFields.append( field ); |
1131 | 1138 | ||
1132 | return true; | 1139 | return true; |
1133 | } | 1140 | } |
1134 | 1141 | ||
1135 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1142 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1136 | { | 1143 | { |
1137 | if (!ab.d) return s; | 1144 | if (!ab.d) return s; |
1138 | 1145 | ||
1139 | return s << ab.d->mAddressees; | 1146 | return s << ab.d->mAddressees; |
1140 | } | 1147 | } |
1141 | 1148 | ||
1142 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1149 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1143 | { | 1150 | { |
1144 | if (!ab.d) return s; | 1151 | if (!ab.d) return s; |
1145 | 1152 | ||
1146 | s >> ab.d->mAddressees; | 1153 | s >> ab.d->mAddressees; |
1147 | 1154 | ||
1148 | return s; | 1155 | return s; |
1149 | } | 1156 | } |
1150 | 1157 | ||
1151 | bool AddressBook::addResource( Resource *resource ) | 1158 | bool AddressBook::addResource( Resource *resource ) |
1152 | { | 1159 | { |
1153 | if ( !resource->open() ) { | 1160 | if ( !resource->open() ) { |
1154 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1161 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1155 | return false; | 1162 | return false; |
1156 | } | 1163 | } |
1157 | 1164 | ||
1158 | resource->setAddressBook( this ); | 1165 | resource->setAddressBook( this ); |
1159 | 1166 | ||
1160 | d->mManager->add( resource ); | 1167 | d->mManager->add( resource ); |
1161 | return true; | 1168 | return true; |
1162 | } | 1169 | } |
1163 | void AddressBook::removeResources() | 1170 | void AddressBook::removeResources() |
1164 | { | 1171 | { |
1165 | //remove all possible resources. This should cleanup the configfile. | 1172 | //remove all possible resources. This should cleanup the configfile. |
1166 | QPtrList<KABC::Resource> mResources = resources(); | 1173 | QPtrList<KABC::Resource> mResources = resources(); |
1167 | 1174 | ||
1168 | QPtrListIterator<KABC::Resource> it(mResources); | 1175 | QPtrListIterator<KABC::Resource> it(mResources); |
1169 | for ( ; it.current(); ++it ) { | 1176 | for ( ; it.current(); ++it ) { |
1170 | KABC::Resource *res = it.current(); | 1177 | KABC::Resource *res = it.current(); |
1171 | removeResource(res); | 1178 | removeResource(res); |
1172 | } | 1179 | } |
1173 | } | 1180 | } |
1174 | 1181 | ||
1175 | bool AddressBook::removeResource( Resource *resource ) | 1182 | bool AddressBook::removeResource( Resource *resource ) |
1176 | { | 1183 | { |
1177 | resource->close(); | 1184 | resource->close(); |
1178 | 1185 | ||
1179 | if ( resource == standardResource() ) | 1186 | if ( resource == standardResource() ) |
1180 | d->mManager->setStandardResource( 0 ); | 1187 | d->mManager->setStandardResource( 0 ); |
1181 | 1188 | ||
1182 | resource->setAddressBook( 0 ); | 1189 | resource->setAddressBook( 0 ); |
1183 | 1190 | ||
1184 | d->mManager->remove( resource ); | 1191 | d->mManager->remove( resource ); |
1185 | return true; | 1192 | return true; |
1186 | } | 1193 | } |
1187 | 1194 | ||
1188 | QPtrList<Resource> AddressBook::resources() | 1195 | QPtrList<Resource> AddressBook::resources() |
1189 | { | 1196 | { |
1190 | QPtrList<Resource> list; | 1197 | QPtrList<Resource> list; |
1191 | 1198 | ||
1192 | // qDebug("AddressBook::resources() 1"); | 1199 | // qDebug("AddressBook::resources() 1"); |
1193 | 1200 | ||
1194 | KRES::Manager<Resource>::ActiveIterator it; | 1201 | KRES::Manager<Resource>::ActiveIterator it; |
1195 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 1202 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
1196 | list.append( *it ); | 1203 | list.append( *it ); |
1197 | 1204 | ||
1198 | return list; | 1205 | return list; |
1199 | } | 1206 | } |
1200 | 1207 | ||
1201 | /*US | 1208 | /*US |
1202 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 1209 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
1203 | { | 1210 | { |
1204 | delete d->mErrorHandler; | 1211 | delete d->mErrorHandler; |
1205 | d->mErrorHandler = handler; | 1212 | d->mErrorHandler = handler; |
1206 | } | 1213 | } |
1207 | */ | 1214 | */ |
1208 | 1215 | ||
1209 | void AddressBook::error( const QString& msg ) | 1216 | void AddressBook::error( const QString& msg ) |
1210 | { | 1217 | { |
1211 | /*US | 1218 | /*US |
1212 | if ( !d->mErrorHandler ) // create default error handler | 1219 | if ( !d->mErrorHandler ) // create default error handler |
1213 | d->mErrorHandler = new ConsoleErrorHandler; | 1220 | d->mErrorHandler = new ConsoleErrorHandler; |
1214 | 1221 | ||
1215 | if ( d->mErrorHandler ) | 1222 | if ( d->mErrorHandler ) |
1216 | d->mErrorHandler->error( msg ); | 1223 | d->mErrorHandler->error( msg ); |
1217 | else | 1224 | else |
1218 | kdError(5700) << "no error handler defined" << endl; | 1225 | kdError(5700) << "no error handler defined" << endl; |
1219 | */ | 1226 | */ |
1220 | kdDebug(5700) << "msg" << endl; | 1227 | kdDebug(5700) << "msg" << endl; |
1221 | qDebug(msg); | 1228 | qDebug(msg); |
1222 | } | 1229 | } |
1223 | 1230 | ||
1224 | void AddressBook::deleteRemovedAddressees() | 1231 | void AddressBook::deleteRemovedAddressees() |
1225 | { | 1232 | { |
1226 | Addressee::List::Iterator it; | 1233 | Addressee::List::Iterator it; |
1227 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 1234 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
1228 | Resource *resource = (*it).resource(); | 1235 | Resource *resource = (*it).resource(); |
1229 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 1236 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
1230 | resource->removeAddressee( *it ); | 1237 | resource->removeAddressee( *it ); |
1231 | } | 1238 | } |
1232 | 1239 | ||
1233 | d->mRemovedAddressees.clear(); | 1240 | d->mRemovedAddressees.clear(); |
1234 | } | 1241 | } |
1235 | 1242 | ||
1236 | void AddressBook::setStandardResource( Resource *resource ) | 1243 | void AddressBook::setStandardResource( Resource *resource ) |
1237 | { | 1244 | { |
1238 | // qDebug("AddressBook::setStandardResource 1"); | 1245 | // qDebug("AddressBook::setStandardResource 1"); |
1239 | d->mManager->setStandardResource( resource ); | 1246 | d->mManager->setStandardResource( resource ); |
1240 | } | 1247 | } |
1241 | 1248 | ||
1242 | Resource *AddressBook::standardResource() | 1249 | Resource *AddressBook::standardResource() |
1243 | { | 1250 | { |
1244 | return d->mManager->standardResource(); | 1251 | return d->mManager->standardResource(); |
1245 | } | 1252 | } |
1246 | 1253 | ||
1247 | KRES::Manager<Resource> *AddressBook::resourceManager() | 1254 | KRES::Manager<Resource> *AddressBook::resourceManager() |
1248 | { | 1255 | { |
1249 | return d->mManager; | 1256 | return d->mManager; |
1250 | } | 1257 | } |
1251 | 1258 | ||
1252 | void AddressBook::cleanUp() | 1259 | void AddressBook::cleanUp() |
1253 | { | 1260 | { |
1254 | KRES::Manager<Resource>::ActiveIterator it; | 1261 | KRES::Manager<Resource>::ActiveIterator it; |
1255 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1262 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1256 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 1263 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
1257 | (*it)->cleanUp(); | 1264 | (*it)->cleanUp(); |
1258 | } | 1265 | } |
1259 | } | 1266 | } |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 568dfc4..d60cd6b 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -1,2139 +1,2141 @@ | |||
1 | /*** Warning! This file has been generated by the script makeaddressee ***/ | 1 | /*** Warning! This file has been generated by the script makeaddressee ***/ |
2 | /* | 2 | /* |
3 | This file is part of libkabc. | 3 | This file is part of libkabc. |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (c) 2004 Ulf Schenk |
25 | 25 | ||
26 | $Id$ | 26 | $Id$ |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <kconfig.h> | 29 | #include <kconfig.h> |
30 | 30 | ||
31 | #include <ksharedptr.h> | 31 | #include <ksharedptr.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <kapplication.h> | 33 | #include <kapplication.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | #include <kidmanager.h> | 35 | #include <kidmanager.h> |
36 | //US | 36 | //US |
37 | #include <kstandarddirs.h> | 37 | #include <kstandarddirs.h> |
38 | #include <libkcal/syncdefines.h> | 38 | #include <libkcal/syncdefines.h> |
39 | 39 | ||
40 | //US #include "resource.h" | 40 | //US #include "resource.h" |
41 | #include "addressee.h" | 41 | #include "addressee.h" |
42 | 42 | ||
43 | using namespace KABC; | 43 | using namespace KABC; |
44 | 44 | ||
45 | static bool matchBinaryPattern( int value, int pattern ); | 45 | static bool matchBinaryPattern( int value, int pattern ); |
46 | static bool matchBinaryPatternA( int value, int pattern ); | 46 | static bool matchBinaryPatternA( int value, int pattern ); |
47 | static bool matchBinaryPatternP( int value, int pattern ); | 47 | static bool matchBinaryPatternP( int value, int pattern ); |
48 | 48 | ||
49 | struct Addressee::AddresseeData : public KShared | 49 | struct Addressee::AddresseeData : public KShared |
50 | { | 50 | { |
51 | QString uid; | 51 | QString uid; |
52 | QString name; | 52 | QString name; |
53 | QString formattedName; | 53 | QString formattedName; |
54 | QString familyName; | 54 | QString familyName; |
55 | QString givenName; | 55 | QString givenName; |
56 | QString additionalName; | 56 | QString additionalName; |
57 | QString prefix; | 57 | QString prefix; |
58 | QString suffix; | 58 | QString suffix; |
59 | QString nickName; | 59 | QString nickName; |
60 | QDateTime birthday; | 60 | QDateTime birthday; |
61 | QString mailer; | 61 | QString mailer; |
62 | TimeZone timeZone; | 62 | TimeZone timeZone; |
63 | Geo geo; | 63 | Geo geo; |
64 | QString title; | 64 | QString title; |
65 | QString role; | 65 | QString role; |
66 | QString organization; | 66 | QString organization; |
67 | QString note; | 67 | QString note; |
68 | QString productId; | 68 | QString productId; |
69 | QDateTime revision; | 69 | QDateTime revision; |
70 | QString sortString; | 70 | QString sortString; |
71 | QString externalUID; | 71 | QString externalUID; |
72 | QString originalExternalUID; | 72 | QString originalExternalUID; |
73 | KURL url; | 73 | KURL url; |
74 | Secrecy secrecy; | 74 | Secrecy secrecy; |
75 | Picture logo; | 75 | Picture logo; |
76 | Picture photo; | 76 | Picture photo; |
77 | Sound sound; | 77 | Sound sound; |
78 | Agent agent; | 78 | Agent agent; |
79 | QString mExternalId; | 79 | QString mExternalId; |
80 | PhoneNumber::List phoneNumbers; | 80 | PhoneNumber::List phoneNumbers; |
81 | Address::List addresses; | 81 | Address::List addresses; |
82 | Key::List keys; | 82 | Key::List keys; |
83 | QStringList emails; | 83 | QStringList emails; |
84 | QStringList categories; | 84 | QStringList categories; |
85 | QStringList custom; | 85 | QStringList custom; |
86 | int mTempSyncStat; | 86 | int mTempSyncStat; |
87 | Resource *resource; | 87 | Resource *resource; |
88 | 88 | ||
89 | bool empty :1; | 89 | bool empty :1; |
90 | bool changed :1; | 90 | bool changed :1; |
91 | bool tagged :1; | 91 | bool tagged :1; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | Addressee::Addressee() | 94 | Addressee::Addressee() |
95 | { | 95 | { |
96 | mData = new AddresseeData; | 96 | mData = new AddresseeData; |
97 | mData->empty = true; | 97 | mData->empty = true; |
98 | mData->changed = false; | 98 | mData->changed = false; |
99 | mData->resource = 0; | 99 | mData->resource = 0; |
100 | mData->mExternalId = ":"; | 100 | mData->mExternalId = ":"; |
101 | mData->revision = QDateTime ( QDate( 2003,1,1)); | 101 | mData->revision = QDateTime ( QDate( 2003,1,1)); |
102 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 102 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
103 | } | 103 | } |
104 | 104 | ||
105 | Addressee::~Addressee() | 105 | Addressee::~Addressee() |
106 | { | 106 | { |
107 | } | 107 | } |
108 | 108 | ||
109 | Addressee::Addressee( const Addressee &a ) | 109 | Addressee::Addressee( const Addressee &a ) |
110 | { | 110 | { |
111 | mData = a.mData; | 111 | mData = a.mData; |
112 | } | 112 | } |
113 | 113 | ||
114 | Addressee &Addressee::operator=( const Addressee &a ) | 114 | Addressee &Addressee::operator=( const Addressee &a ) |
115 | { | 115 | { |
116 | mData = a.mData; | 116 | mData = a.mData; |
117 | return (*this); | 117 | return (*this); |
118 | } | 118 | } |
119 | 119 | ||
120 | Addressee Addressee::copy() | 120 | Addressee Addressee::copy() |
121 | { | 121 | { |
122 | Addressee a; | 122 | Addressee a; |
123 | *(a.mData) = *mData; | 123 | *(a.mData) = *mData; |
124 | return a; | 124 | return a; |
125 | } | 125 | } |
126 | 126 | ||
127 | void Addressee::detach() | 127 | void Addressee::detach() |
128 | { | 128 | { |
129 | if ( mData.count() == 1 ) return; | 129 | if ( mData.count() == 1 ) return; |
130 | *this = copy(); | 130 | *this = copy(); |
131 | } | 131 | } |
132 | 132 | ||
133 | bool Addressee::operator==( const Addressee &a ) const | 133 | bool Addressee::operator==( const Addressee &a ) const |
134 | { | 134 | { |
135 | if ( uid() != a.uid() ) return false; | 135 | if ( uid() != a.uid() ) return false; |
136 | if ( mData->name != a.mData->name ) return false; | 136 | if ( mData->name != a.mData->name ) return false; |
137 | if ( mData->formattedName != a.mData->formattedName ) return false; | 137 | if ( mData->formattedName != a.mData->formattedName ) return false; |
138 | if ( mData->familyName != a.mData->familyName ) return false; | 138 | if ( mData->familyName != a.mData->familyName ) return false; |
139 | if ( mData->givenName != a.mData->givenName ) return false; | 139 | if ( mData->givenName != a.mData->givenName ) return false; |
140 | if ( mData->additionalName != a.mData->additionalName ) return false; | 140 | if ( mData->additionalName != a.mData->additionalName ) return false; |
141 | if ( mData->prefix != a.mData->prefix ) return false; | 141 | if ( mData->prefix != a.mData->prefix ) return false; |
142 | if ( mData->suffix != a.mData->suffix ) return false; | 142 | if ( mData->suffix != a.mData->suffix ) return false; |
143 | if ( mData->nickName != a.mData->nickName ) return false; | 143 | if ( mData->nickName != a.mData->nickName ) return false; |
144 | if ( mData->birthday != a.mData->birthday ) return false; | 144 | if ( mData->birthday != a.mData->birthday ) return false; |
145 | if ( mData->mailer != a.mData->mailer ) return false; | 145 | if ( mData->mailer != a.mData->mailer ) return false; |
146 | if ( mData->timeZone != a.mData->timeZone ) return false; | 146 | if ( mData->timeZone != a.mData->timeZone ) return false; |
147 | if ( mData->geo != a.mData->geo ) return false; | 147 | if ( mData->geo != a.mData->geo ) return false; |
148 | if ( mData->title != a.mData->title ) return false; | 148 | if ( mData->title != a.mData->title ) return false; |
149 | if ( mData->role != a.mData->role ) return false; | 149 | if ( mData->role != a.mData->role ) return false; |
150 | if ( mData->organization != a.mData->organization ) return false; | 150 | if ( mData->organization != a.mData->organization ) return false; |
151 | if ( mData->note != a.mData->note ) return false; | 151 | if ( mData->note != a.mData->note ) return false; |
152 | if ( mData->productId != a.mData->productId ) return false; | 152 | if ( mData->productId != a.mData->productId ) return false; |
153 | //if ( mData->revision != a.mData->revision ) return false; | 153 | //if ( mData->revision != a.mData->revision ) return false; |
154 | if ( mData->sortString != a.mData->sortString ) return false; | 154 | if ( mData->sortString != a.mData->sortString ) return false; |
155 | if ( mData->secrecy != a.mData->secrecy ) return false; | 155 | if ( mData->secrecy != a.mData->secrecy ) return false; |
156 | if ( mData->logo != a.mData->logo ) return false; | 156 | if ( mData->logo != a.mData->logo ) return false; |
157 | if ( mData->photo != a.mData->photo ) return false; | 157 | if ( mData->photo != a.mData->photo ) return false; |
158 | if ( mData->sound != a.mData->sound ) return false; | 158 | if ( mData->sound != a.mData->sound ) return false; |
159 | if ( mData->agent != a.mData->agent ) return false; | 159 | if ( mData->agent != a.mData->agent ) return false; |
160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && | 160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && |
161 | ( mData->url != a.mData->url ) ) return false; | 161 | ( mData->url != a.mData->url ) ) return false; |
162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; | 162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; |
163 | if ( mData->addresses != a.mData->addresses ) return false; | 163 | if ( mData->addresses != a.mData->addresses ) return false; |
164 | if ( mData->keys != a.mData->keys ) return false; | 164 | if ( mData->keys != a.mData->keys ) return false; |
165 | if ( mData->emails != a.mData->emails ) return false; | 165 | if ( mData->emails != a.mData->emails ) return false; |
166 | if ( mData->categories != a.mData->categories ) return false; | 166 | if ( mData->categories != a.mData->categories ) return false; |
167 | if ( mData->custom != a.mData->custom ) return false; | 167 | if ( mData->custom != a.mData->custom ) return false; |
168 | 168 | ||
169 | return true; | 169 | return true; |
170 | } | 170 | } |
171 | 171 | ||
172 | bool Addressee::operator!=( const Addressee &a ) const | 172 | bool Addressee::operator!=( const Addressee &a ) const |
173 | { | 173 | { |
174 | return !( a == *this ); | 174 | return !( a == *this ); |
175 | } | 175 | } |
176 | 176 | ||
177 | bool Addressee::isEmpty() const | 177 | bool Addressee::isEmpty() const |
178 | { | 178 | { |
179 | return mData->empty; | 179 | return mData->empty; |
180 | } | 180 | } |
181 | ulong Addressee::getCsum4List( const QStringList & attList) | 181 | ulong Addressee::getCsum4List( const QStringList & attList) |
182 | { | 182 | { |
183 | int max = attList.count(); | 183 | int max = attList.count(); |
184 | ulong cSum = 0; | 184 | ulong cSum = 0; |
185 | int j,k,i; | 185 | int j,k,i; |
186 | int add; | 186 | int add; |
187 | for ( i = 0; i < max ; ++i ) { | 187 | for ( i = 0; i < max ; ++i ) { |
188 | QString s = attList[i]; | 188 | QString s = attList[i]; |
189 | if ( ! s.isEmpty() ){ | 189 | if ( ! s.isEmpty() ){ |
190 | j = s.length(); | 190 | j = s.length(); |
191 | for ( k = 0; k < j; ++k ) { | 191 | for ( k = 0; k < j; ++k ) { |
192 | int mul = k +1; | 192 | int mul = k +1; |
193 | add = s[k].unicode (); | 193 | add = s[k].unicode (); |
194 | if ( k < 16 ) | 194 | if ( k < 16 ) |
195 | mul = mul * mul; | 195 | mul = mul * mul; |
196 | int ii = i+1; | 196 | int ii = i+1; |
197 | add = add * mul *ii*ii*ii; | 197 | add = add * mul *ii*ii*ii; |
198 | cSum += add; | 198 | cSum += add; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | } | 202 | } |
203 | //QString dump = attList.join(","); | 203 | //QString dump = attList.join(","); |
204 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 204 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
205 | 205 | ||
206 | return cSum; | 206 | return cSum; |
207 | 207 | ||
208 | } | 208 | } |
209 | void Addressee::computeCsum(const QString &dev) | 209 | void Addressee::computeCsum(const QString &dev) |
210 | { | 210 | { |
211 | QStringList l; | 211 | QStringList l; |
212 | //if ( !mData->name.isEmpty() ) l.append(mData->name); | 212 | //if ( !mData->name.isEmpty() ) l.append(mData->name); |
213 | //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); | 213 | //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); |
214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); | 214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); |
215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); | 215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); |
216 | if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName ); | 216 | if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName ); |
217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); | 217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); |
218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); | 218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); |
219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); | 219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); |
220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); | 220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); |
221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); | 221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); |
222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); | 222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); |
223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); | 223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); |
224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); | 224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); |
225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); | 225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); |
226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); | 226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); |
227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); | 227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); |
228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); | 228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); |
229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); | 229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); |
230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); | 230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); |
231 | // if ( !mData->logo.isEmpty() ) l.append( ); | 231 | // if ( !mData->logo.isEmpty() ) l.append( ); |
232 | //if ( !mData->photo.isEmpty() ) l.append( ); | 232 | //if ( !mData->photo.isEmpty() ) l.append( ); |
233 | //if ( !mData->sound.isEmpty() ) l.append( ); | 233 | //if ( !mData->sound.isEmpty() ) l.append( ); |
234 | //if ( !mData->agent.isEmpty() ) l.append( ); | 234 | //if ( !mData->agent.isEmpty() ) l.append( ); |
235 | if ( mData->url.isValid() ) | 235 | if ( mData->url.isValid() ) |
236 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); | 236 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); |
237 | KABC::PhoneNumber::List phoneNumbers; | 237 | KABC::PhoneNumber::List phoneNumbers; |
238 | KABC::PhoneNumber::List::Iterator phoneIter; | 238 | KABC::PhoneNumber::List::Iterator phoneIter; |
239 | 239 | ||
240 | QStringList t; | 240 | QStringList t; |
241 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 241 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
242 | ++phoneIter ) | 242 | ++phoneIter ) |
243 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); | 243 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); |
244 | t.sort(); | 244 | t.sort(); |
245 | uint iii; | 245 | uint iii; |
246 | for ( iii = 0; iii < t.count(); ++iii) | 246 | for ( iii = 0; iii < t.count(); ++iii) |
247 | l.append( t[iii] ); | 247 | l.append( t[iii] ); |
248 | t = mData->emails; | 248 | t = mData->emails; |
249 | t.sort(); | 249 | t.sort(); |
250 | for ( iii = 0; iii < t.count(); ++iii) | 250 | for ( iii = 0; iii < t.count(); ++iii) |
251 | l.append( t[iii] ); | 251 | l.append( t[iii] ); |
252 | t = mData->categories; | 252 | t = mData->categories; |
253 | t.sort(); | 253 | t.sort(); |
254 | for ( iii = 0; iii < t.count(); ++iii) | 254 | for ( iii = 0; iii < t.count(); ++iii) |
255 | l.append( t[iii] ); | 255 | l.append( t[iii] ); |
256 | t = mData->custom; | 256 | t = mData->custom; |
257 | t.sort(); | 257 | t.sort(); |
258 | for ( iii = 0; iii < t.count(); ++iii) | 258 | for ( iii = 0; iii < t.count(); ++iii) |
259 | if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) { | 259 | if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) { |
260 | int find = t[iii].find (':')+1; | 260 | int find = t[iii].find (':')+1; |
261 | //qDebug("lennnn %d %d ", find, t[iii].length()); | 261 | //qDebug("lennnn %d %d ", find, t[iii].length()); |
262 | if ( find < t[iii].length()) | 262 | if ( find < t[iii].length()) |
263 | l.append( t[iii] ); | 263 | l.append( t[iii] ); |
264 | 264 | ||
265 | } | 265 | } |
266 | KABC::Address::List::Iterator addressIter; | 266 | KABC::Address::List::Iterator addressIter; |
267 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 267 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
268 | ++addressIter ) { | 268 | ++addressIter ) { |
269 | t = (*addressIter).asList(); | 269 | t = (*addressIter).asList(); |
270 | t.sort(); | 270 | t.sort(); |
271 | for ( iii = 0; iii < t.count(); ++iii) | 271 | for ( iii = 0; iii < t.count(); ++iii) |
272 | l.append( t[iii] ); | 272 | l.append( t[iii] ); |
273 | } | 273 | } |
274 | uint cs = getCsum4List(l); | 274 | uint cs = getCsum4List(l); |
275 | |||
275 | #if 0 | 276 | #if 0 |
276 | for ( iii = 0; iii < l.count(); ++iii) | 277 | for ( iii = 0; iii < l.count(); ++iii) |
277 | qDebug("%d***%s***",iii,l[iii].latin1()); | 278 | qDebug("%d***%s***",iii,l[iii].latin1()); |
278 | qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); | 279 | qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); |
279 | #endif | 280 | #endif |
281 | |||
280 | setCsum( dev, QString::number (cs )); | 282 | setCsum( dev, QString::number (cs )); |
281 | } | 283 | } |
282 | 284 | ||
283 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) | 285 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) |
284 | { | 286 | { |
285 | 287 | ||
286 | detach(); | 288 | detach(); |
287 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 289 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
288 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 290 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
289 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 291 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
290 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 292 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
291 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 293 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
292 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 294 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
293 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 295 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
294 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 296 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
295 | if ( !mData->birthday.isValid() ) | 297 | if ( !mData->birthday.isValid() ) |
296 | if ( ad.mData->birthday.isValid()) | 298 | if ( ad.mData->birthday.isValid()) |
297 | mData->birthday = ad.mData->birthday; | 299 | mData->birthday = ad.mData->birthday; |
298 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 300 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
299 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 301 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
300 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 302 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
301 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 303 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
302 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 304 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
303 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 305 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
304 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 306 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
305 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 307 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
306 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 308 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
307 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 309 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
308 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 310 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
309 | QStringList t; | 311 | QStringList t; |
310 | QStringList tAD; | 312 | QStringList tAD; |
311 | uint iii; | 313 | uint iii; |
312 | 314 | ||
313 | // ********** phone numbers | 315 | // ********** phone numbers |
314 | PhoneNumber::List phoneAD = ad.phoneNumbers(); | 316 | PhoneNumber::List phoneAD = ad.phoneNumbers(); |
315 | PhoneNumber::List::Iterator phoneItAD; | 317 | PhoneNumber::List::Iterator phoneItAD; |
316 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { | 318 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { |
317 | bool found = false; | 319 | bool found = false; |
318 | PhoneNumber::List::Iterator it; | 320 | PhoneNumber::List::Iterator it; |
319 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 321 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
320 | if ( ( *phoneItAD ).contains( (*it) ) ) { | 322 | if ( ( *phoneItAD ).contains( (*it) ) ) { |
321 | found = true; | 323 | found = true; |
322 | (*it).setType( ( *phoneItAD ).type() ); | 324 | (*it).setType( ( *phoneItAD ).type() ); |
323 | (*it).setNumber( ( *phoneItAD ).number() ); | 325 | (*it).setNumber( ( *phoneItAD ).number() ); |
324 | break; | 326 | break; |
325 | } | 327 | } |
326 | } | 328 | } |
327 | // if ( isSubSet && ! found ) | 329 | // if ( isSubSet && ! found ) |
328 | if ( ! found ) // LR try this one... | 330 | if ( ! found ) // LR try this one... |
329 | mData->phoneNumbers.append( *phoneItAD ); | 331 | mData->phoneNumbers.append( *phoneItAD ); |
330 | } | 332 | } |
331 | if ( isSubSet ) { | 333 | if ( isSubSet ) { |
332 | // ************* emails; | 334 | // ************* emails; |
333 | t = mData->emails; | 335 | t = mData->emails; |
334 | tAD = ad.mData->emails; | 336 | tAD = ad.mData->emails; |
335 | for ( iii = 0; iii < tAD.count(); ++iii) | 337 | for ( iii = 0; iii < tAD.count(); ++iii) |
336 | if ( !t.contains(tAD[iii] ) ) | 338 | if ( !t.contains(tAD[iii] ) ) |
337 | mData->emails.append( tAD[iii] ); | 339 | mData->emails.append( tAD[iii] ); |
338 | } | 340 | } |
339 | 341 | ||
340 | // ************* categories; | 342 | // ************* categories; |
341 | t = mData->categories; | 343 | t = mData->categories; |
342 | tAD = ad.mData->categories; | 344 | tAD = ad.mData->categories; |
343 | for ( iii = 0; iii < tAD.count(); ++iii) | 345 | for ( iii = 0; iii < tAD.count(); ++iii) |
344 | if ( !t.contains(tAD[iii] ) ) | 346 | if ( !t.contains(tAD[iii] ) ) |
345 | mData->categories.append( tAD[iii] ); | 347 | mData->categories.append( tAD[iii] ); |
346 | QStringList::ConstIterator it; | 348 | QStringList::ConstIterator it; |
347 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { | 349 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { |
348 | QString qualifiedName = (*it).left( (*it).find( ":" )); | 350 | QString qualifiedName = (*it).left( (*it).find( ":" )); |
349 | bool found = false; | 351 | bool found = false; |
350 | QStringList::ConstIterator itL; | 352 | QStringList::ConstIterator itL; |
351 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { | 353 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { |
352 | if ( (*itL).startsWith( qualifiedName ) ) { | 354 | if ( (*itL).startsWith( qualifiedName ) ) { |
353 | found = true; | 355 | found = true; |
354 | break; | 356 | break; |
355 | } | 357 | } |
356 | } | 358 | } |
357 | if ( ! found ) { | 359 | if ( ! found ) { |
358 | mData->custom.append( *it ); | 360 | mData->custom.append( *it ); |
359 | } | 361 | } |
360 | } | 362 | } |
361 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; | 363 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; |
362 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; | 364 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; |
363 | if ( !mData->sound.isIntern() ) { | 365 | if ( !mData->sound.isIntern() ) { |
364 | if ( mData->sound.url().isEmpty() ) { | 366 | if ( mData->sound.url().isEmpty() ) { |
365 | mData->sound = ad.mData->sound; | 367 | mData->sound = ad.mData->sound; |
366 | } | 368 | } |
367 | } | 369 | } |
368 | if ( !mData->agent.isIntern() ) { | 370 | if ( !mData->agent.isIntern() ) { |
369 | if ( mData->agent.url().isEmpty() ) { | 371 | if ( mData->agent.url().isEmpty() ) { |
370 | mData->agent = ad.mData->agent; | 372 | mData->agent = ad.mData->agent; |
371 | } | 373 | } |
372 | } | 374 | } |
373 | { | 375 | { |
374 | Key::List::Iterator itA; | 376 | Key::List::Iterator itA; |
375 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { | 377 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { |
376 | bool found = false; | 378 | bool found = false; |
377 | Key::List::Iterator it; | 379 | Key::List::Iterator it; |
378 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 380 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
379 | if ( (*it) == (*itA)) { | 381 | if ( (*it) == (*itA)) { |
380 | found = true; | 382 | found = true; |
381 | break; | 383 | break; |
382 | 384 | ||
383 | } | 385 | } |
384 | } | 386 | } |
385 | if ( ! found ) { | 387 | if ( ! found ) { |
386 | mData->keys.append( *itA ); | 388 | mData->keys.append( *itA ); |
387 | } | 389 | } |
388 | } | 390 | } |
389 | } | 391 | } |
390 | KABC::Address::List::Iterator addressIterA; | 392 | KABC::Address::List::Iterator addressIterA; |
391 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { | 393 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { |
392 | bool found = false; | 394 | bool found = false; |
393 | KABC::Address::List::Iterator addressIter; | 395 | KABC::Address::List::Iterator addressIter; |
394 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 396 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
395 | ++addressIter ) { | 397 | ++addressIter ) { |
396 | if ( (*addressIter) == (*addressIterA)) { | 398 | if ( (*addressIter) == (*addressIterA)) { |
397 | found = true; | 399 | found = true; |
398 | (*addressIter).setType( (*addressIterA).type() ); | 400 | (*addressIter).setType( (*addressIterA).type() ); |
399 | break; | 401 | break; |
400 | } | 402 | } |
401 | 403 | ||
402 | } | 404 | } |
403 | if ( isSubSet && ! found ) { | 405 | if ( isSubSet && ! found ) { |
404 | mData->addresses.append( *addressIterA ); | 406 | mData->addresses.append( *addressIterA ); |
405 | } | 407 | } |
406 | } | 408 | } |
407 | //qDebug("merge contact %s ", ad.uid().latin1()); | 409 | //qDebug("merge contact %s ", ad.uid().latin1()); |
408 | setUid( ad.uid() ); | 410 | setUid( ad.uid() ); |
409 | setRevision( ad.revision() ); | 411 | setRevision( ad.revision() ); |
410 | } | 412 | } |
411 | 413 | ||
412 | bool Addressee::removeVoice() | 414 | bool Addressee::removeVoice() |
413 | { | 415 | { |
414 | PhoneNumber::List phoneN = phoneNumbers(); | 416 | PhoneNumber::List phoneN = phoneNumbers(); |
415 | PhoneNumber::List::Iterator phoneIt; | 417 | PhoneNumber::List::Iterator phoneIt; |
416 | bool found = false; | 418 | bool found = false; |
417 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 419 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
418 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 420 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
419 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 421 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
420 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 422 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
421 | insertPhoneNumber( (*phoneIt) ); | 423 | insertPhoneNumber( (*phoneIt) ); |
422 | found = true; | 424 | found = true; |
423 | } | 425 | } |
424 | } | 426 | } |
425 | 427 | ||
426 | } | 428 | } |
427 | return found; | 429 | return found; |
428 | } | 430 | } |
429 | 431 | ||
430 | bool Addressee::containsAdr(const Addressee& ad ) | 432 | bool Addressee::containsAdr(const Addressee& ad ) |
431 | { | 433 | { |
432 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; | 434 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; |
433 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; | 435 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; |
434 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; | 436 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; |
435 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; | 437 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; |
436 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; | 438 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; |
437 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; | 439 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; |
438 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; | 440 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; |
439 | 441 | ||
440 | // compare phone numbers | 442 | // compare phone numbers |
441 | PhoneNumber::List phoneN = ad.phoneNumbers(); | 443 | PhoneNumber::List phoneN = ad.phoneNumbers(); |
442 | PhoneNumber::List::Iterator phoneIt; | 444 | PhoneNumber::List::Iterator phoneIt; |
443 | bool found = false; | 445 | bool found = false; |
444 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 446 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
445 | bool found = false; | 447 | bool found = false; |
446 | PhoneNumber::List phoneL = ad.phoneNumbers(); | 448 | PhoneNumber::List phoneL = ad.phoneNumbers(); |
447 | PhoneNumber::List::Iterator phoneItL; | 449 | PhoneNumber::List::Iterator phoneItL; |
448 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | 450 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { |
449 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | 451 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { |
450 | found = true; | 452 | found = true; |
451 | break; | 453 | break; |
452 | } | 454 | } |
453 | } | 455 | } |
454 | if ( ! found ) | 456 | if ( ! found ) |
455 | return false; | 457 | return false; |
456 | } | 458 | } |
457 | return true; | 459 | return true; |
458 | 460 | ||
459 | } | 461 | } |
460 | void Addressee::simplifyAddresses() | 462 | void Addressee::simplifyAddresses() |
461 | { | 463 | { |
462 | 464 | ||
463 | 465 | ||
464 | Address::List list; | 466 | Address::List list; |
465 | Address::List::Iterator it; | 467 | Address::List::Iterator it; |
466 | Address::List::Iterator it2; | 468 | Address::List::Iterator it2; |
467 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 469 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
468 | it2 = it; | 470 | it2 = it; |
469 | ++it2; | 471 | ++it2; |
470 | for( ; it2 != mData->addresses.end(); ++it2 ) { | 472 | for( ; it2 != mData->addresses.end(); ++it2 ) { |
471 | if ( (*it) == (*it2) ) { | 473 | if ( (*it) == (*it2) ) { |
472 | list.append( *it ); | 474 | list.append( *it ); |
473 | break; | 475 | break; |
474 | } | 476 | } |
475 | } | 477 | } |
476 | } | 478 | } |
477 | for( it = list.begin(); it != list.end(); ++it ) { | 479 | for( it = list.begin(); it != list.end(); ++it ) { |
478 | removeAddress( (*it) ); | 480 | removeAddress( (*it) ); |
479 | } | 481 | } |
480 | 482 | ||
481 | list.clear(); | 483 | list.clear(); |
482 | int max = 2; | 484 | int max = 2; |
483 | if ( mData->url.isValid() ) | 485 | if ( mData->url.isValid() ) |
484 | max = 1; | 486 | max = 1; |
485 | if ( mData->addresses.count() <= max ) return ; | 487 | if ( mData->addresses.count() <= max ) return ; |
486 | int count = 0; | 488 | int count = 0; |
487 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 489 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
488 | if ( count >= max ) | 490 | if ( count >= max ) |
489 | list.append( *it ); | 491 | list.append( *it ); |
490 | ++count; | 492 | ++count; |
491 | } | 493 | } |
492 | for( it = list.begin(); it != list.end(); ++it ) { | 494 | for( it = list.begin(); it != list.end(); ++it ) { |
493 | removeAddress( (*it) ); | 495 | removeAddress( (*it) ); |
494 | } | 496 | } |
495 | } | 497 | } |
496 | 498 | ||
497 | // removes all emails but the first | 499 | // removes all emails but the first |
498 | // needed by phone sync | 500 | // needed by phone sync |
499 | void Addressee::simplifyEmails() | 501 | void Addressee::simplifyEmails() |
500 | { | 502 | { |
501 | if ( mData->emails.count() == 0 ) return ; | 503 | if ( mData->emails.count() == 0 ) return ; |
502 | QString email = mData->emails.first(); | 504 | QString email = mData->emails.first(); |
503 | detach(); | 505 | detach(); |
504 | mData->emails.clear(); | 506 | mData->emails.clear(); |
505 | mData->emails.append( email ); | 507 | mData->emails.append( email ); |
506 | } | 508 | } |
507 | 509 | ||
508 | void Addressee::simplifyPhoneNumbers() | 510 | void Addressee::simplifyPhoneNumbers() |
509 | { | 511 | { |
510 | int max = 4; | 512 | int max = 4; |
511 | int inList = mData->phoneNumbers.count(); | 513 | int inList = mData->phoneNumbers.count(); |
512 | KABC::PhoneNumber::List removeNumbers; | 514 | KABC::PhoneNumber::List removeNumbers; |
513 | KABC::PhoneNumber::List::Iterator phoneIter; | 515 | KABC::PhoneNumber::List::Iterator phoneIter; |
514 | if ( inList > max ) { | 516 | if ( inList > max ) { |
515 | // delete non-preferred numbers | 517 | // delete non-preferred numbers |
516 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 518 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
517 | ++phoneIter ) { | 519 | ++phoneIter ) { |
518 | if ( inList > max ) { | 520 | if ( inList > max ) { |
519 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { | 521 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { |
520 | removeNumbers.append( ( *phoneIter ) ); | 522 | removeNumbers.append( ( *phoneIter ) ); |
521 | --inList; | 523 | --inList; |
522 | } | 524 | } |
523 | } else | 525 | } else |
524 | break; | 526 | break; |
525 | } | 527 | } |
526 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 528 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
527 | ++phoneIter ) { | 529 | ++phoneIter ) { |
528 | removePhoneNumber(( *phoneIter )); | 530 | removePhoneNumber(( *phoneIter )); |
529 | } | 531 | } |
530 | // delete preferred numbers | 532 | // delete preferred numbers |
531 | if ( inList > max ) { | 533 | if ( inList > max ) { |
532 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 534 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
533 | ++phoneIter ) { | 535 | ++phoneIter ) { |
534 | if ( inList > max ) { | 536 | if ( inList > max ) { |
535 | removeNumbers.append( ( *phoneIter ) ); | 537 | removeNumbers.append( ( *phoneIter ) ); |
536 | --inList; | 538 | --inList; |
537 | } else | 539 | } else |
538 | break; | 540 | break; |
539 | } | 541 | } |
540 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 542 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
541 | ++phoneIter ) { | 543 | ++phoneIter ) { |
542 | removePhoneNumber(( *phoneIter )); | 544 | removePhoneNumber(( *phoneIter )); |
543 | } | 545 | } |
544 | } | 546 | } |
545 | } | 547 | } |
546 | // remove non-numeric characters | 548 | // remove non-numeric characters |
547 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 549 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
548 | ++phoneIter ) { | 550 | ++phoneIter ) { |
549 | if ( ! ( *phoneIter ).simplifyNumber() ) | 551 | if ( ! ( *phoneIter ).simplifyNumber() ) |
550 | removeNumbers.append( ( *phoneIter ) ); | 552 | removeNumbers.append( ( *phoneIter ) ); |
551 | } | 553 | } |
552 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 554 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
553 | ++phoneIter ) { | 555 | ++phoneIter ) { |
554 | removePhoneNumber(( *phoneIter )); | 556 | removePhoneNumber(( *phoneIter )); |
555 | } | 557 | } |
556 | } | 558 | } |
557 | void Addressee::simplifyPhoneNumberTypes() | 559 | void Addressee::simplifyPhoneNumberTypes() |
558 | { | 560 | { |
559 | KABC::PhoneNumber::List::Iterator phoneIter; | 561 | KABC::PhoneNumber::List::Iterator phoneIter; |
560 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 562 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
561 | ++phoneIter ) | 563 | ++phoneIter ) |
562 | ( *phoneIter ).simplifyType(); | 564 | ( *phoneIter ).simplifyType(); |
563 | } | 565 | } |
564 | void Addressee::removeID(const QString &prof) | 566 | void Addressee::removeID(const QString &prof) |
565 | { | 567 | { |
566 | detach(); | 568 | detach(); |
567 | if ( prof.isEmpty() ) | 569 | if ( prof.isEmpty() ) |
568 | mData->mExternalId = ":"; | 570 | mData->mExternalId = ":"; |
569 | else | 571 | else |
570 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | 572 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); |
571 | 573 | ||
572 | } | 574 | } |
573 | void Addressee::setID( const QString & prof , const QString & id ) | 575 | void Addressee::setID( const QString & prof , const QString & id ) |
574 | { | 576 | { |
575 | detach(); | 577 | detach(); |
576 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); | 578 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); |
577 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 579 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
578 | } | 580 | } |
579 | void Addressee::setTempSyncStat( int id ) | 581 | void Addressee::setTempSyncStat( int id ) |
580 | { | 582 | { |
581 | if ( mData->mTempSyncStat == id ) return; | 583 | if ( mData->mTempSyncStat == id ) return; |
582 | detach(); | 584 | detach(); |
583 | mData->mTempSyncStat = id; | 585 | mData->mTempSyncStat = id; |
584 | } | 586 | } |
585 | int Addressee::tempSyncStat() const | 587 | int Addressee::tempSyncStat() const |
586 | { | 588 | { |
587 | return mData->mTempSyncStat; | 589 | return mData->mTempSyncStat; |
588 | } | 590 | } |
589 | 591 | ||
590 | QString Addressee::getID( const QString & prof) | 592 | QString Addressee::getID( const QString & prof) |
591 | { | 593 | { |
592 | return KIdManager::getId ( mData->mExternalId, prof ); | 594 | return KIdManager::getId ( mData->mExternalId, prof ); |
593 | } | 595 | } |
594 | 596 | ||
595 | void Addressee::setCsum( const QString & prof , const QString & id ) | 597 | void Addressee::setCsum( const QString & prof , const QString & id ) |
596 | { | 598 | { |
597 | detach(); | 599 | detach(); |
598 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 600 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
599 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); | 601 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); |
600 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); | 602 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); |
601 | } | 603 | } |
602 | 604 | ||
603 | QString Addressee::getCsum( const QString & prof) | 605 | QString Addressee::getCsum( const QString & prof) |
604 | { | 606 | { |
605 | return KIdManager::getCsum ( mData->mExternalId, prof ); | 607 | return KIdManager::getCsum ( mData->mExternalId, prof ); |
606 | } | 608 | } |
607 | 609 | ||
608 | void Addressee::setIDStr( const QString & s ) | 610 | void Addressee::setIDStr( const QString & s ) |
609 | { | 611 | { |
610 | detach(); | 612 | detach(); |
611 | mData->mExternalId = s; | 613 | mData->mExternalId = s; |
612 | } | 614 | } |
613 | 615 | ||
614 | QString Addressee::IDStr() const | 616 | QString Addressee::IDStr() const |
615 | { | 617 | { |
616 | return mData->mExternalId; | 618 | return mData->mExternalId; |
617 | } | 619 | } |
618 | 620 | ||
619 | void Addressee::setExternalUID( const QString &id ) | 621 | void Addressee::setExternalUID( const QString &id ) |
620 | { | 622 | { |
621 | if ( id == mData->externalUID ) return; | 623 | if ( id == mData->externalUID ) return; |
622 | detach(); | 624 | detach(); |
623 | mData->empty = false; | 625 | mData->empty = false; |
624 | mData->externalUID = id; | 626 | mData->externalUID = id; |
625 | } | 627 | } |
626 | 628 | ||
627 | QString Addressee::externalUID() const | 629 | QString Addressee::externalUID() const |
628 | { | 630 | { |
629 | return mData->externalUID; | 631 | return mData->externalUID; |
630 | } | 632 | } |
631 | void Addressee::setOriginalExternalUID( const QString &id ) | 633 | void Addressee::setOriginalExternalUID( const QString &id ) |
632 | { | 634 | { |
633 | if ( id == mData->originalExternalUID ) return; | 635 | if ( id == mData->originalExternalUID ) return; |
634 | detach(); | 636 | detach(); |
635 | mData->empty = false; | 637 | mData->empty = false; |
636 | //qDebug("*******Set orig uid %s ", id.latin1()); | 638 | //qDebug("*******Set orig uid %s ", id.latin1()); |
637 | mData->originalExternalUID = id; | 639 | mData->originalExternalUID = id; |
638 | } | 640 | } |
639 | 641 | ||
640 | QString Addressee::originalExternalUID() const | 642 | QString Addressee::originalExternalUID() const |
641 | { | 643 | { |
642 | return mData->originalExternalUID; | 644 | return mData->originalExternalUID; |
643 | } | 645 | } |
644 | 646 | ||
645 | void Addressee::setUid( const QString &id ) | 647 | void Addressee::setUid( const QString &id ) |
646 | { | 648 | { |
647 | if ( id == mData->uid ) return; | 649 | if ( id == mData->uid ) return; |
648 | detach(); | 650 | detach(); |
649 | //qDebug("****setuid %s ", id.latin1()); | 651 | //qDebug("****setuid %s ", id.latin1()); |
650 | mData->empty = false; | 652 | mData->empty = false; |
651 | mData->uid = id; | 653 | mData->uid = id; |
652 | } | 654 | } |
653 | 655 | ||
654 | QString Addressee::uid() const | 656 | QString Addressee::uid() const |
655 | { | 657 | { |
656 | if ( mData->uid.isEmpty() ) | 658 | if ( mData->uid.isEmpty() ) |
657 | mData->uid = KApplication::randomString( 10 ); | 659 | mData->uid = KApplication::randomString( 10 ); |
658 | 660 | ||
659 | return mData->uid; | 661 | return mData->uid; |
660 | } | 662 | } |
661 | 663 | ||
662 | QString Addressee::uidLabel() | 664 | QString Addressee::uidLabel() |
663 | { | 665 | { |
664 | return i18n("Unique Identifier"); | 666 | return i18n("Unique Identifier"); |
665 | } | 667 | } |
666 | 668 | ||
667 | void Addressee::setName( const QString &name ) | 669 | void Addressee::setName( const QString &name ) |
668 | { | 670 | { |
669 | if ( name == mData->name ) return; | 671 | if ( name == mData->name ) return; |
670 | detach(); | 672 | detach(); |
671 | mData->empty = false; | 673 | mData->empty = false; |
672 | mData->name = name; | 674 | mData->name = name; |
673 | } | 675 | } |
674 | 676 | ||
675 | QString Addressee::name() const | 677 | QString Addressee::name() const |
676 | { | 678 | { |
677 | return mData->name; | 679 | return mData->name; |
678 | } | 680 | } |
679 | 681 | ||
680 | QString Addressee::nameLabel() | 682 | QString Addressee::nameLabel() |
681 | { | 683 | { |
682 | return i18n("Name"); | 684 | return i18n("Name"); |
683 | } | 685 | } |
684 | 686 | ||
685 | 687 | ||
686 | void Addressee::setFormattedName( const QString &formattedName ) | 688 | void Addressee::setFormattedName( const QString &formattedName ) |
687 | { | 689 | { |
688 | if ( formattedName == mData->formattedName ) return; | 690 | if ( formattedName == mData->formattedName ) return; |
689 | detach(); | 691 | detach(); |
690 | mData->empty = false; | 692 | mData->empty = false; |
691 | mData->formattedName = formattedName; | 693 | mData->formattedName = formattedName; |
692 | } | 694 | } |
693 | 695 | ||
694 | QString Addressee::formattedName() const | 696 | QString Addressee::formattedName() const |
695 | { | 697 | { |
696 | return mData->formattedName; | 698 | return mData->formattedName; |
697 | } | 699 | } |
698 | 700 | ||
699 | QString Addressee::formattedNameLabel() | 701 | QString Addressee::formattedNameLabel() |
700 | { | 702 | { |
701 | return i18n("Formatted Name"); | 703 | return i18n("Formatted Name"); |
702 | } | 704 | } |
703 | 705 | ||
704 | 706 | ||
705 | void Addressee::setFamilyName( const QString &familyName ) | 707 | void Addressee::setFamilyName( const QString &familyName ) |
706 | { | 708 | { |
707 | if ( familyName == mData->familyName ) return; | 709 | if ( familyName == mData->familyName ) return; |
708 | detach(); | 710 | detach(); |
709 | mData->empty = false; | 711 | mData->empty = false; |
710 | mData->familyName = familyName; | 712 | mData->familyName = familyName; |
711 | } | 713 | } |
712 | 714 | ||
713 | QString Addressee::familyName() const | 715 | QString Addressee::familyName() const |
714 | { | 716 | { |
715 | return mData->familyName; | 717 | return mData->familyName; |
716 | } | 718 | } |
717 | 719 | ||
718 | QString Addressee::familyNameLabel() | 720 | QString Addressee::familyNameLabel() |
719 | { | 721 | { |
720 | return i18n("Family Name"); | 722 | return i18n("Family Name"); |
721 | } | 723 | } |
722 | 724 | ||
723 | 725 | ||
724 | void Addressee::setGivenName( const QString &givenName ) | 726 | void Addressee::setGivenName( const QString &givenName ) |
725 | { | 727 | { |
726 | if ( givenName == mData->givenName ) return; | 728 | if ( givenName == mData->givenName ) return; |
727 | detach(); | 729 | detach(); |
728 | mData->empty = false; | 730 | mData->empty = false; |
729 | mData->givenName = givenName; | 731 | mData->givenName = givenName; |
730 | } | 732 | } |
731 | 733 | ||
732 | QString Addressee::givenName() const | 734 | QString Addressee::givenName() const |
733 | { | 735 | { |
734 | return mData->givenName; | 736 | return mData->givenName; |
735 | } | 737 | } |
736 | 738 | ||
737 | QString Addressee::givenNameLabel() | 739 | QString Addressee::givenNameLabel() |
738 | { | 740 | { |
739 | return i18n("Given Name"); | 741 | return i18n("Given Name"); |
740 | } | 742 | } |
741 | 743 | ||
742 | 744 | ||
743 | void Addressee::setAdditionalName( const QString &additionalName ) | 745 | void Addressee::setAdditionalName( const QString &additionalName ) |
744 | { | 746 | { |
745 | if ( additionalName == mData->additionalName ) return; | 747 | if ( additionalName == mData->additionalName ) return; |
746 | detach(); | 748 | detach(); |
747 | mData->empty = false; | 749 | mData->empty = false; |
748 | mData->additionalName = additionalName; | 750 | mData->additionalName = additionalName; |
749 | } | 751 | } |
750 | 752 | ||
751 | QString Addressee::additionalName() const | 753 | QString Addressee::additionalName() const |
752 | { | 754 | { |
753 | return mData->additionalName; | 755 | return mData->additionalName; |
754 | } | 756 | } |
755 | 757 | ||
756 | QString Addressee::additionalNameLabel() | 758 | QString Addressee::additionalNameLabel() |
757 | { | 759 | { |
758 | return i18n("Additional Names"); | 760 | return i18n("Additional Names"); |
759 | } | 761 | } |
760 | 762 | ||
761 | 763 | ||
762 | void Addressee::setPrefix( const QString &prefix ) | 764 | void Addressee::setPrefix( const QString &prefix ) |
763 | { | 765 | { |
764 | if ( prefix == mData->prefix ) return; | 766 | if ( prefix == mData->prefix ) return; |
765 | detach(); | 767 | detach(); |
766 | mData->empty = false; | 768 | mData->empty = false; |
767 | mData->prefix = prefix; | 769 | mData->prefix = prefix; |
768 | } | 770 | } |
769 | 771 | ||
770 | QString Addressee::prefix() const | 772 | QString Addressee::prefix() const |
771 | { | 773 | { |
772 | return mData->prefix; | 774 | return mData->prefix; |
773 | } | 775 | } |
774 | 776 | ||
775 | QString Addressee::prefixLabel() | 777 | QString Addressee::prefixLabel() |
776 | { | 778 | { |
777 | return i18n("Honorific Prefixes"); | 779 | return i18n("Honorific Prefixes"); |
778 | } | 780 | } |
779 | 781 | ||
780 | 782 | ||
781 | void Addressee::setSuffix( const QString &suffix ) | 783 | void Addressee::setSuffix( const QString &suffix ) |
782 | { | 784 | { |
783 | if ( suffix == mData->suffix ) return; | 785 | if ( suffix == mData->suffix ) return; |
784 | detach(); | 786 | detach(); |
785 | mData->empty = false; | 787 | mData->empty = false; |
786 | mData->suffix = suffix; | 788 | mData->suffix = suffix; |
787 | } | 789 | } |
788 | 790 | ||
789 | QString Addressee::suffix() const | 791 | QString Addressee::suffix() const |
790 | { | 792 | { |
791 | return mData->suffix; | 793 | return mData->suffix; |
792 | } | 794 | } |
793 | 795 | ||
794 | QString Addressee::suffixLabel() | 796 | QString Addressee::suffixLabel() |
795 | { | 797 | { |
796 | return i18n("Honorific Suffixes"); | 798 | return i18n("Honorific Suffixes"); |
797 | } | 799 | } |
798 | 800 | ||
799 | 801 | ||
800 | void Addressee::setNickName( const QString &nickName ) | 802 | void Addressee::setNickName( const QString &nickName ) |
801 | { | 803 | { |
802 | if ( nickName == mData->nickName ) return; | 804 | if ( nickName == mData->nickName ) return; |
803 | detach(); | 805 | detach(); |
804 | mData->empty = false; | 806 | mData->empty = false; |
805 | mData->nickName = nickName; | 807 | mData->nickName = nickName; |
806 | } | 808 | } |
807 | 809 | ||
808 | QString Addressee::nickName() const | 810 | QString Addressee::nickName() const |
809 | { | 811 | { |
810 | return mData->nickName; | 812 | return mData->nickName; |
811 | } | 813 | } |
812 | 814 | ||
813 | QString Addressee::nickNameLabel() | 815 | QString Addressee::nickNameLabel() |
814 | { | 816 | { |
815 | return i18n("Nick Name"); | 817 | return i18n("Nick Name"); |
816 | } | 818 | } |
817 | 819 | ||
818 | 820 | ||
819 | void Addressee::setBirthday( const QDateTime &birthday ) | 821 | void Addressee::setBirthday( const QDateTime &birthday ) |
820 | { | 822 | { |
821 | if ( birthday == mData->birthday ) return; | 823 | if ( birthday == mData->birthday ) return; |
822 | detach(); | 824 | detach(); |
823 | mData->empty = false; | 825 | mData->empty = false; |
824 | mData->birthday = birthday; | 826 | mData->birthday = birthday; |
825 | } | 827 | } |
826 | 828 | ||
827 | QDateTime Addressee::birthday() const | 829 | QDateTime Addressee::birthday() const |
828 | { | 830 | { |
829 | return mData->birthday; | 831 | return mData->birthday; |
830 | } | 832 | } |
831 | 833 | ||
832 | QString Addressee::birthdayLabel() | 834 | QString Addressee::birthdayLabel() |
833 | { | 835 | { |
834 | return i18n("Birthday"); | 836 | return i18n("Birthday"); |
835 | } | 837 | } |
836 | 838 | ||
837 | 839 | ||
838 | QString Addressee::homeAddressStreetLabel() | 840 | QString Addressee::homeAddressStreetLabel() |
839 | { | 841 | { |
840 | return i18n("Home Address Street"); | 842 | return i18n("Home Address Street"); |
841 | } | 843 | } |
842 | 844 | ||
843 | 845 | ||
844 | QString Addressee::homeAddressLocalityLabel() | 846 | QString Addressee::homeAddressLocalityLabel() |
845 | { | 847 | { |
846 | return i18n("Home Address Locality"); | 848 | return i18n("Home Address Locality"); |
847 | } | 849 | } |
848 | 850 | ||
849 | 851 | ||
850 | QString Addressee::homeAddressRegionLabel() | 852 | QString Addressee::homeAddressRegionLabel() |
851 | { | 853 | { |
852 | return i18n("Home Address Region"); | 854 | return i18n("Home Address Region"); |
853 | } | 855 | } |
854 | 856 | ||
855 | 857 | ||
856 | QString Addressee::homeAddressPostalCodeLabel() | 858 | QString Addressee::homeAddressPostalCodeLabel() |
857 | { | 859 | { |
858 | return i18n("Home Address Postal Code"); | 860 | return i18n("Home Address Postal Code"); |
859 | } | 861 | } |
860 | 862 | ||
861 | 863 | ||
862 | QString Addressee::homeAddressCountryLabel() | 864 | QString Addressee::homeAddressCountryLabel() |
863 | { | 865 | { |
864 | return i18n("Home Address Country"); | 866 | return i18n("Home Address Country"); |
865 | } | 867 | } |
866 | 868 | ||
867 | 869 | ||
868 | QString Addressee::homeAddressLabelLabel() | 870 | QString Addressee::homeAddressLabelLabel() |
869 | { | 871 | { |
870 | return i18n("Home Address Label"); | 872 | return i18n("Home Address Label"); |
871 | } | 873 | } |
872 | 874 | ||
873 | 875 | ||
874 | QString Addressee::businessAddressStreetLabel() | 876 | QString Addressee::businessAddressStreetLabel() |
875 | { | 877 | { |
876 | return i18n("Business Address Street"); | 878 | return i18n("Business Address Street"); |
877 | } | 879 | } |
878 | 880 | ||
879 | 881 | ||
880 | QString Addressee::businessAddressLocalityLabel() | 882 | QString Addressee::businessAddressLocalityLabel() |
881 | { | 883 | { |
882 | return i18n("Business Address Locality"); | 884 | return i18n("Business Address Locality"); |
883 | } | 885 | } |
884 | 886 | ||
885 | 887 | ||
886 | QString Addressee::businessAddressRegionLabel() | 888 | QString Addressee::businessAddressRegionLabel() |
887 | { | 889 | { |
888 | return i18n("Business Address Region"); | 890 | return i18n("Business Address Region"); |
889 | } | 891 | } |
890 | 892 | ||
891 | 893 | ||
892 | QString Addressee::businessAddressPostalCodeLabel() | 894 | QString Addressee::businessAddressPostalCodeLabel() |
893 | { | 895 | { |
894 | return i18n("Business Address Postal Code"); | 896 | return i18n("Business Address Postal Code"); |
895 | } | 897 | } |
896 | 898 | ||
897 | 899 | ||
898 | QString Addressee::businessAddressCountryLabel() | 900 | QString Addressee::businessAddressCountryLabel() |
899 | { | 901 | { |
900 | return i18n("Business Address Country"); | 902 | return i18n("Business Address Country"); |
901 | } | 903 | } |
902 | 904 | ||
903 | 905 | ||
904 | QString Addressee::businessAddressLabelLabel() | 906 | QString Addressee::businessAddressLabelLabel() |
905 | { | 907 | { |
906 | return i18n("Business Address Label"); | 908 | return i18n("Business Address Label"); |
907 | } | 909 | } |
908 | 910 | ||
909 | 911 | ||
910 | QString Addressee::homePhoneLabel() | 912 | QString Addressee::homePhoneLabel() |
911 | { | 913 | { |
912 | return i18n("Home Phone"); | 914 | return i18n("Home Phone"); |
913 | } | 915 | } |
914 | 916 | ||
915 | 917 | ||
916 | QString Addressee::businessPhoneLabel() | 918 | QString Addressee::businessPhoneLabel() |
917 | { | 919 | { |
918 | return i18n("Business Phone"); | 920 | return i18n("Business Phone"); |
919 | } | 921 | } |
920 | 922 | ||
921 | 923 | ||
922 | QString Addressee::mobilePhoneLabel() | 924 | QString Addressee::mobilePhoneLabel() |
923 | { | 925 | { |
924 | return i18n("Mobile Phone"); | 926 | return i18n("Mobile Phone"); |
925 | } | 927 | } |
926 | 928 | ||
927 | 929 | ||
928 | QString Addressee::homeFaxLabel() | 930 | QString Addressee::homeFaxLabel() |
929 | { | 931 | { |
930 | return i18n("Home Fax"); | 932 | return i18n("Home Fax"); |
931 | } | 933 | } |
932 | 934 | ||
933 | 935 | ||
934 | QString Addressee::businessFaxLabel() | 936 | QString Addressee::businessFaxLabel() |
935 | { | 937 | { |
936 | return i18n("Business Fax"); | 938 | return i18n("Business Fax"); |
937 | } | 939 | } |
938 | 940 | ||
939 | 941 | ||
940 | QString Addressee::carPhoneLabel() | 942 | QString Addressee::carPhoneLabel() |
941 | { | 943 | { |
942 | return i18n("Car Phone"); | 944 | return i18n("Car Phone"); |
943 | } | 945 | } |
944 | 946 | ||
945 | 947 | ||
946 | QString Addressee::isdnLabel() | 948 | QString Addressee::isdnLabel() |
947 | { | 949 | { |
948 | return i18n("ISDN"); | 950 | return i18n("ISDN"); |
949 | } | 951 | } |
950 | 952 | ||
951 | 953 | ||
952 | QString Addressee::pagerLabel() | 954 | QString Addressee::pagerLabel() |
953 | { | 955 | { |
954 | return i18n("Pager"); | 956 | return i18n("Pager"); |
955 | } | 957 | } |
956 | 958 | ||
957 | QString Addressee::sipLabel() | 959 | QString Addressee::sipLabel() |
958 | { | 960 | { |
959 | return i18n("SIP"); | 961 | return i18n("SIP"); |
960 | } | 962 | } |
961 | 963 | ||
962 | QString Addressee::emailLabel() | 964 | QString Addressee::emailLabel() |
963 | { | 965 | { |
964 | return i18n("Email Address"); | 966 | return i18n("Email Address"); |
965 | } | 967 | } |
966 | 968 | ||
967 | 969 | ||
968 | void Addressee::setMailer( const QString &mailer ) | 970 | void Addressee::setMailer( const QString &mailer ) |
969 | { | 971 | { |
970 | if ( mailer == mData->mailer ) return; | 972 | if ( mailer == mData->mailer ) return; |
971 | detach(); | 973 | detach(); |
972 | mData->empty = false; | 974 | mData->empty = false; |
973 | mData->mailer = mailer; | 975 | mData->mailer = mailer; |
974 | } | 976 | } |
975 | 977 | ||
976 | QString Addressee::mailer() const | 978 | QString Addressee::mailer() const |
977 | { | 979 | { |
978 | return mData->mailer; | 980 | return mData->mailer; |
979 | } | 981 | } |
980 | 982 | ||
981 | QString Addressee::mailerLabel() | 983 | QString Addressee::mailerLabel() |
982 | { | 984 | { |
983 | return i18n("Mail Client"); | 985 | return i18n("Mail Client"); |
984 | } | 986 | } |
985 | 987 | ||
986 | 988 | ||
987 | void Addressee::setTimeZone( const TimeZone &timeZone ) | 989 | void Addressee::setTimeZone( const TimeZone &timeZone ) |
988 | { | 990 | { |
989 | if ( timeZone == mData->timeZone ) return; | 991 | if ( timeZone == mData->timeZone ) return; |
990 | detach(); | 992 | detach(); |
991 | mData->empty = false; | 993 | mData->empty = false; |
992 | mData->timeZone = timeZone; | 994 | mData->timeZone = timeZone; |
993 | } | 995 | } |
994 | 996 | ||
995 | TimeZone Addressee::timeZone() const | 997 | TimeZone Addressee::timeZone() const |
996 | { | 998 | { |
997 | return mData->timeZone; | 999 | return mData->timeZone; |
998 | } | 1000 | } |
999 | 1001 | ||
1000 | QString Addressee::timeZoneLabel() | 1002 | QString Addressee::timeZoneLabel() |
1001 | { | 1003 | { |
1002 | return i18n("Time Zone"); | 1004 | return i18n("Time Zone"); |
1003 | } | 1005 | } |
1004 | 1006 | ||
1005 | 1007 | ||
1006 | void Addressee::setGeo( const Geo &geo ) | 1008 | void Addressee::setGeo( const Geo &geo ) |
1007 | { | 1009 | { |
1008 | if ( geo == mData->geo ) return; | 1010 | if ( geo == mData->geo ) return; |
1009 | detach(); | 1011 | detach(); |
1010 | mData->empty = false; | 1012 | mData->empty = false; |
1011 | mData->geo = geo; | 1013 | mData->geo = geo; |
1012 | } | 1014 | } |
1013 | 1015 | ||
1014 | Geo Addressee::geo() const | 1016 | Geo Addressee::geo() const |
1015 | { | 1017 | { |
1016 | return mData->geo; | 1018 | return mData->geo; |
1017 | } | 1019 | } |
1018 | 1020 | ||
1019 | QString Addressee::geoLabel() | 1021 | QString Addressee::geoLabel() |
1020 | { | 1022 | { |
1021 | return i18n("Geographic Position"); | 1023 | return i18n("Geographic Position"); |
1022 | } | 1024 | } |
1023 | 1025 | ||
1024 | 1026 | ||
1025 | void Addressee::setTitle( const QString &title ) | 1027 | void Addressee::setTitle( const QString &title ) |
1026 | { | 1028 | { |
1027 | if ( title == mData->title ) return; | 1029 | if ( title == mData->title ) return; |
1028 | detach(); | 1030 | detach(); |
1029 | mData->empty = false; | 1031 | mData->empty = false; |
1030 | mData->title = title; | 1032 | mData->title = title; |
1031 | } | 1033 | } |
1032 | 1034 | ||
1033 | QString Addressee::title() const | 1035 | QString Addressee::title() const |
1034 | { | 1036 | { |
1035 | return mData->title; | 1037 | return mData->title; |
1036 | } | 1038 | } |
1037 | 1039 | ||
1038 | QString Addressee::titleLabel() | 1040 | QString Addressee::titleLabel() |
1039 | { | 1041 | { |
1040 | return i18n("Title"); | 1042 | return i18n("Title"); |
1041 | } | 1043 | } |
1042 | 1044 | ||
1043 | 1045 | ||
1044 | void Addressee::setRole( const QString &role ) | 1046 | void Addressee::setRole( const QString &role ) |
1045 | { | 1047 | { |
1046 | if ( role == mData->role ) return; | 1048 | if ( role == mData->role ) return; |
1047 | detach(); | 1049 | detach(); |
1048 | mData->empty = false; | 1050 | mData->empty = false; |
1049 | mData->role = role; | 1051 | mData->role = role; |
1050 | } | 1052 | } |
1051 | 1053 | ||
1052 | QString Addressee::role() const | 1054 | QString Addressee::role() const |
1053 | { | 1055 | { |
1054 | return mData->role; | 1056 | return mData->role; |
1055 | } | 1057 | } |
1056 | 1058 | ||
1057 | QString Addressee::roleLabel() | 1059 | QString Addressee::roleLabel() |
1058 | { | 1060 | { |
1059 | return i18n("Role"); | 1061 | return i18n("Role"); |
1060 | } | 1062 | } |
1061 | 1063 | ||
1062 | 1064 | ||
1063 | void Addressee::setOrganization( const QString &organization ) | 1065 | void Addressee::setOrganization( const QString &organization ) |
1064 | { | 1066 | { |
1065 | if ( organization == mData->organization ) return; | 1067 | if ( organization == mData->organization ) return; |
1066 | detach(); | 1068 | detach(); |
1067 | mData->empty = false; | 1069 | mData->empty = false; |
1068 | mData->organization = organization; | 1070 | mData->organization = organization; |
1069 | } | 1071 | } |
1070 | 1072 | ||
1071 | QString Addressee::organization() const | 1073 | QString Addressee::organization() const |
1072 | { | 1074 | { |
1073 | return mData->organization; | 1075 | return mData->organization; |
1074 | } | 1076 | } |
1075 | 1077 | ||
1076 | QString Addressee::organizationLabel() | 1078 | QString Addressee::organizationLabel() |
1077 | { | 1079 | { |
1078 | return i18n("Organization"); | 1080 | return i18n("Organization"); |
1079 | } | 1081 | } |
1080 | 1082 | ||
1081 | 1083 | ||
1082 | void Addressee::setNote( const QString ¬e ) | 1084 | void Addressee::setNote( const QString ¬e ) |
1083 | { | 1085 | { |
1084 | if ( note == mData->note ) return; | 1086 | if ( note == mData->note ) return; |
1085 | detach(); | 1087 | detach(); |
1086 | mData->empty = false; | 1088 | mData->empty = false; |
1087 | mData->note = note; | 1089 | mData->note = note; |
1088 | } | 1090 | } |
1089 | 1091 | ||
1090 | QString Addressee::note() const | 1092 | QString Addressee::note() const |
1091 | { | 1093 | { |
1092 | return mData->note; | 1094 | return mData->note; |
1093 | } | 1095 | } |
1094 | 1096 | ||
1095 | QString Addressee::noteLabel() | 1097 | QString Addressee::noteLabel() |
1096 | { | 1098 | { |
1097 | return i18n("Note"); | 1099 | return i18n("Note"); |
1098 | } | 1100 | } |
1099 | 1101 | ||
1100 | 1102 | ||
1101 | void Addressee::setProductId( const QString &productId ) | 1103 | void Addressee::setProductId( const QString &productId ) |
1102 | { | 1104 | { |
1103 | if ( productId == mData->productId ) return; | 1105 | if ( productId == mData->productId ) return; |
1104 | detach(); | 1106 | detach(); |
1105 | mData->empty = false; | 1107 | mData->empty = false; |
1106 | mData->productId = productId; | 1108 | mData->productId = productId; |
1107 | } | 1109 | } |
1108 | 1110 | ||
1109 | QString Addressee::productId() const | 1111 | QString Addressee::productId() const |
1110 | { | 1112 | { |
1111 | return mData->productId; | 1113 | return mData->productId; |
1112 | } | 1114 | } |
1113 | 1115 | ||
1114 | QString Addressee::productIdLabel() | 1116 | QString Addressee::productIdLabel() |
1115 | { | 1117 | { |
1116 | return i18n("Product Identifier"); | 1118 | return i18n("Product Identifier"); |
1117 | } | 1119 | } |
1118 | 1120 | ||
1119 | 1121 | ||
1120 | void Addressee::setRevision( const QDateTime &revision ) | 1122 | void Addressee::setRevision( const QDateTime &revision ) |
1121 | { | 1123 | { |
1122 | if ( revision == mData->revision ) return; | 1124 | if ( revision == mData->revision ) return; |
1123 | detach(); | 1125 | detach(); |
1124 | mData->empty = false; | 1126 | mData->empty = false; |
1125 | mData->revision = QDateTime( revision.date(), | 1127 | mData->revision = QDateTime( revision.date(), |
1126 | QTime (revision.time().hour(), | 1128 | QTime (revision.time().hour(), |
1127 | revision.time().minute(), | 1129 | revision.time().minute(), |
1128 | revision.time().second())); | 1130 | revision.time().second())); |
1129 | } | 1131 | } |
1130 | 1132 | ||
1131 | QDateTime Addressee::revision() const | 1133 | QDateTime Addressee::revision() const |
1132 | { | 1134 | { |
1133 | return mData->revision; | 1135 | return mData->revision; |
1134 | } | 1136 | } |
1135 | 1137 | ||
1136 | QString Addressee::revisionLabel() | 1138 | QString Addressee::revisionLabel() |
1137 | { | 1139 | { |
1138 | return i18n("Revision Date"); | 1140 | return i18n("Revision Date"); |
1139 | } | 1141 | } |
1140 | 1142 | ||
1141 | 1143 | ||
1142 | void Addressee::setSortString( const QString &sortString ) | 1144 | void Addressee::setSortString( const QString &sortString ) |
1143 | { | 1145 | { |
1144 | if ( sortString == mData->sortString ) return; | 1146 | if ( sortString == mData->sortString ) return; |
1145 | detach(); | 1147 | detach(); |
1146 | mData->empty = false; | 1148 | mData->empty = false; |
1147 | mData->sortString = sortString; | 1149 | mData->sortString = sortString; |
1148 | } | 1150 | } |
1149 | 1151 | ||
1150 | QString Addressee::sortString() const | 1152 | QString Addressee::sortString() const |
1151 | { | 1153 | { |
1152 | return mData->sortString; | 1154 | return mData->sortString; |
1153 | } | 1155 | } |
1154 | 1156 | ||
1155 | QString Addressee::sortStringLabel() | 1157 | QString Addressee::sortStringLabel() |
1156 | { | 1158 | { |
1157 | return i18n("Sort String"); | 1159 | return i18n("Sort String"); |
1158 | } | 1160 | } |
1159 | 1161 | ||
1160 | 1162 | ||
1161 | void Addressee::setUrl( const KURL &url ) | 1163 | void Addressee::setUrl( const KURL &url ) |
1162 | { | 1164 | { |
1163 | if ( url == mData->url ) return; | 1165 | if ( url == mData->url ) return; |
1164 | detach(); | 1166 | detach(); |
1165 | mData->empty = false; | 1167 | mData->empty = false; |
1166 | mData->url = url; | 1168 | mData->url = url; |
1167 | } | 1169 | } |
1168 | 1170 | ||
1169 | KURL Addressee::url() const | 1171 | KURL Addressee::url() const |
1170 | { | 1172 | { |
1171 | return mData->url; | 1173 | return mData->url; |
1172 | } | 1174 | } |
1173 | 1175 | ||
1174 | QString Addressee::urlLabel() | 1176 | QString Addressee::urlLabel() |
1175 | { | 1177 | { |
1176 | return i18n("URL"); | 1178 | return i18n("URL"); |
1177 | } | 1179 | } |
1178 | 1180 | ||
1179 | 1181 | ||
1180 | void Addressee::setSecrecy( const Secrecy &secrecy ) | 1182 | void Addressee::setSecrecy( const Secrecy &secrecy ) |
1181 | { | 1183 | { |
1182 | if ( secrecy == mData->secrecy ) return; | 1184 | if ( secrecy == mData->secrecy ) return; |
1183 | detach(); | 1185 | detach(); |
1184 | mData->empty = false; | 1186 | mData->empty = false; |
1185 | mData->secrecy = secrecy; | 1187 | mData->secrecy = secrecy; |
1186 | } | 1188 | } |
1187 | 1189 | ||
1188 | Secrecy Addressee::secrecy() const | 1190 | Secrecy Addressee::secrecy() const |
1189 | { | 1191 | { |
1190 | return mData->secrecy; | 1192 | return mData->secrecy; |
1191 | } | 1193 | } |
1192 | 1194 | ||
1193 | QString Addressee::secrecyLabel() | 1195 | QString Addressee::secrecyLabel() |
1194 | { | 1196 | { |
1195 | return i18n("Security Class"); | 1197 | return i18n("Security Class"); |
1196 | } | 1198 | } |
1197 | 1199 | ||
1198 | 1200 | ||
1199 | void Addressee::setLogo( const Picture &logo ) | 1201 | void Addressee::setLogo( const Picture &logo ) |
1200 | { | 1202 | { |
1201 | if ( logo == mData->logo ) return; | 1203 | if ( logo == mData->logo ) return; |
1202 | detach(); | 1204 | detach(); |
1203 | mData->empty = false; | 1205 | mData->empty = false; |
1204 | mData->logo = logo; | 1206 | mData->logo = logo; |
1205 | } | 1207 | } |
1206 | 1208 | ||
1207 | Picture Addressee::logo() const | 1209 | Picture Addressee::logo() const |
1208 | { | 1210 | { |
1209 | return mData->logo; | 1211 | return mData->logo; |
1210 | } | 1212 | } |
1211 | 1213 | ||
1212 | QString Addressee::logoLabel() | 1214 | QString Addressee::logoLabel() |
1213 | { | 1215 | { |
1214 | return i18n("Logo"); | 1216 | return i18n("Logo"); |
1215 | } | 1217 | } |
1216 | 1218 | ||
1217 | 1219 | ||
1218 | void Addressee::setPhoto( const Picture &photo ) | 1220 | void Addressee::setPhoto( const Picture &photo ) |
1219 | { | 1221 | { |
1220 | if ( photo == mData->photo ) return; | 1222 | if ( photo == mData->photo ) return; |
1221 | detach(); | 1223 | detach(); |
1222 | mData->empty = false; | 1224 | mData->empty = false; |
1223 | mData->photo = photo; | 1225 | mData->photo = photo; |
1224 | } | 1226 | } |
1225 | 1227 | ||
1226 | Picture Addressee::photo() const | 1228 | Picture Addressee::photo() const |
1227 | { | 1229 | { |
1228 | return mData->photo; | 1230 | return mData->photo; |
1229 | } | 1231 | } |
1230 | 1232 | ||
1231 | QString Addressee::photoLabel() | 1233 | QString Addressee::photoLabel() |
1232 | { | 1234 | { |
1233 | return i18n("Photo"); | 1235 | return i18n("Photo"); |
1234 | } | 1236 | } |
1235 | 1237 | ||
1236 | 1238 | ||
1237 | void Addressee::setSound( const Sound &sound ) | 1239 | void Addressee::setSound( const Sound &sound ) |
1238 | { | 1240 | { |
1239 | if ( sound == mData->sound ) return; | 1241 | if ( sound == mData->sound ) return; |
1240 | detach(); | 1242 | detach(); |
1241 | mData->empty = false; | 1243 | mData->empty = false; |
1242 | mData->sound = sound; | 1244 | mData->sound = sound; |
1243 | } | 1245 | } |
1244 | 1246 | ||
1245 | Sound Addressee::sound() const | 1247 | Sound Addressee::sound() const |
1246 | { | 1248 | { |
1247 | return mData->sound; | 1249 | return mData->sound; |
1248 | } | 1250 | } |
1249 | 1251 | ||
1250 | QString Addressee::soundLabel() | 1252 | QString Addressee::soundLabel() |
1251 | { | 1253 | { |
1252 | return i18n("Sound"); | 1254 | return i18n("Sound"); |
1253 | } | 1255 | } |
1254 | 1256 | ||
1255 | 1257 | ||
1256 | void Addressee::setAgent( const Agent &agent ) | 1258 | void Addressee::setAgent( const Agent &agent ) |
1257 | { | 1259 | { |
1258 | if ( agent == mData->agent ) return; | 1260 | if ( agent == mData->agent ) return; |
1259 | detach(); | 1261 | detach(); |
1260 | mData->empty = false; | 1262 | mData->empty = false; |
1261 | mData->agent = agent; | 1263 | mData->agent = agent; |
1262 | } | 1264 | } |
1263 | 1265 | ||
1264 | Agent Addressee::agent() const | 1266 | Agent Addressee::agent() const |
1265 | { | 1267 | { |
1266 | return mData->agent; | 1268 | return mData->agent; |
1267 | } | 1269 | } |
1268 | 1270 | ||
1269 | QString Addressee::agentLabel() | 1271 | QString Addressee::agentLabel() |
1270 | { | 1272 | { |
1271 | return i18n("Agent"); | 1273 | return i18n("Agent"); |
1272 | } | 1274 | } |
1273 | 1275 | ||
1274 | 1276 | ||
1275 | 1277 | ||
1276 | void Addressee::setNameFromString( const QString &str ) | 1278 | void Addressee::setNameFromString( const QString &str ) |
1277 | { | 1279 | { |
1278 | setFormattedName( str ); | 1280 | setFormattedName( str ); |
1279 | setName( str ); | 1281 | setName( str ); |
1280 | 1282 | ||
1281 | static bool first = true; | 1283 | static bool first = true; |
1282 | static QStringList titles; | 1284 | static QStringList titles; |
1283 | static QStringList suffixes; | 1285 | static QStringList suffixes; |
1284 | static QStringList prefixes; | 1286 | static QStringList prefixes; |
1285 | 1287 | ||
1286 | if ( first ) { | 1288 | if ( first ) { |
1287 | first = false; | 1289 | first = false; |
1288 | titles += i18n( "Dr." ); | 1290 | titles += i18n( "Dr." ); |
1289 | titles += i18n( "Miss" ); | 1291 | titles += i18n( "Miss" ); |
1290 | titles += i18n( "Mr." ); | 1292 | titles += i18n( "Mr." ); |
1291 | titles += i18n( "Mrs." ); | 1293 | titles += i18n( "Mrs." ); |
1292 | titles += i18n( "Ms." ); | 1294 | titles += i18n( "Ms." ); |
1293 | titles += i18n( "Prof." ); | 1295 | titles += i18n( "Prof." ); |
1294 | 1296 | ||
1295 | suffixes += i18n( "I" ); | 1297 | suffixes += i18n( "I" ); |
1296 | suffixes += i18n( "II" ); | 1298 | suffixes += i18n( "II" ); |
1297 | suffixes += i18n( "III" ); | 1299 | suffixes += i18n( "III" ); |
1298 | suffixes += i18n( "Jr." ); | 1300 | suffixes += i18n( "Jr." ); |
1299 | suffixes += i18n( "Sr." ); | 1301 | suffixes += i18n( "Sr." ); |
1300 | 1302 | ||
1301 | prefixes += "van"; | 1303 | prefixes += "van"; |
1302 | prefixes += "von"; | 1304 | prefixes += "von"; |
1303 | prefixes += "de"; | 1305 | prefixes += "de"; |
1304 | 1306 | ||
1305 | KConfig config( locateLocal( "config", "kabcrc") ); | 1307 | KConfig config( locateLocal( "config", "kabcrc") ); |
1306 | config.setGroup( "General" ); | 1308 | config.setGroup( "General" ); |
1307 | titles += config.readListEntry( "Prefixes" ); | 1309 | titles += config.readListEntry( "Prefixes" ); |
1308 | titles.remove( "" ); | 1310 | titles.remove( "" ); |
1309 | prefixes += config.readListEntry( "Inclusions" ); | 1311 | prefixes += config.readListEntry( "Inclusions" ); |
1310 | prefixes.remove( "" ); | 1312 | prefixes.remove( "" ); |
1311 | suffixes += config.readListEntry( "Suffixes" ); | 1313 | suffixes += config.readListEntry( "Suffixes" ); |
1312 | suffixes.remove( "" ); | 1314 | suffixes.remove( "" ); |
1313 | } | 1315 | } |
1314 | 1316 | ||
1315 | // clear all name parts | 1317 | // clear all name parts |
1316 | setPrefix( "" ); | 1318 | setPrefix( "" ); |
1317 | setGivenName( "" ); | 1319 | setGivenName( "" ); |
1318 | setAdditionalName( "" ); | 1320 | setAdditionalName( "" ); |
1319 | setFamilyName( "" ); | 1321 | setFamilyName( "" ); |
1320 | setSuffix( "" ); | 1322 | setSuffix( "" ); |
1321 | 1323 | ||
1322 | if ( str.isEmpty() ) | 1324 | if ( str.isEmpty() ) |
1323 | return; | 1325 | return; |
1324 | 1326 | ||
1325 | int i = str.find(','); | 1327 | int i = str.find(','); |
1326 | if( i < 0 ) { | 1328 | if( i < 0 ) { |
1327 | QStringList parts = QStringList::split( " ", str ); | 1329 | QStringList parts = QStringList::split( " ", str ); |
1328 | int leftOffset = 0; | 1330 | int leftOffset = 0; |
1329 | int rightOffset = parts.count() - 1; | 1331 | int rightOffset = parts.count() - 1; |
1330 | 1332 | ||
1331 | QString suffix; | 1333 | QString suffix; |
1332 | while ( rightOffset >= 0 ) { | 1334 | while ( rightOffset >= 0 ) { |
1333 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 1335 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
1334 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 1336 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
1335 | rightOffset--; | 1337 | rightOffset--; |
1336 | } else | 1338 | } else |
1337 | break; | 1339 | break; |
1338 | } | 1340 | } |
1339 | setSuffix( suffix ); | 1341 | setSuffix( suffix ); |
1340 | 1342 | ||
1341 | if ( rightOffset < 0 ) | 1343 | if ( rightOffset < 0 ) |
1342 | return; | 1344 | return; |
1343 | 1345 | ||
1344 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 1346 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
1345 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 1347 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
1346 | rightOffset--; | 1348 | rightOffset--; |
1347 | } else | 1349 | } else |
1348 | setFamilyName( parts[ rightOffset ] ); | 1350 | setFamilyName( parts[ rightOffset ] ); |
1349 | 1351 | ||
1350 | QString prefix; | 1352 | QString prefix; |
1351 | while ( leftOffset < rightOffset ) { | 1353 | while ( leftOffset < rightOffset ) { |
1352 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1354 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1353 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1355 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1354 | leftOffset++; | 1356 | leftOffset++; |
1355 | } else | 1357 | } else |
1356 | break; | 1358 | break; |
1357 | } | 1359 | } |
1358 | setPrefix( prefix ); | 1360 | setPrefix( prefix ); |
1359 | 1361 | ||
1360 | if ( leftOffset < rightOffset ) { | 1362 | if ( leftOffset < rightOffset ) { |
1361 | setGivenName( parts[ leftOffset ] ); | 1363 | setGivenName( parts[ leftOffset ] ); |
1362 | leftOffset++; | 1364 | leftOffset++; |
1363 | } | 1365 | } |
1364 | 1366 | ||
1365 | QString additionalName; | 1367 | QString additionalName; |
1366 | while ( leftOffset < rightOffset ) { | 1368 | while ( leftOffset < rightOffset ) { |
1367 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1369 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1368 | leftOffset++; | 1370 | leftOffset++; |
1369 | } | 1371 | } |
1370 | setAdditionalName( additionalName ); | 1372 | setAdditionalName( additionalName ); |
1371 | } else { | 1373 | } else { |
1372 | QString part1 = str.left( i ); | 1374 | QString part1 = str.left( i ); |
1373 | QString part2 = str.mid( i + 1 ); | 1375 | QString part2 = str.mid( i + 1 ); |
1374 | 1376 | ||
1375 | QStringList parts = QStringList::split( " ", part1 ); | 1377 | QStringList parts = QStringList::split( " ", part1 ); |
1376 | int leftOffset = 0; | 1378 | int leftOffset = 0; |
1377 | int rightOffset = parts.count() - 1; | 1379 | int rightOffset = parts.count() - 1; |
1378 | 1380 | ||
1379 | QString suffix; | 1381 | QString suffix; |
1380 | while ( rightOffset >= 0 ) { | 1382 | while ( rightOffset >= 0 ) { |
1381 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 1383 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
1382 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 1384 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
1383 | rightOffset--; | 1385 | rightOffset--; |
1384 | } else | 1386 | } else |
1385 | break; | 1387 | break; |
1386 | } | 1388 | } |
1387 | setSuffix( suffix ); | 1389 | setSuffix( suffix ); |
1388 | 1390 | ||
1389 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 1391 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
1390 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 1392 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
1391 | rightOffset--; | 1393 | rightOffset--; |
1392 | } else | 1394 | } else |
1393 | setFamilyName( parts[ rightOffset ] ); | 1395 | setFamilyName( parts[ rightOffset ] ); |
1394 | 1396 | ||
1395 | QString prefix; | 1397 | QString prefix; |
1396 | while ( leftOffset < rightOffset ) { | 1398 | while ( leftOffset < rightOffset ) { |
1397 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1399 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1398 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1400 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1399 | leftOffset++; | 1401 | leftOffset++; |
1400 | } else | 1402 | } else |
1401 | break; | 1403 | break; |
1402 | } | 1404 | } |
1403 | 1405 | ||
1404 | parts = QStringList::split( " ", part2 ); | 1406 | parts = QStringList::split( " ", part2 ); |
1405 | 1407 | ||
1406 | leftOffset = 0; | 1408 | leftOffset = 0; |
1407 | rightOffset = parts.count(); | 1409 | rightOffset = parts.count(); |
1408 | 1410 | ||
1409 | while ( leftOffset < rightOffset ) { | 1411 | while ( leftOffset < rightOffset ) { |
1410 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1412 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1411 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1413 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1412 | leftOffset++; | 1414 | leftOffset++; |
1413 | } else | 1415 | } else |
1414 | break; | 1416 | break; |
1415 | } | 1417 | } |
1416 | setPrefix( prefix ); | 1418 | setPrefix( prefix ); |
1417 | 1419 | ||
1418 | if ( leftOffset < rightOffset ) { | 1420 | if ( leftOffset < rightOffset ) { |
1419 | setGivenName( parts[ leftOffset ] ); | 1421 | setGivenName( parts[ leftOffset ] ); |
1420 | leftOffset++; | 1422 | leftOffset++; |
1421 | } | 1423 | } |
1422 | 1424 | ||
1423 | QString additionalName; | 1425 | QString additionalName; |
1424 | while ( leftOffset < rightOffset ) { | 1426 | while ( leftOffset < rightOffset ) { |
1425 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1427 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1426 | leftOffset++; | 1428 | leftOffset++; |
1427 | } | 1429 | } |
1428 | setAdditionalName( additionalName ); | 1430 | setAdditionalName( additionalName ); |
1429 | } | 1431 | } |
1430 | } | 1432 | } |
1431 | 1433 | ||
1432 | QString Addressee::realName() const | 1434 | QString Addressee::realName() const |
1433 | { | 1435 | { |
1434 | if ( !formattedName().isEmpty() ) | 1436 | if ( !formattedName().isEmpty() ) |
1435 | return formattedName(); | 1437 | return formattedName(); |
1436 | 1438 | ||
1437 | QString n = assembledName(); | 1439 | QString n = assembledName(); |
1438 | 1440 | ||
1439 | if ( n.isEmpty() ) | 1441 | if ( n.isEmpty() ) |
1440 | n = name(); | 1442 | n = name(); |
1441 | 1443 | ||
1442 | return n; | 1444 | return n; |
1443 | } | 1445 | } |
1444 | 1446 | ||
1445 | QString Addressee::assembledName() const | 1447 | QString Addressee::assembledName() const |
1446 | { | 1448 | { |
1447 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + | 1449 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + |
1448 | familyName() + " " + suffix(); | 1450 | familyName() + " " + suffix(); |
1449 | 1451 | ||
1450 | return name.simplifyWhiteSpace(); | 1452 | return name.simplifyWhiteSpace(); |
1451 | } | 1453 | } |
1452 | 1454 | ||
1453 | QString Addressee::fullEmail( const QString &email ) const | 1455 | QString Addressee::fullEmail( const QString &email ) const |
1454 | { | 1456 | { |
1455 | QString e; | 1457 | QString e; |
1456 | if ( email.isNull() ) { | 1458 | if ( email.isNull() ) { |
1457 | e = preferredEmail(); | 1459 | e = preferredEmail(); |
1458 | } else { | 1460 | } else { |
1459 | e = email; | 1461 | e = email; |
1460 | } | 1462 | } |
1461 | if ( e.isEmpty() ) return QString::null; | 1463 | if ( e.isEmpty() ) return QString::null; |
1462 | 1464 | ||
1463 | QString text; | 1465 | QString text; |
1464 | if ( realName().isEmpty() ) | 1466 | if ( realName().isEmpty() ) |
1465 | text = e; | 1467 | text = e; |
1466 | else | 1468 | else |
1467 | text = assembledName() + " <" + e + ">"; | 1469 | text = assembledName() + " <" + e + ">"; |
1468 | 1470 | ||
1469 | return text; | 1471 | return text; |
1470 | } | 1472 | } |
1471 | 1473 | ||
1472 | void Addressee::insertEmail( const QString &email, bool preferred ) | 1474 | void Addressee::insertEmail( const QString &email, bool preferred ) |
1473 | { | 1475 | { |
1474 | detach(); | 1476 | detach(); |
1475 | 1477 | ||
1476 | QStringList::Iterator it = mData->emails.find( email ); | 1478 | QStringList::Iterator it = mData->emails.find( email ); |
1477 | 1479 | ||
1478 | if ( it != mData->emails.end() ) { | 1480 | if ( it != mData->emails.end() ) { |
1479 | if ( !preferred || it == mData->emails.begin() ) return; | 1481 | if ( !preferred || it == mData->emails.begin() ) return; |
1480 | mData->emails.remove( it ); | 1482 | mData->emails.remove( it ); |
1481 | mData->emails.prepend( email ); | 1483 | mData->emails.prepend( email ); |
1482 | } else { | 1484 | } else { |
1483 | if ( preferred ) { | 1485 | if ( preferred ) { |
1484 | mData->emails.prepend( email ); | 1486 | mData->emails.prepend( email ); |
1485 | } else { | 1487 | } else { |
1486 | mData->emails.append( email ); | 1488 | mData->emails.append( email ); |
1487 | } | 1489 | } |
1488 | } | 1490 | } |
1489 | } | 1491 | } |
1490 | 1492 | ||
1491 | void Addressee::removeEmail( const QString &email ) | 1493 | void Addressee::removeEmail( const QString &email ) |
1492 | { | 1494 | { |
1493 | detach(); | 1495 | detach(); |
1494 | 1496 | ||
1495 | QStringList::Iterator it = mData->emails.find( email ); | 1497 | QStringList::Iterator it = mData->emails.find( email ); |
1496 | if ( it == mData->emails.end() ) return; | 1498 | if ( it == mData->emails.end() ) return; |
1497 | 1499 | ||
1498 | mData->emails.remove( it ); | 1500 | mData->emails.remove( it ); |
1499 | } | 1501 | } |
1500 | 1502 | ||
1501 | QString Addressee::preferredEmail() const | 1503 | QString Addressee::preferredEmail() const |
1502 | { | 1504 | { |
1503 | if ( mData->emails.count() == 0 ) return QString::null; | 1505 | if ( mData->emails.count() == 0 ) return QString::null; |
1504 | else return mData->emails.first(); | 1506 | else return mData->emails.first(); |
1505 | } | 1507 | } |
1506 | 1508 | ||
1507 | QStringList Addressee::emails() const | 1509 | QStringList Addressee::emails() const |
1508 | { | 1510 | { |
1509 | return mData->emails; | 1511 | return mData->emails; |
1510 | } | 1512 | } |
1511 | void Addressee::setEmails( const QStringList& emails ) { | 1513 | void Addressee::setEmails( const QStringList& emails ) { |
1512 | detach(); | 1514 | detach(); |
1513 | mData->emails = emails; | 1515 | mData->emails = emails; |
1514 | } | 1516 | } |
1515 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) | 1517 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) |
1516 | { | 1518 | { |
1517 | detach(); | 1519 | detach(); |
1518 | mData->empty = false; | 1520 | mData->empty = false; |
1519 | 1521 | ||
1520 | PhoneNumber::List::Iterator it; | 1522 | PhoneNumber::List::Iterator it; |
1521 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1523 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1522 | if ( (*it).id() == phoneNumber.id() ) { | 1524 | if ( (*it).id() == phoneNumber.id() ) { |
1523 | *it = phoneNumber; | 1525 | *it = phoneNumber; |
1524 | return; | 1526 | return; |
1525 | } | 1527 | } |
1526 | } | 1528 | } |
1527 | mData->phoneNumbers.append( phoneNumber ); | 1529 | mData->phoneNumbers.append( phoneNumber ); |
1528 | } | 1530 | } |
1529 | 1531 | ||
1530 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) | 1532 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) |
1531 | { | 1533 | { |
1532 | detach(); | 1534 | detach(); |
1533 | 1535 | ||
1534 | PhoneNumber::List::Iterator it; | 1536 | PhoneNumber::List::Iterator it; |
1535 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1537 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1536 | if ( (*it).id() == phoneNumber.id() ) { | 1538 | if ( (*it).id() == phoneNumber.id() ) { |
1537 | mData->phoneNumbers.remove( it ); | 1539 | mData->phoneNumbers.remove( it ); |
1538 | return; | 1540 | return; |
1539 | } | 1541 | } |
1540 | } | 1542 | } |
1541 | } | 1543 | } |
1542 | 1544 | ||
1543 | PhoneNumber Addressee::phoneNumber( int type ) const | 1545 | PhoneNumber Addressee::phoneNumber( int type ) const |
1544 | { | 1546 | { |
1545 | PhoneNumber phoneNumber( "", type ); | 1547 | PhoneNumber phoneNumber( "", type ); |
1546 | PhoneNumber::List::ConstIterator it; | 1548 | PhoneNumber::List::ConstIterator it; |
1547 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1549 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1548 | if ( matchBinaryPatternP( (*it).type(), type ) ) { | 1550 | if ( matchBinaryPatternP( (*it).type(), type ) ) { |
1549 | if ( (*it).type() & PhoneNumber::Pref ) | 1551 | if ( (*it).type() & PhoneNumber::Pref ) |
1550 | return (*it); | 1552 | return (*it); |
1551 | else if ( phoneNumber.number().isEmpty() ) | 1553 | else if ( phoneNumber.number().isEmpty() ) |
1552 | phoneNumber = (*it); | 1554 | phoneNumber = (*it); |
1553 | } | 1555 | } |
1554 | } | 1556 | } |
1555 | 1557 | ||
1556 | return phoneNumber; | 1558 | return phoneNumber; |
1557 | } | 1559 | } |
1558 | 1560 | ||
1559 | PhoneNumber::List Addressee::phoneNumbers() const | 1561 | PhoneNumber::List Addressee::phoneNumbers() const |
1560 | { | 1562 | { |
1561 | return mData->phoneNumbers; | 1563 | return mData->phoneNumbers; |
1562 | } | 1564 | } |
1563 | 1565 | ||
1564 | PhoneNumber::List Addressee::phoneNumbers( int type ) const | 1566 | PhoneNumber::List Addressee::phoneNumbers( int type ) const |
1565 | { | 1567 | { |
1566 | PhoneNumber::List list; | 1568 | PhoneNumber::List list; |
1567 | 1569 | ||
1568 | PhoneNumber::List::ConstIterator it; | 1570 | PhoneNumber::List::ConstIterator it; |
1569 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1571 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1570 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1572 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1571 | list.append( *it ); | 1573 | list.append( *it ); |
1572 | } | 1574 | } |
1573 | } | 1575 | } |
1574 | return list; | 1576 | return list; |
1575 | } | 1577 | } |
1576 | 1578 | ||
1577 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const | 1579 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const |
1578 | { | 1580 | { |
1579 | PhoneNumber::List::ConstIterator it; | 1581 | PhoneNumber::List::ConstIterator it; |
1580 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1582 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1581 | if ( (*it).id() == id ) { | 1583 | if ( (*it).id() == id ) { |
1582 | return *it; | 1584 | return *it; |
1583 | } | 1585 | } |
1584 | } | 1586 | } |
1585 | return PhoneNumber(); | 1587 | return PhoneNumber(); |
1586 | } | 1588 | } |
1587 | 1589 | ||
1588 | void Addressee::insertKey( const Key &key ) | 1590 | void Addressee::insertKey( const Key &key ) |
1589 | { | 1591 | { |
1590 | detach(); | 1592 | detach(); |
1591 | mData->empty = false; | 1593 | mData->empty = false; |
1592 | 1594 | ||
1593 | Key::List::Iterator it; | 1595 | Key::List::Iterator it; |
1594 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1596 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1595 | if ( (*it).id() == key.id() ) { | 1597 | if ( (*it).id() == key.id() ) { |
1596 | *it = key; | 1598 | *it = key; |
1597 | return; | 1599 | return; |
1598 | } | 1600 | } |
1599 | } | 1601 | } |
1600 | mData->keys.append( key ); | 1602 | mData->keys.append( key ); |
1601 | } | 1603 | } |
1602 | 1604 | ||
1603 | void Addressee::removeKey( const Key &key ) | 1605 | void Addressee::removeKey( const Key &key ) |
1604 | { | 1606 | { |
1605 | detach(); | 1607 | detach(); |
1606 | 1608 | ||
1607 | Key::List::Iterator it; | 1609 | Key::List::Iterator it; |
1608 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1610 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1609 | if ( (*it).id() == key.id() ) { | 1611 | if ( (*it).id() == key.id() ) { |
1610 | mData->keys.remove( key ); | 1612 | mData->keys.remove( key ); |
1611 | return; | 1613 | return; |
1612 | } | 1614 | } |
1613 | } | 1615 | } |
1614 | } | 1616 | } |
1615 | 1617 | ||
1616 | Key Addressee::key( int type, QString customTypeString ) const | 1618 | Key Addressee::key( int type, QString customTypeString ) const |
1617 | { | 1619 | { |
1618 | Key::List::ConstIterator it; | 1620 | Key::List::ConstIterator it; |
1619 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1621 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1620 | if ( (*it).type() == type ) { | 1622 | if ( (*it).type() == type ) { |
1621 | if ( type == Key::Custom ) { | 1623 | if ( type == Key::Custom ) { |
1622 | if ( customTypeString.isEmpty() ) { | 1624 | if ( customTypeString.isEmpty() ) { |
1623 | return *it; | 1625 | return *it; |
1624 | } else { | 1626 | } else { |
1625 | if ( (*it).customTypeString() == customTypeString ) | 1627 | if ( (*it).customTypeString() == customTypeString ) |
1626 | return (*it); | 1628 | return (*it); |
1627 | } | 1629 | } |
1628 | } else { | 1630 | } else { |
1629 | return *it; | 1631 | return *it; |
1630 | } | 1632 | } |
1631 | } | 1633 | } |
1632 | } | 1634 | } |
1633 | return Key( QString(), type ); | 1635 | return Key( QString(), type ); |
1634 | } | 1636 | } |
1635 | void Addressee::setKeys( const Key::List& list ) { | 1637 | void Addressee::setKeys( const Key::List& list ) { |
1636 | detach(); | 1638 | detach(); |
1637 | mData->keys = list; | 1639 | mData->keys = list; |
1638 | } | 1640 | } |
1639 | 1641 | ||
1640 | Key::List Addressee::keys() const | 1642 | Key::List Addressee::keys() const |
1641 | { | 1643 | { |
1642 | return mData->keys; | 1644 | return mData->keys; |
1643 | } | 1645 | } |
1644 | 1646 | ||
1645 | Key::List Addressee::keys( int type, QString customTypeString ) const | 1647 | Key::List Addressee::keys( int type, QString customTypeString ) const |
1646 | { | 1648 | { |
1647 | Key::List list; | 1649 | Key::List list; |
1648 | 1650 | ||
1649 | Key::List::ConstIterator it; | 1651 | Key::List::ConstIterator it; |
1650 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1652 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1651 | if ( (*it).type() == type ) { | 1653 | if ( (*it).type() == type ) { |
1652 | if ( type == Key::Custom ) { | 1654 | if ( type == Key::Custom ) { |
1653 | if ( customTypeString.isEmpty() ) { | 1655 | if ( customTypeString.isEmpty() ) { |
1654 | list.append(*it); | 1656 | list.append(*it); |
1655 | } else { | 1657 | } else { |
1656 | if ( (*it).customTypeString() == customTypeString ) | 1658 | if ( (*it).customTypeString() == customTypeString ) |
1657 | list.append(*it); | 1659 | list.append(*it); |
1658 | } | 1660 | } |
1659 | } else { | 1661 | } else { |
1660 | list.append(*it); | 1662 | list.append(*it); |
1661 | } | 1663 | } |
1662 | } | 1664 | } |
1663 | } | 1665 | } |
1664 | return list; | 1666 | return list; |
1665 | } | 1667 | } |
1666 | 1668 | ||
1667 | Key Addressee::findKey( const QString &id ) const | 1669 | Key Addressee::findKey( const QString &id ) const |
1668 | { | 1670 | { |
1669 | Key::List::ConstIterator it; | 1671 | Key::List::ConstIterator it; |
1670 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1672 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1671 | if ( (*it).id() == id ) { | 1673 | if ( (*it).id() == id ) { |
1672 | return *it; | 1674 | return *it; |
1673 | } | 1675 | } |
1674 | } | 1676 | } |
1675 | return Key(); | 1677 | return Key(); |
1676 | } | 1678 | } |
1677 | 1679 | ||
1678 | QString Addressee::asString() const | 1680 | QString Addressee::asString() const |
1679 | { | 1681 | { |
1680 | return "Smith, agent Smith..."; | 1682 | return "Smith, agent Smith..."; |
1681 | } | 1683 | } |
1682 | 1684 | ||
1683 | void Addressee::dump() const | 1685 | void Addressee::dump() const |
1684 | { | 1686 | { |
1685 | return; | 1687 | return; |
1686 | #if 0 | 1688 | #if 0 |
1687 | kdDebug(5700) << "Addressee {" << endl; | 1689 | kdDebug(5700) << "Addressee {" << endl; |
1688 | 1690 | ||
1689 | kdDebug(5700) << " Uid: '" << uid() << "'" << endl; | 1691 | kdDebug(5700) << " Uid: '" << uid() << "'" << endl; |
1690 | 1692 | ||
1691 | kdDebug(5700) << " Name: '" << name() << "'" << endl; | 1693 | kdDebug(5700) << " Name: '" << name() << "'" << endl; |
1692 | kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; | 1694 | kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; |
1693 | kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; | 1695 | kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; |
1694 | kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; | 1696 | kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; |
1695 | kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; | 1697 | kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; |
1696 | kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; | 1698 | kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; |
1697 | kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; | 1699 | kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; |
1698 | kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; | 1700 | kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; |
1699 | kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; | 1701 | kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; |
1700 | kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; | 1702 | kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; |
1701 | kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; | 1703 | kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; |
1702 | kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; | 1704 | kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; |
1703 | kdDebug(5700) << " Title: '" << title() << "'" << endl; | 1705 | kdDebug(5700) << " Title: '" << title() << "'" << endl; |
1704 | kdDebug(5700) << " Role: '" << role() << "'" << endl; | 1706 | kdDebug(5700) << " Role: '" << role() << "'" << endl; |
1705 | kdDebug(5700) << " Organization: '" << organization() << "'" << endl; | 1707 | kdDebug(5700) << " Organization: '" << organization() << "'" << endl; |
1706 | kdDebug(5700) << " Note: '" << note() << "'" << endl; | 1708 | kdDebug(5700) << " Note: '" << note() << "'" << endl; |
1707 | kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; | 1709 | kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; |
1708 | kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; | 1710 | kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; |
1709 | kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; | 1711 | kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; |
1710 | kdDebug(5700) << " Url: '" << url().url() << "'" << endl; | 1712 | kdDebug(5700) << " Url: '" << url().url() << "'" << endl; |
1711 | kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; | 1713 | kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; |
1712 | kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; | 1714 | kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; |
1713 | kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; | 1715 | kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; |
1714 | kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; | 1716 | kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; |
1715 | kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; | 1717 | kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; |
1716 | 1718 | ||
1717 | kdDebug(5700) << " Emails {" << endl; | 1719 | kdDebug(5700) << " Emails {" << endl; |
1718 | QStringList e = emails(); | 1720 | QStringList e = emails(); |
1719 | QStringList::ConstIterator it; | 1721 | QStringList::ConstIterator it; |
1720 | for( it = e.begin(); it != e.end(); ++it ) { | 1722 | for( it = e.begin(); it != e.end(); ++it ) { |
1721 | kdDebug(5700) << " " << (*it) << endl; | 1723 | kdDebug(5700) << " " << (*it) << endl; |
1722 | } | 1724 | } |
1723 | kdDebug(5700) << " }" << endl; | 1725 | kdDebug(5700) << " }" << endl; |
1724 | 1726 | ||
1725 | kdDebug(5700) << " PhoneNumbers {" << endl; | 1727 | kdDebug(5700) << " PhoneNumbers {" << endl; |
1726 | PhoneNumber::List p = phoneNumbers(); | 1728 | PhoneNumber::List p = phoneNumbers(); |
1727 | PhoneNumber::List::ConstIterator it2; | 1729 | PhoneNumber::List::ConstIterator it2; |
1728 | for( it2 = p.begin(); it2 != p.end(); ++it2 ) { | 1730 | for( it2 = p.begin(); it2 != p.end(); ++it2 ) { |
1729 | kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; | 1731 | kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; |
1730 | } | 1732 | } |
1731 | kdDebug(5700) << " }" << endl; | 1733 | kdDebug(5700) << " }" << endl; |
1732 | 1734 | ||
1733 | Address::List a = addresses(); | 1735 | Address::List a = addresses(); |
1734 | Address::List::ConstIterator it3; | 1736 | Address::List::ConstIterator it3; |
1735 | for( it3 = a.begin(); it3 != a.end(); ++it3 ) { | 1737 | for( it3 = a.begin(); it3 != a.end(); ++it3 ) { |
1736 | (*it3).dump(); | 1738 | (*it3).dump(); |
1737 | } | 1739 | } |
1738 | 1740 | ||
1739 | kdDebug(5700) << " Keys {" << endl; | 1741 | kdDebug(5700) << " Keys {" << endl; |
1740 | Key::List k = keys(); | 1742 | Key::List k = keys(); |
1741 | Key::List::ConstIterator it4; | 1743 | Key::List::ConstIterator it4; |
1742 | for( it4 = k.begin(); it4 != k.end(); ++it4 ) { | 1744 | for( it4 = k.begin(); it4 != k.end(); ++it4 ) { |
1743 | kdDebug(5700) << " Type: " << int((*it4).type()) << | 1745 | kdDebug(5700) << " Type: " << int((*it4).type()) << |
1744 | " Key: " << (*it4).textData() << | 1746 | " Key: " << (*it4).textData() << |
1745 | " CustomString: " << (*it4).customTypeString() << endl; | 1747 | " CustomString: " << (*it4).customTypeString() << endl; |
1746 | } | 1748 | } |
1747 | kdDebug(5700) << " }" << endl; | 1749 | kdDebug(5700) << " }" << endl; |
1748 | 1750 | ||
1749 | kdDebug(5700) << "}" << endl; | 1751 | kdDebug(5700) << "}" << endl; |
1750 | #endif | 1752 | #endif |
1751 | } | 1753 | } |
1752 | 1754 | ||
1753 | 1755 | ||
1754 | void Addressee::insertAddress( const Address &address ) | 1756 | void Addressee::insertAddress( const Address &address ) |
1755 | { | 1757 | { |
1756 | detach(); | 1758 | detach(); |
1757 | mData->empty = false; | 1759 | mData->empty = false; |
1758 | 1760 | ||
1759 | Address::List::Iterator it; | 1761 | Address::List::Iterator it; |
1760 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1762 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1761 | if ( (*it).id() == address.id() ) { | 1763 | if ( (*it).id() == address.id() ) { |
1762 | *it = address; | 1764 | *it = address; |
1763 | return; | 1765 | return; |
1764 | } | 1766 | } |
1765 | } | 1767 | } |
1766 | mData->addresses.append( address ); | 1768 | mData->addresses.append( address ); |
1767 | } | 1769 | } |
1768 | 1770 | ||
1769 | void Addressee::removeAddress( const Address &address ) | 1771 | void Addressee::removeAddress( const Address &address ) |
1770 | { | 1772 | { |
1771 | detach(); | 1773 | detach(); |
1772 | 1774 | ||
1773 | Address::List::Iterator it; | 1775 | Address::List::Iterator it; |
1774 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1776 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1775 | if ( (*it).id() == address.id() ) { | 1777 | if ( (*it).id() == address.id() ) { |
1776 | mData->addresses.remove( it ); | 1778 | mData->addresses.remove( it ); |
1777 | return; | 1779 | return; |
1778 | } | 1780 | } |
1779 | } | 1781 | } |
1780 | } | 1782 | } |
1781 | 1783 | ||
1782 | Address Addressee::address( int type ) const | 1784 | Address Addressee::address( int type ) const |
1783 | { | 1785 | { |
1784 | Address address( type ); | 1786 | Address address( type ); |
1785 | Address::List::ConstIterator it; | 1787 | Address::List::ConstIterator it; |
1786 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1788 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1787 | if ( matchBinaryPatternA( (*it).type(), type ) ) { | 1789 | if ( matchBinaryPatternA( (*it).type(), type ) ) { |
1788 | if ( (*it).type() & Address::Pref ) | 1790 | if ( (*it).type() & Address::Pref ) |
1789 | return (*it); | 1791 | return (*it); |
1790 | else if ( address.isEmpty() ) | 1792 | else if ( address.isEmpty() ) |
1791 | address = (*it); | 1793 | address = (*it); |
1792 | } | 1794 | } |
1793 | } | 1795 | } |
1794 | 1796 | ||
1795 | return address; | 1797 | return address; |
1796 | } | 1798 | } |
1797 | 1799 | ||
1798 | Address::List Addressee::addresses() const | 1800 | Address::List Addressee::addresses() const |
1799 | { | 1801 | { |
1800 | return mData->addresses; | 1802 | return mData->addresses; |
1801 | } | 1803 | } |
1802 | 1804 | ||
1803 | Address::List Addressee::addresses( int type ) const | 1805 | Address::List Addressee::addresses( int type ) const |
1804 | { | 1806 | { |
1805 | Address::List list; | 1807 | Address::List list; |
1806 | 1808 | ||
1807 | Address::List::ConstIterator it; | 1809 | Address::List::ConstIterator it; |
1808 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1810 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1809 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1811 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1810 | list.append( *it ); | 1812 | list.append( *it ); |
1811 | } | 1813 | } |
1812 | } | 1814 | } |
1813 | 1815 | ||
1814 | return list; | 1816 | return list; |
1815 | } | 1817 | } |
1816 | 1818 | ||
1817 | Address Addressee::findAddress( const QString &id ) const | 1819 | Address Addressee::findAddress( const QString &id ) const |
1818 | { | 1820 | { |
1819 | Address::List::ConstIterator it; | 1821 | Address::List::ConstIterator it; |
1820 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1822 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1821 | if ( (*it).id() == id ) { | 1823 | if ( (*it).id() == id ) { |
1822 | return *it; | 1824 | return *it; |
1823 | } | 1825 | } |
1824 | } | 1826 | } |
1825 | return Address(); | 1827 | return Address(); |
1826 | } | 1828 | } |
1827 | 1829 | ||
1828 | void Addressee::insertCategory( const QString &c ) | 1830 | void Addressee::insertCategory( const QString &c ) |
1829 | { | 1831 | { |
1830 | detach(); | 1832 | detach(); |
1831 | mData->empty = false; | 1833 | mData->empty = false; |
1832 | 1834 | ||
1833 | if ( mData->categories.contains( c ) ) return; | 1835 | if ( mData->categories.contains( c ) ) return; |
1834 | 1836 | ||
1835 | mData->categories.append( c ); | 1837 | mData->categories.append( c ); |
1836 | } | 1838 | } |
1837 | 1839 | ||
1838 | void Addressee::removeCategory( const QString &c ) | 1840 | void Addressee::removeCategory( const QString &c ) |
1839 | { | 1841 | { |
1840 | detach(); | 1842 | detach(); |
1841 | 1843 | ||
1842 | QStringList::Iterator it = mData->categories.find( c ); | 1844 | QStringList::Iterator it = mData->categories.find( c ); |
1843 | if ( it == mData->categories.end() ) return; | 1845 | if ( it == mData->categories.end() ) return; |
1844 | 1846 | ||
1845 | mData->categories.remove( it ); | 1847 | mData->categories.remove( it ); |
1846 | } | 1848 | } |
1847 | 1849 | ||
1848 | bool Addressee::hasCategory( const QString &c ) const | 1850 | bool Addressee::hasCategory( const QString &c ) const |
1849 | { | 1851 | { |
1850 | return ( mData->categories.contains( c ) ); | 1852 | return ( mData->categories.contains( c ) ); |
1851 | } | 1853 | } |
1852 | 1854 | ||
1853 | void Addressee::setCategories( const QStringList &c ) | 1855 | void Addressee::setCategories( const QStringList &c ) |
1854 | { | 1856 | { |
1855 | detach(); | 1857 | detach(); |
1856 | mData->empty = false; | 1858 | mData->empty = false; |
1857 | 1859 | ||
1858 | mData->categories = c; | 1860 | mData->categories = c; |
1859 | } | 1861 | } |
1860 | 1862 | ||
1861 | QStringList Addressee::categories() const | 1863 | QStringList Addressee::categories() const |
1862 | { | 1864 | { |
1863 | return mData->categories; | 1865 | return mData->categories; |
1864 | } | 1866 | } |
1865 | 1867 | ||
1866 | void Addressee::insertCustom( const QString &app, const QString &name, | 1868 | void Addressee::insertCustom( const QString &app, const QString &name, |
1867 | const QString &value ) | 1869 | const QString &value ) |
1868 | { | 1870 | { |
1869 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; | 1871 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; |
1870 | 1872 | ||
1871 | detach(); | 1873 | detach(); |
1872 | mData->empty = false; | 1874 | mData->empty = false; |
1873 | 1875 | ||
1874 | QString qualifiedName = app + "-" + name + ":"; | 1876 | QString qualifiedName = app + "-" + name + ":"; |
1875 | 1877 | ||
1876 | QStringList::Iterator it; | 1878 | QStringList::Iterator it; |
1877 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1879 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1878 | if ( (*it).startsWith( qualifiedName ) ) { | 1880 | if ( (*it).startsWith( qualifiedName ) ) { |
1879 | (*it) = qualifiedName + value; | 1881 | (*it) = qualifiedName + value; |
1880 | return; | 1882 | return; |
1881 | } | 1883 | } |
1882 | } | 1884 | } |
1883 | mData->custom.append( qualifiedName + value ); | 1885 | mData->custom.append( qualifiedName + value ); |
1884 | } | 1886 | } |
1885 | 1887 | ||
1886 | void Addressee::removeCustom( const QString &app, const QString &name) | 1888 | void Addressee::removeCustom( const QString &app, const QString &name) |
1887 | { | 1889 | { |
1888 | detach(); | 1890 | detach(); |
1889 | 1891 | ||
1890 | QString qualifiedName = app + "-" + name + ":"; | 1892 | QString qualifiedName = app + "-" + name + ":"; |
1891 | 1893 | ||
1892 | QStringList::Iterator it; | 1894 | QStringList::Iterator it; |
1893 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1895 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1894 | if ( (*it).startsWith( qualifiedName ) ) { | 1896 | if ( (*it).startsWith( qualifiedName ) ) { |
1895 | mData->custom.remove( it ); | 1897 | mData->custom.remove( it ); |
1896 | return; | 1898 | return; |
1897 | } | 1899 | } |
1898 | } | 1900 | } |
1899 | } | 1901 | } |
1900 | 1902 | ||
1901 | QString Addressee::custom( const QString &app, const QString &name ) const | 1903 | QString Addressee::custom( const QString &app, const QString &name ) const |
1902 | { | 1904 | { |
1903 | QString qualifiedName = app + "-" + name + ":"; | 1905 | QString qualifiedName = app + "-" + name + ":"; |
1904 | QString value; | 1906 | QString value; |
1905 | 1907 | ||
1906 | QStringList::ConstIterator it; | 1908 | QStringList::ConstIterator it; |
1907 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1909 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1908 | if ( (*it).startsWith( qualifiedName ) ) { | 1910 | if ( (*it).startsWith( qualifiedName ) ) { |
1909 | value = (*it).mid( (*it).find( ":" ) + 1 ); | 1911 | value = (*it).mid( (*it).find( ":" ) + 1 ); |
1910 | break; | 1912 | break; |
1911 | } | 1913 | } |
1912 | } | 1914 | } |
1913 | 1915 | ||
1914 | return value; | 1916 | return value; |
1915 | } | 1917 | } |
1916 | 1918 | ||
1917 | void Addressee::setCustoms( const QStringList &l ) | 1919 | void Addressee::setCustoms( const QStringList &l ) |
1918 | { | 1920 | { |
1919 | detach(); | 1921 | detach(); |
1920 | mData->empty = false; | 1922 | mData->empty = false; |
1921 | 1923 | ||
1922 | mData->custom = l; | 1924 | mData->custom = l; |
1923 | } | 1925 | } |
1924 | 1926 | ||
1925 | QStringList Addressee::customs() const | 1927 | QStringList Addressee::customs() const |
1926 | { | 1928 | { |
1927 | return mData->custom; | 1929 | return mData->custom; |
1928 | } | 1930 | } |
1929 | 1931 | ||
1930 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, | 1932 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, |
1931 | QString &email) | 1933 | QString &email) |
1932 | { | 1934 | { |
1933 | int startPos, endPos, len; | 1935 | int startPos, endPos, len; |
1934 | QString partA, partB, result; | 1936 | QString partA, partB, result; |
1935 | char endCh = '>'; | 1937 | char endCh = '>'; |
1936 | 1938 | ||
1937 | startPos = rawEmail.find('<'); | 1939 | startPos = rawEmail.find('<'); |
1938 | if (startPos < 0) | 1940 | if (startPos < 0) |
1939 | { | 1941 | { |
1940 | startPos = rawEmail.find('('); | 1942 | startPos = rawEmail.find('('); |
1941 | endCh = ')'; | 1943 | endCh = ')'; |
1942 | } | 1944 | } |
1943 | if (startPos < 0) | 1945 | if (startPos < 0) |
1944 | { | 1946 | { |
1945 | // We couldn't find any separators, so we assume the whole string | 1947 | // We couldn't find any separators, so we assume the whole string |
1946 | // is the email address | 1948 | // is the email address |
1947 | email = rawEmail; | 1949 | email = rawEmail; |
1948 | fullName = ""; | 1950 | fullName = ""; |
1949 | } | 1951 | } |
1950 | else | 1952 | else |
1951 | { | 1953 | { |
1952 | // We have a start position, try to find an end | 1954 | // We have a start position, try to find an end |
1953 | endPos = rawEmail.find(endCh, startPos+1); | 1955 | endPos = rawEmail.find(endCh, startPos+1); |
1954 | 1956 | ||
1955 | if (endPos < 0) | 1957 | if (endPos < 0) |
1956 | { | 1958 | { |
1957 | // We couldn't find the end of the email address. We can only | 1959 | // We couldn't find the end of the email address. We can only |
1958 | // assume the entire string is the email address. | 1960 | // assume the entire string is the email address. |
1959 | email = rawEmail; | 1961 | email = rawEmail; |
1960 | fullName = ""; | 1962 | fullName = ""; |
1961 | } | 1963 | } |
1962 | else | 1964 | else |
1963 | { | 1965 | { |
1964 | // We have a start and end to the email address | 1966 | // We have a start and end to the email address |
1965 | 1967 | ||
1966 | // Grab the name part | 1968 | // Grab the name part |
1967 | fullName = rawEmail.left(startPos).stripWhiteSpace(); | 1969 | fullName = rawEmail.left(startPos).stripWhiteSpace(); |
1968 | 1970 | ||
1969 | // grab the email part | 1971 | // grab the email part |
1970 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); | 1972 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); |
1971 | 1973 | ||
1972 | // Check that we do not have any extra characters on the end of the | 1974 | // Check that we do not have any extra characters on the end of the |
1973 | // strings | 1975 | // strings |
1974 | len = fullName.length(); | 1976 | len = fullName.length(); |
1975 | if (fullName[0]=='"' && fullName[len-1]=='"') | 1977 | if (fullName[0]=='"' && fullName[len-1]=='"') |
1976 | fullName = fullName.mid(1, len-2); | 1978 | fullName = fullName.mid(1, len-2); |
1977 | else if (fullName[0]=='<' && fullName[len-1]=='>') | 1979 | else if (fullName[0]=='<' && fullName[len-1]=='>') |
1978 | fullName = fullName.mid(1, len-2); | 1980 | fullName = fullName.mid(1, len-2); |
1979 | else if (fullName[0]=='(' && fullName[len-1]==')') | 1981 | else if (fullName[0]=='(' && fullName[len-1]==')') |
1980 | fullName = fullName.mid(1, len-2); | 1982 | fullName = fullName.mid(1, len-2); |
1981 | } | 1983 | } |
1982 | } | 1984 | } |
1983 | } | 1985 | } |
1984 | 1986 | ||
1985 | void Addressee::setResource( Resource *resource ) | 1987 | void Addressee::setResource( Resource *resource ) |
1986 | { | 1988 | { |
1987 | detach(); | 1989 | detach(); |
1988 | mData->resource = resource; | 1990 | mData->resource = resource; |
1989 | } | 1991 | } |
1990 | 1992 | ||
1991 | Resource *Addressee::resource() const | 1993 | Resource *Addressee::resource() const |
1992 | { | 1994 | { |
1993 | return mData->resource; | 1995 | return mData->resource; |
1994 | } | 1996 | } |
1995 | 1997 | ||
1996 | //US | 1998 | //US |
1997 | QString Addressee::resourceLabel() | 1999 | QString Addressee::resourceLabel() |
1998 | { | 2000 | { |
1999 | return i18n("Resource"); | 2001 | return i18n("Resource"); |
2000 | } | 2002 | } |
2001 | QString Addressee::categoryLabel() | 2003 | QString Addressee::categoryLabel() |
2002 | { | 2004 | { |
2003 | return i18n("Category"); | 2005 | return i18n("Category"); |
2004 | } | 2006 | } |
2005 | 2007 | ||
2006 | void Addressee::setChanged( bool value ) | 2008 | void Addressee::setChanged( bool value ) |
2007 | { | 2009 | { |
2008 | detach(); | 2010 | detach(); |
2009 | mData->changed = value; | 2011 | mData->changed = value; |
2010 | } | 2012 | } |
2011 | 2013 | ||
2012 | bool Addressee::changed() const | 2014 | bool Addressee::changed() const |
2013 | { | 2015 | { |
2014 | return mData->changed; | 2016 | return mData->changed; |
2015 | } | 2017 | } |
2016 | 2018 | ||
2017 | void Addressee::setTagged( bool value ) | 2019 | void Addressee::setTagged( bool value ) |
2018 | { | 2020 | { |
2019 | detach(); | 2021 | detach(); |
2020 | mData->tagged = value; | 2022 | mData->tagged = value; |
2021 | } | 2023 | } |
2022 | 2024 | ||
2023 | bool Addressee::tagged() const | 2025 | bool Addressee::tagged() const |
2024 | { | 2026 | { |
2025 | return mData->tagged; | 2027 | return mData->tagged; |
2026 | } | 2028 | } |
2027 | 2029 | ||
2028 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) | 2030 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) |
2029 | { | 2031 | { |
2030 | if (!a.mData) return s; | 2032 | if (!a.mData) return s; |
2031 | 2033 | ||
2032 | s << a.uid(); | 2034 | s << a.uid(); |
2033 | 2035 | ||
2034 | s << a.mData->name; | 2036 | s << a.mData->name; |
2035 | s << a.mData->formattedName; | 2037 | s << a.mData->formattedName; |
2036 | s << a.mData->familyName; | 2038 | s << a.mData->familyName; |
2037 | s << a.mData->givenName; | 2039 | s << a.mData->givenName; |
2038 | s << a.mData->additionalName; | 2040 | s << a.mData->additionalName; |
2039 | s << a.mData->prefix; | 2041 | s << a.mData->prefix; |
2040 | s << a.mData->suffix; | 2042 | s << a.mData->suffix; |
2041 | s << a.mData->nickName; | 2043 | s << a.mData->nickName; |
2042 | s << a.mData->birthday; | 2044 | s << a.mData->birthday; |
2043 | s << a.mData->mailer; | 2045 | s << a.mData->mailer; |
2044 | s << a.mData->timeZone; | 2046 | s << a.mData->timeZone; |
2045 | s << a.mData->geo; | 2047 | s << a.mData->geo; |
2046 | s << a.mData->title; | 2048 | s << a.mData->title; |
2047 | s << a.mData->role; | 2049 | s << a.mData->role; |
2048 | s << a.mData->organization; | 2050 | s << a.mData->organization; |
2049 | s << a.mData->note; | 2051 | s << a.mData->note; |
2050 | s << a.mData->productId; | 2052 | s << a.mData->productId; |
2051 | s << a.mData->revision; | 2053 | s << a.mData->revision; |
2052 | s << a.mData->sortString; | 2054 | s << a.mData->sortString; |
2053 | s << a.mData->url; | 2055 | s << a.mData->url; |
2054 | s << a.mData->secrecy; | 2056 | s << a.mData->secrecy; |
2055 | s << a.mData->logo; | 2057 | s << a.mData->logo; |
2056 | s << a.mData->photo; | 2058 | s << a.mData->photo; |
2057 | s << a.mData->sound; | 2059 | s << a.mData->sound; |
2058 | s << a.mData->agent; | 2060 | s << a.mData->agent; |
2059 | s << a.mData->phoneNumbers; | 2061 | s << a.mData->phoneNumbers; |
2060 | s << a.mData->addresses; | 2062 | s << a.mData->addresses; |
2061 | s << a.mData->emails; | 2063 | s << a.mData->emails; |
2062 | s << a.mData->categories; | 2064 | s << a.mData->categories; |
2063 | s << a.mData->custom; | 2065 | s << a.mData->custom; |
2064 | s << a.mData->keys; | 2066 | s << a.mData->keys; |
2065 | return s; | 2067 | return s; |
2066 | } | 2068 | } |
2067 | 2069 | ||
2068 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) | 2070 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) |
2069 | { | 2071 | { |
2070 | if (!a.mData) return s; | 2072 | if (!a.mData) return s; |
2071 | 2073 | ||
2072 | s >> a.mData->uid; | 2074 | s >> a.mData->uid; |
2073 | 2075 | ||
2074 | s >> a.mData->name; | 2076 | s >> a.mData->name; |
2075 | s >> a.mData->formattedName; | 2077 | s >> a.mData->formattedName; |
2076 | s >> a.mData->familyName; | 2078 | s >> a.mData->familyName; |
2077 | s >> a.mData->givenName; | 2079 | s >> a.mData->givenName; |
2078 | s >> a.mData->additionalName; | 2080 | s >> a.mData->additionalName; |
2079 | s >> a.mData->prefix; | 2081 | s >> a.mData->prefix; |
2080 | s >> a.mData->suffix; | 2082 | s >> a.mData->suffix; |
2081 | s >> a.mData->nickName; | 2083 | s >> a.mData->nickName; |
2082 | s >> a.mData->birthday; | 2084 | s >> a.mData->birthday; |
2083 | s >> a.mData->mailer; | 2085 | s >> a.mData->mailer; |
2084 | s >> a.mData->timeZone; | 2086 | s >> a.mData->timeZone; |
2085 | s >> a.mData->geo; | 2087 | s >> a.mData->geo; |
2086 | s >> a.mData->title; | 2088 | s >> a.mData->title; |
2087 | s >> a.mData->role; | 2089 | s >> a.mData->role; |
2088 | s >> a.mData->organization; | 2090 | s >> a.mData->organization; |
2089 | s >> a.mData->note; | 2091 | s >> a.mData->note; |
2090 | s >> a.mData->productId; | 2092 | s >> a.mData->productId; |
2091 | s >> a.mData->revision; | 2093 | s >> a.mData->revision; |
2092 | s >> a.mData->sortString; | 2094 | s >> a.mData->sortString; |
2093 | s >> a.mData->url; | 2095 | s >> a.mData->url; |
2094 | s >> a.mData->secrecy; | 2096 | s >> a.mData->secrecy; |
2095 | s >> a.mData->logo; | 2097 | s >> a.mData->logo; |
2096 | s >> a.mData->photo; | 2098 | s >> a.mData->photo; |
2097 | s >> a.mData->sound; | 2099 | s >> a.mData->sound; |
2098 | s >> a.mData->agent; | 2100 | s >> a.mData->agent; |
2099 | s >> a.mData->phoneNumbers; | 2101 | s >> a.mData->phoneNumbers; |
2100 | s >> a.mData->addresses; | 2102 | s >> a.mData->addresses; |
2101 | s >> a.mData->emails; | 2103 | s >> a.mData->emails; |
2102 | s >> a.mData->categories; | 2104 | s >> a.mData->categories; |
2103 | s >> a.mData->custom; | 2105 | s >> a.mData->custom; |
2104 | s >> a.mData->keys; | 2106 | s >> a.mData->keys; |
2105 | 2107 | ||
2106 | a.mData->empty = false; | 2108 | a.mData->empty = false; |
2107 | 2109 | ||
2108 | return s; | 2110 | return s; |
2109 | } | 2111 | } |
2110 | bool matchBinaryPattern( int value, int pattern ) | 2112 | bool matchBinaryPattern( int value, int pattern ) |
2111 | { | 2113 | { |
2112 | /** | 2114 | /** |
2113 | We want to match all telephonnumbers/addresses which have the bits in the | 2115 | We want to match all telephonnumbers/addresses which have the bits in the |
2114 | pattern set. More are allowed. | 2116 | pattern set. More are allowed. |
2115 | if pattern == 0 we have a special handling, then we want only those with | 2117 | if pattern == 0 we have a special handling, then we want only those with |
2116 | exactly no bit set. | 2118 | exactly no bit set. |
2117 | */ | 2119 | */ |
2118 | if ( pattern == 0 ) | 2120 | if ( pattern == 0 ) |
2119 | return ( value == 0 ); | 2121 | return ( value == 0 ); |
2120 | else | 2122 | else |
2121 | return ( pattern == ( pattern & value ) ); | 2123 | return ( pattern == ( pattern & value ) ); |
2122 | } | 2124 | } |
2123 | 2125 | ||
2124 | bool matchBinaryPatternP( int value, int pattern ) | 2126 | bool matchBinaryPatternP( int value, int pattern ) |
2125 | { | 2127 | { |
2126 | 2128 | ||
2127 | if ( pattern == 0 ) | 2129 | if ( pattern == 0 ) |
2128 | return ( value == 0 ); | 2130 | return ( value == 0 ); |
2129 | else | 2131 | else |
2130 | return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); | 2132 | return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); |
2131 | } | 2133 | } |
2132 | bool matchBinaryPatternA( int value, int pattern ) | 2134 | bool matchBinaryPatternA( int value, int pattern ) |
2133 | { | 2135 | { |
2134 | 2136 | ||
2135 | if ( pattern == 0 ) | 2137 | if ( pattern == 0 ) |
2136 | return ( value == 0 ); | 2138 | return ( value == 0 ); |
2137 | else | 2139 | else |
2138 | return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); | 2140 | return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); |
2139 | } | 2141 | } |
diff --git a/kabc/secrecy.h b/kabc/secrecy.h index 8f2f736..b2ff565 100644 --- a/kabc/secrecy.h +++ b/kabc/secrecy.h | |||
@@ -1,102 +1,102 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@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 | #ifndef KABC_SECRECY_H | 28 | #ifndef KABC_SECRECY_H |
29 | #define KABC_SECRECY_H | 29 | #define KABC_SECRECY_H |
30 | 30 | ||
31 | #include <qvaluelist.h> | 31 | #include <qvaluelist.h> |
32 | 32 | ||
33 | namespace KABC { | 33 | namespace KABC { |
34 | 34 | ||
35 | class Secrecy | 35 | class Secrecy |
36 | { | 36 | { |
37 | friend QDataStream &operator<<( QDataStream &, const Secrecy & ); | 37 | friend QDataStream &operator<<( QDataStream &, const Secrecy & ); |
38 | friend QDataStream &operator>>( QDataStream &, Secrecy & ); | 38 | friend QDataStream &operator>>( QDataStream &, Secrecy & ); |
39 | 39 | ||
40 | public: | 40 | public: |
41 | typedef QValueList<int> TypeList; | 41 | typedef QValueList<int> TypeList; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Secrecy types | 44 | * Secrecy types |
45 | * | 45 | * |
46 | * @li Public - for public access | 46 | * @li Public - for public access |
47 | * @li Private - only private access | 47 | * @li Private - only private access |
48 | * @li Confidential - access for confidential persons | 48 | * @li Confidential - access for confidential persons |
49 | */ | 49 | */ |
50 | enum Types { | 50 | enum Types { |
51 | Public, | 51 | Public, |
52 | Private, | 52 | Private, |
53 | Confidential, | 53 | Confidential, |
54 | Invalid | 54 | Invalid |
55 | }; | 55 | }; |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Constructor. | 58 | * Constructor. |
59 | * | 59 | * |
60 | * @param type The secrecy type, @see Types. | 60 | * @param type The secrecy type, @see Types. |
61 | */ | 61 | */ |
62 | Secrecy( int type = Invalid ); | 62 | Secrecy( int type = Public ); |
63 | 63 | ||
64 | bool operator==( const Secrecy & ) const; | 64 | bool operator==( const Secrecy & ) const; |
65 | bool operator!=( const Secrecy & ) const; | 65 | bool operator!=( const Secrecy & ) const; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | Returns if the Secrecy object has a valid value. | 68 | Returns if the Secrecy object has a valid value. |
69 | */ | 69 | */ |
70 | bool isValid() const; | 70 | bool isValid() const; |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Sets the type, @see Types. | 73 | * Sets the type, @see Types. |
74 | */ | 74 | */ |
75 | void setType( int type ); | 75 | void setType( int type ); |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Returns the type, @see Types. | 78 | * Returns the type, @see Types. |
79 | */ | 79 | */ |
80 | int type() const; | 80 | int type() const; |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Returns a list of all available secrecy types. | 83 | * Returns a list of all available secrecy types. |
84 | */ | 84 | */ |
85 | static TypeList typeList(); | 85 | static TypeList typeList(); |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * Returns a translated label for a given secrecy type. | 88 | * Returns a translated label for a given secrecy type. |
89 | */ | 89 | */ |
90 | static QString typeLabel( int type ); | 90 | static QString typeLabel( int type ); |
91 | 91 | ||
92 | /** | 92 | /** |
93 | * For debug. | 93 | * For debug. |
94 | */ | 94 | */ |
95 | QString asString() const; | 95 | QString asString() const; |
96 | 96 | ||
97 | private: | 97 | private: |
98 | int mType; | 98 | int mType; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | } | 101 | } |
102 | #endif | 102 | #endif |
diff --git a/kabc/vcard/VCardv.cpp b/kabc/vcard/VCardv.cpp index 1166aac..bad2ef1 100644 --- a/kabc/vcard/VCardv.cpp +++ b/kabc/vcard/VCardv.cpp | |||
@@ -1,294 +1,294 @@ | |||
1 | /* | 1 | /* |
2 | libvcard - vCard parsing library for vCard version 3.0 | 2 | libvcard - vCard parsing library for vCard version 3.0 |
3 | 3 | ||
4 | Copyright (C) 1998 Rik Hemsley rik@kde.org | 4 | Copyright (C) 1998 Rik Hemsley rik@kde.org |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | of this software and associated documentation files (the "Software"), to | 7 | of this software and associated documentation files (the "Software"), to |
8 | deal in the Software without restriction, including without limitation the | 8 | deal in the Software without restriction, including without limitation the |
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | sell copies of the Software, and to permit persons to whom the Software is | 10 | sell copies of the Software, and to permit persons to whom the Software is |
11 | furnished to do so, subject to the following conditions: | 11 | furnished to do so, subject to the following conditions: |
12 | 12 | ||
13 | The above copyright notice and this permission notice shall be included in | 13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. | 14 | all copies or substantial portions of the Software. |
15 | 15 | ||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qcstring.h> | 24 | #include <qcstring.h> |
25 | #include <qstrlist.h> | 25 | #include <qstrlist.h> |
26 | #include <qstringlist.h> | 26 | #include <qstringlist.h> |
27 | #include <qstring.h> | 27 | #include <qstring.h> |
28 | #include <qvaluelist.h> | 28 | #include <qvaluelist.h> |
29 | 29 | ||
30 | #include <VCardEntity.h> | 30 | #include <VCardEntity.h> |
31 | #include <VCardVCard.h> | 31 | #include <VCardVCard.h> |
32 | #include <VCardContentLine.h> | 32 | #include <VCardContentLine.h> |
33 | #include <VCardRToken.h> | 33 | #include <VCardRToken.h> |
34 | 34 | ||
35 | #include <VCardDefines.h> | 35 | #include <VCardDefines.h> |
36 | 36 | ||
37 | using namespace VCARD; | 37 | using namespace VCARD; |
38 | 38 | ||
39 | VCard::VCard() | 39 | VCard::VCard() |
40 | :Entity() | 40 | :Entity() |
41 | { | 41 | { |
42 | contentLineList_.setAutoDelete( TRUE ); | 42 | contentLineList_.setAutoDelete( TRUE ); |
43 | } | 43 | } |
44 | 44 | ||
45 | VCard::VCard(const VCard & x) | 45 | VCard::VCard(const VCard & x) |
46 | :Entity(x), | 46 | :Entity(x), |
47 | group_(x.group_) | 47 | group_(x.group_) |
48 | { | 48 | { |
49 | contentLineList_.setAutoDelete( TRUE ); | 49 | contentLineList_.setAutoDelete( TRUE ); |
50 | 50 | ||
51 | QPtrListIterator<ContentLine> it(x.contentLineList_); | 51 | QPtrListIterator<ContentLine> it(x.contentLineList_); |
52 | for (; it.current(); ++it) { | 52 | for (; it.current(); ++it) { |
53 | ContentLine * c = new ContentLine(*it.current()); | 53 | ContentLine * c = new ContentLine(*it.current()); |
54 | contentLineList_.append(c); | 54 | contentLineList_.append(c); |
55 | } | 55 | } |
56 | 56 | ||
57 | } | 57 | } |
58 | 58 | ||
59 | VCard::VCard(const QCString & s) | 59 | VCard::VCard(const QCString & s) |
60 | :Entity(s) | 60 | :Entity(s) |
61 | { | 61 | { |
62 | contentLineList_.setAutoDelete( TRUE ); | 62 | contentLineList_.setAutoDelete( TRUE ); |
63 | } | 63 | } |
64 | 64 | ||
65 | VCard & | 65 | VCard & |
66 | VCard::operator = (VCard & x) | 66 | VCard::operator = (VCard & x) |
67 | { | 67 | { |
68 | if (*this == x) return *this; | 68 | if (*this == x) return *this; |
69 | 69 | ||
70 | group_ = x.group(); | 70 | group_ = x.group(); |
71 | QPtrListIterator<ContentLine> it(x.contentLineList_); | 71 | QPtrListIterator<ContentLine> it(x.contentLineList_); |
72 | for (; it.current(); ++it) { | 72 | for (; it.current(); ++it) { |
73 | ContentLine * c = new ContentLine(*it.current()); | 73 | ContentLine * c = new ContentLine(*it.current()); |
74 | contentLineList_.append(c); | 74 | contentLineList_.append(c); |
75 | } | 75 | } |
76 | 76 | ||
77 | Entity::operator = (x); | 77 | Entity::operator = (x); |
78 | return *this; | 78 | return *this; |
79 | } | 79 | } |
80 | 80 | ||
81 | VCard & | 81 | VCard & |
82 | VCard::operator = (const QCString & s) | 82 | VCard::operator = (const QCString & s) |
83 | { | 83 | { |
84 | Entity::operator = (s); | 84 | Entity::operator = (s); |
85 | return *this; | 85 | return *this; |
86 | } | 86 | } |
87 | 87 | ||
88 | bool | 88 | bool |
89 | VCard::operator == (VCard & x) | 89 | VCard::operator == (VCard & x) |
90 | { | 90 | { |
91 | x.parse(); | 91 | x.parse(); |
92 | return false; | 92 | return false; |
93 | } | 93 | } |
94 | 94 | ||
95 | VCard::~VCard() | 95 | VCard::~VCard() |
96 | { | 96 | { |
97 | } | 97 | } |
98 | 98 | ||
99 | void | 99 | void |
100 | VCard::_parse() | 100 | VCard::_parse() |
101 | { | 101 | { |
102 | 102 | ||
103 | QStringList l; | 103 | QStringList l; |
104 | QStrList sl; | 104 | QStrList sl; |
105 | 105 | ||
106 | RTokenise(strRep_, "\r\n", sl); | 106 | RTokenise(strRep_, "\r\n", sl); |
107 | 107 | ||
108 | if (sl.count() < 3) { // Invalid VCARD ! | 108 | if (sl.count() < 3) { // Invalid VCARD ! |
109 | //qDebug("invalid vcard "); | 109 | //qDebug("invalid vcard "); |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | l = QStringList::fromStrList( sl ); | 112 | l = QStringList::fromStrList( sl ); |
113 | // Get the first line | 113 | // Get the first line |
114 | QString beginLine = l[0].stripWhiteSpace(); | 114 | QString beginLine = l[0].stripWhiteSpace(); |
115 | 115 | ||
116 | // Remove extra blank lines | 116 | // Remove extra blank lines |
117 | while (l.last().isEmpty()) | 117 | while (l.last().isEmpty()) |
118 | l.remove(l.last()); | 118 | l.remove(l.last()); |
119 | 119 | ||
120 | // Now we know this is the last line | 120 | // Now we know this is the last line |
121 | QString endLine = l.last(); | 121 | QString endLine = l.last(); |
122 | 122 | ||
123 | // Trash the first and last lines as we have seen them. | 123 | // Trash the first and last lines as we have seen them. |
124 | l.remove(l.begin()); | 124 | l.remove(l.begin()); |
125 | l.remove(l.last()); | 125 | l.remove(l.last()); |
126 | 126 | ||
127 | /////////////////////////////////////////////////////////////// | 127 | /////////////////////////////////////////////////////////////// |
128 | // FIRST LINE | 128 | // FIRST LINE |
129 | 129 | ||
130 | int split = beginLine.find(':'); | 130 | int split = beginLine.find(':'); |
131 | 131 | ||
132 | if (split == -1) { // invalid, no BEGIN | 132 | if (split == -1) { // invalid, no BEGIN |
133 | vDebug("No split"); | 133 | vDebug("No split"); |
134 | return; | 134 | return; |
135 | } | 135 | } |
136 | 136 | ||
137 | QString firstPart(beginLine.left(split)); | 137 | QString firstPart(beginLine.left(split)); |
138 | QString valuePart(beginLine.mid(split + 1)); | 138 | QString valuePart(beginLine.mid(split + 1)); |
139 | 139 | ||
140 | split = firstPart.find('.'); | 140 | split = firstPart.find('.'); |
141 | 141 | ||
142 | if (split != -1) { | 142 | if (split != -1) { |
143 | group_ = firstPart.left(split); | 143 | group_ = firstPart.left(split); |
144 | firstPart= firstPart.right(firstPart.length() - split - 1); | 144 | firstPart= firstPart.right(firstPart.length() - split - 1); |
145 | } | 145 | } |
146 | 146 | ||
147 | if (firstPart.left(5) != "BEGIN" ) { // No BEGIN ! | 147 | if (firstPart.left(5) != "BEGIN" ) { // No BEGIN ! |
148 | qDebug("no BEGIN in vcard "); | 148 | qDebug("no BEGIN in vcard "); |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | 151 | ||
152 | if (valuePart.left(5) != "VCARD") { // Not a vcard ! | 152 | if (valuePart.left(5) != "VCARD") { // Not a vcard ! |
153 | qDebug("not a VCARD "); | 153 | qDebug("not a VCARD "); |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | 156 | ||
157 | /////////////////////////////////////////////////////////////// | 157 | /////////////////////////////////////////////////////////////// |
158 | // CONTENT LINES | 158 | // CONTENT LINES |
159 | // | 159 | // |
160 | vDebug("Content lines"); | 160 | vDebug("Content lines"); |
161 | 161 | ||
162 | // Handle folded lines. | 162 | // Handle folded lines. |
163 | 163 | ||
164 | QStringList refolded; | 164 | QStringList refolded; |
165 | 165 | ||
166 | 166 | ||
167 | QStringList::Iterator it = l.begin(); | 167 | QStringList::Iterator it = l.begin(); |
168 | 168 | ||
169 | QString cur; | 169 | QString cur; |
170 | 170 | ||
171 | for (; it != l.end(); ++it) { | 171 | for (; it != l.end(); ++it) { |
172 | cur = (*it); | 172 | cur = (*it); |
173 | ++it; | 173 | ++it; |
174 | while ( it!= l.end() && (*it).at(0) == ' '&& (*it).length()!= 1) { | 174 | while ( it!= l.end() && (*it).at(0) == ' '&& (*it).length()!= 1) { |
175 | cur += (*it) ; | 175 | cur += (*it).mid(1) ; |
176 | ++it; | 176 | ++it; |
177 | } | 177 | } |
178 | --it; | 178 | --it; |
179 | refolded.append(cur); | 179 | refolded.append(cur); |
180 | } | 180 | } |
181 | QStringList::Iterator it2 = refolded.begin(); | 181 | QStringList::Iterator it2 = refolded.begin(); |
182 | for (; it2 != refolded.end(); ++it2) { | 182 | for (; it2 != refolded.end(); ++it2) { |
183 | ContentLine * cl = new ContentLine(QCString((*it2).latin1())); | 183 | ContentLine * cl = new ContentLine(QCString((*it2).latin1())); |
184 | cl->parse(); | 184 | cl->parse(); |
185 | if (cl->value() == 0) | 185 | if (cl->value() == 0) |
186 | { | 186 | { |
187 | qDebug("Content line could not be parsed. Discarded: %s", (*it2).latin1()); | 187 | qDebug("Content line could not be parsed. Discarded: %s", (*it2).latin1()); |
188 | delete cl; | 188 | delete cl; |
189 | } | 189 | } |
190 | else | 190 | else |
191 | contentLineList_.append(cl); | 191 | contentLineList_.append(cl); |
192 | } | 192 | } |
193 | 193 | ||
194 | /////////////////////////////////////////////////////////////// | 194 | /////////////////////////////////////////////////////////////// |
195 | // LAST LINE | 195 | // LAST LINE |
196 | 196 | ||
197 | 197 | ||
198 | // LR: sorry, but the remaining code in this method makes no sense | 198 | // LR: sorry, but the remaining code in this method makes no sense |
199 | 199 | ||
200 | #if 0 | 200 | #if 0 |
201 | split = endLine.find(':'); | 201 | split = endLine.find(':'); |
202 | 202 | ||
203 | if (split == -1) // invalid, no END | 203 | if (split == -1) // invalid, no END |
204 | return; | 204 | return; |
205 | 205 | ||
206 | firstPart = endLine.left(split); | 206 | firstPart = endLine.left(split); |
207 | valuePart = endLine.right(firstPart.length() - split - 1); | 207 | valuePart = endLine.right(firstPart.length() - split - 1); |
208 | 208 | ||
209 | split = firstPart.find('.'); | 209 | split = firstPart.find('.'); |
210 | 210 | ||
211 | if (split != -1) { | 211 | if (split != -1) { |
212 | group_ = firstPart.left(split); | 212 | group_ = firstPart.left(split); |
213 | firstPart= firstPart.right(firstPart.length() - split - 1); | 213 | firstPart= firstPart.right(firstPart.length() - split - 1); |
214 | } | 214 | } |
215 | 215 | ||
216 | if (qstricmp(firstPart, "END") != 0) // No END ! | 216 | if (qstricmp(firstPart, "END") != 0) // No END ! |
217 | return; | 217 | return; |
218 | 218 | ||
219 | if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! | 219 | if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! |
220 | return; | 220 | return; |
221 | #endif | 221 | #endif |
222 | } | 222 | } |
223 | 223 | ||
224 | void | 224 | void |
225 | VCard::_assemble() | 225 | VCard::_assemble() |
226 | { | 226 | { |
227 | vDebug("Assembling vcard"); | 227 | vDebug("Assembling vcard"); |
228 | strRep_ = "BEGIN:VCARD\r\n"; | 228 | strRep_ = "BEGIN:VCARD\r\n"; |
229 | strRep_ += "VERSION:3.0\r\n"; | 229 | strRep_ += "VERSION:3.0\r\n"; |
230 | 230 | ||
231 | QPtrListIterator<ContentLine> it(contentLineList_); | 231 | QPtrListIterator<ContentLine> it(contentLineList_); |
232 | 232 | ||
233 | for (; it.current(); ++it) | 233 | for (; it.current(); ++it) |
234 | strRep_ += it.current()->asString() + "\r\n"; | 234 | strRep_ += it.current()->asString() + "\r\n"; |
235 | 235 | ||
236 | strRep_ += "END:VCARD\r\n"; | 236 | strRep_ += "END:VCARD\r\n"; |
237 | } | 237 | } |
238 | 238 | ||
239 | bool | 239 | bool |
240 | VCard::has(EntityType t) | 240 | VCard::has(EntityType t) |
241 | { | 241 | { |
242 | parse(); | 242 | parse(); |
243 | return contentLine(t) == 0 ? false : true; | 243 | return contentLine(t) == 0 ? false : true; |
244 | } | 244 | } |
245 | 245 | ||
246 | bool | 246 | bool |
247 | VCard::has(const QCString & s) | 247 | VCard::has(const QCString & s) |
248 | { | 248 | { |
249 | parse(); | 249 | parse(); |
250 | return contentLine(s) == 0 ? false : true; | 250 | return contentLine(s) == 0 ? false : true; |
251 | } | 251 | } |
252 | 252 | ||
253 | void | 253 | void |
254 | VCard::add(const ContentLine & cl) | 254 | VCard::add(const ContentLine & cl) |
255 | { | 255 | { |
256 | parse(); | 256 | parse(); |
257 | ContentLine * c = new ContentLine(cl); | 257 | ContentLine * c = new ContentLine(cl); |
258 | contentLineList_.append(c); | 258 | contentLineList_.append(c); |
259 | } | 259 | } |
260 | 260 | ||
261 | void | 261 | void |
262 | VCard::add(const QCString & s) | 262 | VCard::add(const QCString & s) |
263 | { | 263 | { |
264 | parse(); | 264 | parse(); |
265 | ContentLine * c = new ContentLine(s); | 265 | ContentLine * c = new ContentLine(s); |
266 | contentLineList_.append(c); | 266 | contentLineList_.append(c); |
267 | } | 267 | } |
268 | 268 | ||
269 | ContentLine * | 269 | ContentLine * |
270 | VCard::contentLine(EntityType t) | 270 | VCard::contentLine(EntityType t) |
271 | { | 271 | { |
272 | parse(); | 272 | parse(); |
273 | QPtrListIterator<ContentLine> it(contentLineList_); | 273 | QPtrListIterator<ContentLine> it(contentLineList_); |
274 | 274 | ||
275 | for (; it.current(); ++it) | 275 | for (; it.current(); ++it) |
276 | if (it.current()->entityType() == t) | 276 | if (it.current()->entityType() == t) |
277 | return it.current(); | 277 | return it.current(); |
278 | 278 | ||
279 | return 0; | 279 | return 0; |
280 | } | 280 | } |
281 | 281 | ||
282 | ContentLine * | 282 | ContentLine * |
283 | VCard::contentLine(const QCString & s) | 283 | VCard::contentLine(const QCString & s) |
284 | { | 284 | { |
285 | parse(); | 285 | parse(); |
286 | QPtrListIterator<ContentLine> it(contentLineList_); | 286 | QPtrListIterator<ContentLine> it(contentLineList_); |
287 | 287 | ||
288 | for (; it.current(); ++it) | 288 | for (; it.current(); ++it) |
289 | if (it.current()->entityType() == EntityNameToEntityType(s)) | 289 | if (it.current()->entityType() == EntityNameToEntityType(s)) |
290 | return it.current(); | 290 | return it.current(); |
291 | 291 | ||
292 | return 0; | 292 | return 0; |
293 | } | 293 | } |
294 | 294 | ||