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 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); } } }
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 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); }
/*! Returns true if this id is less than the \a other id. This id will be considered less than the \a other id if the manager URI of this id is alphabetically less than the manager URI of the \a other id. If both ids have the same manager URI, this id will be considered less than the \a other id if the local id of this id is less than the local id of the \a other id. The invalid, empty id consists of an empty manager URI and the invalid, zero local id, and hence will be less than any non-invalid id. This operator is provided primarily to allow use of a QContactId as a key in a QMap. \since 1.0 */ bool QContactId::operator<(const QContactId& other) const { const int comp = this->managerUri().compare(other.managerUri()); if (comp != 0) return comp < 0; return this->localId() < other.localId(); }
/*! 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); } } }
SeasideCache::CacheItem *SeasideCache::itemById(int id, bool) { if (id == 0) return 0; // Construct a valid id from this value QString idStr(QString::fromLatin1("qtcontacts:org.nemomobile.contacts.sqlite::sql-%1")); QContactId contactId = QContactId::fromString(idStr.arg(id)); if (contactId.isNull()) { qWarning() << "Unable to formulate valid ID from:" << id; return 0; } return itemById(contactId); }
/*! * 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); } }
/*! 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); } } } }
void GContactClient::filterRemoteAddedModifiedDeletedContacts (const QList<GContactEntry *> remoteContacts, QList<GContactEntry*>& remoteAddedContacts, QList<GContactEntry*>& remoteModifiedContacts, QList<GContactEntry*>& remoteDeletedContacts) { FUNCTION_CALL_TRACE; foreach (GContactEntry* entry, remoteContacts) { if (entry->deleted () == true) { remoteDeletedContacts.append (entry); continue; } QContactId localId = mContactBackend->entryExists(entry->guid()); if (!localId.isNull()) { remoteModifiedContacts.append (entry); } else { remoteAddedContacts.append (entry); } } }
/*! * Returns the hash value for \a key. * \since 1.0 */ uint qHash(const QContactId &key) { return QT_PREPEND_NAMESPACE(qHash)(key.managerUri()) + QT_PREPEND_NAMESPACE(qHash)(key.localId()); }
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; }
bool SeasideCache::validId(const QContactId &id) { return !id.isNull(); }
QDebug operator<<(QDebug dbg, const QContactId& id) { dbg.nospace() << "QContactId(" << id.managerUri() << ", " << id.localId() << ")"; return dbg.maybeSpace(); }
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)); }