/* Synthesise the display label of a contact */ QString QContactWinCEEngine::synthesizedDisplayLabel(const QContact& contact, QContactManager::Error* error) const { Q_UNUSED(error) // The POOM API (well, lack thereof) makes this a bit strange. // It's basically just "Last, First" or "Company", if "FileAs" is not set. QContactName name = contact.detail<QContactName>(); QContactOrganization org = contact.detail<QContactOrganization>(); // Basically we ignore any existing labels for this contact, since we're being // asked what the synthesized label would be // XXX For greatest accuracy we might be better off converting this contact to // a real item (but don't save it), and then retrieve it... if (!name.customLabel().isEmpty()) { return name.customLabel(); } else if (!name.lastName().isEmpty()) { if (!name.firstName().isEmpty()) { return QString(QLatin1String("%1, %2")).arg(name.lastName()).arg(name.firstName()); } else { // Just last return name.lastName(); } } else if (!name.firstName().isEmpty()) { return name.firstName(); } else if (!org.name().isEmpty()) { return org.name(); } else { // XXX grargh. return QLatin1String("Unnamed"); } }
QContactDetail *CntTransformOrganisation::transformItemField(const CContactItemField& field, const QContact &contact) { QContactOrganization *organisation = new QContactOrganization(contact.detail<QContactOrganization>()); CContactTextField* storage = field.TextStorage(); QString orgDetail = QString::fromUtf16(storage->Text().Ptr(), storage->Text().Length()); for (int i = 0; i < field.ContentType().FieldTypeCount(); i++) { //Company if (field.ContentType().FieldType(i) == KUidContactFieldCompanyName) { organisation->setName(orgDetail); } //Department else if (field.ContentType().FieldType(i) == KUidContactFieldDepartmentName) { // Assume only a single department QStringList departments = QStringList(orgDetail); organisation->setDepartment(departments); } //Job title else if (field.ContentType().FieldType(i) == KUidContactFieldJobTitle) { organisation->setTitle(orgDetail); } //Assistant name else if (field.ContentType().FieldType(i) == KUidContactFieldAssistant) { organisation->setAssistantName(orgDetail); } } return organisation; }
void SeasidePerson::setCompanyName(const QString &name) { QContactOrganization companyNameDetail = mContact.detail<QContactOrganization>(); companyNameDetail.setName(name); mContact.saveDetail(&companyNameDetail); emit companyNameChanged(); }
// small helper to avoid inconvenience QString SeasidePerson::generateDisplayLabel(const QContact &mContact, SeasideProxyModel::DisplayLabelOrder order) { //REVISIT: Move this or parts of this to localeutils.cpp QString displayLabel; QContactName name = mContact.detail<QContactName>(); QString nameStr1; QString nameStr2; if (order == SeasideProxyModel::LastNameFirst) { nameStr1 = name.lastName(); nameStr2 = name.firstName(); } else { nameStr1 = name.firstName(); nameStr2 = name.lastName(); } if (!nameStr1.isNull()) displayLabel.append(nameStr1); if (!nameStr2.isNull()) { if (!displayLabel.isEmpty()) displayLabel.append(" "); displayLabel.append(nameStr2); } if (!displayLabel.isEmpty()) return displayLabel; foreach (const QContactOnlineAccount& account, mContact.details<QContactOnlineAccount>()) { if (!account.accountUri().isNull()) return account.accountUri(); } foreach (const QContactEmailAddress& email, mContact.details<QContactEmailAddress>()) { if (!email.emailAddress().isNull()) return email.emailAddress(); } QContactOrganization company = mContact.detail<QContactOrganization>(); if (!company.name().isNull()) return company.name(); foreach (const QContactPhoneNumber& phone, mContact.details<QContactPhoneNumber>()) { if (!phone.number().isNull()) return phone.number(); } // This is last because the custom label is often source from this function, so we want to // overwrite that value in many cases. if (!name.customLabel().isNull()) return name.customLabel(); return "(Unnamed)"; // TODO: localisation }
/*! * 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; }
// small helper to avoid inconvenience static QString generateDisplayLabel(QContact mContact) { //REVISIT: Move this or parts of this to localeutils.cpp QString displayLabel; QContactName name = mContact.detail<QContactName>(); QString nameStr1 = name.firstName(); QString nameStr2 = name.lastName(); if (!nameStr1.isNull()) displayLabel.append(nameStr1); if (!nameStr2.isNull()) { if (!displayLabel.isEmpty()) displayLabel.append(" "); displayLabel.append(nameStr2); } if (!displayLabel.isEmpty()) return displayLabel; foreach (const QContactOnlineAccount& account, mContact.details<QContactOnlineAccount>()) { if (!account.accountUri().isNull()) return account.accountUri(); } foreach (const QContactEmailAddress& email, mContact.details<QContactEmailAddress>()) { if (!email.emailAddress().isNull()) return email.emailAddress(); } QContactOrganization company = mContact.detail<QContactOrganization>(); if (!company.name().isNull()) return company.name(); foreach (const QContactPhoneNumber& phone, mContact.details<QContactPhoneNumber>()) { if (!phone.number().isNull()) return phone.number(); } return "(unnamed)"; // TODO: localisation }
QString SeasidePerson::companyName() const { QContactOrganization company = mContact.detail<QContactOrganization>(); return company.name(); }
void SymbianPluginPerfomance::createComplexContacts() { // Create N contacts QList<QContact> contactsList; for(int i=0; i<NO_OF_CONTACTS; i++) { QContact alice; // Contact details QString c = QString::number(i); QString first("Alice"); QString last("Jones"); QContactName aliceName; aliceName.setFirstName(first.append(c)); aliceName.setLastName(last.append(c)); alice.saveDetail(&aliceName); QContactPhoneNumber number; number.setContexts("Home"); number.setSubTypes("Mobile"); number.setNumber("12345678"); alice.saveDetail(&number); alice.setPreferredDetail("DialAction", number); QContactPhoneNumber number2; number2.setContexts("Work"); number2.setSubTypes("Landline"); number2.setNumber("555-4444"); alice.saveDetail(&number2); QContactAddress add; add.setStreet("Leeds West Yorkshire"); add.setPostcode("10087"); add.setRegion("New York"); add.setCountry("United States"); alice.saveDetail(&add); /* Commented out to ensure compatibility with pre-10.1 platforms QContactGender gender; gender.setGender("Female"); alice.saveDetail(&gender); */ QContactBirthday bday; bday.setDate(QDate(25,10,1978)); alice.saveDetail(&bday); /* Commented out to ensure compatibility with pre-10.1 platforms QContactOnlineAccount acc; acc.setAccountUri("sips:[email protected]"); acc.setSubTypes(QContactOnlineAccount::SubTypeSip); alice.saveDetail(&acc); */ QContactEmailAddress email; email.setEmailAddress("mailto:[email protected]"); alice.saveDetail(&email); QContactOrganization org; org.setDepartment(QStringList("Services")); org.setTitle("Assistant Manager"); // Commented out to ensure compatibility with pre-10.1 platforms //org.setLocation("Nokia Cyber Park"); alice.saveDetail(&org); contactsList.append(alice); } // Save the contacts mTime.restart(); QMap<int, QContactManager::Error> errors; mCntMng->saveContacts(&contactsList, &errors); foreach(QContactManager::Error error, errors) { QCOMPARE(error, QContactManager::NoError); }