CntUrlEditorModel::CntUrlEditorModel(QContact* aContact) :
    CntDetailEditorModel(aContact)
{
    mUrlList = CntDetailOrderingHelper::getOrderedUrls(*mContact);
    if (mUrlList.isEmpty()) {
        QContactUrl url;
        url.setSubType(QContactUrl::SubTypeHomePage);
        mUrlList.append(url);
    }

    foreach( QContactUrl contactUrl, mUrlList ) {
        CntDetailModelItem* item = new CntDetailModelItem(contactUrl);
        appendDataFormItem(item, invisibleRootItem());
        connect( item, SIGNAL(itemDataChanged(CntDetailModelItem*)), this, SLOT(emitDataChanged(CntDetailModelItem*)) );
    }
void TestCntActions::urlSupport()
{
    QContact contact;
    QContactUrl url;
    url.setUrl("www.test.com");
    contact.saveDetail(&url);
    m_manager->saveContact(&contact);
    
    //one number exist in contact
    QList<QContactUrl> urlList = contact.details<QContactUrl>();
    QVERIFY(urlList.count() == 1);
    
    //no actions expected
    QList<QContactActionDescriptor> actionDescriptors = contact.availableActions();
    QStringList actions;
    for (int i = 0;i < actionDescriptors.count();i++)
    {
        QString action = actionDescriptors.at(i).actionName();
        actions << action;
    }
    QVERIFY(actions.count() == 1);   
    QVERIFY(actions.contains("url", Qt::CaseInsensitive));
    
    //pick first number for the actions
    QContactUrl urlAddress = contact.detail<QContactUrl>();
        
    //Test Email action
    QList<QContactActionDescriptor> urlActionDescriptors = QContactAction::actionDescriptors("url", "symbian");
    QVERIFY(urlActionDescriptors.count() == 1);
    QContactAction *urlAction = QContactAction::action(urlActionDescriptors.at(0));
    QVERIFY(urlAction != 0);
    QVERIFY(urlAction->isDetailSupported(urlList.at(0)) == true);
    QList<QContactDetail> supportedDetails = urlAction->supportedDetails(contact);
    QVERIFY(supportedDetails.count() != 0);
    QVariantMap variantMap = urlAction->metaData();
    QVERIFY(variantMap.count() == 0);
    variantMap = urlAction->results();
    QVERIFY(variantMap.count() == 0);
    QSignalSpy spyUrlAction(urlAction, SIGNAL(stateChanged(QContactAction::State)));
    urlAction->invokeAction(contact, urlAddress);
    urlAction->invokeAction(contact);
    QTRY_COMPARE(spyUrlAction.count(), 2); // make sure the signal was emitted exactly once each time
    delete urlAction;
}
Exemple #3
0
QContactDetail *CntTransformUrl::transformItemField(const CContactItemField& field, const QContact &contact)
{
	Q_UNUSED(contact);

	QContactUrl *url = new QContactUrl();

	CContactTextField* storage = field.TextStorage();
	QString urlString = QString::fromUtf16(storage->Text().Ptr(), storage->Text().Length());

	url->setUrl(urlString);
	url->setSubType(QContactUrl::SubTypeHomePage);

	for (int i = 0; i < field.ContentType().FieldTypeCount(); i++)
	{
		setContexts(field.ContentType().FieldType(i), *url);
	}

	return url;
}
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");
}