|
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 core part of Notepad Model class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef NPDCOREMODEL_H |
|
20 #define NPDCOREMODEL_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 #include <badesca.h> |
|
26 #include <d32dbms.h> |
|
27 |
|
28 // CONSTANTS |
|
29 _LIT(KNotepadSqlDeleteHead, "DELETE FROM Table1 WHERE key="); //39 chars |
|
30 const TInt KNotepadSqlDeleteHeadSize(49); // %d costs 10 chars in max |
|
31 |
|
32 // FORWARD DECLARATIONS |
|
33 class CFileStore; |
|
34 class CDaUserColSet; |
|
35 class CEikonEnv; |
|
36 class CPlainText; |
|
37 |
|
38 // CLASS DECLARATION |
|
39 /** |
|
40 * Core part of the Notepad Engine. |
|
41 * CNotepadCoreModel is a core part of Notepad engine. |
|
42 * This class manages a DBMS session. |
|
43 * |
|
44 * @lib NpdLib.lib |
|
45 * @see CNotepadModel, CNotepadTableModel |
|
46 */ |
|
47 class CNotepadCoreModel : public CBase |
|
48 { |
|
49 public: |
|
50 enum TNotepadModelRowResult |
|
51 { |
|
52 ENotepadModelRowNop = 0, |
|
53 ENotepadModelRowDeleted, |
|
54 ENotepadModelRowAdded, |
|
55 ENotepadModelRowUpdated |
|
56 }; |
|
57 |
|
58 public: // Constructors and destructor |
|
59 |
|
60 /** |
|
61 * Default c++ constructor. |
|
62 */ |
|
63 CNotepadCoreModel(); |
|
64 |
|
65 /** |
|
66 * second phase constructor. |
|
67 * |
|
68 * @param aResId resource id of data file name. |
|
69 */ |
|
70 void ConstructL(TInt aResId); |
|
71 |
|
72 /** |
|
73 * Destructor. |
|
74 * |
|
75 */ |
|
76 virtual ~CNotepadCoreModel(); |
|
77 |
|
78 public: // New functions |
|
79 |
|
80 /** |
|
81 * Return contents of a specified key. |
|
82 * |
|
83 * Caller own a returned object. |
|
84 * |
|
85 * @param aKey unique key id of Notepad. |
|
86 * @return text content of specified item. |
|
87 */ |
|
88 HBufC* ContentByKeyL(const TInt aKey); |
|
89 |
|
90 /** |
|
91 * Return the number of items in the database. |
|
92 * |
|
93 * @return Count of items. |
|
94 */ |
|
95 TInt CountL(); |
|
96 |
|
97 /** |
|
98 * Insert a text to the database as a new row. |
|
99 * If a given text is regarded as empty, nothing is done. |
|
100 * |
|
101 * @param aDes descripter to save. if NULL, aText will be used. |
|
102 * @param aText text to save. if NULL, aDes will be used. |
|
103 * @return ENotepadModelRowNop if a given text is regarded as empty, |
|
104 * ENotepadModelRowAdded if really added. |
|
105 */ |
|
106 TInt InsertL(const TDesC& aDes, TInt& aKey); |
|
107 |
|
108 /** |
|
109 * Update an entry. |
|
110 * If a given text is regarded as empty, the row is removed. |
|
111 * If a given text is regarded as unchanged, nothing is done. |
|
112 * |
|
113 * @param aText text to overwrite. |
|
114 * @param aKey entry key to update. |
|
115 * @return ENotepadModelRowNop if a given text is regarded as unchanged, |
|
116 * ENotepadModelRowDeleted if a given text is regarded as empty, and |
|
117 * ENotepadModelRowUpdated if really updated. |
|
118 */ |
|
119 TInt UpdateL(const TDesC& aDes, TInt& aKey); |
|
120 |
|
121 /** |
|
122 * Delete a item by Key. |
|
123 * |
|
124 * @param aKey key to delete. |
|
125 * @return If the key were not found, return ENotepadModelRowNop. |
|
126 */ |
|
127 TInt DeleteL(TInt aKey); |
|
128 |
|
129 /** |
|
130 * Make compaction of the database. |
|
131 * |
|
132 * @return the return value of RDbDatabase::Compact. |
|
133 */ |
|
134 TInt Compact(); |
|
135 |
|
136 /** |
|
137 * Sets the iModOp when a note is inserted/deleted/updated. |
|
138 * |
|
139 * @param aModeOp Insert/Delete/Update Operation. |
|
140 */ |
|
141 void SetModeOp(CNotepadCoreModel::TNotepadModelRowResult aModeOp); |
|
142 |
|
143 protected: // New functions |
|
144 |
|
145 /** |
|
146 * Read text content of aKey into aDes. |
|
147 * |
|
148 * @param aDes buffer for label. |
|
149 * @param aKey key id to read. |
|
150 */ |
|
151 void AppendContentAsLabelL(TDes& aDes, const TInt aKey); |
|
152 |
|
153 /** |
|
154 * Read text content into aDes. |
|
155 * |
|
156 * @param aDes buffer for label. |
|
157 * @param aDbView RDbView already opened for GetL. |
|
158 */ |
|
159 void AppendContentAsLabelL(TDes& aDes, RDbView& aDbView); |
|
160 |
|
161 /* |
|
162 * Ask if the model is running for Templates. |
|
163 */ |
|
164 inline TBool IsTemplates() const; |
|
165 |
|
166 /* |
|
167 * Returs the value of iModOp. |
|
168 * |
|
169 * @return value of the operation. |
|
170 */ |
|
171 CNotepadCoreModel::TNotepadModelRowResult ModeOp(); |
|
172 |
|
173 /** |
|
174 * Updates the ItemArray and the KeyArray when a particular |
|
175 * Note is either Inserted or Deleted or Updated. |
|
176 * |
|
177 * @param aItemArray Array of items to be displayed in the listbox. |
|
178 * @param aKeyArray key array. |
|
179 * @param aTimeFormat Time format. |
|
180 */ |
|
181 void DoUpdateNotepadItemArrayAndKeyArrayL(CDesCArray& aItemArray,RArray<TInt>& aKeyArray,HBufC& aTimeFormat); |
|
182 |
|
183 private: // New functions |
|
184 |
|
185 /** |
|
186 * Open (or create) a database. |
|
187 * |
|
188 * If already opened, do nothing. |
|
189 * If there is no datafile, create a new datafile. |
|
190 * |
|
191 * @internal |
|
192 */ |
|
193 void OpenDatabaseL(); |
|
194 |
|
195 /** |
|
196 * Create and initialize database file. |
|
197 * |
|
198 */ |
|
199 void CreateDataFileL(); |
|
200 |
|
201 /** |
|
202 * Initialize database file. |
|
203 * |
|
204 */ |
|
205 void InitDataFileL(); |
|
206 |
|
207 /** |
|
208 * Insert factory setting of templates. |
|
209 * |
|
210 */ |
|
211 void SetDefaultTemplatesL(); |
|
212 |
|
213 /** |
|
214 * Create database table definition. |
|
215 * |
|
216 * @return created table column definition. |
|
217 */ |
|
218 CDbColSet* CreateDbColSetLC() const; |
|
219 |
|
220 /** |
|
221 * Recover DB and Leave. |
|
222 * |
|
223 */ |
|
224 void Rollback(); |
|
225 |
|
226 /** |
|
227 * Common part of NewRowL and UpdateRowL. |
|
228 * |
|
229 * @param aItemIndex Update if aItemIndex>=0, otherwize Insert. |
|
230 * @param aText content. |
|
231 */ |
|
232 TInt InsertOrUpdateL(const TDesC& aDes, TInt& aKey); |
|
233 |
|
234 /** |
|
235 * Delete database file. |
|
236 * |
|
237 */ |
|
238 void DeleteFileL(); |
|
239 |
|
240 /** |
|
241 * Check the database table. |
|
242 * |
|
243 * @return ETrue if incorrect table, otherwise EFalse. |
|
244 */ |
|
245 TBool IsInvalidTableL(); |
|
246 |
|
247 /** |
|
248 * Gets the Index where the new/updated note needs to be inserted. |
|
249 * |
|
250 * @return Index where the note needs to be inserted. |
|
251 */ |
|
252 TInt GetInsertionIndex(const TDesC& aDes, |
|
253 CDesCArray& aItemArray); |
|
254 |
|
255 protected: // Data |
|
256 |
|
257 enum TNotepadColumnType |
|
258 { |
|
259 ENotepadKey = 1, // this must be 1 (DBMS/SQL restriction) |
|
260 //ENotepadUpdateDate, |
|
261 ENotepadUpdateTime, |
|
262 ENotepadMemo, |
|
263 ENotepadColCountPlusOne // sentinel |
|
264 }; |
|
265 |
|
266 RDbNamedDatabase iDatabase; |
|
267 CEikonEnv* iEnv; // cache |
|
268 |
|
269 private: // Data |
|
270 TInt iDataResourceId; |
|
271 HBufC* iDataFile; // own |
|
272 RDbs iDbs; |
|
273 TNotepadModelRowResult iModeOp; |
|
274 TInt iKey; |
|
275 TTime iNpdItemLastChanged; |
|
276 }; |
|
277 |
|
278 #include "NpdCoreModel.inl" |
|
279 #endif // NPDCOREMODEL_H |
|
280 |
|
281 // End of File |