diff options
| author | Michael Goddard <michael.goddard@nokia.com> | 2010-04-12 17:12:06 +1000 |
|---|---|---|
| committer | Michael Goddard <michael.goddard@nokia.com> | 2010-04-13 16:46:56 +1000 |
| commit | b9b40f7113642c350d57386ce4519eb3bddb1ac0 (patch) | |
| tree | e57a1f52b9fa6e1ff5006a541ce2760878457743 /doc/src/snippets/qtcontactsdocsample/qtcontactsdocsample.cpp | |
| parent | b2aeca3bed03418ea74cec93fff5faa07d7949b1 (diff) | |
Update the QContact documentation.
Added more snippets, a better overview etc.
Task-number: MOBILITY-812
Diffstat (limited to 'doc/src/snippets/qtcontactsdocsample/qtcontactsdocsample.cpp')
| -rw-r--r-- | doc/src/snippets/qtcontactsdocsample/qtcontactsdocsample.cpp | 90 |
1 files changed, 80 insertions, 10 deletions
diff --git a/doc/src/snippets/qtcontactsdocsample/qtcontactsdocsample.cpp b/doc/src/snippets/qtcontactsdocsample/qtcontactsdocsample.cpp index 263f4df4c0..39d9d6992f 100644 --- a/doc/src/snippets/qtcontactsdocsample/qtcontactsdocsample.cpp +++ b/doc/src/snippets/qtcontactsdocsample/qtcontactsdocsample.cpp @@ -312,24 +312,29 @@ void addContact(QContactManager* cm) } //! [Creating a new contact] -//! [Calling an existing contact] void callContact(QContactManager* cm) { QList<QContactLocalId> contactIds = cm->contactIds(); QContact a = cm->contact(contactIds.first()); /* Get this contact's first phone number */ - QContactPhoneNumber phn = a.detail<QContactPhoneNumber>(); - if (!phn.isEmpty()) { - // First, we need some way of retrieving the QObject which provides the action. - // This may be through the (previously announced) Qt Service Framework: - //QServiceManager* manager = new QServiceManager(); - //QObject* dialer = manager->loadInterface("com.nokia.qt.mobility.contacts.Dialer"); - //QContactAction* dialerImpl = static_cast<QContactAction*>dialer; - //dialerImpl->invokeAction(a, phn); + QContactAction* action = 0; + QContact contact; + + //! [Details with action] + QList<QContactDetail> details = contact.detailsWithAction("Call"); + + if (details.count() == 0) { + // Can't call this contact + } else if (details.count() == 1) { + // Just call this specific detail + action->invokeAction(contact, details.first()); + } else { + // Offer the user the choice of details to call + // ... } + //! [Details with action] } -//! [Calling an existing contact] //! [Filtering by definition and value] void matchCall(QContactManager* cm, const QString& incomingCallNbr) @@ -507,6 +512,31 @@ void editView(QContactManager* cm) } //! [Modifying an existing contact] +void displayLabel() +{ + QContactManager *manager; + QContactLocalId myId; +//! [Updating the display label of a contact] + /* Retrieve a contact */ + QContact c = manager->contact(myId); + qDebug() << "Current display label" << c.displayLabel(); + + /* Update some fields that might influence the display label */ + QContactName name = c.detail<QContactName>(); + name.setFirstName("Abigail"); + name.setLastName("Arkansas"); + c.saveDetail(&name); + + /* At this point the display label is not updated, so print what the new one would be if we save it */ + qDebug() << "New label would be:" << manager->synthesizedDisplayLabel(c); + + /* Now save it */ + manager->saveContact(&c); + + qDebug() << "Now the label is:" << c.displayLabel(); +//! [Updating the display label of a contact] +} + //! [Asynchronous contact request] void RequestExample::performRequest() { @@ -549,6 +579,46 @@ void RequestExample::stateChanged(QContactAbstractRequest::State state) } //! [Asynchronous contact request] + +void shortsnippets() +{ + QContact contact; + QContact groupContact; + { + //! [0] + QContactDetail detail = contact.detail(QContactName::DefinitionName); + //! [0] + //! [1] + QContactName name = contact.detail<QContactName>(); + //! [1] + //! [2] + QList<QContactDetail> details = contact.details(QContactPhoneNumber::DefinitionName); + //! [2] + //! [3] + QList<QContactPhoneNumber> phoneNumbers = contact.details<QContactPhoneNumber>(); + //! [3] + //! [4] + QList<QContactPhoneNumber> homePhones = contact.details<QContactPhoneNumber>("Context", "Home"); + //! [4] + //! [5] + QList<QContactRelationship> spouseRelationships = contact.relationships(QContactRelationship::HasSpouse); + // For each relationship in spouseRelationships, contact.id() will either be first() or second() + //! [5] + //! [6] + // Who are the members of a group contact? + QList<QContactId> groupMembers = groupContact.relatedContacts(QContactRelationship::HasMember, QContactRelationship::Second); + // What groups is this contact in? + QList<QContactId> contactGroups = contact.relatedContacts(QContactRelationship::HasMember, QContactRelationship::First); + // An alternative to QContact::relationships() + QList<QContactId> spouses = contact.relatedContacts(QContactRelationship::HasSpouse, QContactRelationship::Either); + if (spouses.count() > 1) { + // Custom relationship type + QList<QContactId> therapists = contact.relatedContacts("HasTherapist", QContactRelationship::Second); + } + //! [6] + } +} + void loadManager() { //! [Loading a specific manager backend] |
