iaupdate/IAD/ui/src/iaupdatehistorycontainer.cpp
changeset 29 26b6f0522fd8
parent 25 98b66e4fb0be
child 30 398876c4ffa7
child 33 8110bf1194d1
equal deleted inserted replaced
25:98b66e4fb0be 29:26b6f0522fd8
     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         HBufC* nodeStateDescription = NodeStateDescriptionLC( *item );
       
   238         TPtr ptr = nodeStateDescription->Des();
       
   239         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr ); 
       
   240  
       
   241         HBufC* name = item->Name().AllocLC();
       
   242         TBuf<iconIndexLength> iconIndexBuf;
       
   243         iconIndexBuf.Format( KIconIndexFormat, iconIndex );
       
   244 
       
   245         HBufC* buffer = HBufC::NewLC( iconIndexBuf.Length() +
       
   246                                       KTabulator.iTypeLength + 
       
   247                                       name->Length() + 
       
   248                                       KTabulator.iTypeLength +
       
   249                                       nodeStateDescription->Length() );  
       
   250 
       
   251         buffer->Des() = iconIndexBuf;
       
   252         buffer->Des() += KTabulator();
       
   253         buffer->Des() += *name;
       
   254         buffer->Des() += KTabulator();
       
   255         buffer->Des() += *nodeStateDescription;        
       
   256          
       
   257         iItemTextArray->AppendL( *buffer );
       
   258                  
       
   259         CleanupStack::PopAndDestroy( buffer );
       
   260         CleanupStack::PopAndDestroy( name );
       
   261         CleanupStack::PopAndDestroy( nodeStateDescription );
       
   262         }    
       
   263     
       
   264     if ( items.Count() > 0 )
       
   265         {
       
   266     	iListBox->
       
   267         ScrollBarFrame()->
       
   268             SetScrollBarVisibilityL( 
       
   269                 CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto ); 
       
   270         }
       
   271     else
       
   272         {
       
   273         iListBox->
       
   274         ScrollBarFrame()->
       
   275             SetScrollBarVisibilityL( 
       
   276                 CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOff );	
       
   277         }     
       
   278     iListBox->HandleItemAdditionL();        
       
   279     }
       
   280 
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CIAUpdateHistoryContainer::OfferKeyEventL
       
   284 // 
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 TKeyResponse CIAUpdateHistoryContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   288                                                         TEventCode aType )
       
   289     {
       
   290     TKeyResponse response = EKeyWasNotConsumed;    
       
   291 
       
   292     if( aType == EEventKey )
       
   293         {
       
   294         switch( aKeyEvent.iCode )
       
   295             {
       
   296             // Up and down arrow actions are delegated to the listbox
       
   297             case EKeyUpArrow:
       
   298             case EKeyDownArrow:
       
   299                 response = iListBox->OfferKeyEventL( aKeyEvent, aType );        
       
   300                 break;
       
   301                 
       
   302             case EKeyOK:
       
   303                 // Nothing to do here
       
   304                 break;
       
   305                 
       
   306             default:
       
   307                 // Nothing to do here
       
   308                 break;
       
   309             }
       
   310         }
       
   311 
       
   312     return response;        
       
   313     }
       
   314     
       
   315 // -----------------------------------------------------------------------------
       
   316 // CIAUpdateHistoryContainer::SizeChanged
       
   317 // 
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CIAUpdateHistoryContainer::SizeChanged()
       
   321     {
       
   322     iListBox->SetRect( Rect() );
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CIAUpdateHistoryContainer::CountComponentControls
       
   327 // 
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 TInt CIAUpdateHistoryContainer::CountComponentControls() const
       
   331     {
       
   332     return 1;
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CIAUpdateHistoryContainer::ComponentControl
       
   337 // 
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 CCoeControl* CIAUpdateHistoryContainer::ComponentControl( TInt aIndex ) const
       
   341     {
       
   342     CCoeControl* control( NULL );
       
   343 
       
   344     switch( aIndex )
       
   345         {
       
   346         case 0:
       
   347             control = iListBox;
       
   348             break;
       
   349             
       
   350         default:
       
   351             break;
       
   352         }
       
   353 
       
   354     return control;
       
   355     }
       
   356     
       
   357     
       
   358 // ---------------------------------------------------------------------------
       
   359 // CIAUpdateHistoryContainer::HandleResourceChange
       
   360 // 
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 void CIAUpdateHistoryContainer::HandleResourceChange( TInt aType )
       
   364     {
       
   365 	CCoeControl::HandleResourceChange( aType );
       
   366 
       
   367     if ( aType == KEikDynamicLayoutVariantSwitch ) //Handle change in layout orientation
       
   368         {
       
   369         TRect mainPaneRect;
       
   370         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   371         SetRect( mainPaneRect );
       
   372 		DrawNow();
       
   373 		}
       
   374     }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CIAUpdateHistoryContainer::NodeStateDescriptionLC
       
   378 // 
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 HBufC* CIAUpdateHistoryContainer::NodeStateDescriptionLC( const MIAUpdateHistoryItem& aItem )
       
   382     {
       
   383     HBufC* stateDescription( NULL );
       
   384 
       
   385     MIAUpdateHistoryItem::TIAHistoryItemState state( aItem.StateL() );
       
   386     TInt errorCode( aItem.LastOperationErrorCode() );
       
   387 
       
   388     HBufC* timeDes = HBufC::NewLC( KTimeLength );
       
   389     TPtr tmpDes = timeDes->Des();
       
   390     
       
   391     // Get the current local time
       
   392     TTime currentTime( 0 );
       
   393     currentTime.HomeTime();
       
   394 
       
   395     TTime lastOperationTime = aItem.LastOperationTime();
       
   396     // Get the local time from the unviversal time.
       
   397     TLocale locale;
       
   398     lastOperationTime += locale.UniversalTimeOffset();
       
   399     
       
   400     if ( lastOperationTime - locale.UniversalTimeOffset() == 0 )
       
   401         {
       
   402         // Because the origianal universal operation time was zero, the given time
       
   403         // is not correct. Set the time string empty. So, we will not give wrong information.
       
   404         tmpDes.Copy( KNullDesC() );
       
   405         }
       
   406     else if ( currentTime.DayNoInYear() != lastOperationTime.DayNoInYear()
       
   407          || currentTime.DaysFrom( lastOperationTime ).Int() > 0 )
       
   408         {
       
   409         // Day has changed.
       
   410         // Just to be sure, other checking is done because year may have also changed.
       
   411         lastOperationTime.FormatL( tmpDes, KDateFormat() );       
       
   412         }
       
   413     else
       
   414         {
       
   415         // Same day
       
   416         lastOperationTime.FormatL( tmpDes, KTimeFormat() );       
       
   417         }      
       
   418     
       
   419     if ( errorCode == KErrNoMemory )
       
   420         {
       
   421         // Last operation could not be completed because we were out of memory.
       
   422         // Show this error text.
       
   423         stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_UPDATE_NO_MEMORY,
       
   424                                                  *timeDes ); 
       
   425         }
       
   426     else 
       
   427         {
       
   428         switch( state )
       
   429             {
       
   430             case MIAUpdateHistoryItem::EInstalled:
       
   431                 if ( errorCode == KErrNone )
       
   432                     {
       
   433                     // Because item is installed successfully, everything has gone ok.
       
   434                     stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_UPDATE_SUCCESSFULL,
       
   435                                                              *timeDes );                    
       
   436                     }
       
   437                 else if ( errorCode == KErrCancel )
       
   438                     {
       
   439                     // For some reason, the state says that an item has been installed,
       
   440                     // but the error code is cancel. In this case, trust the error code.
       
   441                     stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_CANCELLED,
       
   442                                                              *timeDes );
       
   443                     }
       
   444                 else
       
   445                     {
       
   446                     // If everything goes ok, then the item should be installed.
       
   447                     // So, something has gone wrong because we are here. So,
       
   448                     // give the install failed message
       
   449                     stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_FAILED,
       
   450                                                              *timeDes );
       
   451                     }                
       
   452                 break;
       
   453 
       
   454             case MIAUpdateHistoryItem::EDownloaded:
       
   455                 if ( errorCode == KErrCancel )
       
   456                     {
       
   457                     // Because item has been downloaded but the error code is cancel
       
   458                     // this means that the install has been cancelled
       
   459                     stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_CANCELLED,
       
   460                                                              *timeDes );
       
   461                     }
       
   462                 else
       
   463                     {
       
   464                     // If everything goes ok, then the item should be installed.
       
   465                     // So, something has gone wrong because we are here. So,
       
   466                     // give the install failed message
       
   467                     stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_INSTALL_FAILED,
       
   468                                                              *timeDes );
       
   469                     }
       
   470                 break;
       
   471 
       
   472             case MIAUpdateHistoryItem::EPurchased:
       
   473                 if ( errorCode == KErrCancel )
       
   474                     {
       
   475                     // Because item has been purchased but the error code is cancel
       
   476                     // this means that the download has been cancelled
       
   477                     stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_DOWNLOAD_CANCELLED,
       
   478                                                              *timeDes );
       
   479                     }
       
   480                 else
       
   481                     {
       
   482                     // If everything goes ok, then the item should be installed.
       
   483                     // So, something has gone wrong because we are here. So,
       
   484                     // give the download failed message
       
   485                     stateDescription = StringLoader::LoadLC( R_IAUPDATE_TEXT_DOWNLOAD_FAILED,
       
   486                                                              *timeDes );
       
   487                     }
       
   488                 break;
       
   489                                 
       
   490             default:
       
   491                 // We should never come here.
       
   492                 stateDescription = KNullDesC().AllocLC();
       
   493                 break;
       
   494             }        
       
   495         }
       
   496    
       
   497     CleanupStack::Pop( stateDescription );
       
   498     CleanupStack::PopAndDestroy( timeDes );
       
   499     CleanupStack::PushL( stateDescription );
       
   500          
       
   501     return stateDescription;
       
   502     }
       
   503 
       
   504