~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/plugins/organizer/skeleton/qorganizerskeleton.cpp

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtOrganizer module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
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 Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/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 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include "qorganizerskeleton_p.h"
 
43
 
 
44
QT_BEGIN_NAMESPACE_ORGANIZER
 
45
 
 
46
QOrganizerManagerEngine* QOrganizerItemSkeletonFactory::engine(const QMap<QString, QString>& parameters, QOrganizerManager::Error* error)
 
47
{
 
48
    Q_UNUSED(parameters);
 
49
    Q_UNUSED(error);
 
50
 
 
51
    /* TODO - if you understand any specific parameters. save them in the engine so that engine::managerParameters can return them */
 
52
 
 
53
    QOrganizerItemSkeletonEngine* ret = new QOrganizerItemSkeletonEngine(); // manager takes ownership and will clean up.
 
54
    return ret;
 
55
}
 
56
 
 
57
QOrganizerItemEngineId* QOrganizerItemSkeletonFactory::createItemEngineId(const QMap<QString, QString>& parameters, const QString& idString) const
 
58
{
 
59
    /*
 
60
      TODO
 
61
 
 
62
      Instantiate your engine-specific item id in this function.
 
63
 
 
64
      If idString is not empty, then you should deserialize the idString
 
65
      (the opposite of your QOrganizerItemEngineId derived-class'
 
66
      toString() function), otherwise you should instantiate an empty
 
67
      engine-specific collection id.
 
68
 
 
69
      This function allows clients to deserialize serialized ids from
 
70
      your engine.
 
71
     */
 
72
    Q_UNUSED(parameters);
 
73
    QOrganizerItemSkeletonEngineId* retn = new QOrganizerItemSkeletonEngineId;
 
74
    if (!idString.isEmpty())
 
75
        retn->m_itemId = idString.toUInt();
 
76
    return retn;
 
77
}
 
78
 
 
79
QOrganizerCollectionEngineId* QOrganizerItemSkeletonFactory::createCollectionEngineId(const QMap<QString, QString>& parameters, const QString& idString) const
 
80
{
 
81
    /*
 
82
      TODO
 
83
 
 
84
      Instantiate your engine-specific collection id in this function.
 
85
 
 
86
      If idString is not empty, then you should deserialize the idString
 
87
      (the opposite of your QOrganizerCollectionEngineId derived-class'
 
88
      toString() function), otherwise you should instantiate an empty
 
89
      engine-specific collection id.
 
90
 
 
91
      This function allows clients to deserialize serialized ids from
 
92
      your engine.
 
93
     */
 
94
    Q_UNUSED(parameters);
 
95
    QOrganizerCollectionSkeletonEngineId* retn = new QOrganizerCollectionSkeletonEngineId;
 
96
    if (!idString.isEmpty())
 
97
        retn->m_collectionId = idString.toUInt();
 
98
    return retn;
 
99
}
 
100
 
 
101
QString QOrganizerItemSkeletonFactory::managerName() const
 
102
{
 
103
    /* TODO - put your engine name here */
 
104
    return QStringLiteral("skeleton");
 
105
}
 
106
 
 
107
QOrganizerItemSkeletonEngineId::QOrganizerItemSkeletonEngineId()
 
108
    : QOrganizerItemEngineId(), m_itemId(0)
 
109
{
 
110
    /*
 
111
      TODO
 
112
 
 
113
      Initialize any data members of your engine-specific item id in the constructor.
 
114
 
 
115
      This default constructor should not be used when returning a null id,
 
116
      but is provided in order to allow use of the ids in a list, and as an
 
117
      enabler for the implementation of QOrganizerItemId.
 
118
 
 
119
      When returning a null id, the backend should simply return a default
 
120
      constructed QOrganizerItemId.
 
121
 
 
122
      In this example, we use just a single quint32 to identify the item,
 
123
      however your engine may require more information in order to uniquely
 
124
      identify an item within it (e.g., a collection identifier plus an item
 
125
      identifier, and perhaps a datastore identifier which identifies the
 
126
      datastore in which the collection can be found).
 
127
     */
 
128
}
 
129
 
 
130
QOrganizerItemSkeletonEngineId::QOrganizerItemSkeletonEngineId(quint32 itemId)
 
131
    : QOrganizerItemEngineId(), m_itemId(itemId)
 
