HbWidget* CntEmailEditorViewItem::createCustomWidget()
{
    mItem = new CntCommonDetailViewItem(this);
    mItem->editor()->setMaxLength( CNT_EMAIL_EDITOR_MAXLENGTH );
    mItem->editor()->setInputMethodHints(Qt::ImhPreferLowercase);

    HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model());
    CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) );
    QContactDetail detail = item->detail();

    mItem->editor()->setInputMethodHints( Qt::ImhEmailCharactersOnly );

    constructSubTypeModel( detail.contexts() );

    QContactEmailAddress address = detail;
    QString d = address.emailAddress();
    mItem->editor()->setText( address.emailAddress() );

    connect( mItem->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) );
    connect( mItem->editor(), SIGNAL(textChanged(QString)),this, SLOT(textChanged(QString)) );

    // Naming UI components for automation testability
    QString editorObjName = detail.definitionName() + " line edit %1";
    mItem->editor()->setObjectName(editorObjName.arg(modelIndex().row()));

    QString comboBoxObjName = detail.definitionName() + " combo box %1";
    mItem->comboBox()->setObjectName(comboBoxObjName.arg(modelIndex().row()));
    return mItem;
}
QList<CContactItemField *> CntTransformOnlineAccount::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactOnlineAccount::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to phonenumber
	const QContactOnlineAccount &onlineAccount(static_cast<const QContactOnlineAccount&>(detail));

	//get the subType
	QStringList subTypes = onlineAccount.subTypes();

	//no subtype
    if(!subTypes.count())
    {
        User::LeaveIfError(KErrArgument);
    }
    else if (subTypes.contains(QContactOnlineAccount::SubTypeSipVoip)) {
        //internet
        transformToTextFieldL(onlineAccount, fieldList, onlineAccount.accountUri(), KUidContactFieldSIPID, KUidContactFieldVCardMapVOIP, false);
    } else if (subTypes.contains(QContactOnlineAccount::SubTypeVideoShare)) {
        //share video
        transformToTextFieldL( onlineAccount, fieldList, onlineAccount.accountUri(), KUidContactFieldSIPID, KUidContactFieldVCardMapSWIS, false);
    } else if (subTypes.contains(QContactOnlineAccount::SubTypeSip)) {
        //sip
        transformToTextFieldL( onlineAccount, fieldList, onlineAccount.accountUri(), KUidContactFieldSIPID, KUidContactFieldVCardMapSIPID, false);
    }
    else
    {
        User::LeaveIfError(KErrNotSupported);
    }

	return fieldList;
}
Esempio n. 3
0
QList<CContactItemField *> CntTransformUrl::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactUrl::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to url
	const QContactUrl &url(static_cast<const QContactUrl&>(detail));

	//create new field
	TPtrC fieldText(reinterpret_cast<const TUint16*>(url.url().utf16()));
	if(fieldText.Length()) {
	    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldUrl);
	    newField->TextStorage()->SetTextL(fieldText);
	    newField->SetMapping(KUidContactFieldVCardMapURL);

	    QString subType = url.subType();
	    const QString& subTypeHomePage(QContactUrl::SubTypeHomePage);
	    if (subType.length() != 0 && subType.compare(subTypeHomePage) != 0)
	    {
	        User::LeaveIfError(KErrNotSupported);
	    }

	    //contexts
	    setContextsL(url, *newField);

	    fieldList.append(newField);
	    CleanupStack::Pop(newField);
	}

	return fieldList;
}
Esempio n. 4
0
QDebug operator<<(QDebug dbg, const QContactDetail& detail)
{
    dbg.nospace() << "QContactDetail(name=" << detail.definitionName() << ", key=" << detail.key();
    QVariantMap fields = detail.variantValues();
    QVariantMap::const_iterator it;
    for (it = fields.constBegin(); it != fields.constEnd(); ++it) {
        dbg.nospace() << ", " << it.key() << '=' << it.value();
    }
    dbg.nospace() << ')';
    return dbg.maybeSpace();
}
bool MobExample2Action::isDetailSupported(const QContactDetail &detail, const QContact &contact) const
{
    if(QContactPhoneNumber::DefinitionName == detail.definitionName())
    {
        return true;
    }
    else
    {
        return false;
    }
}
bool MobExampleAction::isDetailSupported(const QContactDetail &detail, const QContact &contact) const
{
    if(QContactOnlineAccount::DefinitionName == detail.definitionName())
    {
        return true;
    }
    else
    {
        return false;
    }
}
bool CntMessageAction::isDetailSupported(const QContactDetail &detail, const QContact &/*contact*/) const
{
    if (detail.definitionName() == QContactPhoneNumber::DefinitionName 
        && !static_cast<QContactPhoneNumber>(detail).subTypes().isEmpty())
    {
        return (static_cast<QContactPhoneNumber>(detail).subTypes().first() == QContactPhoneNumber::SubTypeMobile);
    }
    else
    {
        return false;
    }
}
Esempio n. 8
0
void MainWindow::on_pushButton_3_clicked()
{

//    qDebug() << "The default manager for the platform is:" << cm.managerName();
//    qDebug() << "It" << (cm.isRelationshipTypeSupported(QContactRelationship::HasAssistant) ? "supports" : "does not support") << "assistant relationships.";
//    qDebug() << "It" << (cm.supportedContactTypes().contains(QContactType::TypeGroup) ? "supports" : "does not support") << "groups.";
//    qDebug() << "It" << (cm.hasFeature(QContactManager::MutableDefinitions) ? "supports" : "does not support") << "mutable detail definitions.";


    QList<QContactLocalId> contactIds = cm.contactIds();
    QContact a = cm.contact(contactIds.first());
    qDebug() << "Viewing the details of" << a.displayLabel();

    QList<QContactDetail> allDetails = a.details();
    for (int i = 0; i < allDetails.size(); i++) {
        QContactDetail detail = allDetails.at(i);
        QContactDetailDefinition currentDefinition = cm.detailDefinition(detail.definitionName());
        QMap<QString, QContactDetailFieldDefinition> fields = currentDefinition.fields();

        qDebug("\tDetail #%d (%s):", i, detail.definitionName().toAscii().constData());
        foreach (const QString& fieldKey, fields.keys()) {
            qDebug() << "\t\t" << fieldKey << "(" << fields.value(fieldKey).dataType() << ") =" << detail.value(fieldKey);
        }
        qDebug();
    }

    QContact b;
    QContactDetail de;
    foreach (const QContactLocalId& ids, contactIds )
        {
            b =  cm.contact(ids);
            de = b.detail("PhoneNumber");
            bool s = de.hasValue("PhoneNumber");
            qDebug()<< " has Value PhoneNumber key"<<s<<"|"<<de.value("PhoneNumber");
            QString show;
            show = b.displayLabel();
            show.append("\t");
            show.append(de.value("PhoneNumber"));
            ui->listWidget_2->addItem(show);
        }
QList<CContactItemField *> CntTransformGender::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactGender::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to gender
	const QContactGender &gender(static_cast<const QContactGender&>(detail));

    //create new field without contexts
    transformToTextFieldL(gender, fieldList, gender.gender(), KUidContactFieldGender, KUidContactFieldVCardMapUnknown, false);

	return fieldList;
}
Esempio n. 10
0
QList<CContactItemField *> CntTransformNote::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactNote::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to note
	const QContactNote &note(static_cast<const QContactNote&>(detail));

    //create new fields without contexts
    transformToTextFieldL(note, fieldList, note.note(), KUidContactFieldNote, KUidContactFieldVCardMapNOTE, false);

	return fieldList;
}
Esempio n. 11
0
QList<CContactItemField *> CntTransformNickname::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactNickname::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to name
	const QContactNickname &name(static_cast<const QContactNickname &>(detail));

    //create new field without contexts
    transformToTextFieldL(name, fieldList, name.nickname(), KUidContactFieldSecondName, KUidContactFieldVCardMapSECONDNAME, false);

	return fieldList;
}
Esempio n. 12
0
QList<CContactItemField *> CntTransformThumbnail::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactThumbnail::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

    //cast to thumbnail
    const QContactThumbnail &thumbnail(static_cast<const QContactThumbnail&>(detail));

    //if thumbnail was not changed, use existing jpg image
    bool checksumExists;
    qint64 checksum = thumbnail.variantValue(KThumbnailChecksum).toLongLong(&checksumExists);
    if (!thumbnail.thumbnail().isNull() && checksumExists &&
            thumbnail.thumbnail().cacheKey() == checksum) {
        initializeThumbnailFieldL();
        CContactItemField *thumbnailField = CContactItemField::NewLC(*m_thumbnailFieldFromTemplate);
        QByteArray jpgData = thumbnail.variantValue(KThumbnailJpgImage).toByteArray();
        TPtrC8 ptr((TUint8*)jpgData.data(), jpgData.size());
        thumbnailField->StoreStorage()->SetThingL(ptr);
        fieldList.append(thumbnailField);
        CleanupStack::Pop(thumbnailField);
    } else if (!thumbnail.thumbnail().isNull()) {
        QByteArray jpgImage;
        QImage scaledImage;
        if (thumbnail.thumbnail().size().width() <= KMaxThumbnailSize.iWidth &&
                thumbnail.thumbnail().size().height() <= KMaxThumbnailSize.iHeight) {
            scaledImage = thumbnail.thumbnail();
        } else {
            scaledImage = thumbnail.thumbnail().scaled(
                              KMaxThumbnailSize.iWidth, KMaxThumbnailSize.iHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        }
        if (!scaledImage.isNull()) {
            QBuffer buffer(&jpgImage);
            buffer.open(QIODevice::WriteOnly);
            scaledImage.save(&buffer, "JPG");
            buffer.close();
            initializeThumbnailFieldL();
            CContactItemField *thumbnailField = CContactItemField::NewLC(*m_thumbnailFieldFromTemplate);
            TPtrC8 ptr((TUint8*)jpgImage.data(), jpgImage.size());
            thumbnailField->StoreStorage()->SetThingL(ptr);
            fieldList.append(thumbnailField);
            CleanupStack::Pop(thumbnailField);
        }
    }

    return fieldList;
}
Esempio n. 13
0
QList<CContactItemField *> CntTransformFamily::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactFamily::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

    //cast to family
    const QContactFamily &family(static_cast<const QContactFamily&>(detail));

    //create new fields without contexts
    transformToTextFieldL(family, fieldList, family.spouse(), KUidContactFieldSpouse, KUidContactFieldVCardMapSpouse, false);
    foreach(const QString& childName, family.children()) {
        transformToTextFieldL(family, fieldList, childName, KUidContactFieldChildren, KUidContactFieldVCardMapChildren, false);
    }

	return fieldList;
}
QList<CContactItemField *> CntTransformPresence::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactPresence::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to presence
	const QContactPresence &presenceDetail(static_cast<const QContactPresence&>(detail));
	
    HBufC* detailCount = HBufC::NewLC(KMaxDetailCounterLength);
    detailCount->Des().AppendNum(m_detailCounter);

    // Transform presence informaiton
	if(presenceDetail.presenceState() != QContactPresence::PresenceUnknown) {
        QString presence = QString::number(presenceDetail.presenceState());
        CContactItemField* presenceField = CContactItemField::NewLC(KStorageTypeText);
        TPtrC presenceEncodedText(reinterpret_cast<const TUint16*>(presence.utf16()));
        presenceField->TextStorage()->SetTextL(presenceEncodedText);
        presenceField->AddFieldTypeL(KUidContactFieldPresence);
        presenceField->SetLabelL(*detailCount);
        fieldList.append(presenceField);
        CleanupStack::Pop(presenceField);
    }
	         
    // Transform statusMessage
    TPtrC statusMsgText(reinterpret_cast<const TUint16*>(presenceDetail.presenceStateText().utf16()));
    if(statusMsgText.Length()) {
        CContactItemField* statusMsgField = CContactItemField::NewLC(KStorageTypeText);
        statusMsgField->TextStorage()->SetTextL(statusMsgText);
        statusMsgField->AddFieldTypeL(KUidContactFieldStatusMsg);
        statusMsgField->SetLabelL(*detailCount);
        fieldList.append(statusMsgField);
        CleanupStack::Pop(statusMsgField);
	}

    CleanupStack::PopAndDestroy(detailCount);
    
	if(fieldList.count() > 0) {
        m_detailCounter++;
	}
	    
	return fieldList;
}
Esempio n. 15
0
QList<CContactItemField *> CntTransformName::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactName::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

    //cast to name
    const QContactName &name(static_cast<const QContactName&>(detail));

    //create new fields without contexts
    transformToTextFieldL(name, fieldList, name.prefix(), KUidContactFieldPrefixName, KUidContactFieldVCardMapUnusedN, false);
    transformToTextFieldL(name, fieldList, name.firstName(), KUidContactFieldGivenName, KUidContactFieldVCardMapUnusedN, false);
    transformToTextFieldL(name, fieldList, name.middleName(), KUidContactFieldAdditionalName, KUidContactFieldVCardMapUnusedN, false);
    transformToTextFieldL(name, fieldList, name.lastName(), KUidContactFieldFamilyName, KUidContactFieldVCardMapUnusedN, false);
    transformToTextFieldL(name, fieldList, name.suffix(), KUidContactFieldSuffixName, KUidContactFieldVCardMapUnusedN, false);
    transformToTextFieldL(name, fieldList, name.customLabel(), KUidContactFieldTemplateLabel, KUidContactFieldVCardMapUnusedN, false);

    return fieldList;
}
Esempio n. 16
0
QList<CContactItemField *> CntTransformOrganisation::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactOrganization::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to orgenisation
    const QContactOrganization &orgDetails(static_cast<const QContactOrganization&>(detail));

    //create new fields without contexts
    transformToTextFieldL(orgDetails, fieldList, orgDetails.name(), KUidContactFieldCompanyName, KUidContactFieldVCardMapORG, false);
	QStringList departments = orgDetails.department();
	if(departments.count()) // Take only the first department
	    transformToTextFieldL(orgDetails, fieldList, departments[0], KUidContactFieldDepartmentName, KUidContactFieldVCardMapDepartment, false);
	transformToTextFieldL(orgDetails, fieldList, orgDetails.title(), KUidContactFieldJobTitle, KUidContactFieldVCardMapTITLE, false);
    transformToTextFieldL(orgDetails, fieldList, orgDetails.assistantName(), KUidContactFieldAssistant, KUidContactFieldVCardMapAssistant, false);

	return fieldList;
}
QList<CContactItemField *> CntTransformBirthday::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactBirthday::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to birthday
	const QContactBirthday &birthday(static_cast<const QContactUrl&>(detail));

	//create new field
	TDateTime dateTime(birthday.date().year(), TMonth(birthday.date().month() - 1), birthday.date().day() - 1, 0, 0, 0, 0);
	CContactItemField* newField = CContactItemField::NewLC(KStorageTypeDateTime, KUidContactFieldBirthday);
 	newField->DateTimeStorage()->SetTime(dateTime);
	newField->SetMapping(KUidContactFieldVCardMapBDAY);

	fieldList.append(newField);
	CleanupStack::Pop(newField);

	return fieldList;
}
QList<CContactItemField *> CntTransformAvatar::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactAvatar::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

    //cast to avatar
    const QContactAvatar &avatar(static_cast<const QContactAvatar&>(detail));

    //create new field
    QString urlString = avatar.imageUrl().toString();
    TPtrC fieldText(reinterpret_cast<const TUint16*>(urlString.utf16()));

    //copy filename and replace slash with a backslash
    TFileName filename;
    for(TInt i(0); i < fieldText.Length(); ++i) {
        if(i >= filename.MaxLength())
            User::Leave(KErrTooBig);
        if(fieldText[i] == '/') {
            filename.Append('\\');
        } else {
            filename.Append(fieldText[i]);
        }
    }

    if(filename.Length()) {
        TUid uid(KUidContactFieldCodImage);

        CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, uid);

        newField->SetMapping(KUidContactFieldVCardMapUnknown);
        newField->TextStorage()->SetTextL(filename);

        fieldList.append(newField);
        CleanupStack::Pop(newField);
    }

    return fieldList;
}
Esempio n. 19
0
/*!
  Called for each processed detail from QVersitContactExporter during 
  contact export. 
 */
