author | zautrix <zautrix> | 2004-09-18 08:25:05 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-18 08:25:05 (UTC) |
commit | 983b010853dfadfec3638e2afd90e522985f67fb (patch) (unidiff) | |
tree | b691b7664b9f6f23d0d92a0e05bf3e8cbcf2df67 | |
parent | df03bd8c7ff6a738dd386001679542ae4b493a07 (diff) | |
download | kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.zip kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.gz kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.bz2 |
more AB syncing
-rw-r--r-- | kabc/addressbook.cpp | 101 | ||||
-rw-r--r-- | kabc/addressbook.h | 1 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 95 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 5 |
4 files changed, 186 insertions, 16 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 47d298a..70eda1b 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -236,3 +236,23 @@ void AddressBook::init(const QString &config, const QString &family ) | |||
236 | d = new AddressBookData; | 236 | d = new AddressBookData; |
237 | QString fami = family; | ||
238 | qDebug("new ab "); | ||
237 | if (config != 0) { | 239 | if (config != 0) { |
240 | qDebug("config != 0 "); | ||
241 | if ( family == "syncContact" ) { | ||
242 | qDebug("creating sync config "); | ||
243 | fami = "contact"; | ||
244 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | ||
245 | con->setGroup( "General" ); | ||
246 | con->writeEntry( "ResourceKeys", QString("sync") ); | ||
247 | con->writeEntry( "Standard", QString("sync") ); | ||
248 | con->setGroup( "Resource_sync" ); | ||
249 | con->writeEntry( "FileFormat", QString("vcard") ); | ||
250 | con->writeEntry( "FileName", config ); | ||
251 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | ||
252 | con->writeEntry( "ResourceName", QString("sync_res") ); | ||
253 | con->writeEntry( "ResourceType", QString("file") ); | ||
254 | //con->sync(); | ||
255 | d->mConfig = con; | ||
256 | } | ||
257 | else | ||
238 | d->mConfig = new KConfig( locateLocal("config", config) ); | 258 | d->mConfig = new KConfig( locateLocal("config", config) ); |
@@ -246,4 +266,53 @@ void AddressBook::init(const QString &config, const QString &family ) | |||
246 | //US d->mErrorHandler = 0; | 266 | //US d->mErrorHandler = 0; |
247 | d->mManager = new KRES::Manager<Resource>( family, false ); | 267 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
248 | d->mManager->readConfig( d->mConfig ); | 268 | d->mManager->readConfig( d->mConfig ); |
269 | if ( family == "syncContact" ) { | ||
270 | KRES::Manager<Resource> *manager = d->mManager; | ||
271 | KRES::Manager<Resource>::ActiveIterator it; | ||
272 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | ||
273 | (*it)->setAddressBook( this ); | ||
274 | if ( !(*it)->open() ) | ||
275 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | ||
276 | } | ||
277 | Resource *res = standardResource(); | ||
278 | if ( !res ) { | ||
279 | qDebug("ERROR: no standard resource"); | ||
280 | res = manager->createResource( "file" ); | ||
281 | if ( res ) | ||
282 | { | ||
283 | addResource( res ); | ||
284 | } | ||
285 | else | ||
286 | qDebug(" No resource available!!!"); | ||
287 | } | ||
288 | setStandardResource( res ); | ||
289 | manager->writeConfig(); | ||
290 | } | ||
291 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | ||
292 | "X-Department", "KADDRESSBOOK" ); | ||
293 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | ||
294 | "X-Profession", "KADDRESSBOOK" ); | ||
295 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | ||
296 | "X-AssistantsName", "KADDRESSBOOK" ); | ||
297 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | ||
298 | "X-ManagersName", "KADDRESSBOOK" ); | ||
299 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | ||
300 | "X-SpousesName", "KADDRESSBOOK" ); | ||
301 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | ||
302 | "X-Office", "KADDRESSBOOK" ); | ||
303 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | ||
304 | "X-IMAddress", "KADDRESSBOOK" ); | ||
305 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | ||
306 | "X-Anniversary", "KADDRESSBOOK" ); | ||
307 | |||
308 | //US added this field to become compatible with Opie/qtopia addressbook | ||
309 | // values can be "female" or "male" or "". An empty field represents undefined. | ||
310 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | ||
311 | "X-Gender", "KADDRESSBOOK" ); | ||
312 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | ||
313 | "X-Children", "KADDRESSBOOK" ); | ||
314 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | ||
315 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | ||
316 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | ||
317 | "X-ExternalID", "KADDRESSBOOK" ); | ||
249 | } | 318 | } |
@@ -286,3 +355,2 @@ bool AddressBook::save( Ticket *ticket ) | |||
286 | deleteRemovedAddressees(); | 355 | deleteRemovedAddressees(); |
287 | |||
288 | return ticket->resource()->save( ticket ); | 356 | return ticket->resource()->save( ticket ); |
@@ -292,2 +360,31 @@ bool AddressBook::save( Ticket *ticket ) | |||
292 | } | 360 | } |
361 | bool AddressBook::saveAB() | ||
362 | { | ||
363 | bool ok = true; | ||
364 | |||
365 | deleteRemovedAddressees(); | ||
366 | |||
367 | KRES::Manager<Resource>::ActiveIterator it; | ||
368 | KRES::Manager<Resource> *manager = d->mManager; | ||
369 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | ||
370 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | ||
371 | Ticket *ticket = requestSaveTicket( *it ); | ||
372 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | ||
373 | if ( !ticket ) { | ||
374 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | ||
375 | .arg( (*it)->resourceName() ) ); | ||
376 | return false; | ||
377 | } | ||
378 | |||
379 | //if ( !save( ticket ) ) | ||
380 | if ( ticket->resource() ) { | ||
381 | if ( ! ticket->resource()->save( ticket ) ) | ||
382 | ok = false; | ||
383 | } else | ||
384 | ok = false; | ||
385 | |||
386 | } | ||
387 | } | ||
388 | return ok; | ||
389 | } | ||
293 | 390 | ||
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index f89d7da..e43de31 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -143,2 +143,3 @@ class AddressBook : public QObject | |||
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | ||
144 | 145 | ||
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 49c3b19..e912941 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -150,2 +150,3 @@ $Id$ | |||
150 | #include <libkdepim/ksyncprofile.h> | 150 | #include <libkdepim/ksyncprofile.h> |
151 | #include <libkdepim/ksyncprefsdialog.h> | ||
151 | 152 | ||
@@ -181,2 +182,4 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const | |||
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, |
@@ -206,3 +209,3 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const | |||
206 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 209 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
207 | 210 | #endif | |
208 | initGUI(); | 211 | initGUI(); |
@@ -2197,4 +2200,4 @@ void KABCore::slotSyncMenu( int action ) | |||
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 { |
@@ -2319,3 +2322,3 @@ int KABCore::ringSync() | |||
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 ... ")); |
@@ -2335,4 +2338,4 @@ int KABCore::ringSync() | |||
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 { |
@@ -2375,3 +2378,3 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) | |||
2375 | } | 2378 | } |
2376 | QString command = prof->getPreSyncCommand(); | 2379 | QString command = prof->getPreSyncCommandAB(); |
2377 | int fi; | 2380 | int fi; |
@@ -2407,3 +2410,3 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) | |||
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(); |
@@ -2413,3 +2416,3 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) | |||
2413 | if ( KABPrefs::instance()->mWriteBackFile ) { | 2416 | if ( KABPrefs::instance()->mWriteBackFile ) { |
2414 | command = prof->getPostSyncCommand(); | 2417 | command = prof->getPostSyncCommandAB(); |
2415 | int fi; | 2418 | int fi; |
@@ -2512,3 +2515,6 @@ QString KABCore::getPassword( ) | |||
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) |
@@ -2516,2 +2522,54 @@ bool KABCore::syncAB(QString filename, int mode) | |||
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 | } |
@@ -2520,5 +2578,16 @@ bool KABCore::syncAB(QString filename, int mode) | |||
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(); |
@@ -2531,3 +2600,3 @@ void KABCore::syncSharp() | |||
2531 | //mView->syncSharp(); | 2600 | //mView->syncSharp(); |
2532 | mModified = true ; | 2601 | setModified(); |
2533 | 2602 | ||
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 10ce8f4..4487a8a 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h | |||
@@ -458,3 +458,2 @@ class KABCore : public QWidget | |||
458 | void fillSyncMenu(); | 458 | void fillSyncMenu(); |
459 | void confSync(); | ||
460 | QString mCurrentSyncDevice; | 459 | QString mCurrentSyncDevice; |
@@ -473,2 +472,6 @@ class KABCore : public QWidget | |||
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 | // ********************* |