132
{
 
133
    /*
 
134
      TODO
 
135
 
 
136
      Whatever data members your particular class has, should be passed as arguments
 
137
      to a ctor of this type.  This is the constructor which will be used by your
 
138
      engine code.
 
139
 
 
140
      In particular, you will most likely be returning to clients an id by calling:
 
141
      QOrganizerItemId id(new QOrganizerItemSkeletonEngineId(3));
 
142
      or something similar.  Note that the QOrganizerItemId constructor which
 
143
      takes a QOrganizerItemEngineId pointer as a parameter takes ownership
 
144
      of that pointer (and so controls its lifetime).
 
145
     */
 
146
}
 
147
 
 
148
QOrganizerItemSkeletonEngineId::QOrganizerItemSkeletonEngineId(const QOrganizerItemSkeletonEngineId& other)
 
149
    : QOrganizerItemEngineId(), m_itemId(other.m_itemId)
 
150
{
 
151
    /* TODO - implement a copy constructor for your engine-specific id class */
 
152
}
 
153
 
 
154
QOrganizerItemSkeletonEngineId::~QOrganizerItemSkeletonEngineId()
 
155
{
 
156
    /* TODO - Clean up any memory in use by your engine-specific id. */
 
157
}
 
158
 
 
159
bool QOrganizerItemSkeletonEngineId::isEqualTo(const QOrganizerItemEngineId* other) const
 
160
{
 
161
    /*
 
162
      TODO
 
163
 
 
164
      The isEqualTo(other) function is called by the QOrganizerItemId::operator==(other) function.
 
165
      You must implement this in terms of the data members which your class contains.
 
166
 
 
167
      An example implementation is provided below, for the case where only a single quint32
 
168
      is required to uniquely identify an item in a manager.
 
169
     */
 
170
 
 
171
    quint32 otherItemId = static_cast<const QOrganizerItemSkeletonEngineId*>(other)->m_itemId;
 
172
    if (m_itemId != otherItemId)
 
173
        return false;
 
174
    return true;
 
175
}
 
176
 
 
177
bool QOrganizerItemSkeletonEngineId::isLessThan(const QOrganizerItemEngineId* other) const
 
178
{
 
179
    /*
 
180
      TODO
 
181
 
 
182
      The isLessThan(other) function is called by the QOrganizerItemId::operator<(other) function.
 
183
      You must implement this in terms of the data members which your class contains.
 
184
 
 
185
      An example implementation is provided below, for the case where only a single quint32
 
186
      is required to uniquely identify an item in a manager.
 
187
     */
 
188
 
 
189
    quint32 otherItemId = static_cast<const QOrganizerItemSkeletonEngineId*>(other)->m_itemId;
 
190
    return (m_itemId < otherItemId);
 
191
}
 
192
 
 
193
QString QOrganizerItemSkeletonEngineId::managerUri() const
 
194
{
 
195
    // TODO: make this return the actual managerUri (including params) of the
 
196
    // engine it is associated with
 
197
    static const QString uri(QStringLiteral("qtorganizer:skeleton:"));
 
198
    return uri;
 
199
}
 
200
 
 
201
QOrganizerItemEngineId* QOrganizerItemSkeletonEngineId::clone() const
 
202
{
 
203
    /*
 
204
      TODO
 
205
 
 
206
      When a QOrganizerItemId is copied or assigned, it performs a clone of
 
207
      the engine-specific id.  This function is called in that case.
 
208
 
 
209
      Implement this function so that the data members of your engine-specific id
 
210
      are deep-copied.
 
211
 
 
212
      An example implementation for the case where an item can be uniquely identified
 
213
      with just a single quint32 is given below.
 
214
     */
 
215
 
 
216
    QOrganizerItemSkeletonEngineId *myClone = new QOrganizerItemSkeletonEngineId;
 
217
    myClone->m_itemId = m_itemId;
 
218
    return myClone;
 
219
}
 
220
 
 
221
#ifndef QT_NO_DEBUG_STREAM
 
222
QDebug& QOrganizerItemSkeletonEngineId::debugStreamOut(QDebug& dbg) const
 
223
{
 
224
    /*
 
225
      TODO
 
226
 
 
227
      In order to allow clients to debug applications, you must implement this
 
228
      function.  We recommend streaming the name of your class followed by the
 
229
      values of the data members in your engine-specific id class in
 
230
      parentheses.
 
231
 
 
232
      An example implementation for the case where an item can be uniquely identified
 
233
      with just a single quint32 is given below.
 
234
 
 
235
      Note that you must include the #ifndef QT_NO_DEBUG_STREAM preprocessor
 
236
      directive block in order to ensure compilation in environments where that
 
237
      directive is defined.
 
238
     */
 
239
 
 
240
    dbg.nospace() << "QOrganizerItemSkeletonEngineId(" << m_itemId << ")";
 
241
    return dbg.maybeSpace();
 
242
}
 
