예제 #1
0
void SeasidePerson::setFavorite(bool favorite)
{
    QContactFavorite favoriteDetail = mContact.detail<QContactFavorite>();
    favoriteDetail.setFavorite(favorite);
    mContact.saveDetail(&favoriteDetail);
    emit favoriteChanged();
}
void CntVersitFavoritePlugin::propertyProcessed(
    const QVersitDocument& document,
    const QVersitProperty& property,
    const QContact& contact,
    bool* alreadyProcessed,
    QList<QContactDetail>* updatedDetails)
{
    Q_UNUSED(document);
    Q_UNUSED(contact);
    Q_UNUSED(alreadyProcessed);
    Q_UNUSED(updatedDetails);
    
    if (property.name().contains(QLatin1String("X-FAVORITE"), Qt::CaseInsensitive)) {
        // This method is called before the corresponding detail gets imported to QContact.
        // Detail is saved after whole versit document is processed.
        QContactFavorite favorite;
        favorite.setFavorite(true);
        favorite.setIndex(property.value().toInt());
        mFavoriteDetailList.append(favorite);
    }
}
예제 #3
0
bool SeasidePerson::favorite() const
{
    QContactFavorite favoriteDetail = mContact.detail<QContactFavorite>();
    return favoriteDetail.isFavorite();
}
예제 #4
0
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 TestSymbianEngine::saveContactWithFavoriteDetail()
{
    QContactManager::Error err;
    QContactFetchHint hint;
    
    //save a contact without favorite detail
    QContact c1;
    c1.setType(QContactType::TypeContact);
    QContactName name1;
    name1.setFirstName("somename");
    c1.saveDetail(&name1);
    QVERIFY(m_engine->saveContact(&c1, &err));
    QVERIFY(err == QContactManager::NoError);
    //fetch contact and check there is no favorite detail
    QContact savedContact1 = m_engine->contact(c1.localId(), hint, &err);
    QVERIFY(err == QContactManager::NoError);
    QVERIFY(savedContact1.details<QContactFavorite>().count() == 0);
    
    //save a contact with a favorite detail
    QContact c2;
    c2.setType(QContactType::TypeContact);
    QContactName name2;
    name2.setFirstName("firstname");
    c2.saveDetail(&name2);
    QContactFavorite fav;
    fav.setFavorite(true);
    fav.setIndex(100);
    c2.saveDetail(&fav);
    QVERIFY(m_engine->saveContact(&c2, &err));
    QVERIFY(err == QContactManager::NoError);
    //fetch contact and check there is a preferred detail we saved
    QContact savedContact2 = m_engine->contact(c2.localId(), hint, &err);
    QVERIFY(err == QContactManager::NoError);
    QContactFavorite savedFav = savedContact2.detail<QContactFavorite>();
    QVERIFY(savedFav.isFavorite());
    QVERIFY(savedFav.index() == 100);
    
    //remove favorite detail and save contact
    savedContact2.removeDetail(&savedFav);
    QVERIFY(m_engine->saveContact(&savedContact2, &err));
    QVERIFY(err == QContactManager::NoError);
    //fetch contact and check there is no favorite detail
    QContact savedContact3 = m_engine->contact(savedContact2.localId(), hint, &err);
    QVERIFY(err == QContactManager::NoError);
    QVERIFY(savedContact3.details<QContactFavorite>().count() == 0);
    
    //save a contact with a favorite detail, favorite index is 0
    QContact c3;
    c3.setType(QContactType::TypeContact);
    QContactName name3;
    name3.setFirstName("firstname3");
    c3.saveDetail(&name3);
    QContactFavorite fav3;
    fav3.setFavorite(true);
    fav3.setIndex(0);
    c3.saveDetail(&fav3);
    QVERIFY(m_engine->saveContact(&c3, &err));
    QVERIFY(err == QContactManager::NoError);
    //fetch contact and check there is a preferred detail we saved
    QContact savedContact4 = m_engine->contact(c3.localId(), hint, &err);
    QVERIFY(err == QContactManager::NoError);
    QContactFavorite savedFav4 = savedContact4.detail<QContactFavorite>();
    QVERIFY(savedFav4.isFavorite());
    QVERIFY(savedFav4.index() == 0);
    
    //remove favorite detail by changing QContactFavorite detail and save contact
    savedFav4.setFavorite(false);
    savedContact4.saveDetail(&savedFav4);
    QVERIFY(m_engine->saveContact(&savedContact4, &err));
    QVERIFY(err == QContactManager::NoError);
    //fetch contact and check there is no favorite detail
    QContact savedContact5 = m_engine->contact(savedContact4.localId(), hint, &err);
    QVERIFY(err == QContactManager::NoError);
    QVERIFY(savedContact5.details<QContactFavorite>().count() == 0);
}