void CntFavoritesView::handleMemberSelection( QSet<QContactLocalId> aIds ) { if ( aIds.isEmpty() ) { showPreviousView(); } else { QList<QContactRelationship> memberships; foreach (QContactLocalId id, aIds) { QContactId contactId; contactId.setLocalId(id); QContactRelationship membership; membership.setRelationshipType(QContactRelationship::HasMember); membership.setFirst(mContact->id()); membership.setSecond(contactId); memberships.append(membership); } if (!memberships.isEmpty()) { getContactManager()->saveRelationships(&memberships, NULL); } CntViewParameters viewParameters; viewParameters.insert(EViewId, favoritesMemberView); QVariant var; var.setValue(*mContact); viewParameters.insert(ESelectedGroupContact, var); mViewManager->changeView(viewParameters); }
bool DummyEngine::saveContact(QContact* contact, bool batch, QContactManager::Error* error) { // ensure that the contact's details conform to their definitions if (!validateContact(*contact, error)) { *error = QContactManager::InvalidDetailError; return false; } // success! QContactId newId; newId.setManagerUri(managerUri()); newId.setLocalId(5); contact->setId(newId); *error = QContactManager::NoError; // if we need to emit signals (ie, this isn't part of a batch operation) // then emit the correct one. if (!batch) { QList<QContactLocalId> emitList; emitList.append(contact->id().localId()); emit contactsAdded(emitList); } return true; }
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); }
void CntFavoritesMemberView::handleManageFavorites(QSet<QContactLocalId> aIds) { for (int i = 0; i < 2; ++i) { // first iteration processes added members, second removed members QSet<QContactLocalId> members = (i == 0 ? aIds - mOriginalGroupMembers : mOriginalGroupMembers - aIds); QList<QContactRelationship> memberships; foreach (QContactLocalId id, members) { QContactId contactId; contactId.setLocalId(id); QContactRelationship membership; membership.setRelationshipType(QContactRelationship::HasMember); membership.setFirst(mContact->id()); membership.setSecond(contactId); memberships.append(membership); } if (!memberships.isEmpty()) { if (i == 0) { getContactManager()->saveRelationships(&memberships, NULL); } else { getContactManager()->removeRelationships(memberships, NULL); } } }
/*! 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); } } }
/*! * The leaving function that queries the SQL database * * \a aSqlQuery An SQL query * \return the list of matched contact ids */ QList<QContact> CntSymbianSrvConnection::searchContactNamesL(const TDesC& aSqlQuery) { readContactsToBufferL(aSqlQuery, CntSymbianSrvConnection::CntSearchResultList); RBufReadStream readStream; QList<QContact> contacts; TInt id; TBuf<256> firstName; TBuf<256> lastName; TBuf<256> company; readStream.Open(*m_buffer); while ((id = readStream.ReadInt32L()) != 0) { readStream >> firstName; readStream >> lastName; readStream >> company; QContact contact, tempContact; QContactName name; name.setFirstName(QString::fromUtf16(firstName.Ptr(), firstName.Length())); name.setLastName(QString::fromUtf16(lastName.Ptr(), lastName.Length())); tempContact.saveDetail(&name); QContactOrganization organization; organization.setName(QString::fromUtf16(company.Ptr(), company.Length())); tempContact.saveDetail(&organization); QContactManager::Error error(QContactManager::NoError); QString label = m_manager->synthesizedDisplayLabel(tempContact, &error); if (error != QContactManager::NoError) { continue; } tempContact.clearDetails(); m_manager->setContactDisplayLabel(&contact, label); QContactId contactId; contactId.setLocalId(id); contactId.setManagerUri(m_manager->managerUri()); contact.setId(contactId); contacts << contact; } return contacts; }
SeasidePerson *SeasideCache::personById(QContactLocalId id) { if (id == 0) return 0; QHash<QContactLocalId, SeasideCacheItem>::iterator it = instance->m_people.find(id); if (it != instance->m_people.end()) { return person(&(*it)); } else { // Insert a new item into the cache if the one doesn't exist. SeasideCacheItem &cacheItem = instance->m_people[id]; QContactId contactId; contactId.setLocalId(id); cacheItem.contact.setId(contactId); return person(&cacheItem); } }
void CntSimStorePrivate::RunL() { //qDebug() << "CntSimStorePrivate::RunL()" << m_state << iStatus.Int(); m_asyncError = iStatus.Int(); User::LeaveIfError(iStatus.Int()); // NOTE: It is assumed that emitting signals is queued switch (m_state) { case ReadState: { QList<QContact> contacts = decodeSimContactsL(m_buffer); // set sync target and read only access constraint and display label QList<QContact>::iterator i; for (i = contacts.begin(); i != contacts.end(); ++i) { QContactSyncTarget syncTarget; syncTarget.setSyncTarget(KSimSyncTarget); m_engine.setReadOnlyAccessConstraint(&syncTarget); i->saveDetail(&syncTarget); QContactType contactType = i->detail(QContactType::DefinitionName); m_engine.setReadOnlyAccessConstraint(&contactType); i->saveDetail(&contactType); m_engine.updateDisplayLabel(*i); } emit m_simStore.readComplete(contacts, QContactManager::NoError); } break; case WriteState: { // save id QContactId contactId; contactId.setLocalId(m_writeIndex); contactId.setManagerUri(m_managerUri); m_convertedContact.setId(contactId); // set sync target if(m_convertedContact.detail(QContactSyncTarget::DefinitionName).isEmpty()) { QContactSyncTarget syncTarget = m_convertedContact.detail(QContactSyncTarget::DefinitionName); syncTarget.setSyncTarget(KSimSyncTarget); m_engine.setReadOnlyAccessConstraint(&syncTarget); m_convertedContact.saveDetail(&syncTarget); } // set type as read only QContactType contactType = m_convertedContact.detail(QContactType::DefinitionName); m_engine.setReadOnlyAccessConstraint(&contactType); m_convertedContact.saveDetail(&contactType); emit m_simStore.writeComplete(m_convertedContact, QContactManager::NoError); } break; case DeleteState: { emit m_simStore.removeComplete(QContactManager::NoError); } break; case ReadReservedSlotsState: { QList<int> reservedSlots = decodeReservedSlotsL(m_buffer); emit m_simStore.getReservedSlotsComplete(reservedSlots, QContactManager::NoError); } break; default: { User::Leave(KErrUnknown); } break; } m_state = InactiveState; }
void QDeclarativeContactRelationship::setSecond(QContactLocalId secondId) { QContactId id; id.setLocalId(secondId); m_relationship.setSecond(id); }
void QDeclarativeContactRelationship::setFirst(QContactLocalId firstId) { QContactId id; id.setLocalId(firstId); m_relationship.setFirst(id); }
void SeasideCache::reset() { for (int i = 0; i < FilterTypesCount; ++i) { m_contacts[i].clear(); m_populated[i] = false; m_models[i] = 0; } m_cache.clear(); #ifdef USING_QTPIM m_cacheIndices.clear(); #endif for (uint i = 0; i < sizeof(contactsData) / sizeof(Contact); ++i) { QContact contact; #ifdef USING_QTPIM // This is specific to the qtcontacts-sqlite backend: const QString idStr(QString::fromLatin1("qtcontacts:org.nemomobile.contacts.sqlite::sql-%1")); contact.setId(QContactId::fromString(idStr.arg(i + 1))); #else QContactId contactId; contactId.setLocalId(i + 1); contact.setId(contactId); #endif QContactName name; name.setFirstName(QLatin1String(contactsData[i].firstName)); name.setLastName(QLatin1String(contactsData[i].lastName)); contact.saveDetail(&name); if (contactsData[i].avatar) { QContactAvatar avatar; avatar.setImageUrl(QUrl(QLatin1String(contactsData[i].avatar))); contact.saveDetail(&avatar); } QContactStatusFlags statusFlags; if (contactsData[i].email) { QContactEmailAddress email; email.setEmailAddress(QLatin1String(contactsData[i].email)); contact.saveDetail(&email); statusFlags.setFlag(QContactStatusFlags::HasEmailAddress, true); } if (contactsData[i].phoneNumber) { QContactPhoneNumber phoneNumber; phoneNumber.setNumber(QLatin1String(contactsData[i].phoneNumber)); contact.saveDetail(&phoneNumber); statusFlags.setFlag(QContactStatusFlags::HasPhoneNumber, true); } contact.saveDetail(&statusFlags); #ifdef USING_QTPIM m_cacheIndices.insert(internalId(contact), m_cache.count()); #endif m_cache.append(CacheItem(contact)); QString fullName = name.firstName() + QChar::fromLatin1(' ') + name.lastName(); CacheItem &cacheItem = m_cache.last(); cacheItem.nameGroup = determineNameGroup(&cacheItem); cacheItem.displayLabel = fullName; } insert(FilterAll, 0, getContactsForFilterType(FilterAll)); insert(FilterFavorites, 0, getContactsForFilterType(FilterFavorites)); insert(FilterOnline, 0, getContactsForFilterType(FilterOnline)); }