243
#endif
 
244
 
 
245
QString QOrganizerItemSkeletonEngineId::toString() const
 
246
{
 
247
    /*
 
248
      TODO
 
249
 
 
250
      In order to allow clients to serialize QOrganizerItemId's, you must implement
 
251
      this function.
 
252
 
 
253
      An example implementation for the case where an item can be uniquely identified
 
254
      with just a single quint32 is given below.
 
255
     */
 
256
 
 
257
    return QString::number(m_itemId);
 
258
}
 
259
 
 
260
uint QOrganizerItemSkeletonEngineId::hash() const
 
261
{
 
262
    /*
 
263
      TODO
 
264
 
 
265
      Provide a hash function for your engine-specific id.
 
266
      Note that the hash doesn't strictly need to be unique, since isEqualTo()
 
267
      ensures that individual id's in a single hash-bucket can be uniquely
 
268
      determined; however a better hash function will result in better performance
 
269
      because the ids will be distributed more randomly in a hash table.
 
270
 
 
271
      In the example implementation below, we could simply return the id, since the
 
272
      id is a quint32.  In more complex id classes, however, you may need to
 
273
      qHash() individual data members and combine the results somehow.
 
274
     */
 
275
 
 
276
    return QT_PREPEND_NAMESPACE(qHash)(m_itemId);
 
277
}
 
278
 
 
279
 
 
280
QOrganizerCollectionSkeletonEngineId::QOrganizerCollectionSkeletonEngineId()
 
281
    : QOrganizerCollectionEngineId(), m_collectionId(0)
 
282
{
 
283
    /*
 
284
      TODO
 
285
 
 
286
      Initialize any data members of your engine-specific collection id in the constructor.
 
287
 
 
288
      This default constructor should not be used when returning a null id,
 
289
      but is provided in order to allow use of the ids in a list, and as an
 
290
      enabler for the implementation of QOrganizerCollectionId.
 
291
 
 
292
      When returning a null id, the backend should simply return a default
 
293
      constructed QOrganizerCollectionId.
 
294
 
 
295
      In this example, we use just a single quint32 to identify the collection,
 
296
      however your engine may require more information in order to uniquely
 
297
      identify a collection within it (e.g., a collection identifier plus a datastore
 
298
      identifier which identifies the datastore in which the collection can be found).
 
299
     */
 
300
}
 
301
 
 
302
QOrganizerCollectionSkeletonEngineId::QOrganizerCollectionSkeletonEngineId(quint32 collectionId)
 
303
    : QOrganizerCollectionEngineId(), m_collectionId(collectionId)
 
304
{
 
305
    /*
 
306
      TODO
 
307
 
 
308
      Whatever data members your particular class has, should be passed as arguments
 
309
      to a ctor of this type.  This is the constructor which will be used by your
 
310
      engine code.
 
311
 
 
312
      In particular, you will most likely be returning to clients an id by calling:
 
313
      QOrganizerCollectionId id(new QOrganizerCollectionSkeletonEngineId(3));
 
314
      or something similar.  Note that the QOrganizerCollectionId constructor which
 
315
      takes a QOrganizerCollectionEngineId pointer as a parameter takes ownership
 
316
      of that pointer (and so controls its lifetime).
 
317
     */
 
318
}
 
319
 
 
320
QOrganizerCollectionSkeletonEngineId::QOrganizerCollectionSkeletonEngineId(const QOrganizerCollectionSkeletonEngineId& other)
 
321
    : QOrganizerCollectionEngineId(), m_collectionId(other.m_collectionId)
 
322
{
 
323
    /* TODO - implement a copy constructor for your engine-specific id class */
 
324
}
 
325
 
 
326
QOrganizerCollectionSkeletonEngineId::~QOrganizerCollectionSkeletonEngineId()
 
327
{
 
328
    /* TODO - Clean up any memory in use by your engine-specific id. */
 
329
}
 
330
 
 
331
bool QOrganizerCollectionSkeletonEngineId::isEqualTo(const QOrganizerCollectionEngineId* other) const
 
332
{
 
333
    /*
 
334
      TODO
 
335
 
 
336
      The isEqualTo(other) function is called by the QOrganizerCollectionId::operator==(other) function.
 
337
      You must implement this in terms of the data members which your class contains.
 
338
 
 
339
      An example implementation is provided below, for the case where only a single quint32
 
340
      is required to uniquely identify a collection in a manager.
 
341
     */
 
342
 
 
343
    quint32 otherCollectionId = static_cast<const QOrganizerCollectionSkeletonEngineId*>(other)->m_collectionId;
 
344
    if (m_collectionId != otherCollectionId)
 
345
        return false;
 
346
    return true;
 
347
}
 
