iaupdate/IAD/ui/src/iaupdateengine.cpp
changeset 42 d17dc5398051
parent 33 8110bf1194d1
child 44 329d304c1aa1
child 52 92f864ef0288
equal deleted inserted replaced
37:6e7b00453237 42:d17dc5398051
    43 #include "iaupdateresultsdialog.h"
    43 #include "iaupdateresultsdialog.h"
    44 #include "iaupdatedebug.h"
    44 #include "iaupdatedebug.h"
    45 
    45 
    46 
    46 
    47 IAUpdateEngine::IAUpdateEngine(QObject *parent)
    47 IAUpdateEngine::IAUpdateEngine(QObject *parent)
    48      : QObject(parent),
    48      : QObject(parent)
    49       iController(NULL),
       
    50       iFwUpdateHandler(NULL),
       
    51       iGlobalLockHandler(NULL),
       
    52       iIdle(NULL),
       
    53       iIdleAutCheck(NULL),
       
    54       iUpdateNow(EFalse),
       
    55       iRequestIssued(EFalse),
       
    56       iStartedFromApplication(EFalse),
       
    57       iUiRefreshAllowed(ETrue),
       
    58       iUpdatequeryUid(0)
       
    59 {
    49 {
    60     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::IAUpdateEngine() begin");
    50     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::IAUpdateEngine() begin");
       
    51     iController = NULL;
       
    52     iFwUpdateHandler = NULL;
       
    53     iGlobalLockHandler = NULL;
       
    54     iAutomaticCheck = NULL;
       
    55     iIdle = NULL;
       
    56     iIdleAutCheck = NULL;
    61     iEikEnv = CEikonEnv::Static();
    57     iEikEnv = CEikonEnv::Static();
       
    58     mUpdateNow = false;
       
    59     mRequestIssued = false;
       
    60     mStartedFromApplication = false;
       
    61     mUiRefreshAllowed = true;
       
    62     mWgId = 0;
       
    63     mUpdatequeryUid = 0;
       
    64     mDialogState = NoDialog;
       
    65     mResultsDialog = NULL;
    62     mServiceProvider = NULL;
    66     mServiceProvider = NULL;
    63     mServiceProvider = new IAUpdateServiceProvider( *this );
    67     mServiceProvider = new IAUpdateServiceProvider( *this );
    64     connect(mServiceProvider, SIGNAL(clientDisconnected()), this, SLOT(handleAllClientsClosed()));
    68     connect(mServiceProvider, SIGNAL(clientDisconnected()), this, SLOT(handleAllClientsClosed()));
    65     TRAP_IGNORE( iController = CIAUpdateUiController::NewL( *this ));
    69     TRAP_IGNORE( iController = CIAUpdateUiController::NewL( *this ));
    66     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::IAUpdateEngine() end");
    70     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::IAUpdateEngine() end");
    81         }
    85         }
    82     if (iGlobalLockHandler)
    86     if (iGlobalLockHandler)
    83         {
    87         {
    84         delete iGlobalLockHandler;
    88         delete iGlobalLockHandler;
    85         }
    89         }
       
    90     if ( iAutomaticCheck )
       
    91         {
       
    92         delete iAutomaticCheck;
       
    93         }
    86     if ( iController )
    94     if ( iController )
    87         {
    95         {
    88         delete iController;
    96         delete iController;
    89         }
    97         }
    90     if ( iFwUpdateHandler )
    98     if ( iFwUpdateHandler )
   101 // -----------------------------------------------------------------------------
   109 // -----------------------------------------------------------------------------
   102 // IAUpdateEngine::StartedByLauncherL
   110 // IAUpdateEngine::StartedByLauncherL
   103 // 
   111 // 
   104 // -----------------------------------------------------------------------------
   112 // -----------------------------------------------------------------------------
   105 //
   113 //
   106 void IAUpdateEngine::StartedByLauncherL( TBool aRefreshFromNetworkDenied )
   114 void IAUpdateEngine::StartedByLauncherL( bool aRefreshFromNetworkDenied )
   107     {
   115     {
   108     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartedByLauncherL() begin");
   116     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartedByLauncherL() begin");
   109     iRequestIssued = ETrue;
   117     mRequestIssued = true;
   110     iRequestType = IAUpdateUiDefines::ENoRequest;
   118     mRequestType = IAUpdateUiDefines::ENoRequest;
   111     iController->SetRequestType( iRequestType );
   119     iController->SetRequestType( mRequestType );
   112     SetVisibleL( ETrue );
   120     SetVisibleL( true );
   113     CIAUpdateParameters* params = iController->ParamsReadAndRemoveFileL();
   121     CIAUpdateParameters* params = iController->ParamsReadAndRemoveFileL();
   114     iController->CheckUpdatesDeferredL( params, aRefreshFromNetworkDenied );
   122     iController->CheckUpdatesDeferredL( params, aRefreshFromNetworkDenied );
   115     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartedByLauncherL() end");
   123     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartedByLauncherL() end");
   116     }
   124     }
   117 
   125 
   120 // 
   128 // 
   121 // -----------------------------------------------------------------------------
   129 // -----------------------------------------------------------------------------
   122 //
   130 //
   123 void IAUpdateEngine::CheckUpdatesRequestL( int wgid, 
   131 void IAUpdateEngine::CheckUpdatesRequestL( int wgid, 
   124                                            CIAUpdateParameters* aFilterParams,
   132                                            CIAUpdateParameters* aFilterParams,
   125                                            TBool aForcedRefresh )
   133                                            bool aForcedRefresh )
   126                                            
   134                                            
   127     {
   135     {
   128     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::CheckUpdatesRequestL() begin");
   136     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::CheckUpdatesRequestL() begin");
   129     SetClientWgId( wgid );
   137     SetClientWgId( wgid );
   130     iRequestIssued = ETrue;
   138     mRequestIssued = true;
   131     iStartedFromApplication  = ETrue;
   139     mStartedFromApplication  = true;
   132     CleanupStack::PushL( aFilterParams );
   140     CleanupStack::PushL( aFilterParams );
   133     if ( wgid > 0 )
   141     if ( wgid > 0 )
   134         {
   142         {
   135         HideApplicationInFSWL( ETrue );
   143         HideApplicationInFSWL( true );
   136         }
   144         }
   137     CleanupStack::Pop( aFilterParams );
   145     CleanupStack::Pop( aFilterParams );
   138     
   146     
   139     if ( !aFilterParams->ShowProgress() )
   147     if ( !aFilterParams->ShowProgress() )
   140         {
   148         {
   141         iEikEnv->RootWin().SetOrdinalPosition( -1, ECoeWinPriorityNeverAtFront ); 
   149         iEikEnv->RootWin().SetOrdinalPosition( -1, ECoeWinPriorityNeverAtFront ); 
   142         }
   150         }
   143            
   151            
   144     iRequestType = IAUpdateUiDefines::ECheckUpdates; 
   152     mRequestType = IAUpdateUiDefines::ECheckUpdates; 
   145     iController->SetRequestType( iRequestType );
   153     iController->SetRequestType( mRequestType );
   146     iController->SetForcedRefresh( aForcedRefresh );
   154     iController->SetForcedRefresh( aForcedRefresh );
   147     
   155     
   148     iController->CheckUpdatesDeferredL( aFilterParams, EFalse ); 
   156     iController->CheckUpdatesDeferredL( aFilterParams, false ); 
   149     
   157     
   150     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::CheckUpdatesRequestL() end");
   158     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::CheckUpdatesRequestL() end");
   151     }
   159     }
   152 
   160 
   153 // -----------------------------------------------------------------------------
   161 // -----------------------------------------------------------------------------
   157 // 
   165 // 
   158 void IAUpdateEngine::ShowUpdatesRequestL( int wgid, CIAUpdateParameters* aFilterParams )
   166 void IAUpdateEngine::ShowUpdatesRequestL( int wgid, CIAUpdateParameters* aFilterParams )
   159     {
   167     {
   160     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdatesRequestL() begin"); 
   168     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdatesRequestL() begin"); 
   161     SetClientWgId( wgid );
   169     SetClientWgId( wgid );
   162     iRequestIssued = ETrue;
   170     mRequestIssued = true;
   163 //    delete iBackgroundTimer;
   171 //    delete iBackgroundTimer;
   164 //    iBackgroundTimer = NULL;
   172 //    iBackgroundTimer = NULL;
   165     iStartedFromApplication  = ETrue;
   173     mStartedFromApplication  = true;
   166     CleanupStack::PushL( aFilterParams );
   174     CleanupStack::PushL( aFilterParams );
   167     if ( wgid > 0 )
   175     if ( wgid > 0 )
   168         {
   176         {
   169         HideApplicationInFSWL( ETrue );
   177         HideApplicationInFSWL( true );
   170         }
   178         }
   171    
   179    
   172     //StatusPane()->MakeVisible( ETrue );
   180     //StatusPane()->MakeVisible( true );
   173     iEikEnv->RootWin().SetOrdinalPosition( 0, ECoeWinPriorityNormal );
   181     iEikEnv->RootWin().SetOrdinalPosition( 0, ECoeWinPriorityNormal );
   174     
   182     
   175     //iRequestObserver = &aObserver;
   183     //iRequestObserver = &aObserver;
   176     iRequestType = IAUpdateUiDefines::EShowUpdates;
   184     mRequestType = IAUpdateUiDefines::EShowUpdates;
   177     iController->SetRequestType( iRequestType );
   185     iController->SetRequestType( mRequestType );
   178      
   186      
   179 
   187 
   180     //if ( !iMainView )
   188     //if ( !iMainView )
   181     //    {
   189     //    {
   182     //    iMainView  = CIAUpdateMainView::NewL( ClientRect() ); 
   190     //    iMainView  = CIAUpdateMainView::NewL( ClientRect() ); 
   187     // by pushing object to cleanup stack its destructor is called if leave happens
   195     // by pushing object to cleanup stack its destructor is called if leave happens
   188     // so global lock issued by this instance can be released in destructor of CIAUpdateGlobalLockHandler
   196     // so global lock issued by this instance can be released in destructor of CIAUpdateGlobalLockHandler
   189     CIAUpdateGlobalLockHandler* globalLockHandler = CIAUpdateGlobalLockHandler::NewLC();
   197     CIAUpdateGlobalLockHandler* globalLockHandler = CIAUpdateGlobalLockHandler::NewLC();
   190     if ( !globalLockHandler->InUseByAnotherInstanceL() )
   198     if ( !globalLockHandler->InUseByAnotherInstanceL() )
   191         {
   199         {
   192         globalLockHandler->SetToInUseForAnotherInstancesL( ETrue );
   200         globalLockHandler->SetToInUseForAnotherInstancesL( true );
   193         CleanupStack::Pop( globalLockHandler );
   201         CleanupStack::Pop( globalLockHandler );
   194         CleanupStack::Pop( aFilterParams );
   202         CleanupStack::Pop( aFilterParams );
   195         CleanupStack::PushL( globalLockHandler );
   203         CleanupStack::PushL( globalLockHandler );
   196         iController->CheckUpdatesDeferredL( aFilterParams, EFalse );
   204         iController->CheckUpdatesDeferredL( aFilterParams, false );
   197         CleanupStack::Pop( globalLockHandler ); 
   205         CleanupStack::Pop( globalLockHandler ); 
   198         delete iGlobalLockHandler;
   206         delete iGlobalLockHandler;
   199         iGlobalLockHandler = globalLockHandler;
   207         iGlobalLockHandler = globalLockHandler;
   200         //now possible deletion of iGlobalLockHandler in leave situation is handled
   208         //now possible deletion of iGlobalLockHandler in leave situation is handled
   201         //in HandleLeaveErrorL() and HandleLeaveErrorWithoutLeave methods. 
   209         //in HandleLeaveErrorL() and HandleLeaveErrorWithoutLeave methods. 
   215 // -----------------------------------------------------------------------------
   223 // -----------------------------------------------------------------------------
   216 // IAUpdateEngine::ShowUpdateQueryRequestL
   224 // IAUpdateEngine::ShowUpdateQueryRequestL
   217 // 
   225 // 
   218 // -----------------------------------------------------------------------------
   226 // -----------------------------------------------------------------------------
   219 //     
   227 //     
   220 void IAUpdateEngine::ShowUpdateQueryRequestL( int wgid, TUint aUid )
   228 void IAUpdateEngine::ShowUpdateQueryRequestL( int wgid, uint aUid )
   221     {
   229     {
   222     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryRequestL begin");
   230     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryRequestL begin");
   223     SetClientWgId( wgid );
   231     SetClientWgId( wgid );
   224     iRequestIssued = ETrue;
   232     mRequestIssued = true;
   225     iStartedFromApplication  = ETrue;
   233     mStartedFromApplication  = true;
   226     iUpdatequeryUid = aUid;
   234     mUpdatequeryUid = aUid;
   227     iUpdateNow = EFalse;
   235     mUpdateNow = false;
   228     if ( wgid > 0 )
   236     if ( wgid > 0 )
   229         {
   237         {
   230         HideApplicationInFSWL( ETrue );
   238         HideApplicationInFSWL( true );
   231         }
   239         }
   232     
   240     mRequestType = IAUpdateUiDefines::EUpdateQuery;
   233     //iRequestObserver = &aObserver;
       
   234     iRequestType = IAUpdateUiDefines::EUpdateQuery;
       
   235     
   241     
   236     
   242     
   237     delete iIdle;
   243     delete iIdle;
   238     iIdle = NULL;
   244     iIdle = NULL;
   239     iIdle = CIdle::NewL( CActive::EPriorityIdle ); 
   245     iIdle = CIdle::NewL( CActive::EPriorityIdle ); 
   244 // -----------------------------------------------------------------------------
   250 // -----------------------------------------------------------------------------
   245 // IAUpdateEngine::StartUpdate
   251 // IAUpdateEngine::StartUpdate
   246 // 
   252 // 
   247 // -----------------------------------------------------------------------------
   253 // -----------------------------------------------------------------------------
   248 //
   254 //
   249 void IAUpdateEngine::StartUpdate( TBool aFirmwareUpdate )
   255 void IAUpdateEngine::StartUpdate( bool aFirmwareUpdate )
   250     {
   256     {
   251     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartUpdate() begin");
   257     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartUpdate() begin");
   252     if ( aFirmwareUpdate )
   258     if ( aFirmwareUpdate )
   253         {
   259         {
   254         if ( !iFwUpdateHandler )
   260         if ( !iFwUpdateHandler )
   265         // by pushing object to cleanup stack it's destructor is called if leave happens
   271         // by pushing object to cleanup stack it's destructor is called if leave happens
   266         // so global lock issued by this instance can be released in destructor of CIAUpdateGlobalLockHandler
   272         // so global lock issued by this instance can be released in destructor of CIAUpdateGlobalLockHandler
   267         CIAUpdateGlobalLockHandler* globalLockHandler = CIAUpdateGlobalLockHandler::NewLC();
   273         CIAUpdateGlobalLockHandler* globalLockHandler = CIAUpdateGlobalLockHandler::NewLC();
   268         if ( !globalLockHandler->InUseByAnotherInstanceL() )
   274         if ( !globalLockHandler->InUseByAnotherInstanceL() )
   269             {
   275             {
   270             globalLockHandler->SetToInUseForAnotherInstancesL( ETrue );
   276             globalLockHandler->SetToInUseForAnotherInstancesL( true );
   271             // No need to be totally silent since the updating is started
   277             // No need to be totally silent since the updating is started
   272             // by user.
   278             // by user.
   273             SetDefaultConnectionMethodL( EFalse );
   279             SetDefaultConnectionMethodL( false );
   274             iController->StartUpdateL();
   280             iController->StartUpdateL();
   275             CleanupStack::Pop( globalLockHandler ); 
   281             CleanupStack::Pop( globalLockHandler ); 
   276             delete iGlobalLockHandler;
   282             delete iGlobalLockHandler;
   277             iGlobalLockHandler = globalLockHandler;
   283             iGlobalLockHandler = globalLockHandler;
   278             //now possible deletion of iGlobalLockHandler in leave situation is handled
   284             //now possible deletion of iGlobalLockHandler in leave situation is handled
   290 // -----------------------------------------------------------------------------
   296 // -----------------------------------------------------------------------------
   291 // IAUpdateEngine::SetVisibleL
   297 // IAUpdateEngine::SetVisibleL
   292 // 
   298 // 
   293 // -----------------------------------------------------------------------------
   299 // -----------------------------------------------------------------------------
   294 //  
   300 //  
   295 void IAUpdateEngine::SetVisibleL( TBool aVisible )
   301 void IAUpdateEngine::SetVisibleL( bool aVisible )
   296     {
   302     {
   297     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetVisibleL() begin");
   303     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetVisibleL() begin");
   298     IAUPDATE_TRACE_1("[IAUPDATE] visible: %d", aVisible );
   304     IAUPDATE_TRACE_1("[IAUPDATE] visible: %d", aVisible );
   299     /*if ( aVisible )
   305     /*if ( aVisible )
   300         {
   306         {
   319 // -----------------------------------------------------------------------------
   325 // -----------------------------------------------------------------------------
   320 // IAUpdateEngine::SetClientWgId
   326 // IAUpdateEngine::SetClientWgId
   321 // 
   327 // 
   322 // -----------------------------------------------------------------------------
   328 // -----------------------------------------------------------------------------
   323 // 
   329 // 
   324 void IAUpdateEngine::SetClientWgId( TInt aWgId )
   330 void IAUpdateEngine::SetClientWgId( int aWgId )
   325     {
   331     {
   326     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateEngine::SetClientWgId() wgId %d", aWgId );
   332     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateEngine::SetClientWgId() wgId %d", aWgId );
   327     iWgId = aWgId;
   333     mWgId = aWgId;
   328     }
   334     }
   329 
   335 
   330 // -----------------------------------------------------------------------------
   336 // -----------------------------------------------------------------------------
   331 // IAUpdateEngine::ClientInBackgroundL
   337 // IAUpdateEngine::ClientInBackgroundL
   332 // 
   338 // 
   333 // -----------------------------------------------------------------------------
   339 // -----------------------------------------------------------------------------
   334 // 
   340 // 
   335 TInt IAUpdateEngine::ClientInBackgroundL() const
   341 bool IAUpdateEngine::ClientInBackgroundL() const
   336     {
   342     {
   337     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ClientInBackgroundL() begin");
   343     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ClientInBackgroundL() begin");
   338     TBool inBackground = EFalse;
   344     bool inBackground = false;
   339     if ( iWgId > 0 )
   345     if ( mWgId > 0 )
   340         {
   346         {
   341         CArrayFixFlat<TInt>*  wgArray = new( ELeave ) CArrayFixFlat<TInt>(10);  
   347         CArrayFixFlat<int>*  wgArray = new( ELeave ) CArrayFixFlat<int>(10);  
   342         CleanupStack::PushL( wgArray );
   348         CleanupStack::PushL( wgArray );
   343         User::LeaveIfError( iEikEnv->WsSession().WindowGroupList( 0, wgArray ) );  
   349         User::LeaveIfError( iEikEnv->WsSession().WindowGroupList( 0, wgArray ) );  
   344         TInt ownWgId = iEikEnv->RootWin().Identifier();
   350         int ownWgId = iEikEnv->RootWin().Identifier();
   345         if ( ( wgArray->At( 0 ) != ownWgId ) && ( wgArray->At( 0 ) != iWgId  ) )
   351         if ( ( wgArray->At( 0 ) != ownWgId ) && ( wgArray->At( 0 ) != mWgId  ) )
   346             {
   352             {
   347             inBackground = ETrue;
   353             inBackground = true;
   348             }
   354             }
   349         CleanupStack::PopAndDestroy( wgArray );  
   355         CleanupStack::PopAndDestroy( wgArray );  
   350         }
   356         }
   351     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateEngine::ClientInBackgroundL() inBackground: %d", inBackground );
   357     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateEngine::ClientInBackgroundL() inBackground: %d", inBackground );
   352     return inBackground;  
   358     return inBackground;  
   363     qApp->quit(); 
   369     qApp->quit(); 
   364 }
   370 }
   365 
   371 
   366 
   372 
   367 // -----------------------------------------------------------------------------
   373 // -----------------------------------------------------------------------------
       
   374 // IAUpdateEngine::dialogFinished
       
   375 // Called when dialog is finished.
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 void IAUpdateEngine::dialogFinished(HbAction *action)
       
   379     {
       
   380     DialogState dialogState = mDialogState;
       
   381     mDialogState = NoDialog;
       
   382     
       
   383     switch ( dialogState )
       
   384         {
       
   385         case Results:
       
   386             mUiRefreshAllowed = true;
       
   387             if ( iController->ResultsInfo().iRebootAfterInstall )
       
   388                 {
       
   389                 ShowRebootDialogL();
       
   390                 }
       
   391             else
       
   392                 {
       
   393                 DoPossibleApplicationClose();
       
   394                 }
       
   395             break;
       
   396         case RebootQuery:    
       
   397             if (action == mPrimaryAction )
       
   398                 {
       
   399                 RStarterSession startersession;
       
   400                 if( startersession.Connect() == KErrNone )
       
   401                     {
       
   402                     startersession.Reset( RStarterSession::EUnknownReset );
       
   403                     startersession.Close();
       
   404                     }
       
   405                 }
       
   406             else
       
   407                 {
       
   408                 DoPossibleApplicationClose();
       
   409                 }
       
   410             break;
       
   411         case ShowUpdateQuery:    
       
   412             if (action == mPrimaryAction)
       
   413                 {
       
   414                 IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::dialogFinished() Now");
       
   415                 mUpdateNow = true;
       
   416                 }
       
   417             else if (action == mSecondaryAction)
       
   418                 {
       
   419                 IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::dialogFinished() Later");
       
   420                 CIAUpdateQueryHistory* updateQueryHistory = CIAUpdateQueryHistory::NewL();
       
   421                 CleanupStack::PushL( updateQueryHistory );
       
   422                 updateQueryHistory->SetTimeL( mUpdatequeryUid );
       
   423                 CleanupStack::PopAndDestroy( updateQueryHistory );
       
   424                 }
       
   425             InformRequestObserver( KErrNone );
       
   426             break;
       
   427         default: 
       
   428             break;
       
   429         }
       
   430     }
       
   431 
       
   432 
       
   433 
       
   434 // -----------------------------------------------------------------------------
   368 // IAUpdateEngine::StartupComplete
   435 // IAUpdateEngine::StartupComplete
   369 // 
   436 // 
   370 // -----------------------------------------------------------------------------
   437 // -----------------------------------------------------------------------------
   371 //    
   438 //    
   372 void IAUpdateEngine::StartupComplete( TInt aError )
   439 void IAUpdateEngine::StartupComplete( TInt aError )
   402     delete iGlobalLockHandler;
   469     delete iGlobalLockHandler;
   403     iGlobalLockHandler = NULL;
   470     iGlobalLockHandler = NULL;
   404     iGlobalLockHandler = CIAUpdateGlobalLockHandler::NewL();
   471     iGlobalLockHandler = CIAUpdateGlobalLockHandler::NewL();
   405     if ( !iGlobalLockHandler->InUseByAnotherInstanceL() )
   472     if ( !iGlobalLockHandler->InUseByAnotherInstanceL() )
   406         {
   473         {
   407         TBool totalSilent( EFalse );
   474         bool totalSilent(false);
   408         if ( iRequestType == IAUpdateUiDefines::ECheckUpdates )
   475         if ( mRequestType == IAUpdateUiDefines::ECheckUpdates )
   409             {
   476             {
   410             if ( iController->Filter() )
   477             if ( iController->Filter() )
   411                 {
   478                 {
   412                 if ( iController->Filter()->FilterParams() )
   479                 if ( iController->Filter()->FilterParams() )
   413                     {
   480                     {
   414                     if ( iController->Filter()->FilterParams()->Refresh() )
   481                     if ( iController->Filter()->FilterParams()->Refresh() )
   415                         {
   482                         {
   416                         if ( !iController->ForcedRefresh() )
   483                         if ( !iController->ForcedRefresh() )
   417                             {
   484                             {
   418                             //from bgchecker, make it silent
   485                             //from bgchecker, make it silent
   419                             totalSilent = ETrue;
   486                             totalSilent = true;
   420                             }
   487                             }
   421                         }
   488                         }
   422                     }
   489                     }
   423                 }
   490                 }
   424             }
   491             }
   425         SetDefaultConnectionMethodL( totalSilent );
   492         SetDefaultConnectionMethodL( totalSilent );
   426         iGlobalLockHandler->SetToInUseForAnotherInstancesL( ETrue );
   493         iGlobalLockHandler->SetToInUseForAnotherInstancesL(true);
   427         iController->StartRefreshL();  
   494         iController->StartRefreshL();  
   428         }
   495         }
   429     else
   496     else
   430         {
   497         {
   431         RefreshCompleteL( ETrue, KErrServerBusy );
   498         RefreshCompleteL( true, KErrServerBusy );
   432         }    
   499         }    
   433  
   500  
   434        
   501        
   435     
   502     
   436     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartupCompleteL() end");    
   503     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartupCompleteL() end");    
   493     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError );
   560     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError );
   494     //removal of iGlobalLockHandler releases possible global operation lock to other IAD instances
   561     //removal of iGlobalLockHandler releases possible global operation lock to other IAD instances
   495     delete iGlobalLockHandler;
   562     delete iGlobalLockHandler;
   496     iGlobalLockHandler = NULL;   
   563     iGlobalLockHandler = NULL;   
   497    
   564    
   498     if ( iRequestType == IAUpdateUiDefines::ECheckUpdates )
   565     if ( mRequestType == IAUpdateUiDefines::ECheckUpdates )
   499         {
   566         {
   500         InformRequestObserver( aError );
   567         InformRequestObserver( aError );
   501         }
   568         }
   502     else 
   569     else 
   503         {    
   570         {    
   505         //if ( aWithViewActivation)
   572         //if ( aWithViewActivation)
   506           //  {
   573           //  {
   507           //  ActivateLocalViewL( TUid::Uid( EIAUpdateMainViewId ) );
   574           //  ActivateLocalViewL( TUid::Uid( EIAUpdateMainViewId ) );
   508           //  }
   575           //  }
   509         CIAUpdateAgreement* agreement = CIAUpdateAgreement::NewLC();
   576         CIAUpdateAgreement* agreement = CIAUpdateAgreement::NewLC();
   510         TBool agreementAccepted = agreement->AgreementAcceptedL();
   577         bool agreementAccepted = agreement->AgreementAcceptedL();
   511         if ( iController->ForcedRefresh() )    
   578         if ( iController->ForcedRefresh() )    
   512             {
   579             {
   513             if ( !agreementAccepted )
   580             if ( !agreementAccepted )
   514                 {
   581                 {
   515                 agreement->SetAgreementAcceptedL();
   582                 agreement->SetAgreementAcceptedL();
   541     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::UpdateCompleteL begin");
   608     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::UpdateCompleteL begin");
   542     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError );
   609     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError );
   543     //removal of iGlobalLockHandler releases possible global operation lock to other IAD instances
   610     //removal of iGlobalLockHandler releases possible global operation lock to other IAD instances
   544     delete iGlobalLockHandler;
   611     delete iGlobalLockHandler;
   545     iGlobalLockHandler = NULL;  
   612     iGlobalLockHandler = NULL;  
   546     if ( iRequestType != IAUpdateUiDefines::ENoRequest )
   613     if ( mRequestType != IAUpdateUiDefines::ENoRequest )
   547         {
   614         {
   548         InformRequestObserver( aError );
   615         InformRequestObserver( aError );
   549         }
   616         }
   550     
   617     
   551     emit refresh( iController->Nodes(), iController->FwNodes(), KErrNone );
   618     emit refresh( iController->Nodes(), iController->FwNodes(), KErrNone );
   552          
   619          
   553     ShowResultsDialogDeferredL();
   620     ShowResultsDialogL();
   554                 
   621                 
   555     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::UpdateCompleteL end");
   622     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::UpdateCompleteL end");
   556     }
   623     }
   557 
   624 
   558 
   625 
   562 // 
   629 // 
   563 // -----------------------------------------------------------------------------
   630 // -----------------------------------------------------------------------------
   564 //   
   631 //   
   565 void IAUpdateEngine::ShowResultsDialogL()
   632 void IAUpdateEngine::ShowResultsDialogL()
   566     {
   633     {
   567     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogL() begin");
   634     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogL() begin"); 
   568                 
   635                 
   569     iUiRefreshAllowed = ETrue;
   636     mUiRefreshAllowed = false;
   570     IAUpdateResultsDialog resultsDialog;
   637     mResultsDialog = new IAUpdateResultsDialog(this);
   571     resultsDialog.showResults(iController->ResultsInfo());
   638     mResultsDialog->showResults(iController->ResultsInfo(),this,SLOT(dialogFinished(HbAction*)));
   572     
   639     mDialogState = Results;
   573     //TODO: How to recognise when application is closing 
       
   574     if ( iController->ResultsInfo().iRebootAfterInstall )
       
   575         {
       
   576         HbMessageBox messageBox(HbMessageBox::MessageTypeQuestion); 
       
   577         messageBox.setText(QString("Phone restart needed. Restart now?"));
       
   578         HbAction okAction("Ok");
       
   579         HbAction cancelAction("Cancel");
       
   580         messageBox.setPrimaryAction(&okAction);
       
   581         messageBox.setSecondaryAction(&cancelAction);
       
   582         messageBox.setTimeout(HbPopup::NoTimeout);
       
   583         messageBox.show();
       
   584         /*HbAction *selectedAction = messageBox.exec();
       
   585         if (selectedAction == messageBox.primaryAction())
       
   586             {
       
   587             RStarterSession startersession;
       
   588             if( startersession.Connect() == KErrNone )
       
   589                 {
       
   590                 startersession.Reset( RStarterSession::EUnknownReset );
       
   591                 startersession.Close();
       
   592                 return;
       
   593                 }
       
   594             }*/
       
   595         }
       
   596     if ( iStartedFromApplication && 
       
   597         iController->ResultsInfo().iCountCancelled == 0 &&
       
   598         iController->ResultsInfo().iCountFailed == 0 )
       
   599         {
       
   600         qApp->quit();
       
   601         }
       
   602     
       
   603     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateEngine::ShowResultsDialogL() nodes count: %d", iController->Nodes().Count() );
       
   604     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateEngine::ShowResultsDialogL() fw nodes: %d", iController->FwNodes().Count() );
       
   605     //exit from result view if there are no update left
       
   606     if ( iController->Nodes().Count() == 0 && iController->FwNodes().Count() == 0 )
       
   607         {
       
   608         qApp->quit();
       
   609         }
       
   610     
   640     
   611     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogL() end");
   641     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogL() end");
   612     }
   642     }
   613 
   643     
   614 // -----------------------------------------------------------------------------
   644 // -----------------------------------------------------------------------------
   615 // IAUpdateEngin::ShowResultsDialogDeferredL
   645 // IAUpdateEngine::ShowRebootDialogL
   616 // 
   646 // 
   617 // -----------------------------------------------------------------------------
   647 // -----------------------------------------------------------------------------
   618 //       
   648 //
   619 void IAUpdateEngine::ShowResultsDialogDeferredL()
   649 void IAUpdateEngine::ShowRebootDialogL()
   620     {
   650     {
   621     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogDeferredL() begin");
   651     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowRebootDialogL() begin");
   622     delete iIdle;
   652     
   623     iIdle = NULL;
   653     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   624     iIdle = CIdle::NewL( CActive::EPriorityIdle ); 
   654     messageBox->setText(QString("Phone restart needed. Restart now?"));
   625     iIdle->Start( TCallBack( ShowResultsDialogCallbackL, this ) ); 
   655     int actionCount = messageBox->actions().count();
   626     iUiRefreshAllowed = EFalse;
   656     for (int i=actionCount-1; i >= 0; i--)
   627     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogDeferredL() end");
   657     { 
   628     }
   658         messageBox->removeAction(messageBox->actions().at(i));
   629  
   659     }
   630 
   660     mPrimaryAction = NULL;
   631 
   661     mPrimaryAction = new HbAction("Ok");
       
   662     HbAction *secondaryAction = NULL;
       
   663     secondaryAction = new HbAction("Cancel");
       
   664 
       
   665     messageBox->addAction(mPrimaryAction);
       
   666     messageBox->addAction(secondaryAction);
       
   667     messageBox->setTimeout(HbPopup::NoTimeout);
       
   668     messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
   669     messageBox->open(this, SLOT(dialogFinished(HbAction*)));
       
   670     mDialogState = RebootQuery;
       
   671     
       
   672     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowRebootDialogL() end");
       
   673     }
   632 
   674 
   633 
   675 
   634 
   676 
   635 
   677 
   636 
   678 
   638 // -----------------------------------------------------------------------------
   680 // -----------------------------------------------------------------------------
   639 // IAUpdateEngine::InformRequestObserver
   681 // IAUpdateEngine::InformRequestObserver
   640 // 
   682 // 
   641 // -----------------------------------------------------------------------------
   683 // -----------------------------------------------------------------------------
   642 //      
   684 //      
   643 void IAUpdateEngine::InformRequestObserver( TInt aError )
   685 void IAUpdateEngine::InformRequestObserver( int aError )
   644     {
   686     {
   645     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::InformRequestObserver() begin");
   687     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::InformRequestObserver() begin");
   646         
   688         
   647     //if ( iRequestObserver )
   689     //if ( iRequestObserver )
   648     if ( iRequestIssued )    
   690     if ( mRequestIssued )    
   649         {
   691         {
   650         if ( iController->ClosingAllowedByClient() )
   692         if ( iController->ClosingAllowedByClient() )
   651             {
   693             {
   652             if ( iRequestType != IAUpdateUiDefines::ENoRequest )
   694             if ( mRequestType != IAUpdateUiDefines::ENoRequest )
   653                 {
   695                 {
   654 //                if ( iRequestType == IAUpdateUiDefines::EUpdateQuery && iUpdateNow )
   696 //                if ( iRequestType == IAUpdateUiDefines::EUpdateQuery && iUpdateNow )
   655 //                    {
   697 //                    {
   656 //                  if ( !iBackgroundTimer )
   698 //                  if ( !iBackgroundTimer )
   657 //                        {
   699 //                        {
   667                       iEikEnv->RootWin().SetOrdinalPosition( -1, ECoeWinPriorityNeverAtFront );
   709                       iEikEnv->RootWin().SetOrdinalPosition( -1, ECoeWinPriorityNeverAtFront );
   668 //                    }
   710 //                    }
   669                 }
   711                 }
   670             }
   712             }
   671         
   713         
   672         switch ( iRequestType )
   714         switch ( mRequestType )
   673             {
   715             {
   674             case IAUpdateUiDefines::ENoRequest:
   716             case IAUpdateUiDefines::ENoRequest:
   675                 {
   717                 {
   676                 mServiceProvider->completeLauncherLaunch( aError );
   718                 mServiceProvider->completeLauncherLaunch( aError );
   677                 break;
   719                 break;
   704                     }
   746                     }
   705                 break;
   747                 break;
   706                 }
   748                 }
   707             case IAUpdateUiDefines::EUpdateQuery:
   749             case IAUpdateUiDefines::EUpdateQuery:
   708                 {
   750                 {
   709                 mServiceProvider->completeUpdateQuery( iUpdateNow, aError );
   751                 mServiceProvider->completeUpdateQuery( mUpdateNow, aError );
   710                 break;
   752                 break;
   711                 }
   753                 }
   712             default:
   754             default:
   713                 {
   755                 {
   714                 break;
   756                 break;
   715                 }
   757                 }
   716             }
   758             }
   717 
   759 
   718         //iRequestObserver = NULL; 
   760         mRequestIssued = false;
   719         iRequestIssued = EFalse;
       
   720         }
   761         }
   721         
   762         
   722     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::InformRequestObserver() end");
   763     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::InformRequestObserver() end");
   723     }
   764     }
   724 
   765 
   726 // ---------------------------------------------------------------------------
   767 // ---------------------------------------------------------------------------
   727 // IAUpdateEngine::SetDefaultConnectionMethodL
   768 // IAUpdateEngine::SetDefaultConnectionMethodL
   728 // Sets the connection method for the update network connection.
   769 // Sets the connection method for the update network connection.
   729 // ---------------------------------------------------------------------------
   770 // ---------------------------------------------------------------------------
   730 //
   771 //
   731 void IAUpdateEngine::SetDefaultConnectionMethodL( TBool aTotalSilent )
   772 void IAUpdateEngine::SetDefaultConnectionMethodL( bool aTotalSilent )
   732     {
   773     {
   733     if ( aTotalSilent )
   774     if ( aTotalSilent )
   734         {
   775         {
   735         // from back ground checker, choose the IAP to make the internet access silent
   776         // from back ground checker, choose the IAP to make the internet access silent
   736         IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetDefaultConnectionMethodL() begin");
   777         IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetDefaultConnectionMethodL() begin");
   737 
   778 
   738            TUint32 connectionMethodId( 0 );
   779            uint connectionMethodId( 0 );
   739            TInt connMethodId( 0 );
   780            int connMethodId( 0 );
   740 
   781 
   741            // Let's first check whether cenrep contains SNAP id other than zero
   782            // Let's first check whether cenrep contains SNAP id other than zero
   742            CRepository* cenrep( CRepository::NewLC( KCRUidIAUpdateSettings ) );
   783            CRepository* cenrep( CRepository::NewLC( KCRUidIAUpdateSettings ) );
   743            User::LeaveIfError(  
   784            User::LeaveIfError(  
   744                cenrep->Get( KIAUpdateAccessPoint, connMethodId ) );
   785                cenrep->Get( KIAUpdateAccessPoint, connMethodId ) );
   825         }
   866         }
   826     else
   867     else
   827         {
   868         {
   828         // from grid, use the old logic
   869         // from grid, use the old logic
   829         IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetDefaultConnectionMethodL() begin");
   870         IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetDefaultConnectionMethodL() begin");
   830                   TUint32 connectionMethodId( 0 );
   871                   uint connectionMethodId( 0 );
   831                   TInt connMethodId( 0 );
   872                   int connMethodId( 0 );
   832 
   873 
   833                   // Set initial value to always ask
   874                   // Set initial value to always ask
   834                   TInt connectionMethodType( TIAUpdateConnectionMethod::EConnectionMethodTypeAlwaysAsk );
   875                   int connectionMethodType( TIAUpdateConnectionMethod::EConnectionMethodTypeAlwaysAsk );
   835                   TBool needSaving(EFalse);
   876                   bool needSaving(false);
   836 
   877 
   837                   // Let's first check whether cenrep contains SNAP id other than zero
   878                   // Let's first check whether cenrep contains SNAP id other than zero
   838                   CRepository* cenrep( CRepository::NewLC( KCRUidIAUpdateSettings ) );
   879                   CRepository* cenrep( CRepository::NewLC( KCRUidIAUpdateSettings ) );
   839                   User::LeaveIfError(  
   880                   User::LeaveIfError(  
   840                       cenrep->Get( KIAUpdateAccessPoint, connMethodId ) );
   881                       cenrep->Get( KIAUpdateAccessPoint, connMethodId ) );
   861                       cmManagerExt.OpenL();
   902                       cmManagerExt.OpenL();
   862                       CleanupClosePushL( cmManagerExt );
   903                       CleanupClosePushL( cmManagerExt );
   863                       iDestIdArray.Reset();
   904                       iDestIdArray.Reset();
   864                       cmManagerExt.AllDestinationsL( iDestIdArray );
   905                       cmManagerExt.AllDestinationsL( iDestIdArray );
   865 
   906 
   866                       for ( TInt i = 0; i< iDestIdArray.Count(); i++ )
   907                       for ( int i = 0; i< iDestIdArray.Count(); i++ )
   867                           {
   908                           {
   868                           RCmDestinationExt dest = cmManagerExt.DestinationL( iDestIdArray[i] );
   909                           RCmDestinationExt dest = cmManagerExt.DestinationL( iDestIdArray[i] );
   869                           CleanupClosePushL( dest );
   910                           CleanupClosePushL( dest );
   870                            
   911                            
   871                           if ( dest.MetadataL( CMManager::ESnapMetadataInternet ) )
   912                           if ( dest.MetadataL( CMManager::ESnapMetadataInternet ) )
   872                               {
   913                               {
   873                               // Check whether Internet SNAP contains any IAP.
   914                               // Check whether Internet SNAP contains any IAP.
   874                               if ( dest.ConnectionMethodCount() > 0 )
   915                               if ( dest.ConnectionMethodCount() > 0 )
   875                                   {
   916                                   {
   876                                   connectionMethodId = iDestIdArray[i];
   917                                   connectionMethodId = iDestIdArray[i];
   877                                   needSaving = ETrue;
   918                                   needSaving = true;
   878                                   IAUPDATE_TRACE_1("[IAUPDATE] connectionMethodId: %d", connectionMethodId );
   919                                   IAUPDATE_TRACE_1("[IAUPDATE] connectionMethodId: %d", connectionMethodId );
   879                                   }
   920                                   }
   880                               CleanupStack::PopAndDestroy( &dest ); 
   921                               CleanupStack::PopAndDestroy( &dest ); 
   881                               break;
   922                               break;
   882                               }
   923                               }
   899                       connectionMethodType = TIAUpdateConnectionMethod::EConnectionMethodTypeDestination;
   940                       connectionMethodType = TIAUpdateConnectionMethod::EConnectionMethodTypeDestination;
   900                       // Save to cenrep if needed
   941                       // Save to cenrep if needed
   901                       if ( needSaving )
   942                       if ( needSaving )
   902                           {
   943                           {
   903                           cenrep = CRepository::NewLC( KCRUidIAUpdateSettings );
   944                           cenrep = CRepository::NewLC( KCRUidIAUpdateSettings );
   904                           TInt err = cenrep->StartTransaction( CRepository::EReadWriteTransaction );
   945                           int err = cenrep->StartTransaction( CRepository::EReadWriteTransaction );
   905                           User::LeaveIfError( err );
   946                           User::LeaveIfError( err );
   906                           cenrep->CleanupCancelTransactionPushL();
   947                           cenrep->CleanupCancelTransactionPushL();
   907                           
   948                           
   908                           connMethodId = connectionMethodId;
   949                           connMethodId = connectionMethodId;
   909                           err = cenrep->Set( KIAUpdateAccessPoint, connMethodId );
   950                           err = cenrep->Set( KIAUpdateAccessPoint, connMethodId );
   930 // ---------------------------------------------------------------------------
   971 // ---------------------------------------------------------------------------
   931 // IAUpdateEngine::GetBestIAPInAllSNAPsL
   972 // IAUpdateEngine::GetBestIAPInAllSNAPsL
   932 // Sets the best IAP from all snaps
   973 // Sets the best IAP from all snaps
   933 // ---------------------------------------------------------------------------
   974 // ---------------------------------------------------------------------------
   934 //
   975 //
   935 TUint32 IAUpdateEngine::GetBestIAPInAllSNAPsL( RCmManagerExt& aCmManagerExt  )
   976 uint IAUpdateEngine::GetBestIAPInAllSNAPsL( RCmManagerExt& aCmManagerExt  )
   936     { 
   977     { 
   937     //go with internet SNAP first.
   978     //go with internet SNAP first.
   938     TUint32 IAPID = 0;
   979     uint IAPID = 0;
   939     IAPID = GetBestIAPInInternetSNAPL( aCmManagerExt );
   980     IAPID = GetBestIAPInInternetSNAPL( aCmManagerExt );
   940     
   981     
   941     if ( IAPID )
   982     if ( IAPID )
   942         {
   983         {
   943         return IAPID;
   984         return IAPID;
   945     
   986     
   946     //select IAP from rest of the SNAPs
   987     //select IAP from rest of the SNAPs
   947     iDestIdArray.Reset();
   988     iDestIdArray.Reset();
   948     aCmManagerExt.AllDestinationsL( iDestIdArray );
   989     aCmManagerExt.AllDestinationsL( iDestIdArray );
   949     
   990     
   950     for ( TInt i = 0; i< iDestIdArray.Count(); i++ )
   991     for ( int i = 0; i< iDestIdArray.Count(); i++ )
   951         {
   992         {
   952         TUint32 SNAPID = iDestIdArray[i];                   
   993         uint SNAPID = iDestIdArray[i];                   
   953         IAPID = GetBestIAPInThisSNAPL( aCmManagerExt, SNAPID );
   994         IAPID = GetBestIAPInThisSNAPL( aCmManagerExt, SNAPID );
   954         if ( IAPID )
   995         if ( IAPID )
   955             {
   996             {
   956             break;
   997             break;
   957             }
   998             }
   965 // ---------------------------------------------------------------------------
  1006 // ---------------------------------------------------------------------------
   966 // IAUpdateEngine::GetBestIAPInInternetSNAPL
  1007 // IAUpdateEngine::GetBestIAPInInternetSNAPL
   967 // Sets the best IAP from internet snap
  1008 // Sets the best IAP from internet snap
   968 // ---------------------------------------------------------------------------
  1009 // ---------------------------------------------------------------------------
   969 //
  1010 //
   970 TUint32 IAUpdateEngine::GetBestIAPInInternetSNAPL( RCmManagerExt& aCmManagerExt  )
  1011 uint IAUpdateEngine::GetBestIAPInInternetSNAPL( RCmManagerExt& aCmManagerExt  )
   971     {
  1012     {
   972     //select IAP from Internet SNAP
  1013     //select IAP from Internet SNAP
   973     iDestIdArray.Reset();
  1014     iDestIdArray.Reset();
   974     aCmManagerExt.AllDestinationsL( iDestIdArray );
  1015     aCmManagerExt.AllDestinationsL( iDestIdArray );
   975     TUint32 InternetSNAPID = 0;
  1016     uint InternetSNAPID = 0;
   976     for ( TInt i = 0; i< iDestIdArray.Count(); i++ )
  1017     for ( int i = 0; i< iDestIdArray.Count(); i++ )
   977         {
  1018         {
   978         RCmDestinationExt dest = aCmManagerExt.DestinationL( iDestIdArray[i] );
  1019         RCmDestinationExt dest = aCmManagerExt.DestinationL( iDestIdArray[i] );
   979         CleanupClosePushL( dest );
  1020         CleanupClosePushL( dest );
   980                                      
  1021                                      
   981         if ( dest.MetadataL( CMManager::ESnapMetadataInternet ) )
  1022         if ( dest.MetadataL( CMManager::ESnapMetadataInternet ) )
   996 // ---------------------------------------------------------------------------
  1037 // ---------------------------------------------------------------------------
   997 // IAUpdateEngine::GetBestIAPInThisSNAPL
  1038 // IAUpdateEngine::GetBestIAPInThisSNAPL
   998 // Sets the best IAP from the given snap
  1039 // Sets the best IAP from the given snap
   999 // ---------------------------------------------------------------------------
  1040 // ---------------------------------------------------------------------------
  1000 //
  1041 //
  1001 TUint32 IAUpdateEngine::GetBestIAPInThisSNAPL( RCmManagerExt& aCmManagerExt, TUint32 aSNAPID  )
  1042 uint IAUpdateEngine::GetBestIAPInThisSNAPL( RCmManagerExt& aCmManagerExt, uint aSNAPID  )
  1002     {
  1043     {
  1003     //get all usable IAPs
  1044     //get all usable IAPs
  1004     TConnMonIapInfoBuf iapInfo;
  1045     TConnMonIapInfoBuf iapInfo;
  1005     TRequestStatus status;
  1046     TRequestStatus status;
  1006                        
  1047                        
  1016     
  1057     
  1017     RCmDestinationExt dest = aCmManagerExt.DestinationL( aSNAPID );
  1058     RCmDestinationExt dest = aCmManagerExt.DestinationL( aSNAPID );
  1018     CleanupClosePushL( dest );
  1059     CleanupClosePushL( dest );
  1019     
  1060     
  1020     // Check whether the SNAP contains any IAP.
  1061     // Check whether the SNAP contains any IAP.
  1021     for  (TInt i = 0; i < dest.ConnectionMethodCount(); i++ )
  1062     for  (int i = 0; i < dest.ConnectionMethodCount(); i++ )
  1022         {
  1063         {
  1023         RCmConnectionMethodExt cm =  dest.ConnectionMethodL( i );
  1064         RCmConnectionMethodExt cm =  dest.ConnectionMethodL( i );
  1024         CleanupClosePushL( cm );
  1065         CleanupClosePushL( cm );
  1025         
  1066         
  1026         TUint32 iapid= cm.GetIntAttributeL( CMManager::ECmIapId );
  1067         uint iapid= cm.GetIntAttributeL( CMManager::ECmIapId );
  1027         
  1068         
  1028         for ( TInt i = 0; i < iapInfo().iCount; i++ )
  1069         for ( int i = 0; i < iapInfo().iCount; i++ )
  1029             {
  1070             {
  1030             if ( iapInfo().iIap[i].iIapId == iapid )
  1071             if ( iapInfo().iIap[i].iIapId == iapid )
  1031                 {
  1072                 {
  1032                 CleanupStack::PopAndDestroy( 2 ); //cm & dest;
  1073                 CleanupStack::PopAndDestroy( 2 ); //cm & dest;
  1033                 return iapid;
  1074                 return iapid;
  1052     CIAUpdateQueryHistory* updateQueryHistory = CIAUpdateQueryHistory::NewL();
  1093     CIAUpdateQueryHistory* updateQueryHistory = CIAUpdateQueryHistory::NewL();
  1053     // Get the delay information from the controller that has read it from
  1094     // Get the delay information from the controller that has read it from
  1054     // the config file.
  1095     // the config file.
  1055     updateQueryHistory->SetDelay( iController->ConfigData().QueryHistoryDelayHours() );
  1096     updateQueryHistory->SetDelay( iController->ConfigData().QueryHistoryDelayHours() );
  1056     CleanupStack::PushL( updateQueryHistory );
  1097     CleanupStack::PushL( updateQueryHistory );
  1057     if ( !updateQueryHistory->IsDelayedL( iUpdatequeryUid ) )
  1098     bool isDelayed( updateQueryHistory->IsDelayedL( mUpdatequeryUid ) );
       
  1099     CleanupStack::PopAndDestroy( updateQueryHistory );
       
  1100     if ( !isDelayed )
  1058         {
  1101         {
  1059         if ( ClientInBackgroundL() )
  1102         if ( ClientInBackgroundL() )
  1060             {
  1103             {
  1061             iEikEnv->RootWin().SetOrdinalPosition( -1, ECoeWinPriorityNormal );
  1104             iEikEnv->RootWin().SetOrdinalPosition( -1, ECoeWinPriorityNormal );
  1062             }
  1105             }
  1063         else
  1106         else
  1064             {
  1107             {
  1065             iEikEnv->RootWin().SetOrdinalPosition( 0, ECoeWinPriorityNormal );    
  1108             iEikEnv->RootWin().SetOrdinalPosition( 0, ECoeWinPriorityNormal );    
  1066             }
  1109             }
  1067  
  1110  
  1068         HbMessageBox messageBox(HbMessageBox::MessageTypeQuestion); 
  1111         HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion); 
  1069         messageBox.setText(QString("Application update is available from Nokia. Update?"));
  1112         messageBox->setText(QString("Application update is available from Nokia. Update?"));
  1070         HbAction nowAction("Now");
  1113         int actionCount = messageBox->actions().count();
  1071         HbAction laterAction("Later");
  1114         for (int i=actionCount-1; i >= 0; i--)
  1072         messageBox.setPrimaryAction(&nowAction);
  1115         { 
  1073         messageBox.setSecondaryAction(&laterAction);
  1116             messageBox->removeAction(messageBox->actions().at(i));
  1074         messageBox.setTimeout(HbPopup::NoTimeout);
  1117         }
  1075         messageBox.show();
  1118         mPrimaryAction = NULL;
  1076         iUpdateNow = ETrue;
  1119         mPrimaryAction = new HbAction("Now");
  1077         //HbAction *selectedAction = messageBox.exec();
  1120         mSecondaryAction = NULL;
  1078         
  1121         mSecondaryAction = new HbAction("Later");
  1079         /*if (selectedAction == messageBox.primaryAction())
  1122         messageBox->addAction(mPrimaryAction);
  1080             {
  1123         messageBox->addAction(mSecondaryAction);
  1081             IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryL() Now");
  1124         messageBox->setTimeout(HbPopup::NoTimeout);
  1082             iUpdateNow = ETrue;
  1125         messageBox->setAttribute(Qt::WA_DeleteOnClose);
  1083             }
  1126         messageBox->open(this, SLOT(dialogFinished(HbAction*)));
  1084         else if (selectedAction == messageBox.secondaryAction())
  1127         mDialogState = ShowUpdateQuery;
  1085             {
  1128         }
  1086             IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryL() Later");
  1129     else
  1087             updateQueryHistory->SetTimeL( iUpdatequeryUid );
  1130         {
  1088             }*/
  1131         InformRequestObserver( KErrNone );
  1089         }
  1132         }
  1090     CleanupStack::PopAndDestroy( updateQueryHistory );
  1133    
  1091     InformRequestObserver( KErrNone );  
       
  1092     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryL() end");
  1134     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryL() end");
  1093     }
  1135     }
  1094 
  1136 
  1095 
  1137 
  1096 
  1138 
  1097 // -----------------------------------------------------------------------------
  1139 // -----------------------------------------------------------------------------
  1098 // IAUpdateEngine::HideApplicationInFSWL
  1140 // IAUpdateEngine::HideApplicationInFSWL
  1099 // 
  1141 // 
  1100 // -----------------------------------------------------------------------------
  1142 // -----------------------------------------------------------------------------
  1101 //  
  1143 //  
  1102 void IAUpdateEngine::HideApplicationInFSWL( TBool aHide ) const
  1144 void IAUpdateEngine::HideApplicationInFSWL( bool aHide ) const
  1103     {
  1145     {
  1104     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HideApplicationInFSW() begin");
  1146     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HideApplicationInFSW() begin");
  1105     IAUPDATE_TRACE_1("[IAUPDATE] hide: %d", aHide );
  1147     IAUPDATE_TRACE_1("[IAUPDATE] hide: %d", aHide );
  1106     TInt id = iEikEnv->RootWin().Identifier();
  1148     int id = iEikEnv->RootWin().Identifier();
  1107 
  1149 
  1108     CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( 
  1150     CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( 
  1109             iEikEnv->WsSession(), id );
  1151             iEikEnv->WsSession(), id );
  1110     
  1152     
  1111     wgName->SetHidden( aHide );
  1153     wgName->SetHidden( aHide );
  1112     wgName->SetWindowGroupName( iEikEnv->RootWin() );    
  1154     wgName->SetWindowGroupName( iEikEnv->RootWin() );    
  1113     CleanupStack::PopAndDestroy( wgName ); 
  1155     CleanupStack::PopAndDestroy( wgName ); 
  1114     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HideApplicationInFSW() end");
  1156     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HideApplicationInFSW() end");
  1115     }
  1157     }
  1116 
       
  1117 // ---------------------------------------------------------------------------
       
  1118 // IAUpdateEngine::ShowResultsDialogCallbackL
       
  1119 // ---------------------------------------------------------------------------
       
  1120 //
       
  1121 TInt IAUpdateEngine::ShowResultsDialogCallbackL( TAny* aPtr )
       
  1122     {
       
  1123     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogCallbackL() begin");
       
  1124     IAUpdateEngine* engine = static_cast<IAUpdateEngine*>( aPtr );
       
  1125     //TRAPD( err, engine->ShowResultsDialogL() );
       
  1126     TRAP_IGNORE( engine->ShowResultsDialogL() );
       
  1127     //appUI->HandleLeaveErrorL( err );
       
  1128     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogCallbackL() end");
       
  1129     return KErrNone;
       
  1130     }
       
  1131 
       
  1132 
  1158 
  1133 // ---------------------------------------------------------------------------
  1159 // ---------------------------------------------------------------------------
  1134 // IAUpdateEngine::UpdateQueryCallbackL
  1160 // IAUpdateEngine::UpdateQueryCallbackL
  1135 // ---------------------------------------------------------------------------
  1161 // ---------------------------------------------------------------------------
  1136 //
  1162 //
  1156 TInt IAUpdateEngine::AutomaticCheckCallbackL( TAny* aPtr )    
  1182 TInt IAUpdateEngine::AutomaticCheckCallbackL( TAny* aPtr )    
  1157     {
  1183     {
  1158     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::AutomaticCheckCallbackL() begin");
  1184     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::AutomaticCheckCallbackL() begin");
  1159     IAUpdateEngine* engine= static_cast<IAUpdateEngine*>( aPtr ); 
  1185     IAUpdateEngine* engine= static_cast<IAUpdateEngine*>( aPtr ); 
  1160     
  1186     
  1161     TInt err = KErrNone;
  1187     int err = KErrNone;
  1162     CIAUpdateAutomaticCheck* automaticCheck = NULL;
  1188     if ( !engine->iAutomaticCheck )
  1163     TRAP( err, automaticCheck = CIAUpdateAutomaticCheck::NewL() ); 
  1189         {
       
  1190         TRAP( err, engine->iAutomaticCheck = CIAUpdateAutomaticCheck::NewL() ); 
       
  1191         }
  1164     if ( err != KErrNone )
  1192     if ( err != KErrNone )
  1165         {
  1193         {
  1166         engine->HandleLeaveErrorL( err );
  1194         engine->HandleLeaveErrorL( err );
  1167         }
  1195         }
  1168     else
  1196     else
  1169         {
  1197         {
  1170         CleanupStack::PushL( automaticCheck );
  1198         TRAP( err, engine->iAutomaticCheck->AcceptAutomaticCheckL() );
  1171         TRAP( err, automaticCheck->AcceptAutomaticCheckL() );
       
  1172         if ( err != KErrNone )
  1199         if ( err != KErrNone )
  1173             {
  1200             {
  1174             engine->HandleLeaveErrorL( err );
  1201             engine->HandleLeaveErrorL( err );
  1175             }   
  1202             }   
  1176         } 
  1203         } 
  1177     
  1204   
  1178     CleanupStack::PopAndDestroy( automaticCheck );
       
  1179     
       
  1180     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::AutomaticCheckCallbackL() end");
  1205     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::AutomaticCheckCallbackL() end");
  1181     return KErrNone;
  1206     return KErrNone;
  1182     }
  1207     }
  1183 
  1208 
  1184 
  1209 // ---------------------------------------------------------------------------
  1185 
  1210 // IAUpdateEngine::DoPossibleApplicationClose()
       
  1211 // ---------------------------------------------------------------------------
       
  1212 //  
       
  1213 void IAUpdateEngine::DoPossibleApplicationClose()
       
  1214     {
       
  1215     //exit from result view if there are no update left
       
  1216     if ( iController->Nodes().Count() == 0 && iController->FwNodes().Count() == 0 )
       
  1217         {
       
  1218         qApp->quit();
       
  1219         }
       
  1220     else if ( mStartedFromApplication && 
       
  1221         iController->ResultsInfo().iCountCancelled == 0 &&
       
  1222         iController->ResultsInfo().iCountFailed == 0 )
       
  1223         {
       
  1224         qApp->quit();
       
  1225         }
       
  1226     }
       
  1227