~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/plugins/organizer/jsondb/qorganizerjsondbrequestthread.h

  • 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
#ifndef QORGANIZERJSONDBREQUESTTHREAD_H
 
43
#define QORGANIZERJSONDBREQUESTTHREAD_H
 
44
 
 
45
//
 
46
//  W A R N I N G
 
47
//  -------------
 
48
//
 
49
// This file is not part of the Qt API.  It exists purely as an
 
50
// implementation detail.  This header file may change from version to
 
51
// version without notice, or even be removed.
 
52
//
 
53
// We mean it.
 
54
//
 
55
 
 
56
#include "qorganizerjsondbengine.h"
 
57
 
 
58
#include <QtOrganizer/qorganizercollectionchangeset.h>
 
59
#include <QtOrganizer/qorganizeritemchangeset.h>
 
60
#include <QtOrganizer/qorganizeritemrequests.h>
 
61
 
 
62
#include <QtCore/qthread.h>
 
63
 
 
64
QT_BEGIN_NAMESPACE
 
65
class QMutex;
 
66
class QTimer;
 
67
QT_END_NAMESPACE
 
68
 
 
69
QT_BEGIN_NAMESPACE_ORGANIZER
 
70
 
 
71
class QOrganizerJsonDbRequestManager;
 
72
class QOrganizerJsonDbEngine;
 
73
class QOrganizerJsonDbDataStorage;
 
74
 
 
75
class QOrganizerJsonDbRequestThread : public QThread
 
