-rw-r--r-- | kabc/addressbook.cpp | 10 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 4 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmconverter.cpp | 52 |
3 files changed, 12 insertions, 54 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 9e61261..f3744bc 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -611,148 +611,148 @@ void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); KABC::VCardTool tool; list = tool.parseVCards( data ); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { if ( !(*ait).tagged() ) { if ( (*ait).containsAdr(*it)) { (*ait).setTagged(true); QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); (*it).setIDStr( ":"); (*it).setID( currentSyncDevice,id ); (*it).setExternalUID( id ); (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); (*it).setUid( ( (*ait).uid() )); break; } } } if ( ait == end() ) qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); } clear(); for ( it = list.begin(); it != list.end(); ++it ) { insertAddressee( (*it) ); } } bool AddressBook::saveABphone( QString fileName ) { //smplifyAddressees(); qDebug("saveABphone:: saving AB... "); if ( ! export2PhoneFormat( QStringList() ,fileName ) ) return false; qDebug("saveABphone:: writing to phone... "); if ( !PhoneAccess::writeToPhone( fileName) ) { return false; } qDebug("saveABphone:: re-reading from phone... "); if ( !PhoneAccess::readFromPhone( fileName) ) { return false; } return true; } bool AddressBook::saveAB() { bool ok = true; deleteRemovedAddressees(); Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { if ( !(*ait).IDStr().isEmpty() ) { (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); } } KRES::Manager<Resource>::ActiveIterator it; KRES::Manager<Resource> *manager = d->mManager; qDebug("SaveAB::saving..." ); for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { qDebug("SaveAB::checking resource..." ); if ( (*it)->readOnly() ) - qDebug("resource is readonly." ); + qDebug("SaveAB::resource is readonly." ); if ( (*it)->isOpen() ) - qDebug("resource is open" ); + qDebug("SaveAB::resource is open" ); if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = requestSaveTicket( *it ); - qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); + qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { - qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) + qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } //if ( !save( ticket ) ) if ( ticket->resource() ) { QString name = ticket->resource()->resourceName(); if ( ! ticket->resource()->save( ticket ) ) ok = false; else - qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); + qDebug("SaveAB::resource saved '%s'", name.latin1() ); } else ok = false; } } return ok; } AddressBook::Iterator AddressBook::begin() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.begin(); return it; } AddressBook::ConstIterator AddressBook::begin() const { ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.begin(); return it; } AddressBook::Iterator AddressBook::end() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.end(); return it; } AddressBook::ConstIterator AddressBook::end() const { ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.end(); return it; } void AddressBook::clear() { d->mAddressees.clear(); } Ticket *AddressBook::requestSaveTicket( Resource *resource ) { kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; if ( !resource ) { qDebug("AddressBook::requestSaveTicket no resource" ); resource = standardResource(); } KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( (*it) == resource ) { if ( (*it)->readOnly() || !(*it)->isOpen() ) return 0; else return (*it)->requestSaveTicket(); } } return 0; } diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 6413b42..e8f8bdd 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp @@ -77,134 +77,134 @@ ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) { mAccess = 0; init( fileName ); } void ResourceSharpDTM::init( const QString &fileName ) { if (mConverter == 0) { mConverter = new SharpDTMConverter(); bool res = mConverter->init(); if ( !res ) { QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); qDebug(msg); return; } } setFileName( fileName ); } ResourceSharpDTM::~ResourceSharpDTM() { if (mConverter != 0) delete mConverter; if(mAccess != 0) delete mAccess; } void ResourceSharpDTM::writeConfig( KConfig *config ) { Resource::writeConfig( config ); } Ticket *ResourceSharpDTM::requestSaveTicket() { qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); if ( !addressBook() ) return 0; return createTicket( this ); } bool ResourceSharpDTM::doOpen() { if (!mConverter) return false; return true; } void ResourceSharpDTM::doClose() { return; } bool ResourceSharpDTM::load() { if (!mConverter) return false; QString fileN = SlZDataBase::addressbookFileName(); if ( ! mAccess ) { mAccess = new SlZDataBase(fileN, SlZDataBase::addressbookItems(), - 0, false); + 0, true); } if(mAccess == 0) return false; - qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1()); + qDebug("ResourceSharpDTM:: %x load: %s",this, fileName().latin1()); 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 ); } } if(mAccess != 0) delete mAccess; mAccess = 0; return true; } bool ResourceSharpDTM::save( Ticket *ticket ) { if (!mConverter) return false; QString fileN = SlZDataBase::addressbookFileName(); if ( ! mAccess ) { mAccess = new SlZDataBase(fileN, SlZDataBase::addressbookItems(), 0, false); } if(mAccess == 0) return false; qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 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(); 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);; mConverter->setCategories( (*it), mAccess, id ); map.insert(id,(*it).uid()); if (res == false) qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); } else diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp index 95e16b6..4adcae4 100644 --- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp +++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp @@ -359,128 +359,86 @@ bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* da PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); 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, "1"); else if (gt == "female") database->writeField(ZdbAdrs::Gender, "2"); else database->writeField(ZdbAdrs::Gender, ""); QString dateS ; QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate if ( dt.isValid() ) { dateS = KGlobal::locale()->formatDate(dt, true ); } database->writeField(ZdbAdrs::Anniversary, dateS ); database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); dt = addr.birthday().date(); dateS = ""; if ( dt.isValid() ) { dateS = KGlobal::locale()->formatDate(dt, true ); } database->writeField(ZdbAdrs::Birthday, dateS); database->writeField(ZdbAdrs::Nickname, addr.nickName()); // other database->writeField(ZdbAdrs::Notes, addr.note()); //US QString groups() const { return find( Qtopia::Groups ); } //US QStringList groupList() const; //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); return true; } bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact ) { QStringList list = addr.categories(); QArray<int> ids(list.count()); uint index = 0; for(uint i=0; i<ids.size(); i++){ if(catDB->exists(list[i])){ ids[index] = catDB->id(list[i]); - qDebug("set ex cat %d %s ",ids[index] , list[i].latin1()); + //qDebug("set exist cat %d %s ",ids[index] , list[i].latin1()); index++; } else { ids[index] = catDB->addCategory(list[i]); - qDebug("add new cat %d %s ",ids[index] , list[i].latin1()); + //qDebug("add new cat %d %s ",ids[index] , list[i].latin1()); index++; } } bool res ; - if ( res = database->updateCategories(contact, ids) ) - qDebug("cat updated "); - else - qDebug("error cat updating "); - - return res; -} -#if 0 - m_pCategories = new SlCategories; -catDB + if ( !(res = database->updateCategories(contact, ids) )) + qDebug("SharpDTMConverter::Error updating categories"); - if(categories == QString::null) return true; - QStringList list = CSVParser::parse(categories); - QArray<int> ids(list.count()); - uint index = 0; - for(uint i=0; i<ids.size(); i++){ -#if 0 - bool ok; - ids[index] = list[i].toInt(&ok); - if(ok){ - index++; - } else { - if(m_pCategories->exists(list[i])){ - ids[index] = m_pCategories->id(list[i]); - index++; - } - } -#else - if(m_pCategories->exists(list[i])){ - ids[index] = m_pCategories->id(list[i]); - index++; - } else if(m_addCategory){ - ids[index] = m_pCategories->addCategory(list[i]); - index++; - } -#endif - } - if(ids.size() > 0 && index == 0){ - return true; - } else if(index != ids.size()){ - ids.resize(index); - } - if(!m_pZdb->updateCategories(id, ids)){ - return false; + return res; } - return true; -#endif QDate SharpDTMConverter::convertDate( QString s) { QDate dt = KGlobal::locale()->readDate( s ); return dt; return QDate (); } |