1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtOrganizer module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
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 The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free |
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
22 | ** following information to ensure the GNU Lesser General Public License |
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
25 | ** |
26 | ** As a special exception, The Qt Company gives you certain additional |
27 | ** rights. These rights are described in The Qt Company LGPL Exception |
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
29 | ** |
30 | ** $QT_END_LICENSE$ |
31 | ** |
32 | ****************************************************************************/ |
33 | |
34 | #ifndef QCONTACTMEMORYBACKEND_P_H |
35 | #define QCONTACTMEMORYBACKEND_P_H |
36 | |
37 | // |
38 | // W A R N I N G |
39 | // ------------- |
40 | // |
41 | // This file is not part of the Qt API. It exists purely as an |
42 | // implementation detail. This header file may change from version to |
43 | // version without notice, or even be removed. |
44 | // |
45 | // We mean it. |
46 | // |
47 | |
48 | #include <QtOrganizer/qorganizermanagerengine.h> |
49 | #include <QtOrganizer/qorganizermanagerenginefactory.h> |
50 | #include <QtOrganizer/qorganizercollectionchangeset.h> |
51 | #include <QtOrganizer/qorganizeritemchangeset.h> |
52 | #include <QtOrganizer/qorganizerrecurrencerule.h> |
53 | |
54 | QT_BEGIN_NAMESPACE_ORGANIZER |
55 | |
56 | class QOrganizerItemMemoryFactory : public QOrganizerManagerEngineFactory |
57 | { |
58 | Q_OBJECT |
59 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QOrganizerManagerEngineFactoryInterface" FILE "memory.json" ) |
60 | |
61 | public: |
62 | QOrganizerManagerEngine* engine(const QMap<QString, QString>& parameters, QOrganizerManager::Error*); |
63 | QString managerName() const; |
64 | }; |
65 | |
66 | |
67 | class QOrganizerAbstractRequest; |
68 | class QOrganizerManagerEngine; |
69 | class QOrganizerItemMemoryEngineData : public QSharedData |
70 | { |
71 | public: |
72 | enum { DefaultCollectionLocalId = 1 }; // default collection has id of 1. |
73 | |
74 | QOrganizerItemMemoryEngineData(); |
75 | ~QOrganizerItemMemoryEngineData() |
76 | { |
77 | } |
78 | |
79 | QString m_id; // the id parameter value |
80 | |
81 | QHash<QOrganizerItemId, QOrganizerItem> m_idToItemHash; // hash of id to the item identified by that id |
82 | QMultiHash<QOrganizerItemId, QOrganizerItemId> m_parentIdToChildIdHash; // hash of id to that item's children's ids |
83 | QHash<QOrganizerCollectionId, QOrganizerCollection> m_idToCollectionHash; // hash of id to the collection identified by that id |
84 | QMultiHash<QOrganizerCollectionId, QOrganizerItemId> m_itemsInCollectionsHash; // hash of collection ids to the ids of items the collection contains. |
85 | quint32 m_nextOrganizerItemId; // the localId() portion of a QOrganizerItemId |
86 | quint32 m_nextOrganizerCollectionId; // the localId() portion of a QOrganizerCollectionId |
87 | QString m_managerUri; // for faster lookup. |
88 | |
89 | void emitSharedSignals(QOrganizerCollectionChangeSet *cs) |
90 | { |
91 | foreach (QOrganizerManagerEngine *engine, m_sharedEngines) |
92 | cs->emitSignals(engine); |
93 | } |
94 | void emitSharedSignals(QOrganizerItemChangeSet* cs) |
95 | { |
96 | foreach(QOrganizerManagerEngine* engine, m_sharedEngines) |
97 | cs->emitSignals(engine); |
98 | } |
99 | |
100 | QList<QOrganizerManagerEngine*> m_sharedEngines; // The list of engines that share this data |
101 | }; |
102 | |
103 | class QOrganizerItemMemoryEngine : public QOrganizerManagerEngine |
104 | { |
105 | Q_OBJECT |
106 | |
107 | public: |
108 | static QOrganizerItemMemoryEngine *createMemoryEngine(const QMap<QString, QString>& parameters); |
109 | |
110 | ~QOrganizerItemMemoryEngine(); |
111 | |
112 | /* URI reporting */ |
113 | QString managerName() const; |
114 | QMap<QString, QString> managerParameters() const; |
115 | QMap<QString, QString> idInterpretationParameters() const; |
116 | |
117 | // items |
118 | QList<QOrganizerItem> items(const QList<QOrganizerItemId> &itemIds, const QOrganizerItemFetchHint &fetchHint, |
119 | QMap<int, QOrganizerManager::Error> *errorMap, QOrganizerManager::Error *error); |
120 | |
121 | QList<QOrganizerItem> items(const QOrganizerItemFilter &filter, const QDateTime &startDateTime, |
122 | const QDateTime &endDateTime, int maxCount, |
123 | const QList<QOrganizerItemSortOrder> &sortOrders, |
124 | const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error); |
125 | |
126 | QList<QOrganizerItemId> itemIds(const QOrganizerItemFilter &filter, const QDateTime &startDateTime, |
127 | const QDateTime &endDateTime, const QList<QOrganizerItemSortOrder> &sortOrders, |
128 | QOrganizerManager::Error *error); |
129 | |
130 | QList<QOrganizerItem> itemOccurrences(const QOrganizerItem &parentItem, const QDateTime &startDateTime, |
131 | const QDateTime &endDateTime, int maxCount, |
132 | const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error); |
133 | |
134 | QList<QOrganizerItem> itemsForExport(const QDateTime &startDateTime, const QDateTime &endDateTime, |
135 | const QOrganizerItemFilter &filter, |
136 | const QList<QOrganizerItemSortOrder> &sortOrders, |
137 | const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error); |
138 | |
139 | bool saveItems(QList<QOrganizerItem> *items, const QList<QOrganizerItemDetail::DetailType> &detailMask, |
140 | QMap<int, QOrganizerManager::Error> *errorMap, QOrganizerManager::Error *error); |
141 | |
142 | bool removeItems(const QList<QOrganizerItemId> &itemIds, QMap<int, QOrganizerManager::Error> *errorMap, |
143 | QOrganizerManager::Error *error); |
144 | |
145 | bool removeItems(const QList<QOrganizerItem> *items, QMap<int, QOrganizerManager::Error>* errorMap, |
146 | QOrganizerManager::Error* error); |
147 | |
148 | // collections |
149 | QOrganizerCollectionId defaultCollectionId() const; |
150 | QOrganizerCollection collection(const QOrganizerCollectionId &collectionId, QOrganizerManager::Error *error); |
151 | QList<QOrganizerCollection> collections(QOrganizerManager::Error* error); |
152 | bool saveCollection(QOrganizerCollection* collection, QOrganizerManager::Error* error); |
153 | bool removeCollection(const QOrganizerCollectionId& collectionId, QOrganizerManager::Error* error); |
154 | |
155 | /* Asynchronous Request Support */ |
156 | virtual void requestDestroyed(QOrganizerAbstractRequest* req); |
157 | virtual bool startRequest(QOrganizerAbstractRequest* req); |
158 | virtual bool cancelRequest(QOrganizerAbstractRequest* req); |
159 | virtual bool waitForRequestFinished(QOrganizerAbstractRequest* req, int msecs); |
160 | |
161 | /* Capabilities reporting */ |
162 | /*! \reimp */ |
163 | virtual QList<QOrganizerItemFilter::FilterType> supportedFilters() const |
164 | { |
165 | QList<QOrganizerItemFilter::FilterType> supported; |
166 | |
167 | supported << QOrganizerItemFilter::InvalidFilter |
168 | << QOrganizerItemFilter::DetailFilter |
169 | << QOrganizerItemFilter::DetailFieldFilter |
170 | << QOrganizerItemFilter::DetailRangeFilter |
171 | << QOrganizerItemFilter::IntersectionFilter |
172 | << QOrganizerItemFilter::UnionFilter |
173 | << QOrganizerItemFilter::IdFilter |
174 | << QOrganizerItemFilter::CollectionFilter |
175 | << QOrganizerItemFilter::DefaultFilter; |
176 | |
177 | return supported; |
178 | } |
179 | /*! \reimp */ |
180 | virtual QList<QOrganizerItemDetail::DetailType> supportedItemDetails(QOrganizerItemType::ItemType itemType) const; |
181 | |
182 | /*! \reimp */ |
183 | virtual QList<QOrganizerItemType::ItemType> supportedItemTypes() const |
184 | { |
185 | return QList<QOrganizerItemType::ItemType>() << QOrganizerItemType::TypeEvent |
186 | << QOrganizerItemType::TypeEventOccurrence |
187 | << QOrganizerItemType::TypeJournal |
188 | << QOrganizerItemType::TypeNote |
189 | << QOrganizerItemType::TypeTodo |
190 | << QOrganizerItemType::TypeTodoOccurrence; |
191 | } |
192 | |
193 | protected: |
194 | QOrganizerItemMemoryEngine(QOrganizerItemMemoryEngineData* data); |
195 | |
196 | protected: |
197 | /* Implement "signal coalescing" for batch functions via change set */ |
198 | virtual bool storeItem(QOrganizerItem* theOrganizerItem, QOrganizerItemChangeSet& changeSet, const QList<QOrganizerItemDetail::DetailType> &detailMask, QOrganizerManager::Error* error); |
199 | virtual bool removeItem(const QOrganizerItemId& organizeritemId, QOrganizerItemChangeSet& changeSet, QOrganizerManager::Error* error); |
200 | virtual bool removeOccurrence(const QOrganizerItem& organizeritem, QOrganizerItemChangeSet& changeSet, QOrganizerManager::Error* error); |
201 | |
202 | private: |
203 | QOrganizerItem item(const QOrganizerItemId& organizeritemId) const; |
204 | bool storeItems(QList<QOrganizerItem>* organizeritems, const QList<QOrganizerItemDetail::DetailType> &detailMask, QMap<int, QOrganizerManager::Error>* errorMap, QOrganizerManager::Error* error); |
205 | QList<QOrganizerItem> itemsForExport(const QList<QOrganizerItemId> &ids, const QOrganizerItemFetchHint &fetchHint, QMap<int, QOrganizerManager::Error> *errorMap, QOrganizerManager::Error *error); |
206 | QList<QOrganizerItem> internalItems(const QDateTime& startDate, const QDateTime& endDate, const QOrganizerItemFilter& filter, const QList<QOrganizerItemSortOrder>& sortOrders, const QOrganizerItemFetchHint& fetchHint, QOrganizerManager::Error* error, bool forExport) const; |
207 | QList<QOrganizerItem> internalItemOccurrences(const QOrganizerItem& parentItem, const QDateTime& periodStart, const QDateTime& periodEnd, int maxCount, bool includeExceptions, bool sortItems, QList<QDate> *exceptionDates, QOrganizerManager::Error* error) const; |
208 | void addItemRecurrences(QList<QOrganizerItem>& sorted, const QOrganizerItem& c, const QDateTime& startDate, const QDateTime& endDate, const QOrganizerItemFilter& filter, const QList<QOrganizerItemSortOrder>& sortOrders, bool forExport, QSet<QOrganizerItemId>* parentsAdded) const; |
209 | |
210 | bool fixOccurrenceReferences(QOrganizerItem* item, QOrganizerManager::Error* error); |
211 | bool typesAreRelated(QOrganizerItemType::ItemType occurrenceType, QOrganizerItemType::ItemType parentType); |
212 | |
213 | void performAsynchronousOperation(QOrganizerAbstractRequest* request); |
214 | |
215 | QOrganizerItemMemoryEngineData* d; |
216 | }; |
217 | |
218 | QT_END_NAMESPACE_ORGANIZER |
219 | |
220 | #endif // QCONTACTMEMORYBACKEND_P_H |
221 | |