348
 
 
349
bool QOrganizerCollectionSkeletonEngineId::isLessThan(const QOrganizerCollectionEngineId* other) const
 
350
{
 
351
    /*
 
352
      TODO
 
353
 
 
354
      The isLessThan(other) function is called by the QOrganizerCollectionId::operator<(other) function.
 
355
      You must implement this in terms of the data members which your class contains.
 
356
 
 
357
      An example implementation is provided below, for the case where only a single quint32
 
358
      is required to uniquely identify a collection in a manager.
 
359
     */
 
360
 
 
361
    quint32 otherCollectionId = static_cast<const QOrganizerCollectionSkeletonEngineId*>(other)->m_collectionId;
 
362
    if (m_collectionId < otherCollectionId)
 
363
        return true;
 
364
    return false;
 
365
}
 
366
 
 
367
QString QOrganizerCollectionSkeletonEngineId::managerUri() const
 
368
{
 
369
    // TODO: make this return the actual managerUri (including params) of the
 
370
    // engine it is associated with
 
371
    static const QString uri(QStringLiteral("qtorganizer:skeleton:"));
 
372
    return uri;
 
373
}
 
374
 
 
375
QOrganizerCollectionEngineId* QOrganizerCollectionSkeletonEngineId::clone() const
 
376
{
 
377
    /*
 
378
      TODO
 
379
 
 
380
      When a QOrganizerCollectionId is copied or assigned, it performs a clone of
 
381
      the engine-specific id.  This function is called in that case.
 
382
 
 
383
      Implement this function so that the data members of your engine-specific id
 
384
      are deep-copied.
 
385
 
 
386
      An example implementation for the case where a collection can be uniquely identified
 
387
      with just a single quint32 is given below.
 
388
     */
 
389
 
 
390
    QOrganizerCollectionSkeletonEngineId *myClone = new QOrganizerCollectionSkeletonEngineId;
 
391
    myClone->m_collectionId = m_collectionId;
 
392
    return myClone;
 
393
}
 
394
 
 
395
#ifndef QT_NO_DEBUG_STREAM
 
396
QDebug& QOrganizerCollectionSkeletonEngineId::debugStreamOut(QDebug& dbg) const
 
397
{
 
398
    /*
 
399
      TODO
 
400
 
 
401
      In order to allow clients to debug applications, you must implement this
 
402
      function.  We recommend streaming the name of your class followed by the
 
403
      values of the data members in your engine-specific id class in
 
404
      parentheses.
 
405
 
 
406
      An example implementation for the case where a collection can be uniquely identified
 
407
      with just a single quint32 is given below.
 
408
 
 
409
      Note that you must include the #ifndef QT_NO_DEBUG_STREAM preprocessor
 
410
      directive block in order to ensure compilation in environments where that
 
411
      directive is defined.
 
412
     */
 
413
 
 
414
    dbg.nospace() << "QOrganizerCollectionSkeletonEngineId(" << m_collectionId << ")";
 
415
    return dbg.maybeSpace();
 
416
}
 
417
#endif
 
418
 
 
419
QString QOrganizerCollectionSkeletonEngineId::toString() const
 
420
{
 
421
    /*
 
422
      TODO
 
423
 
 
424
      In order to allow clients to serialize QOrganizerCollectionId's, you must implement
 
425
      this function.
 
426
 
 
427
      An example implementation for the case where a collection can be uniquely identified
 
428
      with just a single quint32 is given below.
 
429
     */
 
430
 
 
431
    return QString::number(m_collectionId);
 
432
}
 
433
 
 
434
uint QOrganizerCollectionSkeletonEngineId::hash() const
 
435
{
 
436
    /*
 
437
      TODO
 
438
 
 
439
      Provide a hash function for your engine-specific id.
 
440
      Note that the hash doesn't strictly need to be unique, since isEqualTo()
 
441
      ensures that individual id's in a single hash-bucket can be uniquely
 
442
      determined; however a better hash function will result in better performance
 
443
      because the ids will be distributed more randomly in a hash table.
 
444
 
 
445
      In the example implementation below, we could simply return the id, since the
 
446
      id is a quint32.  In more complex id classes, however, you may need to
 
447
      qHash() individual data members and combine the results somehow.
 
448
     */
 
449
 
 
450
    return QT_PREPEND_NAMESPACE(qHash)(m_collectionId);
 
451
}
 
452
 
 
453
 
 
454
 
 
455
QOrganizerItemSkeletonEngine::~QOrganizerItemSkeletonEngine()
 
