author | zautrix <zautrix> | 2004-09-21 10:08:57 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-21 10:08:57 (UTC) |
commit | 19f445f0b6e7d4591db46b89e877ed9f4332ecd4 (patch) (side-by-side diff) | |
tree | fd21a5dc32332060197d792552ef1eb469e92175 | |
parent | 1cf4cc6e7bf25ee309852c7c97155de86917289f (diff) | |
download | kdepimpi-19f445f0b6e7d4591db46b89e877ed9f4332ecd4.zip kdepimpi-19f445f0b6e7d4591db46b89e877ed9f4332ecd4.tar.gz kdepimpi-19f445f0b6e7d4591db46b89e877ed9f4332ecd4.tar.bz2 |
more sync fixes
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 3 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 48 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmconverter.cpp | 17 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 5 | ||||
-rw-r--r-- | korganizer/calendarview.cpp | 4 |
5 files changed, 70 insertions, 7 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index b8c32d5..6cd63fd 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp @@ -134,96 +134,97 @@ ResourceFile::~ResourceFile() void ResourceFile::writeConfig( KConfig *config ) { config->setGroup( "Resource_" + identifier() ); Resource::writeConfig( config ); config->writeEntry( "FileName", mFileName ); config->writeEntry( "FileFormat", mFormatName ); // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); } Ticket *ResourceFile::requestSaveTicket() { kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; if ( !addressBook() ) return 0; #ifdef ALLOW_LOCKING if ( !lock( mFileName ) ) { qDebug("unablt to lock file "); return 0; } #endif return createTicket( this ); } bool ResourceFile::doOpen() { QFile file( mFileName ); + qDebug("ResourceFile::openfile %s ", mFileName.latin1()); if ( !file.exists() ) { // try to create the file bool ok = file.open( IO_WriteOnly ); if ( ok ) file.close(); return ok; } else { if ( !file.open( IO_ReadWrite ) ) return false; if ( file.size() == 0 ) { file.close(); return true; } bool ok = mFormat->checkFormat( &file ); file.close(); return ok; } } void ResourceFile::doClose() { } bool ResourceFile::load() { - + qDebug("ResourceFile::loadfile %s ", mFileName.latin1()); QFile file( mFileName ); if ( !file.open( IO_ReadOnly ) ) { addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); return false; } // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); return mFormat->loadAll( addressBook(), this, &file ); } bool ResourceFile::save( Ticket *ticket ) { // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); // create backup file QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); /*US we use a simpler method to create a backupfile (void) KSaveFile::backupFile( mFileName, QString::null ,extension ); KSaveFile saveFile( mFileName ); bool ok = false; if ( saveFile.status() == 0 && saveFile.file() ) { mFormat->saveAll( addressBook(), this, saveFile.file() ); ok = saveFile.close(); } */ diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 48d3985..437bda8 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp @@ -175,144 +175,186 @@ bool ResourceSharpDTM::load() bool res = false; CardId id; for (bool res=mAccess->first(); res == true; res=mAccess->next()) { id = mAccess->cardId(); KABC::Addressee addressee; res = mConverter->sharpToAddressee( id, mAccess, addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } return true; } bool ResourceSharpDTM::save( Ticket *ticket ) { qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); mDirWatch.stopScan(); KABC::AddressBook::Iterator it; bool res; KABC::Addressee::List changedAddressees; + typedef QMap<int,QString> AddresseeMap; + AddresseeMap map; + CardId id ; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { QString uid = (*it).originalExternalUID(); - CardId id ; bool res; if ( uid.isEmpty() ) id = 0; else id = uid.toUInt(); KABC::Addressee addressee = (*it); if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { res = mAccess->startEditCard(id); if (res == true) { res = mConverter->addresseeToSharp( (*it), mAccess, id ); if (res == true) { + res = mAccess->finishEditCard(&id); + //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + //(*it).setExternalUID( QString::number( id ) ); + //(*it).setOriginalExternalUID( QString::number( id ) ); + map.insert(id,(*it).uid()); + +#if 0 KABC::Addressee addressee; res = mConverter->sharpToAddressee( id, mAccess, addressee ); addressee.setUid((*it).uid() ); - addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + (it*).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); res = mAccess->finishEditCard(&id); //qDebug("2NEW id is %d", id); addressee.setExternalUID( QString::number( id ) ); addressee.setOriginalExternalUID( QString::number( id ) ); changedAddressees.append( addressee ); +#endif if (res == false) qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); } else { qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); mAccess->cancelEditCard(); } } } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { res = mAccess->deleteCard(&id); if ( res ) qDebug("delete success "); else qDebug("delete error "); } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { //changed qDebug("changed ****"); res = mAccess->startEditCard(id); if (res == true) { res = mConverter->addresseeToSharp( (*it), mAccess, id ); if (res == true) { + res = mAccess->finishEditCard(&id); + //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); + map.insert(id,(*it).uid()); + +#if 0 KABC::Addressee addressee; res = mConverter->sharpToAddressee( id, mAccess, addressee ); addressee.setUid((*it).uid() ); addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); changedAddressees.append( addressee ); res = mAccess->finishEditCard(&id); +#endif if (res == false) qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); } else { qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); mAccess->cancelEditCard(); } } } } } + AddresseeMap::Iterator itam; + res; + for ( res=mAccess->first(); res == true; res=mAccess->next()) + { + id = mAccess->cardId(); + int idint = id; + itam = map.find( idint ); + if ( itam != map.end() ) { + KABC::Addressee addressee; + qDebug("found change %d %s ", idint, itam.data().latin1()); + res = mConverter->sharpToAddressee( id, mAccess, addressee ); + + if ( !addressee.isEmpty() && res ) + { + addressee.setResource( this ); + addressee.setUid( itam.data() ); + addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + addressBook()->insertAddressee( addressee , false ); + } + } + } +#if 0 KABC::Addressee::List::Iterator it2; - for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) + for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) { + (*it2).computeCsum( "Sharp_DTM" ); + qDebug("CSUM: %s ",(*it2).getCsum( "Sharp_DTM" ).latin1() ); addressBook()->insertAddressee((*it2)); + } +#endif //US mAccess->save(); mDirWatch.startScan(); delete ticket; unlock( fileName() ); return true; } bool ResourceSharpDTM::lock( const QString &lockfileName ) { #ifdef ALLOW_LOCKING qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; QString fn = lockfileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); kdDebug(5700) << "-- lock name: " << lockName << endl; if (QFile::exists( lockName )) { qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); return false; } QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp index f3bf2c5..fccf625 100644 --- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp +++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp @@ -257,128 +257,139 @@ bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBa //US QString groups() const { return find( Qtopia::Groups ); } //US QStringList groupList() const; //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" ); QArray<int> catArray = db->readCategories(); QString cat; for ( unsigned int i=0; i < catArray.size(); i++ ) { cat = catDB->label(catArray[i]); if ( cat.isEmpty() ) addr.insertCategory(QString::number(catArray[i])); else addr.insertCategory( cat ); } return true; } bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ) { bool cellHome = false, cellWork = false; // name database->writeField(ZdbAdrs::LastName, addr.familyName()); database->writeField(ZdbAdrs::FirstName, addr.givenName()); database->writeField(ZdbAdrs::MiddleName, addr.additionalName()); database->writeField(ZdbAdrs::Title, addr.prefix()); database->writeField(ZdbAdrs::Suffix, addr.suffix()); //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() ); - database->writeField(ZdbAdrs::FileAs, addr.formattedName()); - database->writeField(ZdbAdrs::FullName, addr.formattedName()); + QString formattedName = addr.formattedName(); + if ( formattedName.isEmpty() ) { + if ( !addr.familyName().isEmpty() ) { + formattedName = addr.familyName(); + if ( !addr.givenName().isEmpty() ) { + formattedName += ", "; + formattedName += addr.givenName(); + } + } else + formattedName = addr.givenName(); + } + database->writeField(ZdbAdrs::FileAs, formattedName); + database->writeField(ZdbAdrs::FullName, formattedName); // email //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!"); //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee"); QString emails = addr.emails().join(" "); database->writeField(ZdbAdrs::Emails, emails ); database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); // home const Address homeaddress = addr.address(Address::Home); if (!homeaddress.isEmpty()) { database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); database->writeField(ZdbAdrs::HomeState, homeaddress.region()); database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); } PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); if (!homephone.number().isEmpty()) database->writeField(ZdbAdrs::HomePhone, homephone.number()); PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); if (!homefax.number().isEmpty()) database->writeField(ZdbAdrs::HomeFax, homefax.number()); PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); if (!homemobile.number().isEmpty()) { database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); cellHome = true; } database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); // business const Address businessaddress = addr.address(Address::Work); if (!businessaddress.isEmpty()) { database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); } PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); if (!businessphone.number().isEmpty()) database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); if (!businessfax.number().isEmpty()) database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); if (!businessmobile.number().isEmpty()) { cellWork = true; database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); } PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); - if (!businessmobile.number().isEmpty()) { + if (! mobile.number().isEmpty()) { if ( ! cellHome ) database->writeField(ZdbAdrs::HomeMobile, mobile.number()); else if (! cellWork ) database->writeField(ZdbAdrs::BusinessMobile, mobile.number()); } PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); if (!businesspager.number().isEmpty()) database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); database->writeField(ZdbAdrs::JobTitle, addr.role()); database->writeField(ZdbAdrs::Company, addr.organization()); database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" )); database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" )); database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" )); database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" )); //personal database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" )); QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1()); //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?"); //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee"); if (gt == "male") database->writeField(ZdbAdrs::Gender, "male"); else if (gt == "female") database->writeField(ZdbAdrs::Gender, "female"); else database->writeField(ZdbAdrs::Gender, ""); diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index c1ead9d..c2f031a 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2740,91 +2740,96 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo w = 220; int h = bar.sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar.show(); int modulo = (er.count()/10)+1; int incCounter = 0; while ( incCounter < er.count()) { if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); uid = er[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; QString idS,OidS; qApp->processEvents(); if ( !skipIncidence ) { inL = local->findByUid( uid ); inR = remote->findByUid( uid ); //inL.setResource( 0 ); //inR.setResource( 0 ); if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { //qDebug("take %d %s ", take, inL.summary().latin1()); if ( take == 3 ) return false; if ( take == 1 ) {// take local if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); + inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); local->insertAddressee( inL, false ); idS = inR.externalUID(); OidS = inR.originalExternalUID(); } else idS = inR.IDStr(); remote->removeAddressee( inR ); inR = inL; inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inR.setOriginalExternalUID( OidS ); inR.setExternalUID( idS ); } else { inR.setIDStr( idS ); } inR.setResource( 0 ); remote->insertAddressee( inR , false); ++changedRemote; } else { // take == 2 take remote if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { if ( inR.revision().date().year() < 2004 ) inR.setRevision( modifiedCalendar ); } idS = inL.IDStr(); local->removeAddressee( inL ); inL = inR; inL.setIDStr( idS ); + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); + inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); + } inL.setResource( 0 ); local->insertAddressee( inL , false ); ++changedLocal; } } } else { // no conflict if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { QString des = addresseeLSync.note(); if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); remote->insertAddressee( inR, false ); ++deletedAddresseeR; } else { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); inL = inR; inL.setResource( 0 ); local->insertAddressee( inL , false); ++addedAddressee; } } else { if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); inR.setResource( 0 ); local->insertAddressee( inR, false ); ++addedAddressee; } else { // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); remote->removeAddressee( inR ); ++deletedAddresseeR; } diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index bbed05b..7fae4a9 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -1020,64 +1020,68 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int qApp->processEvents(); if ( !skipIncidence ) { inL = local->incidence( uid ); if ( inL ) { // maybe conflict - same uid in both calendars int maxrev = inL->revision(); if ( maxrev < inR->revision() ) maxrev = inR->revision(); if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { //qDebug("take %d %s ", take, inL->summary().latin1()); if ( take == 3 ) return false; if ( take == 1 ) {// take local if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); else idS = inR->IDStr(); remote->deleteIncidence( inR ); if ( inL->revision() < maxrev ) inL->setRevision( maxrev ); inR = inL->clone(); inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) inR->setIDStr( idS ); remote->addIncidence( inR ); ++changedRemote; } else { if ( inR->revision() < maxrev ) inR->setRevision( maxrev ); idS = inL->IDStr(); local->deleteIncidence( inL ); inL = inR->clone(); inL->setIDStr( idS ); + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); + inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); + } local->addIncidence( inL ); ++changedLocal; } } } else { // no conflict if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { QString des = eventLSync->description(); QString pref = "e"; if ( inR->type() == "Todo" ) pref = "t"; if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); //remote->deleteIncidence( inR ); ++deletedEventR; } else { inR->setLastModified( modifiedCalendar ); inL = inR->clone(); local->addIncidence( inL ); ++addedEvent; } } else { if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { inR->setLastModified( modifiedCalendar ); local->addIncidence( inR->clone() ); ++addedEvent; } else { checkExternSyncEvent(eventRSyncSharp, inR); remote->deleteIncidence( inR ); ++deletedEventR; } } } |