void CntVersitMyCardPlugin::detailProcessed(
    const QContact& contact,
    const QContactDetail& detail,
    const QVersitDocument& document,
    QSet<QString>* processedFields,
    QList<QVersitProperty>* toBeRemoved,
    QList<QVersitProperty>* toBeAdded)
{
    Q_UNUSED(contact);
    Q_UNUSED(processedFields);
    Q_UNUSED(document);
    Q_UNUSED(toBeRemoved);

    if (detail.definitionName() == MYCARD_DEFINITION_NAME) {
        QVersitProperty property;
        property.setName(QLatin1String("X-SELF"));
        property.setValue("0");
        toBeAdded->append(property);
    }
    // QVersitContactExporter takes care of adding the toBeAdded properties
    // to the versit document.
}
QList<CContactItemField *> CntTransformAnniversarySimple::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactAnniversary::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

    //cast to anniversary
    const QContactAnniversary &anniversary(static_cast<const QContactAnniversary&>(detail));

    //create new field
    TDateTime dateTime(anniversary.originalDate().year(),
                       TMonth(anniversary.originalDate().month() - 1),
                       anniversary.originalDate().day() - 1, 0, 0, 0, 0);
    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeDateTime, KUidContactFieldAnniversary);
    newField->DateTimeStorage()->SetTime(dateTime);
    newField->SetMapping(KUidContactFieldVCardMapAnniversary);

    fieldList.append(newField);
    CleanupStack::Pop(newField);

    return fieldList;
}
void TestSymbianEngine::saveContactWithPreferredDetails()
{
    QContactManager::Error err;

    //save a contact with preferred details
    QContact c;
    c.setType(QContactType::TypeContact);

    QContactPhoneNumber number1;
    number1.setNumber("123");
    number1.setSubTypes(QContactPhoneNumber::SubTypeMobile);
    c.saveDetail(&number1);
    c.setPreferredDetail("call", number1);

    QContactPhoneNumber number2;
    number2.setNumber("456");
    number2.setSubTypes(QContactPhoneNumber::SubTypeMobile);
    c.saveDetail(&number2);
    c.setPreferredDetail("videocall", number2);

    QContactPhoneNumber number3;
    number3.setNumber("789");
    number3.setSubTypes(QContactPhoneNumber::SubTypeMobile);
    c.saveDetail(&number3);
    c.setPreferredDetail("message", number3);

    QContactEmailAddress email;
    email.setEmailAddress("dummyemail");
    c.saveDetail(&email);
    c.setPreferredDetail("email", email);
    
    QContactOnlineAccount onlineAccount;
    onlineAccount.setAccountUri("dummy");
    onlineAccount.setSubTypes(QContactOnlineAccount::SubTypeImpp);
    c.saveDetail(&onlineAccount);
    c.setPreferredDetail("OnlineAccountActions", onlineAccount);
    
    QContactUrl url;
    url.setUrl("http://dummy");
    c.saveDetail(&url);
    c.setPreferredDetail("url", url);

    QVERIFY(m_engine->saveContact(&c, &err));
    QVERIFY(err == QContactManager::NoError);

    //fetch the saved contact and check preferred details
    QContactFetchHint hint = QContactFetchHint();
    QContact fetched = m_engine->contact(c.localId(), hint, &err);
    QVERIFY(err == QContactManager::NoError);

    QContactDetail callDetail1 = fetched.preferredDetail("call");
    QVERIFY(callDetail1.definitionName() == QContactPhoneNumber::DefinitionName);
    QContactPhoneNumber fetchedNumber1 = static_cast<QContactPhoneNumber>(callDetail1);
    QVERIFY(fetchedNumber1.number() == "123");

    QContactDetail callDetail2 = fetched.preferredDetail("videocall");
    QVERIFY(callDetail2.definitionName() == QContactPhoneNumber::DefinitionName);
    QContactPhoneNumber fetchedNumber2 = static_cast<QContactPhoneNumber>(callDetail2);
    QVERIFY(fetchedNumber2.number() == "456");

    QContactDetail callDetail3 = fetched.preferredDetail("message");
    QVERIFY(callDetail3.definitionName() == QContactPhoneNumber::DefinitionName);
    QContactPhoneNumber fetchedNumber3 = static_cast<QContactPhoneNumber>(callDetail3);
    QVERIFY(fetchedNumber3.number() == "789");

    QContactDetail emailDetail = fetched.preferredDetail("email");
    QVERIFY(emailDetail.definitionName() == QContactEmailAddress::DefinitionName);
    QContactEmailAddress fetchedEmail = static_cast<QContactEmailAddress>(emailDetail);
    QVERIFY(fetchedEmail.emailAddress() == "dummyemail");
    
    QContactDetail onlineAccountDetail = fetched.preferredDetail("OnlineAccountActions");
    QVERIFY(onlineAccountDetail.definitionName() == QContactOnlineAccount::DefinitionName);
    QContactOnlineAccount fetchedOnlineAccount = static_cast<QContactOnlineAccount>(onlineAccountDetail);
    QVERIFY(fetchedOnlineAccount.accountUri() == "dummy");

    QContactDetail urlDetail = fetched.preferredDetail("url");
    QVERIFY(urlDetail.definitionName() == QContactUrl::DefinitionName);
    QContactUrl fetchedUrl = static_cast<QContactUrl>(urlDetail);
    QVERIFY(fetchedUrl.url() == "http://dummy");    

    //save a contact with one preferred details for several actions
    QContact c2;
    c2.setType(QContactType::TypeContact);
    c2.saveDetail(&number1);
    c2.setPreferredDetail("call", number1);
    c2.setPreferredDetail("videocall", number1);
    c2.setPreferredDetail("message", number1);

    QVERIFY(m_engine->saveContact(&c2, &err));
    QVERIFY(err == QContactManager::NoError);

    //fetch the saved contact and check preferred details
    QContact fetched2 = m_engine->contact(c2.localId(), hint, &err);
    QVERIFY(err == QContactManager::NoError);

    QContactDetail callDetail4 = fetched2.preferredDetail("call");
    QVERIFY(callDetail4.definitionName() == QContactPhoneNumber::DefinitionName);
    QContactPhoneNumber fetchedNumber4 = static_cast<QContactPhoneNumber>(callDetail4);
    QVERIFY(fetchedNumber4.number() == "123");

    QContactDetail callDetail5 = fetched2.preferredDetail("videocall");
    QVERIFY(callDetail5.definitionName() == QContactPhoneNumber::DefinitionName);
    QContactPhoneNumber fetchedNumber5 = static_cast<QContactPhoneNumber>(callDetail5);
    QVERIFY(fetchedNumber5.number() == "123");

    QContactDetail callDetail6 = fetched2.preferredDetail("message");
    QVERIFY(callDetail6.definitionName() == QContactPhoneNumber::DefinitionName);
    QContactPhoneNumber fetchedNumber6 = static_cast<QContactPhoneNumber>(callDetail6);
    QVERIFY(fetchedNumber6.number() == "123");
}
QList<CContactItemField *> CntTransformOnlineAccount::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactOnlineAccount::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to phonenumber
	const QContactOnlineAccount &onlineAccount(static_cast<const QContactOnlineAccount&>(detail));

	//get the subType
	QStringList subTypes = onlineAccount.subTypes();

	//create new field
	TPtrC fieldText(reinterpret_cast<const TUint16*>(onlineAccount.accountUri().utf16()));
	if(fieldText.Length()) {
        HBufC* detailCount = HBufC::NewLC(KMaxDetailCounterLength);
        detailCount->Des().AppendNum(m_detailCounter);
	
	    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText);
	    newField->TextStorage()->SetTextL(fieldText);

	    //no subtype
	    if(!subTypes.count())
	    {
	        User::LeaveIfError(KErrArgument);
	    }

	    // online account
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeImpp))
	    {
	        newField->AddFieldTypeL(KUidContactFieldIMPP);
	        newField->SetMapping(KUidContactFieldVCardMapUnknown);
	    }

	    //internet
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeSipVoip))
	    {
	        newField->AddFieldTypeL(KUidContactFieldSIPID);
	        newField->SetMapping(KUidContactFieldVCardMapSIPID);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapVOIP);
	    }

	    //share video
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeVideoShare))
	    {
	        newField->AddFieldTypeL(KUidContactFieldSIPID);
	        newField->SetMapping(KUidContactFieldVCardMapSIPID);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapSWIS);
	    }

	    //sip
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeSip))
	    {
	        newField->AddFieldTypeL(KUidContactFieldSIPID);
	        newField->SetMapping(KUidContactFieldVCardMapSIPID);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapSIPID);
	    }

	    else
	    {
	        User::LeaveIfError(KErrNotSupported);
	    }

	    //contexts
	    setContextsL(onlineAccount, *newField);

	    newField->SetLabelL(*detailCount);
	    fieldList.append(newField);
	    CleanupStack::Pop(newField);
	    
        // Transform Service Provider Text
	    TPtrC ServiceProviderText(reinterpret_cast<const TUint16*>(onlineAccount.serviceProvider().utf16()));
	    if(ServiceProviderText.Length()) {
            CContactItemField* serviceProviderField = CContactItemField::NewLC(KStorageTypeText);
	        serviceProviderField->TextStorage()->SetTextL(ServiceProviderText);
	        serviceProviderField->AddFieldTypeL(KUidContactFieldServiceProvider);
	        serviceProviderField->SetLabelL(*detailCount);
	        fieldList.append(serviceProviderField);
	        CleanupStack::Pop(serviceProviderField);
	    }
	    CleanupStack::PopAndDestroy(detailCount);
	}

	if(fieldList.count() > 0) {
        m_detailCounter++;
	}
	    
	return fieldList;
}
Esempio n. 23
0
QList<CContactItemField *> CntTransformPhoneNumber::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactPhoneNumber::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to phonenumber
	const QContactPhoneNumber &phoneNumber(static_cast<const QContactPhoneNumber&>(detail));

	//get the subType
	QStringList subTypes = phoneNumber.subTypes();

	//create new field
	TPtrC fieldText(reinterpret_cast<const TUint16*>(phoneNumber.number().utf16()));
	if(fieldText.Length()) {
	    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText);
	    newField->TextStorage()->SetTextL(fieldText);

	    //no subtype
	    if(!subTypes.count())
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	    }

	    //landline
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeLandline))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapVOICE);
	    }

	    //mobile
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeMobile))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapCELL);
	    }

	    //fax
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeFax))
	    {
	        newField->AddFieldTypeL(KUidContactFieldFax);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapFAX);
	    }

	    //pager
	    else if (subTypes.contains(QContactPhoneNumber::SubTypePager))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapPAGER);
	    }

	    //bbs
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeBulletinBoardSystem))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapBBS);
	    }

	    //car
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeCar))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapCAR);
	    }

	    //DTMF
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeDtmfMenu))
	    {
	        newField->AddFieldTypeL(KUidContactFieldDTMF);
	        newField->SetMapping(KUidContactFieldVCardMapUnknown);
	    }

	    // assistant number
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeAssistant))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapAssistantTel);
	    }
        
	    // video calls
        else if (subTypes.contains(QContactPhoneNumber::SubTypeVideo))
        {
            newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
            newField->SetMapping(KUidContactFieldVCardMapTEL);
            newField->AddFieldTypeL(KUidContactFieldVCardMapVIDEO);
        }
	    else
	    {
	        User::LeaveIfError(KErrNotSupported);
	    }

	    //contexts
	    setContextsL(phoneNumber, *newField);

	    fieldList.append(newField);
	    CleanupStack::Pop(newField);
	}

	return fieldList;
}
Esempio n. 24
0
void tst_QContactDetail::classHierarchy()
{
    QContactDetail f1;
    QContactDetail f2;

    QVERIFY(f1.isEmpty());
    QVERIFY(f2.isEmpty());

    QContactPhoneNumber p1;
    p1.setNumber("123456");
    QVERIFY(!p1.isEmpty());
    QVERIFY(p1.definitionName() == QContactPhoneNumber::DefinitionName);

    QContactName m1;
    m1.setFirstName("Bob");
    QVERIFY(!m1.isEmpty());
    QVERIFY(m1.definitionName() == QContactName::DefinitionName);

    QVERIFY(p1 != m1);
    QVERIFY(f1 == f2);

    f1 = p1; // f1 is a phonenumber
    QVERIFY(f1 == p1);

    f1 = f1; // assign to itself
    QVERIFY(f1 == f1);
    QVERIFY(f1 == p1);
    QVERIFY(f1 != f2);
    QVERIFY(p1 != f2);

    p1 = p1; // assign leaf class to itself
    QVERIFY(p1 == p1);
    QVERIFY(f1 == p1);
    QVERIFY(p1 == f1);

    f2 = f1; // f2 = f1 = phonenumber
    QVERIFY(f1 == f2);
    QVERIFY(f2 == f1);
    QVERIFY(f2 == p1);
    QVERIFY(f1 == p1);

    f1 = m1; // f1 = name, f2 = phonenumber
    QVERIFY(f1 == m1);
    QVERIFY(f1 != f2);
    QVERIFY(f2 == p1);

    QContactPhoneNumber p2(f2); // p2 = f2 = phonenumber
    QVERIFY(p1 == p2);
    QVERIFY(p1 == f2);
    QCOMPARE(p2.number(), p1.number());
    QCOMPARE(p2.number(), QString("123456"));

    p2 = p1; // phone number to phone number
    QVERIFY(p1 == p2);
    QVERIFY(p1 == f2);
    QCOMPARE(p2.number(), p1.number());
    QCOMPARE(p2.number(), QString("123456"));

    p2.setNumber("5678"); // NOTE: implicitly shared, this has caused a detach so p1 != 2
    QVERIFY(p1 != p2);
    QVERIFY(p1 == f2);
    QVERIFY(p2 != f2);
    QCOMPARE(p2.number(), QString("5678"));
    QCOMPARE(p1.number(), QString("123456"));

    /* Bad assignment */
    p2 = m1; // assign a name to a phone number
    QVERIFY(p2 != m1);
    QVERIFY(p2.definitionName() == QContactPhoneNumber::DefinitionName); // should still be a phone number though
    QVERIFY(p2.isEmpty());

    /* copy ctor */
    QContactName m2(m1);
    QVERIFY(m2 == m1);

    /* another bad assignment */
    m2 = p2; // phone number to a name
    QVERIFY(m2 != m1);
    QVERIFY(m2.definitionName() == QContactName::DefinitionName);
    QVERIFY(m2.isEmpty());

    /* Check contexts are considered for equality */
    p2 = QContactPhoneNumber(); // new id / detach
    p2.setNumber(p1.number());
    p2.setContexts(QContactDetail::ContextHome);
    QVERIFY(p1 != p2);
    p2.removeValue(QContactDetail::FieldContext); // note, context is a value.
    QVERIFY(p1 == p2); // different ids but same values should be equal

    /* Copy ctor from valid type */
    QContactDetail f3(p2);
    QVERIFY(f3 == p2);
    QVERIFY(f3.definitionName() == QContactPhoneNumber::DefinitionName);

    /* Copy ctor from invalid type */
    QContactPhoneNumber p3(m1);
    QVERIFY(p3 != m1);
    QVERIFY(p3.definitionName() == QContactPhoneNumber::DefinitionName);
    QVERIFY(p3.isEmpty());

    /* Copy ctore from invalid type, through base type */
    f3 = m1;
    QContactPhoneNumber p4(f3);
    QVERIFY(p4 != f3);
    QVERIFY(p4.definitionName() == QContactPhoneNumber::DefinitionName);
    QVERIFY(p4.isEmpty());

    /* Try a reference */
    p1.setNumber("123456");
    QContactDetail& ref = p1;
    QVERIFY(p1.number() == "123456");
    QVERIFY(p1.value(QContactPhoneNumber::FieldNumber) == "123456");
    QVERIFY(ref.value(QContactPhoneNumber::FieldNumber) == "123456");
    QVERIFY(p1 == ref);
    QVERIFY(ref == p1);

    /* Try changing the original */
    p1.setNumber("56789");
    QVERIFY(p1.number() == "56789");
    QVERIFY(p1.value(QContactPhoneNumber::FieldNumber) == "56789");
    QVERIFY(ref.value(QContactPhoneNumber::FieldNumber) == "56789");
    QVERIFY(p1 == ref);
    QVERIFY(ref == p1);

    /* Try changing the reference */
    ref.setValue(QContactPhoneNumber::FieldNumber, "654321");
    QVERIFY(p1.number() == "654321");
    QVERIFY(p1.value(QContactPhoneNumber::FieldNumber) == "654321");
    QVERIFY(ref.value(QContactPhoneNumber::FieldNumber) == "654321");
    QVERIFY(p1 == ref);
    QVERIFY(ref == p1);

    /* Random other test */
    NonMacroCustomDetail md;
    QVERIFY(md.definitionName() == "malicious");
    QVERIFY(md.setValue("key", "value"));
    QVERIFY(!md.isEmpty());
    md.doAssign(md); // self assignment
    QVERIFY(!md.isEmpty());
    QVERIFY(md.value("key") == "value");

    QContactDetail mdv;
    mdv = md;
    QVERIFY(mdv.definitionName() == "malicious");
    QVERIFY(mdv.value("key") == "value");

    md = mdv;
    QVERIFY(md.definitionName() == "malicious");
    QVERIFY(md.value("key") == "value");

    NonMacroCustomDetail2 md2;
    QVERIFY(md2.setValue("key", "value"));
    QVERIFY(md2.definitionName() == "malicious");
    QVERIFY(md2.value("key") == "value");
    md2.doAssign(md);
    QVERIFY(md2 == md);
    md2 = md;
    QVERIFY(md.definitionName() == "malicious");
    QVERIFY(md.value("key") == "value");

    // Self assignment
    md2.doAssign(md2);
    QVERIFY(md2.definitionName() == "malicious");
    QVERIFY(md2.value("key") == "value");

    md.doAssign(md2);
    QVERIFY(md == md2);

    // Assigning something else
    QContactPhoneNumber pn;
    pn.setNumber("12345");
    md2.doAssign(pn);
    QVERIFY(md2.isEmpty());
    QVERIFY(md2.definitionName() == "malicious");

    NonMacroCustomDetail mdb(pn);
    QVERIFY(mdb.isEmpty());
    QVERIFY(mdb.definitionName() == "malicious");

    NonMacroCustomDetail2 md2b(pn);
    QVERIFY(md2b.isEmpty());
    QVERIFY(md2b.definitionName() == "malicious");
}