|
1 /* |
|
2 * Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributor: |
|
10 * Maximilian Odendahl |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: main Caldav class, all magic happens here |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef _CALSTORE_H |
|
19 #define _CALSTORE_H |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <BADESCA.H> |
|
23 |
|
24 #include <calchangecallback.h> |
|
25 #include <calprogresscallback.h> |
|
26 #include <calfilechangenotification.h> |
|
27 |
|
28 #include <xmlengdomimplementation.h> |
|
29 #include <xmlengdomparser.h> |
|
30 |
|
31 #include "caldavutils.h" |
|
32 |
|
33 class CCalSession; |
|
34 class CCalEntry; |
|
35 class CCalIter; |
|
36 class CCalEntryView; |
|
37 class CCalenExporter; |
|
38 class CCalenImporter; |
|
39 class CCalenInterimUtils2; |
|
40 |
|
41 class RXmlEngDOMImplementation; |
|
42 class RXmlEngDOMParser; |
|
43 class RXmlEngDocument; |
|
44 |
|
45 class CHttpClient; |
|
46 class CalDavTest; |
|
47 |
|
48 // sync interval of 0 correspons to one minute |
|
49 // 0 actually means to enable push connectivity once supported |
|
50 #define DEFAULT_SYNC_MINUTES 0 |
|
51 #define DEFAULT_PAST_DAYS 14 |
|
52 #define DEFAULT_IMMEDIATE_SYNC ETrue |
|
53 #define DEFAULT_KEEP_SERVER_ENTRY EFalse |
|
54 |
|
55 |
|
56 enum TLocalLoopAction |
|
57 { |
|
58 ELoopActionUpload, ELoopActionFillArray, ELoopActionDeleteLocal |
|
59 }; |
|
60 |
|
61 /** |
|
62 * CCalDavEngine |
|
63 * |
|
64 */ |
|
65 class CCalDavEngine : public CBase, MCalProgressCallBack, MCalChangeCallBack2, MCalFileChangeObserver |
|
66 { |
|
67 public: |
|
68 |
|
69 friend class CalDavTest; |
|
70 |
|
71 ~CCalDavEngine(); |
|
72 |
|
73 static CCalDavEngine* NewL(const TDesC& aCalendar); |
|
74 static CCalDavEngine* NewLC(const TDesC& aCalendar); |
|
75 |
|
76 TInt EnableL(); |
|
77 void DisableL(); |
|
78 TBool EnabledSync(); |
|
79 |
|
80 TInt SyncL(); |
|
81 |
|
82 TInt MkcalendarL(const TDesC8 &aName); |
|
83 TInt DeleteCalendarL(const TDesC8 &aName); |
|
84 |
|
85 TPtrC CalendarName() const; |
|
86 TPtrC8 Home() const; |
|
87 |
|
88 TPtrC8 Url() const; |
|
89 void SetUrlL(const TDesC8 &aUrl); |
|
90 |
|
91 TPtrC8 User() const; |
|
92 void SetUserL(const TDesC8 &aUser); |
|
93 |
|
94 TPtrC8 Password() const; |
|
95 void SetPasswordL(const TDesC8 &aPassword); |
|
96 |
|
97 TTimeIntervalMinutes SyncInterval() const; |
|
98 void SetSyncIntervalL(TTimeIntervalMinutes aSyncInterval); |
|
99 |
|
100 TTimeIntervalDays PastDays() const; |
|
101 void SetPastDaysL(TTimeIntervalDays aDays); |
|
102 |
|
103 TBool ImmediateSync() const; |
|
104 void SetImmediateSyncL(TBool aImmediateSyc); |
|
105 |
|
106 TBool KeepServerEntry() const; |
|
107 void SetKeepServerEntryL(TBool aKeepServerEntry); |
|
108 |
|
109 CPeriodic* Timer(); |
|
110 |
|
111 TPtrC8 SyncToken(); |
|
112 TPtrC8 CTag(); |
|
113 |
|
114 private: |
|
115 |
|
116 CCalDavEngine(); |
|
117 void ConstructL(const TDesC& aCalendar); |
|
118 |
|
119 void RegisterL(); |
|
120 HBufC8* GetCTagL(); |
|
121 HBufC8* GetSyncTokenL(); |
|
122 |
|
123 TInt InitL(); |
|
124 |
|
125 // Called during calendar entry view creation |
|
126 void Progress(TInt aPercentageCompleted); |
|
127 void Completed(TInt aError); |
|
128 TBool NotifyProgress(); |
|
129 void CalChangeNotification(RArray<TCalChangeEntry> &aChangeItems); |
|
130 void CalendarInfoChangeNotificationL(RPointerArray<CCalFileChangeInfo>& aCalendarInfoChangeEntries); |
|
131 |
|
132 void CalendarInfoL(); |
|
133 void SetCalendarInfoL(const TDesC8 &aKey, const TDesC8 &aValue); |
|
134 |
|
135 void HandleCalendarInfoChangeL(); |
|
136 void HandleChangeL(MCalChangeCallBack2::TChangeType &aChangeType, |
|
137 MCalChangeCallBack2::TChangeEntryType &aEntryType, |
|
138 TCalLocalUid &aUid); |
|
139 |
|
140 TBool ManualSyncL(); |
|
141 TBool WebDavSyncL(); |
|
142 TInt WebDavSyncReportL(TBool aSynctoken); |
|
143 TBool UploadModifiedSinceDateL(); |
|
144 TBool ClientChangesL(); |
|
145 TBool ServerChangesL(); |
|
146 TInt DeleteRemovedEntriesOnServerL(); |
|
147 TInt LocalLoopL(TLocalLoopAction aAction); |
|
148 |
|
149 TInt ListL(); |
|
150 TInt TimeReportL(TBool VEVENT, const TDesC8 &aStart, TBool aDelete = EFalse); |
|
151 |
|
152 // server actions |
|
153 TInt UploadEntryL(const TCalLocalUid &aUid, |
|
154 MCalChangeCallBack2::TChangeType aChangeType, |
|
155 MCalChangeCallBack2::TChangeEntryType aEntryType); |
|
156 TInt UploadEntryL(CCalEntry* aEntry, |
|
157 MCalChangeCallBack2::TChangeType aChangeType, |
|
158 MCalChangeCallBack2::TChangeEntryType aEntryType); |
|
159 TInt DownloadEntryL(const TDesC8 &aUrl); |
|
160 TInt DownloadEntryL(CDesC8Array* aArray); |
|
161 TInt DeleteEntryL(const TCalLocalUid &aUid); |
|
162 TInt DeleteEntryL(const TDesC8 &aUid); |
|
163 TInt HeadL(const TDesC8 &aUID); |
|
164 |
|
165 // local actions |
|
166 TInt AddModifyLocalEntryL(const TDesC8 &aUrl, const TDesC8 &aETag, |
|
167 CDesC8ArrayFlat* aArray); |
|
168 TInt DeleteLocalEntryL(const TDesC8 &aUID); |
|
169 |
|
170 TInt ParseResponsesDeleteL(const TDesC8 &aDocument); |
|
171 TInt ParseResponsesL(RXmlEngDocument &aDocument, TBool aMultiget = EFalse); |
|
172 TInt ParseResponsesL(const TDesC8 &aDocument, TBool aMultiget = EFalse); |
|
173 |
|
174 unsigned long DoesEntryExistL(const TDesC8 &aUrl); |
|
175 TPtrC8 GetUIDByUrl(const TDesC8 &aUrl); |
|
176 TBool ETagMatchL(const TDesC8& aUrl, const TDesC8& aETag); |
|
177 TInt StoreEntryL(const TDesC8 &aBuf, const TDesC8 &aEtag); |
|
178 |
|
179 void SyncFailedL(); |
|
180 void SetLastSyncTimeL(); |
|
181 void SetSyncTokenL(HBufC8* aToken); |
|
182 void SetCTagL(HBufC8* aToken); |
|
183 |
|
184 void CheckCalendarInfoL(RXmlEngDocument &aDocument); |
|
185 |
|
186 TBool GetOptionsL(); |
|
187 TInt GetCalendarUrlsL(CDesC8ArrayFlat *aArray); |
|
188 void FindUrlsL(const TDesC8 &aDes, HBufC8 *&home, HBufC8 *&inbox, |
|
189 HBufC8 *&outbox); |
|
190 void GetBaseUrl(const TDesC8 &aUrl); |
|
191 HBufC8 * FindCalendarCollectionL(const TDesC8 &aUrl, |
|
192 CDesC8ArrayFlat *aArray); |
|
193 |
|
194 void DeleteCalObjects(); |
|
195 TInt CreateCalObjectsL(); |
|
196 |
|
197 CCalSession* iCalSession; |
|
198 CCalIter* iCalIter; |
|
199 CCalEntryView* iCalEntryView; |
|
200 CCalenExporter* iCalExporter; |
|
201 CCalenImporter* iCalImporter; |
|
202 CCalenInterimUtils2* iCalIntermimUtils2; |
|
203 HBufC *iCalendar; |
|
204 HBufC8 *iUrl; |
|
205 HBufC8 *iBaseUrl; |
|
206 HBufC8 *iHome; |
|
207 |
|
208 TCalDAVOptions iOptions; |
|
209 CHttpClient* iHttp; |
|
210 |
|
211 RXmlEngDOMImplementation iDomImpl; |
|
212 RXmlEngDOMParser iDomParser; |
|
213 |
|
214 // when we get a callback with a localuid, the corresponding entry is already deleted |
|
215 // we therefore need a different way to map from localuid to global uid/filename |
|
216 // this can be completly removed when introducing a new callback, |
|
217 // which includes the to be deleted localuid |
|
218 RArray<TCalLocalUid> iLocalUidArray; |
|
219 RArray<TBuf8<100> > iGlobalUidArray; |
|
220 // |
|
221 RArray<TCalLocalUid> iDeletedEntries; |
|
222 |
|
223 HBufC8 *iSynctoken; |
|
224 HBufC8 *iCTag; |
|
225 TBool iManualSync; |
|
226 TCalTime iLastSyncTime; |
|
227 TBool iFirstInit; |
|
228 |
|
229 // Options |
|
230 TTimeIntervalMinutes iSyncInterval; |
|
231 TTimeIntervalDays iPastDays; |
|
232 TBool iImmediateSync; |
|
233 TBool iKeepServerEntry; |
|
234 TBool iEnabled; |
|
235 |
|
236 CPeriodic* iTimer; |
|
237 }; |
|
238 |
|
239 #endif // CALSTORE_H |