~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to src/organizer/qorganizeritemmanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
**
3
 
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
 
** All rights reserved.
5
 
** OrganizerItem: Nokia Corporation (qt-info@nokia.com)
6
 
**
7
 
** This file is part of the Qt Mobility Components.
8
 
**
9
 
** $QT_BEGIN_LICENSE:LGPL$
10
 
** Commercial Usage
11
 
** Licensees holding valid Qt Commercial licenses may use this file in
12
 
** accordance with the Qt Solutions Commercial License Agreement provided
13
 
** with the Software or, alternatively, in accordance with the terms
14
 
** contained in a written agreement between you and Nokia.
15
 
**
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.
23
 
**
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.
27
 
**
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.
35
 
**
36
 
** Please note Third Party Software included with Qt Solutions may impose
37
 
** additional restrictions and it is the user's responsibility to ensure
38
 
** that they have met the licensing requirements of the GPL, LGPL, or Qt
39
 
** Solutions Commercial license and the relevant license of the Third
40
 
** Party Software they are using.
41
 
**
42
 
** If you are unsure which license is appropriate for your use, please
43
 
** contact the sales department at qt-sales@nokia.com.
44
 
** $QT_END_LICENSE$
45
 
**
46
 
****************************************************************************/
47
 
 
48
 
#include "qorganizeritemmanager.h"
49
 
 
50
 
#include "qorganizeritem_p.h"
51
 
#include "qorganizeritemfilter.h"
52
 
#include "qorganizeritemdetaildefinition.h"
53
 
#include "qorganizeritemmanager_p.h"
54
 
#include "qorganizeritemfetchhint.h"
55
 
 
56
 
#include <QSharedData>
57
 
#include <QPair>
58
 
#include <QSet>
59
 
 
60
 
QTM_BEGIN_NAMESPACE
61
 
 
62
 
/*!
63
 
  \class QOrganizerItemManager
64
 
  \brief The QOrganizerItemManager class provides an interface which allows clients with access to organizer item information stored in a particular backend.
65
 
 
66
 
  \inmodule QtOrganizer
67
 
  \ingroup organizer-main
68
 
 
69
 
  This class provides an abstraction of a datastore or aggregation of datastores which contains organizer item information.
70
 
  It provides methods to retrieve and manipulate organizer item information and supported schema definitions.
71
 
  It also provides metadata and error information reporting.
72
 
 
73
 
  The functions provided by QOrganizerItemManager are purely synchronous; to access the same functionality in an
74
 
  asynchronous manner, clients should use the use-case-specific classes derived from QOrganizerItemAbstractRequest.
75
 
 
76
 
  Some functionality provided by QOrganizerItemManager directly is not accessible using the asynchronous API; see
77
 
  the \l{Organizer Synchronous API}{synchronous} and \l{Organizer Asynchronous API}{asynchronous} API
78
 
  information from the \l{Organizer}{organizer module} API documentation.
79
 
 */
80
 
 
81
 
/*!
82
 
  \fn QOrganizerItemManager::dataChanged()
83
 
  This signal is emitted by the manager if its internal state changes, and it is unable to determine the changes
84
 
  which occurred, or if the manager considers the changes to be radical enough to require clients to reload all data.
85
 
  If this signal is emitted, no other signals will be emitted for the associated changes.
86
 
 */
87
 
 
88
 
/*!
89
 
  \fn QOrganizerItemManager::itemsAdded(const QList<QOrganizerItemLocalId>& organizeritemIds)
90
 
  This signal is emitted at some point once the organizeritems identified by \a organizeritemIds have been added to a datastore managed by this manager.
91
 
  This signal must not be emitted if the dataChanged() signal was previously emitted for these changes.
92
 
 */
93
 
 
94
 
/*!
95
 
  \fn QOrganizerItemManager::itemsChanged(const QList<QOrganizerItemLocalId>& organizeritemIds)
96
 
  This signal is emitted at some point once the organizeritems identified by \a organizeritemIds have been modified in a datastore managed by this manager.
97
 
  This signal must not be emitted if the dataChanged() signal was previously emitted for these changes.
98
 
 */
99
 
 
100
 
/*!
101
 
  \fn QOrganizerItemManager::itemsRemoved(const QList<QOrganizerItemLocalId>& organizeritemIds)
102
 
  This signal is emitted at some point once the organizeritems identified by \a organizeritemIds have been removed from a datastore managed by this manager.
103
 
  This signal must not be emitted if the dataChanged() signal was previously emitted for these changes.
104
 
 */
105
 
 
106
 
 
107
 
 
108
 
#define makestr(x) (#x)
109
 
#define makename(x) makestr(x)
110
 
 
111
 
/*!
112
 
    Returns a list of available manager ids that can be used when constructing
113
 
    a QOrganizerItemManager.  If an empty id is specified to the constructor, the
114
 
    first value in this list will be used instead.
115
 
  */
116
 
QStringList QOrganizerItemManager::availableManagers()
117
 
