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 QORGANIZERMANAGERENGINE_H |
35 | #define QORGANIZERMANAGERENGINE_H |
36 | |
37 | #include <QtOrganizer/qorganizermanager.h> |
38 | #include <QtOrganizer/qorganizerabstractrequest.h> |
39 | #include <QtOrganizer/qorganizerrecurrencerule.h> |
40 | |
41 | QT_BEGIN_NAMESPACE_ORGANIZER |
42 | |
43 | class QOrganizerCollectionFetchRequest; |
44 | class QOrganizerCollectionRemoveRequest; |
45 | class QOrganizerCollectionSaveRequest; |
46 | class QOrganizerItemIdFetchRequest; |
47 | class QOrganizerItemFetchByIdRequest; |
48 | class QOrganizerItemFetchRequest; |
49 | class QOrganizerItemOccurrenceFetchRequest; |
50 | class QOrganizerItemRemoveRequest; |
51 | class QOrganizerItemRemoveByIdRequest; |
52 | class QOrganizerItemSaveRequest; |
53 | class QOrganizerItemFetchForExportRequest; |
54 | |
55 | class Q_ORGANIZER_EXPORT QOrganizerManagerEngine : public QObject |
56 | { |
57 | Q_OBJECT |
58 | |
59 | public: |
60 | QOrganizerManagerEngine(QObject *parent = Q_NULLPTR); |
61 | |
62 | virtual QString managerName() const; |
63 | virtual QMap<QString, QString> managerParameters() const; |
64 | virtual QMap<QString, QString> idInterpretationParameters() const; |
65 | |
66 | inline QString managerUri() const |
67 | { if (m_uri.isNull()) m_uri = QOrganizerManager::buildUri(managerName: managerName(), params: idInterpretationParameters()); return m_uri; } |
68 | |
69 | inline QOrganizerItemId itemId(const QByteArray &localId) const |
70 | { return QOrganizerItemId(managerUri(), localId); } |
71 | inline QOrganizerCollectionId collectionId(const QByteArray &localId) const |
72 | { return QOrganizerCollectionId(managerUri(), localId); } |
73 | |
74 | // items |
75 | virtual QList<QOrganizerItem> items(const QList<QOrganizerItemId> &itemIds, const QOrganizerItemFetchHint &fetchHint, |
76 | QMap<int, QOrganizerManager::Error> *errorMap, QOrganizerManager::Error *error); |
77 | |
78 | virtual QList<QOrganizerItem> items(const QOrganizerItemFilter &filter, const QDateTime &startDateTime, |
79 | const QDateTime &endDateTime, int maxCount, |
80 | const QList<QOrganizerItemSortOrder> &sortOrders, |
81 | const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error); |
82 | |
83 | virtual QList<QOrganizerItemId> itemIds(const QOrganizerItemFilter &filter, const QDateTime &startDateTime, |
84 | const QDateTime &endDateTime, const QList<QOrganizerItemSortOrder> &sortOrders, |
85 | QOrganizerManager::Error *error); |
86 | |
87 | virtual QList<QOrganizerItem> itemOccurrences(const QOrganizerItem &parentItem, const QDateTime &startDateTime, |
88 | const QDateTime &endDateTime, int maxCount, |
89 | const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error); |
90 | |
91 | virtual QList<QOrganizerItem> itemsForExport(const QDateTime &startDateTime, const QDateTime &endDateTime, |
92 | const QOrganizerItemFilter &filter, |
93 | const QList<QOrganizerItemSortOrder> &sortOrders, |
94 | const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error); |
95 | |
96 | virtual bool saveItems(QList<QOrganizerItem> *items, const QList<QOrganizerItemDetail::DetailType> &detailMask, |
97 | QMap<int, QOrganizerManager::Error> *errorMap, QOrganizerManager::Error *error); |
98 | |
99 | virtual bool removeItems(const QList<QOrganizerItemId> &itemIds, QMap<int, QOrganizerManager::Error> *errorMap, |
100 | QOrganizerManager::Error *error); |
101 | |
102 | virtual bool removeItems(const QList<QOrganizerItem> *items, QMap<int, QOrganizerManager::Error> *errorMap, QOrganizerManager::Error *error); |
103 | |
104 | // collections |
105 | virtual QOrganizerCollectionId defaultCollectionId() const; |
106 | virtual QOrganizerCollection collection(const QOrganizerCollectionId &collectionId, QOrganizerManager::Error *error); |
107 | virtual QList<QOrganizerCollection> collections(QOrganizerManager::Error *error); |
108 | virtual bool saveCollection(QOrganizerCollection *collection, QOrganizerManager::Error *error); |
109 | virtual bool removeCollection(const QOrganizerCollectionId &collectionId, QOrganizerManager::Error *error); |
110 | |
111 | // asynchronous request support |
112 | virtual void requestDestroyed(QOrganizerAbstractRequest *request); |
113 | virtual bool startRequest(QOrganizerAbstractRequest *request); |
114 | virtual bool cancelRequest(QOrganizerAbstractRequest *request); |
115 | virtual bool waitForRequestFinished(QOrganizerAbstractRequest *request, int msecs); |
116 | |
117 | static void updateRequestState(QOrganizerAbstractRequest *request, QOrganizerAbstractRequest::State state); |
118 | |
119 | static void updateItemOccurrenceFetchRequest(QOrganizerItemOccurrenceFetchRequest *request, const QList<QOrganizerItem> &result, |
120 | QOrganizerManager::Error error, QOrganizerAbstractRequest::State newState); |
121 | |
122 | static void updateItemIdFetchRequest(QOrganizerItemIdFetchRequest *request, const QList<QOrganizerItemId> &result, |
123 | QOrganizerManager::Error error, QOrganizerAbstractRequest::State newState); |
124 | |
125 | static void updateItemFetchByIdRequest(QOrganizerItemFetchByIdRequest *request, const QList<QOrganizerItem> &result, |
126 | QOrganizerManager::Error error, const QMap<int, QOrganizerManager::Error> &errorMap, |
127 | QOrganizerAbstractRequest::State); |
128 | |
129 | static void updateItemFetchRequest(QOrganizerItemFetchRequest *request, const QList<QOrganizerItem> &result, |
130 | QOrganizerManager::Error error, QOrganizerAbstractRequest::State newState); |
131 | |
132 | static void updateItemFetchForExportRequest(QOrganizerItemFetchForExportRequest *request, const QList<QOrganizerItem> &result, |
133 | QOrganizerManager::Error error, QOrganizerAbstractRequest::State newState); |
134 | |
135 | static void updateItemRemoveRequest(QOrganizerItemRemoveRequest *request, QOrganizerManager::Error error, |
136 | const QMap<int, QOrganizerManager::Error> &errorMap, QOrganizerAbstractRequest::State newState); |
137 | |
138 | static void updateItemRemoveByIdRequest(QOrganizerItemRemoveByIdRequest *request, QOrganizerManager::Error error, |
139 | const QMap<int, QOrganizerManager::Error> &errorMap, QOrganizerAbstractRequest::State newState); |
140 | |
141 | static void updateItemSaveRequest(QOrganizerItemSaveRequest *request, const QList<QOrganizerItem> &result, QOrganizerManager::Error error, |
142 | const QMap<int, QOrganizerManager::Error> &errorMap, QOrganizerAbstractRequest::State newState); |
143 | |
144 | static void updateCollectionFetchRequest(QOrganizerCollectionFetchRequest *request, const QList<QOrganizerCollection> &result, |
145 | QOrganizerManager::Error error, QOrganizerAbstractRequest::State newState); |
146 | |
147 | static void updateCollectionRemoveRequest(QOrganizerCollectionRemoveRequest *request, QOrganizerManager::Error error, |
148 | const QMap<int, QOrganizerManager::Error> &errorMap, QOrganizerAbstractRequest::State newState); |
149 | |
150 | static void updateCollectionSaveRequest(QOrganizerCollectionSaveRequest *request, const QList<QOrganizerCollection> &result, |
151 | QOrganizerManager::Error error, const QMap<int, QOrganizerManager::Error> &errorMap, |
152 | QOrganizerAbstractRequest::State newState); |
153 | |
154 | // functionality reporting |
155 | virtual QList<QOrganizerItemFilter::FilterType> supportedFilters() const; |
156 | virtual QList<QOrganizerItemDetail::DetailType> supportedItemDetails(QOrganizerItemType::ItemType itemType) const; |
157 | virtual QList<QOrganizerItemType::ItemType> supportedItemTypes() const; |
158 | |
159 | // helper |
160 | static int addSorted(QList<QOrganizerItem> *sorted, const QOrganizerItem &toAdd, const QList<QOrganizerItemSortOrder> &sortOrders); |
161 | static bool addDefaultSorted(QMultiMap<QDateTime, QOrganizerItem> *defaultSorted, const QOrganizerItem &toAdd); |
162 | static int compareItem(const QOrganizerItem &a, const QOrganizerItem &b, const QList<QOrganizerItemSortOrder> &sortOrders); |
163 | static int compareVariant(const QVariant &a, const QVariant &b, Qt::CaseSensitivity sensitivity); |
164 | static bool isItemBetweenDates(const QOrganizerItem &item, const QDateTime &startPeriod, const QDateTime &endPeriod); |
165 | static bool itemLessThan(const QOrganizerItem &a, const QOrganizerItem &b); |
166 | static bool testFilter(const QOrganizerItemFilter &filter, const QOrganizerItem &item); |
167 | static QOrganizerItemFilter canonicalizedFilter(const QOrganizerItemFilter &filter); |
168 | |
169 | // recurrence help |
170 | static QOrganizerItem generateOccurrence(const QOrganizerItem &parentItem, const QDateTime &rdate); |
171 | static QList<QDateTime> generateDateTimes(const QDateTime &initialDateTime, QOrganizerRecurrenceRule rrule, const QDateTime &periodStart, const QDateTime &periodEnd, int maxCount); |
172 | static void inferMissingCriteria(QOrganizerRecurrenceRule *rrule, const QDate &initialDate); |
173 | static bool inMultipleOfInterval(const QDate &date, const QDate &initialDate, QOrganizerRecurrenceRule::Frequency frequency, int interval, Qt::DayOfWeek firstDayOfWeek); |
174 | static QDate firstDateInPeriod(const QDate &date, QOrganizerRecurrenceRule::Frequency frequency, Qt::DayOfWeek firstDayOfWeek); |
175 | static QDate firstDateInNextPeriod(const QDate &date, QOrganizerRecurrenceRule::Frequency frequency, Qt::DayOfWeek firstDayOfWeek); |
176 | static QList<QDate> matchingDates(const QDate &periodStart, const QDate &periodEnd, const QOrganizerRecurrenceRule &rrule); |
177 | static QList<QDate> filterByPosition(const QList<QDate> &dates, const QSet<int> positions); |
178 | static bool itemHasReccurence(const QOrganizerItem &oi); |
179 | |
180 | Q_SIGNALS: |
181 | void dataChanged(); |
182 | void itemsAdded(const QList<QOrganizerItemId> &itemIds); |
183 | void itemsChanged(const QList<QOrganizerItemId> &itemIds, const QList<QOrganizerItemDetail::DetailType> &typesChanged); |
184 | void itemsRemoved(const QList<QOrganizerItemId> &itemIds); |
185 | void itemsModified(const QList<QPair<QOrganizerItemId, QOrganizerManager::Operation> > &itemIds); |
186 | void collectionsAdded(const QList<QOrganizerCollectionId> &collectionIds); |
187 | void collectionsChanged(const QList<QOrganizerCollectionId> &collectionIds); |
188 | void collectionsRemoved(const QList<QOrganizerCollectionId> &collectionIds); |
189 | void collectionsModified(const QList<QPair<QOrganizerCollectionId, QOrganizerManager::Operation> > &collectionIds); |
190 | |
191 | private: |
192 | Q_DISABLE_COPY(QOrganizerManagerEngine) |
193 | friend class QOrganizerItemChangeSet; |
194 | friend class QOrganizerCollectionChangeSet; |
195 | |
196 | mutable QString m_uri; |
197 | }; |
198 | |
199 | QT_END_NAMESPACE_ORGANIZER |
200 | |
201 | #endif // QORGANIZERMANAGERENGINE_H |
202 | |