|
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: This module contains the implementation of |
|
15 * CIAUpdateHistoryContainer class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include <coemain.h> |
|
23 #include <aknlists.h> // For the listbox |
|
24 #include <barsread.h> // TResourceReader |
|
25 #include <avkon.mbg> |
|
26 #include <AknIconArray.h> |
|
27 #include <gulicon.h> |
|
28 #include <AknsUtils.h> |
|
29 #include <StringLoader.h> |
|
30 #include <e32std.h> |
|
31 #include <data_caging_path_literals.hrh> |
|
32 #include <iaupdate.rsg> |
|
33 #include <iaupdate.mbg> |
|
34 |
|
35 #include "iaupdatehistorycontainer.h" |
|
36 #include "iaupdatehistory.h" |
|
37 #include "iaupdatehistoryitem.h" |
|
38 #include "iaupdateutils.h" |
|
39 |
|
40 |
|
41 // MACROS |
|
42 _LIT(KIAUpdateIconFileName, "IAUpdate.mif"); |
|
43 // Format for TTime |
|
44 // See: C++ API reference » Date and Time Handling » Using TTime |
|
45 _LIT( KDateFormat, "%*D%*M%Y%/0%4%/1%5" ); |
|
46 _LIT( KTimeFormat, "%-B%:0%J%:1%T%+B" ); |
|
47 _LIT( KIconIndexFormat, "%d" ); |
|
48 _LIT( KTabulator, "\t" ); |
|
49 |
|
50 //CONSTANTS |
|
51 // Item list granularity |
|
52 const TInt KListGranularity( 8 ); |
|
53 // There will be two images. One for error and for success. |
|
54 const TInt KListIconGranularity( 2 ); |
|
55 const TInt KTimeLength( 48 ); |
|
56 // Icon index length is always one because an index is either zero or one |
|
57 const TInt iconIndexLength( 1 ); |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CIAUpdateHistoryContainer::NewL |
|
61 // Two-phased constructor. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CIAUpdateHistoryContainer* CIAUpdateHistoryContainer::NewL( const TRect& aRect ) |
|
65 { |
|
66 CIAUpdateHistoryContainer* self = |
|
67 CIAUpdateHistoryContainer::NewLC( aRect ); |
|
68 CleanupStack::Pop(self); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CIAUpdateHistoryContainer::NewLC |
|
74 // |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CIAUpdateHistoryContainer* CIAUpdateHistoryContainer::NewLC( const TRect& aRect ) |
|
78 { |
|
79 CIAUpdateHistoryContainer* self = |
|
80 new (ELeave) CIAUpdateHistoryContainer(); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL( aRect ); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CIAUpdateHistoryContainer::CIAUpdateHistoryContainer |
|
88 // C++ default constructor can NOT contain any code, that |
|
89 // might leave. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 CIAUpdateHistoryContainer::CIAUpdateHistoryContainer() |
|
93 : CCoeControl() |
|
94 { |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CIAUpdateHistoryContainer::~CIAUpdateHistoryContainer |
|
99 // Destructor |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 CIAUpdateHistoryContainer::~CIAUpdateHistoryContainer() |
|
103 { |
|
104 delete iListBox; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CIAUpdateHistoryContainer::ConstructL |
|
109 // Symbian 2nd phase constructor can leave. |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CIAUpdateHistoryContainer::ConstructL( const TRect& aRect ) |
|
113 { |
|
114 // Create a window for this application view |
|
115 CreateWindowL(); |
|
116 |
|
117 // Create list box |
|
118 iListBox = new( ELeave ) CAknDoubleGraphicStyleListBox(); |
|
119 iListBox->SetContainerWindowL( *this ); |
|
120 |
|
121 TResourceReader reader; |
|
122 // Inserts reader into the cleanupstack. |
|
123 iEikonEnv->CreateResourceReaderLC( reader, R_IAUPDATE_HISTORY_LIST ); |
|
124 iListBox->ConstructFromResourceL( reader ); |
|
125 CleanupStack::PopAndDestroy(); |
|
126 |
|
127 iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue ); |
|
128 |
|
129 // Setup scroll bars |
|
130 iListBox->CreateScrollBarFrameL( ETrue ); |
|
131 iListBox-> |
|
132 ScrollBarFrame()-> |
|
133 SetScrollBarVisibilityL( |
|
134 CEikScrollBarFrame::EOff, |
|
135 CEikScrollBarFrame::EOff ); |
|
136 // Create item text array |
|
137 iItemTextArray = new( ELeave ) CDesCArrayFlat( KListGranularity ); |
|
138 iListBox->Model()->SetItemTextArray( iItemTextArray ); |
|
139 // Ownership of the array is transferred. |
|
140 iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray ); |
|
141 |
|
142 HBufC* text = StringLoader::LoadLC( R_IAUPDATE_NO_UPDATES_DONE ); |
|
143 iListBox->View()->SetListEmptyTextL( *text ); |
|
144 CleanupStack::PopAndDestroy( text ); |
|
145 |
|
146 // Create icon array |
|
147 |
|
148 CFbsBitmap* bitmap( NULL ); |
|
149 CFbsBitmap* mask( NULL ); |
|
150 |
|
151 CArrayPtr<CGulIcon>* iconArray = |
|
152 new( ELeave ) CAknIconArray( KListIconGranularity ); |
|
153 CleanupStack::PushL( iconArray ); |
|
154 |
|
155 HBufC* iconFilePath = HBufC::NewLC( KDC_APP_BITMAP_DIR().Length() + |
|
156 KIAUpdateIconFileName().Length() ); |
|
157 TPtr ptr = iconFilePath->Des(); |
|
158 ptr.Append( KDC_APP_BITMAP_DIR ); |
|
159 ptr.Append( KIAUpdateIconFileName ); |
|
160 |
|
161 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
162 |
|
163 |
|
164 // This method puts both aBitmap and aMask in the cleanup stack. |
|
165 AknsUtils::CreateIconLC( |
|
166 skin, |
|
167 KAknsIIDQgnPropCaleAccepted, |
|
168 bitmap, |
|
169 mask, |
|
170 *iconFilePath, |
|
171 EMbmIaupdateQgn_prop_cale_accepted, |
|
172 EMbmIaupdateQgn_prop_cale_accepted_mask ); |
|
173 CGulIcon* icon = CGulIcon::NewLC(); |
|
174 icon->SetBitmap( bitmap ); |
|
175 icon->SetMask( mask ); |
|
176 icon->SetBitmapsOwnedExternally( EFalse ); |
|
177 iconArray->AppendL( icon ); |
|
178 CleanupStack::Pop( icon ); |
|
179 CleanupStack::Pop( mask ); |
|
180 CleanupStack::Pop( bitmap ); |
|
181 |
|
182 // This method puts both aBitmap and aMask in the cleanup stack. |
|
183 AknsUtils::CreateIconLC( |
|
184 skin, |
|
185 KAknsIIDQgnPropSwupdFailed, |
|
186 bitmap, |
|
187 mask, |
|
188 *iconFilePath, |
|
189 EMbmIaupdateQgn_prop_swupd_failed, |
|
190 EMbmIaupdateQgn_prop_swupd_failed_mask); |
|
191 icon = CGulIcon::NewLC(); |
|
192 icon->SetBitmap( bitmap ); |
|
193 icon->SetMask( mask ); |
|
194 icon->SetBitmapsOwnedExternally( EFalse ); |
|
195 iconArray->AppendL( icon ); |
|
196 CleanupStack::Pop( icon ); |
|
197 CleanupStack::Pop( mask ); |
|
198 CleanupStack::Pop( bitmap ); |
|
199 |
|
200 CleanupStack::PopAndDestroy( iconFilePath ); |
|
201 CleanupStack::Pop( iconArray ); |
|
202 iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray ); |
|
203 |
|
204 // Set the windows size |
|
205 SetRect( aRect ); |
|
206 |
|
207 // Activate the window, which makes it ready to be drawn |
|
208 ActivateL(); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CIAUpdateHistoryContainer::RefreshL |
|
213 // |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CIAUpdateHistoryContainer::RefreshL( MIAUpdateHistory& aHistory ) |
|
217 { |
|
218 iItemTextArray->Reset(); |
|
219 |
|
220 MIAUpdateHistoryItem* item( NULL ); |
|
221 const RPointerArray< MIAUpdateHistoryItem >& items = |
|
222 aHistory.Items(); |
|
223 TInt iconIndex( 0 ); |
|
224 for( TInt i = 0; i < items.Count(); ++i ) |
|
225 { |
|
226 item = items[i]; |
|
227 iconIndex = 0; |
|
228 if ( item->LastOperationErrorCode() != KErrNone |
|
229 || item->StateL() != MIAUpdateHistoryItem::EInstalled ) |
|
230 { |
|
231 // If there was an error in the last operation |
|
232 // or if the node has not been installed, |
|
233 // then use the second icon that is for |
|
234 // error situations. |
|
235 iconIndex = 1; |
|
236 } |
|
237 |
|
238 HBufC* nodeStateDescription = NodeStateDescriptionLC( *item ); |
|
239 TPtr ptr = nodeStateDescription->Des(); |
|
240 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr ); |
|
241 |
|
242 |
|
243 HBufC* nameAndVersion = NULL; |
|
244 |
|
245 _LIT( KZeroVersion, "0.00(0)"); |
|
246 |
|
247 //If version number is all zeros, then only show name of the package |
|
248 //This checking is meant for service pack which doesn't have any version number |
|
249 |
|
250 if ( item->Version().Compare( KZeroVersion ) == 0 ) |
|
251 { |
|
252 nameAndVersion = item->Name().AllocLC(); |
|
253 } |
|
254 else |
|
255 { |
|
256 CDesCArray* stringArray = new ( ELeave ) CDesCArrayFlat( 1 ); |
|
257 CleanupStack::PushL( stringArray ); |
|
258 stringArray->AppendL( item->Name() ); |
|
259 CArrayFix<TInt>* numberArray = new ( ELeave ) CArrayFixFlat<TInt>( 2 ); |
|
260 CleanupStack::PushL( numberArray ); |
|
261 TInt8 majorVersion( 0 ); |
|
262 TInt8 minorVersion( 0 ); |
|
263 TInt16 buildVersion( 0 ); |
|
264 IAUpdateUtils::DesToVersionL( item->Version(), |
|
265 majorVersion, minorVersion, buildVersion ); |
|
266 |
|
267 numberArray->AppendL( majorVersion ); |
|
268 numberArray->AppendL( minorVersion ); |
|
269 |
|
270 nameAndVersion = StringLoader::LoadL( R_IAUPDATE_NAME_WITH_VERSION, |
|
271 *stringArray, |
|
272 *numberArray ); |
|
273 CleanupStack::PopAndDestroy( numberArray ); |
|
274 CleanupStack::PopAndDestroy( stringArray ); |
|
275 |
|
276 CleanupStack::PushL( nameAndVersion ); |
|
277 } |
|
278 |
|
279 |
|
280 TPtr nameAndVersionPtr = nameAndVersion->Des(); |
|
281 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( nameAndVersionPtr ); |
|
282 |
|
283 TBuf<iconIndexLength> iconIndexBuf; |
|
284 iconIndexBuf.Format( KIconIndexFormat, iconIndex ); |
|
285 |
|
286 HBufC* buffer = HBufC::NewLC( iconIndexBuf.Length() + |
|
287 KTabulator.iTypeLength + |
|
288 nameAndVersion->Length() + |
|
289 KTabulator.iTypeLength + |
|
290 nodeStateDescription->Length() ); |
|
291 |
|
292 buffer->Des() = iconIndexBuf; |
|
293 buffer->Des() += KTabulator(); |
|
294 buffer->Des() += *nameAndVersion; |
|
295 buffer->Des() += KTabulator(); |
|
296 buffer->Des() += *nodeStateDescription; |
|
297 |
|
298 iItemTextArray->AppendL( *buffer ); |
|
299 |
|
300 CleanupStack::PopAndDestroy( buffer ); |
|
301 CleanupStack::PopAndDestroy( nameAndVersion ); |
|
302 CleanupStack::PopAndDestroy( nodeStateDescription ); |
|
303 } |
|
304 |
|
305 if ( items.Count() > 0 ) |
|
306 { |
|
307 iListBox-> |
|
308 ScrollBarFrame()-> |
|
309 SetScrollBarVisibilityL( |
|
310 CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto ); |
|
311 } |
|
312 else |
|
313 { |
|
314 iListBox-> |
|
315 ScrollBarFrame()-> |
|
316 SetScrollBarVisibilityL( |
|
317 CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOff ); |
|
318 } |
|
319 iListBox->HandleItemAdditionL(); |
|
320 } |
|
321 |
|
322 |
|
323 // ----------------------------------------------------------------------------- |
|
324 // CIAUpdateHistoryContainer::OfferKeyEventL |
|
325 // |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 TKeyResponse CIAUpdateHistoryContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
329 TEventCode aType ) |
|
330 { |
|
331 TKeyResponse response = EKeyWasNotConsumed; |
|
332 |
|
333 if( aType == EEventKey ) |
|
334 { |
|
335 switch( aKeyEvent.iCode ) |
|
336 { |
|
337 // Up and down arrow actions are delegated to the listbox |
|
338 case EKeyUpArrow: |
|
339 case EKeyDownArrow: |
|
340 response = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
341 break; |
|
342 |
|
343 case EKeyOK: |
|
344 // Nothing to do here |
|
345 break; |
|
346 |
|
347 default: |
|
348 // Nothing to do here |
|
349 break; |
|
350 } |
|
351 } |
|
352 |
|
353 return response; |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // CIAUpdateHistoryContainer::SizeChanged |
|
358 // |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 void CIAUpdateHistoryContainer::SizeChanged() |
|
362 { |
|
363 iListBox->SetRect( Rect() ); |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CIAUpdateHistoryContainer::CountComponentControls |
|
368 // |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 TInt CIAUpdateHistoryContainer::CountComponentControls() const |
|
372 { |
|
373 return 1; |
|
374 } |
|
375 |
|
376 // ----------------------------------------------------------------------------- |
|
377 // CIAUpdateHistoryContainer::ComponentControl |
|
378 // |
|
379 // ----------------------------------------------------------------------------- |
|
380 // |
|
381 CCoeControl* CIAUpdateHistoryContainer::ComponentControl( TInt aIndex ) const |
|
382 { |
|
383 CCoeControl* control( NULL ); |
|
384 |
|
385 switch( aIndex ) |
|
386 { |
|
387 case 0: |
|
388 control = iListBox; |
|
389 break; |
|
390 |
|
391 default: |
|
392 break; |
|
393 } |
|
394 |
|
395 return control; |
|
396 } |
|
397 |
|
398 |
|
399 // --------------------------------------------------------------------------- |
|
400 // CIAUpdateHistoryContainer::HandleResourceChange |
|
401 // |
|
402 // --------------------------------------------------------------------------- |
|
403 // |
|
404 void CIAUpdateHistoryContainer::HandleResourceChange( TInt aType ) |
|
405 { |
|
406 CCoeControl::HandleResourceChange( aType ); |
|
407 |
|
408 if ( aType == KEikDynamicLayoutVariantSwitch ) //Handle change in layout orientation |
|
409 { |
|
410 TRect mainPaneRect; |
|
411 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect ); |
|
412 SetRect( mainPaneRect ); |
|
413 DrawNow(); |
|
414 } |
|
415 } |
|
416 |
|
417 // ----------------------------------------------------------------------------- |
|
418 // CIAUpdateHistoryContainer::NodeStateDescriptionLC |
|
419 // |
|
420 // ----------------------------------------------------------------------------- |
|
421 // |
|
422 HBufC* CIAUpdateHistoryContainer::NodeStateDescriptionLC( const MIAUpdateHistoryItem& aItem ) |
|
423 { |
|
424 HBufC* stateDescription( NULL ); |
|
425 |
|
426 MIAUpdateHistoryItem::TIAHistoryItemState state( aItem.StateL() ); |
|
427 TInt errorCode( aItem.LastOperationErrorCode() ); |
|
428 |
|
429 HBufC* timeDes = HBufC::NewLC( KTimeLength ); |
|
430 TPtr tmpDes = timeDes->Des(); |
|
431 |
|
432 // Get the current local time |
|
433 TTime currentTime( 0 ); |
|
434 currentTime.HomeTime(); |
|
435 |
|
436 TTime lastOperationTime = aItem.LastOperationTime(); |
|
437 // Get the local time from the unviversal time. |
|
438 TLocale locale; |
|
439 lastOperationTime += locale.UniversalTimeOffset(); |
|
440 |
|
441 if ( lastOperationTime - locale.UniversalTimeOffset() == 0 ) |
|
442 { |
|
443 // Because the origianal universal operation time was zero, the given time |
|
444 // is not correct. Set the time string empty. So, we will not give wrong information. |
|
445 tmpDes.Copy( KNullDesC() ); |
|
446 } |
|
447 else if ( currentTime.DayNoInYear() != lastOperationTime.DayNoInYear() |
|
448 || currentTime.DaysFrom( lastOperationTime ).Int() > 0 ) |
|
449 { |
|
450 // Day has changed. |
|
451 // Just to be sure, other checking is done because year may have also changed. |
|
452 lastOperationTime.FormatL( tmpDes, KDateFormat() ); |
|
453 } |
|
454 else |
|
455 { |
|
456 // Same day |
|
457 lastOperationTime.FormatL( tmpDes, KTimeFormat() ); |
|
458 } |
|
459 |
|
460 if ( errorCode == KErrNoMemory ) |
|
461 { |
|
462 // Last operation could not be completed because we were out of memory. |
|
463 // Show this error text. |
|
464 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_UPDATE_NO_MEMORY, |
|
465 *timeDes ); |
|
466 } |
|
467 else |
|
468 { |
|
469 switch( state ) |
|
470 { |
|
471 case MIAUpdateHistoryItem::EInstalled: |
|
472 if ( errorCode == KErrNone ) |
|
473 { |
|
474 // Because item is installed successfully, everything has gone ok. |
|
475 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_UPDATE_SUCCESSFULL, |
|
476 *timeDes ); |
|
477 } |
|
478 else if ( errorCode == KErrCancel ) |
|
479 { |
|
480 // For some reason, the state says that an item has been installed, |
|
481 // but the error code is cancel. In this case, trust the error code. |
|
482 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_CANCELLED, |
|
483 *timeDes ); |
|
484 } |
|
485 else |
|
486 { |
|
487 // If everything goes ok, then the item should be installed. |
|
488 // So, something has gone wrong because we are here. So, |
|
489 // give the install failed message |
|
490 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_FAILED, |
|
491 *timeDes ); |
|
492 } |
|
493 break; |
|
494 |
|
495 case MIAUpdateHistoryItem::EDownloaded: |
|
496 if ( errorCode == KErrCancel ) |
|
497 { |
|
498 // Because item has been downloaded but the error code is cancel |
|
499 // this means that the install has been cancelled |
|
500 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_CANCELLED, |
|
501 *timeDes ); |
|
502 } |
|
503 else |
|
504 { |
|
505 // If everything goes ok, then the item should be installed. |
|
506 // So, something has gone wrong because we are here. So, |
|
507 // give the install failed message |
|
508 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_FAILED, |
|
509 *timeDes ); |
|
510 } |
|
511 break; |
|
512 |
|
513 case MIAUpdateHistoryItem::EPurchased: |
|
514 if ( errorCode == KErrCancel ) |
|
515 { |
|
516 // Because item has been purchased but the error code is cancel |
|
517 // this means that the download has been cancelled |
|
518 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_DOWNLOAD_CANCELLED, |
|
519 *timeDes ); |
|
520 } |
|
521 else |
|
522 { |
|
523 // If everything goes ok, then the item should be installed. |
|
524 // So, something has gone wrong because we are here. So, |
|
525 // give the download failed message |
|
526 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_DOWNLOAD_FAILED, |
|
527 *timeDes ); |
|
528 } |
|
529 break; |
|
530 |
|
531 default: |
|
532 // We should never come here. |
|
533 stateDescription = KNullDesC().AllocLC(); |
|
534 break; |
|
535 } |
|
536 } |
|
537 |
|
538 CleanupStack::Pop( stateDescription ); |
|
539 CleanupStack::PopAndDestroy( timeDes ); |
|
540 CleanupStack::PushL( stateDescription ); |
|
541 |
|
542 return stateDescription; |
|
543 } |
|
544 |
|
545 |