456
{
 
457
    /* TODO clean up your stuff.  Perhaps a QScopedPointer or QSharedDataPointer would be in order */
 
458
}
 
459
 
 
460
QString QOrganizerItemSkeletonEngine::managerName() const
 
461
{
 
462
    /* TODO - put your engine name here */
 
463
    return QStringLiteral("skeleton");
 
464
}
 
465
 
 
466
QMap<QString, QString> QOrganizerItemSkeletonEngine::managerParameters() const
 
467
{
 
468
    /* TODO - in case you have any actual parameters that are relevant that you saved in the factory method, return them here */
 
469
    return QMap<QString, QString>();
 
470
}
 
471
 
 
472
QList<QOrganizerItem> QOrganizerItemSkeletonEngine::itemOccurrences(const QOrganizerItem &parentItem,
 
473
                                                                    const QDateTime &startDateTime,
 
474
                                                                    const QDateTime &endDateTime, int maxCount,
 
475
                                                                    const QOrganizerItemFetchHint &fetchHint,
 
476
                                                                    QOrganizerManager::Error *error)
 
477
{
 
478
    /*
 
479
        TODO
 
480
 
 
481
        This function should create a list of occurrences that occur in the time period from the supplied item,
 
482
        generated from the parent item.
 
483
 
 
484
        The periodStart should always be valid, and either the periodEnd or the maxCount will be valid (if periodEnd is
 
485
        valid, use that.  Otherwise use the count).  It's permissible to limit the number of items returned...
 
486
 
 
487
        Basically, if the parent item is an Event, a list of EventOccurrences should be returned.  Similarly for
 
488
        Todo/TodoOccurrence.
 
489
 
 
490
        If there are no instances, return an empty list.
 
491
 
 
492
        The returned items should have a QOrganizerItemParent detail that points to the parentItem and the
 
493
        original instance that the event would have occurred on (e.g. with an exception).
 
494
 
 
495
        They should not have recurrence information details in them.
 
496
 
 
497
        We might change the signature to split up the periodStart + periodEnd / periodStart + maxCount cases.
 
498
    */
 
499
 
 
500
    return QOrganizerManagerEngine::itemOccurrences(parentItem, startDateTime, endDateTime, maxCount, fetchHint, error);
 
501
}
 
502
 
 
503
QList<QOrganizerItem> QOrganizerItemSkeletonEngine::itemsForExport(const QDateTime &startDateTime,
 
504
                                                                   const QDateTime &endDateTime,
 
505
                                                                   const QOrganizerItemFilter &filter,
 
506
                                                                   const QList<QOrganizerItemSortOrder> &sortOrders,
 
507
                                                                   const QOrganizerItemFetchHint &fetchHint,
 
508
                                                                   QOrganizerManager::Error *error)
 
509
{
 
510
    return QOrganizerManagerEngine::itemsForExport(startDateTime, endDateTime, filter, sortOrders, fetchHint, error);
 
511
}
 
512
 
 
513
QList<QOrganizerItemId> QOrganizerItemSkeletonEngine::itemIds(const QOrganizerItemFilter &filter,
 
514
                                                              const QDateTime &startDateTime,
 
515
                                                              const QDateTime &endDateTime,
 
516
                                                              const QList<QOrganizerItemSortOrder> &sortOrders,
 
517
                                                              QOrganizerManager::Error *error)
 
518
{
 
519
    /*
 
520
        TODO
 
521
 
 
522
        Given the supplied filter and sort order, fetch the list of items [not instances] that correspond, and return their ids.
 
523
 
 
524
        If you don't support the filter or sort orders, you can fetch a partially (or un-) filtered list and ask the helper
 
525
        functions to filter and sort it for you.
 
526
 
 
527
        If you do have to fetch, consider setting a fetch hint that restricts the information to that needed for filtering/sorting.
 
528
    */
 
529
 
 
530
    *error = QOrganizerManager::NotSupportedError; // TODO <- remove this
 
531
 
 
532
    QList<QOrganizerItem> partiallyFilteredItems; // = ..., your code here.. [TODO]
 
533
    QList<QOrganizerItem> ret;
 
534
 
 
535
    foreach(const QOrganizerItem& item, partiallyFilteredItems) {
 
536
        if (QOrganizerManagerEngine::isItemBetweenDates(item, startDateTime, endDateTime) && QOrganizerManagerEngine::testFilter(filter, item)) {
 
537
            QOrganizerManagerEngine::addSorted(&ret, item, sortOrders);
 
538
        }
 
539
    }
 
540
 
 
541
    return QOrganizerManager::extractIds(ret);
 
542
}
 
