SeasideCache::ContactIdType SeasideCache::apiId(const QContact &contact) { #ifdef USING_QTPIM return contact.id(); #else return contact.id().localId(); #endif }
void ContactConnection::addContact(QContact contact) { mEngine->setNotifySimulator(false); QContactManager::Error error; QContactChangeSet changeSet; // if the created contact would get a too high id, delete // the contacts that the simulator knows nothing about QContactMemoryEngineData *edata = QContactMemoryEngineData::data(mEngine); if (edata->m_nextContactId + 1 > contact.localId()) { for (QContactLocalId id = contact.localId(); id <= edata->m_nextContactId; ++id) mEngine->removeContact(id, changeSet, &error); } // make sure the inserted contact gets the same id as in the simulator edata->m_nextContactId = contact.localId() - 1; // add (set localid to 0 first, otherwise the engine thinks we want to update a contact) QContactId newId = contact.id(); newId.setLocalId(0); contact.setId(newId); mEngine->saveContact(&contact, changeSet, &error); mEngine->setNotifySimulator(true); }
QContactManager::Error GContactsBackend::modifyContact(const QString &aID, QContact &aContact) { FUNCTION_CALL_TRACE; Q_ASSERT (iMgr); LOG_DEBUG("Modifying a Contact with ID" << aID); QContactManager::Error modificationStatus = QContactManager::UnspecifiedError; QContact oldContactData; getContact(QContactId::fromString(aID), oldContactData); aContact.setId(oldContactData.id()); oldContactData = aContact; bool modificationOk = iMgr->saveContact(&oldContactData); modificationStatus = iMgr->error(); if(!modificationOk) { // either contact exists or something wrong with one of the detailed definitions LOG_WARNING("Contact Modification Failed"); } // no else return modificationStatus; }
QDebug operator<<(QDebug dbg, const QContact& contact) { dbg.nospace() << "QContact(" << contact.id() << ")"; foreach (const QContactDetail& detail, contact.details()) { dbg.space() << '\n' << detail; } return dbg.maybeSpace(); }
/*! \relates QContact Returns the hash value for \a key. */ uint qHash(const QContact &key) { uint hash = qHash(key.id()); foreach (const QContactDetail& detail, key.details()) { hash += qHash(detail); } return hash; }
/*! Adds QContactTag details to the \a contacts, based on the \a relationships. Tags are created such that if a group contact, B with display label "b", has a HasMember relationship with a contact, A, then a QContactTag, "b", is added to A. Group contacts can be passed in with the \a contacts list. If a contact is part of a group which is not in \a contacts, the \a manager is queried to find them. */ void createTagsFromGroups(QList<QContact>* contacts, const QList<QContactRelationship>& relationships, const QContactManager* manager) { // Map from QContactIds to group names QMap<QContactId, QString> groupMap; // Map from QContactIds to indices into the contacts list QMap<QContactId, int> indexMap; // Build up groupMap and indexMap for (int i = 0; i < contacts->size(); ++i) { QContact contact = contacts->at(i); if (contact.type() == QContactType::TypeGroup) { // In practice, you may want to check that there aren't two distinct groups with the // same name, and you may want to use a field other than display label. groupMap.insert(contact.id(), contact.displayLabel()); } indexMap.insert(contact.id(), i); } // Now add all the tags specified by the group relationships foreach (const QContactRelationship& rel, relationships) { if (rel.relationshipType() == QContactRelationship::HasMember && indexMap.contains(rel.second())) { QString groupName = groupMap.value(rel.first()); // Have we seen the group before? if (groupName.isEmpty()) { // Try and find the group in the manager QContactId groupId = rel.second(); QContactFetchHint fetchHint; fetchHint.setDetailDefinitionsHint(QStringList(QContactDisplayLabel::DefinitionName)); QContact contact = manager->contact(groupId.localId(), fetchHint); if (!contact.isEmpty()) { groupName = contact.displayLabel(); groupMap.insert(groupId, groupName); // Cache the group id/name } } if (!groupName.isEmpty()) { // Add the tag QContactTag tag; tag.setTag(groupName); (*contacts)[indexMap.value(rel.second())].saveDetail(&tag); } } } }
/*! Adds contacts in \a newContacts into \a manager, converting categories specified with tags into group membership relationships. Note that this implementation uses the synchronous API of QContactManager for clarity. It is recommended that the asynchronous API is used in practice. Relationships are added so that if a contact, A, has a tag "b", then a HasMember relationship is created between a group contact in the manager, B with display label "b", and contact A. If there does not exist a group contact with display label "b", one is created. */ void insertWithGroups(const QList<QContact>& newContacts, QContactManager* manager) { // Cache map from group names to QContactIds QMap<QString, QContactId> groupMap; foreach (QContact contact, newContacts) { if (!manager->saveContact(&contact)) continue; // In practice, better error handling may be required foreach (const QContactTag& tag, contact.details<QContactTag>()) { QString groupName = tag.tag(); QContactId groupId; if (groupMap.contains(groupName)) { // We've already seen a group with the right name groupId = groupMap.value(groupName); } else { QContactDetailFilter groupFilter; groupFilter.setDetailDefinitionName(QContactType::DefinitionName); groupFilter.setValue(QLatin1String(QContactType::TypeGroup)); groupFilter.setMatchFlags(QContactFilter::MatchExactly); // In practice, some detail other than the display label could be used QContactDetailFilter nameFilter = QContactDisplayLabel::match(groupName); QList<QContactLocalId> matchingGroups = manager->contactIds(groupFilter & nameFilter); if (!matchingGroups.isEmpty()) { // Found an existing group in the manager QContactId groupId; groupId.setManagerUri(manager->managerUri()); groupId.setLocalId(matchingGroups.first()); groupMap.insert(groupName, groupId); } else { // Make a new group QContact groupContact; QContactName name; name.setCustomLabel(groupName); // Beware that not all managers support custom label groupContact.saveDetail(&name); if (!manager->saveContact(&groupContact)) continue; // In practice, better error handling may be required groupId = groupContact.id(); groupMap.insert(groupName, groupId); } } // Add the relationship QContactRelationship rel; rel.setFirst(groupId); rel.setRelationshipType(QContactRelationship::HasMember); rel.setSecond(contact.id()); manager->saveRelationship(&rel); } } }
void QDeclarativeContact::setContact(const QContact& contact) { m_id = contact.id(); foreach (QDeclarativeContactDetail *detail, m_details) delete detail; m_details.clear(); m_preferredDetails.clear(); QList<QContactDetail> details(contact.details()); foreach (const QContactDetail &detail, details) { QDeclarativeContactDetail *contactDetail = QDeclarativeContactDetailFactory::createContactDetail(static_cast<QDeclarativeContactDetail::DetailType>(detail.type())); contactDetail->setParent(this); contactDetail->setDetail(detail); connect(contactDetail, SIGNAL(detailChanged()), this, SIGNAL(contactChanged())); m_details.append(contactDetail); }
bool CntSimStorePrivate::write(const QContact &contact, QContactManager::Error *error) { if (IsActive()) { *error = QContactManager::LockedError; return false; } if (m_storeInfo.m_readOnlyAccess) { *error = QContactManager::NotSupportedError; return false; } // get index m_writeIndex = KErrNotFound; if (contact.id().managerUri() == m_managerUri && contact.localId() > 0) { m_writeIndex = contact.localId(); // TODO: check that the contact exist in the sim } // encode m_buffer.Zero(); m_buffer.ReAlloc(KOneSimContactBufferSize); m_convertedContact = QContact(contact); TRAPD(err, encodeSimContactL(&m_convertedContact, m_buffer)); if (err != KErrNone) { CntSymbianSimTransformError::transformError(err, error); return false; } // start writing m_etelStore.Write(iStatus, m_buffer, m_writeIndex); SetActive(); m_state = WriteState; *error = QContactManager::NoError; return true; }
void ContactConnection::setRelationships(uint id, const QVariantList &relationships) { QContactManager::Error error; QContactChangeSet changeSet; QContact contact = mEngine->contact(id, QContactFetchHint(), &error); if (error != QContactManager::NoError) return; // adjust relationships to be in sync QList<QContactRelationship> clientRelationships( mEngine->relationships(QString(), contact.id(), QContactRelationship::Either, &error)); QList<QContactRelationship> simulatorRelationships; foreach (const QVariant &v, relationships) simulatorRelationships.append(v.value<QContactRelationship>()); mEngine->setNotifySimulator(false); // remove superfluous foreach (const QContactRelationship &cr, clientRelationships) { if (!simulatorRelationships.contains(cr)) { mEngine->removeRelationship(cr, changeSet, &error); } } // add new foreach (const QContactRelationship &sr, simulatorRelationships) { if (!clientRelationships.contains(sr)) { QContactRelationship toAdd = sr; mEngine->saveRelationship(&toAdd, changeSet, &error); } } mEngine->setNotifySimulator(true); }
QContactManager::Error ContactsBackend::modifyContact(const QString &aID, const QString &aContact) { FUNCTION_CALL_TRACE; LOG_DEBUG("Modifying a Contact with ID" << aID); QContactManager::Error modificationStatus = QContactManager::UnspecifiedError; if (iMgr == NULL) { LOG_WARNING("Contacts backend not available"); } else { QContact oldContactData; #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) getContact(QContactId::fromString (aID), oldContactData); #else getContact(aID.toUInt(), oldContactData); #endif QStringList contactStringList; contactStringList.append(aContact); QContact newContactData = convertVCardListToQContactList(contactStringList).first(); newContactData.setId(oldContactData.id()); oldContactData = newContactData; bool modificationOk = iMgr->saveContact(&oldContactData); modificationStatus = iMgr->error(); if(!modificationOk) { // either contact exists or something wrong with one of the detailed definitions LOG_WARNING("Contact Modification Failed"); } // no else } return modificationStatus; }
static QContactId retrievalId(const QContact &contact) { return contact.id(); }
quint32 SeasideCache::internalId(const QContact &contact) { return internalId(contact.id()); }
foreach(const QContact& c, contacts) { QVERIFY(c.id() == empty); QVERIFY(c.localId() == 0); }
QContactId apiId(const QContact &contact) { return contact.id(); }
QContactId SeasideCache::apiId(const QContact &contact) { return contact.id(); }
bool GContactClient::storeToLocal (const QList<GContactEntry*> remoteContacts) { FUNCTION_CALL_TRACE; bool syncSuccess = false; if (mSlowSync == true) { LOG_DEBUG ("@@@storeToLocal#SLOW SYNC"); // Since we request for all the deleted contacts, if // slow sync is performed many times, even deleted contacts // will appear in *remoteContacts. Filter them out while // saving them to device LOG_DEBUG ("TOTAL REMOTE CONTACTS:" << remoteContacts.size ()); if (remoteContacts.size () > 0) { QList<QContact> remoteQContacts = toQContacts (remoteContacts); QMap<int, GContactsStatus> statusMap; if (mContactBackend->addContacts (remoteQContacts, statusMap)) { // TODO: Saving succeeded. Update sync results syncSuccess = true; } else { // TODO: Saving failed. Update sync results and probably stop sync syncSuccess = false; } } } else if (mSlowSync == false) { LOG_DEBUG ("@@@storeToLocal#FAST SYNC"); QList<GContactEntry*> remoteAddedContacts, remoteModifiedContacts, remoteDeletedContacts; filterRemoteAddedModifiedDeletedContacts (remoteContacts, remoteAddedContacts, remoteModifiedContacts, remoteDeletedContacts); resolveConflicts(remoteModifiedContacts, remoteDeletedContacts); LOG_DEBUG ("###REMOTED ADDED=" << remoteAddedContacts.size ()); LOG_DEBUG ("###REMOTED MODIFIED=" << remoteModifiedContacts.size ()); LOG_DEBUG ("###REMOTED DELETED=" << remoteDeletedContacts.size ()); if (remoteAddedContacts.size () > 0) { LOG_DEBUG ("***Adding " << remoteAddedContacts.size () << " contacts"); QList<QContact> addedContacts = toQContacts (remoteAddedContacts); QMap<int, GContactsStatus> addedStatusMap; if (mContactBackend->addContacts (addedContacts, addedStatusMap)) syncSuccess = true; else syncSuccess = false; } if (remoteModifiedContacts.size () > 0) { LOG_DEBUG ("***Modifying " << remoteModifiedContacts.size () << " contacts"); QList<QContact> modifiedContacts = toQContacts (remoteModifiedContacts); QStringList modifiedIdsList; for (int i=0; i<modifiedContacts.size (); i++) { QContact contact = mContactBackend->getContact(remoteModifiedContacts.at(i)->guid()); LOG_DEBUG("Original contact - " << contact.id().toString()); modifiedIdsList << contact.id().toString(); } QMap<int, GContactsStatus> modifiedStatusMap = mContactBackend->modifyContacts (modifiedContacts, modifiedIdsList); if (modifiedStatusMap.size () > 0) { syncSuccess = true; } else { syncSuccess = false; } } if (remoteDeletedContacts.size () > 0) { LOG_DEBUG ("***Deleting " << remoteDeletedContacts.size () << " contacts"); QStringList guidList; for (int i=0; i<remoteDeletedContacts.size(); i++) guidList << remoteDeletedContacts.at(i)->guid(); QStringList localIdList = mContactBackend->localIds(guidList); QMap<int, GContactsStatus> deletedStatusMap = mContactBackend->deleteContacts (localIdList); if (deletedStatusMap.size () > 0) { syncSuccess = true; } else { syncSuccess = false; } } } return syncSuccess; }
quint32 ContactId::databaseId(const QContact &contact) { return databaseId(contact.id()); }
void TestSymbianEngine::saveContact() { QContactManager::Error err; QList<QContactSortOrder> sortOrders; QContactId empty; QContactFilter defaultFilter = QContactFilter(); int init_count = m_engine->contactIds(defaultFilter, sortOrders, &err).count(); QVERIFY(err == QContactManager::NoError); // Save a "NULL" contact QVERIFY(!m_engine->saveContact(NULL, &err)); QVERIFY(err == QContactManager::BadArgumentError); int current_count = m_engine->contactIds(defaultFilter, sortOrders, &err).count(); QVERIFY(err == QContactManager::NoError); QVERIFY(init_count == current_count); // Save a contact that is not in database QContact invaId; QVERIFY(m_engine->saveContact(&invaId, &err)); // Add to db QVERIFY(err == QContactManager::NoError); QContactId cId = invaId.id(); m_engine->removeContact(invaId.localId(), &err); // Ensure not in db QVERIFY(err == QContactManager::NoError); invaId.setId(cId); QVERIFY(!m_engine->saveContact(&invaId, &err)); // Update non existent contact QVERIFY(err == QContactManager::DoesNotExistError); current_count = m_engine->contactIds(defaultFilter, sortOrders, &err).count(); QVERIFY(err == QContactManager::NoError); QVERIFY(init_count == current_count); QContact alice; alice.setType("Jargon"); // Save a "non contact(Jargon) type" contact QVERIFY(!m_engine->saveContact(&alice, &err)); QVERIFY(err == QContactManager::InvalidDetailError); QVERIFY(alice.id() == empty); QVERIFY(alice.localId() == 0); current_count = m_engine->contactIds(defaultFilter, sortOrders, &err).count(); QVERIFY(err == QContactManager::NoError); QVERIFY(init_count == current_count); // Save a valid contact alice.setType(QContactType::TypeContact); QVERIFY(m_engine->saveContact(&alice, &err)); QVERIFY(err == QContactManager::NoError); QVERIFY(alice.id() != empty); QVERIFY(alice.localId() != 0); QString uri = QString(QLatin1String(CNT_SYMBIAN_MANAGER_NAME)); QVERIFY(alice.id().managerUri().contains(uri, Qt::CaseInsensitive)); current_count = m_engine->contactIds(defaultFilter, sortOrders, &err).count(); QVERIFY(err == QContactManager::NoError); QVERIFY(init_count + 1 == current_count); // Save a valid contact QContact g; g.setType(QContactType::TypeGroup); QContactName en; en.setCustomLabel("ccc"); QVERIFY(g.saveDetail(&en)); QVERIFY(m_engine->saveContact(&g, &err)); QVERIFY(err == QContactManager::NoError); QVERIFY(g.id() != empty); QVERIFY(g.localId() != 0); QVERIFY(g.id().managerUri().contains(uri, Qt::CaseInsensitive)); }
int addTestContact(const QString &name, const QString &remoteUid, const QString &localUid) { QString contactUri = QString("<testcontact:%1>").arg(contactNumber++); QContact contact; QContactSyncTarget syncTarget; syncTarget.setSyncTarget(QLatin1String("commhistory-tests")); if (!contact.saveDetail(&syncTarget)) { qWarning() << "Unable to add sync target to contact:" << contactUri; return -1; } if (!localUid.isEmpty() && localUid.indexOf("/ring/tel/") == -1) { // Create a metadata detail to link the contact with the account QContactOriginMetadata metadata; metadata.setGroupId(localUid); metadata.setId(remoteUid); metadata.setEnabled(true); if (!contact.saveDetail(&metadata)) { qWarning() << "Unable to add metadata to contact:" << contactUri; return false; } } QString normal = CommHistory::normalizePhoneNumber(remoteUid); if (normal.isEmpty()) { QContactOnlineAccount qcoa; qcoa.setValue(QContactOnlineAccount__FieldAccountPath, localUid); qcoa.setAccountUri(remoteUid); if (!contact.saveDetail(&qcoa)) { qWarning() << "Unable to add online account to contact:" << contactUri; return -1; } } else { QContactPhoneNumber phoneNumberDetail; phoneNumberDetail.setNumber(remoteUid); if (!contact.saveDetail(&phoneNumberDetail)) { qWarning() << "Unable to add phone number to contact:" << contactUri; return -1; } } QContactName nameDetail; nameDetail.setLastName(name); if (!contact.saveDetail(&nameDetail)) { qWarning() << "Unable to add name to contact:" << contactUri; return -1; } if (!manager()->saveContact(&contact)) { qWarning() << "Unable to store contact:" << contactUri; return -1; } // We should return the aggregated instance of this contact QContactRelationshipFilter filter; filter.setRelatedContactRole(QContactRelationship::Second); #ifdef USING_QTPIM filter.setRelatedContact(contact); filter.setRelationshipType(QContactRelationship::Aggregates()); #else filter.setRelatedContactId(contact.id()); filter.setRelationshipType(QContactRelationship::Aggregates); #endif foreach (const ContactListener::ApiContactIdType &id, manager()->contactIds(filter)) { qDebug() << "********** contact id" << id; addedContactIds.insert(id); return ContactListener::internalContactId(id); }
void AsyncRequestExample::performRequests() { //! [Creating a new contact in a manager] QContact exampleContact; QContactName nameDetail; nameDetail.setFirstName("Adam"); nameDetail.setLastName("Unlikely"); QContactPhoneNumber phoneNumberDetail; phoneNumberDetail.setNumber("+123 4567"); exampleContact.saveDetail(&nameDetail); exampleContact.saveDetail(&phoneNumberDetail); // save the newly created contact in the manager connect(&m_contactSaveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(contactSaveRequestStateChanged(QContactAbstractRequest::State))); m_contactSaveRequest.setManager(m_manager); m_contactSaveRequest.setContacts(QList<QContact>() << exampleContact); m_contactSaveRequest.start(); //! [Creating a new contact in a manager] m_contactSaveRequest.waitForFinished(); //! [Creating a new contact in a manager waiting until finished] m_contactSaveRequest.setManager(m_manager); m_contactSaveRequest.setContacts(QList<QContact>() << exampleContact); m_contactSaveRequest.start(); m_contactSaveRequest.waitForFinished(); QList<QContact> savedContacts = m_contactSaveRequest.contacts(); //! [Creating a new contact in a manager waiting until finished] //! [Filtering contacts from a manager] connect(&m_contactFetchRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(contactFetchRequestStateChanged(QContactAbstractRequest::State))); m_contactFetchRequest.setManager(m_manager); m_contactFetchRequest.setFilter(QContactPhoneNumber::match("+123 4567")); m_contactFetchRequest.start(); //! [Filtering contacts from a manager] m_contactFetchRequest.waitForFinished(); //! [Retrieving an existing contact from a manager] QContactLocalIdFilter idListFilter; idListFilter.setIds(QList<QContactLocalId>() << exampleContact.localId()); m_contactFetchRequest.setManager(m_manager); m_contactFetchRequest.setFilter(idListFilter); m_contactFetchRequest.start(); //! [Retrieving an existing contact from a manager] m_contactFetchRequest.waitForFinished(); //! [Updating an existing contact in a manager] phoneNumberDetail.setNumber("+123 9876"); exampleContact.saveDetail(&phoneNumberDetail); m_contactSaveRequest.setManager(m_manager); m_contactSaveRequest.setContacts(QList<QContact>() << exampleContact); m_contactSaveRequest.start(); //! [Updating an existing contact in a manager] m_contactFetchRequest.waitForFinished(); //! [Removing a contact from a manager] connect(&m_contactRemoveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(contactRemoveRequestStateChanged(QContactAbstractRequest::State))); m_contactRemoveRequest.setManager(m_manager); m_contactRemoveRequest.setContactIds(QList<QContactLocalId>() << exampleContact.localId()); m_contactRemoveRequest.start(); //! [Removing a contact from a manager] m_contactFetchRequest.waitForFinished(); //! [Creating a new relationship between two contacts] // first, create the group and the group member QContact exampleGroup; exampleGroup.setType(QContactType::TypeGroup); QContactNickname groupName; groupName.setNickname("Example Group"); exampleGroup.saveDetail(&groupName); QContact exampleGroupMember; QContactName groupMemberName; groupMemberName.setFirstName("Member"); exampleGroupMember.saveDetail(&groupMemberName); // second, save those contacts in the manager QList<QContact> saveList; saveList << exampleGroup << exampleGroupMember; m_contactSaveRequest.setContacts(saveList); m_contactSaveRequest.start(); m_contactSaveRequest.waitForFinished(); // third, create the relationship between those contacts QContactRelationship groupRelationship; groupRelationship.setFirst(exampleGroup.id()); groupRelationship.setRelationshipType(QContactRelationship::HasMember); groupRelationship.setSecond(exampleGroupMember.id()); // finally, save the relationship in the manager connect(&m_relationshipSaveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(relationshipSaveRequestStateChanged(QContactAbstractRequest::State))); m_relationshipSaveRequest.setManager(m_manager); m_relationshipSaveRequest.setRelationships(QList<QContactRelationship>() << groupRelationship); m_relationshipSaveRequest.start(); //! [Creating a new relationship between two contacts] m_contactFetchRequest.waitForFinished(); //! [Retrieving relationships between contacts] connect(&m_relationshipFetchRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(relationshipFetchRequestStateChanged(QContactAbstractRequest::State))); m_relationshipFetchRequest.setManager(m_manager); // retrieve the list of relationships between the example group contact and the example member contact // where the group contact is the first contact in the relationship, and the member contact is the // second contact in the relationship. In order to fetch all relationships between them, another // relationship fetch must be performed with their roles reversed, and the results added together. m_relationshipFetchRequest.setFirst(exampleGroup.id()); m_relationshipFetchRequest.setSecond(exampleGroupMember.id()); m_relationshipFetchRequest.start(); //! [Retrieving relationships between contacts] m_contactFetchRequest.waitForFinished(); //! [Providing a fetch hint] QContactFetchHint hasMemberRelationshipsOnly; hasMemberRelationshipsOnly.setRelationshipTypesHint(QStringList(QContactRelationship::HasMember)); m_contactFetchRequest.setManager(m_manager); m_contactFetchRequest.setFilter(QContactFilter()); // all contacts m_contactFetchRequest.setFetchHint(hasMemberRelationshipsOnly); m_contactFetchRequest.start(); //! [Providing a fetch hint] //! [Removing a relationship] connect(&m_relationshipRemoveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(relationshipRemoveRequestStateChanged(QContactAbstractRequest::State))); m_relationshipRemoveRequest.setManager(m_manager); m_relationshipRemoveRequest.setRelationships(QList<QContactRelationship>() << groupRelationship); m_relationshipRemoveRequest.start(); //! [Removing a relationship] connect(&m_definitionFetchRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(definitionFetchRequestStateChanged(QContactAbstractRequest::State))); //! [Querying the schema supported by a manager] m_definitionFetchRequest.setManager(m_manager); m_definitionFetchRequest.setDefinitionNames(QStringList(QContactName::DefinitionName)); m_definitionFetchRequest.start(); m_definitionFetchRequest.waitForFinished(); QMap<QString, QContactDetailDefinition> definitions = m_definitionFetchRequest.definitions(); qDebug() << "This manager" << (definitions.value(QContactName::DefinitionName).fields().contains(QContactName::FieldCustomLabel) ? "supports" : "does not support") << "the custom label field of QContactName"; //! [Querying the schema supported by a manager] connect(&m_definitionSaveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(definitionSaveRequestStateChanged(QContactAbstractRequest::State))); connect(&m_definitionRemoveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(definitionRemoveRequestStateChanged(QContactAbstractRequest::State))); //! [Modifying the schema supported by a manager] // modify the name definition, adding a patronym field QContactDetailDefinition nameDefinition = definitions.value(QContactName::DefinitionName); QContactDetailFieldDefinition fieldPatronym; fieldPatronym.setDataType(QVariant::String); nameDefinition.insertField("Patronym", fieldPatronym); // save the updated definition in the manager if supported... if (m_manager->hasFeature(QContactManager::MutableDefinitions)) { m_definitionSaveRequest.setManager(m_manager); m_definitionSaveRequest.setContactType(QContactType::TypeContact); m_definitionSaveRequest.setDefinitions(QList<QContactDetailDefinition>() << nameDefinition); m_definitionSaveRequest.start(); } //! [Modifying the schema supported by a manager] QCoreApplication::exit(0); }
QTCONTACTS_USE_NAMESPACE #include <QContactIdFilter> static QContactId retrievalId(const QContact &contact) { return contact.id(); }
QString ContactId::toString(const QContact &c) { return toString(c.id()); }