本文整理汇总了C++中QContactPhoneNumber::setNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ QContactPhoneNumber::setNumber方法的具体用法?C++ QContactPhoneNumber::setNumber怎么用?C++ QContactPhoneNumber::setNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QContactPhoneNumber
的用法示例。
在下文中一共展示了QContactPhoneNumber::setNumber方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
bool CntSimStorePrivate::read(int index, int numSlots, QContactManager::Error *error)
{
if (IsActive()) {
*error = QContactManager::LockedError;
return false;
}
// ON store requires different read approach.
// fetch ON contacts synchronously since there are usually only couple of them
if (m_storeInfo.m_storeName == KParameterValueSimStoreNameOn) {
TRequestStatus status;
QList<QContact> fetchedContacts;
for (int i = index; i <= numSlots; i++) {
RMobileONStore::TMobileONEntryV1 onEntry;
onEntry.iIndex = i;
RMobileONStore::TMobileONEntryV1Pckg onEntryPkg(onEntry);
m_etelOnStore.Read(status, onEntryPkg);
User::WaitForRequest(status);
if (status.Int() == KErrNone) {
QContact c;
c.setType(QContactType::TypeContact);
QContactName name;
name.setCustomLabel(QString::fromUtf16(onEntry.iText.Ptr(),
onEntry.iText.Length()));
c.saveDetail(&name);
QContactPhoneNumber number;
number.setNumber(QString::fromUtf16(onEntry.iNumber.iTelNumber.Ptr(),
onEntry.iNumber.iTelNumber.Length()));
c.saveDetail(&number);
QScopedPointer<QContactId> contactId(new QContactId());
contactId->setLocalId(i);
contactId->setManagerUri(m_managerUri);
c.setId(*contactId);
fetchedContacts.append(c);
}
}
emit m_simStore.readComplete(fetchedContacts, QContactManager::NoError);
*error = QContactManager::NoError;
return true;
}
// start reading
m_buffer.Zero();
m_buffer.ReAlloc(KOneSimContactBufferSize*numSlots);
m_etelStore.Read(iStatus, index, numSlots, m_buffer);
SetActive();
m_state = ReadState;
*error = QContactManager::NoError;
return true;
}
示例2: phonenumberNoMessageSupport
void TestCntActions::phonenumberNoMessageSupport()
{
QContactPhoneNumber faxNumber;
faxNumber.setNumber("555111222");
faxNumber.setSubTypes(QContactPhoneNumber::SubTypeFacsimile);
QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors("message", "symbian");
QContactAction* contactAction = QContactAction::action(actionDescriptors.first());
bool isSupportDetail = contactAction->isDetailSupported(faxNumber);
delete contactAction;
QVERIFY(isSupportDetail == false);
}
示例3: phonenumberCallSupport
void TestCntActions::phonenumberCallSupport()
{
QContact contact;
//Add phonenumber to contact
QContactPhoneNumber number;
number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
number.setNumber("555111222");
contact.saveDetail(&number);
m_manager->saveContact(&contact);
//verify that the contact has a phonenumber
QList<QContactPhoneNumber> numberList = contact.details<QContactPhoneNumber>();
QVERIFY(numberList.count() > 0);
//get the actions
QList<QContactActionDescriptor> actionDescriptors = contact.availableActions();
QStringList actions;
for (int i = 0;i < actionDescriptors.count();i++)
{
QString action = actionDescriptors.at(i).actionName();
actions << action;
}
//verify that it includes the actiosn
QVERIFY(actions.contains("call", Qt::CaseInsensitive));
//verify that the action works
QList<QContactActionDescriptor> callActionDescriptors = QContactAction::actionDescriptors("call", "symbian");
QVERIFY(callActionDescriptors.count() == 1);
QContactAction *callAction = QContactAction::action(callActionDescriptors.at(0));
QVERIFY(callAction != 0);
QContactAction::State state = callAction->state();
QVERIFY(state != QContactAction::InactiveState);
QVERIFY(callAction->isDetailSupported(numberList.at(0)) == true);
QList<QContactDetail> supportedDetails = callAction->supportedDetails(contact);
QVERIFY(supportedDetails.count() != 0);
QVariantMap variantMap = callAction->metaData();
QVERIFY(variantMap.count() == 0);
variantMap = callAction->results();
QVERIFY(variantMap.count() == 0);
QSignalSpy spyCallAction(callAction, SIGNAL(stateChanged(QContactAction::State)));
callAction->invokeAction(contact, numberList.at(0));
callAction->invokeAction(contact);
QTRY_COMPARE(spyCallAction.count(), 2); // make sure the signal was emitted exactly one time
delete callAction;
}
示例4: updateContact
void MainWindow::updateContact()
{
const QString& name = m_nameEdit->text();
const QString& phone = m_phoneEdit->text();
const QString& email = m_emailEdit->text();
if (!name.isEmpty()) {
QContactName detail = m_contact.detail<QContactName>();
detail.setFirstName(name);
m_contact.saveDetail(&detail);
}
if (!phone.isEmpty()) {
QContactPhoneNumber detail = m_contact.detail<QContactPhoneNumber>();
detail.setNumber(phone);
m_contact.saveDetail(&detail);
}
if (!email.isEmpty()) {
QContactEmailAddress detail = m_contact.detail<QContactEmailAddress>();
detail.setEmailAddress(email);
m_contact.saveDetail(&detail);
}
}
示例5: bufPtr
/*! Parses SIM contacts in TLV format.
*
* \param rawData SIM contacts in TLV format.
* \return List of contacts.
*/
QList<QContact> CntSimStorePrivate::decodeSimContactsL(TDes8& rawData) const
{
PbkPrintToLog(_L("CntSymbianSimEngine::decodeSimContactsL() - IN"));
QList<QContact> fetchedContacts;
QContact currentContact;
TBuf16<KDataClientBuf> buffer;
TPtrC16 bufPtr(buffer);
TUint8 tagValue(0);
CPhoneBookBuffer::TPhBkTagType dataType;
bool isAdditionalNumber = false;
CPhoneBookBuffer* pbBuffer = new(ELeave) CPhoneBookBuffer();
CleanupStack::PushL(pbBuffer);
pbBuffer->Set(&rawData);
pbBuffer->StartRead();
while (pbBuffer->GetTagAndType(tagValue, dataType) == KErrNone) {
switch (tagValue)
{
case RMobilePhoneBookStore::ETagPBAdnIndex:
{
//save contact's id (SIM card index) and manager's name
TUint16 index;
if (pbBuffer->GetValue(index) == KErrNone) {
QScopedPointer<QContactId> contactId(new QContactId());
contactId->setLocalId(index);
contactId->setManagerUri(m_managerUri);
currentContact.setId(*contactId);
}
isAdditionalNumber = false;
break;
}
case RMobilePhoneBookStore::ETagPBTonNpi:
{
// Note, that TON info can be incorporated into the phone number by Etel
// implementation (TSY). E.g. this is the case with Nokia TSY.
// Here general case is implemented.
// Check number type, we are only interested if it's international or not.
// We assume here that ETagPBTonNpi always comes after ETagPBNumber, not before.
TUint8 tonNpi;
if (pbBuffer->GetValue(tonNpi) == KErrNone) {
TUint8 intFlag = (tonNpi & KEtsiTonPosition) >> 4;
if (intFlag == 1) {
//international number format, append "+" to the last
//saved number
QList<QContactDetail> phoneNumbers = currentContact.details(
QContactPhoneNumber::DefinitionName);
if (phoneNumbers.count() > 0) {
QContactPhoneNumber lastNumber = static_cast<QContactPhoneNumber>(
phoneNumbers.at(phoneNumbers.count() - 1));
QString number = lastNumber.number();
number.insert(0, "+");
lastNumber.setNumber(number);
if (m_storeInfo.m_readOnlyAccess)
m_engine.setReadOnlyAccessConstraint(&lastNumber);
currentContact.saveDetail(&lastNumber);
}
}
}
// We have rearched to the end of the number,
// invalidate additional number flag.
isAdditionalNumber = false;
break;
}
case RMobilePhoneBookStore::ETagPBText:
{
if (pbBuffer->GetValue(bufPtr) == KErrNone) {
if (isAdditionalNumber) {
// For additional number bufPtr contains number alpha string,
// this is ignored currently
}
else {
// Contact name otherwise
QContactName name;
QString nameString = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
name.setCustomLabel(nameString);
if (m_storeInfo.m_readOnlyAccess)
m_engine.setReadOnlyAccessConstraint(&name);
currentContact.saveDetail(&name);
QContactManager::Error error(QContactManager::NoError);
m_engine.setContactDisplayLabel(¤tContact, m_engine.synthesizedDisplayLabel(currentContact, &error));
}
}
break;
}
case RMobilePhoneBookStore::ETagPBSecondName:
{
if (pbBuffer->GetValue(bufPtr) == KErrNone) {
QContactNickname nickName;
QString name = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
//.........这里部分代码省略.........
示例6: generateContact
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;
}
示例7: reset
void SeasideCache::reset()
{
for (int i = 0; i < FilterTypesCount; ++i) {
m_contacts[i].clear();
m_populated[i] = false;
m_models[i] = 0;
}
m_cache.clear();
m_cacheIndices.clear();
for (uint i = 0; i < sizeof(contactsData) / sizeof(Contact); ++i) {
QContact contact;
// This is specific to the qtcontacts-sqlite backend:
const QString idStr(QString::fromLatin1("qtcontacts:org.nemomobile.contacts.sqlite::sql-%1"));
contact.setId(QContactId::fromString(idStr.arg(i + 1)));
QContactName name;
name.setFirstName(QString::fromLatin1(contactsData[i].firstName));
name.setMiddleName(QString::fromUtf8(contactsData[i].middleName));
name.setLastName(QString::fromLatin1(contactsData[i].lastName));
contact.saveDetail(&name);
if (contactsData[i].avatar) {
QContactAvatar avatar;
avatar.setImageUrl(QUrl(QLatin1String(contactsData[i].avatar)));
contact.saveDetail(&avatar);
}
QContactStatusFlags statusFlags;
if (contactsData[i].email) {
QContactEmailAddress email;
email.setEmailAddress(QLatin1String(contactsData[i].email));
contact.saveDetail(&email);
statusFlags.setFlag(QContactStatusFlags::HasEmailAddress, true);
}
if (contactsData[i].phoneNumber) {
QContactPhoneNumber phoneNumber;
phoneNumber.setNumber(QLatin1String(contactsData[i].phoneNumber));
contact.saveDetail(&phoneNumber);
statusFlags.setFlag(QContactStatusFlags::HasPhoneNumber, true);
}
contact.saveDetail(&statusFlags);
m_cacheIndices.insert(internalId(contact), m_cache.count());
m_cache.append(CacheItem(contact));
QString fullName = name.firstName() + QChar::fromLatin1(' ') + name.lastName();
CacheItem &cacheItem = m_cache.last();
cacheItem.nameGroup = determineNameGroup(&cacheItem);
cacheItem.displayLabel = fullName;
}
insert(FilterAll, 0, getContactsForFilterType(FilterAll));
insert(FilterFavorites, 0, getContactsForFilterType(FilterFavorites));
insert(FilterOnline, 0, getContactsForFilterType(FilterOnline));
}
示例8: classHierarchy
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());
//.........这里部分代码省略.........
示例9: testDescriptor
void tst_QContactActions::testDescriptor()
{
// first, test retrieving an invalid action
QContactAction* invalidAction = QContactAction::action(QContactActionDescriptor());
QVERIFY(invalidAction == 0); // should be null.
QContact c;
QContactEmailAddress e;
e.setEmailAddress("[email protected]");
c.saveDetail(&e);
QContactPhoneNumber p;
p.setNumber("12345");
c.saveDetail(&p);
QVERIFY(QContactAction::availableActions().contains("SendEmail"));
QVERIFY(QContactAction::availableActions("tst_qcontactactions:sendemailaction").contains("SendEmail"));
QContactActionDescriptor sendEmailDescriptor;
QContactActionDescriptor multiActionOneDescriptor;
QContactActionDescriptor multiActionTwoDescriptor;
QList<QContactActionDescriptor> descrs = QContactAction::actionDescriptors();
QContactAction* sendEmailAction = 0;
for (int i = 0; i < descrs.size(); i++) {
QContactActionDescriptor temp = descrs.at(i);
if (temp.actionName() == QString("SendEmail")) {
sendEmailAction = QContactAction::action(temp);
QVERIFY(c.availableActions().contains(temp)); // has an email address, so should be available
QVERIFY(temp.supportsContact(c));
sendEmailDescriptor = temp;
} else if (temp.actionName() == QString("call")) {
if (temp.metaData(QString(QLatin1String("Provider"))) == QString(QLatin1String("sip"))) {
multiActionOneDescriptor = temp;
} else {
multiActionTwoDescriptor = temp;
}
}
}
QVERIFY(sendEmailDescriptor.isValid());
QVERIFY(multiActionOneDescriptor.isValid());
QVERIFY(multiActionTwoDescriptor.isValid());
QVERIFY(sendEmailAction != 0);
delete sendEmailAction;
// now test equivalence. The send email action descriptor should
// have a different action name to both multi action one and two.
QVERIFY(sendEmailDescriptor.actionName() != multiActionOneDescriptor.actionName());
QVERIFY(sendEmailDescriptor.actionName() != multiActionTwoDescriptor.actionName());
QVERIFY(sendEmailDescriptor != multiActionOneDescriptor);
QVERIFY(sendEmailDescriptor != multiActionTwoDescriptor);
// multi action one and two should have the same action name, service
// name and implementation (minor) version. BUT they have different
// implementations (Provider is different) so they should NOT be equal.
QVERIFY(multiActionOneDescriptor.actionName() == multiActionTwoDescriptor.actionName());
QVERIFY(multiActionOneDescriptor.serviceName() == multiActionTwoDescriptor.serviceName());
QVERIFY(multiActionOneDescriptor.implementationVersion() == multiActionTwoDescriptor.implementationVersion());
QVERIFY(multiActionOneDescriptor != multiActionTwoDescriptor);
// verify that the meta data is reported correctly
QVERIFY(multiActionOneDescriptor.metaData("Provider") != multiActionTwoDescriptor.metaData("Provider"));
}
示例10: addTestContact
int addTestContact(const QString &name, const QString &remoteUid, const QString &localUid)
{
QString contactUri = QString("<testcontact:%1>").arg(contactNumber++);
QContact contact;
QContactSyncTarget syncTarget;
syncTarget.setSyncTarget(QLatin1String("commhistory-tests"));
if (!contact.saveDetail(&syncTarget)) {
qWarning() << "Unable to add sync target to contact:" << contactUri;
return -1;
}
if (!localUid.isEmpty() && localUid.indexOf("/ring/tel/") == -1) {
// Create a metadata detail to link the contact with the account
QContactOriginMetadata metadata;
metadata.setGroupId(localUid);
metadata.setId(remoteUid);
metadata.setEnabled(true);
if (!contact.saveDetail(&metadata)) {
qWarning() << "Unable to add metadata to contact:" << contactUri;
return false;
}
}
QString normal = CommHistory::normalizePhoneNumber(remoteUid);
if (normal.isEmpty()) {
QContactOnlineAccount qcoa;
qcoa.setValue(QContactOnlineAccount__FieldAccountPath, localUid);
qcoa.setAccountUri(remoteUid);
if (!contact.saveDetail(&qcoa)) {
qWarning() << "Unable to add online account to contact:" << contactUri;
return -1;
}
} else {
QContactPhoneNumber phoneNumberDetail;
phoneNumberDetail.setNumber(remoteUid);
if (!contact.saveDetail(&phoneNumberDetail)) {
qWarning() << "Unable to add phone number to contact:" << contactUri;
return -1;
}
}
QContactName nameDetail;
nameDetail.setLastName(name);
if (!contact.saveDetail(&nameDetail)) {
qWarning() << "Unable to add name to contact:" << contactUri;
return -1;
}
if (!manager()->saveContact(&contact)) {
qWarning() << "Unable to store contact:" << contactUri;
return -1;
}
// We should return the aggregated instance of this contact
QContactRelationshipFilter filter;
filter.setRelatedContactRole(QContactRelationship::Second);
#ifdef USING_QTPIM
filter.setRelatedContact(contact);
filter.setRelationshipType(QContactRelationship::Aggregates());
#else
filter.setRelatedContactId(contact.id());
filter.setRelationshipType(QContactRelationship::Aggregates);
#endif
foreach (const ContactListener::ApiContactIdType &id, manager()->contactIds(filter)) {
qDebug() << "********** contact id" << id;
addedContactIds.insert(id);
return ContactListener::internalContactId(id);
}
示例11: createComplexContacts
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);
}
示例12: testRequestInfo
void TestCntPresenceInfoProvider::testRequestInfo()
{
PrcPresenceWriter *writer = PrcPresenceWriter::createWriter();
PrcPresenceBuddyInfoQt *buddy = PrcPresenceBuddyInfoQt::createInstance();
buddy->setIdentity("sip:[email protected]");
buddy->setAvailability(PrcPresenceBuddyInfoQt::PrcNotAvailable, "meh");
writer->writePresence(*buddy);
QContactManager manager("symbian");
QContact c;
QContactName name;
name.setFirstName("firstname");
name.setLastName("lastname");
c.saveDetail(&name);
QContactPhoneNumber number;
number.setNumber("1234567");
number.setContexts(QContactDetail::ContextHome);
number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
c.saveDetail(&number);
manager.saveContact(&c);
ContactInfoFields fields;
fields = ContactInfoTextField;
QSignalSpy spy(mCntPresenceInfoProvider, SIGNAL(infoFieldReady(CntInfoProvider*, int, ContactInfoField, const QString&)));
mCntPresenceInfoProvider->requestInfo(c, fields);
QCOMPARE(spy.count(), 0);
QVERIFY(mCntPresenceInfoProvider->mBuddyMap.isEmpty());
fields = ContactInfoIcon2Field;
mCntPresenceInfoProvider->requestInfo(c, fields);
QCOMPARE(spy.count(), 0);
QVERIFY(mCntPresenceInfoProvider->mBuddyMap.isEmpty());
QContactOnlineAccount account;
account.setSubTypes(QStringList() << QContactOnlineAccount::SubTypeSip);
account.setServiceProvider("sip");
account.setAccountUri("[email protected]");
c.saveDetail(&account);
QContactOnlineAccount account2;
account2.setSubTypes(QStringList() << QContactOnlineAccount::SubTypeSipVoip);
account.setServiceProvider("sip");
account2.setAccountUri("[email protected]");
c.saveDetail(&account2);
QContactOnlineAccount account3;
account3.setSubTypes(QStringList() << QContactOnlineAccount::SubTypeSip);
account3.setAccountUri("malformatted");
c.saveDetail(&account3);
manager.saveContact(&c);
mCntPresenceInfoProvider->requestInfo(c, fields);
QCOMPARE(spy.count(), 0);
QCOMPARE(mCntPresenceInfoProvider->mBuddyMap.count(), 1);
delete mCntPresenceInfoProvider;
mCntPresenceInfoProvider = NULL;
buddy->setAvailability(PrcPresenceBuddyInfoQt::PrcAvailable, "meh");
writer->writePresence(*buddy);
mCntPresenceInfoProvider = new CntPresenceInfoProvider();
QSignalSpy spy2(mCntPresenceInfoProvider, SIGNAL(infoFieldReady(CntInfoProvider*, int, ContactInfoField, const QString&)));
mCntPresenceInfoProvider->requestInfo(c, fields);
QCOMPARE(spy2.count(), 1);
QCOMPARE(mCntPresenceInfoProvider->mBuddyMap.count(), 1);
delete buddy;
delete writer;
}
示例13: performRequests
void AsyncRequestExample::performRequests()
{
//! [Creating a new contact in a manager]
QContact exampleContact;
QContactName nameDetail;
nameDetail.setFirstName("Adam");
nameDetail.setLastName("Unlikely");
QContactPhoneNumber phoneNumberDetail;
phoneNumberDetail.setNumber("+123 4567");
exampleContact.saveDetail(&nameDetail);
exampleContact.saveDetail(&phoneNumberDetail);
// save the newly created contact in the manager
connect(&m_contactSaveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(contactSaveRequestStateChanged(QContactAbstractRequest::State)));
m_contactSaveRequest.setManager(m_manager);
m_contactSaveRequest.setContacts(QList<QContact>() << exampleContact);
m_contactSaveRequest.start();
//! [Creating a new contact in a manager]
m_contactSaveRequest.waitForFinished();
//! [Creating a new contact in a manager waiting until finished]
m_contactSaveRequest.setManager(m_manager);
m_contactSaveRequest.setContacts(QList<QContact>() << exampleContact);
m_contactSaveRequest.start();
m_contactSaveRequest.waitForFinished();
QList<QContact> savedContacts = m_contactSaveRequest.contacts();
//! [Creating a new contact in a manager waiting until finished]
//! [Filtering contacts from a manager]
connect(&m_contactFetchRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(contactFetchRequestStateChanged(QContactAbstractRequest::State)));
m_contactFetchRequest.setManager(m_manager);
m_contactFetchRequest.setFilter(QContactPhoneNumber::match("+123 4567"));
m_contactFetchRequest.start();
//! [Filtering contacts from a manager]
m_contactFetchRequest.waitForFinished();
//! [Retrieving an existing contact from a manager]
QContactLocalIdFilter idListFilter;
idListFilter.setIds(QList<QContactLocalId>() << exampleContact.localId());
m_contactFetchRequest.setManager(m_manager);
m_contactFetchRequest.setFilter(idListFilter);
m_contactFetchRequest.start();
//! [Retrieving an existing contact from a manager]
m_contactFetchRequest.waitForFinished();
//! [Updating an existing contact in a manager]
phoneNumberDetail.setNumber("+123 9876");
exampleContact.saveDetail(&phoneNumberDetail);
m_contactSaveRequest.setManager(m_manager);
m_contactSaveRequest.setContacts(QList<QContact>() << exampleContact);
m_contactSaveRequest.start();
//! [Updating an existing contact in a manager]
m_contactFetchRequest.waitForFinished();
//! [Removing a contact from a manager]
connect(&m_contactRemoveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(contactRemoveRequestStateChanged(QContactAbstractRequest::State)));
m_contactRemoveRequest.setManager(m_manager);
m_contactRemoveRequest.setContactIds(QList<QContactLocalId>() << exampleContact.localId());
m_contactRemoveRequest.start();
//! [Removing a contact from a manager]
m_contactFetchRequest.waitForFinished();
//! [Creating a new relationship between two contacts]
// first, create the group and the group member
QContact exampleGroup;
exampleGroup.setType(QContactType::TypeGroup);
QContactNickname groupName;
groupName.setNickname("Example Group");
exampleGroup.saveDetail(&groupName);
QContact exampleGroupMember;
QContactName groupMemberName;
groupMemberName.setFirstName("Member");
exampleGroupMember.saveDetail(&groupMemberName);
// second, save those contacts in the manager
QList<QContact> saveList;
saveList << exampleGroup << exampleGroupMember;
m_contactSaveRequest.setContacts(saveList);
m_contactSaveRequest.start();
m_contactSaveRequest.waitForFinished();
// third, create the relationship between those contacts
QContactRelationship groupRelationship;
groupRelationship.setFirst(exampleGroup.id());
groupRelationship.setRelationshipType(QContactRelationship::HasMember);
groupRelationship.setSecond(exampleGroupMember.id());
// finally, save the relationship in the manager
connect(&m_relationshipSaveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(relationshipSaveRequestStateChanged(QContactAbstractRequest::State)));
m_relationshipSaveRequest.setManager(m_manager);
m_relationshipSaveRequest.setRelationships(QList<QContactRelationship>() << groupRelationship);
//.........这里部分代码省略.........