summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp135
1 files changed, 26 insertions, 109 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 1f90fcb..f9cabcb 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -54,4 +54,2 @@ $Id$
54#include "resourceqtopia.h" 54#include "resourceqtopia.h"
55#include <libkdepim/ksyncprofile.h>
56#include <qpe/quuid.h>
57 55
@@ -193,115 +191,34 @@ bool ResourceQtopia::save( Ticket *ticket )
193{ 191{
194 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 192 qDebug("ResourceQtopia::save: %s", fileName().latin1());
195
196 mDirWatch.stopScan();
197
198 KABC::AddressBook::Iterator it;
199 bool res;
200 KABC::Addressee::List changedAddressees;
201 QStringList addedUID;
202 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
203 //KABC::Addressee addressee = (*it);
204 // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() );
205 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
206 QUuid uid( (*it).originalExternalUID() );
207 bool ok;
208 PimContact c = mAccess->contactForId( uid, &ok );
209 qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() );
210 res = mConverter->addresseeToQtopia( *it, c );
211 if (res == true) {
212 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
213 qDebug("skipping adding of contact ");
214 continue;
215 PimContact e;
216 AddressBookAccess Access2;
217 Access2.addContact(e);
218 const PimContact* contact;
219 bool res;
220 QString uid2, Ouid;
221 AddressBookIterator itt(Access2);
222 for (contact=itt.toFirst(); itt.current(); ++itt)
223 {
224 contact = itt.current();
225 QString exuid = contact->uid().toString();
226 Ouid =exuid;
227 int ente = exuid.find( "-0000");
228 if ( exuid.left(1) == "{" )
229 exuid = exuid.mid(1);
230 if ( ente > -1 )
231 exuid = exuid.left( ente-1 );
232 uid2 = exuid;
233 qDebug("trying find uid ");
234 if ( !addressBook()->containsExternalUid( uid2 ) ) {
235 qDebug("ab not contains ");
236 if ( !addedUID.contains( uid2 )) {
237 qDebug("list not contains ");
238 break;
239 }
240 }
241
242 }
243 if ( !itt.current()) {
244 qDebug("ERROR uid ");
245 continue;
246 }
247 else
248 qDebug("ADD uid detected ");
249
250
251 QUuid uid3( Ouid);
252 PimContact d = Access2.contactForId( uid3, &ok );
253 if ( ! ok ) {
254 qDebug("ADD: Error getting new uid ");
255 } else {
256 qDebug("NEW UID found ");
257 PimContact g = mAccess->contactForId( c.uid(), &ok );
258 KABC::Addressee addressee;
259 mConverter->qtopiaToAddressee( g, addressee );
260 addressee.setUid((*it).uid() );
261 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
262 changedAddressees.append( addressee );
263 addedUID.append( uid2 );
264 }
265
266
267 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
268 qDebug("Remove contact ");
269 if ( ok )
270 mAccess->removeContact(c);
271 else
272 qDebug("Error remove contact from qtopia ");
273 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
274 if ( ok ) {
275 qDebug("Update contact ");
276 mAccess->updateContact(c);
277 PimContact g = mAccess->contactForId( c.uid(), &ok );
278 KABC::Addressee addressee;
279 mConverter->qtopiaToAddressee( g, addressee );
280 addressee.setUid((*it).uid() );
281 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
282 changedAddressees.append( addressee );
283 }
284 else
285 qDebug("Error update contact from qtopia ");
286
287 }
288
289 } else {
290 qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1());
291 }
292 }
293 }
294 193
295 KABC::Addressee::List::Iterator it2; 194 mDirWatch.stopScan();
296 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 )
297 addressBook()->insertAddressee((*it2));
298 195
196 KABC::AddressBook::Iterator it;
197 bool res;
299 198
199 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
200 PimContact c;
201 KABC::Addressee addressee = (*it);
300 202
301 mDirWatch.startScan(); 203 res = mConverter->addresseeToQtopia( *it, c );
204 if (res == true)
205 {
206 mAccess->addContact(c);
207// if (res == false)
208// qDebug("Unable to append Contact %s", c.fullName().latin1());
209 }
210 else
211 {
212 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
213 }
214 }
302 215
303 delete ticket; 216// mAccess->addressBookUpdated();
304 unlock( fileName() );
305 217
306 return true; 218 mDirWatch.startScan();
219
220 delete ticket;
221 unlock( fileName() );
222
223 return true;
307} 224}