543
 
 
544
QList<QOrganizerItem> QOrganizerItemSkeletonEngine::items(const QOrganizerItemFilter &filter, const QDateTime &startDateTime,
 
545
                                                          const QDateTime &endDateTime, int maxCount,
 
546
                                                          const QList<QOrganizerItemSortOrder> &sortOrders,
 
547
                                                          const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error)
 
548
{
 
549
    /*
 
550
        TODO
 
551
 
 
552
        Given the supplied filter and sort order, fetch the list of items [not instances] that correspond, and return them.
 
553
 
 
554
        If you don't support the filter or sort orders, you can fetch a partially (or un-) filtered list and ask the helper
 
555
        functions to filter and sort it for you.
 
556
 
 
557
        The fetch hint suggests how much of the item to fetch.  You can ignore the fetch hint and fetch everything (but you must
 
558
        fetch at least what is mentioned in the fetch hint).
 
559
    */
 
560
 
 
561
    Q_UNUSED(startDateTime)
 
562
    Q_UNUSED(endDateTime)
 
563
    Q_UNUSED(maxCount)
 
564
    Q_UNUSED(fetchHint)
 
565
 
 
566
    *error = QOrganizerManager::NotSupportedError; // TODO <- remove this
 
567
 
 
568
    QList<QOrganizerItem> partiallyFilteredItems; // = ..., your code here.. [TODO]
 
569
    QList<QOrganizerItem> ret;
 
570
 
 
571
    foreach(const QOrganizerItem& item, partiallyFilteredItems) {
 
572
        if (QOrganizerManagerEngine::isItemBetweenDates(item, startDateTime, endDateTime) && QOrganizerManagerEngine::testFilter(filter, item)) {
 
573
            QOrganizerManagerEngine::addSorted(&ret, item, sortOrders);
 
574
        }
 
575
    }
 
576
 
 
577
    /* An alternative formulation, depending on how your engine is implemented is just:
 
578
 
 
579
        foreach(const QOrganizerItemId& id, itemIds(filter, sortOrders, error)) {
 
580
            ret.append(item(id, fetchHint, error);
 
581
        }
 
582
     */
 
583
 
 
584
    return ret;
 
585
}
 
586
 
 
587
QList<QOrganizerItem> QOrganizerItemSkeletonEngine::items(const QList<QOrganizerItemId> &itemIds, const QOrganizerItemFetchHint &fetchHint,
 
588
                                                          QMap<int, QOrganizerManager::Error> *errorMap, QOrganizerManager::Error* error)
 
589
{
 
590
    /*
 
591
        TODO
 
592
 
 
593
        Fetch a single item by id.
 
594
 
 
595
        The fetch hint suggests how much of the item to fetch.  You can ignore the fetch hint and fetch everything (but you must
 
596
        fetch at least what is mentioned in the fetch hint).
 
597
 
 
598
    */
 
599
    return QOrganizerManagerEngine::items(itemIds, fetchHint, errorMap, error);
 
600
}
 
601
 
 
602
bool QOrganizerItemSkeletonEngine::saveItems(QList<QOrganizerItem> *items, const QList<QOrganizerItemDetail::DetailType> &detailMask,
 
603
                                             QMap<int, QOrganizerManager::Error>* errorMap, QOrganizerManager::Error* error)
 
604
{
 
605
    /*
 
606
        TODO
 
607
 
 
608
        Save a list of items into the collection specified in each (or their current collection
 
609
        if no collection is specified and they already exist, or the default collection
 
610
        if no collection is specified and they do not exist).
 
611
 
 
612
        For each item, convert it to your type, assign an item id, and update the
 
613
        QOrganizerItem's ID (in the list above - e.g. *items[idx] = updated item).
 
614
        Then, examine the collection id specified in each item and save the item in that collection.
 
615
 
 
616
        If you encounter an error (e.g. converting to type, or saving), insert an entry into
 
617
        the map above at the corresponding index (e.g. errorMap->insert(idx, QOIM::InvalidDetailError).
 
618
        You should set the "error" variable as well (first, last, most serious error etc).
 
619
 
 
620
        The item passed in should be validated according to the schema.
 
621
    */
 
622
    return QOrganizerManagerEngine::saveItems(items, detailMask, errorMap, error);
 
623
}
 
624
 
 
625
bool QOrganizerItemSkeletonEngine::removeItems(const QList<QOrganizerItemId> &itemIds, QMap<int, QOrganizerManager::Error> *errorMap,
 
626
                                               QOrganizerManager::Error *error)
 