{
118
 
    QStringList ret;
119
 
    ret << QLatin1String("memory") << QLatin1String("invalid");
120
 
    QOrganizerItemManagerData::loadFactories();
121
 
    ret.append(QOrganizerItemManagerData::m_engines.keys());
122
 
 
123
 
    // now swizzle the default engine to pole position
124
 
#if defined(Q_ORGANIZER_DEFAULT_ENGINE)
125
 
    if (ret.removeAll(QLatin1String(makename(Q_ORGANIZER_DEFAULT_ENGINE)))) {
126
 
        ret.prepend(QLatin1String(makename(Q_ORGANIZER_DEFAULT_ENGINE)));
127
 
    }
128
 
#endif
129
 
 
130
 
    return ret;
131
 
}
132
 
 
133
 
/*!
134
 
  Splits the given \a uri into the manager, store, and parameters that it describes, and places the information into the memory addressed by \a pManagerId and \a pParams respectively.  Returns true if \a uri could be split successfully, otherwise returns false
135
 
 */
136
 
bool QOrganizerItemManager::parseUri(const QString& uri, QString* pManagerId, QMap<QString, QString>* pParams)
137
 
{
138
 
    // Format: qtorganizer:<managerid>:<key>=<value>&<key>=<value>
139
 
    // 1) parameters are currently a qstringlist.. should they be a map?
140
 
    // 2) is the uri going to be escaped?  my guess would be "probably not"
141
 
    // 3) hence, do we assume that the prefix, managerid and storeid cannot contain `:'
142
 
    // 4) similarly, that neither keys nor values can contain `=' or `&'
143
 
 
144
 
    QStringList colonSplit = uri.split(QLatin1Char(':'));
145
 
    QString prefix = colonSplit.value(0);
146
 
 
147
 
    if (prefix != QLatin1String("qtorganizer"))
148
 
        return false;
149
 
 
150
 
    QString managerName = colonSplit.value(1);
151
 
 
152
 
    if (managerName.trimmed().isEmpty())
153
 
        return false;
154
 
 
155
 
    QString firstParts = prefix + QLatin1Char(':') + managerName + QLatin1Char(':');
156
 
    QString paramString = uri.mid(firstParts.length());
157
 
 
158
 
    QMap<QString, QString> outParams;
159
 
 
160
 
    // Now we have to decode each parameter
161
 
    if (!paramString.isEmpty()) {
162
 
        QStringList params = paramString.split(QRegExp(QLatin1String("&(?!(amp;|equ;))")), QString::KeepEmptyParts);
163
 
        // If we have an empty string for paramstring, we get one entry in params,
164
 
        // so skip that case.
165
 
        for(int i = 0; i < params.count(); i++) {
166
 
            /* This should be something like "foo&amp;bar&equ;=grob&amp;" */
167
 
            QStringList paramChunk = params.value(i).split(QLatin1String("="), QString::KeepEmptyParts);
168
 
 
169
 
            if (paramChunk.count() != 2)
170
 
                return false;
171
 
 
172
 
            QString arg = paramChunk.value(0);
173
 
            QString param = paramChunk.value(1);
174
 
            arg.replace(QLatin1String("&equ;"), QLatin1String("="));
175
 
            arg.replace(QLatin1String("&amp;"), QLatin1String("&"));
176
 
            param.replace(QLatin1String("&equ;"), QLatin1String("="));
177
 
            param.replace(QLatin1String("&amp;"), QLatin1String("&"));
178
 
            if (arg.isEmpty())
179
 
                return false;
180
 
            outParams.insert(arg, param);
181
 
        }
182
 
    }
183
 
 
184
 
    if (pParams)
185
 
        *pParams = outParams;
186
 
    if (pManagerId)
187
 
        *pManagerId = managerName;
188
 
    return true;
189
 
}
190
 
 
191
 
/*! Returns a URI that completely describes a manager implementation, datastore, and the parameters with which to instantiate the manager, from the given \a managerName, \a params and an optional \a implementationVersion */
192
 
QString QOrganizerItemManager::buildUri(const QString& managerName, const QMap<QString, QString>& params, int implementationVersion)
193
 
{
194
 
    QString ret(QLatin1String("qtorganizer:%1:%2"));
195
 
    // we have to escape each param
196
 
    QStringList escapedParams;
197
 
    QStringList keys = params.keys();
198
 
    for (int i=0; i < keys.size(); i++) {
199
 
        QString key = keys.at(i);
200
 
        QString arg = params.value(key);
201
 
        arg = arg.replace(QLatin1Char('&'), QLatin1String("&amp;"));
202
 
        arg = arg.replace(QLatin1Char('='), QLatin1String("&equ;"));
203
 
        key = key.replace(QLatin1Char('&'), QLatin1String("&amp;"));
204
 
        key = key.replace(QLatin1Char('='), QLatin1String("&equ;"));
205
 
        key = key + QLatin1Char('=') + arg;
206
 
        escapedParams.append(key);
207
 
    }
208
 
 
209
 
    if (implementationVersion != -1) {
210
 
        QString versionString = QString(QLatin1String(QTORGANIZER_IMPLEMENTATION_VERSION_NAME));
211
 
        versionString += QString::fromAscii("=");
212
 
        versionString += QString::number(implementationVersion);
213
 
        escapedParams.append(versionString);
214
 
    }
215
 
 
216
 
    return ret.arg(managerName, escapedParams.join(QLatin1String("&")));
217
 
}
218
 
 
219
 
