|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation 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 Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Declaration of Notepad Model class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef NPDMODEL_PLATSEC_H |
|
20 #define NPDMODEL_PLATSEC_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <d32dbms.h> |
|
24 #include "NpdCoreModel.h" |
|
25 #include "NpdModelObserver.h" |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KNotepadModelInvalidIndex(-1); |
|
29 const TInt KNotepadInvalidKeyId(-1); |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class RFs; |
|
33 class MNotepadModelObserver; |
|
34 |
|
35 // CLASS DECLARATION |
|
36 /** |
|
37 * Engine of NpdLib. |
|
38 * CNotepadModel is the engine of Notepad Library. |
|
39 * This class has an array of texts for listing data in a text list box. |
|
40 * |
|
41 * @lib NpdLib.lib |
|
42 * @see CNotepadCoreModel, CNotepadTableModel |
|
43 */ |
|
44 class CNotepadModel : public CNotepadCoreModel, |
|
45 public MDesCArray |
|
46 { |
|
47 public: // Constuctor and destructor |
|
48 enum TNotepadModelFlag |
|
49 { |
|
50 ENotepadRequireDbViewUpdate = 0x01, |
|
51 ENotepadRequireItemArrayUpdate = 0x02, |
|
52 ENotepadIsDeleting = 0x04, |
|
53 ENotepadIsRemovingLinks = 0x08, |
|
54 ENotepadItemArrayUpdateOnly = 0x10 |
|
55 }; |
|
56 |
|
57 /** |
|
58 * Constructor. |
|
59 * |
|
60 * @param aFs file server session. |
|
61 * @param aResId resource id of type STRUCT NOTEPAD_MODEL. |
|
62 * @return new CNotepadModel object. |
|
63 */ |
|
64 IMPORT_C static CNotepadModel* NewL(RFs& aFs, TInt aResId); |
|
65 |
|
66 /** |
|
67 * Destructor. |
|
68 */ |
|
69 IMPORT_C virtual ~CNotepadModel(); |
|
70 |
|
71 public: // New functions |
|
72 |
|
73 /** |
|
74 * Save text as a memo. |
|
75 * API for SaveAsMemo. |
|
76 * |
|
77 * @param aText text to save |
|
78 */ |
|
79 IMPORT_C void AddContentL(const TDesC& aText); |
|
80 |
|
81 /** |
|
82 * Open (or create) a datafile. |
|
83 * |
|
84 * If already opened, do nothing. |
|
85 * If there is no datafile, create a new datafile. |
|
86 * |
|
87 * @deprecated |
|
88 * @internal |
|
89 */ |
|
90 IMPORT_C void OpenL(); |
|
91 |
|
92 /** |
|
93 * Close a datafile. |
|
94 * |
|
95 * @deprecated |
|
96 * @internal |
|
97 */ |
|
98 IMPORT_C void Close(); |
|
99 |
|
100 /** |
|
101 * Return ETrue if it is opened now. |
|
102 * |
|
103 * @return ETrue if opened. |
|
104 * @internal |
|
105 * @deprecated |
|
106 */ |
|
107 IMPORT_C TBool IsOpen(); |
|
108 |
|
109 // Query |
|
110 |
|
111 /** |
|
112 * Return key UID of specified item. |
|
113 * |
|
114 * @return key of specified item. |
|
115 */ |
|
116 inline TInt Key(TInt aItemIndex) const; |
|
117 |
|
118 /** |
|
119 * Return iKeyArray (for Editor to create a sequence). |
|
120 * |
|
121 * @return internal iKeyArray. |
|
122 */ |
|
123 inline const RArray<TInt>& KeyArray() const; |
|
124 |
|
125 /** |
|
126 * Seek a specified key UID in item array. |
|
127 * |
|
128 * @param aKey key to seek. |
|
129 * @return 0 if found. |
|
130 */ |
|
131 IMPORT_C TInt SeekKey(const TInt aKey); |
|
132 |
|
133 /** |
|
134 * Return content of the item. |
|
135 * |
|
136 * Caller own a returned object. |
|
137 * |
|
138 * @param aItemIndex target index. |
|
139 * @return text content of specified item. |
|
140 */ |
|
141 HBufC* ContentL( TInt aItemIndex ); |
|
142 |
|
143 /** |
|
144 * Return an index of the key. |
|
145 * |
|
146 * @param aKey unique key id. |
|
147 * @return index if found, KNotepadModelInvalidIndex if not found |
|
148 */ |
|
149 TInt IndexOf(const TInt aKey) const; |
|
150 |
|
151 /** |
|
152 * Return ETrue if deleting process is running. |
|
153 * |
|
154 * @return ETrue if iExecuter is running for deletion. |
|
155 */ |
|
156 inline TBool IsDeleting() const; |
|
157 |
|
158 // Update |
|
159 |
|
160 /** |
|
161 * Refresh the text array. |
|
162 * |
|
163 * This function should be called if date has changed. |
|
164 */ |
|
165 void HandleDateChangedL(TBool aSyncNow); |
|
166 |
|
167 /** |
|
168 * Start deleting process. |
|
169 * This method gives an incremental version of deletion. |
|
170 * |
|
171 * @param aKeys keys of items to be deleted. |
|
172 */ |
|
173 void DeleteByKeysL(const RArray<TInt>& aKeys); |
|
174 |
|
175 /** |
|
176 * Cancel deleting process if running. |
|
177 */ |
|
178 void CancelDeletion(); |
|
179 |
|
180 /** |
|
181 * Sync iDbView, iItemArray and iKeyArray. |
|
182 * |
|
183 * @param aForceSync force sync. |
|
184 * @return ETrue if any change on iDbView, iItemArray or iKeyArray. |
|
185 */ |
|
186 /*TBool*/ void SyncL( const TBool aForceSync ); |
|
187 |
|
188 /** |
|
189 * Refresh the cached data accroding to changes of the database. |
|
190 * |
|
191 * This function is called from iDatabaseChangeNotifer. |
|
192 */ |
|
193 void HandleDatabaseChangedL(TInt aStatus); |
|
194 |
|
195 /** |
|
196 * Set a Notepad model observer. |
|
197 * |
|
198 * @param aObserver an object which implements MNotepadModelObserver. |
|
199 */ |
|
200 void SetNotepadModelObserver(MNotepadModelObserver* aObserver); |
|
201 |
|
202 public: // Functions from base classes |
|
203 |
|
204 /** |
|
205 * From MDesCArray. |
|
206 * Return the number of items. |
|
207 */ |
|
208 IMPORT_C TInt MdcaCount() const; |
|
209 |
|
210 /** |
|
211 * From MDesCArray. |
|
212 * Return the text of specified item. |
|
213 */ |
|
214 IMPORT_C TPtrC MdcaPoint(TInt aIndex) const; |
|
215 |
|
216 private: // Constructors |
|
217 |
|
218 /** |
|
219 * Default C++ constructor. |
|
220 */ |
|
221 CNotepadModel(); |
|
222 |
|
223 /** |
|
224 * Second phase constructor. |
|
225 * |
|
226 * @param aResId resource id of type STRUCT NOTEPAD_MODEL |
|
227 */ |
|
228 void ConstructL(TInt aResId); |
|
229 |
|
230 private: // New functions |
|
231 |
|
232 /** |
|
233 * Prepare to start deletion. |
|
234 * Create a SQL statement and set it on iDbUpdate. |
|
235 * |
|
236 * @param aKeys keys of items to be deleted. |
|
237 */ |
|
238 void PrepareToDeleteByKeysL(const RArray<TInt>& aKeys); |
|
239 |
|
240 void ExecuteDeleteStepL(); |
|
241 |
|
242 /** |
|
243 * Should be called if deleting process was aborted. |
|
244 */ |
|
245 void AbortDeletionL(); |
|
246 |
|
247 /** |
|
248 * Should be called if deleting process has completed. |
|
249 */ |
|
250 void CompleteDeletionL(); |
|
251 |
|
252 /** |
|
253 * Callback function while iExecuter is running for deletion. |
|
254 * |
|
255 * @param aSelf an object of this class. |
|
256 */ |
|
257 static TInt DeleteCallBack(TAny *aSelf); |
|
258 |
|
259 /** |
|
260 * Callback function while iExecuter is running for deletion. |
|
261 */ |
|
262 TInt DoDeleteCallBackL(); |
|
263 |
|
264 /** |
|
265 * Callback function while iExecuter is running for removal of links. |
|
266 */ |
|
267 TInt DoRemoveLinkCallBackL(); |
|
268 |
|
269 /** |
|
270 * Create iItemArray and iKeyArray. |
|
271 */ |
|
272 void BuildItemArrayL( const TBool aForceSync ); |
|
273 |
|
274 /** |
|
275 * Implementation of BuildItemArrayL. |
|
276 * |
|
277 */ |
|
278 void DoBuildItemArrayL(); |
|
279 |
|
280 /** |
|
281 * Implementation of BuildItemArrayL when Notepad. |
|
282 * |
|
283 */ |
|
284 void DoBuildNotepadItemArrayL(TPtr& aBuf); |
|
285 |
|
286 /** |
|
287 * Implementation of BuildItemArrayL when Tempaltes. |
|
288 * |
|
289 */ |
|
290 void DoBuildTemplateItemArrayL(TPtr& aBuf); |
|
291 |
|
292 /** |
|
293 * Reserved. |
|
294 * @internal |
|
295 */ |
|
296 IMPORT_C void CNotepadModel_Reserved(); |
|
297 |
|
298 public: |
|
299 |
|
300 /** |
|
301 * Sets the item array flags. |
|
302 * |
|
303 */ |
|
304 void SetItemArrayFlags(); |
|
305 |
|
306 /** |
|
307 * Retruns the item array flags. |
|
308 * |
|
309 */ |
|
310 TUint ItemArrayFlags(); |
|
311 |
|
312 private: // Inner class |
|
313 |
|
314 /** |
|
315 * Inner calss to observe changes of the database. |
|
316 * |
|
317 */ |
|
318 class CDatabaseChangeNotifier : public CActive |
|
319 { |
|
320 public: // constructor, destructor |
|
321 static CDatabaseChangeNotifier* NewL( |
|
322 RDbDatabase& aDatabase, |
|
323 CNotepadModel& aModel ); |
|
324 ~CDatabaseChangeNotifier(); |
|
325 private: // constructor |
|
326 CDatabaseChangeNotifier(CNotepadModel& aModel); |
|
327 void ConstructL(RDbDatabase& aDatabase); |
|
328 private: // from CActive |
|
329 void DoCancel(); |
|
330 void RunL(); |
|
331 private: // data |
|
332 RDbNotifier iDbNotifier; |
|
333 CNotepadModel& iModel; |
|
334 }; |
|
335 |
|
336 private: // Data |
|
337 |
|
338 TUint iFlag; |
|
339 RDbUpdate iDbUpdate; |
|
340 RArray<TInt> iSavedDeleteKeys; |
|
341 CNotepadModel::CDatabaseChangeNotifier* iDatabaseChangeNotifier; //own |
|
342 RDbView iDbView; |
|
343 CIdle* iExecuter; // own |
|
344 CDesCArray* iItemArray; // own |
|
345 RArray<TInt> iKeyArray; // map ItemIndex -> Key. |
|
346 MNotepadModelObserver* iModelObserver; // not own |
|
347 TInt iProgressCount; // for progress infomation callback |
|
348 TInt iListingStyle; |
|
349 HBufC* iDateFormat; |
|
350 HBufC* iTimeFormat; |
|
351 TInt iStepCount; |
|
352 RFs iFileSession; |
|
353 TInt iRetval; |
|
354 }; |
|
355 |
|
356 #include "NpdModel.inl" |
|
357 #endif // NPDMODEL_PLATSEC_H |
|
358 |
|
359 // End of File |