|
1 /* |
|
2 * Copyright (c) 2007-2010 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->EnableStretching( EFalse ); |
|
128 iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue ); |
|
129 |
|
130 // Setup scroll bars |
|
131 iListBox->CreateScrollBarFrameL( ETrue ); |
|
132 iListBox-> |
|
133 ScrollBarFrame()-> |
|
134 SetScrollBarVisibilityL( |
|
135 CEikScrollBarFrame::EOff, |
|
136 CEikScrollBarFrame::EOff ); |
|
137 // Create item text array |
|
138 iItemTextArray = new( ELeave ) CDesCArrayFlat( KListGranularity ); |
|
139 iListBox->Model()->SetItemTextArray( iItemTextArray ); |
|
140 // Ownership of the array is transferred. |
|
141 iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray ); |
|
142 |
|
143 HBufC* text = StringLoader::LoadLC( R_IAUPDATE_NO_UPDATES_DONE ); |
|
144 iListBox->View()->SetListEmptyTextL( *text ); |
|
145 CleanupStack::PopAndDestroy( text ); |
|
146 |
|
147 // Create icon array |
|
148 |
|
149 CFbsBitmap* bitmap( NULL ); |
|
150 CFbsBitmap* mask( NULL ); |
|
151 |
|
152 CArrayPtr<CGulIcon>* iconArray = |
|
153 new( ELeave ) CAknIconArray( KListIconGranularity ); |
|
154 CleanupStack::PushL( iconArray ); |
|
155 |
|
156 HBufC* iconFilePath = HBufC::NewLC( KDC_APP_BITMAP_DIR().Length() + |
|
157 KIAUpdateIconFileName().Length() ); |
|
158 TPtr ptr = iconFilePath->Des(); |
|
159 ptr.Append( KDC_APP_BITMAP_DIR ); |
|
160 ptr.Append( KIAUpdateIconFileName ); |
|
161 |
|
162 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
163 |
|
164 |
|
165 // This method puts both aBitmap and aMask in the cleanup stack. |
|
166 AknsUtils::CreateIconLC( |
|
167 skin, |
|
168 KAknsIIDQgnPropCaleAccepted, |
|
169 bitmap, |
|
170 mask, |
|
171 *iconFilePath, |
|
172 EMbmIaupdateQgn_prop_cale_accepted, |
|
173 EMbmIaupdateQgn_prop_cale_accepted_mask ); |
|
174 CGulIcon* icon = CGulIcon::NewLC(); |
|
175 icon->SetBitmap( bitmap ); |
|
176 icon->SetMask( mask ); |
|
177 icon->SetBitmapsOwnedExternally( EFalse ); |
|
178 iconArray->AppendL( icon ); |
|
179 CleanupStack::Pop( icon ); |
|
180 CleanupStack::Pop( mask ); |
|
181 CleanupStack::Pop( bitmap ); |
|
182 |
|
183 // This method puts both aBitmap and aMask in the cleanup stack. |
|
184 AknsUtils::CreateIconLC( |
|
185 skin, |
|
186 KAknsIIDQgnPropSwupdFailed, |
|
187 bitmap, |
|
188 mask, |
|
189 *iconFilePath, |
|
190 EMbmIaupdateQgn_prop_swupd_failed, |
|
191 EMbmIaupdateQgn_prop_swupd_failed_mask); |
|
192 icon = CGulIcon::NewLC(); |
|
193 icon->SetBitmap( bitmap ); |
|
194 icon->SetMask( mask ); |
|
195 icon->SetBitmapsOwnedExternally( EFalse ); |
|
196 iconArray->AppendL( icon ); |
|
197 CleanupStack::Pop( icon ); |
|
198 CleanupStack::Pop( mask ); |
|
199 CleanupStack::Pop( bitmap ); |
|
200 |
|
201 CleanupStack::PopAndDestroy( iconFilePath ); |
|
202 CleanupStack::Pop( iconArray ); |
|
203 iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray ); |
|
204 |
|
205 // Set the windows size |
|
206 SetRect( aRect ); |
|
207 |
|
208 // Activate the window, which makes it ready to be drawn |
|
209 ActivateL(); |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CIAUpdateHistoryContainer::RefreshL |
|
214 // |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CIAUpdateHistoryContainer::RefreshL( MIAUpdateHistory& aHistory ) |
|
218 { |
|
219 iItemTextArray->Reset(); |
|
220 |
|
221 MIAUpdateHistoryItem* item( NULL ); |
|
222 const RPointerArray< MIAUpdateHistoryItem >& items = |
|
223 aHistory.Items(); |
|
224 TInt iconIndex( 0 ); |
|
225 for( TInt i = 0; i < items.Count(); ++i ) |
|
226 { |
|
227 item = items[i]; |
|
228 iconIndex = 0; |
|
229 if ( item->LastOperationErrorCode() != KErrNone |
|
230 || item->StateL() != MIAUpdateHistoryItem::EInstalled ) |
|
231 { |
|
232 // If there was an error in the last operation |
|
233 // or if the node has not been installed, |
|
234 // then use the second icon that is for |
|
235 // error situations. |
|
236 iconIndex = 1; |
|
237 } |
|
238 HBufC* nodeStateDescription = NodeStateDescriptionLC( *item ); |
|
239 TPtr ptr = nodeStateDescription->Des(); |
|
240 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr ); |
|
241 |
|
242 HBufC* name = item->Name().AllocLC(); |
|
243 TBuf<iconIndexLength> iconIndexBuf; |
|
244 iconIndexBuf.Format( KIconIndexFormat, iconIndex ); |
|
245 |
|
246 HBufC* buffer = HBufC::NewLC( iconIndexBuf.Length() + |
|
247 KTabulator.iTypeLength + |
|
248 name->Length() + |
|
249 KTabulator.iTypeLength + |
|
250 nodeStateDescription->Length() ); |
|
251 |
|
252 buffer->Des() = iconIndexBuf; |
|
253 buffer->Des() += KTabulator(); |
|
254 buffer->Des() += *name; |
|
255 buffer->Des() += KTabulator(); |
|
256 buffer->Des() += *nodeStateDescription; |
|
257 |
|
258 iItemTextArray->AppendL( *buffer ); |
|
259 |
|
260 CleanupStack::PopAndDestroy( buffer ); |
|
261 CleanupStack::PopAndDestroy( name ); |
|
262 CleanupStack::PopAndDestroy( nodeStateDescription ); |
|
263 } |
|
264 |
|
265 if ( items.Count() > 0 ) |
|
266 { |
|
267 iListBox-> |
|
268 ScrollBarFrame()-> |
|
269 SetScrollBarVisibilityL( |
|
270 CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto ); |
|
271 } |
|
272 else |
|
273 { |
|
274 iListBox-> |
|
275 ScrollBarFrame()-> |
|
276 SetScrollBarVisibilityL( |
|
277 CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOff ); |
|
278 } |
|
279 iListBox->HandleItemAdditionL(); |
|
280 } |
|
281 |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CIAUpdateHistoryContainer::OfferKeyEventL |
|
285 // |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 TKeyResponse CIAUpdateHistoryContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
289 TEventCode aType ) |
|
290 { |
|
291 TKeyResponse response = EKeyWasNotConsumed; |
|
292 |
|
293 if( aType == EEventKey ) |
|
294 { |
|
295 switch( aKeyEvent.iCode ) |
|
296 { |
|
297 // Up and down arrow actions are delegated to the listbox |
|
298 case EKeyUpArrow: |
|
299 case EKeyDownArrow: |
|
300 response = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
301 break; |
|
302 |
|
303 case EKeyOK: |
|
304 // Nothing to do here |
|
305 break; |
|
306 |
|
307 default: |
|
308 // Nothing to do here |
|
309 break; |
|
310 } |
|
311 } |
|
312 |
|
313 return response; |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CIAUpdateHistoryContainer::SizeChanged |
|
318 // |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 void CIAUpdateHistoryContainer::SizeChanged() |
|
322 { |
|
323 iListBox->SetRect( Rect() ); |
|
324 } |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CIAUpdateHistoryContainer::CountComponentControls |
|
328 // |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 TInt CIAUpdateHistoryContainer::CountComponentControls() const |
|
332 { |
|
333 return 1; |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CIAUpdateHistoryContainer::ComponentControl |
|
338 // |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 CCoeControl* CIAUpdateHistoryContainer::ComponentControl( TInt aIndex ) const |
|
342 { |
|
343 CCoeControl* control( NULL ); |
|
344 |
|
345 switch( aIndex ) |
|
346 { |
|
347 case 0: |
|
348 control = iListBox; |
|
349 break; |
|
350 |
|
351 default: |
|
352 break; |
|
353 } |
|
354 |
|
355 return control; |
|
356 } |
|
357 |
|
358 |
|
359 // --------------------------------------------------------------------------- |
|
360 // CIAUpdateHistoryContainer::HandleResourceChange |
|
361 // |
|
362 // --------------------------------------------------------------------------- |
|
363 // |
|
364 void CIAUpdateHistoryContainer::HandleResourceChange( TInt aType ) |
|
365 { |
|
366 CCoeControl::HandleResourceChange( aType ); |
|
367 |
|
368 if ( aType == KEikDynamicLayoutVariantSwitch ) //Handle change in layout orientation |
|
369 { |
|
370 TRect mainPaneRect; |
|
371 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect ); |
|
372 SetRect( mainPaneRect ); |
|
373 DrawNow(); |
|
374 } |
|
375 } |
|
376 |
|
377 // ----------------------------------------------------------------------------- |
|
378 // CIAUpdateHistoryContainer::NodeStateDescriptionLC |
|
379 // |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 HBufC* CIAUpdateHistoryContainer::NodeStateDescriptionLC( const MIAUpdateHistoryItem& aItem ) |
|
383 { |
|
384 HBufC* stateDescription( NULL ); |
|
385 |
|
386 MIAUpdateHistoryItem::TIAHistoryItemState state( aItem.StateL() ); |
|
387 TInt errorCode( aItem.LastOperationErrorCode() ); |
|
388 |
|
389 HBufC* timeDes = HBufC::NewLC( KTimeLength ); |
|
390 TPtr tmpDes = timeDes->Des(); |
|
391 |
|
392 // Get the current local time |
|
393 TTime currentTime( 0 ); |
|
394 currentTime.HomeTime(); |
|
395 |
|
396 TTime lastOperationTime = aItem.LastOperationTime(); |
|
397 // Get the local time from the unviversal time. |
|
398 TLocale locale; |
|
399 lastOperationTime += locale.UniversalTimeOffset(); |
|
400 |
|
401 if ( lastOperationTime - locale.UniversalTimeOffset() == 0 ) |
|
402 { |
|
403 // Because the origianal universal operation time was zero, the given time |
|
404 // is not correct. Set the time string empty. So, we will not give wrong information. |
|
405 tmpDes.Copy( KNullDesC() ); |
|
406 } |
|
407 else if ( currentTime.DayNoInYear() != lastOperationTime.DayNoInYear() |
|
408 || currentTime.DaysFrom( lastOperationTime ).Int() > 0 ) |
|
409 { |
|
410 // Day has changed. |
|
411 // Just to be sure, other checking is done because year may have also changed. |
|
412 lastOperationTime.FormatL( tmpDes, KDateFormat() ); |
|
413 } |
|
414 else |
|
415 { |
|
416 // Same day |
|
417 lastOperationTime.FormatL( tmpDes, KTimeFormat() ); |
|
418 } |
|
419 |
|
420 if ( errorCode == KErrNoMemory ) |
|
421 { |
|
422 // Last operation could not be completed because we were out of memory. |
|
423 // Show this error text. |
|
424 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_UPDATE_NO_MEMORY, |
|
425 *timeDes ); |
|
426 } |
|
427 else |
|
428 { |
|
429 switch( state ) |
|
430 { |
|
431 case MIAUpdateHistoryItem::EInstalled: |
|
432 if ( errorCode == KErrNone ) |
|
433 { |
|
434 // Because item is installed successfully, everything has gone ok. |
|
435 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_UPDATE_SUCCESSFULL, |
|
436 *timeDes ); |
|
437 } |
|
438 else if ( errorCode == KErrCancel ) |
|
439 { |
|
440 // For some reason, the state says that an item has been installed, |
|
441 // but the error code is cancel. In this case, trust the error code. |
|
442 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_CANCELLED, |
|
443 *timeDes ); |
|
444 } |
|
445 else |
|
446 { |
|
447 // If everything goes ok, then the item should be installed. |
|
448 // So, something has gone wrong because we are here. So, |
|
449 // give the install failed message |
|
450 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_FAILED, |
|
451 *timeDes ); |
|
452 } |
|
453 break; |
|
454 |
|
455 case MIAUpdateHistoryItem::EDownloaded: |
|
456 if ( errorCode == KErrCancel ) |
|
457 { |
|
458 // Because item has been downloaded but the error code is cancel |
|
459 // this means that the install has been cancelled |
|
460 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_CANCELLED, |
|
461 *timeDes ); |
|
462 } |
|
463 else |
|
464 { |
|
465 // If everything goes ok, then the item should be installed. |
|
466 // So, something has gone wrong because we are here. So, |
|
467 // give the install failed message |
|
468 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_FAILED, |
|
469 *timeDes ); |
|
470 } |
|
471 break; |
|
472 |
|
473 case MIAUpdateHistoryItem::EPurchased: |
|
474 if ( errorCode == KErrCancel ) |
|
475 { |
|
476 // Because item has been purchased but the error code is cancel |
|
477 // this means that the download has been cancelled |
|
478 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_DOWNLOAD_CANCELLED, |
|
479 *timeDes ); |
|
480 } |
|
481 else |
|
482 { |
|
483 // If everything goes ok, then the item should be installed. |
|
484 // So, something has gone wrong because we are here. So, |
|
485 // give the download failed message |
|
486 stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_DOWNLOAD_FAILED, |
|
487 *timeDes ); |
|
488 } |
|
489 break; |
|
490 |
|
491 default: |
|
492 // We should never come here. |
|
493 stateDescription = KNullDesC().AllocLC(); |
|
494 break; |
|
495 } |
|
496 } |
|
497 |
|
498 CleanupStack::Pop( stateDescription ); |
|
499 CleanupStack::PopAndDestroy( timeDes ); |
|
500 CleanupStack::PushL( stateDescription ); |
|
501 |
|
502 return stateDescription; |
|
503 } |
|
504 |
|
505 |