/*!
220
 
  Constructs a QOrganizerItemManager whose implementation, store and parameters are specified in the given \a storeUri,
221
 
  and whose parent object is \a parent.
222
 
 */
223
 
QOrganizerItemManager* QOrganizerItemManager::fromUri(const QString& storeUri, QObject* parent)
224
 
{
225
 
    if (storeUri.isEmpty()) {
226
 
        return new QOrganizerItemManager(QString(), QMap<QString, QString>(), parent);
227
 
    } else {
228
 
        QString id;
229
 
        QMap<QString, QString> parameters;
230
 
        if (parseUri(storeUri, &id, &parameters)) {
231
 
            return new QOrganizerItemManager(id, parameters, parent);
232
 
        } else {
233
 
            // invalid
234
 
            return new QOrganizerItemManager(QLatin1String("invalid"), QMap<QString, QString>(), parent);
235
 
        }
236
 
    }
237
 
}
238
 
 
239
 
/*!
240
 
  Constructs a QOrganizerItemManager whose parent QObject is \a parent.
241
 
  The default implementation for the platform will be created.
242
 
 */
243
 
QOrganizerItemManager::QOrganizerItemManager(QObject* parent)
244
 
    : QObject(parent)
245
 
{
246
 
    createEngine(QString(), QMap<QString, QString>());
247
 
}
248
 
 
249
 
/*!
250
 
  Constructs a QOrganizerItemManager whose implementation is identified by \a managerName with the given \a parameters.
251
 
 
252
 
  The \a parent QObject will be used as the parent of this QOrganizerItemManager.
253
 
 
254
 
  If an empty \a managerName is specified, the default implementation for the platform will
255
 
  be used.
256
 
 */
257
 
QOrganizerItemManager::QOrganizerItemManager(const QString& managerName, const QMap<QString, QString>& parameters, QObject* parent)
258
 
    : QObject(parent),
259
 
    d(new QOrganizerItemManagerData)
260
 
{
261
 
    createEngine(managerName, parameters);
262
 
}
263
 
 
264
 
void QOrganizerItemManager::createEngine(const QString& managerName, const QMap<QString, QString>& parameters)
265
 
{
266
 
    d->createEngine(managerName, parameters);
267
 
    connect(d->m_engine, SIGNAL(dataChanged()), this, SIGNAL(dataChanged()));
268
 
    connect(d->m_engine, SIGNAL(itemsAdded(QList<QOrganizerItemLocalId>)), this, SIGNAL(itemsAdded(QList<QOrganizerItemLocalId>)));
269
 
    connect(d->m_engine, SIGNAL(itemsChanged(QList<QOrganizerItemLocalId>)), this, SIGNAL(itemsChanged(QList<QOrganizerItemLocalId>)));
270
 
    connect(d->m_engine, SIGNAL(itemsRemoved(QList<QOrganizerItemLocalId>)), this, SIGNAL(itemsRemoved(QList<QOrganizerItemLocalId>)));
271
 
    connect(d->m_engine, SIGNAL(collectionsAdded(QList<QOrganizerCollectionLocalId>)), this, SIGNAL(collectionsAdded(QList<QOrganizerCollectionLocalId>)));
272
 
    connect(d->m_engine, SIGNAL(collectionsChanged(QList<QOrganizerCollectionLocalId>)), this, SIGNAL(collectionsChanged(QList<QOrganizerCollectionLocalId>)));
273
 
    connect(d->m_engine, SIGNAL(collectionsRemoved(QList<QOrganizerCollectionLocalId>)), this, SIGNAL(collectionsRemoved(QList<QOrganizerCollectionLocalId>)));
274
 
}
275
 
 
276
 
/*!
277
 
  Constructs a QOrganizerItemManager whose backend has the name \a managerName and version \a implementationVersion, where the manager
278
 
  is constructed with the provided \a parameters.
279
 
 
280
 
  The \a parent QObject will be used as the parent of this QOrganizerItemManager.
281
 
 
282
 
  If an empty \a managerName is specified, the default implementation for the platform will be instantiated.
283
 
  If the specified implementation version is not available, the manager with the name \a managerName with the default implementation version is instantiated.
284
 
 */
285
 
QOrganizerItemManager::QOrganizerItemManager(const QString& managerName, int implementationVersion, const QMap<QString, QString>& parameters, QObject* parent)
286
 
    : QObject(parent),
287
 
    d(new QOrganizerItemManagerData)
288
 
{
289
 
    QMap<QString, QString> params = parameters;
290
 
    params[QString(QLatin1String(QTORGANIZER_IMPLEMENTATION_VERSION_NAME))] = QString::number(implementationVersion);
291
 
    createEngine(managerName, params);
292
 
}
293
 
 
294
 
/*! Frees the memory used by the QOrganizerItemManager */
295
 
QOrganizerItemManager::~QOrganizerItemManager()
296
 
{
297
 
    delete d;
298
 
}
299
 
 
300
 
