| 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 QtOrganizer 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 "qorganizeritemsaverequest.h" |
| 35 | |
| 36 | #include "qorganizeritemrequests_p.h" |
| 37 | |
| 38 | QT_BEGIN_NAMESPACE_ORGANIZER |
| 39 | |
| 40 | /*! |
| 41 | \class QOrganizerItemSaveRequest |
| 42 | \brief The QOrganizerItemSaveRequest class allows a client to asynchronously request that certain |
| 43 | organizer items be saved to a backend. |
| 44 | \inmodule QtOrganizer |
| 45 | \ingroup organizer-requests |
| 46 | */ |
| 47 | |
| 48 | /*! |
| 49 | Constructs a new organizer item save request whose parent is the specified \a parent. |
| 50 | */ |
| 51 | QOrganizerItemSaveRequest::QOrganizerItemSaveRequest(QObject *parent) |
| 52 | : QOrganizerAbstractRequest(new QOrganizerItemSaveRequestPrivate, parent) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | /*! |
| 57 | Frees memory in use by this request. |
| 58 | */ |
| 59 | QOrganizerItemSaveRequest::~QOrganizerItemSaveRequest() |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | /*! |
| 64 | Sets the organizer item to be saved to \a item. |
| 65 | Equivalent to calling: |
| 66 | \code |
| 67 | setItems(QList<QOrganizerItem>() << item); |
| 68 | \endcode |
| 69 | */ |
| 70 | void QOrganizerItemSaveRequest::setItem(const QOrganizerItem &item) |
| 71 | { |
| 72 | Q_D(QOrganizerItemSaveRequest); |
| 73 | QMutexLocker ml(&d->m_mutex); |
| 74 | d->m_organizeritems.clear(); |
| 75 | d->m_organizeritems.append(t: item); |
| 76 | } |
| 77 | |
| 78 | /*! |
| 79 | Sets the list of organizer items to be saved to \a items. |
| 80 | */ |
| 81 | void QOrganizerItemSaveRequest::setItems(const QList<QOrganizerItem> &items) |
| 82 | { |
| 83 | Q_D(QOrganizerItemSaveRequest); |
| 84 | QMutexLocker ml(&d->m_mutex); |
| 85 | d->m_organizeritems = items; |
| 86 | } |
| 87 | |
| 88 | /*! |
| 89 | Returns the list of organizer items which will be saved if called prior to calling start(), |
| 90 | otherwise returns the list of organizer items as they were saved in the organizer item store. |
| 91 | */ |
| 92 | QList<QOrganizerItem> QOrganizerItemSaveRequest::items() const |
| 93 | { |
| 94 | Q_D(const QOrganizerItemSaveRequest); |
| 95 | QMutexLocker ml(&d->m_mutex); |
| 96 | return d->m_organizeritems; |
| 97 | } |
| 98 | |
| 99 | /*! |
| 100 | Returns the map of input definition list indices to errors which occurred. |
| 101 | */ |
| 102 | QMap<int, QOrganizerManager::Error> QOrganizerItemSaveRequest::errorMap() const |
| 103 | { |
| 104 | Q_D(const QOrganizerItemSaveRequest); |
| 105 | QMutexLocker ml(&d->m_mutex); |
| 106 | return d->m_errors; |
| 107 | } |
| 108 | |
| 109 | /*! |
| 110 | Set the list of detail types to restrict saving to \a detailMask. This allows you to perform |
| 111 | partial save (and remove) operations on existing items. |
| 112 | |
| 113 | If \a detailMask is empty (the default), no restrictions will apply, and the passed |
| 114 | in items will be saved as is. Otherwise, only details whose types are in |
| 115 | the list will be saved. If a detail type is present in the list, but there are no |
| 116 | corresponding details in the item passed into this request, any existing details in |
| 117 | the manager for that item will be removed. |
| 118 | |
| 119 | This is useful if you've used a fetch hint to fetch a partial item from a manager |
| 120 | so that you can save changes to the details you actually fetched without removing |
| 121 | the details you didn't. |
| 122 | |
| 123 | Additionally, when performing synchronization operations with other managers that don't |
| 124 | support the full range of details, you can restrict the update operation to only those |
| 125 | details so that you don't lose the extra details that are supported in this manager. |
| 126 | |
| 127 | \note Some managers do not support partial updates natively, in which case the QtOrganizer |
| 128 | framework will emulate the functionality (fetching the whole item, applying the |
| 129 | new restricted details, and saving the item back). |
| 130 | */ |
| 131 | void QOrganizerItemSaveRequest::setDetailMask(const QList<QOrganizerItemDetail::DetailType> &detailMask) |
| 132 | { |
| 133 | Q_D(QOrganizerItemSaveRequest); |
| 134 | QMutexLocker ml(&d->m_mutex); |
| 135 | d->m_detailMask = detailMask; |
| 136 | } |
| 137 | |
| 138 | /*! |
| 139 | Returns the list of definitions that this request will operate on. |
| 140 | |
| 141 | If the list is empty, the request will operate on all details. |
| 142 | */ |
| 143 | QList<QOrganizerItemDetail::DetailType> QOrganizerItemSaveRequest::detailMask() const |
| 144 | { |
| 145 | Q_D(const QOrganizerItemSaveRequest); |
| 146 | QMutexLocker ml(&d->m_mutex); |
| 147 | return d->m_detailMask; |
| 148 | } |
| 149 | |
| 150 | #include "moc_qorganizeritemsaverequest.cpp" |
| 151 | |
| 152 | QT_END_NAMESPACE_ORGANIZER |
| 153 | |