-rw-r--r-- | kaddressbook/kabcore.cpp | 95 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 5 |
2 files changed, 86 insertions, 14 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 49c3b19..e912941 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -148,6 +148,7 @@ $Id$ | |||
148 | #endif | 148 | #endif |
149 | // sync includes | 149 | // sync includes |
150 | #include <libkdepim/ksyncprofile.h> | 150 | #include <libkdepim/ksyncprofile.h> |
151 | #include <libkdepim/ksyncprefsdialog.h> | ||
151 | 152 | ||
152 | 153 | ||
153 | bool pasteWithNewUid = true; | 154 | bool pasteWithNewUid = true; |
@@ -179,6 +180,8 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const | |||
179 | connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), | 180 | connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), |
180 | SLOT( addressBookChanged() ) ); | 181 | SLOT( addressBookChanged() ) ); |
181 | 182 | ||
183 | #if 0 | ||
184 | // LP moved to addressbook init method | ||
182 | mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, | 185 | mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, |
183 | "X-Department", "KADDRESSBOOK" ); | 186 | "X-Department", "KADDRESSBOOK" ); |
184 | mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 187 | mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
@@ -204,7 +207,7 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const | |||
204 | "X-Children", "KADDRESSBOOK" ); | 207 | "X-Children", "KADDRESSBOOK" ); |
205 | mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 208 | mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
206 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 209 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
207 | 210 | #endif | |
208 | initGUI(); | 211 | initGUI(); |
209 | 212 | ||
210 | mIncSearchWidget->setFocus(); | 213 | mIncSearchWidget->setFocus(); |
@@ -2195,8 +2198,8 @@ void KABCore::slotSyncMenu( int action ) | |||
2195 | 2198 | ||
2196 | } else if ( action >= 1003 ) { | 2199 | } else if ( action >= 1003 ) { |
2197 | if ( temp->getIsLocalFileSync() ) { | 2200 | if ( temp->getIsLocalFileSync() ) { |
2198 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 2201 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
2199 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); | 2202 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
2200 | } else { | 2203 | } else { |
2201 | if ( temp->getIsPhoneSync() ) { | 2204 | if ( temp->getIsPhoneSync() ) { |
2202 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | 2205 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; |
@@ -2317,7 +2320,7 @@ int KABCore::ringSync() | |||
2317 | mCurrentSyncProfile = i; | 2320 | mCurrentSyncProfile = i; |
2318 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 2321 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
2319 | temp->readConfig(&config); | 2322 | temp->readConfig(&config); |
2320 | if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) { | 2323 | if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { |
2321 | setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 2324 | setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
2322 | ++syncedProfiles; | 2325 | ++syncedProfiles; |
2323 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 2326 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
@@ -2333,8 +2336,8 @@ int KABCore::ringSync() | |||
2333 | syncSharp(); | 2336 | syncSharp(); |
2334 | } else { | 2337 | } else { |
2335 | if ( temp->getIsLocalFileSync() ) { | 2338 | if ( temp->getIsLocalFileSync() ) { |
2336 | if ( syncWithFile( temp->getRemoteFileName( ), true ) ) | 2339 | if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) |
2337 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); | 2340 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
2338 | } else { | 2341 | } else { |
2339 | if ( temp->getIsPhoneSync() ) { | 2342 | if ( temp->getIsPhoneSync() ) { |
2340 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | 2343 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; |
@@ -2373,7 +2376,7 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) | |||
2373 | 0, 0 ) != 0 ) | 2376 | 0, 0 ) != 0 ) |
2374 | return; | 2377 | return; |
2375 | } | 2378 | } |
2376 | QString command = prof->getPreSyncCommand(); | 2379 | QString command = prof->getPreSyncCommandAB(); |
2377 | int fi; | 2380 | int fi; |
2378 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2381 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2379 | QString pwd = getPassword(); | 2382 | QString pwd = getPassword(); |
@@ -2405,13 +2408,13 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) | |||
2405 | } | 2408 | } |
2406 | setCaption ( i18n( "Copying succeed." ) ); | 2409 | setCaption ( i18n( "Copying succeed." ) ); |
2407 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 2410 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
2408 | if ( syncWithFile( prof->getLocalTempFile(), true ) ) { | 2411 | if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { |
2409 | // Event* e = mView->getLastSyncEvent(); | 2412 | // Event* e = mView->getLastSyncEvent(); |
2410 | // e->setReadOnly( false ); | 2413 | // e->setReadOnly( false ); |
2411 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2414 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2412 | // e->setReadOnly( true ); | 2415 | // e->setReadOnly( true ); |
2413 | if ( KABPrefs::instance()->mWriteBackFile ) { | 2416 | if ( KABPrefs::instance()->mWriteBackFile ) { |
2414 | command = prof->getPostSyncCommand(); | 2417 | command = prof->getPostSyncCommandAB(); |
2415 | int fi; | 2418 | int fi; |
2416 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2419 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2417 | QString pwd = getPassword(); | 2420 | QString pwd = getPassword(); |
@@ -2510,17 +2513,83 @@ QString KABCore::getPassword( ) | |||
2510 | return retfile; | 2513 | return retfile; |
2511 | 2514 | ||
2512 | } | 2515 | } |
2516 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | ||
2517 | { | ||
2513 | 2518 | ||
2519 | } | ||
2514 | bool KABCore::syncAB(QString filename, int mode) | 2520 | bool KABCore::syncAB(QString filename, int mode) |
2515 | { | 2521 | { |
2516 | 2522 | ||
2523 | |||
2524 | |||
2525 | mGlobalSyncMode = SYNC_MODE_NORMAL; | ||
2526 | AddressBook abLocal(filename,"syncContact"); | ||
2527 | bool syncOK = false; | ||
2528 | if ( abLocal.load() ) { | ||
2529 | qDebug("AB loaded %s mode %d",filename.latin1(), mode ); | ||
2530 | AddressBook::Iterator it; | ||
2531 | QStringList vcards; | ||
2532 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | ||
2533 | qDebug("Name %s ", (*it).familyName().latin1()); | ||
2534 | } | ||
2535 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | ||
2536 | if ( syncOK ) { | ||
2537 | if ( KABPrefs::instance()->mWriteBackFile ) | ||
2538 | { | ||
2539 | abLocal.saveAB(); | ||
2540 | } | ||
2541 | } | ||
2542 | setModified(); | ||
2543 | |||
2544 | } | ||
2545 | if ( syncOK ) | ||
2546 | ;//updateView(); | ||
2547 | return syncOK; | ||
2548 | #if 0 | ||
2549 | mGlobalSyncMode = SYNC_MODE_NORMAL; | ||
2550 | CalendarLocal* calendar = new CalendarLocal(); | ||
2551 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | ||
2552 | FileStorage* storage = new FileStorage( calendar ); | ||
2553 | bool syncOK = false; | ||
2554 | storage->setFileName( filename ); | ||
2555 | // qDebug("loading ... "); | ||
2556 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | ||
2557 | getEventViewerDialog()->setSyncMode( true ); | ||
2558 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | ||
2559 | getEventViewerDialog()->setSyncMode( false ); | ||
2560 | if ( syncOK ) { | ||
2561 | if ( KOPrefs::instance()->mWriteBackFile ) | ||
2562 | { | ||
2563 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | ||
2564 | storage->save(); | ||
2565 | } | ||
2566 | } | ||
2567 | setModified(); | ||
2568 | } | ||
2569 | delete storage; | ||
2570 | delete calendar; | ||
2571 | if ( syncOK ) | ||
2572 | updateView(); | ||
2573 | return syncOK; | ||
2574 | #endif | ||
2517 | } | 2575 | } |
2518 | 2576 | ||
2519 | 2577 | ||
2520 | void KABCore::confSync() | 2578 | void KABCore::confSync() |
2521 | { | 2579 | { |
2522 | //mView->confSync(); | 2580 | static KSyncPrefsDialog* sp = 0; |
2523 | qDebug("pending KABCore::confSync() "); | 2581 | if ( ! sp ) { |
2582 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | ||
2583 | } | ||
2584 | sp->usrReadConfig(); | ||
2585 | #ifndef DESKTOP_VERSION | ||
2586 | sp->showMaximized(); | ||
2587 | #else | ||
2588 | sp->show(); | ||
2589 | #endif | ||
2590 | sp->exec(); | ||
2591 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | ||
2592 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | ||
2524 | fillSyncMenu(); | 2593 | fillSyncMenu(); |
2525 | } | 2594 | } |
2526 | void KABCore::syncSharp() | 2595 | void KABCore::syncSharp() |
@@ -2529,7 +2598,7 @@ void KABCore::syncSharp() | |||
2529 | save(); | 2598 | save(); |
2530 | qDebug("pending syncSharp() "); | 2599 | qDebug("pending syncSharp() "); |
2531 | //mView->syncSharp(); | 2600 | //mView->syncSharp(); |
2532 | mModified = true ; | 2601 | setModified(); |
2533 | 2602 | ||
2534 | } | 2603 | } |
2535 | void KABCore::syncPhone() | 2604 | void KABCore::syncPhone() |
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 10ce8f4..4487a8a 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h | |||
@@ -456,7 +456,6 @@ class KABCore : public QWidget | |||
456 | // sync stuff! | 456 | // sync stuff! |
457 | QPopupMenu *syncMenu; | 457 | QPopupMenu *syncMenu; |
458 | void fillSyncMenu(); | 458 | void fillSyncMenu(); |
459 | void confSync(); | ||
460 | QString mCurrentSyncDevice; | 459 | QString mCurrentSyncDevice; |
461 | QString mCurrentSyncName; | 460 | QString mCurrentSyncName; |
462 | void quickSyncLocalFile(); | 461 | void quickSyncLocalFile(); |
@@ -471,6 +470,10 @@ class KABCore : public QWidget | |||
471 | bool syncAB(QString filename, int mode); | 470 | bool syncAB(QString filename, int mode); |
472 | int ringSync(); | 471 | int ringSync(); |
473 | QString getPassword( ); | 472 | QString getPassword( ); |
473 | int mGlobalSyncMode; | ||
474 | bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); | ||
475 | public slots: | ||
476 | void confSync(); | ||
474 | // ********************* | 477 | // ********************* |
475 | 478 | ||
476 | }; | 479 | }; |