/*!
301
 
  \enum QOrganizerItemManager::Error
302
 
 
303
 
  This enum specifies an error that occurred during the most recent operation:
304
 
 
305
 
  \value NoError The most recent operation was successful
306
 
  \value DoesNotExistError The most recent operation failed because the requested organizer item or detail definition does not exist
307
 
  \value AlreadyExistsError The most recent operation failed because the specified organizer item or detail definition already exists
308
 
  \value InvalidDetailError The most recent operation failed because the specified organizer item contains details which do not conform to their definition
309
 
  \value InvalidItemTypeError The most recent operation failed because the organizer item type specified was not valid for the operation
310
 
  \value LockedError The most recent operation failed because the datastore specified is currently locked
311
 
  \value DetailAccessError The most recent operation failed because a detail was modified or removed and its access method does not allow that
312
 
  \value PermissionsError The most recent operation failed because the caller does not have permission to perform the operation
313
 
  \value OutOfMemoryError The most recent operation failed due to running out of memory
314
 
  \value VersionMismatchError The most recent operation failed because the backend of the manager is not of the required version
315
 
  \value LimitReachedError The most recent operation failed because the limit for that type of object has been reached
316
 
  \value NotSupportedError The most recent operation failed because the requested operation is not supported in the specified store
317
 
  \value BadArgumentError The most recent operation failed because one or more of the parameters to the operation were invalid
318
 
  \value UnspecifiedError The most recent operation failed for an undocumented reason
319
 
  \value InvalidOccurrenceError The most recent operation failed because it was an attempt to save an occurrence without a correct InstanceOrigin detail
320
 
 */
321
 
 
322
 
/*! Return the error code of the most recent operation */
323
 
QOrganizerItemManager::Error QOrganizerItemManager::error() const
324
 
{
325
 
    return d->m_error;
326
 
}
327
 
 
328
 
/*!
329
 
  Return the list of organizer item instances which match the given \a filter, sorted according to the given \a sortOrders.
330
 
  The client may instruct the manager that it does not require all possible information about each instance by specifying a fetch hint \a fetchHint;
331
 
  the manager can choose to ignore the fetch hint, but if it does so, it must return all possible information about each instance.
332
 
  */
333
 
QList<QOrganizerItem> QOrganizerItemManager::itemInstances(const QOrganizerItemFilter& filter, const QList<QOrganizerItemSortOrder>& sortOrders, const QOrganizerItemFetchHint& fetchHint) const
334
 
{
335
 
    d->m_error = QOrganizerItemManager::NoError;
336
 
    return d->m_engine->itemInstances(filter, sortOrders, fetchHint, &d->m_error);
337
 
}
338
 
 
339
 
/*!
340
 
  Return the list of a maximum of \a maxCount organizer item instances which are occurrences of the given \a generator recurring item, which
341
 
  occur between the given \a periodStart date and the given \a periodEnd date.
342
 
 
343
 
  If \a periodStart is after \a periodEnd, the operation will fail.
344
 
  If \a maxCount is negative, it is backend specific as to how many occurrences will be returned.
345
 
  Some backends may return no instances, others may return some limited number of occurrences.
346
 
  */
347
 
QList<QOrganizerItem> QOrganizerItemManager::itemInstances(const QOrganizerItem& generator, const QDateTime& periodStart, const QDateTime& periodEnd, int maxCount) const
348
 
{
349
 
    d->m_error = QOrganizerItemManager::NoError;
350
 
    return d->m_engine->itemInstances(generator, periodStart, periodEnd, maxCount, &d->m_error);
351
 
}
352
 
 
353
 
 
354
 
/*!
355
 
  Return the list of organizer item ids, sorted according to the given list of \a sortOrders
356
 
 */
357
 
QList<QOrganizerItemLocalId> QOrganizerItemManager::itemIds(const QList<QOrganizerItemSortOrder>& sortOrders) const
358
 
{
359
 
    d->m_error = QOrganizerItemManager::NoError;
360
 
    return d->m_engine->itemIds(QOrganizerItemFilter(), sortOrders, &d->m_error);
361
 
}
362
 
 
363
 
/*!
364
 
  Returns a list of organizer item ids that match the given \a filter, sorted according to the given list of \a sortOrders.
365
 
  Depending on the backend, this filtering operation may involve retrieving all the organizeritems.
366
 
 */
367
 
QList<QOrganizerItemLocalId> QOrganizerItemManager::itemIds(const QOrganizerItemFilter& filter, const QList<QOrganizerItemSortOrder>& sortOrders) const
368
 
{
369
 
    d->m_error = QOrganizerItemManager::NoError;
370
 
    return d->m_engine->itemIds(filter, sortOrders, &d->m_error);
371
 
}
372
 
 
373
 
/*!
374
 
  Returns the list of organizeritems stored in the manager sorted according to the given list of \a sortOrders.
375
 
 
376
 
  The \a fetchHint parameter describes the optimization hints that a manager may take.
377
 
  If the \a fetchHint is the default constructed hint, all existing details and relationships
378
 
  in the matching organizeritems will be returned.  A client should not make changes to an organizer item which has
379
 
  been retrieved using a fetch hint other than the default fetch hint.  Doing so will result in information
380
 
  loss when saving the organizer item back to the manager (as the "new" restricted organizer item will
381
 
  replace the previously saved organizer item in the backend).
382
 
 
383
 
  \sa QOrganizerItemFetchHint
384
 
 */
385
 
QList<QOrganizerItem> QOrganizerItemManager::items(const QList<QOrganizerItemSortOrder>& sortOrders, const QOrganizerItemFetchHint& fetchHint) const
386
 
