| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtContacts module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 2.1 or version 3 as published by the Free |
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
| 22 | ** following information to ensure the GNU Lesser General Public License |
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 25 | ** |
| 26 | ** As a special exception, The Qt Company gives you certain additional |
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception |
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 29 | ** |
| 30 | ** $QT_END_LICENSE$ |
| 31 | ** |
| 32 | ****************************************************************************/ |
| 33 | |
| 34 | #include "qcontactfetchbyidrequest.h" |
| 35 | |
| 36 | #include "qcontactrequests_p.h" |
| 37 | |
| 38 | QT_BEGIN_NAMESPACE_CONTACTS |
| 39 | |
| 40 | /*! |
| 41 | \class QContactFetchByIdRequest |
| 42 | \brief The QContactFetchByIdRequest class allows a client to asynchronously |
| 43 | request contacts from a contacts store manager, given a list of contact IDs. |
| 44 | |
| 45 | The contacts fetched by the backend should have a one-to-one correspondence to the |
| 46 | IDs passed into this class. That is, the nth contact in the returned list should |
| 47 | have an ID which is equal to the nth ID in the list of IDs. Any invalid ID should |
| 48 | correspond to an empty QContact. |
| 49 | |
| 50 | For a QContactFetchByIdRequest, the resultsAvailable() signal will be emitted when the |
| 51 | resultant contacts (which may be retrieved by calling contacts()), are updated, as well |
| 52 | as if the overall operation error (which may be retrieved by calling error()) is |
| 53 | updated. |
| 54 | |
| 55 | Please see the class documentation of QContactAbstractRequest for more information about |
| 56 | the usage of request classes and ownership semantics. |
| 57 | |
| 58 | |
| 59 | \inmodule QtContacts |
| 60 | |
| 61 | \ingroup contacts-requests |
| 62 | */ |
| 63 | |
| 64 | /*! Constructs a new contact fetch request whose parent is the specified \a parent */ |
| 65 | QContactFetchByIdRequest::QContactFetchByIdRequest(QObject* parent) |
| 66 | : QContactAbstractRequest(new QContactFetchByIdRequestPrivate, parent) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | /*! Frees any memory used by this request */ |
| 71 | QContactFetchByIdRequest::~QContactFetchByIdRequest() |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | /*! |
| 76 | Sets the list of ids of the contacts that the backend should retrieve to \a ids. |
| 77 | */ |
| 78 | void QContactFetchByIdRequest::setIds(const QList<QContactId>& ids) |
| 79 | { |
| 80 | Q_D(QContactFetchByIdRequest); |
| 81 | QMutexLocker ml(&d->m_mutex); |
| 82 | d->m_contactIds = ids; |
| 83 | } |
| 84 | |
| 85 | /*! |
| 86 | Sets the fetch hint which may be used by the backend to optimize contact retrieval |
| 87 | to \a fetchHint. A client should not make changes to a contact which has been retrieved |
| 88 | using a fetch hint other than the default fetch hint. Doing so will result in information |
| 89 | loss when saving the contact back to the manager (as the "new" restricted contact will |
| 90 | replace the previously saved contact in the backend). |
| 91 | \sa QContactFetchHint |
| 92 | */ |
| 93 | void QContactFetchByIdRequest::setFetchHint(const QContactFetchHint &fetchHint) |
| 94 | { |
| 95 | Q_D(QContactFetchByIdRequest); |
| 96 | QMutexLocker ml(&d->m_mutex); |
| 97 | d->m_fetchHint = fetchHint; |
| 98 | } |
| 99 | |
| 100 | /*! |
| 101 | Returns the list of ids of the contacts that the backend should retrieve. |
| 102 | */ |
| 103 | QList<QContactId> QContactFetchByIdRequest::contactIds() const |
| 104 | { |
| 105 | Q_D(const QContactFetchByIdRequest); |
| 106 | QMutexLocker ml(&d->m_mutex); |
| 107 | return d->m_contactIds; |
| 108 | } |
| 109 | |
| 110 | /*! |
| 111 | Returns the fetch hint which may be used by the backend to optimize contact retrieval. |
| 112 | A client should not make changes to a contact which has been retrieved |
| 113 | using a fetch hint other than the default fetch hint. Doing so will result in information |
| 114 | loss when saving the contact back to the manager (as the "new" restricted contact will |
| 115 | replace the previously saved contact in the backend). |
| 116 | \sa QContactFetchHint |
| 117 | */ |
| 118 | QContactFetchHint QContactFetchByIdRequest::fetchHint() const |
| 119 | { |
| 120 | Q_D(const QContactFetchByIdRequest); |
| 121 | QMutexLocker ml(&d->m_mutex); |
| 122 | return d->m_fetchHint; |
| 123 | } |
| 124 | |
| 125 | /*! Returns the list of contacts retrieved by this request */ |
| 126 | QList<QContact> QContactFetchByIdRequest::contacts() const |
| 127 | { |
| 128 | Q_D(const QContactFetchByIdRequest); |
| 129 | QMutexLocker ml(&d->m_mutex); |
| 130 | return d->m_contacts; |
| 131 | } |
| 132 | |
| 133 | /*! |
| 134 | Returns the map of input definition list indices to errors which occurred. |
| 135 | In case of global errors like QContactManager::TimeoutError affecting to |
| 136 | all items in the input definitions the error map may be empty. |
| 137 | */ |
| 138 | QMap<int, QContactManager::Error> QContactFetchByIdRequest::errorMap() const |
| 139 | { |
| 140 | Q_D(const QContactFetchByIdRequest); |
| 141 | QMutexLocker ml(&d->m_mutex); |
| 142 | return d->m_errors; |
| 143 | } |
| 144 | |
| 145 | #include "moc_qcontactfetchbyidrequest.cpp" |
| 146 | |
| 147 | QT_END_NAMESPACE_CONTACTS |
| 148 | |