summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kabcore.cpp
Unidiff
Diffstat (limited to 'kaddressbook/kabcore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index e61f65f..aa04631 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -218,97 +218,97 @@ class KABFormatPrefs : public QDialog
218 company = new QRadioButton(i18n("Organization: MI6"), format ); 218 company = new QRadioButton(i18n("Organization: MI6"), format );
219 simple->setChecked( true ); 219 simple->setChecked( true );
220 setCompany = new QCheckBox(i18n("Set formatted name to\norganization, if name empty"), this); 220 setCompany = new QCheckBox(i18n("Set formatted name to\norganization, if name empty"), this);
221 lay->addWidget( setCompany ); 221 lay->addWidget( setCompany );
222 QPushButton * ok = new QPushButton( i18n("Select contact list"), this ); 222 QPushButton * ok = new QPushButton( i18n("Select contact list"), this );
223 lay->addWidget( ok ); 223 lay->addWidget( ok );
224 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 224 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
225 lay->addWidget( cancel ); 225 lay->addWidget( cancel );
226 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 226 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
227 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 227 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
228 resize( 200, 200 ); 228 resize( 200, 200 );
229 } 229 }
230public: 230public:
231 QRadioButton* simple, *full, *reverse, *company; 231 QRadioButton* simple, *full, *reverse, *company;
232 QCheckBox* setCompany; 232 QCheckBox* setCompany;
233}; 233};
234 234
235 235
236 236
237class KAex2phonePrefs : public QDialog 237class KAex2phonePrefs : public QDialog
238{ 238{
239 public: 239 public:
240 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : 240 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
241 QDialog( parent, name, true ) 241 QDialog( parent, name, true )
242 { 242 {
243 setCaption( i18n("Export to phone options") ); 243 setCaption( i18n("Export to phone options") );
244 QVBoxLayout* lay = new QVBoxLayout( this ); 244 QVBoxLayout* lay = new QVBoxLayout( this );
245 lay->setSpacing( 3 ); 245 lay->setSpacing( 3 );
246 lay->setMargin( 3 ); 246 lay->setMargin( 3 );
247 QLabel *lab; 247 QLabel *lab;
248 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); 248 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
249 lab->setAlignment (AlignHCenter ); 249 lab->setAlignment (AlignHCenter );
250 QHBox* temphb; 250 QHBox* temphb;
251 temphb = new QHBox( this ); 251 temphb = new QHBox( this );
252 new QLabel( i18n("I/O device: "), temphb ); 252 new QLabel( i18n("I/O device: "), temphb );
253 mPhoneDevice = new QLineEdit( temphb); 253 mPhoneDevice = new QLineEdit( temphb);
254 lay->addWidget( temphb ); 254 lay->addWidget( temphb );
255 temphb = new QHBox( this ); 255 temphb = new QHBox( this );
256 new QLabel( i18n("Connection: "), temphb ); 256 new QLabel( i18n("Connection: "), temphb );
257 mPhoneConnection = new QLineEdit( temphb); 257 mPhoneConnection = new QLineEdit( temphb);
258 lay->addWidget( temphb ); 258 lay->addWidget( temphb );
259 temphb = new QHBox( this ); 259 temphb = new QHBox( this );
260 new QLabel( i18n("Model(opt.): "), temphb ); 260 new QLabel( i18n("Model(opt.): "), temphb );
261 mPhoneModel = new QLineEdit( temphb); 261 mPhoneModel = new QLineEdit( temphb);
262 lay->addWidget( temphb ); 262 lay->addWidget( temphb );
263 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); 263 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
264 // lay->addWidget( mWriteToSim ); 264 // lay->addWidget( mWriteToSim );
265 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); 265 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) );
266 lab->setAlignment (AlignHCenter ); 266 lab->setAlignment (AlignHCenter);
267 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); 267 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
268 lay->addWidget( ok ); 268 lay->addWidget( ok );
269 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 269 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
270 lay->addWidget( cancel ); 270 lay->addWidget( cancel );
271 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 271 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
272 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 272 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
273 resize( 220, 240 ); 273 resize( 220, 240 );
274 274
275 } 275 }
276 276
277public: 277public:
278 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; 278 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
279 QCheckBox* mWriteToSim; 279 QCheckBox* mWriteToSim;
280}; 280};
281 281
282 282
283bool pasteWithNewUid = true; 283bool pasteWithNewUid = true;
284 284
285#ifdef KAB_EMBEDDED 285#ifdef KAB_EMBEDDED
286KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 286KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
287 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 287 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
288 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 288 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
289 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 289 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
290#else //KAB_EMBEDDED 290#else //KAB_EMBEDDED
291KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 291KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
292 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 292 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
293 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 293 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
294 mReadWrite( readWrite ), mModified( false ) 294 mReadWrite( readWrite ), mModified( false )
295#endif //KAB_EMBEDDED 295#endif //KAB_EMBEDDED
296{ 296{
297 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 297 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
298 // syncManager->setBlockSave(false); 298 // syncManager->setBlockSave(false);
299 mMiniSplitter = 0; 299 mMiniSplitter = 0;
300 mExtensionBarSplitter = 0; 300 mExtensionBarSplitter = 0;
301 mIsPart = !parent->inherits( "KAddressBookMain" ); 301 mIsPart = !parent->inherits( "KAddressBookMain" );
302 mAddressBook = KABC::StdAddressBook::self(); 302 mAddressBook = KABC::StdAddressBook::self();
303 KABC::StdAddressBook::setAutomaticSave( false ); 303 KABC::StdAddressBook::setAutomaticSave( false );
304 304
305#ifndef KAB_EMBEDDED 305#ifndef KAB_EMBEDDED
306 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 306 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
307#endif //KAB_EMBEDDED 307#endif //KAB_EMBEDDED
308 308
309 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 309 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
310 SLOT( addressBookChanged() ) ); 310 SLOT( addressBookChanged() ) );
311 311
312#if 0 312#if 0
313 // LP moved to addressbook init method 313 // LP moved to addressbook init method
314 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, 314 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
@@ -520,96 +520,98 @@ void KABCore::restoreSettings()
520*/ 520*/
521 mViewManager->restoreSettings(); 521 mViewManager->restoreSettings();
522 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 522 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
523 mExtensionManager->restoreSettings(); 523 mExtensionManager->restoreSettings();
524#ifdef DESKTOP_VERSION 524#ifdef DESKTOP_VERSION
525 int wid = width(); 525 int wid = width();
526 if ( wid < 10 ) 526 if ( wid < 10 )
527 wid = 400; 527 wid = 400;
528#else 528#else
529 int wid = QApplication::desktop()->width(); 529 int wid = QApplication::desktop()->width();
530 if ( wid < 640 ) 530 if ( wid < 640 )
531 wid = QApplication::desktop()->height(); 531 wid = QApplication::desktop()->height();
532#endif 532#endif
533 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 533 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
534 if ( true /*splitterSize.count() == 0*/ ) { 534 if ( true /*splitterSize.count() == 0*/ ) {
535 splitterSize.append( wid / 2 ); 535 splitterSize.append( wid / 2 );
536 splitterSize.append( wid / 2 ); 536 splitterSize.append( wid / 2 );
537 } 537 }
538 mMiniSplitter->setSizes( splitterSize ); 538 mMiniSplitter->setSizes( splitterSize );
539 if ( mExtensionBarSplitter ) { 539 if ( mExtensionBarSplitter ) {
540 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 540 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
541 if ( true /*splitterSize.count() == 0*/ ) { 541 if ( true /*splitterSize.count() == 0*/ ) {
542 splitterSize.append( wid / 2 ); 542 splitterSize.append( wid / 2 );
543 splitterSize.append( wid / 2 ); 543 splitterSize.append( wid / 2 );
544 } 544 }
545 mExtensionBarSplitter->setSizes( splitterSize ); 545 mExtensionBarSplitter->setSizes( splitterSize );
546 546
547 } 547 }
548 548
549 549
550} 550}
551 551
552void KABCore::saveSettings() 552void KABCore::saveSettings()
553{ 553{
554 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 554 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
555 if ( mExtensionBarSplitter ) 555 if ( mExtensionBarSplitter )
556 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 556 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
557 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 557 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
558 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 558 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
559#ifndef KAB_EMBEDDED 559#ifndef KAB_EMBEDDED
560 560
561 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 561 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
562 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 562 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
563#endif //KAB_EMBEDDED 563#endif //KAB_EMBEDDED
564 mExtensionManager->saveSettings(); 564 mExtensionManager->saveSettings();
565 mViewManager->saveSettings(); 565 mViewManager->saveSettings();
566 566
567 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 567 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
568 KABPrefs::instance()->writeConfig();
569 qDebug("KABPrefs::instance()->writeConfig() ");
568} 570}
569 571
570KABC::AddressBook *KABCore::addressBook() const 572KABC::AddressBook *KABCore::addressBook() const
571{ 573{
572 return mAddressBook; 574 return mAddressBook;
573} 575}
574 576
575KConfig *KABCore::config() 577KConfig *KABCore::config()
576{ 578{
577#ifndef KAB_EMBEDDED 579#ifndef KAB_EMBEDDED
578 return KABPrefs::instance()->config(); 580 return KABPrefs::instance()->config();
579#else //KAB_EMBEDDED 581#else //KAB_EMBEDDED
580 return KABPrefs::instance()->getConfig(); 582 return KABPrefs::instance()->getConfig();
581#endif //KAB_EMBEDDED 583#endif //KAB_EMBEDDED
582} 584}
583 585
584KActionCollection *KABCore::actionCollection() const 586KActionCollection *KABCore::actionCollection() const
585{ 587{
586 return mGUIClient->actionCollection(); 588 return mGUIClient->actionCollection();
587} 589}
588 590
589KABC::Field *KABCore::currentSearchField() const 591KABC::Field *KABCore::currentSearchField() const
590{ 592{
591 if (mIncSearchWidget) 593 if (mIncSearchWidget)
592 return mIncSearchWidget->currentField(); 594 return mIncSearchWidget->currentField();
593 else 595 else
594 return 0; 596 return 0;
595} 597}
596 598
597QStringList KABCore::selectedUIDs() const 599QStringList KABCore::selectedUIDs() const
598{ 600{
599 return mViewManager->selectedUids(); 601 return mViewManager->selectedUids();
600} 602}
601 603
602KABC::Resource *KABCore::requestResource( QWidget *parent ) 604KABC::Resource *KABCore::requestResource( QWidget *parent )
603{ 605{
604 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 606 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
605 607
606 QPtrList<KRES::Resource> kresResources; 608 QPtrList<KRES::Resource> kresResources;
607 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 609 QPtrListIterator<KABC::Resource> resIt( kabcResources );
608 KABC::Resource *resource; 610 KABC::Resource *resource;
609 while ( ( resource = resIt.current() ) != 0 ) { 611 while ( ( resource = resIt.current() ) != 0 ) {
610 ++resIt; 612 ++resIt;
611 if ( !resource->readOnly() ) { 613 if ( !resource->readOnly() ) {
612 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 614 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
613 if ( res ) 615 if ( res )
614 kresResources.append( res ); 616 kresResources.append( res );
615 } 617 }
@@ -2640,175 +2642,177 @@ void KABCore::faq()
2640} 2642}
2641 2643
2642#include <libkcal/syncdefines.h> 2644#include <libkcal/syncdefines.h>
2643 2645
2644KABC::Addressee KABCore::getLastSyncAddressee() 2646KABC::Addressee KABCore::getLastSyncAddressee()
2645{ 2647{
2646 Addressee lse; 2648 Addressee lse;
2647 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2649 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2648 2650
2649 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2651 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2650 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2652 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2651 if (lse.isEmpty()) { 2653 if (lse.isEmpty()) {
2652 qDebug("Creating new last-syncAddressee "); 2654 qDebug("Creating new last-syncAddressee ");
2653 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2655 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2654 QString sum = ""; 2656 QString sum = "";
2655 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2657 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2656 sum = "E: "; 2658 sum = "E: ";
2657 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2659 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2658 lse.setRevision( mLastAddressbookSync ); 2660 lse.setRevision( mLastAddressbookSync );
2659 lse.setCategories( i18n("SyncEvent") ); 2661 lse.setCategories( i18n("SyncEvent") );
2660 mAddressBook->insertAddressee( lse ); 2662 mAddressBook->insertAddressee( lse );
2661 } 2663 }
2662 return lse; 2664 return lse;
2663} 2665}
2664int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2666int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2665{ 2667{
2666 2668
2667 //void setZaurusId(int id); 2669 //void setZaurusId(int id);
2668 // int zaurusId() const; 2670 // int zaurusId() const;
2669 // void setZaurusUid(int id); 2671 // void setZaurusUid(int id);
2670 // int zaurusUid() const; 2672 // int zaurusUid() const;
2671 // void setZaurusStat(int id); 2673 // void setZaurusStat(int id);
2672 // int zaurusStat() const; 2674 // int zaurusStat() const;
2673 // 0 equal 2675 // 0 equal
2674 // 1 take local 2676 // 1 take local
2675 // 2 take remote 2677 // 2 take remote
2676 // 3 cancel 2678 // 3 cancel
2677 QDateTime lastSync = mLastAddressbookSync; 2679 QDateTime lastSync = mLastAddressbookSync;
2678 QDateTime localMod = local->revision(); 2680 QDateTime localMod = local->revision();
2679 QDateTime remoteMod = remote->revision(); 2681 QDateTime remoteMod = remote->revision();
2680 2682
2681 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2683 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2682 2684
2683 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2685 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2684 bool remCh, locCh; 2686 bool remCh, locCh;
2685 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2687 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2686 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2688 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2687 locCh = ( localMod > mLastAddressbookSync ); 2689 locCh = ( localMod > mLastAddressbookSync );
2690 //qDebug("cahnged rem %d loc %d",remCh, locCh );
2688 if ( !remCh && ! locCh ) { 2691 if ( !remCh && ! locCh ) {
2689 //qDebug("both not changed "); 2692 //qDebug("both not changed ");
2690 lastSync = localMod.addDays(1); 2693 lastSync = localMod.addDays(1);
2691 if ( mode <= SYNC_PREF_ASK ) 2694 if ( mode <= SYNC_PREF_ASK )
2692 return 0; 2695 return 0;
2693 } else { 2696 } else {
2694 if ( locCh ) { 2697 if ( locCh ) {
2695 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2698 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2696 lastSync = localMod.addDays( -1 ); 2699 lastSync = localMod.addDays( -1 );
2697 if ( !remCh ) 2700 if ( !remCh )
2698 remoteMod =( lastSync.addDays( -1 ) ); 2701 remoteMod =( lastSync.addDays( -1 ) );
2699 } else { 2702 } else {
2700 //qDebug(" not loc changed "); 2703 //qDebug(" not loc changed ");
2701 lastSync = localMod.addDays( 1 ); 2704 lastSync = localMod.addDays( 1 );
2702 if ( remCh ) { 2705 if ( remCh ) {
2703 //qDebug("rem changed "); 2706 //qDebug("rem changed ");
2704 remoteMod =( lastSync.addDays( 1 ) ); 2707 remoteMod =( lastSync.addDays( 1 ) );
2705 } 2708 }
2706 2709
2707 } 2710 }
2708 } 2711 }
2709 full = true; 2712 full = true;
2710 if ( mode < SYNC_PREF_ASK ) 2713 if ( mode < SYNC_PREF_ASK )
2711 mode = SYNC_PREF_ASK; 2714 mode = SYNC_PREF_ASK;
2712 } else { 2715 } else {
2713 if ( localMod == remoteMod ) 2716 if ( localMod == remoteMod )
2714 return 0; 2717 return 0;
2715 2718
2716 } 2719 }
2717 //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); 2720 //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec());
2718 //qDebug("lastsync %s ", lastSync.toString().latin1() ); 2721 //qDebug("lastsync %s ", lastSync.toString().latin1() );
2719 //full = true; //debug only 2722 //full = true; //debug only
2720 if ( full ) { 2723 if ( full ) {
2721 bool equ = ( (*local) == (*remote) ); 2724 bool equ = ( (*local) == (*remote) );
2722 if ( equ ) { 2725 if ( equ ) {
2723 //qDebug("equal "); 2726 //qDebug("equal ");
2724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2727 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2725 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2728 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2726 } 2729 }
2727 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2730 if ( mode < SYNC_PREF_FORCE_LOCAL )
2728 return 0; 2731 return 0;
2729 2732
2730 }//else //debug only 2733 }//else //debug only
2731 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2734 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2732 } 2735 }
2733 int result; 2736 int result;
2734 bool localIsNew; 2737 bool localIsNew;
2735 //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() ); 2738 //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() );
2736 2739
2737 if ( full && mode < SYNC_PREF_NEWEST ) 2740 if ( full && mode < SYNC_PREF_NEWEST )
2738 mode = SYNC_PREF_ASK; 2741 mode = SYNC_PREF_ASK;
2739 2742
2740 switch( mode ) { 2743 switch( mode ) {
2741 case SYNC_PREF_LOCAL: 2744 case SYNC_PREF_LOCAL:
2742 if ( lastSync > remoteMod ) 2745 if ( lastSync > remoteMod )
2743 return 1; 2746 return 1;
2744 if ( lastSync > localMod ) 2747 if ( lastSync > localMod )
2745 return 2; 2748 return 2;
2746 return 1; 2749 return 1;
2747 break; 2750 break;
2748 case SYNC_PREF_REMOTE: 2751 case SYNC_PREF_REMOTE:
2749 if ( lastSync > remoteMod ) 2752 if ( lastSync > remoteMod )
2750 return 1; 2753 return 1;
2751 if ( lastSync > localMod ) 2754 if ( lastSync > localMod )
2752 return 2; 2755 return 2;
2753 return 2; 2756 return 2;
2754 break; 2757 break;
2755 case SYNC_PREF_NEWEST: 2758 case SYNC_PREF_NEWEST:
2756 if ( localMod > remoteMod ) 2759 if ( localMod > remoteMod )
2757 return 1; 2760 return 1;
2758 else 2761 else
2759 return 2; 2762 return 2;
2760 break; 2763 break;
2761 case SYNC_PREF_ASK: 2764 case SYNC_PREF_ASK:
2762 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2765 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2763 if ( lastSync > remoteMod ) 2766 if ( lastSync > remoteMod )
2764 return 1; 2767 return 1;
2765 if ( lastSync > localMod ) 2768 if ( lastSync > localMod ) {
2766 return 2; 2769 return 2;
2770 }
2767 localIsNew = localMod >= remoteMod; 2771 localIsNew = localMod >= remoteMod;
2768 //qDebug("conflict! ************************************** "); 2772 //qDebug("conflict! ************************************** ");
2769 { 2773 {
2770 KABC::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2774 KABC::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2771 result = acd.executeD(localIsNew); 2775 result = acd.executeD(localIsNew);
2772 return result; 2776 return result;
2773 } 2777 }
2774 break; 2778 break;
2775 case SYNC_PREF_FORCE_LOCAL: 2779 case SYNC_PREF_FORCE_LOCAL:
2776 return 1; 2780 return 1;
2777 break; 2781 break;
2778 case SYNC_PREF_FORCE_REMOTE: 2782 case SYNC_PREF_FORCE_REMOTE:
2779 return 2; 2783 return 2;
2780 break; 2784 break;
2781 2785
2782 default: 2786 default:
2783 // SYNC_PREF_TAKE_BOTH not implemented 2787 // SYNC_PREF_TAKE_BOTH not implemented
2784 break; 2788 break;
2785 } 2789 }
2786 return 0; 2790 return 0;
2787} 2791}
2788 2792
2789 2793
2790bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2794bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2791{ 2795{
2792 bool syncOK = true; 2796 bool syncOK = true;
2793 int addedAddressee = 0; 2797 int addedAddressee = 0;
2794 int addedAddresseeR = 0; 2798 int addedAddresseeR = 0;
2795 int deletedAddresseeR = 0; 2799 int deletedAddresseeR = 0;
2796 int deletedAddresseeL = 0; 2800 int deletedAddresseeL = 0;
2797 int changedLocal = 0; 2801 int changedLocal = 0;
2798 int changedRemote = 0; 2802 int changedRemote = 0;
2799 2803
2800 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2804 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2801 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2805 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2802 2806
2803 //QPtrList<Addressee> el = local->rawAddressees(); 2807 //QPtrList<Addressee> el = local->rawAddressees();
2804 Addressee addresseeR; 2808 Addressee addresseeR;
2805 QString uid; 2809 QString uid;
2806 int take; 2810 int take;
2807 Addressee addresseeL; 2811 Addressee addresseeL;
2808 Addressee addresseeRSync; 2812 Addressee addresseeRSync;
2809 Addressee addresseeLSync; 2813 Addressee addresseeLSync;
2810 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2814 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2811 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2815 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2812 bool fullDateRange = false; 2816 bool fullDateRange = false;
2813 local->resetTempSyncStat(); 2817 local->resetTempSyncStat();
2814 mLastAddressbookSync = QDateTime::currentDateTime(); 2818 mLastAddressbookSync = QDateTime::currentDateTime();
@@ -2961,100 +2965,102 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2961 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2965 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2962 remote->insertAddressee( inR, false ); 2966 remote->insertAddressee( inR, false );
2963 ++deletedAddresseeR; 2967 ++deletedAddresseeR;
2964 } else { 2968 } else {
2965 inR.setRevision( modifiedCalendar ); 2969 inR.setRevision( modifiedCalendar );
2966 remote->insertAddressee( inR, false ); 2970 remote->insertAddressee( inR, false );
2967 inL = inR; 2971 inL = inR;
2968 inL.setIDStr( ":" ); 2972 inL.setIDStr( ":" );
2969 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2973 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2970 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2974 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2971 inL.setResource( 0 ); 2975 inL.setResource( 0 );
2972 local->insertAddressee( inL , false); 2976 local->insertAddressee( inL , false);
2973 ++addedAddressee; 2977 ++addedAddressee;
2974 } 2978 }
2975 } else { 2979 } else {
2976 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2980 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2977 inR.setRevision( modifiedCalendar ); 2981 inR.setRevision( modifiedCalendar );
2978 remote->insertAddressee( inR, false ); 2982 remote->insertAddressee( inR, false );
2979 inR.setResource( 0 ); 2983 inR.setResource( 0 );
2980 local->insertAddressee( inR, false ); 2984 local->insertAddressee( inR, false );
2981 ++addedAddressee; 2985 ++addedAddressee;
2982 } else { 2986 } else {
2983 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2987 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2984 remote->removeAddressee( inR ); 2988 remote->removeAddressee( inR );
2985 ++deletedAddresseeR; 2989 ++deletedAddresseeR;
2986 } 2990 }
2987 } 2991 }
2988 } 2992 }
2989 } 2993 }
2990 } 2994 }
2991 ++incCounter; 2995 ++incCounter;
2992 } 2996 }
2993 er.clear(); 2997 er.clear();
2994 QStringList el = local->uidList(); 2998 QStringList el = local->uidList();
2995 modulo = (el.count()/10)+1; 2999 modulo = (el.count()/10)+1;
2996 3000
2997 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3001 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2998 incCounter = 0; 3002 incCounter = 0;
2999 while ( incCounter < el.count()) { 3003 while ( incCounter < el.count()) {
3000 qApp->processEvents(); 3004 qApp->processEvents();
3001 if (syncManager->isProgressBarCanceled()) 3005 if (syncManager->isProgressBarCanceled())
3002 return false; 3006 return false;
3003 if ( incCounter % modulo == 0 ) 3007 if ( incCounter % modulo == 0 )
3004 syncManager->showProgressBar(incCounter); 3008 syncManager->showProgressBar(incCounter);
3005 uid = el[ incCounter ]; 3009 uid = el[ incCounter ];
3006 bool skipIncidence = false; 3010 bool skipIncidence = false;
3007 if ( uid.left(19) == QString("last-syncAddressee-") ) 3011 if ( uid.left(19) == QString("last-syncAddressee-") )
3008 skipIncidence = true; 3012 skipIncidence = true;
3009 if ( !filterOUT.name().isEmpty() && ! filterOUT.filterAddressee( inL ) ) 3013 if ( ! skipIncidence ) {
3010 skipIncidence = true;
3011 if ( !skipIncidence ) {
3012 inL = local->findByUid( uid ); 3014 inL = local->findByUid( uid );
3015 if ( (!filterOUT.name().isEmpty()) && (! filterOUT.filterAddressee( inL ) ) )
3016 skipIncidence = true;
3017 }
3018 if ( !skipIncidence ) {
3013 if ( !inL.resource() || inL.resource()->includeInSync() ) { 3019 if ( !inL.resource() || inL.resource()->includeInSync() ) {
3014 inR = remote->findByUid( uid ); 3020 inR = remote->findByUid( uid );
3015 if ( inR.isEmpty() ) { // no conflict ********** add or delete local 3021 if ( inR.isEmpty() ) { // no conflict ********** add or delete local
3016 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 3022 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
3017 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 3023 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
3018 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3024 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3019 local->removeAddressee( inL ); 3025 local->removeAddressee( inL );
3020 ++deletedAddresseeL; 3026 ++deletedAddresseeL;
3021 } else { 3027 } else {
3022 if ( ! syncManager->mWriteBackExistingOnly ) { 3028 if ( ! syncManager->mWriteBackExistingOnly ) {
3023 inL.removeID(mCurrentSyncDevice ); 3029 inL.removeID(mCurrentSyncDevice );
3024 ++addedAddresseeR; 3030 ++addedAddresseeR;
3025 inL.setRevision( modifiedCalendar ); 3031 inL.setRevision( modifiedCalendar );
3026 local->insertAddressee( inL, false ); 3032 local->insertAddressee( inL, false );
3027 inR = inL; 3033 inR = inL;
3028 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 3034 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
3029 inR.setResource( 0 ); 3035 inR.setResource( 0 );
3030 remote->insertAddressee( inR, false ); 3036 remote->insertAddressee( inR, false );
3031 } 3037 }
3032 } 3038 }
3033 } else { 3039 } else {
3034 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 3040 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
3035 //qDebug("data %s ", inL.revision().toString().latin1()); 3041 //qDebug("data %s ", inL.revision().toString().latin1());
3036 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3042 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3037 local->removeAddressee( inL ); 3043 local->removeAddressee( inL );
3038 ++deletedAddresseeL; 3044 ++deletedAddresseeL;
3039 } else { 3045 } else {
3040 if ( ! syncManager->mWriteBackExistingOnly ) { 3046 if ( ! syncManager->mWriteBackExistingOnly ) {
3041 ++addedAddresseeR; 3047 ++addedAddresseeR;
3042 inL.setRevision( modifiedCalendar ); 3048 inL.setRevision( modifiedCalendar );
3043 local->insertAddressee( inL, false ); 3049 local->insertAddressee( inL, false );
3044 inR = inL; 3050 inR = inL;
3045 inR.setIDStr( ":" ); 3051 inR.setIDStr( ":" );
3046 inR.setResource( 0 ); 3052 inR.setResource( 0 );
3047 remote->insertAddressee( inR, false ); 3053 remote->insertAddressee( inR, false );
3048 } 3054 }
3049 } 3055 }
3050 } 3056 }
3051 } 3057 }
3052 } 3058 }
3053 } 3059 }
3054 ++incCounter; 3060 ++incCounter;
3055 } 3061 }
3056 el.clear(); 3062 el.clear();
3057 syncManager->hideProgressBar(); 3063 syncManager->hideProgressBar();
3058 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 3064 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
3059 // get rid of micro seconds 3065 // get rid of micro seconds
3060 QTime t = mLastAddressbookSync.time(); 3066 QTime t = mLastAddressbookSync.time();