1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtOrganizer module of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
42
#ifndef QORGANIZERJSONDBREQUESTTHREAD_H
43
#define QORGANIZERJSONDBREQUESTTHREAD_H
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.
56
#include "qorganizerjsondbengine.h"
58
#include <QtOrganizer/qorganizercollectionchangeset.h>
59
#include <QtOrganizer/qorganizeritemchangeset.h>
60
#include <QtOrganizer/qorganizeritemrequests.h>
62
#include <QtCore/qthread.h>
69
QT_BEGIN_NAMESPACE_ORGANIZER
71
class QOrganizerJsonDbRequestManager;
72
class QOrganizerJsonDbEngine;
73
class QOrganizerJsonDbDataStorage;
75
class QOrganizerJsonDbRequestThread : public QThread
79
QOrganizerJsonDbRequestThread();
80
virtual ~QOrganizerJsonDbRequestThread();
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;
89
void handleRequest(QOrganizerAbstractRequest* req);
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);
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();
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>());
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);
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;
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);
142
bool validRequest(QOrganizerAbstractRequest *req);
143
bool validPlatform(QOrganizerAbstractRequest *req);
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;
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;
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;
160
QOrganizerItemChangeSet m_ics;
161
QOrganizerCollectionChangeSet m_ccs;
163
void startTimer(); // Only used by onItemChanged() and onCollectionChanged()
165
// constants for generating occurrences
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;
173
QT_END_NAMESPACE_ORGANIZER
175
#endif // QORGANIZERJSONDBREQUESTTHREAD_H