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