void SeasidePerson::setPhoneNumberType(int which, SeasidePerson::DetailTypes type) { const QList<QContactPhoneNumber> &numbers = mContact.details<QContactPhoneNumber>(); if (which >= numbers.length()) { qWarning() << "Unable to set type for phone number: invalid index specified. Aborting."; return; } QContactPhoneNumber number = numbers.at(which); if (type == SeasidePerson::PhoneHomeType) { number.setSubTypes(QContactPhoneNumber::SubTypeLandline); number.setContexts(QContactDetail::ContextHome); } else if (type == SeasidePerson::PhoneWorkType) { number.setSubTypes(QContactPhoneNumber::SubTypeLandline); number.setContexts(QContactDetail::ContextWork); } else if (type == SeasidePerson::PhoneMobileType) { number.setSubTypes(QContactPhoneNumber::SubTypeMobile); number.setContexts(QContactDetail::ContextHome); } else if (type == SeasidePerson::PhoneFaxType) { number.setSubTypes(QContactPhoneNumber::SubTypeFax); number.setContexts(QContactDetail::ContextHome); } else if (type == SeasidePerson::PhonePagerType) { number.setSubTypes(QContactPhoneNumber::SubTypePager); number.setContexts(QContactDetail::ContextHome); } else { qWarning() << "Warning: Could not save phone type '" << type << "'"; } mContact.saveDetail(&number); emit phoneNumberTypesChanged(); }
void MT_CntVersitMyCardPlugin::exportOwnContact() { //create contact QContact phonecontact; QContactName contactName; contactName.setFirstName("Jo"); contactName.setLastName("Black"); phonecontact.saveDetail(&contactName); QContactPhoneNumber number; number.setContexts("Home"); number.setSubTypes("Mobile"); number.setNumber("+02644424429"); phonecontact.saveDetail(&number); //set MyCard detail QContactDetail myCard(MYCARD_DEFINTION_NAME); phonecontact.saveDetail(&myCard); //export QList<QContact> list; list.append(phonecontact); QVersitContactExporter exporter; QVERIFY(exporter.exportContacts(list, QVersitDocument::VCard21Type)); QList<QVersitDocument> documents = exporter.documents(); //X-SELF property is exported if MyCard QVersitDocument document = documents.first(); QVersitProperty property; property.setName(QLatin1String("X-SELF")); property.setValue("0"); bool propertyFound = document.properties().contains(property); QVERIFY(propertyFound); }
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 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); }
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("*****@*****.**"); c.saveDetail(&account); QContactOnlineAccount account2; account2.setSubTypes(QStringList() << QContactOnlineAccount::SubTypeSipVoip); account.setServiceProvider("sip"); account2.setAccountUri("*****@*****.**"); 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; }