{
387
 
    d->m_error = QOrganizerItemManager::NoError;
388
 
    return d->m_engine->items(QOrganizerItemFilter(), sortOrders, fetchHint, &d->m_error);
389
 
}
390
 
 
391
 
/*!
392
 
  Returns a list of organizeritems that match the given \a filter, sorted according to the given list of \a sortOrders.
393
 
 
394
 
  Depending on the manager implementation, this filtering operation might be slow and involve retrieving all the
395
 
  organizeritems and testing them against the supplied filter - see the \l isFilterSupported() function.
396
 
 
397
 
  The \a fetchHint parameter describes the optimization hints that a manager may take.
398
 
  If the \a fetchHint is the default constructed hint, all existing details and relationships
399
 
  in the matching organizeritems will be returned.  A client should not make changes to an organizer item which has
400
 
  been retrieved using a fetch hint other than the default fetch hint.  Doing so will result in information
401
 
  loss when saving the organizer item back to the manager (as the "new" restricted organizer item will
402
 
  replace the previously saved organizer item in the backend).
403
 
 
404
 
  \sa QOrganizerItemFetchHint
405
 
 */
406
 
QList<QOrganizerItem> QOrganizerItemManager::items(const QOrganizerItemFilter& filter, const QList<QOrganizerItemSortOrder>& sortOrders, const QOrganizerItemFetchHint& fetchHint) const
407
 
{
408
 
    d->m_error = QOrganizerItemManager::NoError;
409
 
    return d->m_engine->items(filter, sortOrders, fetchHint, &d->m_error);
410
 
}
411
 
 
412
 
/*!
413
 
  Returns the organizer item in the database identified by \a organizeritemId.
414
 
 
415
 
  If the organizer item does not exist, an empty, default constructed QOrganizerItem will be returned,
416
 
  and the error returned by \l error() will be \c QOrganizerItemManager::DoesNotExistError.
417
 
 
418
 
  The \a fetchHint parameter describes the optimization hints that a manager may take.
419
 
  If the \a fetchHint is the default constructed hint, all existing details and relationships
420
 
  in the matching organizer item will be returned.  A client should not make changes to an organizer item which has
421
 
  been retrieved using a fetch hint other than the default fetch hint.  Doing so will result in information
422
 
  loss when saving the organizer item back to the manager (as the "new" restricted organizer item will
423
 
  replace the previously saved organizer item in the backend).
424
 
 
425
 
  \sa QOrganizerItemFetchHint
426
 
 */
427
 
QOrganizerItem QOrganizerItemManager::item(const QOrganizerItemLocalId& organizeritemId, const QOrganizerItemFetchHint& fetchHint) const
428
 
{
429
 
    d->m_error = QOrganizerItemManager::NoError;
430
 
    return d->m_engine->item(organizeritemId, fetchHint, &d->m_error);
431
 
}
432
 
 
433
 
/*!
434
 
  Adds the given \a organizeritem to the database if \a organizeritem has a
435
 
  default-constructed id, or an id with the manager URI set to the URI of
436
 
  this manager and a local id of zero.  It will be saved in the collection specified
437
 
  by \a collectionId if the specified collection exists, or if no \a collectionId is
438
 
  specified, or the \a collectionId is the default (zero) collection id, it will be
439
 
  saved in the collection in which the item is currently saved (if it is not a new
440
 
  item) or in the default collection (if it is a new item).
441
 
 
442
 
  Each collection may have a different schema, so if the item cannot be saved
443
 
  in the given collection due to invalid details, the function will return false.
444
 
  An item which is valid in one collection may be invalid in another collection, in the
445
 
  same manager.
446
 
 
447
 
  If the manager URI of the id of the \a organizeritem is neither empty nor equal to the URI of
448
 
  this manager, or local id of the \a organizeritem is non-zero but does not exist in the
449
 
  manager, the operation will fail and calling error() will return
450
 
  \c QOrganizerItemManager::DoesNotExistError.
451
 
 
452
 
  Alternatively, the function will update the existing organizer item in the database if \a organizeritem
453
 
  has a non-zero id and currently exists in the database.
454
 
 
455
 
  If the \a organizeritem contains one or more details whose definitions have
456
 
  not yet been saved with the manager, the operation will fail and calling
457
 
  error() will return \c QOrganizerItemManager::UnsupportedError.
458
 
 
459
 
  Returns false on failure, or true on
460
 
  success.  On successful save of an organizer item with an id of zero, its
461
 
  id will be set to a new, valid id with the manager URI set to the URI of
462
 
  this manager, and the local id set to a new, valid local id.
463
 
  The manager will automatically synthesize the display label of the organizer item when it is saved.
464
 
  The manager is not required to fetch updated details of the organizer item on save,
465
 
  and as such, clients should fetch an organizer item if they want the most up-to-date information
466
 
  by calling \l QOrganizerItemManager::item().
467
 
 
468
 
  \sa managerUri()
469
 
 */
470
 
bool QOrganizerItemManager::saveItem(QOrganizerItem* organizeritem, const QOrganizerCollectionLocalId& collectionId)
471
 
