1 /* |
|
2 * Copyright (c) 2003 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: calss which directly deal with notepad database. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef NSMLNOTEPADDATABASE_H |
|
20 #define NSMLNOTEPADDATABASE_H |
|
21 |
|
22 |
|
23 //INCLUDES |
|
24 #include <d32dbms.h> |
|
25 #include <badesca.h> |
|
26 |
|
27 //CLASS Forward declarations |
|
28 class CNpdItem; |
|
29 class CCalSession; |
|
30 class CCalInstanceView; |
|
31 class CCalEntryView; |
|
32 |
|
33 const TInt KMaxFileLength(255); |
|
34 |
|
35 //Class declarations |
|
36 |
|
37 // ------------------------------------------------------------------------------------------------ |
|
38 // CNSmlNotepadDatabase |
|
39 // ------------------------------------------------------------------------------------------------ |
|
40 |
|
41 class CNSmlNotepadDatabase : public CBase |
|
42 { |
|
43 public: |
|
44 /** |
|
45 * Creates new instance of CNpdSmlDbModel based class. |
|
46 * @return CNpdSmlDbModel* Newly created instance. |
|
47 */ |
|
48 static CNSmlNotepadDatabase* NewL(); |
|
49 |
|
50 virtual ~CNSmlNotepadDatabase(); |
|
51 |
|
52 private: |
|
53 // Constructor |
|
54 CNSmlNotepadDatabase(); |
|
55 |
|
56 /** |
|
57 * 2-phase constructor |
|
58 */ |
|
59 void ConstructL(); |
|
60 |
|
61 public: |
|
62 |
|
63 /** |
|
64 * Opens notepad database file. If file does not exist, or is corrupted, |
|
65 * a new, empty file is created. |
|
66 * @param aStoreName, name of the notepad database file name |
|
67 */ |
|
68 void OpenL(const TDesC& aStoreName); |
|
69 |
|
70 /** |
|
71 * Adds a note to the database. |
|
72 * @param aNote the note to be added. |
|
73 * @param aKey database index of the newly added note. |
|
74 */ |
|
75 void AddNoteL(CNpdItem& aNote, TInt &aKey); |
|
76 |
|
77 /** |
|
78 * Deletes a note from the database. |
|
79 * @param aKey database index of the note to be deleted. |
|
80 */ |
|
81 void DeleteNoteL(const TInt aKey); |
|
82 |
|
83 |
|
84 /** |
|
85 * Closes the database. |
|
86 */ |
|
87 void Close(); |
|
88 |
|
89 /** |
|
90 * Reads a note from the database. |
|
91 * @param aKey database index of the desired note. |
|
92 * @param aNote reference to note object, used to return note data. |
|
93 */ |
|
94 void GetNoteL(const TInt aKey, CNpdItem& aNote); |
|
95 |
|
96 /** |
|
97 * Updates a note in the database. |
|
98 * @param aKey database index of the note to be updated. |
|
99 * @param aItem note data. This data overrides existing note. |
|
100 */ |
|
101 void UpdateNoteL(const TInt aKey, CNpdItem& aItem); |
|
102 |
|
103 |
|
104 /** |
|
105 * Empties the database. All notes are deleted. |
|
106 * @return KErrNone if successful, a system wide error code otherwise. |
|
107 */ |
|
108 TInt ResetL(); |
|
109 |
|
110 /** |
|
111 * Checks if the database has been succesfully openend |
|
112 * @return ETrue if database has been succesfully opened, EFalse otherwise |
|
113 */ |
|
114 TBool IsOpen(); |
|
115 |
|
116 |
|
117 /** |
|
118 * Fetch all the note items if aKey is not present. Else item with the aKey. |
|
119 * @returns array of NpdItem. |
|
120 */ |
|
121 CArrayPtr<CNpdItem>* FetchItemsLC(TBool aIncludeText = EFalse, TInt* aKey = 0); |
|
122 |
|
123 /** |
|
124 * Close all the CalSession related sessions |
|
125 * viz., instance view, entry view and calsession itself |
|
126 */ |
|
127 void CloseAgendaSessions(); |
|
128 |
|
129 private: // Data |
|
130 |
|
131 // Flag for whether database has been opened |
|
132 TBool iOpened; |
|
133 CCalSession* iSession; |
|
134 CCalInstanceView* iInstanceView; |
|
135 CCalEntryView* iEntryView; |
|
136 |
|
137 enum TNotepadColumnType |
|
138 { |
|
139 ENotepadKey = 1, // this must be 1 (DBMS/SQL restriction) |
|
140 ENotepadUpdateTime, |
|
141 ENotepadMemo |
|
142 }; |
|
143 }; |
|
144 |
|
145 class CNpdItem : public CBase |
|
146 { |
|
147 public: |
|
148 // Destructor |
|
149 virtual ~CNpdItem(); |
|
150 |
|
151 /** |
|
152 * Creates new instance of CNpdItem based class. |
|
153 * @return CNpdItem* Newly created instance. |
|
154 */ |
|
155 static CNpdItem* NewLC(); |
|
156 |
|
157 /** |
|
158 * Creates new instance of CNpdItem based class. |
|
159 * @param aKey database index key |
|
160 * @param aLastModified timestamp |
|
161 * @param aContent content (text) of the note |
|
162 * @return CNpdItem* Newly created instance. |
|
163 */ |
|
164 static CNpdItem* NewLC(TInt aKey, const TTime& aLastModified, HBufC* aContent); |
|
165 |
|
166 private: |
|
167 // Constructor |
|
168 CNpdItem(); |
|
169 |
|
170 //Overloaded Constructor |
|
171 CNpdItem(TInt aKey, const TTime& aLastModified, HBufC *content); |
|
172 |
|
173 public: |
|
174 /** |
|
175 * Returns database key. |
|
176 * @return key value. |
|
177 */ |
|
178 TInt Key() const; |
|
179 |
|
180 /** |
|
181 * Returns the time stamp of the note. |
|
182 * @return when note was last modified. |
|
183 */ |
|
184 TTime LastModified() const; |
|
185 |
|
186 /** |
|
187 * Returns content of the note |
|
188 * @return text of the note. |
|
189 */ |
|
190 HBufC* Content(); |
|
191 |
|
192 /** |
|
193 * Set note data. |
|
194 * @param aKey database index |
|
195 * @param aModTime time note was last modified |
|
196 * @param aContent content of the note |
|
197 */ |
|
198 void Set(TInt aKey, const TTime& aModTime, HBufC* aContent); |
|
199 |
|
200 /** |
|
201 * Set key of the note |
|
202 * @param aKey key of the note. |
|
203 */ |
|
204 void SetKey(TInt aKey); |
|
205 |
|
206 /** |
|
207 * Set content of the note |
|
208 * @param aContent text of the note. |
|
209 */ |
|
210 void SetContent(HBufC* aContent); |
|
211 |
|
212 /** |
|
213 * Returns timestamp of the note |
|
214 * @param aLastModified time note was last modified. |
|
215 */ |
|
216 void SetModified(const TTime& aLastModified); |
|
217 |
|
218 private: |
|
219 TInt iKey; |
|
220 TTime iLastModified; |
|
221 HBufC* iContent; // owned |
|
222 }; |
|
223 |
|
224 #endif // NSMLNOTEPADDATABASE_H |
|