summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-19 09:11:04 (UTC)
committer zautrix <zautrix>2004-09-19 09:11:04 (UTC)
commit953277a85e6ec5630ab0d64b4d68815e4e4f9906 (patch) (unidiff)
tree0a6acbc3ecd65784c1e875159b720849bc27dc48
parent787181d34f0d195ad72c9cf6aedbc317b6dd713e (diff)
downloadkdepimpi-953277a85e6ec5630ab0d64b4d68815e4e4f9906.zip
kdepimpi-953277a85e6ec5630ab0d64b4d68815e4e4f9906.tar.gz
kdepimpi-953277a85e6ec5630ab0d64b4d68815e4e4f9906.tar.bz2
More AB sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp9
-rw-r--r--kaddressbook/kabcore.cpp16
2 files changed, 12 insertions, 13 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index d6b70c4..c34f671 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -143,294 +143,293 @@ bool Addressee::operator==( const Addressee &a ) const
143 if ( mData->title != a.mData->title ) return false; 143 if ( mData->title != a.mData->title ) return false;
144 if ( mData->role != a.mData->role ) return false; 144 if ( mData->role != a.mData->role ) return false;
145 if ( mData->organization != a.mData->organization ) return false; 145 if ( mData->organization != a.mData->organization ) return false;
146 if ( mData->note != a.mData->note ) return false; 146 if ( mData->note != a.mData->note ) return false;
147 if ( mData->productId != a.mData->productId ) return false; 147 if ( mData->productId != a.mData->productId ) return false;
148 if ( mData->revision != a.mData->revision ) return false; 148 if ( mData->revision != a.mData->revision ) return false;
149 if ( mData->sortString != a.mData->sortString ) return false; 149 if ( mData->sortString != a.mData->sortString ) return false;
150 if ( mData->secrecy != a.mData->secrecy ) return false; 150 if ( mData->secrecy != a.mData->secrecy ) return false;
151 if ( mData->logo != a.mData->logo ) return false; 151 if ( mData->logo != a.mData->logo ) return false;
152 if ( mData->photo != a.mData->photo ) return false; 152 if ( mData->photo != a.mData->photo ) return false;
153 if ( mData->sound != a.mData->sound ) return false; 153 if ( mData->sound != a.mData->sound ) return false;
154 if ( mData->agent != a.mData->agent ) return false; 154 if ( mData->agent != a.mData->agent ) return false;
155 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 155 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
156 ( mData->url != a.mData->url ) ) return false; 156 ( mData->url != a.mData->url ) ) return false;
157 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 157 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
158 if ( mData->addresses != a.mData->addresses ) return false; 158 if ( mData->addresses != a.mData->addresses ) return false;
159 if ( mData->keys != a.mData->keys ) return false; 159 if ( mData->keys != a.mData->keys ) return false;
160 if ( mData->emails != a.mData->emails ) return false; 160 if ( mData->emails != a.mData->emails ) return false;
161 if ( mData->categories != a.mData->categories ) return false; 161 if ( mData->categories != a.mData->categories ) return false;
162 if ( mData->custom != a.mData->custom ) return false; 162 if ( mData->custom != a.mData->custom ) return false;
163 163
164 return true; 164 return true;
165} 165}
166 166
167bool Addressee::operator!=( const Addressee &a ) const 167bool Addressee::operator!=( const Addressee &a ) const
168{ 168{
169 return !( a == *this ); 169 return !( a == *this );
170} 170}
171 171
172bool Addressee::isEmpty() const 172bool Addressee::isEmpty() const
173{ 173{
174 return mData->empty; 174 return mData->empty;
175} 175}
176ulong Addressee::getCsum4List( const QStringList & attList) 176ulong Addressee::getCsum4List( const QStringList & attList)
177{ 177{
178 int max = attList.count(); 178 int max = attList.count();
179 ulong cSum = 0; 179 ulong cSum = 0;
180 int j,k,i; 180 int j,k,i;
181 int add; 181 int add;
182 for ( i = 0; i < max ; ++i ) { 182 for ( i = 0; i < max ; ++i ) {
183 QString s = attList[i]; 183 QString s = attList[i];
184 if ( ! s.isEmpty() ){ 184 if ( ! s.isEmpty() ){
185 j = s.length(); 185 j = s.length();
186 for ( k = 0; k < j; ++k ) { 186 for ( k = 0; k < j; ++k ) {
187 int mul = k +1; 187 int mul = k +1;
188 add = s[k].unicode (); 188 add = s[k].unicode ();
189 if ( k < 16 ) 189 if ( k < 16 )
190 mul = mul * mul; 190 mul = mul * mul;
191 int ii = i+1; 191 int ii = i+1;
192 add = add * mul *ii*ii*ii; 192 add = add * mul *ii*ii*ii;
193 cSum += add; 193 cSum += add;
194 } 194 }
195 } 195 }
196 196
197 } 197 }
198 //QString dump = attList.join(","); 198 //QString dump = attList.join(",");
199 //qDebug("csum: %d %s", cSum,dump.latin1()); 199 //qDebug("csum: %d %s", cSum,dump.latin1());
200 200
201 return cSum; 201 return cSum;
202 202
203} 203}
204void Addressee::computeCsum(const QString &dev) 204void Addressee::computeCsum(const QString &dev)
205{ 205{
206 QStringList l; 206 QStringList l;
207 if ( !mData->name.isEmpty() ) l.append(mData->name); 207 if ( !mData->name.isEmpty() ) l.append(mData->name);
208 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 208 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
209 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 209 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
210 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 210 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
211 if ( !mData->additionalName ) l.append( mData->additionalName ); 211 if ( !mData->additionalName ) l.append( mData->additionalName );
212 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 212 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
213 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 213 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
214 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 214 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
215 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 215 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
216 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 216 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
217 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 217 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
218 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 218 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
219 if ( !mData->title .isEmpty() ) l.append( mData->title ); 219 if ( !mData->title .isEmpty() ) l.append( mData->title );
220 if ( !mData->role.isEmpty() ) l.append( mData->role ); 220 if ( !mData->role.isEmpty() ) l.append( mData->role );
221 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 221 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
222 if ( !mData->note.isEmpty() ) l.append( mData->note ); 222 if ( !mData->note.isEmpty() ) l.append( mData->note );
223 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 223 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
224 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 224 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
225 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 225 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
226 // if ( !mData->logo.isEmpty() ) l.append( ); 226 // if ( !mData->logo.isEmpty() ) l.append( );
227 //if ( !mData->photo.isEmpty() ) l.append( ); 227 //if ( !mData->photo.isEmpty() ) l.append( );
228 //if ( !mData->sound.isEmpty() ) l.append( ); 228 //if ( !mData->sound.isEmpty() ) l.append( );
229 //if ( !mData->agent.isEmpty() ) l.append( ); 229 //if ( !mData->agent.isEmpty() ) l.append( );
230 //if ( mData->url.isValid() ) l.append( ); 230 //if ( mData->url.isValid() ) l.append( );
231#if 0 231#if 0
232 if ( !mData->phoneNumbers.isEmpty() ) l.append( ); 232 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
233 if ( !mData->addresses.isEmpty() ) l.append( ); 233 if ( !mData->addresses.isEmpty() ) l.append( );
234 //if ( !mData->keys.isEmpty() ) l.append( ); 234 //if ( !mData->keys.isEmpty() ) l.append( );
235 if ( !mData->emails.isEmpty() ) l.append( ); 235 if ( !mData->emails.isEmpty() ) l.append( );
236 if ( !mData->categories .isEmpty() ) l.append( ); 236 if ( !mData->categories .isEmpty() ) l.append( );
237 if ( !mData->custom.isEmpty() ) l.append( ); 237 if ( !mData->custom.isEmpty() ) l.append( );
238#endif 238#endif
239 KABC::PhoneNumber::List phoneNumbers; 239 KABC::PhoneNumber::List phoneNumbers;
240 KABC::PhoneNumber::List::Iterator phoneIter; 240 KABC::PhoneNumber::List::Iterator phoneIter;
241 241
242 QStringList t; 242 QStringList t;
243 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 243 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
244 ++phoneIter ) 244 ++phoneIter )
245 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 245 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
246 t.sort(); 246 t.sort();
247 uint iii; 247 uint iii;
248 for ( iii = 0; iii < t.count(); ++iii) 248 for ( iii = 0; iii < t.count(); ++iii)
249 l.append( t[iii] ); 249 l.append( t[iii] );
250 t = mData->emails; 250 t = mData->emails;
251 t.sort(); 251 t.sort();
252 for ( iii = 0; iii < t.count(); ++iii) 252 for ( iii = 0; iii < t.count(); ++iii)
253 l.append( t[iii] ); 253 l.append( t[iii] );
254 t = mData->categories; 254 t = mData->categories;
255 t.sort(); 255 t.sort();
256 for ( iii = 0; iii < t.count(); ++iii) 256 for ( iii = 0; iii < t.count(); ++iii)
257 l.append( t[iii] ); 257 l.append( t[iii] );
258 t = mData->custom; 258 t = mData->custom;
259 t.sort(); 259 t.sort();
260 for ( iii = 0; iii < t.count(); ++iii) 260 for ( iii = 0; iii < t.count(); ++iii)
261 l.append( t[iii] ); 261 l.append( t[iii] );
262 KABC::Address::List::Iterator addressIter; 262 KABC::Address::List::Iterator addressIter;
263 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 263 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
264 ++addressIter ) { 264 ++addressIter ) {
265 t = (*addressIter).asList(); 265 t = (*addressIter).asList();
266 t.sort(); 266 t.sort();
267 for ( iii = 0; iii < t.count(); ++iii) 267 for ( iii = 0; iii < t.count(); ++iii)
268 l.append( t[iii] ); 268 l.append( t[iii] );
269 } 269 }
270 uint cs = getCsum4List(l); 270 uint cs = getCsum4List(l);
271 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 271 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
272 setCsum( dev, QString::number (cs )); 272 setCsum( dev, QString::number (cs ));
273} 273}
274void Addressee::removeID(const QString &prof) 274void Addressee::removeID(const QString &prof)
275{ 275{
276 detach(); 276 detach();
277 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 277 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
278 278
279} 279}
280void Addressee::setID( const QString & prof , const QString & id ) 280void Addressee::setID( const QString & prof , const QString & id )
281{ 281{
282 detach(); 282 detach();
283 qDebug("setID1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
284 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 283 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
285 qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 284 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
286} 285}
287void Addressee::setTempSyncStat( int id ) 286void Addressee::setTempSyncStat( int id )
288{ 287{
289 if ( mData->mTempSyncStat == id ) return; 288 if ( mData->mTempSyncStat == id ) return;
290 detach(); 289 detach();
291 mData->mTempSyncStat = id; 290 mData->mTempSyncStat = id;
292} 291}
293int Addressee::tempSyncStat() const 292int Addressee::tempSyncStat() const
294{ 293{
295 return mData->mTempSyncStat; 294 return mData->mTempSyncStat;
296} 295}
297 296
298QString Addressee::getID( const QString & prof) 297QString Addressee::getID( const QString & prof)
299{ 298{
300 return KIdManager::getId ( mData->mExternalId, prof ); 299 return KIdManager::getId ( mData->mExternalId, prof );
301} 300}
302 301
303void Addressee::setCsum( const QString & prof , const QString & id ) 302void Addressee::setCsum( const QString & prof , const QString & id )
304{ 303{
305 detach(); 304 detach();
306 qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 305 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
307 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 306 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
308 qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 307 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
309} 308}
310 309
311QString Addressee::getCsum( const QString & prof) 310QString Addressee::getCsum( const QString & prof)
312{ 311{
313 return KIdManager::getCsum ( mData->mExternalId, prof ); 312 return KIdManager::getCsum ( mData->mExternalId, prof );
314} 313}
315 314
316void Addressee::setIDStr( const QString & s ) 315void Addressee::setIDStr( const QString & s )
317{ 316{
318 detach(); 317 detach();
319 mData->mExternalId = s; 318 mData->mExternalId = s;
320} 319}
321 320
322QString Addressee::IDStr() const 321QString Addressee::IDStr() const
323{ 322{
324 return mData->mExternalId; 323 return mData->mExternalId;
325} 324}
326 325
327 326
328void Addressee::setUid( const QString &id ) 327void Addressee::setUid( const QString &id )
329{ 328{
330 if ( id == mData->uid ) return; 329 if ( id == mData->uid ) return;
331 detach(); 330 detach();
332 mData->empty = false; 331 mData->empty = false;
333 mData->uid = id; 332 mData->uid = id;
334} 333}
335 334
336QString Addressee::uid() const 335QString Addressee::uid() const
337{ 336{
338 if ( mData->uid.isEmpty() ) 337 if ( mData->uid.isEmpty() )
339 mData->uid = KApplication::randomString( 10 ); 338 mData->uid = KApplication::randomString( 10 );
340 339
341 return mData->uid; 340 return mData->uid;
342} 341}
343 342
344QString Addressee::uidLabel() 343QString Addressee::uidLabel()
345{ 344{
346 return i18n("Unique Identifier"); 345 return i18n("Unique Identifier");
347} 346}
348 347
349void Addressee::setName( const QString &name ) 348void Addressee::setName( const QString &name )
350{ 349{
351 if ( name == mData->name ) return; 350 if ( name == mData->name ) return;
352 detach(); 351 detach();
353 mData->empty = false; 352 mData->empty = false;
354 mData->name = name; 353 mData->name = name;
355} 354}
356 355
357QString Addressee::name() const 356QString Addressee::name() const
358{ 357{
359 return mData->name; 358 return mData->name;
360} 359}
361 360
362QString Addressee::nameLabel() 361QString Addressee::nameLabel()
363{ 362{
364 return i18n("Name"); 363 return i18n("Name");
365} 364}
366 365
367 366
368void Addressee::setFormattedName( const QString &formattedName ) 367void Addressee::setFormattedName( const QString &formattedName )
369{ 368{
370 if ( formattedName == mData->formattedName ) return; 369 if ( formattedName == mData->formattedName ) return;
371 detach(); 370 detach();
372 mData->empty = false; 371 mData->empty = false;
373 mData->formattedName = formattedName; 372 mData->formattedName = formattedName;
374} 373}
375 374
376QString Addressee::formattedName() const 375QString Addressee::formattedName() const
377{ 376{
378 return mData->formattedName; 377 return mData->formattedName;
379} 378}
380 379
381QString Addressee::formattedNameLabel() 380QString Addressee::formattedNameLabel()
382{ 381{
383 return i18n("Formatted Name"); 382 return i18n("Formatted Name");
384} 383}
385 384
386 385
387void Addressee::setFamilyName( const QString &familyName ) 386void Addressee::setFamilyName( const QString &familyName )
388{ 387{
389 if ( familyName == mData->familyName ) return; 388 if ( familyName == mData->familyName ) return;
390 detach(); 389 detach();
391 mData->empty = false; 390 mData->empty = false;
392 mData->familyName = familyName; 391 mData->familyName = familyName;
393} 392}
394 393
395QString Addressee::familyName() const 394QString Addressee::familyName() const
396{ 395{
397 return mData->familyName; 396 return mData->familyName;
398} 397}
399 398
400QString Addressee::familyNameLabel() 399QString Addressee::familyNameLabel()
401{ 400{
402 return i18n("Family Name"); 401 return i18n("Family Name");
403} 402}
404 403
405 404
406void Addressee::setGivenName( const QString &givenName ) 405void Addressee::setGivenName( const QString &givenName )
407{ 406{
408 if ( givenName == mData->givenName ) return; 407 if ( givenName == mData->givenName ) return;
409 detach(); 408 detach();
410 mData->empty = false; 409 mData->empty = false;
411 mData->givenName = givenName; 410 mData->givenName = givenName;
412} 411}
413 412
414QString Addressee::givenName() const 413QString Addressee::givenName() const
415{ 414{
416 return mData->givenName; 415 return mData->givenName;
417} 416}
418 417
419QString Addressee::givenNameLabel() 418QString Addressee::givenNameLabel()
420{ 419{
421 return i18n("Given Name"); 420 return i18n("Given Name");
422} 421}
423 422
424 423
425void Addressee::setAdditionalName( const QString &additionalName ) 424void Addressee::setAdditionalName( const QString &additionalName )
426{ 425{
427 if ( additionalName == mData->additionalName ) return; 426 if ( additionalName == mData->additionalName ) return;
428 detach(); 427 detach();
429 mData->empty = false; 428 mData->empty = false;
430 mData->additionalName = additionalName; 429 mData->additionalName = additionalName;
431} 430}
432 431
433QString Addressee::additionalName() const 432QString Addressee::additionalName() const
434{ 433{
435 return mData->additionalName; 434 return mData->additionalName;
436} 435}
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 56f6af2..fa0c51f 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2427,596 +2427,596 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask)
2427 result = system ( command ); 2427 result = system ( command );
2428 qDebug("KO: Writing back file result: %d ", result); 2428 qDebug("KO: Writing back file result: %d ", result);
2429 if ( result != 0 ) { 2429 if ( result != 0 ) {
2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2431 return; 2431 return;
2432 } else { 2432 } else {
2433 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2433 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2434 } 2434 }
2435 } 2435 }
2436 } 2436 }
2437 return; 2437 return;
2438} 2438}
2439#include <qpushbutton.h> 2439#include <qpushbutton.h>
2440#include <qradiobutton.h> 2440#include <qradiobutton.h>
2441#include <qbuttongroup.h> 2441#include <qbuttongroup.h>
2442void KABCore::edit_sync_options() 2442void KABCore::edit_sync_options()
2443{ 2443{
2444 //mDialogManager->showSyncOptions(); 2444 //mDialogManager->showSyncOptions();
2445 //KABPrefs::instance()->mSyncAlgoPrefs 2445 //KABPrefs::instance()->mSyncAlgoPrefs
2446 QDialog dia( this, "dia", true ); 2446 QDialog dia( this, "dia", true );
2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2449 QVBoxLayout lay ( &dia ); 2449 QVBoxLayout lay ( &dia );
2450 lay.setSpacing( 2 ); 2450 lay.setSpacing( 2 );
2451 lay.setMargin( 3 ); 2451 lay.setMargin( 3 );
2452 lay.addWidget(&gr); 2452 lay.addWidget(&gr);
2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2459 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2459 //QRadioButton both( i18n("Take both on conflict"), &gr );
2460 QPushButton pb ( "OK", &dia); 2460 QPushButton pb ( "OK", &dia);
2461 lay.addWidget( &pb ); 2461 lay.addWidget( &pb );
2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { 2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) {
2464 case 0: 2464 case 0:
2465 loc.setChecked( true); 2465 loc.setChecked( true);
2466 break; 2466 break;
2467 case 1: 2467 case 1:
2468 rem.setChecked( true ); 2468 rem.setChecked( true );
2469 break; 2469 break;
2470 case 2: 2470 case 2:
2471 newest.setChecked( true); 2471 newest.setChecked( true);
2472 break; 2472 break;
2473 case 3: 2473 case 3:
2474 ask.setChecked( true); 2474 ask.setChecked( true);
2475 break; 2475 break;
2476 case 4: 2476 case 4:
2477 f_loc.setChecked( true); 2477 f_loc.setChecked( true);
2478 break; 2478 break;
2479 case 5: 2479 case 5:
2480 f_rem.setChecked( true); 2480 f_rem.setChecked( true);
2481 break; 2481 break;
2482 case 6: 2482 case 6:
2483 // both.setChecked( true); 2483 // both.setChecked( true);
2484 break; 2484 break;
2485 default: 2485 default:
2486 break; 2486 break;
2487 } 2487 }
2488 if ( dia.exec() ) { 2488 if ( dia.exec() ) {
2489 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2489 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2490 } 2490 }
2491 2491
2492 2492
2493} 2493}
2494QString KABCore::getPassword( ) 2494QString KABCore::getPassword( )
2495{ 2495{
2496 QString retfile = ""; 2496 QString retfile = "";
2497 QDialog dia ( this, "input-dialog", true ); 2497 QDialog dia ( this, "input-dialog", true );
2498 QLineEdit lab ( &dia ); 2498 QLineEdit lab ( &dia );
2499 lab.setEchoMode( QLineEdit::Password ); 2499 lab.setEchoMode( QLineEdit::Password );
2500 QVBoxLayout lay( &dia ); 2500 QVBoxLayout lay( &dia );
2501 lay.setMargin(7); 2501 lay.setMargin(7);
2502 lay.setSpacing(7); 2502 lay.setSpacing(7);
2503 lay.addWidget( &lab); 2503 lay.addWidget( &lab);
2504 dia.setFixedSize( 230,50 ); 2504 dia.setFixedSize( 230,50 );
2505 dia.setCaption( i18n("Enter password") ); 2505 dia.setCaption( i18n("Enter password") );
2506 QPushButton pb ( "OK", &dia); 2506 QPushButton pb ( "OK", &dia);
2507 lay.addWidget( &pb ); 2507 lay.addWidget( &pb );
2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2509 dia.show(); 2509 dia.show();
2510 int res = dia.exec(); 2510 int res = dia.exec();
2511 if ( res ) 2511 if ( res )
2512 retfile = lab.text(); 2512 retfile = lab.text();
2513 dia.hide(); 2513 dia.hide();
2514 qApp->processEvents(); 2514 qApp->processEvents();
2515 return retfile; 2515 return retfile;
2516 2516
2517} 2517}
2518#include <libkcal/syncdefines.h> 2518#include <libkcal/syncdefines.h>
2519 2519
2520KABC::Addressee KABCore::getLastSyncAddressee() 2520KABC::Addressee KABCore::getLastSyncAddressee()
2521{ 2521{
2522 Addressee lse; 2522 Addressee lse;
2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2525 if (lse.isEmpty()) { 2525 if (lse.isEmpty()) {
2526 qDebug("Creating new last-syncAddressee "); 2526 qDebug("Creating new last-syncAddressee ");
2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2528 QString sum = ""; 2528 QString sum = "";
2529 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2529 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2530 sum = "E: "; 2530 sum = "E: ";
2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2532 lse.setRevision( mLastAddressbookSync ); 2532 lse.setRevision( mLastAddressbookSync );
2533 lse.setCategories( i18n("SyncEvent") ); 2533 lse.setCategories( i18n("SyncEvent") );
2534 mAddressBook->insertAddressee( lse ); 2534 mAddressBook->insertAddressee( lse );
2535 } 2535 }
2536 return lse; 2536 return lse;
2537} 2537}
2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2539{ 2539{
2540 2540
2541 //void setZaurusId(int id); 2541 //void setZaurusId(int id);
2542 // int zaurusId() const; 2542 // int zaurusId() const;
2543 // void setZaurusUid(int id); 2543 // void setZaurusUid(int id);
2544 // int zaurusUid() const; 2544 // int zaurusUid() const;
2545 // void setZaurusStat(int id); 2545 // void setZaurusStat(int id);
2546 // int zaurusStat() const; 2546 // int zaurusStat() const;
2547 // 0 equal 2547 // 0 equal
2548 // 1 take local 2548 // 1 take local
2549 // 2 take remote 2549 // 2 take remote
2550 // 3 cancel 2550 // 3 cancel
2551 QDateTime lastSync = mLastAddressbookSync; 2551 QDateTime lastSync = mLastAddressbookSync;
2552 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2552 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2553 bool remCh, locCh; 2553 bool remCh, locCh;
2554 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2554 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2555 if ( remCh ) 2555
2556 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2556 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2557 locCh = ( local->revision() > mLastAddressbookSync ); 2557 locCh = ( local->revision() > mLastAddressbookSync );
2558 if ( !remCh && ! locCh ) { 2558 if ( !remCh && ! locCh ) {
2559 qDebug("both not changed "); 2559 //qDebug("both not changed ");
2560 lastSync = local->revision().addDays(1); 2560 lastSync = local->revision().addDays(1);
2561 if ( mode <= SYNC_PREF_ASK ) 2561 if ( mode <= SYNC_PREF_ASK )
2562 return 0; 2562 return 0;
2563 } else { 2563 } else {
2564 if ( locCh ) { 2564 if ( locCh ) {
2565 qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1()); 2565 //qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1());
2566 lastSync = local->revision().addDays( -1 ); 2566 lastSync = local->revision().addDays( -1 );
2567 if ( !remCh ) 2567 if ( !remCh )
2568 remote->setRevision( lastSync.addDays( -1 ) ); 2568 remote->setRevision( lastSync.addDays( -1 ) );
2569 } else { 2569 } else {
2570 //qDebug(" not loc changed "); 2570 //qDebug(" not loc changed ");
2571 lastSync = local->revision().addDays( 1 ); 2571 lastSync = local->revision().addDays( 1 );
2572 if ( remCh ) 2572 if ( remCh )
2573 remote->setRevision( lastSync.addDays( 1 ) ); 2573 remote->setRevision( lastSync.addDays( 1 ) );
2574 2574
2575 } 2575 }
2576 } 2576 }
2577 full = true; 2577 full = true;
2578 if ( mode < SYNC_PREF_ASK ) 2578 if ( mode < SYNC_PREF_ASK )
2579 mode = SYNC_PREF_ASK; 2579 mode = SYNC_PREF_ASK;
2580 } else { 2580 } else {
2581 if ( local->revision() == remote->revision() ) 2581 if ( local->revision() == remote->revision() )
2582 return 0; 2582 return 0;
2583 2583
2584 } 2584 }
2585 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2585 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2586 2586
2587 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 2587 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
2588 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2588 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2589 //full = true; //debug only 2589 //full = true; //debug only
2590 if ( full ) { 2590 if ( full ) {
2591 bool equ = ( (*local) == (*remote) ); 2591 bool equ = ( (*local) == (*remote) );
2592 if ( equ ) { 2592 if ( equ ) {
2593 //qDebug("equal "); 2593 //qDebug("equal ");
2594 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2594 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2595 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2595 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2596 } 2596 }
2597 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2597 if ( mode < SYNC_PREF_FORCE_LOCAL )
2598 return 0; 2598 return 0;
2599 2599
2600 }//else //debug only 2600 }//else //debug only
2601 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2601 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2602 } 2602 }
2603 int result; 2603 int result;
2604 bool localIsNew; 2604 bool localIsNew;
2605 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 2605 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2606 2606
2607 if ( full && mode < SYNC_PREF_NEWEST ) 2607 if ( full && mode < SYNC_PREF_NEWEST )
2608 mode = SYNC_PREF_ASK; 2608 mode = SYNC_PREF_ASK;
2609 2609
2610 switch( mode ) { 2610 switch( mode ) {
2611 case SYNC_PREF_LOCAL: 2611 case SYNC_PREF_LOCAL:
2612 if ( lastSync > remote->revision() ) 2612 if ( lastSync > remote->revision() )
2613 return 1; 2613 return 1;
2614 if ( lastSync > local->revision() ) 2614 if ( lastSync > local->revision() )
2615 return 2; 2615 return 2;
2616 return 1; 2616 return 1;
2617 break; 2617 break;
2618 case SYNC_PREF_REMOTE: 2618 case SYNC_PREF_REMOTE:
2619 if ( lastSync > remote->revision() ) 2619 if ( lastSync > remote->revision() )
2620 return 1; 2620 return 1;
2621 if ( lastSync > local->revision() ) 2621 if ( lastSync > local->revision() )
2622 return 2; 2622 return 2;
2623 return 2; 2623 return 2;
2624 break; 2624 break;
2625 case SYNC_PREF_NEWEST: 2625 case SYNC_PREF_NEWEST:
2626 if ( local->revision() > remote->revision() ) 2626 if ( local->revision() > remote->revision() )
2627 return 1; 2627 return 1;
2628 else 2628 else
2629 return 2; 2629 return 2;
2630 break; 2630 break;
2631 case SYNC_PREF_ASK: 2631 case SYNC_PREF_ASK:
2632 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); 2632 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() );
2633 if ( lastSync > remote->revision() ) 2633 if ( lastSync > remote->revision() )
2634 return 1; 2634 return 1;
2635 if ( lastSync > local->revision() ) 2635 if ( lastSync > local->revision() )
2636 return 2; 2636 return 2;
2637 localIsNew = local->revision() >= remote->revision(); 2637 localIsNew = local->revision() >= remote->revision();
2638 //qDebug("conflict! ************************************** "); 2638 //qDebug("conflict! ************************************** ");
2639 { 2639 {
2640 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2640 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2641 result = acd.executeD(localIsNew); 2641 result = acd.executeD(localIsNew);
2642 return result; 2642 return result;
2643 } 2643 }
2644 break; 2644 break;
2645 case SYNC_PREF_FORCE_LOCAL: 2645 case SYNC_PREF_FORCE_LOCAL:
2646 return 1; 2646 return 1;
2647 break; 2647 break;
2648 case SYNC_PREF_FORCE_REMOTE: 2648 case SYNC_PREF_FORCE_REMOTE:
2649 return 2; 2649 return 2;
2650 break; 2650 break;
2651 2651
2652 default: 2652 default:
2653 // SYNC_PREF_TAKE_BOTH not implemented 2653 // SYNC_PREF_TAKE_BOTH not implemented
2654 break; 2654 break;
2655 } 2655 }
2656 return 0; 2656 return 0;
2657} 2657}
2658bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2658bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2659{ 2659{
2660 bool syncOK = true; 2660 bool syncOK = true;
2661 int addedAddressee = 0; 2661 int addedAddressee = 0;
2662 int addedAddresseeR = 0; 2662 int addedAddresseeR = 0;
2663 int deletedAddresseeR = 0; 2663 int deletedAddresseeR = 0;
2664 int deletedAddresseeL = 0; 2664 int deletedAddresseeL = 0;
2665 int changedLocal = 0; 2665 int changedLocal = 0;
2666 int changedRemote = 0; 2666 int changedRemote = 0;
2667 //QPtrList<Addressee> el = local->rawAddressees(); 2667 //QPtrList<Addressee> el = local->rawAddressees();
2668 Addressee addresseeR; 2668 Addressee addresseeR;
2669 QString uid; 2669 QString uid;
2670 int take; 2670 int take;
2671 Addressee addresseeL; 2671 Addressee addresseeL;
2672 Addressee addresseeRSync; 2672 Addressee addresseeRSync;
2673 Addressee addresseeLSync; 2673 Addressee addresseeLSync;
2674 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2674 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2675 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2675 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2676 bool fullDateRange = false; 2676 bool fullDateRange = false;
2677 local->resetTempSyncStat(); 2677 local->resetTempSyncStat();
2678 mLastAddressbookSync = QDateTime::currentDateTime(); 2678 mLastAddressbookSync = QDateTime::currentDateTime();
2679 QDateTime modifiedCalendar = mLastAddressbookSync;; 2679 QDateTime modifiedCalendar = mLastAddressbookSync;;
2680 addresseeLSync = getLastSyncAddressee(); 2680 addresseeLSync = getLastSyncAddressee();
2681 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2681 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2682 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2682 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2683 if ( !addresseeR.isEmpty() ) { 2683 if ( !addresseeR.isEmpty() ) {
2684 addresseeRSync = addresseeR; 2684 addresseeRSync = addresseeR;
2685 remote->removeAddressee(addresseeR ); 2685 remote->removeAddressee(addresseeR );
2686 2686
2687 } else { 2687 } else {
2688 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2688 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2689 addresseeRSync = addresseeLSync ; 2689 addresseeRSync = addresseeLSync ;
2690 } else { 2690 } else {
2691 qDebug("FULLDATE 1"); 2691 qDebug("FULLDATE 1");
2692 fullDateRange = true; 2692 fullDateRange = true;
2693 Addressee newAdd; 2693 Addressee newAdd;
2694 addresseeRSync = newAdd; 2694 addresseeRSync = newAdd;
2695 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2695 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2696 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2696 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2697 addresseeRSync.setRevision( mLastAddressbookSync ); 2697 addresseeRSync.setRevision( mLastAddressbookSync );
2698 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2698 addresseeRSync.setCategories( i18n("SyncAddressee") );
2699 } 2699 }
2700 } 2700 }
2701 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2701 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2702 qDebug("FULLDATE 2"); 2702 qDebug("FULLDATE 2");
2703 fullDateRange = true; 2703 fullDateRange = true;
2704 } 2704 }
2705 if ( ! fullDateRange ) { 2705 if ( ! fullDateRange ) {
2706 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2706 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2707 2707
2708 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2708 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2709 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2709 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2710 fullDateRange = true; 2710 fullDateRange = true;
2711 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2711 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2712 } 2712 }
2713 } 2713 }
2714 // fullDateRange = true; // debug only! 2714 // fullDateRange = true; // debug only!
2715 if ( fullDateRange ) 2715 if ( fullDateRange )
2716 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2716 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2717 else 2717 else
2718 mLastAddressbookSync = addresseeLSync.revision(); 2718 mLastAddressbookSync = addresseeLSync.revision();
2719 // for resyncing if own file has changed 2719 // for resyncing if own file has changed
2720 // PENDING fixme later when implemented 2720 // PENDING fixme later when implemented
2721#if 0 2721#if 0
2722 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2722 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2723 mLastAddressbookSync = loadedFileVersion; 2723 mLastAddressbookSync = loadedFileVersion;
2724 qDebug("setting mLastAddressbookSync "); 2724 qDebug("setting mLastAddressbookSync ");
2725 } 2725 }
2726#endif 2726#endif
2727 2727
2728 //qDebug("*************************** "); 2728 //qDebug("*************************** ");
2729 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2729 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2730 QStringList er = remote->uidList(); 2730 QStringList er = remote->uidList();
2731 Addressee inR ;//= er.first(); 2731 Addressee inR ;//= er.first();
2732 Addressee inL; 2732 Addressee inL;
2733 QProgressBar bar( er.count(),0 ); 2733 QProgressBar bar( er.count(),0 );
2734 bar.setCaption (i18n("Syncing - close to abort!") ); 2734 bar.setCaption (i18n("Syncing - close to abort!") );
2735 2735
2736 int w = 300; 2736 int w = 300;
2737 if ( QApplication::desktop()->width() < 320 ) 2737 if ( QApplication::desktop()->width() < 320 )
2738 w = 220; 2738 w = 220;
2739 int h = bar.sizeHint().height() ; 2739 int h = bar.sizeHint().height() ;
2740 int dw = QApplication::desktop()->width(); 2740 int dw = QApplication::desktop()->width();
2741 int dh = QApplication::desktop()->height(); 2741 int dh = QApplication::desktop()->height();
2742 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2742 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2743 bar.show(); 2743 bar.show();
2744 int modulo = (er.count()/10)+1; 2744 int modulo = (er.count()/10)+1;
2745 int incCounter = 0; 2745 int incCounter = 0;
2746 while ( incCounter < er.count()) { 2746 while ( incCounter < er.count()) {
2747 if ( ! bar.isVisible() ) 2747 if ( ! bar.isVisible() )
2748 return false; 2748 return false;
2749 if ( incCounter % modulo == 0 ) 2749 if ( incCounter % modulo == 0 )
2750 bar.setProgress( incCounter ); 2750 bar.setProgress( incCounter );
2751 uid = er[ incCounter ]; 2751 uid = er[ incCounter ];
2752 bool skipIncidence = false; 2752 bool skipIncidence = false;
2753 if ( uid.left(19) == QString("last-syncAddressee-") ) 2753 if ( uid.left(19) == QString("last-syncAddressee-") )
2754 skipIncidence = true; 2754 skipIncidence = true;
2755 QString idS; 2755 QString idS;
2756 qApp->processEvents(); 2756 qApp->processEvents();
2757 if ( !skipIncidence ) { 2757 if ( !skipIncidence ) {
2758 inL = local->findByUid( uid ); 2758 inL = local->findByUid( uid );
2759 inR = remote->findByUid( uid ); 2759 inR = remote->findByUid( uid );
2760 //inL.setResource( 0 ); 2760 //inL.setResource( 0 );
2761 //inR.setResource( 0 ); 2761 //inR.setResource( 0 );
2762 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2762 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2763 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2763 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2764 //qDebug("take %d %s ", take, inL.summary().latin1()); 2764 //qDebug("take %d %s ", take, inL.summary().latin1());
2765 if ( take == 3 ) 2765 if ( take == 3 )
2766 return false; 2766 return false;
2767 if ( take == 1 ) {// take local 2767 if ( take == 1 ) {// take local
2768 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2768 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2769 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2769 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2770 local->insertAddressee( inL, false ); 2770 local->insertAddressee( inL, false );
2771 } 2771 }
2772 else 2772 else
2773 idS = inR.IDStr(); 2773 idS = inR.IDStr();
2774 remote->removeAddressee( inR ); 2774 remote->removeAddressee( inR );
2775 inR = inL; 2775 inR = inL;
2776 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2776 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2777 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 2777 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
2778 inR.setIDStr( idS ); 2778 inR.setIDStr( idS );
2779 inR.setResource( 0 ); 2779 inR.setResource( 0 );
2780 remote->insertAddressee( inR , false); 2780 remote->insertAddressee( inR , false);
2781 ++changedRemote; 2781 ++changedRemote;
2782 } else { 2782 } else {
2783 idS = inL.IDStr(); 2783 idS = inL.IDStr();
2784 local->removeAddressee( inL ); 2784 local->removeAddressee( inL );
2785 inL = inR; 2785 inL = inR;
2786 inL.setIDStr( idS ); 2786 inL.setIDStr( idS );
2787 inL.setResource( 0 ); 2787 inL.setResource( 0 );
2788 local->insertAddressee( inL , false ); 2788 local->insertAddressee( inL , false );
2789 ++changedLocal; 2789 ++changedLocal;
2790 } 2790 }
2791 } 2791 }
2792 } else { // no conflict 2792 } else { // no conflict
2793 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2793 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2794 QString des = addresseeLSync.note(); 2794 QString des = addresseeLSync.note();
2795 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2795 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2796 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2796 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2797 remote->insertAddressee( inR, false ); 2797 remote->insertAddressee( inR, false );
2798 ++deletedAddresseeR; 2798 ++deletedAddresseeR;
2799 } else { 2799 } else {
2800 inR.setRevision( modifiedCalendar ); 2800 inR.setRevision( modifiedCalendar );
2801 remote->insertAddressee( inR, false ); 2801 remote->insertAddressee( inR, false );
2802 inL = inR; 2802 inL = inR;
2803 inL.setResource( 0 ); 2803 inL.setResource( 0 );
2804 local->insertAddressee( inL , false); 2804 local->insertAddressee( inL , false);
2805 ++addedAddressee; 2805 ++addedAddressee;
2806 } 2806 }
2807 } else { 2807 } else {
2808 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2808 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2809 inR.setRevision( modifiedCalendar ); 2809 inR.setRevision( modifiedCalendar );
2810 remote->insertAddressee( inR, false ); 2810 remote->insertAddressee( inR, false );
2811 inR.setResource( 0 ); 2811 inR.setResource( 0 );
2812 local->insertAddressee( inR, false ); 2812 local->insertAddressee( inR, false );
2813 ++addedAddressee; 2813 ++addedAddressee;
2814 } else { 2814 } else {
2815 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2815 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2816 remote->removeAddressee( inR ); 2816 remote->removeAddressee( inR );
2817 ++deletedAddresseeR; 2817 ++deletedAddresseeR;
2818 } 2818 }
2819 } 2819 }
2820 } 2820 }
2821 } 2821 }
2822 ++incCounter; 2822 ++incCounter;
2823 } 2823 }
2824 er.clear(); 2824 er.clear();
2825 QStringList el = local->uidList(); 2825 QStringList el = local->uidList();
2826 modulo = (el.count()/10)+1; 2826 modulo = (el.count()/10)+1;
2827 bar.setCaption (i18n("Add / remove addressees") ); 2827 bar.setCaption (i18n("Add / remove addressees") );
2828 bar.setTotalSteps ( el.count() ) ; 2828 bar.setTotalSteps ( el.count() ) ;
2829 bar.show(); 2829 bar.show();
2830 incCounter = 0; 2830 incCounter = 0;
2831 while ( incCounter < el.count()) { 2831 while ( incCounter < el.count()) {
2832 qApp->processEvents(); 2832 qApp->processEvents();
2833 if ( ! bar.isVisible() ) 2833 if ( ! bar.isVisible() )
2834 return false; 2834 return false;
2835 if ( incCounter % modulo == 0 ) 2835 if ( incCounter % modulo == 0 )
2836 bar.setProgress( incCounter ); 2836 bar.setProgress( incCounter );
2837 uid = el[ incCounter ]; 2837 uid = el[ incCounter ];
2838 bool skipIncidence = false; 2838 bool skipIncidence = false;
2839 if ( uid.left(19) == QString("last-syncAddressee-") ) 2839 if ( uid.left(19) == QString("last-syncAddressee-") )
2840 skipIncidence = true; 2840 skipIncidence = true;
2841 if ( !skipIncidence ) { 2841 if ( !skipIncidence ) {
2842 inL = local->findByUid( uid ); 2842 inL = local->findByUid( uid );
2843 inR = remote->findByUid( uid ); 2843 inR = remote->findByUid( uid );
2844 if ( inR.isEmpty() ) { 2844 if ( inR.isEmpty() ) {
2845 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2845 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2846 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2846 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2847 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2847 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2848 local->removeAddressee( inL ); 2848 local->removeAddressee( inL );
2849 ++deletedAddresseeL; 2849 ++deletedAddresseeL;
2850 } else { 2850 } else {
2851 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2851 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2852 inL.removeID(mCurrentSyncDevice ); 2852 inL.removeID(mCurrentSyncDevice );
2853 ++addedAddresseeR; 2853 ++addedAddresseeR;
2854 inL.setRevision( modifiedCalendar ); 2854 inL.setRevision( modifiedCalendar );
2855 local->insertAddressee( inL, false ); 2855 local->insertAddressee( inL, false );
2856 inR = inL; 2856 inR = inL;
2857 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2857 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2858 inR.setResource( 0 ); 2858 inR.setResource( 0 );
2859 remote->insertAddressee( inR, false ); 2859 remote->insertAddressee( inR, false );
2860 } 2860 }
2861 } 2861 }
2862 } else { 2862 } else {
2863 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2863 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2864 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2864 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2865 local->removeAddressee( inL ); 2865 local->removeAddressee( inL );
2866 ++deletedAddresseeL; 2866 ++deletedAddresseeL;
2867 } else { 2867 } else {
2868 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2868 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2869 ++addedAddresseeR; 2869 ++addedAddresseeR;
2870 inL.setRevision( modifiedCalendar ); 2870 inL.setRevision( modifiedCalendar );
2871 local->insertAddressee( inL, false ); 2871 local->insertAddressee( inL, false );
2872 inR = inL; 2872 inR = inL;
2873 inR.setResource( 0 ); 2873 inR.setResource( 0 );
2874 remote->insertAddressee( inR, false ); 2874 remote->insertAddressee( inR, false );
2875 } 2875 }
2876 } 2876 }
2877 } 2877 }
2878 } 2878 }
2879 } 2879 }
2880 ++incCounter; 2880 ++incCounter;
2881 } 2881 }
2882 el.clear(); 2882 el.clear();
2883 bar.hide(); 2883 bar.hide();
2884 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2884 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2885 // get rid of micro seconds 2885 // get rid of micro seconds
2886 QTime t = mLastAddressbookSync.time(); 2886 QTime t = mLastAddressbookSync.time();
2887 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2887 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2888 addresseeLSync.setRevision( mLastAddressbookSync ); 2888 addresseeLSync.setRevision( mLastAddressbookSync );
2889 addresseeRSync.setRevision( mLastAddressbookSync ); 2889 addresseeRSync.setRevision( mLastAddressbookSync );
2890 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2890 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2891 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2891 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2892 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2892 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2893 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2893 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2894 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2894 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2895 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2895 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2896 addresseeRSync.setNote( "" ) ; 2896 addresseeRSync.setNote( "" ) ;
2897 addresseeLSync.setNote( "" ); 2897 addresseeLSync.setNote( "" );
2898 2898
2899 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2899 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2900 remote->insertAddressee( addresseeRSync, false ); 2900 remote->insertAddressee( addresseeRSync, false );
2901 local->insertAddressee( addresseeLSync, false ); 2901 local->insertAddressee( addresseeLSync, false );
2902 QString mes; 2902 QString mes;
2903 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2903 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2904 if ( KABPrefs::instance()->mShowSyncSummary ) { 2904 if ( KABPrefs::instance()->mShowSyncSummary ) {
2905 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2905 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2906 } 2906 }
2907 qDebug( mes ); 2907 qDebug( mes );
2908 return syncOK; 2908 return syncOK;
2909} 2909}
2910 2910
2911bool KABCore::syncAB(QString filename, int mode) 2911bool KABCore::syncAB(QString filename, int mode)
2912{ 2912{
2913 2913
2914 //pending prepare addresseeview for output 2914 //pending prepare addresseeview for output
2915 //pending detect, if remote file has REV field. if not switch to external sync 2915 //pending detect, if remote file has REV field. if not switch to external sync
2916 mGlobalSyncMode = SYNC_MODE_NORMAL; 2916 mGlobalSyncMode = SYNC_MODE_NORMAL;
2917 AddressBook abLocal(filename,"syncContact"); 2917 AddressBook abLocal(filename,"syncContact");
2918 bool syncOK = false; 2918 bool syncOK = false;
2919 if ( abLocal.load() ) { 2919 if ( abLocal.load() ) {
2920 qDebug("AB loaded %s mode %d",filename.latin1(), mode ); 2920 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2921 bool external = false; 2921 bool external = false;
2922 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2922 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2923 if ( ! lse.isEmpty() ) { 2923 if ( ! lse.isEmpty() ) {
2924 if ( lse.familyName().left(4) == "!E: " ) 2924 if ( lse.familyName().left(4) == "!E: " )
2925 external = true; 2925 external = true;
2926 } else { 2926 } else {
2927 bool found = false; 2927 bool found = false;
2928 QDateTime dt( QDate( 2004,1,1)); 2928 QDateTime dt( QDate( 2004,1,1));
2929 AddressBook::Iterator it; 2929 AddressBook::Iterator it;
2930 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2930 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2931 if ( (*it).revision() != dt ) { 2931 if ( (*it).revision() != dt ) {
2932 found = true; 2932 found = true;
2933 break; 2933 break;
2934 } 2934 }
2935 } 2935 }
2936 external = ! found; 2936 external = ! found;
2937 } 2937 }
2938 2938
2939 if ( external ) { 2939 if ( external ) {
2940 qDebug("**********Setting vcf mode to external "); 2940 qDebug("Setting vcf mode to external ");
2941 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2941 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2942 AddressBook::Iterator it; 2942 AddressBook::Iterator it;
2943 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2943 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2944 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2944 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2945 (*it).computeCsum( mCurrentSyncDevice ); 2945 (*it).computeCsum( mCurrentSyncDevice );
2946 } 2946 }
2947 } 2947 }
2948 //AddressBook::Iterator it; 2948 //AddressBook::Iterator it;
2949 //QStringList vcards; 2949 //QStringList vcards;
2950 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2950 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2951 // qDebug("Name %s ", (*it).familyName().latin1()); 2951 // qDebug("Name %s ", (*it).familyName().latin1());
2952 //} 2952 //}
2953 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2953 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2954 if ( syncOK ) { 2954 if ( syncOK ) {
2955 if ( KABPrefs::instance()->mWriteBackFile ) 2955 if ( KABPrefs::instance()->mWriteBackFile )
2956 { 2956 {
2957 if ( external ) 2957 if ( external )
2958 abLocal.removeDeletedAddressees(); 2958 abLocal.removeDeletedAddressees();
2959 qDebug("saving remote AB "); 2959 qDebug("Saving remote AB ");
2960 abLocal.saveAB(); 2960 abLocal.saveAB();
2961 } 2961 }
2962 } 2962 }
2963 setModified(); 2963 setModified();
2964 2964
2965 } 2965 }
2966 if ( syncOK ) 2966 if ( syncOK )
2967 mViewManager->refreshView(); 2967 mViewManager->refreshView();
2968 return syncOK; 2968 return syncOK;
2969#if 0 2969#if 0
2970 2970
2971 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2971 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2972 getEventViewerDialog()->setSyncMode( true ); 2972 getEventViewerDialog()->setSyncMode( true );
2973 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 2973 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2974 getEventViewerDialog()->setSyncMode( false ); 2974 getEventViewerDialog()->setSyncMode( false );
2975 if ( syncOK ) { 2975 if ( syncOK ) {
2976 if ( KOPrefs::instance()->mWriteBackFile ) 2976 if ( KOPrefs::instance()->mWriteBackFile )
2977 { 2977 {
2978 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2978 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2979 storage->save(); 2979 storage->save();
2980 } 2980 }
2981 } 2981 }
2982 setModified(); 2982 setModified();
2983 } 2983 }
2984 2984
2985#endif 2985#endif
2986} 2986}
2987 2987
2988void KABCore::confSync() 2988void KABCore::confSync()
2989{ 2989{
2990 static KSyncPrefsDialog* sp = 0; 2990 static KSyncPrefsDialog* sp = 0;
2991 if ( ! sp ) { 2991 if ( ! sp ) {
2992 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 2992 sp = new KSyncPrefsDialog( this, "syncprefs", true );
2993 } 2993 }
2994 sp->usrReadConfig(); 2994 sp->usrReadConfig();
2995#ifndef DESKTOP_VERSION 2995#ifndef DESKTOP_VERSION
2996 sp->showMaximized(); 2996 sp->showMaximized();
2997#else 2997#else
2998 sp->show(); 2998 sp->show();
2999#endif 2999#endif
3000 sp->exec(); 3000 sp->exec();
3001 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 3001 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
3002 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 3002 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
3003 fillSyncMenu(); 3003 fillSyncMenu();
3004} 3004}
3005void KABCore::syncSharp() 3005void KABCore::syncSharp()
3006{ 3006{
3007 if ( mModified ) 3007 if ( mModified )
3008 save(); 3008 save();
3009 qDebug("pending syncSharp() "); 3009 qDebug("pending syncSharp() ");
3010 //mView->syncSharp(); 3010 //mView->syncSharp();
3011 setModified(); 3011 setModified();
3012 3012
3013} 3013}
3014void KABCore::syncPhone() 3014void KABCore::syncPhone()
3015{ 3015{
3016 if ( mModified ) 3016 if ( mModified )
3017 save(); 3017 save();
3018 qDebug("pending syncPhone(); "); 3018 qDebug("pending syncPhone(); ");
3019 //mView->syncPhone(); 3019 //mView->syncPhone();
3020 setModified(); 3020 setModified();
3021 3021
3022} 3022}