{
472
 
    if (organizeritem) {
473
 
        d->m_error = QOrganizerItemManager::NoError;
474
 
        return d->m_engine->saveItem(organizeritem, collectionId, &d->m_error);
475
 
    } else {
476
 
        d->m_error = QOrganizerItemManager::BadArgumentError;
477
 
        return false;
478
 
    }
479
 
}
480
 
 
481
 
/*!
482
 
  Remove the organizer item identified by \a organizeritemId from the database.
483
 
  Returns true if the organizer item was removed successfully, otherwise
484
 
  returns false.
485
 
 */
486
 
bool QOrganizerItemManager::removeItem(const QOrganizerItemLocalId& organizeritemId)
487
 
{
488
 
    d->m_error = QOrganizerItemManager::NoError;
489
 
    return d->m_engine->removeItem(organizeritemId, &d->m_error);
490
 
}
491
 
 
492
 
/*!
493
 
  Adds the list of organizeritems given by \a organizeritems list to the database, in
494
 
  the collection identified by the given \a collectionId.
495
 
  Returns true if the organizeritems were saved successfully, otherwise false.
496
 
 
497
 
  If the given \a collectionId does not exist, the function will return false.
498
 
  If the given \a collectionId is the default (zero) id, the items will be saved
499
 
  in the collection in which they are currently saved (if they are not new items) or
500
 
  in the default collection (if they are new items).
501
 
  If the given \a collectionId does exist, all items will be saved in the collection
502
 
  identified by the given \a collectionId.
503
 
 
504
 
  Each collection may have a different schema, so if any of the items cannot be saved
505
 
  in the given collection due to invalid details, the function will return false.
506
 
  An item which is valid in one collection may be invalid in another collection, in the
507
 
  same manager.
508
 
 
509
 
  The manager might populate \a errorMap (the map of indices of the \a organizeritems list to
510
 
  the error which occurred when saving the organizer item at that index) for
511
 
  every index for which the organizer item could not be saved, if it is able.
512
 
  The \l QOrganizerItemManager::error() function will only return \c QOrganizerItemManager::NoError
513
 
  if all organizeritems were saved successfully.
514
 
 
515
 
  For each newly saved organizer item that was successful, the id of the organizeritem
516
 
  in the \a organizeritems list will be updated with the new value.  If a failure occurs
517
 
  when saving a new organizeritem, the id will be cleared.
518
 
 
519
 
  \sa QOrganizerItemManager::saveItem()
520
 
 */
521
 
bool QOrganizerItemManager::saveItems(QList<QOrganizerItem>* organizeritems, const QOrganizerCollectionLocalId& collectionId, QMap<int, QOrganizerItemManager::Error>* errorMap)
522
 
{
523
 
    if (errorMap)
524
 
        errorMap->clear();
525
 
    if (!organizeritems) {
526
 
        d->m_error = QOrganizerItemManager::BadArgumentError;
527
 
        return false;
528
 
    }
529
 
 
530
 
    d->m_error = QOrganizerItemManager::NoError;
531
 
    return d->m_engine->saveItems(organizeritems, collectionId, errorMap, &d->m_error);
532
 
}
533
 
 
534
 
/*!
535
 
  Remove every organizer item whose id is contained in the list of organizeritems ids
536
 
  \a organizeritemIds.  Returns true if all organizeritems were removed successfully,
537
 
  otherwise false.
538
 
 
539
 
  The manager might populate \a errorMap (the map of indices of the \a organizeritemIds list to
540
 
  the error which occurred when saving the organizer item at that index) for every
541
 
  index for which the organizer item could not be removed, if it is able.
542
 
  The \l QOrganizerItemManager::error() function will
543
 
  only return \c QOrganizerItemManager::NoError if all organizeritems were removed
544
 
  successfully.
545
 
 
546
 
  If the given list of organizer item ids \a organizeritemIds is empty, the function will return false
547
 
  and calling error() will return \c QOrganizerItemManager::BadArgumentError.  If the list is non-empty
548
 
  and contains ids which do not identify a valid organizer item in the manager, the function will
549
 
  remove any organizeritems which are identified by ids in the \a organizeritemIds list, insert
550
 
  \c QOrganizerItemManager::DoesNotExist entries into the \a errorMap for the indices of invalid ids
551
 
  in the \a organizeritemIds list, return false, and set the overall operation error to
552
 
  \c QOrganizerItemManager::DoesNotExistError.
553
 
 
554
 
  \sa QOrganizerItemManager::removeItem()
555
 
 */
556
 
bool QOrganizerItemManager::removeItems(const QList<QOrganizerItemLocalId>& organizeritemIds, QMap<int, QOrganizerItemManager::Error>* errorMap)
557
 
{
558
 
    if (errorMap)
559
 
        errorMap->clear();
560
 
    if (organizeritemIds.isEmpty()) {
561
 
        d->m_error = QOrganizerItemManager::BadArgumentError;
562
 
        return false;
563
 
    }
564
 
 
565
 
    d->m_error = QOrganizerItemManager::NoError;
566
 
    return d->m_engine->removeItems(organizeritemIds, errorMap, &d->m_error);
567
 
}
568
 
 
569
 
/*!
570
 
  Returns the id of the default collection managed by this manager
571
 
 */
572
 
