本文整理汇总了C++中QContactName::setFirstName方法的典型用法代码示例。如果您正苦于以下问题:C++ QContactName::setFirstName方法的具体用法?C++ QContactName::setFirstName怎么用?C++ QContactName::setFirstName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QContactName
的用法示例。
在下文中一共展示了QContactName::setFirstName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testChangeName
void TestBirthdayPlugin::testChangeName()
{
const QString contactID = QUuid::createUuid().toString();
const QDateTime contactBirthDate = QDateTime::currentDateTime();
// Add contact with birthday to tracker.
QContactName contactName;
contactName.setFirstName(contactID);
QContactBirthday contactBirthday;
contactBirthday.setDateTime(contactBirthDate);
QContact contact;
QVERIFY(contact.saveDetail(&contactName));
QVERIFY(contact.saveDetail(&contactBirthday));
QVERIFY2(mManager->saveContact(&contact), "Error saving contact to tracker");
// Wait until calendar event gets to calendar.
loopWait(calendarTimeout);
// Open calendar database.
mKCal::ExtendedCalendar::Ptr calendar =
mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
mKCal::ExtendedStorage::Ptr storage =
mKCal::ExtendedCalendar::defaultStorage(calendar);
storage->open();
QVERIFY2(not storage->notebook(calNotebookId).isNull(), "No calendar database found");
// Check calendar database for contact.
QVERIFY2(storage->loadNotebookIncidences(calNotebookId), "Unable to load events from notebook");
KCalCore::Event::List eventList = calendar->events();
QCOMPARE(countCalendarEvents(eventList, contact), 1);
// Change the contact name and see if the calendar is updated.
const QString newContactID = QUuid::createUuid().toString();
contactName.setFirstName(newContactID);
QVERIFY(contact.saveDetail(&contactName));
// TODO: Should it be necessary to refetch the contact to get the synthesised displayLabel?
contact = mManager->contact(apiId(contact));
QVERIFY2(mManager->saveContact(&contact), "Unable to update test contact in tracker");
// Wait until calendar event gets to calendar.
loopWait(calendarTimeout);
// Search for any events in the calendar.
QVERIFY2(storage->loadNotebookIncidences(calNotebookId), "Unable to load events from notebook");
eventList = calendar->events();
QCOMPARE(countCalendarEvents(eventList, contact), 1);
// Close the calendar.
QVERIFY2(storage->close(), "Error closing the calendar");
}
示例2: createSimpleContacts
void SymbianPluginPerfomance::createSimpleContacts()
{
// Create N contacts
QList<QContact> contactsList;
for(int i=0; i<NO_OF_CONTACTS; i++) {
QString c = QString::number(i);
QString first("Alice");
QContact alice;
// Contact details
QContactName aliceName;
aliceName.setFirstName(first.append(c));
alice.saveDetail(&aliceName);
contactsList.append(alice);
}
// Save the contacts
mTime.start();
mCntMng->saveContacts(&contactsList, 0);
int elapsed = mTime.elapsed();
qDebug() << "Created " << contactsList.count() << " simple contacts in"
<< elapsed / 1000 << "s" << elapsed % 1000 << "ms";
}
示例3: exportOwnContact
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);
}
示例4: setFirstName
void SeasideCache::setFirstName(FilterType filterType, int index, const QString &firstName)
{
#ifdef USING_QTPIM
CacheItem &cacheItem = m_cache[m_cacheIndices[m_contacts[filterType].at(index)]];
#else
CacheItem &cacheItem = m_cache[m_contacts[filterType].at(index) - 1];
#endif
QContactName name = cacheItem.contact.detail<QContactName>();
name.setFirstName(firstName);
cacheItem.contact.saveDetail(&name);
QString fullName = name.firstName() + QChar::fromLatin1(' ') + name.lastName();
cacheItem.nameGroup = determineNameGroup(&cacheItem);
cacheItem.displayLabel = fullName;
ItemListener *listener(cacheItem.listeners);
while (listener) {
listener->itemUpdated(&cacheItem);
listener = listener->next;
}
if (m_models[filterType])
m_models[filterType]->sourceDataChanged(index, index);
}
示例5: testExporterPlugins
void tst_QVersitContactPlugins::testExporterPlugins() {
QVersitContactExporter exporter("Test");
QContact contact;
QContactName name;
name.setFirstName("first name");
contact.saveDetail(&name);
QVERIFY(exporter.exportContacts(QList<QContact>() << contact));
QCOMPARE(exporter.documents().size(), 1);
QList<QVersitProperty> properties(exporter.documents().first().properties());
// The plugins have had their index set such that they should be executed in reverse order
// Check that they are all loaded, and run in the correct order
int n = 0;
foreach (QVersitProperty property, properties) {
if (property.name() == "TEST-PROPERTY") {
switch (n) {
case 0: QCOMPARE(property.value(), QLatin1String("5")); break;
case 1: QCOMPARE(property.value(), QLatin1String("4")); break;
case 2: QCOMPARE(property.value(), QLatin1String("3")); break;
case 3: QCOMPARE(property.value(), QLatin1String("2")); break;
case 4: QCOMPARE(property.value(), QLatin1String("1")); break;
}
n++;
}
}
QCOMPARE(n, 5);
}
示例6: setFirstName
void SeasidePerson::setFirstName(const QString &name)
{
QContactName nameDetail = mContact.detail<QContactName>();
nameDetail.setFirstName(name);
mContact.saveDetail(&nameDetail);
emit firstNameChanged();
recalculateDisplayLabel();
}
示例7: testLeapYears
void TestBirthdayPlugin::testLeapYears()
{
const QString contactID = QUuid::createUuid().toString();
QFETCH(QDate, contactBirthDate);
// Add contact with birthday to tracker.
QContactName contactName;
contactName.setFirstName(contactID);
QContactBirthday contactBirthday;
contactBirthday.setDate(contactBirthDate);
QContact contact;
QVERIFY(contact.saveDetail(&contactName));
QVERIFY(contact.saveDetail(&contactBirthday));
QVERIFY(saveContact(contact));
// Wait until calendar event gets to calendar.
loopWait(calendarTimeout);
// Open calendar database.
mKCal::ExtendedCalendar::Ptr calendar =
mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
mKCal::ExtendedStorage::Ptr storage =
mKCal::ExtendedCalendar::defaultStorage(calendar);
QVERIFY(storage->open());
QVERIFY(not storage->notebook(calNotebookId).isNull());
// Check calendar database for contact.
QVERIFY(storage->loadNotebookIncidences(calNotebookId));
const KCalCore::Event::List eventList = findCalendarEvents(calendar->events(), contact);
QCOMPARE(eventList.count(), 1);
const KCalCore::Event::Ptr event = eventList.first();
QCOMPARE(event->summary(), contactID);
QCOMPARE(event->dtStart().date(), contactBirthDate);
QCOMPARE(event->allDay(), true);
// Check number of recurrences and their values.
const KDateTime first(QDate(2000, 1, 1), QTime(), KDateTime::ClockTime);
const KDateTime last(QDate(2020, 12, 31), QTime(), KDateTime::ClockTime);
const KCalCore::DateTimeList instances = event->recurrence()->timesInInterval(first, last);
QCOMPARE(instances.length(), 13);
for(int i = 0; i < instances.length(); ++i) {
QCOMPARE(instances.at(i).date(), contactBirthDate.addYears(i));
}
}
示例8: error
/*!
* The leaving function that queries the SQL database
*
* \a aSqlQuery An SQL query
* \return the list of matched contact ids
*/
QList<QContact> CntSymbianSrvConnection::searchContactNamesL(const TDesC& aSqlQuery)
{
readContactsToBufferL(aSqlQuery, CntSymbianSrvConnection::CntSearchResultList);
RBufReadStream readStream;
QList<QContact> contacts;
TInt id;
TBuf<256> firstName;
TBuf<256> lastName;
TBuf<256> company;
readStream.Open(*m_buffer);
while ((id = readStream.ReadInt32L()) != 0) {
readStream >> firstName;
readStream >> lastName;
readStream >> company;
QContact contact, tempContact;
QContactName name;
name.setFirstName(QString::fromUtf16(firstName.Ptr(), firstName.Length()));
name.setLastName(QString::fromUtf16(lastName.Ptr(), lastName.Length()));
tempContact.saveDetail(&name);
QContactOrganization organization;
organization.setName(QString::fromUtf16(company.Ptr(), company.Length()));
tempContact.saveDetail(&organization);
QContactManager::Error error(QContactManager::NoError);
QString label = m_manager->synthesizedDisplayLabel(tempContact, &error);
if (error != QContactManager::NoError) {
continue;
}
tempContact.clearDetails();
m_manager->setContactDisplayLabel(&contact, label);
QContactId contactId;
contactId.setLocalId(id);
contactId.setManagerUri(m_manager->managerUri());
contact.setId(contactId);
contacts << contact;
}
return contacts;
}
示例9: testAddAndRemoveBirthday
void TestBirthdayPlugin::testAddAndRemoveBirthday()
{
const QString contactID = QUuid::createUuid().toString();
const QDateTime contactBirthDate = QDateTime::currentDateTime();
// Add contact with birthday to tracker.
QContactName contactName;
contactName.setFirstName(contactID);
QContactBirthday contactBirthday;
contactBirthday.setDateTime(contactBirthDate);
QContact contact;
QVERIFY(contact.saveDetail(&contactName));
QVERIFY(contact.saveDetail(&contactBirthday));
QVERIFY2(mManager->saveContact(&contact), "Error saving contact to tracker");
// Wait until calendar event gets to calendar.
loopWait(calendarTimeout);
// Open calendar database, which should have been created by the birthday plugin.
mKCal::ExtendedCalendar::Ptr calendar =
mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
mKCal::ExtendedStorage::Ptr storage =
mKCal::ExtendedCalendar::defaultStorage(calendar);
storage->open();
QVERIFY2(not storage->notebook(calNotebookId).isNull(), "No calendar database found");
// Check calendar database for contact.
QVERIFY2(storage->loadNotebookIncidences(calNotebookId), "Unable to load events from notebook");
KCalCore::Event::List eventList = calendar->events();
QCOMPARE(countCalendarEvents(eventList, contact), 1);
// Delete the contact and see if the birthday is also deleted.
QVERIFY2(mManager->removeContact(apiId(contact)), "Unable to delete test contact from tracker database");
// Wait until calendar event gets to calendar.
loopWait(calendarTimeout);
// Search for any events in the calendar.
QVERIFY2(storage->loadNotebookIncidences(calNotebookId), "Unable to load events from notebook");
eventList = calendar->events();
QCOMPARE(countCalendarEvents(eventList, contact), 0);
// Close the calendar.
QVERIFY2(storage->close(), "Error closing the calendar");
}
示例10: exportExample
void exportExample()
{
//! [Export example]
QVersitContactExporter contactExporter;
QContact contact;
// Create a name
QContactName name;
name.setFirstName(QString::fromAscii("John"));
contact.saveDetail(&name);
if (!contactExporter.exportContacts(QList<QContact>() << contact, QVersitDocument::VCard30Type))
return;
QList<QVersitDocument> versitDocuments = contactExporter.documents();
// detailHandler.mUnknownDetails now contains the list of unknown details
//! [Export example]
}
示例11: 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);
}
}
示例12: if
QContactDetail *CntTransformName::transformItemField(const CContactItemField& field, const QContact &contact)
{
QContactName *name = new QContactName(contact.detail<QContactName>());
CContactTextField* storage = field.TextStorage();
QString nameValue = QString::fromUtf16(storage->Text().Ptr(), storage->Text().Length());
for (int i = 0; i < field.ContentType().FieldTypeCount(); i++) {
//Prefix
if (field.ContentType().FieldType(i) == KUidContactFieldPrefixName) {
name->setPrefix(nameValue);
}
//First name
else if (field.ContentType().FieldType(i) == KUidContactFieldGivenName) {
name->setFirstName(nameValue);
}
//Middle name
else if (field.ContentType().FieldType(i) == KUidContactFieldAdditionalName) {
name->setMiddleName(nameValue);
}
//Last name
else if (field.ContentType().FieldType(i) == KUidContactFieldFamilyName) {
name->setLastName(nameValue);
}
//Suffix
else if (field.ContentType().FieldType(i) == KUidContactFieldSuffixName) {
name->setSuffix(nameValue);
}
// custom label
else if (field.ContentType().FieldType(i) == KUidContactFieldTemplateLabel) {
name->setCustomLabel(nameValue);
}
}
return name;
}
示例13: 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;
}
示例14: 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));
}
示例15: 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);
//.........这里部分代码省略.........