-rw-r--r-- | kabc/addressbook.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 5774c36..6194d6d 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -112,1143 +112,1143 @@ Addressee &AddressBook::Iterator::operator*() | |||
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 | QDateTime dt ( QDate( 2004,1,1) ); | 565 | QDateTime dt ( QDate( 2004,1,1) ); |
566 | while ( it != end() ) { | 566 | while ( it != end() ) { |
567 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 567 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
568 | it2 = it; | 568 | it2 = it; |
569 | //qDebug("removing %s ",(*it).uid().latin1() ); | 569 | //qDebug("removing %s ",(*it).uid().latin1() ); |
570 | ++it; | 570 | ++it; |
571 | removeAddressee( it2 ); | 571 | removeAddressee( it2 ); |
572 | } else { | 572 | } else { |
573 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 573 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
574 | ++it; | 574 | ++it; |
575 | } | 575 | } |
576 | } | 576 | } |
577 | } else { | 577 | } else { |
578 | Addressee lse; | 578 | Addressee lse; |
579 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); | 579 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); |
580 | if ( ! lse.isEmpty() ) | 580 | if ( ! lse.isEmpty() ) |
581 | removeAddressee( lse ); | 581 | removeAddressee( lse ); |
582 | } | 582 | } |
583 | 583 | ||
584 | } | 584 | } |
585 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 585 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
586 | { | 586 | { |
587 | Iterator ait; | 587 | Iterator ait; |
588 | for ( ait = begin(); ait != end(); ++ait ) { | 588 | for ( ait = begin(); ait != end(); ++ait ) { |
589 | QString id = (*ait).IDStr(); | 589 | QString id = (*ait).IDStr(); |
590 | (*ait).setIDStr( ":"); | 590 | (*ait).setIDStr( ":"); |
591 | (*ait).setExternalUID( id ); | 591 | (*ait).setExternalUID( id ); |
592 | (*ait).setOriginalExternalUID( id ); | 592 | (*ait).setOriginalExternalUID( id ); |
593 | if ( isPreSync ) | 593 | if ( isPreSync ) |
594 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 594 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
595 | else { | 595 | else { |
596 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 596 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
597 | (*ait).setID( currentSyncDevice,id ); | 597 | (*ait).setID( currentSyncDevice,id ); |
598 | 598 | ||
599 | } | 599 | } |
600 | } | 600 | } |
601 | } | 601 | } |
602 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 602 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
603 | { | 603 | { |
604 | 604 | ||
605 | setUntagged(); | 605 | setUntagged(); |
606 | KABC::Addressee::List list; | 606 | KABC::Addressee::List list; |
607 | QFile file( fileName ); | 607 | QFile file( fileName ); |
608 | file.open( IO_ReadOnly ); | 608 | file.open( IO_ReadOnly ); |
609 | QByteArray rawData = file.readAll(); | 609 | QByteArray rawData = file.readAll(); |
610 | file.close(); | 610 | file.close(); |
611 | QString data; | 611 | QString data; |
612 | 612 | ||
613 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 613 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
614 | KABC::VCardTool tool; | 614 | KABC::VCardTool tool; |
615 | list = tool.parseVCards( data ); | 615 | list = tool.parseVCards( data ); |
616 | KABC::Addressee::List::Iterator it; | 616 | KABC::Addressee::List::Iterator it; |
617 | for ( it = list.begin(); it != list.end(); ++it ) { | 617 | for ( it = list.begin(); it != list.end(); ++it ) { |
618 | Iterator ait; | 618 | Iterator ait; |
619 | for ( ait = begin(); ait != end(); ++ait ) { | 619 | for ( ait = begin(); ait != end(); ++ait ) { |
620 | if ( !(*ait).tagged() ) { | 620 | if ( !(*ait).tagged() ) { |
621 | if ( (*ait).containsAdr(*it)) { | 621 | if ( (*ait).containsAdr(*it)) { |
622 | (*ait).setTagged(true); | 622 | (*ait).setTagged(true); |
623 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 623 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
624 | (*it).setIDStr( ":"); | 624 | (*it).setIDStr( ":"); |
625 | (*it).setID( currentSyncDevice,id ); | 625 | (*it).setID( currentSyncDevice,id ); |
626 | (*it).setExternalUID( id ); | 626 | (*it).setExternalUID( id ); |
627 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 627 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
628 | (*it).setUid( ( (*ait).uid() )); | 628 | (*it).setUid( ( (*ait).uid() )); |
629 | break; | 629 | break; |
630 | } | 630 | } |
631 | } | 631 | } |
632 | 632 | ||
633 | } | 633 | } |
634 | if ( ait == end() ) | 634 | if ( ait == end() ) |
635 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 635 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
636 | } | 636 | } |
637 | clear(); | 637 | clear(); |
638 | for ( it = list.begin(); it != list.end(); ++it ) { | 638 | for ( it = list.begin(); it != list.end(); ++it ) { |
639 | insertAddressee( (*it) ); | 639 | insertAddressee( (*it) ); |
640 | } | 640 | } |
641 | } | 641 | } |
642 | 642 | ||
643 | bool AddressBook::saveABphone( QString fileName ) | 643 | bool AddressBook::saveABphone( QString fileName ) |
644 | { | 644 | { |
645 | //smplifyAddressees(); | 645 | //smplifyAddressees(); |
646 | qDebug("saveABphone:: saving AB... "); | 646 | qDebug("saveABphone:: saving AB... "); |
647 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 647 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
648 | return false; | 648 | return false; |
649 | qDebug("saveABphone:: writing to phone... "); | 649 | qDebug("saveABphone:: writing to phone... "); |
650 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 650 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
651 | return false; | 651 | return false; |
652 | } | 652 | } |
653 | qDebug("saveABphone:: re-reading from phone... "); | 653 | qDebug("saveABphone:: re-reading from phone... "); |
654 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 654 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
655 | return false; | 655 | return false; |
656 | } | 656 | } |
657 | return true; | 657 | return true; |
658 | } | 658 | } |
659 | bool AddressBook::saveAB() | 659 | bool AddressBook::saveAB() |
660 | { | 660 | { |
661 | bool ok = true; | 661 | bool ok = true; |
662 | 662 | ||
663 | deleteRemovedAddressees(); | 663 | deleteRemovedAddressees(); |
664 | Iterator ait; | 664 | Iterator ait; |
665 | for ( ait = begin(); ait != end(); ++ait ) { | 665 | for ( ait = begin(); ait != end(); ++ait ) { |
666 | if ( !(*ait).IDStr().isEmpty() ) { | 666 | if ( !(*ait).IDStr().isEmpty() ) { |
667 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 667 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
668 | } | 668 | } |
669 | } | 669 | } |
670 | KRES::Manager<Resource>::ActiveIterator it; | 670 | KRES::Manager<Resource>::ActiveIterator it; |
671 | KRES::Manager<Resource> *manager = d->mManager; | 671 | KRES::Manager<Resource> *manager = d->mManager; |
672 | qDebug("SaveAB::saving..." ); | 672 | qDebug("SaveAB::saving..." ); |
673 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 673 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
674 | qDebug("SaveAB::checking resource..." ); | 674 | qDebug("SaveAB::checking resource..." ); |
675 | if ( (*it)->readOnly() ) | 675 | if ( (*it)->readOnly() ) |
676 | qDebug("resource is readonly." ); | 676 | qDebug("resource is readonly." ); |
677 | if ( (*it)->isOpen() ) | 677 | if ( (*it)->isOpen() ) |
678 | qDebug("resource is open" ); | 678 | qDebug("resource is open" ); |
679 | 679 | ||
680 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 680 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
681 | Ticket *ticket = requestSaveTicket( *it ); | 681 | Ticket *ticket = requestSaveTicket( *it ); |
682 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 682 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
683 | if ( !ticket ) { | 683 | if ( !ticket ) { |
684 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 684 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
685 | .arg( (*it)->resourceName() ) ); | 685 | .arg( (*it)->resourceName() ) ); |
686 | return false; | 686 | return false; |
687 | } | 687 | } |
688 | 688 | ||
689 | //if ( !save( ticket ) ) | 689 | //if ( !save( ticket ) ) |
690 | if ( ticket->resource() ) { | 690 | if ( ticket->resource() ) { |
691 | QString name = ticket->resource()->resourceName(); | 691 | QString name = ticket->resource()->resourceName(); |
692 | if ( ! ticket->resource()->save( ticket ) ) | 692 | if ( ! ticket->resource()->save( ticket ) ) |
693 | ok = false; | 693 | ok = false; |
694 | else | 694 | else |
695 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); | 695 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
696 | 696 | ||
697 | } else | 697 | } else |
698 | ok = false; | 698 | ok = false; |
699 | 699 | ||
700 | } | 700 | } |
701 | } | 701 | } |
702 | return ok; | 702 | return ok; |
703 | } | 703 | } |
704 | 704 | ||
705 | AddressBook::Iterator AddressBook::begin() | 705 | AddressBook::Iterator AddressBook::begin() |
706 | { | 706 | { |
707 | Iterator it = Iterator(); | 707 | Iterator it = Iterator(); |
708 | it.d->mIt = d->mAddressees.begin(); | 708 | it.d->mIt = d->mAddressees.begin(); |
709 | return it; | 709 | return it; |
710 | } | 710 | } |
711 | 711 | ||
712 | AddressBook::ConstIterator AddressBook::begin() const | 712 | AddressBook::ConstIterator AddressBook::begin() const |
713 | { | 713 | { |
714 | ConstIterator it = ConstIterator(); | 714 | ConstIterator it = ConstIterator(); |
715 | it.d->mIt = d->mAddressees.begin(); | 715 | it.d->mIt = d->mAddressees.begin(); |
716 | return it; | 716 | return it; |
717 | } | 717 | } |
718 | 718 | ||
719 | AddressBook::Iterator AddressBook::end() | 719 | AddressBook::Iterator AddressBook::end() |
720 | { | 720 | { |
721 | Iterator it = Iterator(); | 721 | Iterator it = Iterator(); |
722 | it.d->mIt = d->mAddressees.end(); | 722 | it.d->mIt = d->mAddressees.end(); |
723 | return it; | 723 | return it; |
724 | } | 724 | } |
725 | 725 | ||
726 | AddressBook::ConstIterator AddressBook::end() const | 726 | AddressBook::ConstIterator AddressBook::end() const |
727 | { | 727 | { |
728 | ConstIterator it = ConstIterator(); | 728 | ConstIterator it = ConstIterator(); |
729 | it.d->mIt = d->mAddressees.end(); | 729 | it.d->mIt = d->mAddressees.end(); |
730 | return it; | 730 | return it; |
731 | } | 731 | } |
732 | 732 | ||
733 | void AddressBook::clear() | 733 | void AddressBook::clear() |
734 | { | 734 | { |
735 | d->mAddressees.clear(); | 735 | d->mAddressees.clear(); |
736 | } | 736 | } |
737 | 737 | ||
738 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 738 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
739 | { | 739 | { |
740 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 740 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
741 | 741 | ||
742 | if ( !resource ) | 742 | if ( !resource ) |
743 | { | 743 | { |
744 | qDebug("AddressBook::requestSaveTicket no resource" ); | 744 | qDebug("AddressBook::requestSaveTicket no resource" ); |
745 | resource = standardResource(); | 745 | resource = standardResource(); |
746 | } | 746 | } |
747 | 747 | ||
748 | KRES::Manager<Resource>::ActiveIterator it; | 748 | KRES::Manager<Resource>::ActiveIterator it; |
749 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 749 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
750 | if ( (*it) == resource ) { | 750 | if ( (*it) == resource ) { |
751 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 751 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
752 | return 0; | 752 | return 0; |
753 | else | 753 | else |
754 | return (*it)->requestSaveTicket(); | 754 | return (*it)->requestSaveTicket(); |
755 | } | 755 | } |
756 | } | 756 | } |
757 | 757 | ||
758 | return 0; | 758 | return 0; |
759 | } | 759 | } |
760 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 760 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
761 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 761 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
762 | { | 762 | { |
763 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 763 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
764 | //qDebug("block insert "); | 764 | //qDebug("block insert "); |
765 | return; | 765 | return; |
766 | } | 766 | } |
767 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 767 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
768 | bool found = false; | 768 | bool found = false; |
769 | Addressee::List::Iterator it; | 769 | Addressee::List::Iterator it; |
770 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 770 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
771 | if ( a.uid() == (*it).uid() ) { | 771 | if ( a.uid() == (*it).uid() ) { |
772 | 772 | ||
773 | bool changed = false; | 773 | bool changed = false; |
774 | Addressee addr = a; | 774 | Addressee addr = a; |
775 | if ( addr != (*it) ) | 775 | if ( addr != (*it) ) |
776 | changed = true; | 776 | changed = true; |
777 | 777 | ||
778 | if ( takeResource ) { | 778 | if ( takeResource ) { |
779 | Resource * res = (*it).resource(); | 779 | Resource * res = (*it).resource(); |
780 | (*it) = a; | 780 | (*it) = a; |
781 | (*it).setResource( res ); | 781 | (*it).setResource( res ); |
782 | } else { | 782 | } else { |
783 | (*it) = a; | 783 | (*it) = a; |
784 | if ( (*it).resource() == 0 ) | 784 | if ( (*it).resource() == 0 ) |
785 | (*it).setResource( standardResource() ); | 785 | (*it).setResource( standardResource() ); |
786 | } | 786 | } |
787 | if ( changed ) { | 787 | if ( changed ) { |
788 | if ( setRev ) { | 788 | if ( setRev ) { |
789 | 789 | ||
790 | // get rid of micro seconds | 790 | // get rid of micro seconds |
791 | QDateTime dt = QDateTime::currentDateTime(); | 791 | QDateTime dt = QDateTime::currentDateTime(); |
792 | QTime t = dt.time(); | 792 | QTime t = dt.time(); |
793 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 793 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
794 | (*it).setRevision( dt ); | 794 | (*it).setRevision( dt ); |
795 | } | 795 | } |
796 | (*it).setChanged( true ); | 796 | (*it).setChanged( true ); |
797 | } | 797 | } |
798 | 798 | ||
799 | found = true; | 799 | found = true; |
800 | } else { | 800 | } else { |
801 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 801 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
802 | QString name = (*it).uid().mid( 19 ); | 802 | QString name = (*it).uid().mid( 19 ); |
803 | Addressee b = a; | 803 | Addressee b = a; |
804 | QString id = b.getID( name ); | 804 | QString id = b.getID( name ); |
805 | if ( ! id.isEmpty() ) { | 805 | if ( ! id.isEmpty() ) { |
806 | QString des = (*it).note(); | 806 | QString des = (*it).note(); |
807 | int startN; | 807 | int startN; |
808 | if( (startN = des.find( id ) ) >= 0 ) { | 808 | if( (startN = des.find( id ) ) >= 0 ) { |
809 | int endN = des.find( ",", startN+1 ); | 809 | int endN = des.find( ",", startN+1 ); |
810 | des = des.left( startN ) + des.mid( endN+1 ); | 810 | des = des.left( startN ) + des.mid( endN+1 ); |
811 | (*it).setNote( des ); | 811 | (*it).setNote( des ); |
812 | } | 812 | } |
813 | } | 813 | } |
814 | } | 814 | } |
815 | } | 815 | } |
816 | } | 816 | } |
817 | if ( found ) | 817 | if ( found ) |
818 | return; | 818 | return; |
819 | d->mAddressees.append( a ); | 819 | d->mAddressees.append( a ); |
820 | Addressee& addr = d->mAddressees.last(); | 820 | Addressee& addr = d->mAddressees.last(); |
821 | if ( addr.resource() == 0 ) | 821 | if ( addr.resource() == 0 ) |
822 | addr.setResource( standardResource() ); | 822 | addr.setResource( standardResource() ); |
823 | 823 | ||
824 | addr.setChanged( true ); | 824 | addr.setChanged( true ); |
825 | } | 825 | } |
826 | 826 | ||
827 | void AddressBook::removeAddressee( const Addressee &a ) | 827 | void AddressBook::removeAddressee( const Addressee &a ) |
828 | { | 828 | { |
829 | Iterator it; | 829 | Iterator it; |
830 | Iterator it2; | 830 | Iterator it2; |
831 | bool found = false; | 831 | bool found = false; |
832 | for ( it = begin(); it != end(); ++it ) { | 832 | for ( it = begin(); it != end(); ++it ) { |
833 | if ( a.uid() == (*it).uid() ) { | 833 | if ( a.uid() == (*it).uid() ) { |
834 | found = true; | 834 | found = true; |
835 | it2 = it; | 835 | it2 = it; |
836 | } else { | 836 | } else { |
837 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 837 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
838 | QString name = (*it).uid().mid( 19 ); | 838 | QString name = (*it).uid().mid( 19 ); |
839 | Addressee b = a; | 839 | Addressee b = a; |
840 | QString id = b.getID( name ); | 840 | QString id = b.getID( name ); |
841 | if ( ! id.isEmpty() ) { | 841 | if ( ! id.isEmpty() ) { |
842 | QString des = (*it).note(); | 842 | QString des = (*it).note(); |
843 | if( des.find( id ) < 0 ) { | 843 | if( des.find( id ) < 0 ) { |
844 | des += id + ","; | 844 | des += id + ","; |
845 | (*it).setNote( des ); | 845 | (*it).setNote( des ); |
846 | } | 846 | } |
847 | } | 847 | } |
848 | } | 848 | } |
849 | 849 | ||
850 | } | 850 | } |
851 | } | 851 | } |
852 | 852 | ||
853 | if ( found ) | 853 | if ( found ) |
854 | removeAddressee( it2 ); | 854 | removeAddressee( it2 ); |
855 | 855 | ||
856 | } | 856 | } |
857 | 857 | ||
858 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 858 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
859 | { | 859 | { |
860 | Iterator it = begin(); | 860 | Iterator it = begin(); |
861 | Iterator it2 ; | 861 | Iterator it2 ; |
862 | QDateTime dt ( QDate( 2004,1,1) ); | 862 | QDateTime dt ( QDate( 2004,1,1) ); |
863 | while ( it != end() ) { | 863 | while ( it != end() ) { |
864 | (*it).setRevision( dt ); | 864 | (*it).setRevision( dt ); |
865 | if (( *it).IDStr() != "changed" ) { | 865 | if (( *it).IDStr() != "changed" ) { |
866 | // "changed" is used for tagging changed addressees when syncing with KDE or OL | 866 | // "changed" is used for tagging changed addressees when syncing with KDE or OL |
867 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 867 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
868 | (*it).setIDStr(""); | 868 | (*it).setIDStr(""); |
869 | } | 869 | } |
870 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 870 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
871 | it2 = it; | 871 | it2 = it; |
872 | //qDebug("removing %s ",(*it).uid().latin1() ); | 872 | //qDebug("removing %s ",(*it).uid().latin1() ); |
873 | ++it; | 873 | ++it; |
874 | removeAddressee( it2 ); | 874 | removeAddressee( it2 ); |
875 | } else { | 875 | } else { |
876 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 876 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
877 | if ( removeDeleted ) { | 877 | if ( removeDeleted ) { |
878 | // we have no postprocessing in the resource, we have to do it here | 878 | // we have no postprocessing in the resource, we have to do it here |
879 | // we have to compute csum for all, because it could be the first sync | 879 | // we have to compute csum for all, because it could be the first sync |
880 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | 880 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
881 | 881 | ||
882 | 882 | ||
883 | } | 883 | } |
884 | ++it; | 884 | ++it; |
885 | } | 885 | } |
886 | } | 886 | } |
887 | deleteRemovedAddressees(); | 887 | deleteRemovedAddressees(); |
888 | } | 888 | } |
889 | 889 | ||
890 | void AddressBook::removeAddressee( const Iterator &it ) | 890 | void AddressBook::removeAddressee( const Iterator &it ) |
891 | { | 891 | { |
892 | d->mRemovedAddressees.append( (*it) ); | 892 | d->mRemovedAddressees.append( (*it) ); |
893 | d->mAddressees.remove( it.d->mIt ); | 893 | d->mAddressees.remove( it.d->mIt ); |
894 | } | 894 | } |
895 | 895 | ||
896 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 896 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
897 | { | 897 | { |
898 | Iterator it; | 898 | Iterator it; |
899 | for ( it = begin(); it != end(); ++it ) { | 899 | for ( it = begin(); it != end(); ++it ) { |
900 | if ( a.uid() == (*it).uid() ) { | 900 | if ( a.uid() == (*it).uid() ) { |
901 | return it; | 901 | return it; |
902 | } | 902 | } |
903 | } | 903 | } |
904 | return end(); | 904 | return end(); |
905 | } | 905 | } |
906 | 906 | ||
907 | Addressee AddressBook::findByUid( const QString &uid ) | 907 | Addressee AddressBook::findByUid( const QString &uid ) |
908 | { | 908 | { |
909 | Iterator it; | 909 | Iterator it; |
910 | for ( it = begin(); it != end(); ++it ) { | 910 | for ( it = begin(); it != end(); ++it ) { |
911 | if ( uid == (*it).uid() ) { | 911 | if ( uid == (*it).uid() ) { |
912 | return *it; | 912 | return *it; |
913 | } | 913 | } |
914 | } | 914 | } |
915 | return Addressee(); | 915 | return Addressee(); |
916 | } | 916 | } |
917 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 917 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
918 | { | 918 | { |
919 | //qDebug("AddressBook::preExternSync "); | 919 | //qDebug("AddressBook::preExternSync "); |
920 | AddressBook::Iterator it; | 920 | AddressBook::Iterator it; |
921 | for ( it = begin(); it != end(); ++it ) { | 921 | for ( it = begin(); it != end(); ++it ) { |
922 | (*it).setID( csd, (*it).externalUID() ); | 922 | (*it).setID( csd, (*it).externalUID() ); |
923 | (*it).computeCsum( csd ); | 923 | (*it).computeCsum( csd ); |
924 | } | 924 | } |
925 | mergeAB( aBook ,csd, isSubset ); | 925 | mergeAB( aBook ,csd, isSubset ); |
926 | } | 926 | } |
927 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) | 927 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) |
928 | { | 928 | { |
929 | //qDebug("AddressBook::postExternSync "); | 929 | //qDebug("AddressBook::postExternSync "); |
930 | AddressBook::Iterator it; | 930 | AddressBook::Iterator it; |
931 | for ( it = begin(); it != end(); ++it ) { | 931 | for ( it = begin(); it != end(); ++it ) { |
932 | //qDebug("check uid %s ", (*it).uid().latin1() ); | 932 | //qDebug("check uid %s ", (*it).uid().latin1() ); |
933 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 933 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
934 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 934 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
935 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 935 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
936 | if ( ad.isEmpty() ) { | 936 | if ( ad.isEmpty() ) { |
937 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 937 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
938 | } else { | 938 | } else { |
939 | (*it).setIDStr(":"); | 939 | (*it).setIDStr(":"); |
940 | (*it).computeCsum( csd ); | 940 | (*it).computeCsum( csd ); |
941 | if ( setID ) { | 941 | if ( setID ) { |
942 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 942 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
943 | ad.setID( csd, (*it).externalUID() ); | 943 | ad.setID( csd, (*it).externalUID() ); |
944 | } else | 944 | } else |
945 | ad.setID( csd, "_" ); | 945 | ad.setID( csd, (*it).uid() ); |
946 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 946 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
947 | aBook->insertAddressee( ad ); | 947 | aBook->insertAddressee( ad ); |
948 | } | 948 | } |
949 | } | 949 | } |
950 | } | 950 | } |
951 | } | 951 | } |
952 | 952 | ||
953 | bool AddressBook::containsExternalUid( const QString& uid ) | 953 | bool AddressBook::containsExternalUid( const QString& uid ) |
954 | { | 954 | { |
955 | Iterator it; | 955 | Iterator it; |
956 | for ( it = begin(); it != end(); ++it ) { | 956 | for ( it = begin(); it != end(); ++it ) { |
957 | if ( uid == (*it).externalUID( ) ) | 957 | if ( uid == (*it).externalUID( ) ) |
958 | return true; | 958 | return true; |
959 | } | 959 | } |
960 | return false; | 960 | return false; |
961 | } | 961 | } |
962 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 962 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
963 | { | 963 | { |
964 | Iterator it; | 964 | Iterator it; |
965 | for ( it = begin(); it != end(); ++it ) { | 965 | for ( it = begin(); it != end(); ++it ) { |
966 | if ( uid == (*it).getID( profile ) ) | 966 | if ( uid == (*it).getID( profile ) ) |
967 | return (*it); | 967 | return (*it); |
968 | } | 968 | } |
969 | return Addressee(); | 969 | return Addressee(); |
970 | } | 970 | } |
971 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 971 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
972 | { | 972 | { |
973 | Iterator it; | 973 | Iterator it; |
974 | Addressee ad; | 974 | Addressee ad; |
975 | for ( it = begin(); it != end(); ++it ) { | 975 | for ( it = begin(); it != end(); ++it ) { |
976 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 976 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
977 | if ( !ad.isEmpty() ) { | 977 | if ( !ad.isEmpty() ) { |
978 | (*it).mergeContact( ad ,isSubset); | 978 | (*it).mergeContact( ad ,isSubset); |
979 | } | 979 | } |
980 | } | 980 | } |
981 | #if 0 | 981 | #if 0 |
982 | // test only | 982 | // test only |
983 | for ( it = begin(); it != end(); ++it ) { | 983 | for ( it = begin(); it != end(); ++it ) { |
984 | 984 | ||
985 | qDebug("uid %s ", (*it).uid().latin1()); | 985 | qDebug("uid %s ", (*it).uid().latin1()); |
986 | } | 986 | } |
987 | #endif | 987 | #endif |
988 | } | 988 | } |
989 | 989 | ||
990 | #if 0 | 990 | #if 0 |
991 | Addressee::List AddressBook::getExternLastSyncAddressees() | 991 | Addressee::List AddressBook::getExternLastSyncAddressees() |
992 | { | 992 | { |
993 | Addressee::List results; | 993 | Addressee::List results; |
994 | 994 | ||
995 | Iterator it; | 995 | Iterator it; |
996 | for ( it = begin(); it != end(); ++it ) { | 996 | for ( it = begin(); it != end(); ++it ) { |
997 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 997 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
998 | if ( (*it).familyName().left(4) == "!E: " ) | 998 | if ( (*it).familyName().left(4) == "!E: " ) |
999 | results.append( *it ); | 999 | results.append( *it ); |
1000 | } | 1000 | } |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | return results; | 1003 | return results; |
1004 | } | 1004 | } |
1005 | #endif | 1005 | #endif |
1006 | void AddressBook::resetTempSyncStat() | 1006 | void AddressBook::resetTempSyncStat() |
1007 | { | 1007 | { |
1008 | Iterator it; | 1008 | Iterator it; |
1009 | for ( it = begin(); it != end(); ++it ) { | 1009 | for ( it = begin(); it != end(); ++it ) { |
1010 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 1010 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
1011 | } | 1011 | } |
1012 | 1012 | ||
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | QStringList AddressBook:: uidList() | 1015 | QStringList AddressBook:: uidList() |
1016 | { | 1016 | { |
1017 | QStringList results; | 1017 | QStringList results; |
1018 | Iterator it; | 1018 | Iterator it; |
1019 | for ( it = begin(); it != end(); ++it ) { | 1019 | for ( it = begin(); it != end(); ++it ) { |
1020 | results.append( (*it).uid() ); | 1020 | results.append( (*it).uid() ); |
1021 | } | 1021 | } |
1022 | return results; | 1022 | return results; |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | 1025 | ||
1026 | Addressee::List AddressBook::allAddressees() | 1026 | Addressee::List AddressBook::allAddressees() |
1027 | { | 1027 | { |
1028 | return d->mAddressees; | 1028 | return d->mAddressees; |
1029 | 1029 | ||
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | Addressee::List AddressBook::findByName( const QString &name ) | 1032 | Addressee::List AddressBook::findByName( const QString &name ) |
1033 | { | 1033 | { |
1034 | Addressee::List results; | 1034 | Addressee::List results; |
1035 | 1035 | ||
1036 | Iterator it; | 1036 | Iterator it; |
1037 | for ( it = begin(); it != end(); ++it ) { | 1037 | for ( it = begin(); it != end(); ++it ) { |
1038 | if ( name == (*it).realName() ) { | 1038 | if ( name == (*it).realName() ) { |
1039 | results.append( *it ); | 1039 | results.append( *it ); |
1040 | } | 1040 | } |
1041 | } | 1041 | } |
1042 | 1042 | ||
1043 | return results; | 1043 | return results; |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | Addressee::List AddressBook::findByEmail( const QString &email ) | 1046 | Addressee::List AddressBook::findByEmail( const QString &email ) |
1047 | { | 1047 | { |
1048 | Addressee::List results; | 1048 | Addressee::List results; |
1049 | QStringList mailList; | 1049 | QStringList mailList; |
1050 | 1050 | ||
1051 | Iterator it; | 1051 | Iterator it; |
1052 | for ( it = begin(); it != end(); ++it ) { | 1052 | for ( it = begin(); it != end(); ++it ) { |
1053 | mailList = (*it).emails(); | 1053 | mailList = (*it).emails(); |
1054 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 1054 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
1055 | if ( email == (*ite) ) { | 1055 | if ( email == (*ite) ) { |
1056 | results.append( *it ); | 1056 | results.append( *it ); |
1057 | } | 1057 | } |
1058 | } | 1058 | } |
1059 | } | 1059 | } |
1060 | 1060 | ||
1061 | return results; | 1061 | return results; |
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1064 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1065 | { | 1065 | { |
1066 | Addressee::List results; | 1066 | Addressee::List results; |
1067 | 1067 | ||
1068 | Iterator it; | 1068 | Iterator it; |
1069 | for ( it = begin(); it != end(); ++it ) { | 1069 | for ( it = begin(); it != end(); ++it ) { |
1070 | if ( (*it).hasCategory( category) ) { | 1070 | if ( (*it).hasCategory( category) ) { |
1071 | results.append( *it ); | 1071 | results.append( *it ); |
1072 | } | 1072 | } |
1073 | } | 1073 | } |
1074 | 1074 | ||
1075 | return results; | 1075 | return results; |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | void AddressBook::dump() const | 1078 | void AddressBook::dump() const |
1079 | { | 1079 | { |
1080 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1080 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1081 | 1081 | ||
1082 | ConstIterator it; | 1082 | ConstIterator it; |
1083 | for( it = begin(); it != end(); ++it ) { | 1083 | for( it = begin(); it != end(); ++it ) { |
1084 | (*it).dump(); | 1084 | (*it).dump(); |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1087 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1088 | } | 1088 | } |
1089 | 1089 | ||
1090 | QString AddressBook::identifier() | 1090 | QString AddressBook::identifier() |
1091 | { | 1091 | { |
1092 | QStringList identifier; | 1092 | QStringList identifier; |
1093 | 1093 | ||
1094 | 1094 | ||
1095 | KRES::Manager<Resource>::ActiveIterator it; | 1095 | KRES::Manager<Resource>::ActiveIterator it; |
1096 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1096 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1097 | if ( !(*it)->identifier().isEmpty() ) | 1097 | if ( !(*it)->identifier().isEmpty() ) |
1098 | identifier.append( (*it)->identifier() ); | 1098 | identifier.append( (*it)->identifier() ); |
1099 | } | 1099 | } |
1100 | 1100 | ||
1101 | return identifier.join( ":" ); | 1101 | return identifier.join( ":" ); |
1102 | } | 1102 | } |
1103 | 1103 | ||
1104 | Field::List AddressBook::fields( int category ) | 1104 | Field::List AddressBook::fields( int category ) |
1105 | { | 1105 | { |
1106 | if ( d->mAllFields.isEmpty() ) { | 1106 | if ( d->mAllFields.isEmpty() ) { |
1107 | d->mAllFields = Field::allFields(); | 1107 | d->mAllFields = Field::allFields(); |
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | if ( category == Field::All ) return d->mAllFields; | 1110 | if ( category == Field::All ) return d->mAllFields; |
1111 | 1111 | ||
1112 | Field::List result; | 1112 | Field::List result; |
1113 | Field::List::ConstIterator it; | 1113 | Field::List::ConstIterator it; |
1114 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1114 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1115 | if ( (*it)->category() & category ) result.append( *it ); | 1115 | if ( (*it)->category() & category ) result.append( *it ); |
1116 | } | 1116 | } |
1117 | 1117 | ||
1118 | return result; | 1118 | return result; |
1119 | } | 1119 | } |
1120 | 1120 | ||
1121 | bool AddressBook::addCustomField( const QString &label, int category, | 1121 | bool AddressBook::addCustomField( const QString &label, int category, |
1122 | const QString &key, const QString &app ) | 1122 | const QString &key, const QString &app ) |
1123 | { | 1123 | { |
1124 | if ( d->mAllFields.isEmpty() ) { | 1124 | if ( d->mAllFields.isEmpty() ) { |
1125 | d->mAllFields = Field::allFields(); | 1125 | d->mAllFields = Field::allFields(); |
1126 | } | 1126 | } |
1127 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1127 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1128 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1128 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1129 | 1129 | ||
1130 | QString k = key.isNull() ? label : key; | 1130 | QString k = key.isNull() ? label : key; |
1131 | 1131 | ||
1132 | Field *field = Field::createCustomField( label, category, k, a ); | 1132 | Field *field = Field::createCustomField( label, category, k, a ); |
1133 | 1133 | ||
1134 | if ( !field ) return false; | 1134 | if ( !field ) return false; |
1135 | 1135 | ||
1136 | d->mAllFields.append( field ); | 1136 | d->mAllFields.append( field ); |
1137 | 1137 | ||
1138 | return true; | 1138 | return true; |
1139 | } | 1139 | } |
1140 | 1140 | ||
1141 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1141 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1142 | { | 1142 | { |
1143 | if (!ab.d) return s; | 1143 | if (!ab.d) return s; |
1144 | 1144 | ||
1145 | return s << ab.d->mAddressees; | 1145 | return s << ab.d->mAddressees; |
1146 | } | 1146 | } |
1147 | 1147 | ||
1148 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1148 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1149 | { | 1149 | { |
1150 | if (!ab.d) return s; | 1150 | if (!ab.d) return s; |
1151 | 1151 | ||
1152 | s >> ab.d->mAddressees; | 1152 | s >> ab.d->mAddressees; |
1153 | 1153 | ||
1154 | return s; | 1154 | return s; |
1155 | } | 1155 | } |
1156 | 1156 | ||
1157 | bool AddressBook::addResource( Resource *resource ) | 1157 | bool AddressBook::addResource( Resource *resource ) |
1158 | { | 1158 | { |
1159 | if ( !resource->open() ) { | 1159 | if ( !resource->open() ) { |
1160 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1160 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1161 | return false; | 1161 | return false; |
1162 | } | 1162 | } |
1163 | 1163 | ||
1164 | resource->setAddressBook( this ); | 1164 | resource->setAddressBook( this ); |
1165 | 1165 | ||
1166 | d->mManager->add( resource ); | 1166 | d->mManager->add( resource ); |
1167 | return true; | 1167 | return true; |
1168 | } | 1168 | } |
1169 | 1169 | ||
1170 | bool AddressBook::removeResource( Resource *resource ) | 1170 | bool AddressBook::removeResource( Resource *resource ) |
1171 | { | 1171 | { |
1172 | resource->close(); | 1172 | resource->close(); |
1173 | 1173 | ||
1174 | if ( resource == standardResource() ) | 1174 | if ( resource == standardResource() ) |
1175 | d->mManager->setStandardResource( 0 ); | 1175 | d->mManager->setStandardResource( 0 ); |
1176 | 1176 | ||
1177 | resource->setAddressBook( 0 ); | 1177 | resource->setAddressBook( 0 ); |
1178 | 1178 | ||
1179 | d->mManager->remove( resource ); | 1179 | d->mManager->remove( resource ); |
1180 | return true; | 1180 | return true; |
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | QPtrList<Resource> AddressBook::resources() | 1183 | QPtrList<Resource> AddressBook::resources() |
1184 | { | 1184 | { |
1185 | QPtrList<Resource> list; | 1185 | QPtrList<Resource> list; |
1186 | 1186 | ||
1187 | // qDebug("AddressBook::resources() 1"); | 1187 | // qDebug("AddressBook::resources() 1"); |
1188 | 1188 | ||
1189 | KRES::Manager<Resource>::ActiveIterator it; | 1189 | KRES::Manager<Resource>::ActiveIterator it; |
1190 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 1190 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
1191 | list.append( *it ); | 1191 | list.append( *it ); |
1192 | 1192 | ||
1193 | return list; | 1193 | return list; |
1194 | } | 1194 | } |
1195 | 1195 | ||
1196 | /*US | 1196 | /*US |
1197 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 1197 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
1198 | { | 1198 | { |
1199 | delete d->mErrorHandler; | 1199 | delete d->mErrorHandler; |
1200 | d->mErrorHandler = handler; | 1200 | d->mErrorHandler = handler; |
1201 | } | 1201 | } |
1202 | */ | 1202 | */ |
1203 | 1203 | ||
1204 | void AddressBook::error( const QString& msg ) | 1204 | void AddressBook::error( const QString& msg ) |
1205 | { | 1205 | { |
1206 | /*US | 1206 | /*US |
1207 | if ( !d->mErrorHandler ) // create default error handler | 1207 | if ( !d->mErrorHandler ) // create default error handler |
1208 | d->mErrorHandler = new ConsoleErrorHandler; | 1208 | d->mErrorHandler = new ConsoleErrorHandler; |
1209 | 1209 | ||
1210 | if ( d->mErrorHandler ) | 1210 | if ( d->mErrorHandler ) |
1211 | d->mErrorHandler->error( msg ); | 1211 | d->mErrorHandler->error( msg ); |
1212 | else | 1212 | else |
1213 | kdError(5700) << "no error handler defined" << endl; | 1213 | kdError(5700) << "no error handler defined" << endl; |
1214 | */ | 1214 | */ |
1215 | kdDebug(5700) << "msg" << endl; | 1215 | kdDebug(5700) << "msg" << endl; |
1216 | qDebug(msg); | 1216 | qDebug(msg); |
1217 | } | 1217 | } |
1218 | 1218 | ||
1219 | void AddressBook::deleteRemovedAddressees() | 1219 | void AddressBook::deleteRemovedAddressees() |
1220 | { | 1220 | { |
1221 | Addressee::List::Iterator it; | 1221 | Addressee::List::Iterator it; |
1222 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 1222 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
1223 | Resource *resource = (*it).resource(); | 1223 | Resource *resource = (*it).resource(); |
1224 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 1224 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
1225 | resource->removeAddressee( *it ); | 1225 | resource->removeAddressee( *it ); |
1226 | } | 1226 | } |
1227 | 1227 | ||
1228 | d->mRemovedAddressees.clear(); | 1228 | d->mRemovedAddressees.clear(); |
1229 | } | 1229 | } |
1230 | 1230 | ||
1231 | void AddressBook::setStandardResource( Resource *resource ) | 1231 | void AddressBook::setStandardResource( Resource *resource ) |
1232 | { | 1232 | { |
1233 | // qDebug("AddressBook::setStandardResource 1"); | 1233 | // qDebug("AddressBook::setStandardResource 1"); |
1234 | d->mManager->setStandardResource( resource ); | 1234 | d->mManager->setStandardResource( resource ); |
1235 | } | 1235 | } |
1236 | 1236 | ||
1237 | Resource *AddressBook::standardResource() | 1237 | Resource *AddressBook::standardResource() |
1238 | { | 1238 | { |
1239 | return d->mManager->standardResource(); | 1239 | return d->mManager->standardResource(); |
1240 | } | 1240 | } |
1241 | 1241 | ||
1242 | KRES::Manager<Resource> *AddressBook::resourceManager() | 1242 | KRES::Manager<Resource> *AddressBook::resourceManager() |
1243 | { | 1243 | { |
1244 | return d->mManager; | 1244 | return d->mManager; |
1245 | } | 1245 | } |
1246 | 1246 | ||
1247 | void AddressBook::cleanUp() | 1247 | void AddressBook::cleanUp() |
1248 | { | 1248 | { |
1249 | KRES::Manager<Resource>::ActiveIterator it; | 1249 | KRES::Manager<Resource>::ActiveIterator it; |
1250 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1250 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1251 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 1251 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
1252 | (*it)->cleanUp(); | 1252 | (*it)->cleanUp(); |
1253 | } | 1253 | } |
1254 | } | 1254 | } |