QOrganizerCollectionLocalId QOrganizerItemManager::defaultCollectionId() const
573
 
{
574
 
    d->m_error = QOrganizerItemManager::NoError;
575
 
    return d->m_engine->defaultCollectionId(&d->m_error);
576
 
}
577
 
 
578
 
/*!
579
 
  Returns the ids of collections managed by this manager.
580
 
 */
581
 
QList<QOrganizerCollectionLocalId> QOrganizerItemManager::collectionIds() const
582
 
{
583
 
    d->m_error = QOrganizerItemManager::NoError;
584
 
    return d->m_engine->collectionIds(&d->m_error);
585
 
}
586
 
 
587
 
/*!
588
 
  Returns the collections managed by this manager which
589
 
  have an id contained in the list of collection ids \a collectionIds.
590
 
  If the list of collection ids \a collectionIds is empty or
591
 
  not specified, this function will return
592
 
  all collections managed by this manager.
593
 
 */
594
 
QList<QOrganizerCollection> QOrganizerItemManager::collections(const QList<QOrganizerCollectionLocalId>& collectionIds) const
595
 
{
596
 
    d->m_error = QOrganizerItemManager::NoError;
597
 
    return d->m_engine->collections(collectionIds, &d->m_error);
598
 
}
599
 
 
600
 
/*!
601
 
  Saves the given \a collection in the manager.
602
 
  Returns true on success, false on failure.
603
 
 
604
 
  Some managers do not allow modifications to collections,
605
 
  and thus attempting to save a collection will always fail
606
 
  when attempted in such a manager.
607
 
 
608
 
  Some managers do not allow adding new collections,
609
 
  and thus attempting to save a new collection will always fail
610
 
  when attempted in such a manager.
611
 
 
612
 
  Some managers provide front-ends to read-only datastores, and
613
 
  attempting to save a new collection in such a manager will
614
 
  always fail.
615
 
 */
616
 
bool QOrganizerItemManager::saveCollection(QOrganizerCollection* collection)
617
 
{
618
 
    d->m_error = QOrganizerItemManager::NoError;
619
 
    return d->m_engine->saveCollection(collection, &d->m_error);
620
 
}
621
 
 
622
 
/*!
623
 
  Removes the collection identified by the given \a collectionId (and all items in the collection)
624
 
  from the manager if the given \a collectionId exists.
625
 
  Returns true on success, false on failure.
626
 
 
627
 
  XXX TODO:
628
 
  What happens if you attempt to remove the default collection?
629
 
  Fails?  Or sets next collection to be the default?  Or..?
630
 
  Do we need functions: setDefaultCollection(collection)?
631
 
  etc.
632
 
 */
633
 
bool QOrganizerItemManager::removeCollection(const QOrganizerCollectionLocalId& collectionId)
634
 
{
635
 
    d->m_error = QOrganizerItemManager::NoError;
636
 
    return d->m_engine->removeCollection(collectionId, &d->m_error);
637
 
}
638
 
 
639
 
/*!
640
 
  Returns a pruned or modified version of the \a original organizer item which is valid and can be saved in the manager.
641
 
  The returned organizer item might have entire details removed or arbitrarily changed.  The cache of relationships
642
 
  in the organizer item are ignored entirely when considering compatibility with the backend, as they are
643
 
  saved and validated separately.
644
 
 */
645
 
QOrganizerItem QOrganizerItemManager::compatibleItem(const QOrganizerItem& original)
646
 
{
647
 
    d->m_error = QOrganizerItemManager::NoError;
648
 
    return d->m_engine->compatibleItem(original, &d->m_error);
649
 
}
650
 
 
651
 
/*!
652
 
  Returns a map of identifier to detail definition for the registered detail definitions which are valid for organizeritems whose type is the given \a organizeritemType
653
 
  which are valid for the organizeritems in this store
654
 
 */
655
 
QMap<QString, QOrganizerItemDetailDefinition> QOrganizerItemManager::detailDefinitions(const QString& organizeritemType) const
656
 
{
657
 
    if (!supportedItemTypes().contains(organizeritemType)) {
658
 
        d->m_error = QOrganizerItemManager::InvalidItemTypeError;
659
 
        return QMap<QString, QOrganizerItemDetailDefinition>();
660
 
    }
661
 
 
662
 
    d->m_error = QOrganizerItemManager::NoError;
663
 
    return d->m_engine->detailDefinitions(organizeritemType, &d->m_error);
664
 
}
665
 
 
666
 
/*! Returns the definition identified by the given \a definitionName that is valid for the organizeritems whose type is the given \a organizeritemType in this store, or a default-constructed QOrganizerItemDetailDefinition if no such definition exists */
667
 
QOrganizerItemDetailDefinition QOrganizerItemManager::detailDefinition(const QString& definitionName, const QString& organizeritemType) const
668
 
{
669
 
    if (!supportedItemTypes().contains(organizeritemType)) {
670
 
        d->m_error = QOrganizerItemManager::InvalidItemTypeError;
671
 
        return QOrganizerItemDetailDefinition();
672
 
    }
673
 
 
674
 
    d->m_error = QOrganizerItemManager::NoError;
675
 
    return d->m_engine->detailDefinition(definitionName, organizeritemType, &d->m_error);
676
 
}
677
 
 
678
 
