55 /*! |
55 /*! |
56 \class QContactManager |
56 \class QContactManager |
57 \brief The QContactManager class provides an interface which allows clients with access to contact information stored in a particular backend. |
57 \brief The QContactManager class provides an interface which allows clients with access to contact information stored in a particular backend. |
58 \ingroup contacts-main |
58 \ingroup contacts-main |
59 |
59 |
60 This class provides adding, updating and removal of contacts. |
60 This class provides an abstraction of a datastore or aggregation of datastores which contains contact information. |
61 It also provides definitions for details and fields that can be found in contacts. |
61 It provides methods to retrieve and manipulate contact information, contact relationship information, and |
|
62 supported schema definitions. It also provides metadata and error information reporting. |
|
63 |
|
64 The functions provided by QContactManager are purely synchronous; to access the same functionality in an |
|
65 asynchronous manner, clients should use the use-case-specific classes derived from QContactAbstractRequest. |
|
66 |
|
67 Some functionality provided by QContactManager directly is not accessible using the asynchronous API; see |
|
68 the \l{Contacts Synchronous API}{synchronous} and \l{Contacts Asynchronous API}{asynchronous} API |
|
69 information from the \l{Contacts}{contacts module} API documentation. |
62 */ |
70 */ |
63 |
71 |
64 /*! |
72 /*! |
65 \fn QContactManager::dataChanged() |
73 \fn QContactManager::dataChanged() |
66 This signal is emitted by the manager if its internal state changes, and it is unable to determine the changes |
74 This signal is emitted by the manager if its internal state changes, and it is unable to determine the changes |
330 /*! |
338 /*! |
331 Return the list of contact ids, sorted according to the given list of \a sortOrders |
339 Return the list of contact ids, sorted according to the given list of \a sortOrders |
332 */ |
340 */ |
333 QList<QContactLocalId> QContactManager::contactIds(const QList<QContactSortOrder>& sortOrders) const |
341 QList<QContactLocalId> QContactManager::contactIds(const QList<QContactSortOrder>& sortOrders) const |
334 { |
342 { |
|
343 d->m_error = QContactManager::NoError; |
335 return d->m_engine->contactIds(QContactFilter(), sortOrders, &d->m_error); |
344 return d->m_engine->contactIds(QContactFilter(), sortOrders, &d->m_error); |
336 } |
345 } |
337 |
346 |
338 /*! |
347 /*! |
339 Returns a list of contact ids that match the given \a filter, sorted according to the given list of \a sortOrders. |
348 Returns a list of contact ids that match the given \a filter, sorted according to the given list of \a sortOrders. |
340 Depending on the backend, this filtering operation may involve retrieving all the contacts. |
349 Depending on the backend, this filtering operation may involve retrieving all the contacts. |
341 */ |
350 */ |
342 QList<QContactLocalId> QContactManager::contactIds(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders) const |
351 QList<QContactLocalId> QContactManager::contactIds(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders) const |
343 { |
352 { |
|
353 d->m_error = QContactManager::NoError; |
344 return d->m_engine->contactIds(filter, sortOrders, &d->m_error); |
354 return d->m_engine->contactIds(filter, sortOrders, &d->m_error); |
345 } |
355 } |
346 |
356 |
347 /*! |
357 /*! |
348 Returns the list of contacts stored in the manager sorted according to the given list of \a sortOrders. |
358 Returns the list of contacts stored in the manager sorted according to the given list of \a sortOrders. |
349 |
359 |
350 The \a fetchHint parameter describes the optimization hints that a manager may take. |
360 The \a fetchHint parameter describes the optimization hints that a manager may take. |
351 If the \a fetchHint is the default constructed hint, all existing details, relationships and action preferences |
361 If the \a fetchHint is the default constructed hint, all existing details and relationships |
352 in the matching contacts will be returned. A client should not make changes to a contact which has |
362 in the matching contacts will be returned. A client should not make changes to a contact which has |
353 been retrieved using a fetch hint other than the default fetch hint. Doing so will result in information |
363 been retrieved using a fetch hint other than the default fetch hint. Doing so will result in information |
354 loss when saving the contact back to the manager (as the "new" restricted contact will |
364 loss when saving the contact back to the manager (as the "new" restricted contact will |
355 replace the previously saved contact in the backend). |
365 replace the previously saved contact in the backend). |
356 |
366 |
357 \sa QContactFetchHint |
367 \sa QContactFetchHint |
358 */ |
368 */ |
359 QList<QContact> QContactManager::contacts(const QList<QContactSortOrder>& sortOrders, const QContactFetchHint& fetchHint) const |
369 QList<QContact> QContactManager::contacts(const QList<QContactSortOrder>& sortOrders, const QContactFetchHint& fetchHint) const |
360 { |
370 { |
|
371 d->m_error = QContactManager::NoError; |
361 return d->m_engine->contacts(QContactFilter(), sortOrders, fetchHint, &d->m_error); |
372 return d->m_engine->contacts(QContactFilter(), sortOrders, fetchHint, &d->m_error); |
362 } |
373 } |
363 |
374 |
364 /*! |
375 /*! |
365 Returns a list of contacts that match the given \a filter, sorted according to the given list of \a sortOrders. |
376 Returns a list of contacts that match the given \a filter, sorted according to the given list of \a sortOrders. |
366 |
377 |
367 Depending on the manager implementation, this filtering operation might be slow and involve retrieving all the |
378 Depending on the manager implementation, this filtering operation might be slow and involve retrieving all the |
368 contacts and testing them against the supplied filter - see the \l isFilterSupported() function. |
379 contacts and testing them against the supplied filter - see the \l isFilterSupported() function. |
369 |
380 |
370 The \a fetchHint parameter describes the optimization hints that a manager may take. |
381 The \a fetchHint parameter describes the optimization hints that a manager may take. |
371 If the \a fetchHint is the default constructed hint, all existing details, relationships and action preferences |
382 If the \a fetchHint is the default constructed hint, all existing details and relationships |
372 in the matching contacts will be returned. A client should not make changes to a contact which has |
383 in the matching contacts will be returned. A client should not make changes to a contact which has |
373 been retrieved using a fetch hint other than the default fetch hint. Doing so will result in information |
384 been retrieved using a fetch hint other than the default fetch hint. Doing so will result in information |
374 loss when saving the contact back to the manager (as the "new" restricted contact will |
385 loss when saving the contact back to the manager (as the "new" restricted contact will |
375 replace the previously saved contact in the backend). |
386 replace the previously saved contact in the backend). |
376 |
387 |
377 \sa QContactFetchHint |
388 \sa QContactFetchHint |
378 */ |
389 */ |
379 QList<QContact> QContactManager::contacts(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, const QContactFetchHint& fetchHint) const |
390 QList<QContact> QContactManager::contacts(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, const QContactFetchHint& fetchHint) const |
380 { |
391 { |
|
392 d->m_error = QContactManager::NoError; |
381 return d->m_engine->contacts(filter, sortOrders, fetchHint, &d->m_error); |
393 return d->m_engine->contacts(filter, sortOrders, fetchHint, &d->m_error); |
382 } |
394 } |
383 |
395 |
384 /*! |
396 /*! |
385 Returns the contact in the database identified by \a contactId. |
397 Returns the contact in the database identified by \a contactId. |
386 |
398 |
387 If the contact does not exist, an empty, default constructed QContact will be returned, |
399 If the contact does not exist, an empty, default constructed QContact will be returned, |
388 and the error returned by \l error() will be \c QContactManager::DoesNotExistError. |
400 and the error returned by \l error() will be \c QContactManager::DoesNotExistError. |
389 |
401 |
390 The \a fetchHint parameter describes the optimization hints that a manager may take. |
402 The \a fetchHint parameter describes the optimization hints that a manager may take. |
391 If the \a fetchHint is the default constructed hint, all existing details, relationships and action preferences |
403 If the \a fetchHint is the default constructed hint, all existing details and relationships |
392 in the matching contact will be returned. A client should not make changes to a contact which has |
404 in the matching contact will be returned. A client should not make changes to a contact which has |
393 been retrieved using a fetch hint other than the default fetch hint. Doing so will result in information |
405 been retrieved using a fetch hint other than the default fetch hint. Doing so will result in information |
394 loss when saving the contact back to the manager (as the "new" restricted contact will |
406 loss when saving the contact back to the manager (as the "new" restricted contact will |
395 replace the previously saved contact in the backend). |
407 replace the previously saved contact in the backend). |
396 |
408 |
397 \sa QContactFetchHint |
409 \sa QContactFetchHint |
398 */ |
410 */ |
399 QContact QContactManager::contact(const QContactLocalId& contactId, const QContactFetchHint& fetchHint) const |
411 QContact QContactManager::contact(const QContactLocalId& contactId, const QContactFetchHint& fetchHint) const |
400 { |
412 { |
|
413 d->m_error = QContactManager::NoError; |
401 return d->m_engine->contact(contactId, fetchHint, &d->m_error); |
414 return d->m_engine->contact(contactId, fetchHint, &d->m_error); |
402 } |
415 } |
403 |
416 |
404 /*! |
417 /*! |
405 Adds the given \a contact to the database if \a contact has a |
418 Adds the given \a contact to the database if \a contact has a |
531 |
549 |
532 This function is preliminary and the behaviour is subject to change! |
550 This function is preliminary and the behaviour is subject to change! |
533 */ |
551 */ |
534 QContact QContactManager::compatibleContact(const QContact& original) |
552 QContact QContactManager::compatibleContact(const QContact& original) |
535 { |
553 { |
|
554 d->m_error = QContactManager::NoError; |
536 return d->m_engine->compatibleContact(original, &d->m_error); |
555 return d->m_engine->compatibleContact(original, &d->m_error); |
537 } |
556 } |
538 |
557 |
539 /*! |
558 /*! |
540 Returns a display label for a \a contact which is synthesized from its details in a platform-specific manner |
559 Returns a display label for a \a contact which is synthesized from its details in a manager specific |
541 */ |
560 manner. |
542 QString QContactManager::synthesizedDisplayLabel(const QContact& contact) const |
561 |
543 { |
562 If you want to update the display label stored in the contact, use the synthesizeContactDisplayLabel() |
|
563 function instead. |
|
564 |
|
565 \sa synthesizeContactDisplayLabel() |
|
566 */ |
|
567 QString QContactManager::synthesizedContactDisplayLabel(const QContact& contact) const |
|
568 { |
|
569 d->m_error = QContactManager::NoError; |
544 return d->m_engine->synthesizedDisplayLabel(contact, &d->m_error); |
570 return d->m_engine->synthesizedDisplayLabel(contact, &d->m_error); |
|
571 } |
|
572 |
|
573 /*! |
|
574 * Updates the display label of the supplied \a contact, according to the formatting rules |
|
575 * of this manager. |
|
576 * |
|
577 * Different managers can format the display label of a contact in different ways - |
|
578 * some managers may only consider first or last name, or might put them in different |
|
579 * orders. Others might consider an organization, a nickname, or a freeform label. |
|
580 * |
|
581 * This function will update the QContactDisplayLabel of this contact, and the string |
|
582 * returned by QContact::displayLabel(). |
|
583 * |
|
584 * If \a contact is null, nothing will happen. |
|
585 * |
|
586 * See the following example for more information: |
|
587 * \snippet doc/src/snippets/qtcontactsdocsample/qtcontactsdocsample.cpp Updating the display label of a contact |
|
588 * |
|
589 * \sa synthesizedContactDisplayLabel(), QContact::displayLabel() |
|
590 */ |
|
591 void QContactManager::synthesizeContactDisplayLabel(QContact *contact) const |
|
592 { |
|
593 if (contact) { |
|
594 d->m_error = QContactManager::NoError; |
|
595 QContactManagerEngine::setContactDisplayLabel(contact, d->m_engine->synthesizedDisplayLabel(*contact, &d->m_error)); |
|
596 } else { |
|
597 d->m_error = QContactManager::BadArgumentError; |
|
598 } |
545 } |
599 } |
546 |
600 |
547 /*! |
601 /*! |
548 Sets the id of the "self" contact to the given \a contactId. |
602 Sets the id of the "self" contact to the given \a contactId. |
549 Returns true if the "self" contact id was set successfully. |
603 Returns true if the "self" contact id was set successfully. |
567 the concept of a "self" contact, an invalid id will be returned |
622 the concept of a "self" contact, an invalid id will be returned |
568 and the error will be set to \c QContactManager::DoesNotExistError. |
623 and the error will be set to \c QContactManager::DoesNotExistError. |
569 */ |
624 */ |
570 QContactLocalId QContactManager::selfContactId() const |
625 QContactLocalId QContactManager::selfContactId() const |
571 { |
626 { |
|
627 d->m_error = QContactManager::NoError; |
572 return d->m_engine->selfContactId(&d->m_error); |
628 return d->m_engine->selfContactId(&d->m_error); |
573 } |
629 } |
574 |
630 |
575 |
631 |
576 /*! |
632 /*! |
577 Returns a list of relationships in which the contact identified by the given \a participantId participates in the given \a role. |
633 Returns a list of relationships in which the contact identified by the given \a participantId participates in the given \a role. |
578 If \a participantId is the default-constructed id, \a role is ignored and all relationships are returned. |
634 If \a participantId is the default-constructed id, \a role is ignored and all relationships are returned. |
579 */ |
635 */ |
580 QList<QContactRelationship> QContactManager::relationships(const QContactId& participantId, QContactRelationship::Role role) const |
636 QList<QContactRelationship> QContactManager::relationships(const QContactId& participantId, QContactRelationship::Role role) const |
581 { |
637 { |
|
638 d->m_error = QContactManager::NoError; |
582 return d->m_engine->relationships(QString(), participantId, role, &d->m_error); |
639 return d->m_engine->relationships(QString(), participantId, role, &d->m_error); |
583 } |
640 } |
584 |
641 |
585 /*! |
642 /*! |
586 Returns a list of relationships of the given \a relationshipType in which the contact identified by the given \a participantId participates in the given \a role. |
643 Returns a list of relationships of the given \a relationshipType in which the contact identified by the given \a participantId participates in the given \a role. |
587 If \a participantId is the default-constructed id, \a role is ignored and all relationships of the given \a relationshipType are returned. |
644 If \a participantId is the default-constructed id, \a role is ignored and all relationships of the given \a relationshipType are returned. |
588 If \a relationshipType is empty, relationships of any type are returned. |
645 If \a relationshipType is empty, relationships of any type are returned. |
589 */ |
646 */ |
590 QList<QContactRelationship> QContactManager::relationships(const QString& relationshipType, const QContactId& participantId, QContactRelationship::Role role) const |
647 QList<QContactRelationship> QContactManager::relationships(const QString& relationshipType, const QContactId& participantId, QContactRelationship::Role role) const |
591 { |
648 { |
|
649 d->m_error = QContactManager::NoError; |
592 return d->m_engine->relationships(relationshipType, participantId, role, &d->m_error); |
650 return d->m_engine->relationships(relationshipType, participantId, role, &d->m_error); |
593 } |
651 } |
594 |
652 |
595 /*! |
653 /*! |
596 Saves the given \a relationship in the database. If the relationship already exists in the database, this function will |
654 Saves the given \a relationship in the database. If the relationship already exists in the database, this function will |
699 if (!supportedContactTypes().contains(contactType)) { |
764 if (!supportedContactTypes().contains(contactType)) { |
700 d->m_error =QContactManager::InvalidContactTypeError; |
765 d->m_error =QContactManager::InvalidContactTypeError; |
701 return false; |
766 return false; |
702 } |
767 } |
703 |
768 |
|
769 d->m_error = QContactManager::NoError; |
704 return d->m_engine->removeDetailDefinition(definitionName, contactType, &d->m_error); |
770 return d->m_engine->removeDetailDefinition(definitionName, contactType, &d->m_error); |
705 } |
771 } |
706 |
772 |
707 /*! |
773 /*! |
708 \enum QContactManager::ManagerFeature |
774 \enum QContactManager::ManagerFeature |
709 This enum describes the possible features that a particular manager may support |
775 This enum describes the possible features that a particular manager may support |
710 \value Groups The manager supports all QContactGroup related operations, and emits the appropriate signals |
776 \value Groups The manager supports saving contacts of the \c QContactType::TypeGroup type |
711 \value ActionPreferences The manager supports saving preferred details per action per contact |
777 \omitvalue ActionPreferences The manager supports saving preferred details per action per contact |
712 \value DetailOrdering When a contact is retrieved, the manager will return the details in the same order in which they were saved |
778 \value DetailOrdering When a contact is retrieved, the manager will return the details in the same order in which they were saved |
713 \value Relationships The manager supports at least some types of relationships between contacts |
779 \value Relationships The manager supports at least some types of relationships between contacts |
714 \value ArbitraryRelationshipTypes The manager supports relationships of arbitrary types between contacts |
780 \value ArbitraryRelationshipTypes The manager supports relationships of arbitrary types between contacts |
715 \value MutableDefinitions The manager supports saving, updating or removing detail definitions. Some built-in definitions may still be immutable |
781 \value MutableDefinitions The manager supports saving, updating or removing detail definitions. Some built-in definitions may still be immutable |
716 \value SelfContact The manager supports the concept of saving a contact which represents the current user |
782 \value SelfContact The manager supports the concept of saving a contact which represents the current user |