76
{
 
77
    Q_OBJECT
 
78
public:
 
79
    QOrganizerJsonDbRequestThread();
 
80
    virtual ~QOrganizerJsonDbRequestThread();
 
81
 
 
82
    void setEngine(QOrganizerJsonDbEngine* engine);
 
83
    void addRequest(QOrganizerAbstractRequest* req);
 
84
    bool waitForRequestFinished(QOrganizerAbstractRequest* req, int msecs);
 
85
    void requestDestroyed(QOrganizerAbstractRequest* req);
 
86
    QOrganizerCollection defaultCollection() const;
 
87
 
 
88
public slots:
 
89
    void handleRequest(QOrganizerAbstractRequest* req);
 
90
 
 
91
signals:
 
92
    void initialized();
 
93
 
 
94
protected:
 
95
    virtual void run();
 
96
 
 
97
private slots:
 
98
    // Since these three slots are triggered either by signals from data storage for notifications
 
99
    // from JsonDb, or by the timer, and they are executed only in this thread, no mutex is needed.
 
100
    void onItemAdded(const QOrganizerItemId &itemId);
 
101
    void onItemChanged(const QOrganizerItemId &itemId);
 
102
    void onItemRemoved(const QOrganizerItemId &itemId);
 
103
    void onCollectionAdded(const QOrganizerCollectionId &collectionId);
 
104
    void onCollectionChanged(const QOrganizerCollectionId &collectionId);
 
105
    void onCollectionRemoved(const QOrganizerCollectionId &collectionId);
 
106
    void onTimeout();
 
107
 
 
108
private:
 
109
    void handleItemSaveRequest(QOrganizerItemSaveRequest* saveReq);
 
110
    void handleItemFetchRequest(QOrganizerItemFetchRequest* fetchReq);
 
111
    void handleItemIdFetchRequest(QOrganizerItemIdFetchRequest* idFetchReq);
 
112
    void handleItemFetchByIdRequest(QOrganizerItemFetchByIdRequest* fetchByIdReq);
 
113
    void handleItemFetchForExportRequest(QOrganizerItemFetchForExportRequest *fetchForExportReq);
 
114
    void handleItemOccurrenceFetchRequest(QOrganizerItemOccurrenceFetchRequest* occurrenceFetchReq);
 
115
    void handleItemRemoveRequest(QOrganizerItemRemoveRequest* removeReq);
 
116
    void handleItemRemoveByIdRequest(QOrganizerItemRemoveByIdRequest *removeByIdReq);
 
117
    void handleCollectionSaveRequest(QOrganizerCollectionSaveRequest* collectionSaveReq);
 
118
    void handleCollectionFetchRequest(QOrganizerCollectionFetchRequest* collectionFetchReq);
 
119
    void handleCollectionRemoveRequest(QOrganizerCollectionRemoveRequest* collectionRemoveReq);
 
120
    void initDefaultCollection();
 
121
 
 
122
    void finishRequest(QOrganizerAbstractRequest &request, QOrganizerManager::Error latestError,
 
123
                              const QMap<int, QOrganizerManager::Error> &errorMap,
 
124
                              const QList<QOrganizerItem> &itemList = QList<QOrganizerItem>(),
 
125
                              const QList<QOrganizerCollection> &collectionList = QList<QOrganizerCollection>(),
 
126
                              const QList<QOrganizerItemId> &itemIdList = QList<QOrganizerItemId>());
 
127
 
 
128
    QOrganizerItem fetchParentItem(const QOrganizerItem &occurrence);
 
129
    bool typesAreRelated(QOrganizerItemType::ItemType occurrenceType, QOrganizerItemType::ItemType parentType);
 
130
    bool fixParentReferences(QOrganizerItem *item, const QOrganizerItem &parentItem);
 
131
    bool fixGuidReferences(QOrganizerItem *item, const QOrganizerItem &parentItem);
 
132
    bool fixCollectionReferences(QOrganizerItem *item, const QOrganizerItem &parentItem, bool itemIsNew, QOrganizerJsonDbEngine::StorageLocation storageLocation);
 
133
 
 
134
    QList<QOrganizerItem> internalItems(const QDateTime &startDate, const QDateTime &endDate, const QOrganizerItemFilter &filter, const QList<QOrganizerItemSortOrder> &sortOrders,
 
135
                                        const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error, bool forExport, QOrganizerJsonDbEngine::StorageLocations storageLocations) const;
 
136
    QList<QOrganizerItem> internalItemOccurrences(const QOrganizerItem &parentItem, const QDateTime &periodStart, const QDateTime &periodEnd, const QOrganizerItemFetchHint &fetchHint,
 
137
                                                  int maxCount, bool includeExceptions, bool sortItems, QList<QDate> *exceptionDates, QOrganizerManager::Error *error) const;
 
138
 
 
139
    void removeItems(const QList<QOrganizerItemId> &itemIds, QOrganizerManager::Error *error, QMap<int, QOrganizerManager::Error> *errorMap);
 
140
    void removeAlarmObjects(const QList<QOrganizerItemId> &itemIds, const QMap<int, QOrganizerManager::Error> &errorMap);
 
141
 
 
142
    bool validRequest(QOrganizerAbstractRequest *req);
 
143
    bool validPlatform(QOrganizerAbstractRequest *req);
 
144
 
 
145
    QOrganizerManager::Error checkRequestSpecificStorageLocation(const QOrganizerJsonDbEngine::StorageLocations &requestSpecificStorageLocations);
 
146
    QOrganizerJsonDbEngine::StorageLocations resolveNeededStorageLocationsForItems(const QList<QOrganizerItemId> &itemIds) const;
 
147
    QOrganizerJsonDbEngine::StorageLocations resolveNeededStorageLocationsForCollections(const QList<QOrganizerCollectionId> &collectionIds) const;
 
148
 
 
149
    // Member variables
 
150
    QOrganizerJsonDbEngine* m_engine;
 
151
    QOrganizerJsonDbDataStorage* m_storage;
 
152
    QOrganizerJsonDbRequestManager* m_requestMgr;
 
153
    //Mutex to make the request state changes atomic
 
154
    QMutex* m_reqStateMutex;
 
155
 
 
156
    // Handle item / collection changes
 
157
    // They are only used by the notification system, so no mutex is needed.
 
158
    static const int TIMEOUT_INTERVAL;
 
159
    QTimer *m_timer;
 
160
    QOrganizerItemChangeSet m_ics;
 
161
    QOrganizerCollectionChangeSet m_ccs;
 
162
 
 
163
    void startTimer();  // Only used by onItemChanged() and onCollectionChanged()
 
164
 
 
165
    // constants for generating occurrences
 
166
 
 
167
    // number of days to use as time period for generating occurrences if no period is defined
 
168
    static const int DefaultTimePeriod;
 
169
    static const int MaxOccurrenceCount;
 
170
 
 
171
};
 
172
 
 
173
QT_END_NAMESPACE_ORGANIZER
 
174
 
 
175
#endif // QORGANIZERJSONDBREQUESTTHREAD_H