/*! Persists the given definition \a def in the database, which is valid for organizeritems whose type is the given \a organizeritemType.  Returns true if the definition was saved successfully, otherwise returns false */
679
 
bool QOrganizerItemManager::saveDetailDefinition(const QOrganizerItemDetailDefinition& def, const QString& organizeritemType)
680
 
{
681
 
    if (!supportedItemTypes().contains(organizeritemType)) {
682
 
        d->m_error = QOrganizerItemManager::InvalidItemTypeError;
683
 
        return false;
684
 
    }
685
 
 
686
 
    d->m_error = QOrganizerItemManager::NoError;
687
 
    return d->m_engine->saveDetailDefinition(def, organizeritemType, &d->m_error);
688
 
}
689
 
 
690
 
/*! Removes the detail definition identified by \a definitionName from the database, which is valid for organizeritems whose type is the given \a organizeritemType.  Returns true if the definition was removed successfully, otherwise returns false */
691
 
bool QOrganizerItemManager::removeDetailDefinition(const QString& definitionName, const QString& organizeritemType)
692
 
{
693
 
    if (!supportedItemTypes().contains(organizeritemType)) {
694
 
        d->m_error = QOrganizerItemManager::InvalidItemTypeError;
695
 
        return false;
696
 
    }
697
 
 
698
 
    d->m_error = QOrganizerItemManager::NoError;
699
 
    return d->m_engine->removeDetailDefinition(definitionName, organizeritemType, &d->m_error);
700
 
}
701
 
 
702
 
/*!
703
 
  \enum QOrganizerItemManager::ManagerFeature
704
 
  This enum describes the possible features that a particular manager may support
705
 
  \value MutableDefinitions The manager supports saving, updating or removing detail definitions.  Some built-in definitions may still be immutable
706
 
  \value ChangeLogs The manager supports reporting of timestamps of changes, and filtering and sorting by those timestamps
707
 
  \value Anonymous The manager is isolated from other managers
708
 
 */
709
 
 
710
 
/*!
711
 
  Returns true if the given feature \a feature is supported by the manager, for the specified type of organizer item \a organizeritemType
712
 
 */
713
 
bool QOrganizerItemManager::hasFeature(QOrganizerItemManager::ManagerFeature feature, const QString& organizeritemType) const
714
 
{
715
 
    return d->m_engine->hasFeature(feature, organizeritemType);
716
 
}
717
 
 
718
 
/*!
719
 
  Returns the list of data types supported by the manager
720
 
 */
721
 
QList<QVariant::Type> QOrganizerItemManager::supportedDataTypes() const
722
 
{
723
 
    return d->m_engine->supportedDataTypes();
724
 
}
725
 
 
726
 
/*!
727
 
  Returns true if the given \a filter is supported natively by the
728
 
  manager, and false if the filter behaviour would be emulated.
729
 
 
730
 
  Note: In some cases, the behaviour of an unsupported filter
731
 
  cannot be emulated.  For example, a filter that requests organizeritems
732
 
  that have changed since a given time depends on having that information
733
 
  available.  In these cases, the filter will fail.
734
 
 */
735
 
bool QOrganizerItemManager::isFilterSupported(const QOrganizerItemFilter& filter) const
736
 
{
737
 
    return d->m_engine->isFilterSupported(filter);
738
 
}
739
 
 
740
 
/*!
741
 
  Returns the list of organizer item types which are supported by this manager.
742
 
  This is a convenience function, equivalent to retrieving the allowable values
743
 
  for the \c QOrganizerItemType::FieldType field of the QOrganizerItemType definition
744
 
  which is valid in this manager.
745
 
 */
746
 
QStringList QOrganizerItemManager::supportedItemTypes() const
747
 
{
748
 
    return d->m_engine->supportedItemTypes();
749
 
}
750
 
 
751
 
/*!
752
 
  Returns the engine backend implementation version number
753
 
 */
754
 
int QOrganizerItemManager::managerVersion() const
755
 
{
756
 
    return d->m_engine->managerVersion();
757
 
}
758
 
 
759
 
/*! Returns the manager name for this QOrganizerItemManager */
760
 
QString QOrganizerItemManager::managerName() const
761
 
{
762
 
    return d->m_engine->managerName();
763
 
}
764
 
 
765
 
/*! Return the parameters relevant to the creation of this QOrganizerItemManager */
766
 
QMap<QString, QString> QOrganizerItemManager::managerParameters() const
767
 
{
768
 
    QMap<QString, QString> params = d->m_engine->managerParameters();
769
 
 
770
 
    params.remove(QString::fromAscii(QTORGANIZER_VERSION_NAME));
771
 
    params.remove(QString::fromAscii(QTORGANIZER_IMPLEMENTATION_VERSION_NAME));
772
 
    return params;
773
 
}
774
 
 
775
 
/*!
776
 
  Return the uri describing this QOrganizerItemManager, consisting of the manager name and any parameters.
777
 
 */
778
 
QString QOrganizerItemManager::managerUri() const
779
 
{
780
 
    return d->m_engine->managerUri();
781
 
}
782
 
 
783
 
#include "moc_qorganizeritemmanager.cpp"
784
 
 
785
 
QTM_END_NAMESPACE