void SeasidePerson::setMiddleName(const QString &name) { QContactName nameDetail = mContact.detail<QContactName>(); nameDetail.setMiddleName(name); mContact.saveDetail(&nameDetail); emit middleNameChanged(); recalculateDisplayLabel(); }
QContactDetail *CntTransformName::transformItemField(const CContactItemField& field, const QContact &contact) { QContactName *name = new QContactName(contact.detail<QContactName>()); CContactTextField* storage = field.TextStorage(); QString nameValue = QString::fromUtf16(storage->Text().Ptr(), storage->Text().Length()); for (int i = 0; i < field.ContentType().FieldTypeCount(); i++) { //Prefix if (field.ContentType().FieldType(i) == KUidContactFieldPrefixName) { name->setPrefix(nameValue); } //First name else if (field.ContentType().FieldType(i) == KUidContactFieldGivenName) { name->setFirstName(nameValue); } //Middle name else if (field.ContentType().FieldType(i) == KUidContactFieldAdditionalName) { name->setMiddleName(nameValue); } //Last name else if (field.ContentType().FieldType(i) == KUidContactFieldFamilyName) { name->setLastName(nameValue); } //Suffix else if (field.ContentType().FieldType(i) == KUidContactFieldSuffixName) { name->setSuffix(nameValue); } // custom label else if (field.ContentType().FieldType(i) == KUidContactFieldTemplateLabel) { name->setCustomLabel(nameValue); } } return name; }
QContact generateContact(const QString &syncTarget = QString(QLatin1String("local")), bool possiblyAggregate = false) { static const QStringList firstNames(generateFirstNamesList()); static const QStringList middleNames(generateMiddleNamesList()); static const QStringList lastNames(generateLastNamesList()); static const QStringList nonOverlappingFirstNames(generateNonOverlappingFirstNamesList()); static const QStringList nonOverlappingLastNames(generateNonOverlappingLastNamesList()); static const QStringList phoneNumbers(generatePhoneNumbersList()); static const QStringList emailProviders(generateEmailProvidersList()); static const QStringList avatars(generateAvatarsList()); static const QStringList hobbies(generateHobbiesList()); // we randomly determine whether to generate various details // to ensure that we have heterogeneous contacts in the db. QContact retn; int random = qrand(); bool preventAggregate = (syncTarget != QLatin1String("local") && !possiblyAggregate); // We always have a sync target. QContactSyncTarget synctarget; synctarget.setSyncTarget(syncTarget); retn.saveDetail(&synctarget); // We always have a name. Select an overlapping name if the sync target // is something other than "local" and possiblyAggregate is true. QContactName name; name.setFirstName(preventAggregate ? nonOverlappingFirstNames.at(random % nonOverlappingFirstNames.size()) : firstNames.at(random % firstNames.size())); name.setLastName(preventAggregate ? nonOverlappingLastNames.at(random % nonOverlappingLastNames.size()) : lastNames.at(random % lastNames.size())); if ((random % 6) == 0) name.setMiddleName(middleNames.at(random % middleNames.size())); if ((random % 17) == 0) name.setPrefix(QLatin1String("Dr.")); retn.saveDetail(&name); // Favorite if ((random % 31) == 0) { QContactFavorite fav; fav.setFavorite(true); retn.saveDetail(&fav); } // Phone number if ((random % 3) == 0) { QContactPhoneNumber phn; QString randomPhn = phoneNumbers.at(random % phoneNumbers.size()); phn.setNumber(preventAggregate ? QString(QString::number(random % 500000) + randomPhn) : randomPhn); if ((random % 9) == 0) phn.setContexts(QContactDetail::ContextWork); retn.saveDetail(&phn); } // Email if ((random % 2) == 0) { QContactEmailAddress em; em.setEmailAddress(QString(QLatin1String("%1%2%3%4")) .arg(preventAggregate ? QString(QString::number(random % 500000) + syncTarget) : QString()) .arg(name.firstName()).arg(name.lastName()) .arg(emailProviders.at(random % emailProviders.size()))); if (random % 9) em.setContexts(QContactDetail::ContextWork); retn.saveDetail(&em); } // Avatar if ((random % 5) == 0) { QContactAvatar av; av.setImageUrl(name.firstName() + avatars.at(random % avatars.size())); retn.saveDetail(&av); } // Hobby if ((random % 21) == 0) { QContactHobby h1; h1.setHobby(hobbies.at(random % hobbies.size())); retn.saveDetail(&h1); int newRandom = qrand(); if ((newRandom % 2) == 0) { QContactHobby h2; h2.setHobby(hobbies.at(newRandom % hobbies.size())); retn.saveDetail(&h2); } } return retn; }
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(); m_cacheIndices.clear(); for (uint i = 0; i < sizeof(contactsData) / sizeof(Contact); ++i) { QContact contact; // 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))); QContactName name; name.setFirstName(QString::fromLatin1(contactsData[i].firstName)); name.setMiddleName(QString::fromUtf8(contactsData[i].middleName)); name.setLastName(QString::fromLatin1(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); m_cacheIndices.insert(internalId(contact), m_cache.count()); 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)); }