627
{
 
628
    /*
 
629
        TODO
 
630
 
 
631
        Remove a list of items, given by their id.
 
632
 
 
633
        If you encounter an error, insert an error into the appropriate place in the error map,
 
634
        and update the error variable as well.
 
635
 
 
636
        DoesNotExistError should be used if the id refers to a non existent item.
 
637
    */
 
638
    return QOrganizerManagerEngine::removeItems(itemIds, errorMap, error);
 
639
}
 
640
 
 
641
QOrganizerCollection QOrganizerItemSkeletonEngine::defaultCollection(QOrganizerManager::Error* error)
 
642
{
 
643
    /*
 
644
        TODO
 
645
 
 
646
        This allows clients to determine which collection an item will be saved,
 
647
        if the item is saved via saveItems() without specifying a collection id
 
648
        of a collection in which to save the item, via item->setCollectionId().
 
649
 
 
650
        There is always at least one collection in a manager, and all items are
 
651
        saved in exactly one collection.
 
652
     */
 
653
    return QOrganizerManagerEngine::defaultCollection(error);
 
654
}
 
655
 
 
656
QOrganizerCollection QOrganizerItemSkeletonEngine::collection(const QOrganizerCollectionId& collectionId, QOrganizerManager::Error* error)
 
657
{
 
658
    /*
 
659
        TODO
 
660
 
 
661
        This allows clients to retrieve a collection by (manager) id.
 
662
        Prior to saving items, clients will set which collection the item will/should
 
663
        be saved by calling item->setCollectionId().
 
664
     */
 
665
    return QOrganizerManagerEngine::collection(collectionId, error);
 
666
}
 
667
 
 
668
QList<QOrganizerCollection> QOrganizerItemSkeletonEngine::collections(QOrganizerManager::Error* error)
 
669
{
 
670
    /*
 
671
        TODO
 
672
 
 
673
        This allows clients to retrieve a list of all of the collections currently
 
674
        in this manager.  Some backends will have a prepopulated list of valid
 
675
        collections, others will not.  A collection can have properties
 
676
        like colour, description, perhaps a priority, etc etc.
 
677
     */
 
678
    return QOrganizerManagerEngine::collections(error);
 
679
}
 
680
 
 
681
bool QOrganizerItemSkeletonEngine::saveCollection(QOrganizerCollection* collection, QOrganizerManager::Error* error)
 
682
{
 
683
    /*
 
684
        TODO
 
685
 
 
686
        This allows clients to create or update collections if supported by the
 
687
        backend.
 
688
     */
 
689
    return QOrganizerManagerEngine::saveCollection(collection, error);
 
690
}
 
691
 
 
692
bool QOrganizerItemSkeletonEngine::removeCollection(const QOrganizerCollectionId& collectionId, QOrganizerManager::Error* error)
 
693
{
 
694
    /*
 
695
        TODO
 
696
 
 
697
        This allows clients to remove collections if supported by the backend.
 
698
 
 
699
        When a collection is removed, all items in the collection are removed.
 
700
        That is, they are _not_ transferred to another collection.
 
701
 
 
702
        If the user attempts to remove the collection which is the default collection,
 
703
        the backend may decide whether to fail (with a permissions error) or to
 
704
        succeed and arbitrarily choose another collection to be the default collection.
 
705
     */
 
706
    return QOrganizerManagerEngine::removeCollection(collectionId, error);
 
707
}
 
708
 
 
709
bool QOrganizerItemSkeletonEngine::startRequest(QOrganizerAbstractRequest* req)
 
710
{
 
711
    /*
 
712
        TODO
 
713
 
 
714
        This is the entry point to the async API.  The request object describes the
 
715
        type of request (switch on req->type()).  Req will not be null when called
 
716
        by the framework.
 
717
 
 
718
        Generally, you can queue the request and process them at some later time
 
719
        (probably in another thread).
 
720
 
 
721
        Once you start a request, call the updateRequestState and/or the
 
722
        specific updateXXXXXRequest functions to mark it in the active state.
 
723
 
 
724
        If your engine is particularly fast, or the operation involves only in
 
725
        memory data, you can process and complete the request here.  That is
 
726
        probably not the case, though.
 
727
 
 
728
        Note that when the client is threaded, and the request might live on a
 
729
        different thread, you might need to be careful with locking.  In particular,
 
730
        the request might be deleted while you are still working on it.  In this case,
 
731
        your requestDestroyed function will be called while the request is still valid,
 
732
        and you should block in that function until your worker thread (etc) has been
 
733
        notified not to touch that request any more.
 
734
 
 
735
        We plan to provide some boiler plate code that will allow you to:
 
736
 
 
737
        1) implement the sync functions, and have the async versions call the sync
 
738
           in another thread
 
739
 
 
740
        2) or implement the async versions of the function, and have the sync versions
 
741
           call the async versions.
 
742
 
 
743
        It's not ready yet, though.
 
744
 
 
745
        Return true if the request can be started, false otherwise.  You can set an error
 
746
        in the request if you like.
 
747
    */
 
748
    return QOrganizerManagerEngine::startRequest(req);
 
749
}
 
