QString RingControl::findRingTone() { QString ringTone; if(DialerControl::instance()->hasIncomingCall()) { QPhoneCall call = DialerControl::instance()->incomingCall(); QString numberOrName = call.number(); QContact cnt; QContactModel *m = ServerContactModel::instance(); if (!call.contact().isNull()) { cnt = m->contact(call.contact()); } else if (!numberOrName.isEmpty()) { cnt = m->matchPhoneNumber(numberOrName); } if (!cnt.uid().isNull()) { numberOrName = cnt.label(); // video ringtone ringTone = cnt.customField( "videotone" ); if ( !ringTone.isEmpty() ) { d->videoTone = true; } else { // normal ringtone ringTone = cnt.customField( "tone" ); d->videoTone = false; } if ( ringTone.isEmpty() ) { // check if the contacts category has a ringtone QList<QString> catList = cnt.categories(); if ( catList.count() ) { QCategoryManager catManager; ringTone = catManager.ringTone( catList.at( 0 ) ); } d->videoTone = false; } } } return ringTone; }
QContact GoogleSession::merge(QContact contact, GoogleContact gContact) { qDebug() << "=="; qDebug() << contact.label() << gContact.label(); // merge email lists QStringList gl = gContact.emailList(); QStringList el = contact.emailList(); for (int i=0; i<gl.size(); ++i) { if ( el.contains( gl.at(i) ) ) qDebug() << "already have email" << gl.at(i) ; else contact.insertEmail( gl.at(i) ); } // merge phone number lists QMap<QContact::PhoneType, QString> nums = contact.phoneNumbers(); QMap<QContact::PhoneType, QString> gNums = gContact.phoneNumbers(); // iterate google data QMapIterator<QContact::PhoneType, QString> gNumIt(gNums); while (gNumIt.hasNext()) { gNumIt.next(); QString phone = gNumIt.value(); QContact::PhoneType type = gNumIt.key(); if (! nums.values().contains( phone ) ) { gContact.setPhoneNumber(type, phone); qDebug () << "adding phone" << phone << "of type" << type; } else { // iterate qtopia data QMapIterator<QContact::PhoneType, QString> it(nums); while (it.hasNext()) { it.next(); qDebug() << "contacts has phone" << it.value() << "of type" << it.key(); qDebug() << "comparing to google" << phone << "of type" << type; if (it.value() == phone && it.key() != type ) { bool updatedef = (contact.defaultPhoneNumber() == phone); nums.remove(it.key() ); nums.remove(type); // FIXME nums.insert(type, phone); contact.setPhoneNumbers(nums); if (updatedef) contact.setDefaultPhoneNumber(type); qDebug() << "replaced phone of type" << type << phone << updatedef; break; } } qDebug () << "skipping phone" << phone << type ; } } QStringList googleGroupList = gContact.categories(); for (int i=0; i<googleGroupList.size(); ++i) { QString googleGroupId = googleGroupList.at(i); QString googleGroupName = groups[googleGroupId]; QString googleGroupQId = "category." + googleGroupName; qDebug() << "Group id" <<googleGroupId << "name" << googleGroupName ; if (googleGroupName.isEmpty()) continue; QList<QString> qGroupList = contact.categories(); if (! qGroupList.contains(googleGroupQId) ) { qGroupList << googleGroupQId; qDebug() << "Adding group" << googleGroupName ; contact.setCategories(qGroupList); } else { qDebug() << "Skipping group" << googleGroupName; } qDebug() << "group count" << qGroupList.count(); } qDebug() << "\n"; return contact; }