iaupdate/IAD/ui/src/iaupdateuicontroller.cpp
changeset 0 ba25891c3a9e
child 9 51c0f5edf5ef
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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 CIAUpdateUiController
       
    15 *                class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include <avkon.hrh>
       
    23 #include <StringLoader.h> 
       
    24 #include <centralrepository.h>
       
    25 #include <AknUtils.h>
       
    26 #include <SWInstDefs.h>
       
    27 #include <avkon.rsg>
       
    28 #include <featurecontrol.h>
       
    29 #include <iaupdate.rsg>
       
    30 #include <iaupdateparameters.h>
       
    31 
       
    32 #include "iaupdateuicontroller.h"
       
    33 #include "iaupdateuicontrollerobserver.h"
       
    34 #include "iaupdateappui.h"
       
    35 #include "iaupdate.hrh"
       
    36 #include "iaupdatewaitdialog.h"
       
    37 #include "iaupdateprogressdialog.h"
       
    38 #include "iaupdatenode.h"
       
    39 #include "iaupdatefwnode.h"
       
    40 #include "iaupdatebasenode.h"
       
    41 #include "iaupdatenodefilter.h"
       
    42 #include "iaupdatefactory.h"
       
    43 #include "iaupdatestarter.h"
       
    44 #include "iaupdateprivatecrkeys.h"
       
    45 #include "iaupdatecontrollerfile.h"
       
    46 #include "iaupdateuiconfigdata.h"
       
    47 #include "iaupdatedialogutil.h"
       
    48 #include "iaupdateutils.h"
       
    49 #include "iaupdateagreement.h"
       
    50 #include "iaupdateautomaticcheck.h"
       
    51 #include "iaupdateroaminghandler.h"
       
    52 #include "iaupdatependingnodesfile.h"
       
    53 #include "iaupdaterestartinfo.h"
       
    54 #include "iaupdaterresultsfile.h"
       
    55 #include "iaupdaterresult.h"
       
    56 #include "iaupdateridentifier.h"
       
    57 #include "iaupdateruids.h"
       
    58 #include "iaupdaterdefs.h"
       
    59 #include "iaupdatetools.h"
       
    60 #include "iaupdateparametersfilemanager.h"
       
    61 #include "iaupdateerrorcodes.h"
       
    62 #include "iaupdatefileconsts.h"
       
    63 #include "iaupdatefirsttimeinfo.h"
       
    64 #include "iaupdaterefreshhandler.h"
       
    65 #include "iaupdatedebug.h"
       
    66 
       
    67 
       
    68 // cenrep in emulator:
       
    69 // copy 2000F85A.txt to '\epoc32\release\winscw\udeb\Z\private\10202be9\'
       
    70 // delete 2000F85A.txt from 'epoc32\winscw\c\private\10202be9\persists'
       
    71 //
       
    72 // cenrep in hardware:
       
    73 // copy 2000F85A.txt to '\epoc32\data\Z\private\10202be9'
       
    74 //
       
    75 
       
    76 
       
    77 // This is a static function that is used with RPointerArray::Sort to sort
       
    78 // the nodes according to their node depths and other special values.
       
    79 TInt SortSelectedNodes( const MIAUpdateNode& aNode1, const MIAUpdateNode& aNode2 )
       
    80     {
       
    81     // Temporarily use the const_cast here to get the base node.
       
    82     // After that, base node is set back to const. So, the casting here
       
    83     // is safe to do.
       
    84     const MIAUpdateBaseNode& baseNode1( 
       
    85         const_cast< MIAUpdateNode& >( aNode1 ).Base() );
       
    86     const MIAUpdateBaseNode& baseNode2( 
       
    87         const_cast< MIAUpdateNode& >( aNode2 ).Base() );
       
    88 
       
    89     if ( baseNode1.Uid().iUid == KIAUpdaterUid
       
    90          && baseNode2.Uid().iUid != KIAUpdaterUid )
       
    91         {
       
    92         // Self updater should always be the first one
       
    93         // in the node array.
       
    94         return -1;
       
    95         }
       
    96     else if ( baseNode2.Uid().iUid == KIAUpdaterUid
       
    97               && baseNode1.Uid().iUid != KIAUpdaterUid )
       
    98         {
       
    99         // Self updater should always be the first one
       
   100         // in the node array.
       
   101         return 1;
       
   102         }
       
   103     else if ( aNode1.IsSelfUpdate() && !aNode2.IsSelfUpdate() )
       
   104         {
       
   105         // Self updates always before normal nodes.
       
   106         return -1;
       
   107         }
       
   108     else if ( !aNode1.IsSelfUpdate() && aNode2.IsSelfUpdate() )
       
   109         {
       
   110         // Self updates always before normal nodes.
       
   111         return 1;
       
   112         }
       
   113     else
       
   114         {
       
   115         // The depth can be used in normal cases to make sure that dependency
       
   116         // nodes are handled before their dependants. Notice, that this is
       
   117         // a safe way even if dependency chain contains hidden nodes.
       
   118         // The dependency nodes should be before its dependants in the array.
       
   119         // The depth value informs how deep in the dependency hierarchy the node is.
       
   120         // A depth value zero means that the node is a root. If multiple branches lead to
       
   121         // a same node, then the greatest depth value is used for the node.
       
   122         // The node can not ever depend on the node that has the same or greater depth.
       
   123 
       
   124         TInt depthDiff( aNode2.Depth() - aNode1.Depth() );
       
   125 
       
   126         if ( depthDiff != 0 )
       
   127             {
       
   128             // Depths were different.
       
   129             // In some cases, the user may have chosen a dependency node only
       
   130             // and left the dependant out. Then this node may be moved unnecessarily
       
   131             // in the array. But because dependecies may change the selection order
       
   132             // usually quite much, the possible unnecessary movement here should not
       
   133             // matter. Notice, that using the depth values is really safe way to make
       
   134             // sure the dependency nodes are handled before their dependants.
       
   135             return depthDiff;
       
   136             }
       
   137         else
       
   138             {
       
   139             // Because depthDiffs equal we need to do some additional checking.
       
   140             // This kind of comparison is also used in the filter.
       
   141             // See: CIAUpdateNodeFilter::CompareAndMarkFilterNodes
       
   142             TInt importanceDiff( 
       
   143                 baseNode2.Importance() - baseNode1.Importance() );
       
   144             if ( importanceDiff != 0 )
       
   145                 {
       
   146                 // Sort according to the importance because importances
       
   147                 // differ.
       
   148                 return importanceDiff;
       
   149                 }
       
   150             else
       
   151                 {
       
   152                 // Because evertyhing else matched, we finally check
       
   153                 // the name. Items should be handled in alphabetical order
       
   154                 // now.
       
   155                 return baseNode1.Name().CompareC( baseNode2.Name() );
       
   156                 }
       
   157             }
       
   158         }
       
   159     }
       
   160 
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CIAUpdateUiController::NewLC
       
   164 // Two-phased constructor.
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 CIAUpdateUiController* CIAUpdateUiController::NewLC( 
       
   168     MIAUpdateUiControllerObserver& aObserver )
       
   169     {
       
   170     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::NewLC() begin");
       
   171     CIAUpdateUiController* self = 
       
   172         new( ELeave ) CIAUpdateUiController( aObserver );
       
   173     CleanupStack::PushL( self );
       
   174     self->ConstructL();
       
   175     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::NewLC() end");
       
   176     return self;
       
   177     }
       
   178 
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CIAUpdateUiController::NewL
       
   182 // Two-phased constructor.
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 CIAUpdateUiController* CIAUpdateUiController::NewL( 
       
   186     MIAUpdateUiControllerObserver& aObserver )
       
   187     {
       
   188     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::NewL() begin");
       
   189     CIAUpdateUiController* self = 
       
   190         CIAUpdateUiController::NewLC( aObserver );
       
   191     CleanupStack::Pop( self );
       
   192     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::NewL() end");
       
   193     return self;
       
   194     }
       
   195 
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CIAUpdateUiController::CIAUpdateUiController
       
   199 // C++ constructor
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 CIAUpdateUiController::CIAUpdateUiController( 
       
   203     MIAUpdateUiControllerObserver& aObserver )
       
   204 : iObserver( aObserver ),
       
   205   iState( EIdle )
       
   206     {    
       
   207     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CIAUpdateUiController()");
       
   208     iEikEnv = CEikonEnv::Static();
       
   209     }
       
   210 
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CIAUpdateUiController::ConstructL
       
   214 // 
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CIAUpdateUiController::ConstructL()
       
   218     {    
       
   219     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ConstructL() begin");
       
   220         
       
   221     iClosingAllowedByClient = ETrue;
       
   222     iController = 
       
   223         IAUpdateFactory::CreateControllerL( 
       
   224             TUid::Uid( KIAUpdateFamilyUid ), *this );
       
   225     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ConstructL() 1");
       
   226     iFilter = CIAUpdateNodeFilter::NewL();
       
   227     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ConstructL() 2");
       
   228 
       
   229     // Notice, this will read the init values from the file
       
   230     // if the file exists. Otherwise, default values are used.
       
   231     iControllerFile = 
       
   232         CIAUpdateControllerFile::NewL( IAUpdateFileConsts::KControllerFile );
       
   233     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ConstructL() 3");
       
   234     
       
   235     iConfigData = CIAUpdateUiConfigData::NewL();
       
   236     
       
   237     iOffConfigurated = !IAUpdateEnabledL();
       
   238 
       
   239     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ConstructL() end");   
       
   240     }
       
   241 
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CIAUpdateUiController::~CIAUpdateUiController
       
   245 // Destructor
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 CIAUpdateUiController::~CIAUpdateUiController()
       
   249     {    
       
   250     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::~CIAUpdateUiController() begin");
       
   251 
       
   252     CancelOperation();
       
   253     delete iController;
       
   254     iNodes.Reset();
       
   255     iFwNodes.Reset();
       
   256     iSelectedNodesArray.Reset();
       
   257     iServicePackNodes.Reset();
       
   258     delete iFilter;
       
   259     delete iControllerFile;
       
   260     delete iIdle;
       
   261     delete iStarter;
       
   262     delete iConfigData;
       
   263     delete iRoamingHandler;
       
   264     delete iParams;
       
   265     delete iRefreshHandler;
       
   266     delete iPreviousSelections;
       
   267 
       
   268     // If dialogs have not been released yet, release them now.
       
   269     // ProcessFinishedL() should normally be used for dialogs but
       
   270     // here just use non-leaving delete. In normal cases, dialogs should
       
   271     // already be released in the end of the update flow before coming here.
       
   272     delete iWaitDialog;
       
   273     delete iProgressDialog;
       
   274         
       
   275 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::~CIAUpdateUiController() end");
       
   276     }        
       
   277 
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CIAUpdateUiController::ConfigData
       
   281 // Returns the configuration data from the config file.
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 const CIAUpdateUiConfigData& CIAUpdateUiController::ConfigData() const
       
   285     {
       
   286     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ConfigData()");
       
   287     return *iConfigData;
       
   288     }
       
   289 
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // CIAUpdateUiController::SetDefaultConnectionMethodL
       
   293 // Sets the connection method for the update network connection.
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CIAUpdateUiController::SetDefaultConnectionMethodL( const TIAUpdateConnectionMethod& aMethod )
       
   297     {
       
   298     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::SetDefaultConnectionMethodL() begin");
       
   299 
       
   300     iController->SetDefaultConnectionMethodL( aMethod );
       
   301 
       
   302     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::SetDefaultConnectionMethodL() end"); 
       
   303     }
       
   304 
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // CIAUpdateUiController::CheckUpdatesL
       
   308 // Updates the update item list.
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 void CIAUpdateUiController::CheckUpdatesL()
       
   312     {
       
   313     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CheckUpdatesL() begin");
       
   314 
       
   315     iCountOfAvailableUpdates = 0;
       
   316     
       
   317     if ( iParams )
       
   318         {
       
   319     	iFilter->SetFilterParams( iParams ); //iParams ownership is changed
       
   320     	iParams = NULL;
       
   321         }
       
   322      
       
   323     TBool agreementAccepted( EFalse ); 
       
   324     CIAUpdateAgreement* agreement = CIAUpdateAgreement::NewLC();
       
   325     agreementAccepted = agreement->AgreementAcceptedL();
       
   326     if ( ( !agreementAccepted )&& ( iRequestType != IAUpdateUiDefines::ECheckUpdates ) )
       
   327         {
       
   328         // agreement (disclaimer) dialog is not prompted when CheckUpdates is called
       
   329         //
       
   330         // Refresh from network is allowed when first time case 
       
   331         iRefreshFromNetworkDenied = EFalse;
       
   332     	agreementAccepted = agreement->AcceptAgreementL();	
       
   333         }
       
   334         	
       
   335     CleanupStack::PopAndDestroy( agreement );
       
   336              
       
   337     if ( !agreementAccepted )
       
   338         {
       
   339         if ( iRequestType == IAUpdateUiDefines::ECheckUpdates )
       
   340             {
       
   341             CIAUpdateAutomaticCheck* automaticCheck = CIAUpdateAutomaticCheck::NewLC();
       
   342             TBool autoUpdateCheckEnabled = automaticCheck->AutoUpdateCheckEnabledL();
       
   343             CleanupStack::PopAndDestroy( automaticCheck );
       
   344             if ( !autoUpdateCheckEnabled )
       
   345                 {
       
   346                 iObserver.RefreshCompleteL( ETrue, KErrNone );
       
   347                 return;
       
   348                 }
       
   349             }
       
   350         else if ( iRequestType == IAUpdateUiDefines::EShowUpdates )
       
   351             {
       
   352        	    iObserver.UpdateCompleteL( KErrNone ); 
       
   353        	    return;
       
   354        	    }
       
   355        	else
       
   356        	    {
       
   357        	    CIAUpdateAppUi* appUi = 
       
   358        	            static_cast< CIAUpdateAppUi* >( iEikEnv->EikAppUi() );
       
   359             appUi->Exit();
       
   360        	    return;	
       
   361        	    }
       
   362         }
       
   363             
       
   364     if ( iRequestType == IAUpdateUiDefines::EShowUpdates && iRefreshed )
       
   365         {
       
   366     	iFilter->FilterAndSortNodesL( iNodes, iFwNodes );
       
   367         iObserver.RefreshCompleteL( ETrue, KErrNone );
       
   368         }
       
   369     else
       
   370         {
       
   371         if ( IsStartedByLauncher() && AllowNetworkRefreshL() )
       
   372             {
       
   373         	iUserRoamingRejection = iRoamingHandler->RoamingRejectionL();
       
   374             }
       
   375 
       
   376         TInt ret( iController->Startup() );
       
   377         if ( ret == KErrAlreadyExists )   
       
   378             {
       
   379             IAUPDATE_TRACE("[IAUPDATE] Controller startup already done.");
       
   380             // Controller startup has already been done. 
       
   381             // So, no operation was started from the controller. 
       
   382             // So, call StartupComplete directly from here. 
       
   383     	    StartupComplete( KErrNone );
       
   384             }
       
   385         else
       
   386             {
       
   387             IAUPDATE_TRACE_1("[IAUPDATE] Controller startup error code: %d", ret);
       
   388             // Something went wrong with controller startup if error code is not
       
   389             // KErrNone here. Above, KErrAlreadyExists was handled separately.
       
   390             // If ret is KErrInUse, then startup was still going on
       
   391             // and new startup should not be called. Also, leave in that case.
       
   392             User::LeaveIfError( ret );	
       
   393             }	
       
   394         }
       
   395 
       
   396     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CheckUpdatesL() end");
       
   397     }
       
   398 
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // CIAUpdateUiController::StartUpdateL
       
   402 // Starts software updating
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 void CIAUpdateUiController::StartUpdateL()
       
   406     {
       
   407     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartUpdateL() begin");
       
   408 
       
   409     // Just to be sure that self update related information
       
   410     // is always in resetted state when new update flows are
       
   411     // started.
       
   412     iController->ResetSelfUpdate();
       
   413 
       
   414     iUserRoamingRejection = iRoamingHandler->RoamingRejectionL();
       
   415     if ( !iUserRoamingRejection )
       
   416         {
       
   417         CreateSelectedNodesArrayL();
       
   418                 
       
   419         if ( !IAUpdateUtils::SpaceAvailableInInternalDrivesL( iSelectedNodesArray ) )
       
   420             {
       
   421     	    HBufC* noteText = NULL;
       
   422             noteText = StringLoader::LoadLC( R_IAUPDATE_INSUFFICIENT_MEMORY );
       
   423             IAUpdateDialogUtil::ShowInformationQueryL( *noteText ); 
       
   424             CleanupStack::PopAndDestroy( noteText );
       
   425             }
       
   426         else
       
   427             {
       
   428             if ( !IsStartedByLauncher() )
       
   429                 {
       
   430                 if ( !iStarter )
       
   431                     {
       
   432                     // Notice, that the ownership of the filter parameters will
       
   433                     // remain in the filter.
       
   434                     CIAUpdateParameters* params = iFilter->FilterParams();
       
   435         	        iStarter = CIAUpdateStarter::NewL( params->CommandLineExecutable(), 
       
   436         	                                           params->CommandLineArguments() );
       
   437                     }
       
   438                 }
       
   439             // Inform the controller that we are now starting updates. This way the
       
   440             // controller can handle situations as a whole and not as one item at the
       
   441             // time.
       
   442             iController->StartingUpdatesL();
       
   443             
       
   444             iFileInUseError = EFalse;
       
   445             // Set the node index to -1 because ContinueUpdateL increases it by one
       
   446             // in the beginning of the function. So, we can use the ContinueUpdateL
       
   447             // also in here.
       
   448             iNodeIndex = -1;
       
   449             ContinueUpdateL( EFalse );
       
   450             }
       
   451         }
       
   452 
       
   453 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartUpdateL() end");
       
   454     }
       
   455 
       
   456   
       
   457 // ---------------------------------------------------------------------------
       
   458 // CIAUpdateUiController::ContinueUpdateL
       
   459 // Continues software updating from the next node
       
   460 // ---------------------------------------------------------------------------
       
   461 //
       
   462 void CIAUpdateUiController::ContinueUpdateL( TBool aSelfUpdateFinished )
       
   463     {
       
   464     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateUiController::ContinueUpdateL() begin: %d",
       
   465                    aSelfUpdateFinished );
       
   466     
       
   467     // Get the node index of the next node.
       
   468     // The node that is indexed by iNodeIndex has already been handled in
       
   469     // previous loop. So, increase the temp index by one here as it will be done
       
   470     // in the while loop below for real index.
       
   471     TInt tmpIndex( iNodeIndex + 1 );
       
   472     if ( tmpIndex > 0 
       
   473         && tmpIndex < iSelectedNodesArray.Count()
       
   474         && iSelectedNodesArray[ tmpIndex - 1 ]->IsSelfUpdate()
       
   475         && !iSelectedNodesArray[ tmpIndex ]->IsSelfUpdate()
       
   476         && !aSelfUpdateFinished
       
   477         && iController->SelfUpdateDataExists() )
       
   478         {
       
   479         IAUPDATE_TRACE_1("[IAUPDATE] Self updates have been handled now: %d",
       
   480                          iNodeIndex);
       
   481         // Self update should be started now because
       
   482         // current node is not anymore self update and previous nodes were.
       
   483         // UpdateCompleteL will start the self updater and inform observers.
       
   484         // If no self update data can be found, then there has been some error
       
   485         // when self update data has been set. So, then there is no reason to start
       
   486         // self updater here. In that case, continue normally in the while loop below if
       
   487         // other items are waiting for update.
       
   488         iNodeIndex++;
       
   489         UpdateCompleteL( KErrNone );
       
   490 
       
   491         // Do not continue after this.
       
   492         return;
       
   493         }
       
   494 
       
   495     TBool nextUpdate( ETrue );
       
   496     while ( nextUpdate )
       
   497        {
       
   498        IAUPDATE_TRACE_1("[IAUPDATE] Next update while loop: %d",
       
   499                         iNodeIndex);
       
   500        iNodeIndex++;
       
   501        if ( iNodeIndex < iSelectedNodesArray.Count() )
       
   502             {
       
   503             MIAUpdateNode* selectedNode = iSelectedNodesArray[ iNodeIndex ];
       
   504 
       
   505             // Only update items that have not been installed yet.
       
   506             if ( !selectedNode->IsInstalled() )
       
   507                 {
       
   508                 IAUPDATE_TRACE("[IAUPDATE] Item not installed yet");    
       
   509                 if ( !selectedNode->IsDownloaded() )
       
   510                     {
       
   511                     // Because content has not been downloaded or installed yet,
       
   512                     // it needs to be downloaded before it can be installed.
       
   513                     IAUPDATE_TRACE("[IAUPDATE] Download");
       
   514                     selectedNode->DownloadL( *this );
       
   515                     iState = EDownloading;
       
   516                     iClosingAllowedByClient = ETrue;
       
   517                     ShowUpdatingDialogL( R_IAUPDATE_DOWNLOADING_NOTE,
       
   518                                          selectedNode->Base().Name(),
       
   519                                          iNodeIndex + 1,
       
   520                                          iSelectedNodesArray.Count() ); 
       
   521                     nextUpdate = EFalse;
       
   522                     }
       
   523                 else
       
   524                     {
       
   525                     // Because content has been downloaded but not installed yet,
       
   526                     // it needs to be installed now.
       
   527                     IAUPDATE_TRACE("[IAUPDATE] Install");
       
   528                     selectedNode->InstallL( *this );
       
   529                     iState = EInstalling;
       
   530                     iClosingAllowedByClient = EFalse;
       
   531                     CIAUpdateAppUi* appUi = 
       
   532                         static_cast< CIAUpdateAppUi* >( iEikEnv->EikAppUi() );
       
   533                     appUi->StartWGListChangeMonitoring();
       
   534                     ShowUpdatingDialogL( R_IAUPDATE_INSTALLING_NOTE,
       
   535                                          selectedNode->Base().Name(),
       
   536                                          iNodeIndex + 1,
       
   537                                          iSelectedNodesArray.Count() ); 
       
   538                     nextUpdate = EFalse;                     
       
   539                     }      
       
   540                 }
       
   541             }
       
   542         else
       
   543             {
       
   544             IAUPDATE_TRACE("[IAUPDATE] Update flow complete");
       
   545             nextUpdate = EFalse;
       
   546             UpdateCompleteL( KErrNone );	
       
   547             }
       
   548         }
       
   549 
       
   550     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ContinueUpdateL() end");
       
   551     }
       
   552    
       
   553 
       
   554 // ---------------------------------------------------------------------------
       
   555 // CIAUpdateUiController::StartInstallL
       
   556 // Starts software installing
       
   557 // ---------------------------------------------------------------------------
       
   558 //    
       
   559 void CIAUpdateUiController::StartInstallL( MIAUpdateNode& aNode )   
       
   560     {
       
   561     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartInstallL() begin");
       
   562    
       
   563     if ( aNode.Type() == MIAUpdateNode::EPackageTypeServicePack )
       
   564         {
       
   565         iServicePackNodes.Reset();
       
   566         aNode.GetDependenciesL( iServicePackNodes, ETrue );
       
   567         }
       
   568             
       
   569     aNode.InstallL( *this );
       
   570     iState = EInstalling;
       
   571     CIAUpdateAppUi* appUi = static_cast<CIAUpdateAppUi*>( iEikEnv->EikAppUi() );
       
   572     appUi->StartWGListChangeMonitoring();
       
   573     iClosingAllowedByClient = EFalse;
       
   574     ShowUpdatingDialogL( R_IAUPDATE_INSTALLING_NOTE,
       
   575                          aNode.Base().Name(),
       
   576                          iNodeIndex + 1,
       
   577                          iSelectedNodesArray.Count()  );
       
   578     
       
   579 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartInstallL() end");
       
   580     }
       
   581 
       
   582     
       
   583 // ---------------------------------------------------------------------------
       
   584 // CIAUpdateUiController::StartRefreshL()
       
   585 // Starts meta data refresh
       
   586 // ---------------------------------------------------------------------------
       
   587 // 
       
   588 void CIAUpdateUiController::StartRefreshL()
       
   589     {
       
   590     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartRefreshL() begin");
       
   591     
       
   592     iCountOfAvailableUpdates = 0;
       
   593     iClosingAllowedByClient = ETrue;
       
   594     if ( iOffConfigurated  )
       
   595         {
       
   596         iObserver.RefreshCompleteL( ETrue, KErrNone );
       
   597         }
       
   598     else
       
   599         {
       
   600         iState = ERefreshing;    
       
   601         TBool allowNetworkRefresh = AllowNetworkRefreshL();
       
   602         iSelectedNodesArray.Reset();
       
   603         iController->StartRefreshL( allowNetworkRefresh );
       
   604             
       
   605         if ( iRequestType == IAUpdateUiDefines::ECheckUpdates && iFilter->FilterParams() )
       
   606             {
       
   607             if ( iFilter->FilterParams()->ShowProgress() )
       
   608                 {
       
   609                 // to avoid flickering IAD is brought to foreground only when wait dialog is really shown
       
   610                 if ( allowNetworkRefresh )
       
   611                     {
       
   612                     iEikEnv->RootWin().SetOrdinalPosition( 0, ECoeWinPriorityNormal );
       
   613                     HBufC* noteText = StringLoader::LoadLC( R_IAUPDATE_REFRESHING_UPDATE_LIST );
       
   614                     ShowWaitDialogL( *noteText, ETrue );
       
   615                     CleanupStack::PopAndDestroy( noteText );
       
   616                     }
       
   617                 }
       
   618             }
       
   619         else
       
   620             {
       
   621             HBufC* noteText = StringLoader::LoadLC( R_IAUPDATE_REFRESHING_UPDATE_LIST );
       
   622             ShowWaitDialogL( *noteText, EFalse );
       
   623             CleanupStack::PopAndDestroy( noteText );
       
   624             }
       
   625         }
       
   626     
       
   627        
       
   628 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartRefreshL() end");
       
   629     }
       
   630  
       
   631    
       
   632 // ---------------------------------------------------------------------------
       
   633 // CIAUpdateUiController::Nodes
       
   634 // 
       
   635 // ---------------------------------------------------------------------------
       
   636 //     
       
   637 const RPointerArray< MIAUpdateNode >& CIAUpdateUiController::Nodes() const
       
   638     {
       
   639     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::Nodes()");
       
   640     return iNodes;
       
   641     }
       
   642 
       
   643 
       
   644 // ---------------------------------------------------------------------------
       
   645 // CIAUpdateUiController::FwNodes
       
   646 // 
       
   647 // ---------------------------------------------------------------------------
       
   648 //     
       
   649 const RPointerArray<MIAUpdateFwNode>& CIAUpdateUiController::FwNodes() const
       
   650     {
       
   651     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::FwNodes()");
       
   652     return iFwNodes;
       
   653     }
       
   654 
       
   655 
       
   656 // ---------------------------------------------------------------------------
       
   657 // CIAUpdateUiController::HistoryL
       
   658 // 
       
   659 // ---------------------------------------------------------------------------
       
   660 //  
       
   661 MIAUpdateHistory& CIAUpdateUiController::HistoryL()
       
   662     {
       
   663     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::HistoryL()");
       
   664     return iController->HistoryL();
       
   665     }
       
   666 
       
   667 
       
   668 // ---------------------------------------------------------------------------
       
   669 // CIAUpdateUiController::SetRequestType
       
   670 // 
       
   671 // ---------------------------------------------------------------------------
       
   672 void CIAUpdateUiController::SetRequestType( 
       
   673     IAUpdateUiDefines::TIAUpdateUiRequestType aRequestType )
       
   674     {
       
   675     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::SetRequestType() begin");
       
   676     IAUPDATE_TRACE_1("[IAUPDATE] request type: %d", aRequestType );
       
   677 
       
   678     iRequestType = aRequestType;    
       
   679     
       
   680     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::SetRequestType() end");
       
   681     }
       
   682 
       
   683 
       
   684 // ---------------------------------------------------------------------------
       
   685 // CIAUpdateUiController::CancelOperation
       
   686 // 
       
   687 // ---------------------------------------------------------------------------    
       
   688 void CIAUpdateUiController::CancelOperation() 
       
   689     {
       
   690     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CancelOperation() begin");
       
   691 
       
   692     // Set the flag to inform possible callback functions
       
   693     // that operation cancell is going on.
       
   694     iCancelling = ETrue;
       
   695 
       
   696     if ( iIdle )
       
   697         {
       
   698     	iIdle->Cancel();
       
   699         }
       
   700     if ( iStarter )
       
   701         {
       
   702     	iStarter->Cancel();
       
   703         }
       
   704     if ( iRoamingHandler )
       
   705         {
       
   706     	iRoamingHandler->CancelPreparing();
       
   707         }
       
   708     
       
   709 	if ( iState == EDownloading || iState == EInstalling )
       
   710 	    {
       
   711 	    // Current node.
       
   712         MIAUpdateNode* node( iSelectedNodesArray[ iNodeIndex ] );
       
   713 
       
   714         // Cancel the operation of that node.
       
   715     	node->CancelOperation();
       
   716 
       
   717         // Also set the purchase history information to other nodes
       
   718         // even if their operations were not started yet.
       
   719         for ( TInt i = iNodeIndex + 1; i < iSelectedNodesArray.Count(); ++i )
       
   720             {
       
   721             node = iSelectedNodesArray[ i ];
       
   722             if ( MIAUpdateNode::EPackageTypeServicePack == node->Type()
       
   723                   && node->IsInstalled() )
       
   724                 {
       
   725                 IAUPDATE_TRACE("[IAUPDATE] Service pack was completed");
       
   726                 // Even if cancel occurred, some of the nodes inside the
       
   727                 // service pack were installed from some other dependency
       
   728                 // chain way. And, now there is nothing to be installed
       
   729                 // inside the service pack.
       
   730                 TRAP_IGNORE ( node->Base().
       
   731                     SetInstallStatusToPurchaseHistoryL( KErrNone, ETrue ) );
       
   732                 }
       
   733             else
       
   734                 {
       
   735                 IAUPDATE_TRACE("[IAUPDATE] Node cancelled");
       
   736                 // Notice, that this can also still be service pack node.
       
   737                 // Because we are handling nodes that are visible in UI,
       
   738                 // we can force the node as visible in history.
       
   739                 TRAP_IGNORE ( 
       
   740                     node->Base().SetIdleCancelToPurchaseHistoryL( ETrue ) ); 
       
   741                 }
       
   742             }
       
   743 	    }
       
   744     else if ( iState == ERefreshing )
       
   745         {
       
   746         iController->CancelRefresh();
       
   747         }
       
   748 
       
   749     // Just to be sure that self update related information
       
   750     // is always in resetted state when new update flows are
       
   751     // started after operation cancel.
       
   752 	if ( iController )
       
   753 	    {
       
   754 	    iController->ResetSelfUpdate();
       
   755 	    }
       
   756     // After cancellation, the new state is idle.
       
   757     iState = EIdle;
       
   758     iClosingAllowedByClient = ETrue;
       
   759 
       
   760     // Cancelling is over. So, set the flag accrodingly.
       
   761     iCancelling = EFalse;
       
   762 
       
   763     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CancelOperation() end");
       
   764     }
       
   765 
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // CIAUpdateUiController::ResultsInfo
       
   769 // 
       
   770 // ---------------------------------------------------------------------------    
       
   771 TIAUpdateResultsInfo CIAUpdateUiController::ResultsInfo() const
       
   772 	{
       
   773     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ResultsInfo() begin");
       
   774 
       
   775 	TIAUpdateResultsInfo resultsInfo( 0, 0, 0, iFileInUseError, EFalse );
       
   776 	for ( TInt i = 0; i < iSelectedNodesArray.Count(); ++i )
       
   777 	    {
       
   778 	    MIAUpdateNode* node( iSelectedNodesArray[ i ] );
       
   779 	    TInt lastErrorCode( KErrNone );
       
   780 	    TRAPD ( trapError, 
       
   781 	            lastErrorCode = node->Base().LastUpdateErrorCodeL() );
       
   782 	    if ( node->IsInstalled() )
       
   783 	        {
       
   784 	        // Because node is installed, update must have been a success.
       
   785 	        ++resultsInfo.iCountSuccessfull;
       
   786 	        if ( node->Base().RebootAfterInstall() )
       
   787 	            {
       
   788 	            resultsInfo.iRebootAfterInstall = ETrue;
       
   789 	            }
       
   790 	        }
       
   791         else if ( trapError == KErrNone 
       
   792                   && lastErrorCode == KErrCancel )
       
   793             {
       
   794             ++resultsInfo.iCountCancelled;
       
   795             }
       
   796         else
       
   797             {
       
   798             ++resultsInfo.iCountFailed;
       
   799             }
       
   800 	    }
       
   801 	    
       
   802 	IAUPDATE_TRACE_1("[IAUPDATE] Successfull count: %d", resultsInfo.iCountSuccessfull );
       
   803 	IAUPDATE_TRACE_1("[IAUPDATE] Cancelled count: %d", resultsInfo.iCountCancelled );
       
   804 	IAUPDATE_TRACE_1("[IAUPDATE] Failed count: %d", resultsInfo.iCountFailed );
       
   805 	
       
   806     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ResultsInfo() end");
       
   807 
       
   808 	return resultsInfo;
       
   809 	}
       
   810 
       
   811 
       
   812 // ---------------------------------------------------------------------------
       
   813 // CIAUpdateUiController::CountOfAvailableUpdates
       
   814 // 
       
   815 // ---------------------------------------------------------------------------    
       
   816 TInt CIAUpdateUiController::CountOfAvailableUpdates() const
       
   817 	{
       
   818 	IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateUiController::CountOfAvailableUpdates() count: %d",
       
   819                      iCountOfAvailableUpdates );
       
   820 	return iCountOfAvailableUpdates;
       
   821 	}
       
   822 
       
   823 
       
   824 // ---------------------------------------------------------------------------
       
   825 // CIAUpdateUiController::Starter()
       
   826 // 
       
   827 // ---------------------------------------------------------------------------    
       
   828 const CIAUpdateStarter* CIAUpdateUiController::Starter() const
       
   829     {
       
   830     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::Starter()");
       
   831     return iStarter;	
       
   832     }
       
   833 
       
   834 // ---------------------------------------------------------------------------
       
   835 // CIAUpdateUiController::Filter()
       
   836 // 
       
   837 // --------------------------------------------------------------------------- 
       
   838 const CIAUpdateNodeFilter* CIAUpdateUiController::Filter() const
       
   839     {
       
   840     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::Filter()");
       
   841     return iFilter;	
       
   842     }
       
   843 
       
   844 // -----------------------------------------------------------------------------
       
   845 // CIAUpdateUiController::DoCancelIfAllowed
       
   846 // 
       
   847 // -----------------------------------------------------------------------------
       
   848 //
       
   849 TBool CIAUpdateUiController::DoCancelIfAllowed()
       
   850    {
       
   851    IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::DoCancelIfAllowed() begin");
       
   852 
       
   853    if ( iClosingAllowedByClient )
       
   854        {
       
   855    	   CancelOperation();
       
   856        }
       
   857 
       
   858    IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::DoCancelIfAllowed() end");
       
   859 
       
   860    return iClosingAllowedByClient;	
       
   861    }
       
   862 
       
   863 
       
   864 // -----------------------------------------------------------------------------
       
   865 // CIAUpdateUiController::ClosingAllowedByClient
       
   866 // 
       
   867 // -----------------------------------------------------------------------------
       
   868 //  
       
   869  TBool CIAUpdateUiController::ClosingAllowedByClient()
       
   870      {
       
   871      IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ClosingAllowedByClient()");
       
   872      IAUPDATE_TRACE_1("[IAUPDATE] closing allowed: %d", iClosingAllowedByClient );
       
   873      TBool closingAllowed = iClosingAllowedByClient;
       
   874      if ( iRequestType != IAUpdateUiDefines::EShowUpdates )
       
   875          {
       
   876          // iaupdate can be orphaned from its client only when ShowUpdates() was called  
       
   877          closingAllowed = ETrue;
       
   878          }
       
   879  	 return closingAllowed;
       
   880      }
       
   881  	
       
   882 
       
   883 // -----------------------------------------------------------------------------
       
   884 // CIAUpdateUiController::CheckUpdatesDeferredL
       
   885 // 
       
   886 // -----------------------------------------------------------------------------
       
   887 //
       
   888 void CIAUpdateUiController::CheckUpdatesDeferredL( CIAUpdateParameters* aParams, 
       
   889                                                    TBool aRefreshFromNetworkDenied )
       
   890     {
       
   891     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CheckUpdatesDeferredL() begin");
       
   892     
       
   893     iClosingAllowedByClient = ETrue;
       
   894     delete iParams;
       
   895     iParams = aParams; //ownership of parameters is taken
       
   896     iRefreshFromNetworkDenied = aRefreshFromNetworkDenied; 
       
   897     delete iIdle;
       
   898     iIdle = NULL;
       
   899 	iIdle = CIdle::NewL( CActive::EPriorityIdle ); 
       
   900     iIdle->Start( TCallBack( CheckUpdatesDeferredCallbackL, this ) );
       
   901 
       
   902     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CheckUpdatesDeferredL() end");
       
   903     }
       
   904 
       
   905 
       
   906 // -----------------------------------------------------------------------------
       
   907 // CIAUpdateUiController::PrepareRoamingHandlerL
       
   908 // 
       
   909 // -----------------------------------------------------------------------------
       
   910 //
       
   911 void CIAUpdateUiController::PrepareRoamingHandlerL()
       
   912     {
       
   913 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::PrepareRoamingHandlerL() begin");
       
   914 	    
       
   915     if ( !iRoamingHandler )
       
   916         {
       
   917     	iRoamingHandler = CIAUpdateRoamingHandler::NewL();
       
   918         }
       
   919     if ( !iRoamingHandler->Prepared() )
       
   920         {
       
   921     	iRoamingHandler->CancelPreparing();
       
   922     	//async call that will return in RoamingHandlerPrepared()
       
   923     	iRoamingHandler->PrepareL( *this );
       
   924         }
       
   925     else
       
   926         {
       
   927         CheckUpdatesL();	
       
   928         }
       
   929     
       
   930 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::PrepareRoamingHandlerL() end");
       
   931     }
       
   932 
       
   933 
       
   934 
       
   935 // -----------------------------------------------------------------------------
       
   936 // CIAUpdateUiController::HandlePossibleSelfUpdateRestartL
       
   937 // 
       
   938 // -----------------------------------------------------------------------------
       
   939 //
       
   940 TBool CIAUpdateUiController::HandlePossibleSelfUpdateRestartL( TBool aShutdownRequest )
       
   941     {
       
   942     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::HandlePossibleSelfUpdateRestartL() begin");
       
   943     IAUPDATE_TRACE_1("[IAUPDATE] ShutdownRequest: %d", aShutdownRequest );
       
   944 
       
   945     TBool restarted( EFalse );
       
   946 
       
   947     CIAUpdateRestartInfo* info( iController->SelfUpdateRestartInfo() );
       
   948 
       
   949     if ( info )
       
   950         {
       
   951         IAUPDATE_TRACE("[IAUPDATE] Self updater related info available.");
       
   952 
       
   953         CleanupStack::PushL( info );
       
   954 
       
   955         // Delete the unnecessary files because we will still have 
       
   956         // required objects available.
       
   957         // Notice, that if for some reason a leave occurs after this and the
       
   958         // application does not continue the update, then next time the application
       
   959         // is started, update restart is not rehandled any more.
       
   960         info->DeleteFiles();
       
   961 
       
   962         // Get the data for the updater results.            
       
   963         CIAUpdaterResultsFile& results( info->ResultsFile() );
       
   964 
       
   965         // This flag is set if self updater operation was cancelled.
       
   966         TBool selfUpdateCancelled( EFalse );
       
   967 
       
   968         // Because we have restarted the iaupdate after self updating,
       
   969         // also start to gather possible new update flow reports into 
       
   970         // a report bundle. Inform the controller, so the controller 
       
   971         // can handle situations as a whole and not as one item at the
       
   972         // time.
       
   973         iController->StartingUpdatesL();
       
   974 
       
   975         RPointerArray< CIAUpdaterResult >& resultArray( results.Results() );
       
   976         // Because self updater will insert the possible hidden dependencies
       
   977         // before the actual item, start from the beginning of the array to
       
   978         // set the error codes. This way, the main item will be set last and
       
   979         // it will get the latest time for the purchase history.
       
   980         for ( TInt i = 0; i < resultArray.Count(); ++i )
       
   981             {
       
   982             CIAUpdaterResult* result( resultArray[ i ] );
       
   983             
       
   984             if ( result->ErrorCode() == KErrCancel )
       
   985                 {
       
   986                 IAUPDATE_TRACE("[IAUPDATE] Self Updater cancelled"); 
       
   987             	selfUpdateCancelled = ETrue;
       
   988                 }
       
   989 
       
   990             // Because, the self update installation was finished.
       
   991             // Update the purchase history with the correct information.
       
   992             // Notice, that we can just set the purchase history here for
       
   993             // the self updater items. If some of the items were installed,
       
   994             // before self updater items, then their information was already
       
   995             // correctly into the history. Notice, that result nodes may be hidden
       
   996             // nodes that were not initially visible in the UI. So, do not
       
   997             // force the results visible in purchase history.
       
   998             MIAUpdateNode& node( iController->NodeL( result->Identifier() ) );
       
   999             node.Base().
       
  1000                 SetInstallStatusToPurchaseHistoryL( 
       
  1001                     result->ErrorCode(), EFalse );
       
  1002             }
       
  1003 
       
  1004         IAUPDATE_TRACE("[IAUPDATE] Self update info inserted to purchase history."); 
       
  1005 
       
  1006            
       
  1007         // Get the data for the pending node info.
       
  1008         CIAUpdatePendingNodesFile& pendings(
       
  1009             info->PendingNodesFile() );
       
  1010 
       
  1011 
       
  1012         // Because ContinueUpdateL will use the counters and
       
  1013         // node index and iSelectedNodesArray, we set the correponding information
       
  1014         // here. Then, the update operation will continue correctly for the pending
       
  1015         // nodes.
       
  1016             
       
  1017 
       
  1018         // Set the node index to -1 because ContinueUpdateL increases it by one
       
  1019         // in the beginning of the function. So, we can use the ContinueUpdateL
       
  1020         // also in the end of this function to start the actual update process.
       
  1021         iNodeIndex = -1;
       
  1022         iSelectedNodesArray.Reset();
       
  1023         
       
  1024         // Also, reset nodearray nodes as not selected because original parameter
       
  1025         // settings may have been overruled by the user before user started 
       
  1026         // the self update from UI. Correct nodes will be chosen in the for-loops below.
       
  1027         for ( TInt i = 0; i < iNodes.Count(); ++i )
       
  1028             {
       
  1029             MIAUpdateNode& node( *iNodes[ i ] );
       
  1030             node.Base().SetSelected( EFalse );
       
  1031             }
       
  1032         for ( TInt i = 0; i < iFwNodes.Count(); ++i )
       
  1033             {
       
  1034             MIAUpdateFwNode& fwNode( *iFwNodes[ i ] );  
       
  1035             fwNode.Base().SetSelected( EFalse );
       
  1036             }
       
  1037         
       
  1038 
       
  1039         if ( !selfUpdateCancelled )
       
  1040             {
       
  1041             IAUPDATE_TRACE("[IAUPDATE] Self update not cancelled.");
       
  1042 
       
  1043             // Notice, that the ownership of the filter parameters will
       
  1044             // remain in the filter.
       
  1045             CIAUpdateParameters* params( iFilter->FilterParams() );
       
  1046             if ( !IsStartedByLauncher() || params )
       
  1047                 {
       
  1048                 IAUPDATE_TRACE("[IAUPDATE] Self update handling will set parameters.");
       
  1049 
       
  1050                 // Check if IAD was started from the grid or through API.
       
  1051                 // If IAD was started like from the grid but it still has parameters set,
       
  1052                 // then act as it was started through API. Most likely, then the IAD was
       
  1053                 // originally started through API but because of self update IAD was restarted
       
  1054                 // and now it has original parameters set.
       
  1055 
       
  1056                 if ( !iStarter )
       
  1057                     {
       
  1058                     IAUPDATE_TRACE("[IAUPDATE] iStarter not set");
       
  1059             	    iStarter = CIAUpdateStarter::NewL( params->CommandLineExecutable(), 
       
  1060             	                                       params->CommandLineArguments() );
       
  1061                     }
       
  1062                 }
       
  1063             }
       
  1064 
       
  1065         // Get list of nodes that were initially chosen for the flow.
       
  1066         RPointerArray< CIAUpdaterIdentifier >& pendingIdentifiers = 
       
  1067             pendings.PendingNodes();
       
  1068         TInt pendingIdentifiersCount( pendingIdentifiers.Count() );
       
  1069         // Get the index to the node that has not yet been handled.
       
  1070         TInt pendingsIndex( pendings.Index() );
       
  1071         iSelectedNodesArray.ReserveL( pendingIdentifiersCount );
       
  1072         for ( TInt i = 0; i < pendingIdentifiersCount; ++i )
       
  1073             {
       
  1074             CIAUpdaterIdentifier* identifier( pendingIdentifiers[ i ] );
       
  1075             MIAUpdateNode& node( 
       
  1076                 iController->NodeL( *identifier ) );
       
  1077             iSelectedNodesArray.AppendL( &node );
       
  1078 
       
  1079             // Also, set the node as selected because then UI can easily check
       
  1080             // which nodes should be marked when the UI is restarted after selfupdate.
       
  1081             node.Base().SetSelected( ETrue );
       
  1082 
       
  1083             if ( i < pendingsIndex )
       
  1084                 {
       
  1085                 // We come here if index suggests that node has already been handled
       
  1086 
       
  1087                 // Increase the node index. So, it will already point
       
  1088                 // to the correct place. Because, we want to omit these files
       
  1089                 // when list is gone through.
       
  1090                 ++iNodeIndex;
       
  1091 
       
  1092             	if ( iStarter && node.IsInstalled() )
       
  1093             	    {
       
  1094                     IAUPDATE_TRACE("[IAUPDATE] Self update handling will set parameters, node installed");
       
  1095                     // Because application starting parameters may have been given through the
       
  1096                     // API, we need to pass UID of installed package to starter if it exists.
       
  1097                     // Then, the starter will start the given exe in the end of the install flow
       
  1098                     // if at least one file was succesfully installed.
       
  1099             		iStarter->CheckInstalledPackageL( node.Base().Uid() );
       
  1100             	    }
       
  1101                 }
       
  1102             else if ( selfUpdateCancelled )
       
  1103                 {
       
  1104                 IAUPDATE_TRACE("[IAUPDATE] Set idle cancel info to purchase history");
       
  1105                 // Check if self updater actions were cancelled.
       
  1106                 // Set the purchase history information to nodes not handled yet.
       
  1107                 // If visible service pack was changed to hidden during the operation
       
  1108                 // then force the current history info visible. Then the history
       
  1109                 // corresponds the situation that was when operation flow was started.
       
  1110                 // This may occure if some of the items were installed after all.
       
  1111                 // Notice, that here we can think that node was initially visible
       
  1112                 // because all nodes in UI selection list are visible and possible
       
  1113                 // hidden self update nodes have been handled already in the beginning
       
  1114                 // of this for loop.
       
  1115                 if ( MIAUpdateNode::EPackageTypeServicePack == node.Type()
       
  1116                       && node.IsInstalled() )
       
  1117                     {
       
  1118                     IAUPDATE_TRACE("[IAUPDATE] Service pack was completed");
       
  1119                     // Even if cancel occurred, some of the nodes inside the
       
  1120                     // service pack were installed. And, now there is nothing
       
  1121                     // to be installed inside the service pack.
       
  1122                     node.Base().
       
  1123                         SetInstallStatusToPurchaseHistoryL( KErrNone, ETrue );
       
  1124                     }
       
  1125                 else
       
  1126                     {
       
  1127                     IAUPDATE_TRACE("[IAUPDATE] Node cancelled");
       
  1128                     // Notice, that this can also still be service pack node.
       
  1129                     // Because we are handling nodes that are visible in UI,
       
  1130                     // we can force the node as visible in history.
       
  1131                     node.Base().SetIdleCancelToPurchaseHistoryL( ETrue ); 
       
  1132                     }
       
  1133                 }
       
  1134             else if ( MIAUpdateNode::EPackageTypeServicePack == node.Type()
       
  1135                       && node.IsInstalled() )
       
  1136                 {
       
  1137                 IAUPDATE_TRACE("[IAUPDATE] Service pack has become installed");
       
  1138                 // Because service pack has become installed during self update
       
  1139                 // it means that the service pack was originally missing only
       
  1140                 // the selfupdate. Set, the service pack as installed also into
       
  1141                 // purchase history because no other operation will be done to
       
  1142                 // it after this. Notice, that because service pack was originally
       
  1143                 // in the list, it has been visible for UI. So, make sure that it
       
  1144                 // is also visible in history. IAD Engine will set service packs
       
  1145                 // whose all content is installed as hidden. Therefore, force the
       
  1146                 // visibility here.
       
  1147                 // Notice, that here we can think that node was initially visible
       
  1148                 // because all nodes in UI selection list are visible and possible
       
  1149                 // hidden self update nodes have been handled already in the beginning
       
  1150                 // of this for loop.
       
  1151                 node.Base().
       
  1152                     SetInstallStatusToPurchaseHistoryL( KErrNone, ETrue );
       
  1153                 }
       
  1154             }
       
  1155 
       
  1156         // Info is not needed any more. 
       
  1157         // So, delete it before update flow will be continued below 
       
  1158         // if necessary.
       
  1159         CleanupStack::PopAndDestroy( info );
       
  1160 
       
  1161         // Check if self updater actions was closed by using red key.
       
  1162         // If so, then do not continue update flow here. 
       
  1163         // Instead, this application should be closed.
       
  1164         if ( !aShutdownRequest )
       
  1165             {
       
  1166             IAUPDATE_TRACE("[IAUPDATE] Self update not closed with red key.");            
       
  1167             if ( selfUpdateCancelled )
       
  1168                 {
       
  1169                 IAUPDATE_TRACE("[IAUPDATE] Self update cancelled.");
       
  1170                 // Because self update is cancelled, do not continue here either.
       
  1171                 // Instead end the update flow directly.
       
  1172                 UpdateCompleteL( KErrCancel );
       
  1173                 }
       
  1174             else
       
  1175                 {
       
  1176                 IAUPDATE_TRACE("[IAUPDATE] Self update finished, continue udpate.");
       
  1177                 // Continue udpate normally.
       
  1178                 ContinueUpdateL( ETrue );                
       
  1179                 }
       
  1180             }
       
  1181         else
       
  1182             {
       
  1183             IAUPDATE_TRACE("[IAUPDATE] Self update closed with red key. Handle dialogs.");
       
  1184             // Because shutdown was requested, we do not continue the update flow.
       
  1185             // A updating dialog may still show. So, release it here.
       
  1186             RemoveUpdatingDialogsL();
       
  1187             }
       
  1188 
       
  1189         // Self updater provided some data that was handeld above.
       
  1190         restarted = ETrue;
       
  1191         }
       
  1192 
       
  1193     IAUPDATE_TRACE_1("[IAUPDATE] restarted: %d", restarted );   
       
  1194     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::HandlePossibleSelfUpdateRestartL() end");
       
  1195 
       
  1196     return restarted;
       
  1197     }
       
  1198 
       
  1199 
       
  1200 // -----------------------------------------------------------------------------
       
  1201 // CIAUpdateUiController::TestRole
       
  1202 // 
       
  1203 // -----------------------------------------------------------------------------
       
  1204 //
       
  1205 TBool CIAUpdateUiController::TestRole() const 
       
  1206     {
       
  1207     return iTestRole;	
       
  1208     }
       
  1209 
       
  1210 
       
  1211 // -----------------------------------------------------------------------------
       
  1212 // CIAUpdateUiController::RefreshComplete
       
  1213 // 
       
  1214 // -----------------------------------------------------------------------------
       
  1215 //                            
       
  1216 void CIAUpdateUiController::RefreshComplete( 
       
  1217     const RPointerArray< MIAUpdateAnyNode >& aNodes,
       
  1218     TInt aError )
       
  1219     {
       
  1220     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RefreshComplete() begin");
       
  1221     TInt completionError = KErrNone;
       
  1222     if ( iState == EUiRefreshing )
       
  1223         {
       
  1224     	iState = EIdle;
       
  1225     	TRAP( completionError, RefreshUiCompleteL( aNodes, aError ) );
       
  1226         }
       
  1227     else
       
  1228         {
       
  1229         iState = EIdle;
       
  1230         TRAP ( completionError, RemoveWaitDialogL() );
       
  1231         if ( completionError == KErrNone )
       
  1232             {
       
  1233     	    TRAP( completionError, RefreshCompleteL( aNodes, aError ) );
       
  1234             }	
       
  1235         }
       
  1236     if ( completionError == KErrNone )
       
  1237         {
       
  1238         iRefreshed = ETrue;
       
  1239         }
       
  1240     else
       
  1241         {
       
  1242         iObserver.HandleLeaveErrorWithoutLeave( completionError );
       
  1243         }
       
  1244     
       
  1245     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RefreshComplete() end");
       
  1246     }
       
  1247 
       
  1248 
       
  1249 // -----------------------------------------------------------------------------
       
  1250 // CIAUpdateUiController::SelfUpdaterComplete
       
  1251 // 
       
  1252 // -----------------------------------------------------------------------------
       
  1253 //                            
       
  1254 void CIAUpdateUiController::SelfUpdaterComplete( TInt aErrorCode )
       
  1255     {
       
  1256     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::SelfUpdaterComplete() begin");
       
  1257     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aErrorCode );
       
  1258 
       
  1259     // Self updater completed its job.
       
  1260     // Normally we should not come here because self update should shut down this
       
  1261     // application before installation. But, now because we came here, complete
       
  1262     // the update operation.
       
  1263 
       
  1264     // Remove params file if it exists. This is a temporary file that would be
       
  1265     // otherwise read during next grid start if not removed here. There is no need
       
  1266     // to use that file now, because all the necessary parameters are already set
       
  1267     // because restart of IAD did not occur.
       
  1268     
       
  1269     iState = EIdle;
       
  1270     TRAP_IGNORE ( ParamsRemoveFileL() );
       
  1271 
       
  1272     TInt err( KErrNone );
       
  1273     TBool restartDataWasAvailable( EFalse );
       
  1274     TRAP ( err, 
       
  1275            restartDataWasAvailable = 
       
  1276             HandlePossibleSelfUpdateRestartL( 
       
  1277                 aErrorCode == IAUpdaterDefs::KIAUpdaterShutdownRequest ) );
       
  1278     if ( err != KErrNone )
       
  1279         {
       
  1280     	iObserver.HandleLeaveErrorWithoutLeave( err );
       
  1281         }
       
  1282     else if ( !restartDataWasAvailable )
       
  1283         {
       
  1284         IAUPDATE_TRACE("[IAUPDATE] Restart data not available");
       
  1285         // For some reason the self updater was not able to give the restart data.
       
  1286         // So, try to continue the update in a normal way.
       
  1287         TRAP ( err, UpdateFailedSelfUpdaterInfoToPurchaseHistoryL( aErrorCode ) );
       
  1288         if ( err == KErrNone )
       
  1289             {
       
  1290             IAUPDATE_TRACE("[IAUPDATE] Continue update flow");
       
  1291         	TRAP ( err, ContinueUpdateL( EFalse ) );
       
  1292             }
       
  1293         if ( err != KErrNone )
       
  1294             {
       
  1295             IAUPDATE_TRACE_1("[IAUPDATE] Purchase history update error: %d", err);
       
  1296         	iObserver.HandleLeaveErrorWithoutLeave( err );
       
  1297             }
       
  1298         }
       
  1299 
       
  1300     if ( aErrorCode == IAUpdaterDefs::KIAUpdaterShutdownRequest )
       
  1301         {
       
  1302         CIAUpdateAppUi* appUi = static_cast<CIAUpdateAppUi*>( iEikEnv->EikAppUi() );
       
  1303     	appUi->Exit();
       
  1304         }
       
  1305 
       
  1306     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::SelfUpdaterComplete() end");
       
  1307     }
       
  1308 
       
  1309 
       
  1310 // -----------------------------------------------------------------------------
       
  1311 // CIAUpdateUiController::ServerReportSent
       
  1312 // 
       
  1313 // -----------------------------------------------------------------------------
       
  1314 //                            
       
  1315 void CIAUpdateUiController::ServerReportSent( TInt aError )
       
  1316     {
       
  1317     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateUiController::ServerReportSent() begin: %d",
       
  1318                      aError);
       
  1319 
       
  1320     // This call back is called when MIAUpdateController::UpdateFinishedL
       
  1321     // function is called and that asynchronous operation completes.
       
  1322     // Report sending is done in the background.
       
  1323     if ( iState == ESendingReport )
       
  1324         {
       
  1325         IAUPDATE_TRACE("[IAUPDATE] End the update flow now that report has been sent");
       
  1326         // Reports are sent only when update flow has finished. Also, in normal 
       
  1327         // flow, we wait that report sending finishes before continuing to the end. 
       
  1328         TRAP_IGNORE( EndUpdateFlowL( aError ) ); 
       
  1329         }
       
  1330 
       
  1331     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ServerReportSent() end");
       
  1332     }
       
  1333 
       
  1334 
       
  1335 // -----------------------------------------------------------------------------
       
  1336 // CIAUpdateUiController::ClientRole
       
  1337 // 
       
  1338 // -----------------------------------------------------------------------------
       
  1339 //     
       
  1340 void CIAUpdateUiController::ClientRole( const TDesC& aClientRole )
       
  1341     {
       
  1342 	if ( aClientRole == IAUpdateUiDefines::KTestRole() )
       
  1343 	    {
       
  1344 	    iTestRole = ETrue;
       
  1345 	    }
       
  1346     }
       
  1347 
       
  1348 
       
  1349 // -----------------------------------------------------------------------------
       
  1350 // CIAUpdateUiController::DownloadProgress
       
  1351 // 
       
  1352 // -----------------------------------------------------------------------------
       
  1353 //
       
  1354 void CIAUpdateUiController::DownloadProgress( MIAUpdateNode& /*aNode*/, 
       
  1355                                               TUint aProgress,
       
  1356                                               TUint aMaxProgress )
       
  1357     {
       
  1358     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::DownloadProgress() begin");  
       
  1359 
       
  1360     if ( iProgressDialog )
       
  1361         {
       
  1362     	TRAP_IGNORE ( iProgressDialog->SetProgressDialogFinalValueL( aMaxProgress ) );
       
  1363         TRAP_IGNORE ( iProgressDialog->UpdateProgressDialogValueL( aProgress ) );
       
  1364         }
       
  1365 
       
  1366     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::DownloadProgress() end");  
       
  1367     }                            
       
  1368 
       
  1369 
       
  1370 // -----------------------------------------------------------------------------
       
  1371 // CIAUpdateUiController::DownloadComplete
       
  1372 // 
       
  1373 // -----------------------------------------------------------------------------
       
  1374 //                            
       
  1375 void CIAUpdateUiController::DownloadComplete( MIAUpdateNode& aNode,
       
  1376                                               TInt aError )
       
  1377     {
       
  1378     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::DownloadComplete() begin");
       
  1379 
       
  1380     iState = EIdle;
       
  1381 	TRAPD ( completionError, DownloadCompleteL( aNode, aError ) );
       
  1382     if ( completionError != KErrNone )
       
  1383         {
       
  1384         // If we came here, DownloadCompleteL function may have left
       
  1385         // before dialog was removed. So, try one more time to remove it here
       
  1386         // before informing the observer.
       
  1387         TRAP_IGNORE( RemoveUpdatingDialogsL() );
       
  1388         iObserver.HandleLeaveErrorWithoutLeave( completionError );
       
  1389         }
       
  1390 
       
  1391     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::DownloadComplete() end");
       
  1392     }
       
  1393 
       
  1394 
       
  1395 // -----------------------------------------------------------------------------
       
  1396 // CIAUpdateUiController::InstallProgress
       
  1397 // 
       
  1398 // -----------------------------------------------------------------------------
       
  1399 //
       
  1400 void CIAUpdateUiController::InstallProgress( MIAUpdateNode& /*aNode*/, 
       
  1401                                              TUint /*aProgress*/,
       
  1402                                              TUint /*aMaxProgress*/ )
       
  1403     {
       
  1404     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::InstallProgress()");    
       
  1405     }                            
       
  1406 
       
  1407 
       
  1408 // -----------------------------------------------------------------------------
       
  1409 // CIAUpdateUiController::InstallComplete
       
  1410 // 
       
  1411 // -----------------------------------------------------------------------------
       
  1412 //
       
  1413 void CIAUpdateUiController::InstallComplete( MIAUpdateNode& aNode,
       
  1414                                              TInt aError )  
       
  1415     {
       
  1416     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::InstallComplete() begin");
       
  1417 
       
  1418     iState = EIdle;
       
  1419     CIAUpdateAppUi* appUi = static_cast<CIAUpdateAppUi*>( iEikEnv->EikAppUi() );
       
  1420     appUi->StopWGListChangeMonitoring();
       
  1421     if ( aError == SwiUI::KSWInstErrFileInUse )
       
  1422         {
       
  1423     	iFileInUseError = ETrue;
       
  1424         }
       
  1425     
       
  1426 	TRAPD ( completionError, InstallCompleteL( aNode, aError ) );
       
  1427     if ( completionError != KErrNone )
       
  1428         {
       
  1429         // If we came here, InstallCompleteL function may have left
       
  1430         // before dialog was removed. So, try one more time to remove it here
       
  1431         // before informing the observer.
       
  1432         TRAP_IGNORE( RemoveUpdatingDialogsL() );
       
  1433         iObserver.HandleLeaveErrorWithoutLeave( completionError );
       
  1434         }
       
  1435 
       
  1436     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::InstallComplete() end");
       
  1437     }
       
  1438 
       
  1439     
       
  1440 // ---------------------------------------------------------------------------
       
  1441 // CIAUpdateUiController::StartupComplete
       
  1442 // 
       
  1443 // ---------------------------------------------------------------------------
       
  1444 // 
       
  1445 void CIAUpdateUiController::StartupComplete( TInt aError )
       
  1446     {  
       
  1447     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartupComplete() begin");  
       
  1448 
       
  1449     if ( aError == IAUpdateErrorCodes::KErrCacheCleared )
       
  1450         {
       
  1451         IAUPDATE_TRACE("[IAUPDATE] Cache cleared during startup.");  
       
  1452         // Because cache was cleared, change the refresh information data
       
  1453         // so that the network refresh will be done during refresh operation.
       
  1454         
       
  1455         // The values have been read from the file when the controller file 
       
  1456         // object was created or the defaul values are used if the file did
       
  1457         // not exist. So, no need to re-read them here.
       
  1458         // Replace the time with zero. So, the zero time will
       
  1459         // suggest that network refresh is required later on. 
       
  1460         iControllerFile->SetRefreshTime( 0 );
       
  1461 
       
  1462         // Save data into the file.
       
  1463         // Change aError value to correct one. 
       
  1464         // aError will be KErrNone if everything goes ok inside trap,
       
  1465         // or else it will contain the correct error code.
       
  1466         TRAP ( aError, iControllerFile->WriteControllerDataL(); );
       
  1467         
       
  1468         CIAUpdateRestartInfo* info( iController->SelfUpdateRestartInfo() ); 
       
  1469         if ( info ) 
       
  1470             { 
       
  1471             IAUPDATE_TRACE("[IAUPDATE] Delete restart info because of cache clean.");
       
  1472             // Restart info was available. 
       
  1473             // Delete self upate files because otherwise a net connection
       
  1474             // may be prevented during refresh and the cleared cache can not
       
  1475             // be updated. If this is not done here, HandlePossibleSelfUpdateRestartL
       
  1476             // may leave because required nodes are not found. Notice, that also
       
  1477             // HandlePossibleSelfUpdateRestartL deletes these files but by handling
       
  1478             // this special case here, an application can continue without leave later.
       
  1479             info->DeleteFiles();
       
  1480             delete info; 
       
  1481             info = NULL; 
       
  1482             }
       
  1483         }
       
  1484         
       
  1485     iObserver.StartupComplete( aError );
       
  1486     
       
  1487     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartupComplete() end");  
       
  1488     }
       
  1489 
       
  1490 
       
  1491 // ---------------------------------------------------------------------------
       
  1492 // CIAUpdateUiController::StartExecutableCompletedL
       
  1493 // 
       
  1494 // ---------------------------------------------------------------------------
       
  1495 // 
       
  1496 void CIAUpdateUiController::StartExecutableCompletedL( TInt /*aError*/ )
       
  1497     {
       
  1498     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartExecutableCompletedL() begin"); 
       
  1499 
       
  1500     // Before informing the observer, close the possible existing dialog.
       
  1501     RemoveUpdatingDialogsL();
       
  1502     
       
  1503     // Possible error is not passed to a client. Typically client is already closed. 
       
  1504     // Even in the case when client's request is still ongoing, it's disinformation to return
       
  1505     // error from failed executable start. 
       
  1506     TRAPD ( err, iObserver.UpdateCompleteL( KErrNone ) );
       
  1507     if ( err != KErrNone )
       
  1508         {
       
  1509     	iObserver.HandleLeaveErrorL( err );
       
  1510         }
       
  1511 
       
  1512 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartExecutableCompletedL() end");
       
  1513     }
       
  1514 
       
  1515 
       
  1516 // ---------------------------------------------------------------------------
       
  1517 // CIAUpdateUiController::RoamingHandlerPrepared
       
  1518 // 
       
  1519 // ---------------------------------------------------------------------------
       
  1520 // 
       
  1521 void CIAUpdateUiController::RoamingHandlerPrepared()
       
  1522     {
       
  1523     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RoamingHandlerPrepared() begin");
       
  1524     TRAPD ( err, CheckUpdatesL() );
       
  1525 	if ( err != KErrNone )
       
  1526         {
       
  1527     	iObserver.HandleLeaveErrorWithoutLeave( err );
       
  1528         }
       
  1529     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RoamingHandlerPrepared() end");
       
  1530     }
       
  1531 
       
  1532 
       
  1533 // -----------------------------------------------------------------------------
       
  1534 // CIAUpdateUiController::HandleDialogExitL
       
  1535 // Called when wait/progress dialog is about to be cancelled.
       
  1536 // (other items were commented in a header).
       
  1537 // -----------------------------------------------------------------------------
       
  1538 //
       
  1539 TBool CIAUpdateUiController::HandleDialogExitL( TInt aButtonId )
       
  1540     {
       
  1541     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::HandleDialogExitL() begin");
       
  1542     IAUPDATE_TRACE_1("[IAUPDATE] button id: %d", aButtonId );
       
  1543     
       
  1544     TInt ret( ETrue );
       
  1545     if ( aButtonId == EAknSoftkeyCancel )
       
  1546         {  
       
  1547         TRAPD ( err, HandleUserCancelL() );
       
  1548         if ( err != KErrNone )
       
  1549             {
       
  1550         	iObserver.HandleLeaveErrorL( err );
       
  1551             }
       
  1552         }   
       
  1553 
       
  1554     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::HandleDialogExitL() end");
       
  1555 
       
  1556     return ret;    
       
  1557     }
       
  1558 
       
  1559 // -----------------------------------------------------------------------------
       
  1560 // CIAUpdateUiController::HandleUiRefreshL
       
  1561 // 
       
  1562 // -----------------------------------------------------------------------------
       
  1563 //
       
  1564 void CIAUpdateUiController::HandleUiRefreshL()
       
  1565     {
       
  1566 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::HandleUiRefreshL() begin"); 
       
  1567 
       
  1568 	if ( iRequestType == IAUpdateUiDefines::ECheckUpdates )
       
  1569 	    {
       
  1570 	    iRefreshed = EFalse;
       
  1571 	    }
       
  1572 	else if ( iState == EIdle )
       
  1573 	    {
       
  1574 	    CIAUpdateAppUi* appUi = static_cast< CIAUpdateAppUi* >( iEikEnv->EikAppUi() );
       
  1575         if ( appUi->UiRefreshAllowed() )
       
  1576 		    {
       
  1577 	    	iState = EUiRefreshing;
       
  1578 	        // store node identification (package UID and version) of currently selected nodes
       
  1579 	        // to restore selections after refresh
       
  1580 	        delete iPreviousSelections;
       
  1581 	        iPreviousSelections = NULL;
       
  1582 	        iPreviousSelections = new( ELeave ) CArrayFixFlat<SIAUpdateNodeId>( iNodes.Count() + 1 );
       
  1583 	        for ( TInt i = 0; i < iNodes.Count(); ++i )
       
  1584                 {
       
  1585                 MIAUpdateNode* node( iNodes[ i ] );
       
  1586                 SIAUpdateNodeId nodeId;
       
  1587                 nodeId.iNodeType = MIAUpdateAnyNode::ENodeTypeNormal;
       
  1588                 nodeId.iPackageUid = node->Base().Uid();
       
  1589                 nodeId.iVersion = node->Base().Version();
       
  1590                 nodeId.iSelected = node->Base().IsSelected();
       
  1591                 iPreviousSelections->AppendL( nodeId );
       
  1592                 }
       
  1593 
       
  1594             if ( iFwNodes.Count() > 0 )
       
  1595                 {   
       
  1596                 MIAUpdateFwNode* fwNode( iFwNodes[ 0 ] );
       
  1597                 SIAUpdateNodeId nodeId;
       
  1598                 nodeId.iNodeType = MIAUpdateAnyNode::ENodeTypeFw;
       
  1599                 nodeId.iSelected = fwNode->Base().IsSelected();
       
  1600                 iPreviousSelections->AppendL( nodeId );
       
  1601                 }
       
  1602         
       
  1603    	        iController->StartRefreshL( EFalse );
       
  1604 	        }
       
  1605 	    }
       
  1606 	
       
  1607 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::HandleUiRefreshL() end");
       
  1608     }
       
  1609 
       
  1610 
       
  1611 // ---------------------------------------------------------------------------
       
  1612 // CIAUpdateUiController::RefreshCompleteL
       
  1613 // 
       
  1614 // ---------------------------------------------------------------------------
       
  1615 //        
       
  1616 void CIAUpdateUiController::RefreshCompleteL( 
       
  1617     const RPointerArray< MIAUpdateAnyNode >& aNodes,
       
  1618     TInt aError )
       
  1619     {
       
  1620     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RefreshCompleteL() begin");
       
  1621 
       
  1622     iState = EIdle;
       
  1623     if ( !iRefreshHandler  && !iOffConfigurated )
       
  1624         {
       
  1625         iRefreshHandler = CIAUpdateRefreshHandler::NewL();
       
  1626         }
       
  1627     if ( aError == KErrNone ) 
       
  1628         {
       
  1629         // Inform refresh to other IAD instances 
       
  1630         if ( !iOffConfigurated  && AllowNetworkRefreshL() && iRefreshHandler )
       
  1631             {
       
  1632             iRefreshHandler->InformRefreshL();   
       
  1633             }
       
  1634                   
       
  1635         // Because refresh was successfully completed,
       
  1636         // update the controller information to the controller file
       
  1637         UpdateControllerFileL();
       
  1638         }
       
  1639 
       
  1640     // Even in a case when refresh failed, there may be old cache available.
       
  1641     // It's also possible that only firmware node or normal node refresh failed, so there is 
       
  1642     // partial list available
       
  1643     // ==> all nodes returned by engine are shown in UI
       
  1644     iNodes.Reset();
       
  1645     iFwNodes.Reset();
       
  1646     iNodes.ReserveL( aNodes.Count() );
       
  1647     for ( TInt i = 0; i < aNodes.Count(); ++i )
       
  1648         {
       
  1649         MIAUpdateAnyNode* anyNode( aNodes[ i ] );
       
  1650         if ( anyNode->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal )
       
  1651             {
       
  1652             MIAUpdateNode* node( 
       
  1653                 static_cast< MIAUpdateNode* >( anyNode ) );
       
  1654             iNodes.AppendL( node );                
       
  1655             }
       
  1656         else if ( anyNode->NodeType() == MIAUpdateAnyNode::ENodeTypeFw )
       
  1657             {
       
  1658             MIAUpdateFwNode* fwNode( 
       
  1659                 static_cast< MIAUpdateFwNode* >( anyNode ) );
       
  1660             iFwNodes.AppendL( fwNode );
       
  1661             }
       
  1662         }
       
  1663 
       
  1664     switch ( iRequestType )
       
  1665         {
       
  1666         case IAUpdateUiDefines::ECheckUpdates:
       
  1667         	
       
  1668             if ( iFilter->FilterParams() )
       
  1669                 {
       
  1670            		iFilter->CountOfAvailableUpdatesL( 
       
  1671                		                         iNodes, 
       
  1672                		                         iFwNodes,
       
  1673                		                         iCountOfAvailableUpdates ); 
       
  1674                 }
       
  1675             break;
       
  1676         
       
  1677         default: 
       
  1678             // Sort the nodes according to the filter values
       
  1679             // This function performs default marking also
       
  1680             iFilter->FilterAndSortNodesL( iNodes, iFwNodes );
       
  1681                                           
       
  1682             break;
       
  1683         }
       
  1684 
       
  1685     if ( aError == KErrNone )
       
  1686         {
       
  1687         // Now, that refresh has been done, 
       
  1688         // check if there is some self update related settings .
       
  1689         HandlePossibleSelfUpdateRestartL( EFalse );
       
  1690         }
       
  1691     
       
  1692     if ( !iOffConfigurated  && iRefreshHandler )
       
  1693         {
       
  1694         iRefreshHandler->StartListeningL( this );
       
  1695         }
       
  1696     iObserver.RefreshCompleteL( ETrue, aError );        
       
  1697         
       
  1698     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RefreshCompleteL() end");
       
  1699     }
       
  1700 
       
  1701 
       
  1702 // ---------------------------------------------------------------------------
       
  1703 // CIAUpdateUiController::RefreshUiCompleteL
       
  1704 // 
       
  1705 // ---------------------------------------------------------------------------
       
  1706 //        
       
  1707 void CIAUpdateUiController::RefreshUiCompleteL( 
       
  1708     const RPointerArray< MIAUpdateAnyNode >& aNodes,
       
  1709     TInt /*aError*/ )
       
  1710     {
       
  1711     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RefreshUiCompleteL() begin");
       
  1712     // : Is error handling needed?
       
  1713     iNodes.Reset();
       
  1714     iFwNodes.Reset();
       
  1715     iNodes.ReserveL( aNodes.Count() );
       
  1716     // Find out if there was umarked firmware update in old selections,
       
  1717     // that case needs special handling
       
  1718     TBool unmarkedFw = EFalse;
       
  1719     for ( TInt i = 0; i < iPreviousSelections->Count(); ++i )
       
  1720         {
       
  1721         SIAUpdateNodeId prevNodeId = iPreviousSelections->At( i );
       
  1722         if ( prevNodeId.iNodeType == MIAUpdateAnyNode::ENodeTypeFw  && !prevNodeId.iSelected )
       
  1723              {
       
  1724              unmarkedFw = ETrue;
       
  1725              }
       
  1726         }
       
  1727      
       
  1728     for ( TInt i = 0; i < aNodes.Count(); ++i )
       
  1729         {
       
  1730         MIAUpdateAnyNode* anyNode( aNodes[ i ] );
       
  1731         if ( anyNode->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal )
       
  1732             {
       
  1733             MIAUpdateNode* node( static_cast< MIAUpdateNode* >( anyNode ) );
       
  1734             iNodes.AppendL( node );                
       
  1735             }
       
  1736         else if ( anyNode->NodeType() == MIAUpdateAnyNode::ENodeTypeFw && !unmarkedFw )
       
  1737             {
       
  1738             // if umarked firmware update in old selections, firmawares are not appended 
       
  1739             // before iFilter->FilterAndSortNodesL() is called
       
  1740             MIAUpdateFwNode* fwNode( 
       
  1741                     static_cast< MIAUpdateFwNode* >( anyNode ) );
       
  1742             iFwNodes.AppendL( fwNode );
       
  1743             }
       
  1744         }
       
  1745     iFilter->FilterAndSortNodesL( iNodes, iFwNodes );
       
  1746     
       
  1747     if ( unmarkedFw )
       
  1748         {
       
  1749         for ( TInt i = 0; i < aNodes.Count(); ++i )
       
  1750             {
       
  1751             MIAUpdateAnyNode* anyNode( aNodes[ i ] );
       
  1752             if ( anyNode->NodeType() == MIAUpdateAnyNode::ENodeTypeFw )
       
  1753                 {
       
  1754                 MIAUpdateFwNode* fwNode( 
       
  1755                         static_cast< MIAUpdateFwNode* >( anyNode ) );
       
  1756                 iFwNodes.AppendL( fwNode );
       
  1757                 }
       
  1758             }
       
  1759         }
       
  1760     
       
  1761     //restore previous selections/deselections  
       
  1762     for ( TInt i = 0; i < iNodes.Count(); ++i )
       
  1763         {
       
  1764         MIAUpdateNode* node( iNodes[ i ] );
       
  1765         for ( TInt j = 0; j < iPreviousSelections->Count(); ++j )
       
  1766             {
       
  1767             SIAUpdateNodeId prevNodeId = iPreviousSelections->At(j);
       
  1768         	if ( node->Base().Uid() == prevNodeId.iPackageUid &&
       
  1769         	     node->Base().Version() == prevNodeId.iVersion )
       
  1770                 {
       
  1771         		node->Base().SetSelected( prevNodeId.iSelected );
       
  1772         	    }
       
  1773             }
       
  1774         }
       
  1775     
       
  1776     // When dependant is marked, all dependencies to be marked also
       
  1777     for ( TInt i = 0; i < iNodes.Count(); ++i )
       
  1778         {
       
  1779         MIAUpdateNode* node( iNodes[ i ] );
       
  1780         if ( node->Base().IsSelected() )
       
  1781             {
       
  1782             iFilter->SetDependenciesSelectedL( *node, iNodes );
       
  1783             }
       
  1784         }
       
  1785     
       
  1786     TBool firmwareSelected = EFalse;
       
  1787     for ( TInt i = 0; i < iFwNodes.Count(); ++i )
       
  1788         {
       
  1789         MIAUpdateFwNode* fwNode( iFwNodes[ i ] );
       
  1790     	for ( TInt j = 0; j < iPreviousSelections->Count(); ++j )
       
  1791     	    {
       
  1792     	    SIAUpdateNodeId prevNodeId = iPreviousSelections->At(j);
       
  1793     		if ( prevNodeId.iNodeType == MIAUpdateAnyNode::ENodeTypeFw )
       
  1794     		    {
       
  1795     			fwNode->Base().SetSelected( prevNodeId.iSelected );
       
  1796     		    }
       
  1797     	    }
       
  1798     	if ( fwNode->Base().IsSelected() )
       
  1799     	    {
       
  1800     	    firmwareSelected = ETrue;
       
  1801     	    }
       
  1802         }
       
  1803     
       
  1804     // if firmware is marked, normal nodes to be unmarked
       
  1805     if ( firmwareSelected )
       
  1806         {
       
  1807         for ( TInt i = 0; i < iNodes.Count(); ++i )
       
  1808             {
       
  1809             MIAUpdateNode* node( iNodes[ i ] );
       
  1810             node->Base().SetSelected( EFalse );
       
  1811             }
       
  1812         }
       
  1813     
       
  1814     CreateSelectedNodesArrayL();
       
  1815     iObserver.RefreshCompleteL( EFalse, KErrNone );
       
  1816      
       
  1817     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RefreshUiCompleteL() end"); 
       
  1818     }
       
  1819     
       
  1820     
       
  1821     
       
  1822 // ---------------------------------------------------------------------------
       
  1823 // CIAUpdateUiController::DownloadCompleteL
       
  1824 // 
       
  1825 // ---------------------------------------------------------------------------
       
  1826 //            
       
  1827 void CIAUpdateUiController::DownloadCompleteL( MIAUpdateNode& aNode, TInt aError )
       
  1828     {
       
  1829     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::DownloadCompleteL() begin");
       
  1830     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError );
       
  1831 
       
  1832     if ( aError == KErrAbort )
       
  1833         {
       
  1834         // Abort is interpreted so that a connection was not allowed by the user.
       
  1835         // So, do not continue to a new operation. 
       
  1836         // Instead, complete the update flow now.
       
  1837         // Set the purchase history information to nodes.
       
  1838         // Because the current node has KErrAbort as the last operation error code,
       
  1839         // change it to KErrCancel because we want to think it as cancellation instead
       
  1840         // of as abort error. This way, error counters and history info will show cancel
       
  1841         // instead of failed. Also, update cancel info to other pending nodes.
       
  1842         for ( TInt i = iNodeIndex; i < iSelectedNodesArray.Count(); ++i )
       
  1843             {
       
  1844             MIAUpdateNode* node( iSelectedNodesArray[ i ] );
       
  1845             // Because we are handling nodes that are visible in UI,
       
  1846             // we can force the node as visible in history.
       
  1847             TRAP_IGNORE ( 
       
  1848                 node->Base().SetIdleCancelToPurchaseHistoryL( ETrue ) );
       
  1849             }
       
  1850         UpdateCompleteL( KErrNone );        
       
  1851         }
       
  1852     else if ( aError != KErrNone )
       
  1853         {
       
  1854     	InstallCompleteL( aNode, aError );
       
  1855         }
       
  1856     else   
       
  1857         {
       
  1858 	    StartInstallL( aNode );
       
  1859         }    
       
  1860  
       
  1861     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::DownloadCompleteL() end");
       
  1862     }
       
  1863 
       
  1864 
       
  1865 // ---------------------------------------------------------------------------
       
  1866 // CIAUpdateUiController::InstallCompleteL
       
  1867 // 
       
  1868 // ---------------------------------------------------------------------------
       
  1869 //      
       
  1870 void CIAUpdateUiController::InstallCompleteL( MIAUpdateNode& aNode, 
       
  1871                                               TInt aError )    
       
  1872     {
       
  1873     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::InstallCompleteL() begin");
       
  1874     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError );
       
  1875 
       
  1876     // In release mode, we do not need the aError info, because
       
  1877     // success counters are counted by using the last operation error info
       
  1878     // when counter info is asked. In debug mode the error code is logged above.
       
  1879     (void)aError;
       
  1880     
       
  1881     // pass UID of installed package to starter
       
  1882     if ( iStarter )
       
  1883         {
       
  1884     	if ( aNode.Type() == MIAUpdateNode::EPackageTypeServicePack )
       
  1885     	    { 
       
  1886     	    IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::InstallCompleteL() node type is service pack");
       
  1887      	    for ( TInt i = 0; i < iServicePackNodes.Count(); ++i )
       
  1888     	        {
       
  1889     	        if ( iServicePackNodes[i]->IsInstalled() )   
       
  1890     	            {
       
  1891     	            IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::InstallCompleteL() node is installed");
       
  1892     	            iStarter->CheckInstalledPackageL( iServicePackNodes[i]->Base().Uid() );
       
  1893     	            }
       
  1894     	        }
       
  1895     	    iServicePackNodes.Reset();
       
  1896     	    }
       
  1897     	else if ( aNode.IsInstalled() )
       
  1898     	    {
       
  1899     	    IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::InstallCompleteL() node is installed");
       
  1900     	    iStarter->CheckInstalledPackageL( aNode.Base().Uid() );
       
  1901     	    }
       
  1902         }
       
  1903     
       
  1904     // If installation was marked as KErrCancel here,
       
  1905     // we think that it was just the disclaimer and
       
  1906     // let this continue.        
       
  1907     ContinueUpdateL( EFalse );
       
  1908 
       
  1909     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::InstallCompleteL() end");
       
  1910     }
       
  1911 
       
  1912 
       
  1913 // ---------------------------------------------------------------------------
       
  1914 // CIAUpdateUiController::UpdateCompleteL
       
  1915 // 
       
  1916 // ---------------------------------------------------------------------------
       
  1917 //      
       
  1918 void CIAUpdateUiController::UpdateCompleteL( TInt aError ) 
       
  1919     {
       
  1920     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::UpdateCompleteL() begin");
       
  1921 
       
  1922     iState = EIdle;
       
  1923     iClosingAllowedByClient = EFalse;
       
  1924 
       
  1925     // Remove installed nodes from the node array.
       
  1926 	for ( TInt i = iNodes.Count() - 1; i >= 0; --i ) 
       
  1927         {   
       
  1928         MIAUpdateNode* node = iNodes[ i ];
       
  1929         if ( node->IsInstalled() ) 
       
  1930             {
       
  1931             iNodes.Remove( i );
       
  1932             }
       
  1933         }
       
  1934     
       
  1935     TInt error( aError );
       
  1936     TBool selfUpdaterStarted( EFalse );
       
  1937 
       
  1938     if ( error == KErrNone )
       
  1939         {
       
  1940         IAUPDATE_TRACE("[IAUPDATE] Check self update start");
       
  1941         // Set the error to correspond to the trap error. So, 
       
  1942         // the observer will get correct information about the end result
       
  1943         // of the update.
       
  1944         TRAP ( error, 
       
  1945                selfUpdaterStarted = StartPossibleSelfUpdateL() );
       
  1946         if ( error != KErrNone )
       
  1947             {
       
  1948             IAUPDATE_TRACE_1("[IAUPDATE] trap error: %d", error);
       
  1949             // Because self update could not be started the counters may not be
       
  1950             // correct. Also, update purchase history with the error value 
       
  1951             // because install operation failed here.
       
  1952             UpdateFailedSelfUpdaterInfoToPurchaseHistoryL( error ); 
       
  1953             }
       
  1954         }                   
       
  1955 
       
  1956     // Check if self updater was started.
       
  1957     // If it was not, then there most likely was not any self updates set,
       
  1958     // or something went wrong when self updater was tried to be started.
       
  1959     if ( selfUpdaterStarted )
       
  1960         {
       
  1961         iState = ESelfUpdating;
       
  1962         }
       
  1963     else
       
  1964         {
       
  1965         IAUPDATE_TRACE("[IAUPDATE] SelfUpdater was not started");
       
  1966 
       
  1967         // Notice, that if the self updater was started, then
       
  1968         // do not inform the UI here that the operation was completed.
       
  1969         // Also, do not start possible executable yet.
       
  1970         // Instead, let the self updater do its thing in the background.
       
  1971         // Most likely, the updater will close this application during installation.
       
  1972         // But, if it does not, it will result to the SelfUpdaterComplete function
       
  1973         // call, and we can continue the installation from there.
       
  1974 
       
  1975         // Inform the controller that we finished the updates. This way the
       
  1976         // controller can handle situations as a whole and not as one item at the
       
  1977         // time. Notice, that this will start the asynchronous operation that sends
       
  1978         // possible reports to the server. Callback is called when operation is finished.
       
  1979         // Also notice, that this reporting operation is not part of the normal update
       
  1980         // flow but a separate action meant  after update flow finishes. 
       
  1981         // The destructor of the engine controller can handle the cancellation of 
       
  1982         // the reporting operation. Also, no callbacks are called back to UI when 
       
  1983         // cancellation occurs. Notice, that if close request for application is issued
       
  1984         // before reports are sent, then objects are delete immediately and we will not 
       
  1985         // wait report sending to finish but reports are sent next time the application 
       
  1986         // is started.
       
  1987         // Maximum wait time for server reports is given in micro seconds.
       
  1988         // Notice, that in case of cancellations there would not be any need
       
  1989         // for timer. But just use it as in normal cases. Then, server report
       
  1990         // completion or timer will call the callback later. But, that callback
       
  1991         // will be ignored in CIAUpdateUiController::ServerReportSent because
       
  1992         // iState is already then changed from ESendingReport to something else. 
       
  1993         const TInt KServerReportMaxWaitTime( 10000000 );
       
  1994         iController->FinishedUpdatesL( ETrue, KServerReportMaxWaitTime );
       
  1995         iState = ESendingReport;
       
  1996         }
       
  1997 
       
  1998     // When reports are sent, EndUpdateFlowL is called via the callback functions
       
  1999     // and the update flow will be finished there. But, if we come here when cancel
       
  2000     // is pressed, then call EndUpdateFlowL directly because then we do not wait
       
  2001     // report sending to finish. This will also set the state to EIdle to inform
       
  2002     // that when cancelling, we do not wait for the report sending to complete.
       
  2003     if ( aError == KErrCancel )
       
  2004         {
       
  2005         IAUPDATE_TRACE("[IAUPDATE] Cancelling. Call EndUpdateFlowL directly");
       
  2006         EndUpdateFlowL( error );
       
  2007         }
       
  2008 
       
  2009     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::UpdateCompleteL() end");
       
  2010     }
       
  2011 
       
  2012 
       
  2013 // ---------------------------------------------------------------------------
       
  2014 // CIAUpdateUiController::EndUpdateFlowL
       
  2015 // 
       
  2016 // ---------------------------------------------------------------------------
       
  2017 //  
       
  2018 void CIAUpdateUiController::EndUpdateFlowL( TInt aError )    
       
  2019     {
       
  2020     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::EndUpdateFlowL() begin");
       
  2021 
       
  2022     // Because we are ending the flow, set the state to idle.
       
  2023     iState = EIdle;
       
  2024     
       
  2025     // Notice, that the ownership of the filter parameters will
       
  2026     // remain in the filter.
       
  2027     CIAUpdateParameters* params( iFilter->FilterParams() );
       
  2028     if ( !IsStartedByLauncher()
       
  2029          || params )
       
  2030         {
       
  2031         IAUPDATE_TRACE_1("[IAUPDATE] Request type check matched: %d", iRequestType);
       
  2032 
       
  2033         // Check if IAD was started from the grid or through API.
       
  2034         // If IAD was started like from the grid but it still has parameters set,
       
  2035         // then act as it was started through API. Most likely, then the IAD was
       
  2036         // originally started through API but because of self update IAD was restarted
       
  2037         // and now it has original parameters set.
       
  2038 
       
  2039         if ( !iStarter )
       
  2040             {
       
  2041             IAUPDATE_TRACE("[IAUPDATE] iStarter not set");
       
  2042         	iStarter = CIAUpdateStarter::NewL( params->CommandLineExecutable(), 
       
  2043         	                                   params->CommandLineArguments() );
       
  2044             }
       
  2045 
       
  2046         // Notice, that when starter calls StartExecutableCompletedL callback function,
       
  2047         // the observer is informed from there about the completion of the update flow.
       
  2048         // So, do not inform observer here.
       
  2049         iStarter->StartExecutableL( *this );
       
  2050         }
       
  2051     else
       
  2052         {
       
  2053         // Do not try to start any application. 
       
  2054         // But, use the start application callback function
       
  2055         // to end the update flow correctly (same way as after 
       
  2056         // application start with other options).
       
  2057         IAUPDATE_TRACE_1("[IAUPDATE] Update complete error: %d", aError );
       
  2058         StartExecutableCompletedL( aError );
       
  2059         }    
       
  2060 
       
  2061     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::EndUpdateFlowL() end");
       
  2062     }
       
  2063 
       
  2064 // ---------------------------------------------------------------------------
       
  2065 // CIAUpdateUiController::CheckUpdatesDeferredCallbackL
       
  2066 // CheckUpdates as deferred to get empty main view visible before CheckUpdates
       
  2067 //
       
  2068 // ---------------------------------------------------------------------------
       
  2069 //
       
  2070 TInt CIAUpdateUiController::CheckUpdatesDeferredCallbackL( TAny* aPtr )
       
  2071     {
       
  2072     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CheckUpdatesDeferredCallbackL() begin");
       
  2073 
       
  2074     CIAUpdateUiController* uiCtrl = static_cast<CIAUpdateUiController*>( aPtr );
       
  2075     
       
  2076     TRAPD ( err, uiCtrl->PrepareRoamingHandlerL() );
       
  2077     if ( err != KErrNone )
       
  2078         {
       
  2079         uiCtrl->iObserver.HandleLeaveErrorL( err );
       
  2080         }
       
  2081 
       
  2082     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CheckUpdatesDeferredCallbackL() end");
       
  2083 
       
  2084 	return KErrNone;
       
  2085     }
       
  2086 
       
  2087 
       
  2088 // ---------------------------------------------------------------------------
       
  2089 // CIAUpdateUiController::ShowUpdatingDialogL
       
  2090 // 
       
  2091 // ---------------------------------------------------------------------------
       
  2092 //
       
  2093 void CIAUpdateUiController::ShowUpdatingDialogL( TInt aTextResourceId,
       
  2094                                                  const TDesC& aName,
       
  2095                                                  TInt aNumber,
       
  2096                                                  TInt aTotalCount )   
       
  2097                                                     
       
  2098     {
       
  2099     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ShowUpdatingDialogL() begin");
       
  2100 
       
  2101     // Before trying ot create a new dialog,
       
  2102     // remove possible existing dialog.
       
  2103     RemoveUpdatingDialogsL();
       
  2104 
       
  2105     CDesCArray* stringArray = new( ELeave ) CDesCArrayFlat( 1 );
       
  2106     CleanupStack::PushL( stringArray );
       
  2107     stringArray->AppendL( aName );
       
  2108     CArrayFix<TInt>* numberArray = new( ELeave ) CArrayFixFlat<TInt>( 2 );
       
  2109     CleanupStack::PushL( numberArray );
       
  2110     numberArray->AppendL( aNumber ); 
       
  2111     numberArray->AppendL( aTotalCount );
       
  2112     HBufC* noteText = NULL;
       
  2113     noteText = StringLoader::LoadLC( aTextResourceId, 
       
  2114                                      *stringArray, 
       
  2115                                      *numberArray );
       
  2116     TPtr ptr = noteText->Des();
       
  2117     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr ); 
       
  2118     if ( iState == EDownloading )
       
  2119         {
       
  2120     	ShowProgressDialogL( *noteText, ETrue );
       
  2121         }
       
  2122     else
       
  2123         {
       
  2124         ShowWaitDialogL( *noteText, ETrue );	
       
  2125         }
       
  2126     
       
  2127     CleanupStack::PopAndDestroy( noteText ); 
       
  2128     CleanupStack::PopAndDestroy( numberArray );
       
  2129     CleanupStack::PopAndDestroy( stringArray );
       
  2130 
       
  2131     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ShowUpdatingDialogL() end");
       
  2132     }
       
  2133  
       
  2134 
       
  2135 // ---------------------------------------------------------------------------
       
  2136 // CIAUpdateUiController::ShowWaitDialogL
       
  2137 // 
       
  2138 // ---------------------------------------------------------------------------
       
  2139 //
       
  2140 void CIAUpdateUiController::ShowWaitDialogL( const TDesC& aDisplayString, 
       
  2141                                              TBool aVisibilityDelayOff ) 
       
  2142     {
       
  2143     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ShowWaitDialogL() begin");
       
  2144 
       
  2145     if ( iWaitDialog )
       
  2146         {
       
  2147         IAUPDATE_TRACE("[IAUPDATE] Wait dialog already existed. Remove it first");
       
  2148         // in some rare cases previous dialog still exists
       
  2149         // it's now just deleted (not recommended way) to avoid forwarding problem(s). 
       
  2150         delete iWaitDialog;
       
  2151         iWaitDialog = NULL;
       
  2152         }
       
  2153     iWaitDialog = 
       
  2154         new( ELeave ) CIAUpdateWaitDialog( 
       
  2155             reinterpret_cast< CEikDialog** >( &iWaitDialog ),
       
  2156             aVisibilityDelayOff );
       
  2157                 
       
  2158     iWaitDialog->SetTextL( aDisplayString );
       
  2159     iWaitDialog->SetCallback( this );        
       
  2160     iWaitDialog->ExecuteLD( R_IAUPDATE_WAIT_DIALOG );
       
  2161 
       
  2162     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ShowWaitDialogL() end");
       
  2163     }
       
  2164 
       
  2165 
       
  2166 // ---------------------------------------------------------------------------
       
  2167 // CIAUpdateUiController::ShowProgressDialogL
       
  2168 // 
       
  2169 // ---------------------------------------------------------------------------
       
  2170 //
       
  2171 void CIAUpdateUiController::ShowProgressDialogL( const TDesC& aDisplayString, 
       
  2172                                                  TBool aVisibilityDelayOff ) 
       
  2173     {
       
  2174     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ShowProgressDialogL() begin");
       
  2175 
       
  2176     if ( iProgressDialog )
       
  2177         {
       
  2178         IAUPDATE_TRACE("[IAUPDATE] Progress dialog already existed. Remove it first");
       
  2179         // in some rare cases previous dialog still exists
       
  2180         // it's now just deleted (not recommended way) to avoid forwarding problem(s). 
       
  2181         delete iProgressDialog;
       
  2182         iProgressDialog = NULL;
       
  2183         }
       
  2184     iProgressDialog = 
       
  2185         new( ELeave ) CIAUpdateProgressDialog( 
       
  2186             reinterpret_cast< CEikDialog** >( &iProgressDialog ),
       
  2187             aVisibilityDelayOff );
       
  2188                 
       
  2189     iProgressDialog->SetTextL( aDisplayString );
       
  2190     iProgressDialog->SetCallback( this );        
       
  2191     iProgressDialog->ExecuteLD( R_IAUPDATE_PROGRESS_DIALOG );
       
  2192 
       
  2193     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ShowProgressDialogL() end");
       
  2194     }
       
  2195 
       
  2196 
       
  2197 // ---------------------------------------------------------------------------
       
  2198 // CIAUpdateUiController::RemoveUpdatingDialogsL
       
  2199 // 
       
  2200 // ---------------------------------------------------------------------------
       
  2201 //
       
  2202 void CIAUpdateUiController::RemoveUpdatingDialogsL()
       
  2203     {
       
  2204     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RemoveUpdatingDialogsL() begin");
       
  2205     
       
  2206     RemoveWaitDialogL();
       
  2207     RemoveProgressDialogL();
       
  2208 
       
  2209     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RemoveUpdatingDialogsL() end");
       
  2210     }
       
  2211 
       
  2212 
       
  2213 // ---------------------------------------------------------------------------
       
  2214 // CIAUpdateUiController::RemoveWaitDialogL
       
  2215 // 
       
  2216 // ---------------------------------------------------------------------------
       
  2217 //
       
  2218 void CIAUpdateUiController::RemoveWaitDialogL()
       
  2219     {
       
  2220     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RemoveWaitDialogL() begin");
       
  2221 
       
  2222     if ( !iCancelling )  //that's needed because AVKON  in 3.2.3 wk12, returning
       
  2223                          //EFalse in TryToExitL() causes a crash   
       
  2224         {
       
  2225     	if ( iWaitDialog )
       
  2226             {
       
  2227     	    iWaitDialog->ProcessFinishedL();
       
  2228             }
       
  2229         }
       
  2230     
       
  2231 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RemoveWaitDialogL() end");
       
  2232     }
       
  2233 
       
  2234 
       
  2235 // ---------------------------------------------------------------------------
       
  2236 // CIAUpdateUiController::RemoveProgressDialogL
       
  2237 // 
       
  2238 // ---------------------------------------------------------------------------
       
  2239 //
       
  2240 void CIAUpdateUiController::RemoveProgressDialogL()
       
  2241     {
       
  2242     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RemoveProgressDialogL() begin");
       
  2243 
       
  2244     if ( !iCancelling )  //that's needed because AVKON  in 3.2.3 wk12, returning
       
  2245                          //EFalse in TryToExitL() causes a crash   
       
  2246         {
       
  2247     	if ( iProgressDialog )
       
  2248             {
       
  2249     	    iProgressDialog->ProcessFinishedL();
       
  2250             }
       
  2251         }
       
  2252     
       
  2253 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RemoveProgressDialogL() end");
       
  2254     }
       
  2255 
       
  2256 
       
  2257 // ---------------------------------------------------------------------------
       
  2258 // CIAUpdateUiController::AllowNetworkRefreshL
       
  2259 // 
       
  2260 // ---------------------------------------------------------------------------
       
  2261 //
       
  2262 TBool CIAUpdateUiController::AllowNetworkRefreshL()
       
  2263     {
       
  2264     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::AllowNetworkRefreshL() begin");
       
  2265     
       
  2266     TBool allowRefresh( EFalse );
       
  2267     if ( IsStartedByLauncher() )
       
  2268         {
       
  2269     	if ( !iRefreshFromNetworkDenied && 
       
  2270     	     !iUserRoamingRejection && 
       
  2271     	     !RestartedFromSelfUpdate() )
       
  2272     	    {
       
  2273     		if ( LocalNodesExpiredL() )
       
  2274     		    {
       
  2275     			allowRefresh = ETrue;
       
  2276     		    }
       
  2277     	    }
       
  2278         }
       
  2279     else   
       
  2280         {
       
  2281         // started by an application
       
  2282         if ( iFilter )
       
  2283     	    {
       
  2284     	    CIAUpdateParameters* params( iFilter->FilterParams() );
       
  2285     	    if ( params )
       
  2286     	        {
       
  2287     	    	if ( params->Refresh() )
       
  2288     	    	    {
       
  2289       	      		// Check from the central repocitory what are the automatic checking and 
       
  2290                     // roaming settings.     
       
  2291                     TInt autoUpdateCheckValue( 0 );
       
  2292                     CRepository* cenrep( 
       
  2293                              CRepository::NewLC( KCRUidIAUpdateSettings ) );
       
  2294                     // Notice, that KIAUpdateSettingAutoUpdateCheck can give following values
       
  2295                     // 0 = No automatic update check
       
  2296                     // 1 = Automatic update check enabled when not roaming
       
  2297                     // 2 = Automatic update enabled
       
  2298 
       
  2299                     User::LeaveIfError( cenrep->Get( KIAUpdateAutoUpdateCheck, 
       
  2300                                                      autoUpdateCheckValue ) );
       
  2301                     CleanupStack::PopAndDestroy( cenrep );
       
  2302                     if ( ( autoUpdateCheckValue == EIAUpdateSettingValueEnable ) || 
       
  2303     	               ( autoUpdateCheckValue == EIAUpdateSettingValueDisableWhenRoaming &&
       
  2304     	                 !iRoamingHandler->IsRoaming() ) )
       
  2305                         {
       
  2306                     	allowRefresh = ETrue;
       
  2307                         }
       
  2308      	    	    }
       
  2309     	        }
       
  2310     	    }
       
  2311         }
       
  2312     
       
  2313     IAUPDATE_TRACE_1("[IAUPDATE] allowRefresh: %d", allowRefresh );    
       
  2314     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::AllowNetworkRefreshL() end");  
       
  2315     return allowRefresh;
       
  2316     }
       
  2317 
       
  2318 
       
  2319 
       
  2320 // ---------------------------------------------------------------------------
       
  2321 // CIAUpdateUiController::LocalNodesExpiredL
       
  2322 // 
       
  2323 // ---------------------------------------------------------------------------
       
  2324 //
       
  2325 TBool CIAUpdateUiController::LocalNodesExpiredL()
       
  2326     {
       
  2327     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::LocalNodesExpiredL() begin");
       
  2328 
       
  2329     // Notice, that the values for the iControllerFile, that are used here for
       
  2330     // expiration checkings, are set after successfull completion of refresh
       
  2331     // operation. See, UpdateControllerFileL that is called when operation
       
  2332     // finishes successfully. 
       
  2333 
       
  2334     const TTimeIntervalHours KExpirationDeltaInHours( 
       
  2335         ConfigData().GridRefreshDeltaHours() );
       
  2336     
       
  2337     // Make sure that the most current data is gotten from the file.
       
  2338     iControllerFile->ReadControllerDataL();
       
  2339 
       
  2340     TLanguage currentLanguage = User::Language();
       
  2341     TLanguage lastTimeLanguage = iControllerFile->Language();
       
  2342     if ( lastTimeLanguage != currentLanguage )
       
  2343         {
       
  2344         // Think nodes as expired because the language 
       
  2345         // has been changed in the phone. By updating the nodes,
       
  2346         // the items in UI will show correct language.
       
  2347         // No need to set the language to the controller file here.
       
  2348         // The value is set when the operation is successfully completed.
       
  2349         IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::LocalNodesExpiredL() ETrue end");
       
  2350         return ETrue;
       
  2351         }
       
  2352         
       
  2353     // Because the language check has passed,
       
  2354     // check also the time expirations.
       
  2355 
       
  2356     // Get the last recorded refresh time from the controller file    
       
  2357     TTime lastRefreshTime( iControllerFile->RefreshTime() );
       
  2358 
       
  2359     // Initialize expireTime with the last refresh time. Notice,
       
  2360     // that this expire time will be increased below with the correct 
       
  2361     // value
       
  2362     TTime expireTime( lastRefreshTime );
       
  2363 
       
  2364     expireTime += KExpirationDeltaInHours;
       
  2365 
       
  2366     // Get the current time.
       
  2367     TTime universalTime;
       
  2368     universalTime.UniversalTime();
       
  2369 
       
  2370     if ( expireTime < universalTime
       
  2371          || lastRefreshTime > universalTime )
       
  2372         {
       
  2373         // Database is expired because current time has passed the
       
  2374         // expiration time. Also, sanity check is made. If
       
  2375         // last refresh time is larger than current time, then the
       
  2376         // last refresh value has been set wrong, and the database can
       
  2377         // be thought as expired. This might be the case if the user has
       
  2378         // changed the time in the phone.
       
  2379         IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::LocalNodesExpiredL() ETrue end");
       
  2380         return ETrue;
       
  2381         }
       
  2382     else
       
  2383         {
       
  2384         // Database is not expired yet.
       
  2385         IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::LocalNodesExpiredL() EFalse end");
       
  2386         return EFalse;        
       
  2387         } 
       
  2388     }
       
  2389 
       
  2390 
       
  2391 // ---------------------------------------------------------------------------
       
  2392 // CIAUpdateUiController::UpdateControllerFileL
       
  2393 // 
       
  2394 // ---------------------------------------------------------------------------
       
  2395 //
       
  2396 void CIAUpdateUiController::UpdateControllerFileL()
       
  2397     {
       
  2398     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::UpdateControllerFileL() begin");
       
  2399 
       
  2400     // This function is called after the refresh operation has
       
  2401     // completed.
       
  2402 
       
  2403     // Check if local nodes were updated from the server.
       
  2404     // Notice, that last refresh time and language are both checked
       
  2405     // here when LocalNodesExpiredL() is called from AllowNetworkRefreshL.
       
  2406     // AllowNetworkRefreshL is called here because autoupdate and roaming checks
       
  2407     // should also be done when deciding if the nodes were updated.
       
  2408     if ( AllowNetworkRefreshL() )
       
  2409         {
       
  2410         // Update controller file with current information 
       
  2411         // because old values were expired.
       
  2412         iControllerFile->SetCurrentData();
       
  2413 
       
  2414         // Because data is not up to date,
       
  2415         // save new data into the file.
       
  2416         iControllerFile->WriteControllerDataL();        
       
  2417         }
       
  2418 
       
  2419     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::UpdateControllerFileL() end");
       
  2420     }
       
  2421 
       
  2422 
       
  2423 // ---------------------------------------------------------------------------
       
  2424 // CIAUpdateUiController::IsStartedByLauncher
       
  2425 // 
       
  2426 // ---------------------------------------------------------------------------
       
  2427 //
       
  2428 TBool CIAUpdateUiController::IsStartedByLauncher()
       
  2429     {
       
  2430     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::IsStartedByLauncher()");
       
  2431 
       
  2432     if ( iRequestType == IAUpdateUiDefines::ENoRequest )
       
  2433         {
       
  2434         IAUPDATE_TRACE("[IAUPDATE] Started by launcher");
       
  2435         // This operation was started from the application that was
       
  2436         // started by launcher
       
  2437         // Currently it means that launching is originated 
       
  2438         // from application grid or background checker. There is only
       
  2439         // one iaupdate instance started by launcher
       
  2440         return ETrue;
       
  2441         }
       
  2442     else
       
  2443         {
       
  2444         IAUPDATE_TRACE("[IAUPDATE] NOT started by launcher");
       
  2445         // According to the request type, 
       
  2446         // API was used to start the operation.
       
  2447         return EFalse;        
       
  2448         }
       
  2449     }
       
  2450 
       
  2451 
       
  2452 // ---------------------------------------------------------------------------
       
  2453 // CIAUpdateUiController::StartPossibleSelfUpdateL
       
  2454 // 
       
  2455 // ---------------------------------------------------------------------------
       
  2456 //
       
  2457 TBool CIAUpdateUiController::StartPossibleSelfUpdateL()
       
  2458     {
       
  2459     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartPossibleSelfUpdateL() begin");
       
  2460 
       
  2461     // If there exist some self updater files that need to be installed
       
  2462     // separately, start self updating process.
       
  2463     TBool started( 
       
  2464         iController->
       
  2465             StartPossibleSelfUpdateL( iNodeIndex, 
       
  2466                                       iSelectedNodesArray.Count(),
       
  2467                                       iSelectedNodesArray,
       
  2468                                       EFalse ) );
       
  2469             
       
  2470     // Because self updater has gotten all the information it needs now,
       
  2471     // we can reset the data that is meant for the updater.
       
  2472     iController->ResetSelfUpdate();
       
  2473 
       
  2474     IAUPDATE_TRACE_1("[IAUPDATE] started: %d", started );
       
  2475     if ( started )
       
  2476         {
       
  2477         // Because self update was started, save possible parameters data 
       
  2478         // for the possible restart of IAD. The, IAD can continue correctly.
       
  2479         ParamsWriteFileL();
       
  2480         }
       
  2481 
       
  2482     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::StartPossibleSelfUpdateL() end");
       
  2483     
       
  2484     return started;  
       
  2485     }
       
  2486 
       
  2487 
       
  2488 // ---------------------------------------------------------------------------
       
  2489 // CIAUpdateUiController::UpdateFailedSelfUpdaterInfoToPurchaseHistoryL
       
  2490 // 
       
  2491 // ---------------------------------------------------------------------------
       
  2492 //
       
  2493 void CIAUpdateUiController::UpdateFailedSelfUpdaterInfoToPurchaseHistoryL( TInt aErrorCode )
       
  2494     {
       
  2495     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::UpdateFailedSelfUpdaterInfoToPurchaseHistoryL() begin");
       
  2496     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aErrorCode );
       
  2497 
       
  2498     // Check all the items that have been updated so far.
       
  2499     // And, set the error info to purchase history accordingly.
       
  2500     for ( TInt i = 0; 
       
  2501           i < iSelectedNodesArray.Count()
       
  2502           && i < iNodeIndex + 1;
       
  2503           ++i )
       
  2504         {
       
  2505         MIAUpdateNode* node( iSelectedNodesArray[ i ] );
       
  2506         if ( node->IsSelfUpdate() )
       
  2507             {
       
  2508             TBool installSuccess( node->IsInstalled() );
       
  2509             if ( !installSuccess  )
       
  2510                 {
       
  2511                 // Notice, that we can just set the purchase history here for
       
  2512                 // the self updater items. If some of the items were installed,
       
  2513                 // before self updater items, then their information was already
       
  2514                 // correctly into the history.
       
  2515                 TInt error( aErrorCode );
       
  2516                 if ( aErrorCode == KErrNone )
       
  2517                     {
       
  2518                     error = KErrUnknown;
       
  2519                     }
       
  2520 
       
  2521                 // Because we are handling nodes that are visible in UI,
       
  2522                 // we can force the node as visible in history.                    
       
  2523                 node->Base().SetInstallStatusToPurchaseHistoryL( error, ETrue );
       
  2524                 }
       
  2525             }
       
  2526         }
       
  2527 
       
  2528     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::UpdateFailedSelfUpdaterInfoToPurchaseHistoryL() end");    
       
  2529     }
       
  2530 
       
  2531 
       
  2532 // ---------------------------------------------------------------------------
       
  2533 // CIAUpdateUiController::HandleUserCancelL
       
  2534 // 
       
  2535 // ---------------------------------------------------------------------------
       
  2536 //      
       
  2537 void CIAUpdateUiController::HandleUserCancelL()
       
  2538     {
       
  2539 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::HandleUserCancelL() begin");
       
  2540 
       
  2541     // Get the current state.
       
  2542     // CancelOperation will set a new value for the state and we do not 
       
  2543     // want to use that.
       
  2544     TState state( iState );
       
  2545     
       
  2546     CancelOperation();
       
  2547     
       
  2548     // Set the flag on. 
       
  2549     // So, dialogs are handled correctly.
       
  2550     iCancelling = ETrue;
       
  2551     
       
  2552     if ( state == EDownloading || state == EInstalling )
       
  2553         {
       
  2554         IAUPDATE_TRACE("[IAUPDATE] Cancel pressed while updating");
       
  2555         // Update flow is completed here.
       
  2556         // Notice, that this will also start the report sending,
       
  2557         // but we do not wait the sending to be complete before continuing.
       
  2558         UpdateCompleteL( KErrCancel );
       
  2559         }
       
  2560     else if ( state == ESendingReport )
       
  2561         {
       
  2562         IAUPDATE_TRACE("[IAUPDATE] Dialog cancel called while sending reports");
       
  2563         // Reports are sent only when update flow has finished.
       
  2564         // So, UpdateCompleteL has already been called and an update flow
       
  2565         // dialog is still being shown. Because cancel is called, complete 
       
  2566         // flow without waiting for the report sending to finish.
       
  2567         EndUpdateFlowL( KErrCancel ); 
       
  2568         }
       
  2569 
       
  2570     // Set the flag off because cancellation is over.
       
  2571     iCancelling = EFalse;
       
  2572 
       
  2573 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::HandleUserCancelL() end");
       
  2574     }
       
  2575 
       
  2576 
       
  2577 // ---------------------------------------------------------------------------
       
  2578 // CIAUpdateUiController::RestartedFromSelfUpdate
       
  2579 // 
       
  2580 // ---------------------------------------------------------------------------
       
  2581 //      
       
  2582 TBool CIAUpdateUiController::RestartedFromSelfUpdate()
       
  2583     {
       
  2584 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::RestartedFromSelfUpdate() begin");
       
  2585 	
       
  2586     TBool restarted( EFalse );
       
  2587     
       
  2588     CIAUpdateRestartInfo* info( iController->SelfUpdateRestartInfo() ); 
       
  2589     if ( info ) 
       
  2590         { 
       
  2591         // Restart info was available. 
       
  2592         delete info; 
       
  2593         info = NULL; 
       
  2594         restarted = ETrue; 
       
  2595         }    
       
  2596 
       
  2597 	IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateUiController::RestartedFromSelfUpdate() end: %d", 
       
  2598 	                 restarted);
       
  2599     
       
  2600     return restarted;
       
  2601     }
       
  2602 
       
  2603 
       
  2604 // ---------------------------------------------------------------------------
       
  2605 // CIAUpdateUiController::ParamsReadAndRemoveFileL
       
  2606 // 
       
  2607 // ---------------------------------------------------------------------------
       
  2608 //  
       
  2609 CIAUpdateParameters* CIAUpdateUiController::ParamsReadAndRemoveFileL()
       
  2610     {
       
  2611 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ParamsReadAndRemoveFileL() begin");
       
  2612 	
       
  2613     CIAUpdateParameters* params( NULL );
       
  2614 
       
  2615     CIAUpdateParametersFileManager* mgr( CIAUpdateParametersFileManager::NewLC() );
       
  2616     params = mgr->ReadL();
       
  2617     mgr->RemoveFile();
       
  2618     CleanupStack::PopAndDestroy( mgr );
       
  2619         
       
  2620 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ParamsReadAndRemoveFileL() end");    
       
  2621     
       
  2622     return params;
       
  2623     }
       
  2624 
       
  2625 
       
  2626 // ---------------------------------------------------------------------------
       
  2627 // CIAUpdateUiController::ParamsWriteFileL
       
  2628 // 
       
  2629 // ---------------------------------------------------------------------------
       
  2630 //  
       
  2631 void CIAUpdateUiController::ParamsWriteFileL()
       
  2632     {
       
  2633 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ParamsWriteFileL() begin");
       
  2634 	
       
  2635 	// Ownership is not transferred here.
       
  2636 	CIAUpdateParameters* params( iFilter->FilterParams() );
       
  2637 	if ( params )
       
  2638 	    {
       
  2639         CIAUpdateParametersFileManager* mgr( 
       
  2640             CIAUpdateParametersFileManager::NewLC() );
       
  2641         mgr->WriteL( *params );
       
  2642         CleanupStack::PopAndDestroy( mgr );
       
  2643 	    }
       
  2644 
       
  2645 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ParamsWriteFileL() end");    
       
  2646     }
       
  2647 
       
  2648 
       
  2649 // ---------------------------------------------------------------------------
       
  2650 // CIAUpdateUiController::ParamsRemoveFileL
       
  2651 // 
       
  2652 // ---------------------------------------------------------------------------
       
  2653 //  
       
  2654 void CIAUpdateUiController::ParamsRemoveFileL()
       
  2655     {
       
  2656 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ParamsRemoveFileL() begin");
       
  2657 	
       
  2658     CIAUpdateParametersFileManager* mgr( 
       
  2659         CIAUpdateParametersFileManager::NewL() );
       
  2660     mgr->RemoveFile();
       
  2661     delete mgr;
       
  2662     mgr = NULL;
       
  2663             
       
  2664 	IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::ParamsRemoveFileL() end");    
       
  2665     }
       
  2666 
       
  2667 
       
  2668 // ---------------------------------------------------------------------------
       
  2669 // CIAUpdateUiController::CreateSelectedNodesArrayL
       
  2670 // 
       
  2671 // ---------------------------------------------------------------------------
       
  2672 //
       
  2673 void CIAUpdateUiController::CreateSelectedNodesArrayL()
       
  2674     {
       
  2675     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CreateSelectedNodesArrayL() begin");
       
  2676     iSelectedNodesArray.Reset();
       
  2677     for ( TInt i = 0; i < iNodes.Count(); ++i )
       
  2678         {
       
  2679         if ( iNodes[ i ]->Base().IsSelected() )
       
  2680             {
       
  2681             iSelectedNodesArray.AppendL( iNodes[ i ] );
       
  2682             }
       
  2683         }
       
  2684 
       
  2685     // Dependency nodes to be updated before their dependants.
       
  2686     // Also, self update nodes should be handled correctly.
       
  2687     iSelectedNodesArray.Sort( 
       
  2688           TLinearOrder< MIAUpdateNode >( &SortSelectedNodes ) );
       
  2689     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::CreateSelectedNodesArrayL() end");
       
  2690     }
       
  2691 
       
  2692 // ---------------------------------------------------------------------------
       
  2693 // CIAUpdateUiController::IAUpdateEnabledL()
       
  2694 // ---------------------------------------------------------------------------
       
  2695 //
       
  2696 TBool CIAUpdateUiController::IAUpdateEnabledL() const
       
  2697     {
       
  2698     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::IAUpdateEnabledL() begin");
       
  2699     TBool enabled = EFalse;
       
  2700     RFeatureControl featureControl;
       
  2701     TInt error( KErrNone );
       
  2702 
       
  2703     error = featureControl.Connect();
       
  2704     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateUiController::IAUpdateEnabledL() Connection to the Feature Manager Server: %d", error);
       
  2705     
       
  2706     User::LeaveIfError( error );
       
  2707     
       
  2708     TUid iaupdatefeature;
       
  2709     iaupdatefeature.iUid = KFeatureIdIAUpdate;
       
  2710     
       
  2711     TInt ret = featureControl.FeatureSupported( iaupdatefeature );
       
  2712     if ( ret == KFeatureSupported )
       
  2713         {
       
  2714         enabled = ETrue;
       
  2715         }
       
  2716     featureControl.Close(); 
       
  2717     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateUiController::IAUpdateEnabledL() end");
       
  2718     return enabled;        
       
  2719     }
       
  2720 
       
  2721 // End of File