/* 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");
    }
}
Esempio n. 2
0
// 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
}
QString CntSymbianSimEngine::synthesizedDisplayLabel(const QContact& contact, QContactManager::Error* error) const
{
    Q_UNUSED(error);

    QContactName name = contact.detail(QContactName::DefinitionName);
    if(!name.customLabel().isEmpty()) {
        return name.customLabel();
    } else {
        return QString("");
    }
}
Esempio n. 4
0
void SeasideCache::contactsAvailable()
{
    if (m_fetchFilter == SeasideFilteredModel::FilterFavorites
            || m_fetchFilter == SeasideFilteredModel::FilterOnline
            || m_fetchFilter == SeasideFilteredModel::FilterAll) {
        // Part of an initial query.
        appendContacts(m_fetchRequest.contacts());
    } else {
        // An update.
        const QList<QContact> contacts = m_fetchRequest.contacts();

        for (int i = m_resultsRead; i < contacts.count(); ++i) {
            QContact contact = contacts.at(i);
            SeasideCacheItem &item = m_people[contact.localId()];
            QContactName oldName = item.contact.detail<QContactName>();
            QContactName newName = contact.detail<QContactName>();

            if (newName.customLabel().isEmpty()) {
                newName.setCustomLabel(oldName.customLabel());
                contact.saveDetail(&newName);
            }

            const bool roleDataChanged = newName != oldName
                    || contact.detail<QContactAvatar>().imageUrl() != item.contact.detail<QContactAvatar>().imageUrl();

            item.contact = contact;
            item.hasCompleteContact = true;
            if (item.person) {
                item.person->setContact(contact);
                item.person->setComplete(true);
            }

             QList<QContactPhoneNumber> phoneNumbers = contact.details<QContactPhoneNumber>();
             for (int j = 0; j < phoneNumbers.count(); ++j) {
                 m_phoneNumberIds[phoneNumbers.at(j).number()] = contact.localId();
             }

             if (roleDataChanged) {
                instance->updateContactData(contact.localId(), SeasideFilteredModel::FilterFavorites);
                instance->updateContactData(contact.localId(), SeasideFilteredModel::FilterOnline);
                instance->updateContactData(contact.localId(), SeasideFilteredModel::FilterAll);
             }
        }
        m_resultsRead = contacts.count();
    }
}
Esempio n. 5
0
QString SeasidePerson::displayLabel()
{
    if (mDisplayLabel.isEmpty()) {
        QContactName name = mContact.detail<QContactName>();
        mDisplayLabel = name.customLabel();
        if (mDisplayLabel.isEmpty())
            recalculateDisplayLabel();
    }

    return mDisplayLabel;
}