750
 
 
751
bool QOrganizerItemSkeletonEngine::cancelRequest(QOrganizerAbstractRequest* req)
 
752
{
 
753
    /*
 
754
        TODO
 
755
 
 
756
        Cancel an in progress async request.  If not possible, return false from here.
 
757
    */
 
758
    return QOrganizerManagerEngine::cancelRequest(req);
 
759
}
 
760
 
 
761
bool QOrganizerItemSkeletonEngine::waitForRequestFinished(QOrganizerAbstractRequest* req, int msecs)
 
762
{
 
763
    /*
 
764
        TODO
 
765
 
 
766
        Wait for a request to complete (up to a max of msecs milliseconds).
 
767
 
 
768
        Return true if the request is finished (including if it was already).  False otherwise.
 
769
 
 
770
        You should really implement this function, if nothing else than as a delay, since clients
 
771
        may call this in a loop.
 
772
 
 
773
        It's best to avoid processing events, if you can, or at least only process non-UI events.
 
774
    */
 
775
    return QOrganizerManagerEngine::waitForRequestFinished(req, msecs);
 
776
}
 
777
 
 
778
void QOrganizerItemSkeletonEngine::requestDestroyed(QOrganizerAbstractRequest* req)
 
779
{
 
780
    /*
 
781
        TODO
 
782
 
 
783
        This is called when a request is being deleted.  It lets you know:
 
784
 
 
785
        1) the client doesn't care about the request any more.  You can still complete it if
 
786
           you feel like it.
 
787
        2) you can't reliably access any properties of the request pointer any more.  The pointer will
 
788
           be invalid once this function returns.
 
789
 
 
790
        This means that if you have a worker thread, you need to let that thread know that the
 
791
        request object is not valid and block until that thread acknowledges it.  One way to do this
 
792
        is to have a QSet<QOIAR*> (or QMap<QOIAR, MyCustomRequestState>) that tracks active requests, and
 
793
        insert into that set in startRequest, and remove in requestDestroyed (or when it finishes or is
 
794
        cancelled).  Protect that set/map with a mutex, and make sure you take the mutex in the worker
 
795
        thread before calling any of the QOIAR::updateXXXXXXRequest functions.  And be careful of lock
 
796
        ordering problems :D
 
797
 
 
798
    */
 
799
    return QOrganizerManagerEngine::requestDestroyed(req);
 
800
}
 
801
 
 
802
QList<QOrganizerItemFilter::FilterType> QOrganizerItemSkeletonEngine::supportedFilters() const
 
803
{
 
804
    // TODO if you engine can natively support the filter, return true.  Otherwise you should emulate support in the item{Ids} functions.
 
805
    return QList<QOrganizerItemFilter::FilterType>();
 
806
}
 
807
 
 
808
QList<QOrganizerItemDetail::DetailType> QOrganizerItemSkeletonEngine::supportedItemDetails(QOrganizerItemType::ItemType itemType) const
 
809
{
 
810
    // TODO - return which [predefined] details this engine supports for this item type
 
811
    Q_UNUSED(itemType)
 
812
 
 
813
    return QList<QOrganizerItemDetail::DetailType>();
 
814
}
 
815
 
 
816
QList<QOrganizerItemType::ItemType> QOrganizerItemSkeletonEngine::supportedItemTypes() const
 
817
{
 
818
    // TODO - return which [predefined] types this engine supports
 
819
    QList<QOrganizerItemType::ItemType> ret;
 
820
 
 
821
    ret << QOrganizerItemType::TypeEvent;
 
822
    ret << QOrganizerItemType::TypeEventOccurrence;
 
823
    ret << QOrganizerItemType::TypeJournal;
 
824
    ret << QOrganizerItemType::TypeNote;
 
825
    ret << QOrganizerItemType::TypeTodo;
 
826
    ret << QOrganizerItemType::TypeTodoOccurrence;
 
827
 
 
828
    return ret;
 
829
}
 
830
 
 
831
#include "moc_qorganizerskeleton_p.cpp"
 
832
 
 
833
QT_END_NAMESPACE_ORGANIZER