1
/****************************************************************************
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** OrganizerItem: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the Qt Mobility Components.
9
** $QT_BEGIN_LICENSE:LGPL$
11
** Licensees holding valid Qt Commercial licenses may use this file in
12
** accordance with the Qt Commercial License Agreement provided with
13
** the Software or, alternatively, in accordance with the terms
14
** contained in a written agreement between you and Nokia.
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file. Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** GNU General Public License Usage
29
** Alternatively, this file may be used under the terms of the GNU
30
** General Public License version 3.0 as published by the Free Software
31
** Foundation and appearing in the file LICENSE.GPL included in the
32
** packaging of this file. Please review the following information to
33
** ensure the GNU General Public License version 3.0 requirements will be
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at qt-sales@nokia.com.
40
****************************************************************************/
42
#include "qorganizerabstractrequest.h"
43
#include "qorganizerabstractrequest_p.h"
44
#include "qorganizermanager.h"
45
#include "qorganizermanager_p.h"
46
#include "qorganizermanagerengine.h"
52
\class QOrganizerAbstractRequest
54
\brief The QOrganizerAbstractRequest class provides a mechanism for
55
asynchronous requests to be made of a manager if it supports them.
59
\ingroup organizer-main
61
It allows a client to asynchronously request some functionality of a
62
particular QOrganizerManager. Instances of the class will emit signals
63
when the state of the request changes, or when more results become
66
Clients should not attempt to create instances of this class directly,
67
but should instead use the use-case-specific classes derived from this
70
After creating any sort of request, the client retains ownership and
71
must delete the request to avoid leaking memory. The client may either
72
do this directly (if not within a slot connected to a signal emitted
73
by the request) or by using the deleteLater() slot to schedule the
74
request for deletion when control returns to the event loop.
78
\fn QOrganizerAbstractRequest::stateChanged(QOrganizerAbstractRequest::State newState)
79
This signal is emitted when the state of the request is changed. The new state of
80
the request will be contained in \a newState.
85
\fn QOrganizerAbstractRequest::resultsAvailable()
86
This signal is emitted when new results are available. Results can include
87
the operation error which may be accessed via error(), or derived-class-specific
88
results which are accessible through the derived class API.
94
\enum QOrganizerAbstractRequest::RequestType
95
Enumerates the various possible types of asynchronous requests
96
\value InvalidRequest An invalid request
97
\value ItemOccurrenceFetchRequest A request to fetch a list of occurrences of an organizer item
98
\value ItemFetchRequest A request to fetch a list of organizer items
99
\value ItemFetchForExportRequest A request to fetch a list of persisted organizer items and exceptions
100
\value ItemIdFetchRequest A request to fetch a list of organizer item ids
101
\value ItemRemoveRequest A request to remove a list of organizer items
102
\value ItemSaveRequest A request to save a list of organizer items
103
\value DetailDefinitionFetchRequest A request to fetch a collection of detail definitions
104
\value DetailDefinitionRemoveRequest A request to remove a list of detail definitions
105
\value DetailDefinitionSaveRequest A request to save a list of detail definitions
106
\value CollectionFetchRequest A request to fetch a collection.
107
\value CollectionRemoveRequest A request to remove a collection.
108
\value CollectionSaveRequest A request to save a collection.
112
\enum QOrganizerAbstractRequest::State
113
Enumerates the various states that a request may be in at any given time
114
\value InactiveState Operation not yet started
115
\value ActiveState Operation started, not yet finished
116
\value CanceledState Operation is finished due to cancellation
117
\value FinishedState Operation successfully completed
121
\fn QOrganizerAbstractRequest::QOrganizerAbstractRequest(QObject* parent)
122
Constructs a new, invalid asynchronous request with the specified \a parent
127
Constructs a new request from the given request data \a otherd with
128
the given parent \a parent
130
QOrganizerAbstractRequest::QOrganizerAbstractRequest(QOrganizerAbstractRequestPrivate* otherd, QObject* parent)
131
: QObject(parent), d_ptr(otherd)
135
/*! Cleans up the memory used by this request */
136
QOrganizerAbstractRequest::~QOrganizerAbstractRequest()
139
QOrganizerManagerEngine *engine = QOrganizerManagerData::engine(d_ptr->m_manager);
141
engine->requestDestroyed(this);
149
Returns true if the request is in the \c QOrganizerAbstractRequest::InactiveState state; otherwise, returns false
153
bool QOrganizerAbstractRequest::isInactive() const
155
QMutexLocker ml(&d_ptr->m_mutex);
156
return (d_ptr->m_state == QOrganizerAbstractRequest::InactiveState);
160
Returns true if the request is in the \c QOrganizerAbstractRequest::ActiveState state; otherwise, returns false
164
bool QOrganizerAbstractRequest::isActive() const
166
QMutexLocker ml(&d_ptr->m_mutex);
167
return (d_ptr->m_state == QOrganizerAbstractRequest::ActiveState);
171
Returns true if the request is in the \c QOrganizerAbstractRequest::FinishedState; otherwise, returns false
175
bool QOrganizerAbstractRequest::isFinished() const
177
QMutexLocker ml(&d_ptr->m_mutex);
178
return (d_ptr->m_state == QOrganizerAbstractRequest::FinishedState);
182
Returns true if the request is in the \c QOrganizerAbstractRequest::CanceledState; otherwise, returns false
186
bool QOrganizerAbstractRequest::isCanceled() const
188
QMutexLocker ml(&d_ptr->m_mutex);
189
return (d_ptr->m_state == QOrganizerAbstractRequest::CanceledState);
192
/*! Returns the overall error of the most recent asynchronous operation */
193
QOrganizerManager::Error QOrganizerAbstractRequest::error() const
195
QMutexLocker ml(&d_ptr->m_mutex);
196
return d_ptr->m_error;
200
Returns the type of this asynchronous request
202
QOrganizerAbstractRequest::RequestType QOrganizerAbstractRequest::type() const
204
QMutexLocker ml(&d_ptr->m_mutex);
205
return d_ptr->type();
209
Returns the current state of the request.
211
QOrganizerAbstractRequest::State QOrganizerAbstractRequest::state() const
213
QMutexLocker ml(&d_ptr->m_mutex);
214
return d_ptr->m_state;
217
/*! Returns a pointer to the manager of which this request instance requests operations */
218
QOrganizerManager* QOrganizerAbstractRequest::manager() const
220
QMutexLocker ml(&d_ptr->m_mutex);
221
return d_ptr->m_manager;
224
/*! Sets the manager of which this request instance requests operations to \a manager */
225
void QOrganizerAbstractRequest::setManager(QOrganizerManager* manager)
227
QMutexLocker ml(&d_ptr->m_mutex);
228
// In theory we might have been active and the manager didn't cancel/finish us
229
if (d_ptr->m_state == QOrganizerAbstractRequest::ActiveState && d_ptr->m_manager)
231
d_ptr->m_manager = manager;
232
d_ptr->m_engine = QOrganizerManagerData::engine(d_ptr->m_manager);
235
/*! Attempts to start the request. Returns false if the request is not in the \c QOrganizerAbstractRequest::Inactive, \c QOrganizerAbstractRequest::Finished or \c QOrganizerAbstractRequest::Cancelled states,
236
or if the request was unable to be performed by the manager engine; otherwise returns true. */
237
bool QOrganizerAbstractRequest::start()
239
QMutexLocker ml(&d_ptr->m_mutex);
240
if (d_ptr->m_engine && (d_ptr->m_state == QOrganizerAbstractRequest::CanceledState
241
|| d_ptr->m_state == QOrganizerAbstractRequest::FinishedState
242
|| d_ptr->m_state == QOrganizerAbstractRequest::InactiveState)) {
244
return d_ptr->m_engine->startRequest(this);
247
return false; // unable to start operation; another operation already in progress or no engine.
250
/*! Attempts to cancel the request. Returns false if the request is not in the \c QOrganizerAbstractRequest::Active state,
251
or if the request is unable to be cancelled by the manager engine; otherwise returns true. */
252
bool QOrganizerAbstractRequest::cancel()
254
QMutexLocker ml(&d_ptr->m_mutex);
255
if (d_ptr->m_engine && d_ptr->m_state == QOrganizerAbstractRequest::ActiveState) {
257
return d_ptr->m_engine->cancelRequest(this);
260
return false; // unable to cancel operation; not in progress or no engine.
263
/*! Blocks until the request has been completed by the manager engine, or until \a msecs milliseconds has elapsed.
264
If \a msecs is zero or negative, this function will block until the request is complete, regardless of how long it takes.
265
Returns true if the request was cancelled or completed successfully within the given period, otherwise false.
266
Some backends are unable to support this operation safely, and will return false immediately.
268
bool QOrganizerAbstractRequest::waitForFinished(int msecs)
270
QMutexLocker ml(&d_ptr->m_mutex);
271
if (d_ptr->m_engine) {
272
switch (d_ptr->m_state) {
273
case QOrganizerAbstractRequest::ActiveState:
275
return d_ptr->m_engine->waitForRequestFinished(this, msecs);
276
case QOrganizerAbstractRequest::CanceledState:
277
case QOrganizerAbstractRequest::FinishedState:
284
return false; // unable to wait for operation; not in progress or no engine
287
#include "moc_qorganizerabstractrequest.cpp"