|
1 /* |
|
2 * Copyright (c) 2007-2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "iaupdatequeryhistory.h" |
|
23 #include "iaupdatedebug.h" |
|
24 #include "iaupdatedialogutil.h" |
|
25 |
|
26 #include <bautils.h> // bafl.lib |
|
27 #include <s32file.h> // estor.lib |
|
28 #include <sysutil.h> |
|
29 |
|
30 // CONSTANTS |
|
31 const TInt KHistoryDrive( EDriveC ); |
|
32 const TInt KHistoryItemSize( 12 ); |
|
33 |
|
34 // MACROS |
|
35 _LIT( KHistoryFile, "IADQueryHistory" ); |
|
36 |
|
37 |
|
38 /******************************************************************************* |
|
39 * class TIAUpdateQueryHistoryItem |
|
40 *******************************************************************************/ |
|
41 |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // TIAUpdateQueryHistoryItem::Time |
|
45 // |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 TTime TIAUpdateQueryHistoryItem::Time() |
|
49 { |
|
50 return iTime; |
|
51 } |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // TIAUpdateQueryHistoryItem::SetTime |
|
56 // |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void TIAUpdateQueryHistoryItem::SetTime( TTime aTime ) |
|
60 { |
|
61 iTime = aTime; |
|
62 } |
|
63 |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // TIAUpdateQueryHistoryItem::InternalizeL |
|
67 // |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void TIAUpdateQueryHistoryItem::InternalizeL( RReadStream& aStream ) |
|
71 { |
|
72 iUid = aStream.ReadUint32L(); |
|
73 |
|
74 TInt64 temp = 0; |
|
75 aStream >> temp; |
|
76 |
|
77 if ( temp <= 0 ) |
|
78 { |
|
79 User::Leave( KErrCorrupt ); |
|
80 } |
|
81 TTime time( temp ); |
|
82 iTime = time; |
|
83 } |
|
84 |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // TIAUpdateQueryHistoryItem::ExternalizeL |
|
88 // |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void TIAUpdateQueryHistoryItem::ExternalizeL( RWriteStream& aStream ) |
|
92 { |
|
93 aStream.WriteUint32L( iUid ); |
|
94 aStream << iTime.Int64(); |
|
95 } |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 /******************************************************************************* |
|
102 * class CIAUpdateQueryHistory |
|
103 *******************************************************************************/ |
|
104 |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CIAUpdateQueryHistory::NewL |
|
108 // |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 CIAUpdateQueryHistory* CIAUpdateQueryHistory::NewL() |
|
112 { |
|
113 CIAUpdateQueryHistory* self = new (ELeave) CIAUpdateQueryHistory(); |
|
114 CleanupStack::PushL(self); |
|
115 self->ConstructL(); |
|
116 CleanupStack::Pop(self); |
|
117 |
|
118 return(self); |
|
119 } |
|
120 |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CIAUpdateQueryHistory::CIAUpdateQueryHistory |
|
124 // |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 CIAUpdateQueryHistory::CIAUpdateQueryHistory() |
|
128 : iDelay( KDefaultDelayHours ) |
|
129 { |
|
130 } |
|
131 |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // Destructor |
|
135 // |
|
136 // ---------------------------------------------------------------------------- |
|
137 // |
|
138 CIAUpdateQueryHistory::~CIAUpdateQueryHistory() |
|
139 { |
|
140 iList.Close(); |
|
141 } |
|
142 |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CIAUpdateQueryHistory::ConstructL |
|
146 // |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CIAUpdateQueryHistory::ConstructL() |
|
150 { |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CIAUpdateQueryHistory::SetTimeL |
|
155 // |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CIAUpdateQueryHistory::SetTimeL( TUint aUid ) |
|
159 { |
|
160 |
|
161 |
|
162 RFs fsSession; |
|
163 HBufC* path = HBufC::NewLC( KMaxFileName ); |
|
164 TPtr pathPtr = path->Des(); |
|
165 |
|
166 ConnectLC( fsSession, pathPtr ); |
|
167 |
|
168 ReadHistoryL( fsSession, *path ); |
|
169 |
|
170 TTime currentTime; |
|
171 currentTime.UniversalTime(); |
|
172 |
|
173 TIAUpdateQueryHistoryItem item; |
|
174 item.iUid = aUid; |
|
175 item.SetTime( currentTime ); |
|
176 AddItemL( item ); |
|
177 |
|
178 WriteHistoryL( fsSession, *path ); |
|
179 |
|
180 CleanupStack::PopAndDestroy( &fsSession ); |
|
181 CleanupStack::PopAndDestroy( path ); |
|
182 |
|
183 |
|
184 } |
|
185 |
|
186 |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CIAUpdateQueryHistory::SetDelay |
|
190 // |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CIAUpdateQueryHistory::SetDelay( TInt aHours ) |
|
194 { |
|
195 iDelay = aHours; |
|
196 } |
|
197 |
|
198 |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CIAUpdateQueryHistory::IsDelayedL |
|
202 // |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 TBool CIAUpdateQueryHistory::IsDelayedL( TUint aUid ) |
|
206 { |
|
207 RFs fsSession; |
|
208 HBufC* path = HBufC::NewLC( KMaxFileName ); |
|
209 TPtr pathPtr = path->Des(); |
|
210 |
|
211 ConnectLC( fsSession, pathPtr ); |
|
212 |
|
213 ReadHistoryL( fsSession, *path ); |
|
214 |
|
215 CleanupStack::PopAndDestroy( &fsSession ); |
|
216 CleanupStack::PopAndDestroy( path ); |
|
217 |
|
218 TInt index = ItemIndex( aUid ); |
|
219 if ( index == KErrNotFound ) |
|
220 { |
|
221 return EFalse; // no history data for this uid |
|
222 } |
|
223 |
|
224 TIAUpdateQueryHistoryItem& item = Item( index ); |
|
225 |
|
226 return IsDelayed( item ); |
|
227 } |
|
228 |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CIAUpdateQueryHistory::ConnectLC |
|
232 // |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CIAUpdateQueryHistory::ConnectLC( RFs& aFsSession, TDes& aPath ) |
|
236 { |
|
237 User::LeaveIfError( aFsSession.Connect() ); |
|
238 CleanupClosePushL( aFsSession ); |
|
239 User::LeaveIfError( aFsSession.SetSessionToPrivate( KHistoryDrive ) ); |
|
240 // sessionpath in emulator: '\epoc32\winscw\c\private\2000F85A' |
|
241 User::LeaveIfError( aFsSession.SessionPath( aPath ) ); |
|
242 BaflUtils::EnsurePathExistsL( aFsSession, aPath ); |
|
243 aPath.Append( KHistoryFile ); |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CIAUpdateQueryHistory::InternalizeL |
|
248 // |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 void CIAUpdateQueryHistory::InternalizeL( RReadStream& aStream ) |
|
252 { |
|
253 TInt count = aStream.ReadInt32L(); |
|
254 if ( count < 0 ) |
|
255 { |
|
256 User::Leave( KErrCorrupt ); |
|
257 } |
|
258 |
|
259 for (TInt i = 0; i< count; i++ ) |
|
260 { |
|
261 TIAUpdateQueryHistoryItem item; |
|
262 item.InternalizeL( aStream ); |
|
263 iList.AppendL( item ); |
|
264 } |
|
265 } |
|
266 |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CIAUpdateQueryHistory::ExternalizeL |
|
270 // |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CIAUpdateQueryHistory::ExternalizeL( RWriteStream& aStream ) |
|
274 { |
|
275 TInt count = iList.Count(); |
|
276 aStream.WriteInt32L( count ); |
|
277 |
|
278 for (TInt i = 0; i < count; i++ ) |
|
279 { |
|
280 TIAUpdateQueryHistoryItem& item = iList[i]; |
|
281 item.ExternalizeL( aStream ); |
|
282 } |
|
283 } |
|
284 |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CIAUpdateQueryHistory::ReadHistoryL |
|
288 // |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CIAUpdateQueryHistory::ReadHistoryL( RFs& aFsSession, const TDesC& aPath ) |
|
292 { |
|
293 iList.Reset(); |
|
294 RFile file; |
|
295 TInt err = file.Open( aFsSession, aPath, EFileRead|EFileShareAny ); |
|
296 if ( err != KErrNotFound ) |
|
297 { |
|
298 User::LeaveIfError( err ); |
|
299 CleanupClosePushL( file ); |
|
300 |
|
301 RFileReadStream stream( file, 0 ); |
|
302 CleanupClosePushL( stream ); |
|
303 |
|
304 InternalizeL( stream ); |
|
305 |
|
306 CleanupStack::PopAndDestroy( &stream ); |
|
307 CleanupStack::PopAndDestroy( &file ); |
|
308 } |
|
309 } |
|
310 |
|
311 |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CIAUpdateQueryHistory::WriteHistoryL |
|
315 // |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 void CIAUpdateQueryHistory::WriteHistoryL( RFs& aFsSession, const TDesC& aPath ) |
|
319 { |
|
320 |
|
321 TDriveUnit driveUnit( KHistoryDrive ); |
|
322 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &aFsSession, KHistoryItemSize, driveUnit ) ) |
|
323 { |
|
324 User::Leave( KErrDiskFull ); |
|
325 } |
|
326 RFile file; |
|
327 User::LeaveIfError( file.Replace( aFsSession, aPath, EFileWrite|EFileShareAny ) ); |
|
328 CleanupClosePushL( file ); |
|
329 |
|
330 RFileWriteStream stream( file, 0 ); |
|
331 CleanupClosePushL( stream ); |
|
332 |
|
333 ExternalizeL( stream ); |
|
334 |
|
335 stream.CommitL(); |
|
336 |
|
337 CleanupStack::PopAndDestroy( &stream ); |
|
338 CleanupStack::PopAndDestroy( &file ); |
|
339 } |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CIAUpdateQueryHistory::IsDelayed |
|
347 // |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 TBool CIAUpdateQueryHistory::IsDelayed( TIAUpdateQueryHistoryItem& aItem ) |
|
351 { |
|
352 TTime currentTime; |
|
353 currentTime.UniversalTime(); |
|
354 |
|
355 TTime lastQueryTime = aItem.Time(); |
|
356 |
|
357 TTimeIntervalHours hours; |
|
358 TInt err = currentTime.HoursFrom( lastQueryTime, hours ); |
|
359 if ( err != KErrNone ) |
|
360 { |
|
361 return EFalse; |
|
362 } |
|
363 |
|
364 TInt hourCount = hours.Int(); |
|
365 if ( hourCount >= 0 && hourCount < iDelay ) |
|
366 { |
|
367 return ETrue; |
|
368 } |
|
369 |
|
370 return EFalse; |
|
371 } |
|
372 |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CIAUpdateQueryHistory::AddItemL |
|
376 // |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 void CIAUpdateQueryHistory::AddItemL( TIAUpdateQueryHistoryItem aItem ) |
|
380 { |
|
381 TInt index = ItemIndex( aItem.iUid ); |
|
382 if ( index != KErrNotFound ) |
|
383 { |
|
384 iList.Remove( index ); |
|
385 } |
|
386 |
|
387 User::LeaveIfError( iList.Append( aItem ) ); |
|
388 |
|
389 } |
|
390 |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CIAUpdateQueryHistory::ItemIndex |
|
394 // |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 TInt CIAUpdateQueryHistory::ItemIndex( TUint aUid ) |
|
398 { |
|
399 TInt count = iList.Count(); |
|
400 |
|
401 for (TInt i=0; i < count; i++) |
|
402 { |
|
403 TIAUpdateQueryHistoryItem& item= iList[i]; |
|
404 if ( item.iUid == aUid ) |
|
405 { |
|
406 return i; |
|
407 } |
|
408 } |
|
409 |
|
410 return KErrNotFound; |
|
411 } |
|
412 |
|
413 |
|
414 // ----------------------------------------------------------------------------- |
|
415 // CIAUpdateQueryHistory::Item |
|
416 // |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 TIAUpdateQueryHistoryItem& CIAUpdateQueryHistory::Item( TInt aIndex ) |
|
420 { |
|
421 return iList[aIndex]; |
|
422 } |
|
423 |
|
424 |
|
425 // End of File |