iaupdate/IAD/ui/src/iaupdateengine.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
       
     2  * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:   This module contains the implementation of IAUpdateEngine
       
    15  *                class member functions.
       
    16  *
       
    17  */
       
    18 
       
    19 #include <qapplication.h>
       
    20 #include <hbmessagebox.h>
       
    21 #include <hbaction.h>
       
    22 #include <eikenv.h>
       
    23 #include <centralrepository.h>
       
    24 #include <cmmanager.h>
       
    25 #include <cmdestination.h>
       
    26 #include <rconnmon.h>
       
    27 #include <apgwgnam.h>
       
    28 #include <starterclient.h>
       
    29 
       
    30 #include "iaupdateengine.h"
       
    31 #include "iaupdateserviceprovider.h"
       
    32 #include "iaupdateuicontroller.h"
       
    33 #include "iaupdatefwupdatehandler.h"
       
    34 #include "iaupdategloballockhandler.h"
       
    35 #include "iaupdatenodefilter.h"
       
    36 #include "iaupdateresult.h"
       
    37 #include "iaupdateprivatecrkeys.h"
       
    38 #include "iaupdateuiconfigdata.h"
       
    39 #include "iaupdatequeryhistory.h"
       
    40 #include "iaupdateparameters.h"
       
    41 #include "iaupdateagreement.h"
       
    42 #include "iaupdateautomaticcheck.h"
       
    43 #include "iaupdateresultsdialog.h"
       
    44 #include "iaupdatedebug.h"
       
    45 
       
    46 IAUpdateEngine::IAUpdateEngine(QObject *parent) :
       
    47     QObject(parent)
       
    48     {
       
    49     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::IAUpdateEngine() begin");
       
    50     iController = NULL;
       
    51     iFwUpdateHandler = NULL;
       
    52     iGlobalLockHandler = NULL;
       
    53     iAutomaticCheck = NULL;
       
    54     iIdle = NULL;
       
    55     iIdleAutCheck = NULL;
       
    56     iEikEnv = CEikonEnv::Static();
       
    57     mUpdateNow = false;
       
    58     mRequestIssued = false;
       
    59     mStartedFromApplication = false;
       
    60     mUiRefreshAllowed = true;
       
    61     mWgId = 0;
       
    62     mUpdatequeryUid = 0;
       
    63     mDialogState = NoDialog;
       
    64     mResultsDialog = NULL;
       
    65     mServiceProvider = NULL;
       
    66     mServiceProvider = new IAUpdateServiceProvider(*this);
       
    67     connect(mServiceProvider, SIGNAL(clientDisconnected()), this,
       
    68             SLOT(handleAllClientsClosed()));
       
    69     TRAP_IGNORE( iController = CIAUpdateUiController::NewL( *this ));
       
    70     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::IAUpdateEngine() end");
       
    71     }
       
    72 
       
    73 IAUpdateEngine::~IAUpdateEngine()
       
    74     {
       
    75     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::~IAUpdateEngine() begin");
       
    76     InformRequestObserver(KErrCancel);
       
    77     if (iIdle)
       
    78         {
       
    79         delete iIdle;
       
    80         }
       
    81     if (iIdleAutCheck)
       
    82         {
       
    83         delete iIdleAutCheck;
       
    84         }
       
    85     if (iGlobalLockHandler)
       
    86         {
       
    87         delete iGlobalLockHandler;
       
    88         }
       
    89     if (iAutomaticCheck)
       
    90         {
       
    91         delete iAutomaticCheck;
       
    92         }
       
    93     if (iController)
       
    94         {
       
    95         delete iController;
       
    96         }
       
    97     if (iFwUpdateHandler)
       
    98         {
       
    99         delete iFwUpdateHandler;
       
   100         }
       
   101     if (mServiceProvider)
       
   102         {
       
   103         delete mServiceProvider;
       
   104         }
       
   105     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::~IAUpdateEngine() end");
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // IAUpdateEngine::StartedByLauncherL
       
   110 // 
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void IAUpdateEngine::StartedByLauncherL(bool aRefreshFromNetworkDenied)
       
   114     {
       
   115     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartedByLauncherL() begin");
       
   116     mRequestIssued = true;
       
   117     mRequestType = IAUpdateUiDefines::ENoRequest;
       
   118     iController->SetRequestType(mRequestType);
       
   119     SetVisibleL(true);
       
   120     CIAUpdateParameters* params = iController->ParamsReadAndRemoveFileL();
       
   121     iController->CheckUpdatesDeferredL(params, aRefreshFromNetworkDenied);
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // IAUpdateEngine::CheckUpdatesRequestL
       
   126 // 
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void IAUpdateEngine::CheckUpdatesRequestL(int wgid,
       
   130         CIAUpdateParameters* aFilterParams, bool aForcedRefresh)
       
   131 
       
   132     {
       
   133     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::CheckUpdatesRequestL() begin");
       
   134     SetClientWgId(wgid);
       
   135     mRequestIssued = true;
       
   136     mStartedFromApplication = true;
       
   137     CleanupStack::PushL(aFilterParams);
       
   138     if (wgid > 0)
       
   139         {
       
   140         HideApplicationInFSWL(true);
       
   141         }
       
   142     CleanupStack::Pop(aFilterParams);
       
   143 
       
   144     if (!aFilterParams->ShowProgress())
       
   145         {
       
   146         iEikEnv->RootWin().SetOrdinalPosition(-1, ECoeWinPriorityNeverAtFront);
       
   147         }
       
   148 
       
   149     mRequestType = IAUpdateUiDefines::ECheckUpdates;
       
   150     iController->SetRequestType(mRequestType);
       
   151     iController->SetForcedRefresh(aForcedRefresh);
       
   152 
       
   153     iController->CheckUpdatesDeferredL(aFilterParams, false);
       
   154 
       
   155     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::CheckUpdatesRequestL() end");
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // IAUpdateEngine::ShowUpdatesRequestL
       
   160 // 
       
   161 // -----------------------------------------------------------------------------
       
   162 // 
       
   163 void IAUpdateEngine::ShowUpdatesRequestL(int wgid,
       
   164         CIAUpdateParameters* aFilterParams)
       
   165     {
       
   166     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdatesRequestL() begin");
       
   167     SetClientWgId(wgid);
       
   168     mRequestIssued = true;
       
   169     //    delete iBackgroundTimer;
       
   170     //    iBackgroundTimer = NULL;
       
   171     mStartedFromApplication = true;
       
   172     CleanupStack::PushL(aFilterParams);
       
   173     if (wgid > 0)
       
   174         {
       
   175         HideApplicationInFSWL(true);
       
   176         }
       
   177 
       
   178     //StatusPane()->MakeVisible( true );
       
   179     iEikEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityNormal);
       
   180 
       
   181     //iRequestObserver = &aObserver;
       
   182     mRequestType = IAUpdateUiDefines::EShowUpdates;
       
   183     iController->SetRequestType(mRequestType);
       
   184 
       
   185     //if ( !iMainView )
       
   186     //    {
       
   187     //    iMainView  = CIAUpdateMainView::NewL( ClientRect() ); 
       
   188     //    AddViewL( iMainView );
       
   189     //    }
       
   190 
       
   191 
       
   192     // by pushing object to cleanup stack its destructor is called if leave happens
       
   193     // so global lock issued by this instance can be released in destructor of CIAUpdateGlobalLockHandler
       
   194     CIAUpdateGlobalLockHandler* globalLockHandler =
       
   195             CIAUpdateGlobalLockHandler::NewLC();
       
   196     if (!globalLockHandler->InUseByAnotherInstanceL())
       
   197         {
       
   198         globalLockHandler->SetToInUseForAnotherInstancesL(true);
       
   199         CleanupStack::Pop(globalLockHandler);
       
   200         CleanupStack::Pop(aFilterParams);
       
   201         CleanupStack::PushL(globalLockHandler);
       
   202         iController->CheckUpdatesDeferredL(aFilterParams, false);
       
   203         CleanupStack::Pop(globalLockHandler);
       
   204         delete iGlobalLockHandler;
       
   205         iGlobalLockHandler = globalLockHandler;
       
   206         //now possible deletion of iGlobalLockHandler in leave situation is handled
       
   207         //in HandleLeaveErrorL() and HandleLeaveErrorWithoutLeave methods. 
       
   208         }
       
   209     else
       
   210         {
       
   211         CleanupStack::PopAndDestroy(globalLockHandler);
       
   212         CleanupStack::PopAndDestroy(aFilterParams);
       
   213         // locked by another IAD instance, nothing else to do than just complete client's request.  
       
   214         InformRequestObserver(KErrNone);
       
   215         }
       
   216 
       
   217     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdatesRequestL() end");
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // IAUpdateEngine::ShowUpdateQueryRequestL
       
   222 // 
       
   223 // -----------------------------------------------------------------------------
       
   224 //     
       
   225 void IAUpdateEngine::ShowUpdateQueryRequestL(int wgid, uint aUid)
       
   226     {
       
   227     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryRequestL begin");
       
   228     SetClientWgId(wgid);
       
   229     mRequestIssued = true;
       
   230     mStartedFromApplication = true;
       
   231     mUpdatequeryUid = aUid;
       
   232     mUpdateNow = false;
       
   233     if (wgid > 0)
       
   234         {
       
   235         HideApplicationInFSWL(true);
       
   236         }
       
   237     mRequestType = IAUpdateUiDefines::EUpdateQuery;
       
   238 
       
   239     delete iIdle;
       
   240     iIdle = NULL;
       
   241     iIdle = CIdle::NewL(CActive::EPriorityIdle);
       
   242     iIdle->Start(TCallBack(UpdateQueryCallbackL, this));
       
   243     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryRequestL end")
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // IAUpdateEngine::StartUpdate
       
   248 // 
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 void IAUpdateEngine::StartUpdate(bool aFirmwareUpdate)
       
   252     {
       
   253     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartUpdate() begin");
       
   254     if (aFirmwareUpdate)
       
   255         {
       
   256         if (!iFwUpdateHandler)
       
   257             {
       
   258             TRAP_IGNORE( CIAUpdateFWUpdateHandler::NewL() );
       
   259             }
       
   260         if (iFwUpdateHandler)
       
   261             {
       
   262             iFwUpdateHandler->FirmWareUpdatewithFOTA();
       
   263             }
       
   264         }
       
   265     else
       
   266         {
       
   267         // by pushing object to cleanup stack it's destructor is called if leave happens
       
   268         // so global lock issued by this instance can be released in destructor of CIAUpdateGlobalLockHandler
       
   269         CIAUpdateGlobalLockHandler* globalLockHandler =
       
   270                 CIAUpdateGlobalLockHandler::NewLC();
       
   271         if (!globalLockHandler->InUseByAnotherInstanceL())
       
   272             {
       
   273             globalLockHandler->SetToInUseForAnotherInstancesL(true);
       
   274             // No need to be totally silent since the updating is started
       
   275             // by user.
       
   276             SetDefaultConnectionMethodL(false);
       
   277             iController->StartUpdateL();
       
   278             CleanupStack::Pop(globalLockHandler);
       
   279             delete iGlobalLockHandler;
       
   280             iGlobalLockHandler = globalLockHandler;
       
   281             //now possible deletion of iGlobalLockHandler in leave situation is handled
       
   282             //in HandleLeaveErrorL() and HandleLeaveErrorWithoutLeave methods. 
       
   283             }
       
   284         else
       
   285             {
       
   286             CleanupStack::PopAndDestroy(globalLockHandler);
       
   287             }
       
   288         }
       
   289     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartUpdate() end");
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // IAUpdateEngine::SetVisibleL
       
   294 // 
       
   295 // -----------------------------------------------------------------------------
       
   296 //  
       
   297 void IAUpdateEngine::SetVisibleL(bool /*aVisible*/)
       
   298     {
       
   299     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetVisibleL() begin");
       
   300     //IAUPDATE_TRACE_1("[IAUPDATE] visible: %d", aVisible );
       
   301     /*if ( aVisible )
       
   302      {
       
   303      if ( iEikonEnv->RootWin().OrdinalPosition() != 0 || iEikonEnv->RootWin().OrdinalPriority() != ECoeWinPriorityNormal )
       
   304      {
       
   305      iEikonEnv->RootWin().SetOrdinalPosition( 0, ECoeWinPriorityNormal );
       
   306      }
       
   307      
       
   308      StatusPane()->MakeVisible( ETrue );
       
   309      iMainView  = CIAUpdateMainView::NewL( ClientRect() ); 
       
   310      AddViewL( iMainView );
       
   311      ActivateLocalViewL( TUid::Uid( EIAUpdateMainViewId ) );
       
   312      }
       
   313      else
       
   314      {
       
   315      iEikonEnv->RootWin().SetOrdinalPosition( -1, ECoeWinPriorityNeverAtFront );
       
   316      StatusPane()->MakeVisible( EFalse );
       
   317      }*/
       
   318     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetVisibleL() end");
       
   319     }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // IAUpdateEngine::SetClientWgId
       
   323 // 
       
   324 // -----------------------------------------------------------------------------
       
   325 // 
       
   326 void IAUpdateEngine::SetClientWgId(int aWgId)
       
   327     {
       
   328     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateEngine::SetClientWgId() wgId %d", aWgId );
       
   329     mWgId = aWgId;
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // IAUpdateEngine::ClientInBackgroundL
       
   334 // 
       
   335 // -----------------------------------------------------------------------------
       
   336 // 
       
   337 bool IAUpdateEngine::ClientInBackgroundL() const
       
   338     {
       
   339     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ClientInBackgroundL() begin");
       
   340     bool inBackground = false;
       
   341     if (mWgId > 0)
       
   342         {
       
   343         CArrayFixFlat<int>* wgArray = new (ELeave) CArrayFixFlat<int> (10);
       
   344         CleanupStack::PushL(wgArray);
       
   345         User::LeaveIfError(iEikEnv->WsSession().WindowGroupList(0, wgArray));
       
   346         int ownWgId = iEikEnv->RootWin().Identifier();
       
   347         if ((wgArray->At(0) != ownWgId) && (wgArray->At(0) != mWgId))
       
   348             {
       
   349             inBackground = true;
       
   350             }
       
   351         CleanupStack::PopAndDestroy(wgArray);
       
   352         }
       
   353     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateEngine::ClientInBackgroundL() inBackground: %d", inBackground );
       
   354     return inBackground;
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // IAUpdateEngine::handleAllClientsClosed()
       
   359 // 
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 void IAUpdateEngine::handleAllClientsClosed()
       
   363     {
       
   364     qApp->quit();
       
   365     }
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // IAUpdateEngine::dialogFinished
       
   369 // Called when dialog is finished.
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 void IAUpdateEngine::dialogFinished(HbAction *action)
       
   373     {
       
   374     DialogState dialogState = mDialogState;
       
   375     mDialogState = NoDialog;
       
   376 
       
   377     switch (dialogState)
       
   378         {
       
   379         case Results:
       
   380             mUiRefreshAllowed = true;
       
   381             if (iController->ResultsInfo().iRebootAfterInstall)
       
   382                 {
       
   383                 ShowRebootDialogL();
       
   384                 }
       
   385             else
       
   386                 {
       
   387                 if (!DoPossibleApplicationClose())
       
   388                     {
       
   389                     iController->RefreshNodeList();
       
   390                     RefreshUI();
       
   391                     }
       
   392                 }
       
   393             break;
       
   394         case RebootQuery:
       
   395             if (action == mPrimaryAction)
       
   396                 {
       
   397                 RStarterSession startersession;
       
   398                 if (startersession.Connect() == KErrNone)
       
   399                     {
       
   400                     startersession.Reset(RStarterSession::EUnknownReset);
       
   401                     startersession.Close();
       
   402                     }
       
   403                 }
       
   404             else
       
   405                 {
       
   406                 if (!DoPossibleApplicationClose())
       
   407                     {
       
   408                     iController->RefreshNodeList();
       
   409                     RefreshUI();
       
   410                     }
       
   411                 }
       
   412             break;
       
   413         case ShowUpdateQuery:
       
   414             if (action == mPrimaryAction)
       
   415                 {
       
   416                 IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::dialogFinished() Now");
       
   417                 mUpdateNow = true;
       
   418                 }
       
   419             else if (action == mSecondaryAction)
       
   420                 {
       
   421                 IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::dialogFinished() Later");
       
   422                 CIAUpdateQueryHistory* updateQueryHistory =
       
   423                         CIAUpdateQueryHistory::NewL();
       
   424                 CleanupStack::PushL(updateQueryHistory);
       
   425                 updateQueryHistory->SetTimeL(mUpdatequeryUid);
       
   426                 CleanupStack::PopAndDestroy(updateQueryHistory);
       
   427                 }
       
   428             InformRequestObserver(KErrNone);
       
   429             break;
       
   430         default:
       
   431             break;
       
   432         }
       
   433     }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // IAUpdateEngine::StartupComplete
       
   437 // 
       
   438 // -----------------------------------------------------------------------------
       
   439 //    
       
   440 void IAUpdateEngine::StartupComplete(TInt aError)
       
   441     {
       
   442     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartupComplete() begin");
       
   443     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError);
       
   444 
       
   445     if (aError != KErrNone)
       
   446         {
       
   447         HandleLeaveErrorWithoutLeave(aError);
       
   448         }
       
   449     else
       
   450         {
       
   451         TRAPD( err, StartupCompleteL() );
       
   452         if (err != KErrNone)
       
   453             {
       
   454             HandleLeaveErrorWithoutLeave(err);
       
   455             }
       
   456         }
       
   457 
       
   458     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartupComplete() end");
       
   459     }
       
   460 
       
   461 // -----------------------------------------------------------------------------
       
   462 // IAUpdateEngine::StartupCompleteL
       
   463 // 
       
   464 // -----------------------------------------------------------------------------
       
   465 //    
       
   466 void IAUpdateEngine::StartupCompleteL()
       
   467     {
       
   468     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartupCompleteL() begin");
       
   469 
       
   470     delete iGlobalLockHandler;
       
   471     iGlobalLockHandler = NULL;
       
   472     iGlobalLockHandler = CIAUpdateGlobalLockHandler::NewL();
       
   473     if (!iGlobalLockHandler->InUseByAnotherInstanceL())
       
   474         {
       
   475         bool totalSilent(false);
       
   476         if (mRequestType == IAUpdateUiDefines::ECheckUpdates)
       
   477             {
       
   478             if (iController->Filter())
       
   479                 {
       
   480                 if (iController->Filter()->FilterParams())
       
   481                     {
       
   482                     if (iController->Filter()->FilterParams()->Refresh())
       
   483                         {
       
   484                         if (!iController->ForcedRefresh())
       
   485                             {
       
   486                             //from bgchecker, make it silent
       
   487                             totalSilent = true;
       
   488                             }
       
   489                         }
       
   490                     }
       
   491                 }
       
   492             }
       
   493         SetDefaultConnectionMethodL(totalSilent);
       
   494         iGlobalLockHandler->SetToInUseForAnotherInstancesL(true);
       
   495         iController->StartRefreshL();
       
   496         }
       
   497     else
       
   498         {
       
   499         RefreshCompleteL(true, KErrServerBusy);
       
   500         }
       
   501 
       
   502     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::StartupCompleteL() end");
       
   503     }
       
   504 
       
   505 // -----------------------------------------------------------------------------
       
   506 // IAUpdateEngine::HandleLeaveErrorL
       
   507 // 
       
   508 // -----------------------------------------------------------------------------
       
   509 //        
       
   510 void IAUpdateEngine::HandleLeaveErrorL(TInt aError)
       
   511     {
       
   512     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HandleLeaveErrorL() begin");
       
   513     //removal of iGlobalLockHandler releases possible global operation lock to other IAD instances
       
   514     delete iGlobalLockHandler;
       
   515     iGlobalLockHandler = NULL;
       
   516     // client request is completed before leave in case of leave error
       
   517     if (aError != KErrNone)
       
   518         {
       
   519         InformRequestObserver(aError);
       
   520         User::Leave(aError);
       
   521         }
       
   522 
       
   523     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HandleLeaveErrorL() end");
       
   524     }
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // IAUpdateEngine::HandleLeaveErrorWithoutLeave
       
   528 // 
       
   529 // -----------------------------------------------------------------------------
       
   530 //  
       
   531 void IAUpdateEngine::HandleLeaveErrorWithoutLeave(TInt aError)
       
   532     {
       
   533     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HandleLeaveErrorWithoutLeave() begin");
       
   534     //removal of iGlobalLockHandler releases possible global operation lock to other IAD instances
       
   535     delete iGlobalLockHandler;
       
   536     iGlobalLockHandler = NULL;
       
   537     if (aError != KErrNone)
       
   538         {
       
   539         InformRequestObserver(aError);
       
   540         }
       
   541     if (aError == KErrDiskFull)
       
   542         {
       
   543         //TRAP_IGNORE( ShowGlobalErrorNoteL( aError ) );
       
   544         }
       
   545     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HandleLeaveErrorWithoutLeave end");
       
   546     }
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // IAUpdateEngine::RefreshUI
       
   550 // 
       
   551 // -----------------------------------------------------------------------------
       
   552 // 
       
   553 void IAUpdateEngine::RefreshUI()
       
   554     {
       
   555     emit refresh(iController->Nodes(), iController->FwNodes(), KErrNone);
       
   556     }
       
   557 
       
   558 // -----------------------------------------------------------------------------
       
   559 // IAUpdateEngine::RefreshCompleteL
       
   560 // 
       
   561 // -----------------------------------------------------------------------------
       
   562 //      
       
   563 void IAUpdateEngine::RefreshCompleteL(TBool /*aWithViewActivation*/,
       
   564         TInt aError)
       
   565     {
       
   566     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::RefreshCompleteL() begin");
       
   567     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError );
       
   568     //removal of iGlobalLockHandler releases possible global operation lock to other IAD instances
       
   569     delete iGlobalLockHandler;
       
   570     iGlobalLockHandler = NULL;
       
   571 
       
   572     if (mRequestType == IAUpdateUiDefines::ECheckUpdates)
       
   573         {
       
   574         InformRequestObserver(aError);
       
   575         }
       
   576     else
       
   577         {
       
   578         emit refresh(iController->Nodes(), iController->FwNodes(), aError);
       
   579         //if ( aWithViewActivation)
       
   580         //  {
       
   581         //  ActivateLocalViewL( TUid::Uid( EIAUpdateMainViewId ) );
       
   582         //  }
       
   583         CIAUpdateAgreement* agreement = CIAUpdateAgreement::NewLC();
       
   584         bool agreementAccepted = agreement->AgreementAcceptedL();
       
   585         if (iController->ForcedRefresh())
       
   586             {
       
   587             if (!agreementAccepted)
       
   588                 {
       
   589                 agreement->SetAgreementAcceptedL();
       
   590                 }
       
   591             }
       
   592         CleanupStack::PopAndDestroy(agreement);
       
   593         // By calling CIdle possible waiting dialog can be closed before
       
   594         // automatic check where a new dialog may be launched
       
   595         delete iIdleAutCheck;
       
   596         iIdleAutCheck = NULL;
       
   597         iIdleAutCheck = CIdle::NewL(CActive::EPriorityIdle);
       
   598         iIdleAutCheck->Start(TCallBack(AutomaticCheckCallbackL, this));
       
   599         }
       
   600 
       
   601     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::RefreshCompleteL() end");
       
   602     }
       
   603 
       
   604 // -----------------------------------------------------------------------------
       
   605 // IAUpdateEngine::UpdateCompleteL
       
   606 // 
       
   607 // -----------------------------------------------------------------------------
       
   608 //     
       
   609 void IAUpdateEngine::UpdateCompleteL(TInt aError)
       
   610     {
       
   611     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::UpdateCompleteL begin");
       
   612     IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", aError );
       
   613     //removal of iGlobalLockHandler releases possible global operation lock to other IAD instances
       
   614     delete iGlobalLockHandler;
       
   615     iGlobalLockHandler = NULL;
       
   616     if (mRequestType != IAUpdateUiDefines::ENoRequest)
       
   617         {
       
   618         InformRequestObserver(aError);
       
   619         }
       
   620 
       
   621     ShowResultsDialogL();
       
   622 
       
   623     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::UpdateCompleteL end");
       
   624     }
       
   625 
       
   626 // -----------------------------------------------------------------------------
       
   627 // IAUpdateEngine::ShowResultsDialogL
       
   628 // 
       
   629 // -----------------------------------------------------------------------------
       
   630 //   
       
   631 void IAUpdateEngine::ShowResultsDialogL()
       
   632     {
       
   633     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogL() begin");
       
   634 
       
   635     mUiRefreshAllowed = false;
       
   636     mResultsDialog = new IAUpdateResultsDialog(this);
       
   637     mResultsDialog->showResults(iController->ResultsInfo(), this,
       
   638             SLOT(dialogFinished(HbAction*)));
       
   639     mDialogState = Results;
       
   640 
       
   641     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowResultsDialogL() end");
       
   642     }
       
   643 
       
   644 // -----------------------------------------------------------------------------
       
   645 // IAUpdateEngine::ShowRebootDialogL
       
   646 // 
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 void IAUpdateEngine::ShowRebootDialogL()
       
   650     {
       
   651     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowRebootDialogL() begin");
       
   652 
       
   653     HbMessageBox *messageBox = new HbMessageBox(
       
   654             HbMessageBox::MessageTypeQuestion);
       
   655     messageBox->setText(QString("Phone restart needed. Restart now?"));
       
   656     int actionCount = messageBox->actions().count();
       
   657     for (int i = actionCount - 1; i >= 0; i--)
       
   658         {
       
   659         messageBox->removeAction(messageBox->actions().at(i));
       
   660         }
       
   661     mPrimaryAction = NULL;
       
   662     mPrimaryAction = new HbAction("Ok");
       
   663     HbAction *secondaryAction = NULL;
       
   664     secondaryAction = new HbAction("Cancel");
       
   665 
       
   666     messageBox->addAction(mPrimaryAction);
       
   667     messageBox->addAction(secondaryAction);
       
   668     messageBox->setTimeout(HbPopup::NoTimeout);
       
   669     messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
   670     messageBox->open(this, SLOT(dialogFinished(HbAction*)));
       
   671     mDialogState = RebootQuery;
       
   672 
       
   673     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowRebootDialogL() end");
       
   674     }
       
   675 
       
   676 // -----------------------------------------------------------------------------
       
   677 // IAUpdateEngine::InformRequestObserver
       
   678 // 
       
   679 // -----------------------------------------------------------------------------
       
   680 //      
       
   681 void IAUpdateEngine::InformRequestObserver(int aError)
       
   682     {
       
   683     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::InformRequestObserver() begin");
       
   684 
       
   685     //if ( iRequestObserver )
       
   686     if (mRequestIssued)
       
   687         {
       
   688         if (iController->ClosingAllowedByClient())
       
   689             {
       
   690             if (mRequestType != IAUpdateUiDefines::ENoRequest)
       
   691                 {
       
   692                 //                if ( iRequestType == IAUpdateUiDefines::EUpdateQuery && iUpdateNow )
       
   693                 //                    {
       
   694                 //                  if ( !iBackgroundTimer )
       
   695                 //                        {
       
   696                 //                        iBackgroundTimer = CIAUpdateUITimer::NewL( *this, CIAUpdateUITimer::EBackgroundDelay );
       
   697                 //                        }
       
   698                 //                 if ( !iBackgroundTimer->IsActive() )
       
   699                 //                        {
       
   700                 //                        iBackgroundTimer->After( 500000 );
       
   701                 //                        }
       
   702                 //                    }
       
   703                 //                 else
       
   704                 //                    {
       
   705                 iEikEnv->RootWin().SetOrdinalPosition(-1,
       
   706                         ECoeWinPriorityNeverAtFront);
       
   707                 //                    }
       
   708                 }
       
   709             }
       
   710 
       
   711         switch (mRequestType)
       
   712             {
       
   713             case IAUpdateUiDefines::ENoRequest:
       
   714                 {
       
   715                 mServiceProvider->completeLauncherLaunch(aError);
       
   716                 break;
       
   717                 }
       
   718             case IAUpdateUiDefines::ECheckUpdates:
       
   719                 {
       
   720                 mServiceProvider->completeCheckUpdates(
       
   721                         iController->CountOfAvailableUpdates(), aError);
       
   722                 break;
       
   723                 }
       
   724             case IAUpdateUiDefines::EShowUpdates:
       
   725                 {
       
   726                 CIAUpdateResult* result(NULL);
       
   727                 TRAPD( error, result = CIAUpdateResult::NewL() )
       
   728                 if (result)
       
   729                     {
       
   730                     TIAUpdateResultsInfo resultsInfo(
       
   731                             iController->ResultsInfo());
       
   732                     IAUPDATE_TRACE_3("[IAUPDATE] IAUpdateEngine::InformRequestObserver succeed: %d failed: %d  cancelled: %d",
       
   733                             resultsInfo.iCountSuccessfull,
       
   734                             resultsInfo.iCountFailed,
       
   735                             resultsInfo.iCountCancelled );
       
   736                     result->SetSuccessCount(resultsInfo.iCountSuccessfull);
       
   737                     result->SetFailCount(resultsInfo.iCountFailed);
       
   738                     result->SetCancelCount(resultsInfo.iCountCancelled);
       
   739                     mServiceProvider->completeShowUpdates(result, aError);
       
   740                     // Ownership of result is transferred here.
       
   741                     }
       
   742                 else
       
   743                     {
       
   744                     mServiceProvider->completeShowUpdates(NULL, error);
       
   745                     }
       
   746                 break;
       
   747                 }
       
   748             case IAUpdateUiDefines::EUpdateQuery:
       
   749                 {
       
   750                 mServiceProvider->completeUpdateQuery(mUpdateNow, aError);
       
   751                 break;
       
   752                 }
       
   753             default:
       
   754                 {
       
   755                 break;
       
   756                 }
       
   757             }
       
   758 
       
   759         mRequestIssued = false;
       
   760         }
       
   761 
       
   762     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::InformRequestObserver() end");
       
   763     }
       
   764 
       
   765 // ---------------------------------------------------------------------------
       
   766 // IAUpdateEngine::SetDefaultConnectionMethodL
       
   767 // Sets the connection method for the update network connection.
       
   768 // ---------------------------------------------------------------------------
       
   769 //
       
   770 void IAUpdateEngine::SetDefaultConnectionMethodL(bool aTotalSilent)
       
   771     {
       
   772     if (aTotalSilent)
       
   773         {
       
   774         // from back ground checker, choose the IAP to make the internet access silent
       
   775         IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetDefaultConnectionMethodL() begin");
       
   776 
       
   777         uint connectionMethodId(0);
       
   778         int connMethodId(0);
       
   779 
       
   780         // Let's first check whether cenrep contains SNAP id other than zero
       
   781         CRepository* cenrep(CRepository::NewLC(KCRUidIAUpdateSettings));
       
   782         User::LeaveIfError(cenrep->Get(KIAUpdateAccessPoint, connMethodId));
       
   783         CleanupStack::PopAndDestroy(cenrep);
       
   784         cenrep = NULL;
       
   785 
       
   786         RCmManager cmManager;
       
   787         cmManager.OpenL();
       
   788         CleanupClosePushL(cmManager);
       
   789 
       
   790         if (connMethodId == -1)
       
   791             {
       
   792             IAUPDATE_TRACE("[IAUPDATE] user chooses default connection, use IAP logic");
       
   793 
       
   794             //check what is the default connection by users     
       
   795 
       
   796             TCmDefConnValue DCSetting;
       
   797             cmManager.ReadDefConnL(DCSetting);
       
   798 
       
   799             switch (DCSetting.iType)
       
   800                 {
       
   801                 case ECmDefConnAlwaysAsk:
       
   802                 case ECmDefConnAskOnce:
       
   803                     {
       
   804                     //go with the best IAP under internet snap
       
   805                     connectionMethodId = GetBestIAPInAllSNAPsL(cmManager);
       
   806                     break;
       
   807                     }
       
   808                 case ECmDefConnDestination:
       
   809                     {
       
   810                     //go with the best IAP under this snap
       
   811                     connectionMethodId = GetBestIAPInThisSNAPL(cmManager,
       
   812                             DCSetting.iId);
       
   813                     break;
       
   814                     }
       
   815                 case ECmDefConnConnectionMethod:
       
   816                     {
       
   817                     //go with the best IAP under this snap
       
   818                     connectionMethodId = DCSetting.iId;
       
   819                     break;
       
   820                     }
       
   821                 }
       
   822             }
       
   823         else if (connMethodId == 0)
       
   824             {
       
   825             //no choice from user, we go with the best IAP under Internent SNAP
       
   826             connectionMethodId = GetBestIAPInAllSNAPsL(cmManager);
       
   827             }
       
   828         else
       
   829             {
       
   830             IAUPDATE_TRACE("[IAUPDATE] use chooses a snap");
       
   831             // It was some SNAP value
       
   832             connectionMethodId = GetBestIAPInThisSNAPL(cmManager,
       
   833                     connMethodId);
       
   834             }
       
   835 
       
   836         CleanupStack::PopAndDestroy(&cmManager);
       
   837 
       
   838         if (connectionMethodId != 0)
       
   839             {
       
   840             TIAUpdateConnectionMethod
       
   841                     connectionMethod(
       
   842                             connectionMethodId,
       
   843                             TIAUpdateConnectionMethod::EConnectionMethodTypeAccessPoint);
       
   844 
       
   845             iController->SetDefaultConnectionMethodL(connectionMethod);
       
   846             }
       
   847         else
       
   848             {
       
   849             //In the totally silent case, if no usable IAP, we complete the check update with 0 updates.
       
   850             //the bgchecker will try again later after 1 month. 
       
   851             //The LEAVE will be catched up later and complete the request from background checker.
       
   852             User::LeaveIfError(KErrNotFound);
       
   853             }
       
   854         IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetDefaultConnectionMethodL() end");
       
   855         }
       
   856     else
       
   857         {
       
   858         // from grid, use the old logic
       
   859         IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetDefaultConnectionMethodL() begin");
       
   860         uint connectionMethodId(0);
       
   861         int connMethodId(0);
       
   862 
       
   863         // Set initial value to always ask
       
   864         int connectionMethodType(
       
   865                 TIAUpdateConnectionMethod::EConnectionMethodTypeAlwaysAsk);
       
   866         bool needSaving(false);
       
   867 
       
   868         // Let's first check whether cenrep contains SNAP id other than zero
       
   869         CRepository* cenrep(CRepository::NewLC(KCRUidIAUpdateSettings));
       
   870         User::LeaveIfError(cenrep->Get(KIAUpdateAccessPoint, connMethodId));
       
   871         CleanupStack::PopAndDestroy(cenrep);
       
   872         cenrep = NULL;
       
   873 
       
   874         if (connMethodId == -1)
       
   875             {
       
   876             IAUPDATE_TRACE("[IAUPDATE] user chooses default connection, use IAP logic");
       
   877 
       
   878             connectionMethodId = 0;
       
   879             connectionMethodType
       
   880                     = TIAUpdateConnectionMethod::EConnectionMethodTypeDefault;
       
   881             }
       
   882         else if (connMethodId == 0)
       
   883             {
       
   884             IAUPDATE_TRACE("[IAUPDATE] use chooses nothing, use internal IAP logic");
       
   885             //if nothing is set by user, use our new logic
       
   886             //SetDefaultConnectionMethod2L();
       
   887             //return;
       
   888             // CenRep didn't contain any SNAP id. Let's try Internet SNAP then.
       
   889 
       
   890             RCmManager cmManager;
       
   891             cmManager.OpenL();
       
   892             CleanupClosePushL(cmManager);
       
   893             iDestIdArray.Reset();
       
   894             cmManager.AllDestinationsL(iDestIdArray);
       
   895 
       
   896             for (int i = 0; i < iDestIdArray.Count(); i++)
       
   897                 {
       
   898                 RCmDestination dest = cmManager.DestinationL(iDestIdArray[i]);
       
   899                 CleanupClosePushL(dest);
       
   900 
       
   901                 if (dest.MetadataL(CMManager::ESnapMetadataInternet))
       
   902                     {
       
   903                     // Check whether Internet SNAP contains any IAP.
       
   904                     if (dest.ConnectionMethodCount() > 0)
       
   905                         {
       
   906                         connectionMethodId = iDestIdArray[i];
       
   907                         needSaving = true;
       
   908                         IAUPDATE_TRACE_1("[IAUPDATE] connectionMethodId: %d", connectionMethodId );
       
   909                         }
       
   910                     CleanupStack::PopAndDestroy(&dest);
       
   911                     break;
       
   912                     }
       
   913 
       
   914                 CleanupStack::PopAndDestroy(&dest);
       
   915                 }
       
   916             iDestIdArray.Reset();
       
   917             CleanupStack::PopAndDestroy(&cmManager);
       
   918             }
       
   919         else
       
   920             {
       
   921             IAUPDATE_TRACE("[IAUPDATE] use chooses a snap");
       
   922             // It was some SNAP value
       
   923             connectionMethodId = connMethodId;
       
   924             }
       
   925 
       
   926         if (connectionMethodId > 0)
       
   927             {
       
   928             // We have now some valid SNAP id, either from CenRep or Internet SNAP
       
   929             connectionMethodType
       
   930                     = TIAUpdateConnectionMethod::EConnectionMethodTypeDestination;
       
   931             // Save to cenrep if needed
       
   932             if (needSaving)
       
   933                 {
       
   934                 cenrep = CRepository::NewLC(KCRUidIAUpdateSettings);
       
   935                 int err = cenrep->StartTransaction(
       
   936                         CRepository::EReadWriteTransaction);
       
   937                 User::LeaveIfError(err);
       
   938                 cenrep->CleanupCancelTransactionPushL();
       
   939 
       
   940                 connMethodId = connectionMethodId;
       
   941                 err = cenrep->Set(KIAUpdateAccessPoint, connMethodId);
       
   942                 User::LeaveIfError(err);
       
   943                 TUint32 ignore = KErrNone;
       
   944                 User::LeaveIfError(cenrep->CommitTransaction(ignore));
       
   945                 CleanupStack::PopAndDestroy(); // CleanupCancelTransactionPushL()
       
   946                 CleanupStack::PopAndDestroy(cenrep);
       
   947                 }
       
   948             }
       
   949 
       
   950         TIAUpdateConnectionMethod
       
   951                 connectionMethod(
       
   952                         connectionMethodId,
       
   953                         static_cast<TIAUpdateConnectionMethod::TConnectionMethodType> (connectionMethodType));
       
   954 
       
   955         iController->SetDefaultConnectionMethodL(connectionMethod);
       
   956 
       
   957         IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::SetDefaultConnectionMethodL() end");
       
   958         }
       
   959     }
       
   960 
       
   961 // ---------------------------------------------------------------------------
       
   962 // IAUpdateEngine::GetBestIAPInAllSNAPsL
       
   963 // Sets the best IAP from all snaps
       
   964 // ---------------------------------------------------------------------------
       
   965 //
       
   966 uint IAUpdateEngine::GetBestIAPInAllSNAPsL(RCmManager& aCmManager)
       
   967     {
       
   968     //go with internet SNAP first.
       
   969     uint IAPID = 0;
       
   970     IAPID = GetBestIAPInInternetSNAPL(aCmManager);
       
   971 
       
   972     if (IAPID)
       
   973         {
       
   974         return IAPID;
       
   975         }
       
   976 
       
   977     //select IAP from rest of the SNAPs
       
   978     iDestIdArray.Reset();
       
   979     aCmManager.AllDestinationsL(iDestIdArray);
       
   980 
       
   981     for (int i = 0; i < iDestIdArray.Count(); i++)
       
   982         {
       
   983         uint SNAPID = iDestIdArray[i];
       
   984         IAPID = GetBestIAPInThisSNAPL(aCmManager, SNAPID);
       
   985         if (IAPID)
       
   986             {
       
   987             break;
       
   988             }
       
   989         }
       
   990     iDestIdArray.Reset();
       
   991     return IAPID;
       
   992     }
       
   993 
       
   994 // ---------------------------------------------------------------------------
       
   995 // IAUpdateEngine::GetBestIAPInInternetSNAPL
       
   996 // Sets the best IAP from internet snap
       
   997 // ---------------------------------------------------------------------------
       
   998 //
       
   999 uint IAUpdateEngine::GetBestIAPInInternetSNAPL(RCmManager& aCmManager)
       
  1000     {
       
  1001     //select IAP from Internet SNAP
       
  1002     iDestIdArray.Reset();
       
  1003     aCmManager.AllDestinationsL(iDestIdArray);
       
  1004     uint InternetSNAPID = 0;
       
  1005     for (int i = 0; i < iDestIdArray.Count(); i++)
       
  1006         {
       
  1007         RCmDestination dest = aCmManager.DestinationL(iDestIdArray[i]);
       
  1008         CleanupClosePushL(dest);
       
  1009 
       
  1010         if (dest.MetadataL(CMManager::ESnapMetadataInternet))
       
  1011             {
       
  1012             InternetSNAPID = iDestIdArray[i];
       
  1013             CleanupStack::PopAndDestroy(&dest);
       
  1014             break;
       
  1015             }
       
  1016         CleanupStack::PopAndDestroy(&dest);
       
  1017         }
       
  1018     iDestIdArray.Reset();
       
  1019 
       
  1020     return GetBestIAPInThisSNAPL(aCmManager, InternetSNAPID);
       
  1021     }
       
  1022 
       
  1023 // ---------------------------------------------------------------------------
       
  1024 // IAUpdateEngine::GetBestIAPInThisSNAPL
       
  1025 // Sets the best IAP from the given snap
       
  1026 // ---------------------------------------------------------------------------
       
  1027 //
       
  1028 uint IAUpdateEngine::GetBestIAPInThisSNAPL(RCmManager& aCmManager,
       
  1029         uint aSNAPID)
       
  1030     {
       
  1031     //get all usable IAPs
       
  1032     TConnMonIapInfoBuf iapInfo;
       
  1033     TRequestStatus status;
       
  1034 
       
  1035     RConnectionMonitor connMon;
       
  1036     connMon.ConnectL();
       
  1037     CleanupClosePushL(connMon);
       
  1038 
       
  1039     connMon.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iapInfo,
       
  1040             status);
       
  1041     User::WaitForRequest(status);
       
  1042     User::LeaveIfError(status.Int());
       
  1043 
       
  1044     CleanupStack::PopAndDestroy(&connMon);
       
  1045 
       
  1046     RCmDestination dest = aCmManager.DestinationL(aSNAPID);
       
  1047     CleanupClosePushL(dest);
       
  1048 
       
  1049     // Check whether the SNAP contains any IAP.
       
  1050     for (int i = 0; i < dest.ConnectionMethodCount(); i++)
       
  1051         {
       
  1052         RCmConnectionMethod cm = dest.ConnectionMethodL(i);
       
  1053         CleanupClosePushL(cm);
       
  1054 
       
  1055         uint iapid = cm.GetIntAttributeL(CMManager::ECmIapId);
       
  1056 
       
  1057         for (int i = 0; i < iapInfo().iCount; i++)
       
  1058             {
       
  1059             if (iapInfo().iIap[i].iIapId == iapid)
       
  1060                 {
       
  1061                 CleanupStack::PopAndDestroy(2); //cm & dest;
       
  1062                 return iapid;
       
  1063                 }
       
  1064             }
       
  1065 
       
  1066         CleanupStack::PopAndDestroy(&cm);
       
  1067         }
       
  1068 
       
  1069     CleanupStack::PopAndDestroy(&dest);
       
  1070     return 0;
       
  1071     }
       
  1072 
       
  1073 // -----------------------------------------------------------------------------
       
  1074 // IAUpdateEngine::ShowUpdateQueryL
       
  1075 // 
       
  1076 // -----------------------------------------------------------------------------
       
  1077 //    
       
  1078 void IAUpdateEngine::ShowUpdateQueryL()
       
  1079     {
       
  1080     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryL() begin");
       
  1081     CIAUpdateQueryHistory* updateQueryHistory = CIAUpdateQueryHistory::NewL();
       
  1082     // Get the delay information from the controller that has read it from
       
  1083     // the config file.
       
  1084     updateQueryHistory->SetDelay(
       
  1085             iController->ConfigData().QueryHistoryDelayHours());
       
  1086     CleanupStack::PushL(updateQueryHistory);
       
  1087     bool isDelayed(updateQueryHistory->IsDelayedL(mUpdatequeryUid));
       
  1088     CleanupStack::PopAndDestroy(updateQueryHistory);
       
  1089     if (!isDelayed)
       
  1090         {
       
  1091         if (ClientInBackgroundL())
       
  1092             {
       
  1093             iEikEnv->RootWin().SetOrdinalPosition(-1, ECoeWinPriorityNormal);
       
  1094             }
       
  1095         else
       
  1096             {
       
  1097             iEikEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityNormal);
       
  1098             }
       
  1099 
       
  1100         HbMessageBox *messageBox = new HbMessageBox(
       
  1101                 HbMessageBox::MessageTypeQuestion);
       
  1102         messageBox->setText(QString(
       
  1103                 "Application update is available from Nokia. Update?"));
       
  1104         int actionCount = messageBox->actions().count();
       
  1105         for (int i = actionCount - 1; i >= 0; i--)
       
  1106             {
       
  1107             messageBox->removeAction(messageBox->actions().at(i));
       
  1108             }
       
  1109         mPrimaryAction = NULL;
       
  1110         mPrimaryAction = new HbAction("Now");
       
  1111         mSecondaryAction = NULL;
       
  1112         mSecondaryAction = new HbAction("Later");
       
  1113         messageBox->addAction(mPrimaryAction);
       
  1114         messageBox->addAction(mSecondaryAction);
       
  1115         messageBox->setTimeout(HbPopup::NoTimeout);
       
  1116         messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
  1117         messageBox->open(this, SLOT(dialogFinished(HbAction*)));
       
  1118         mDialogState = ShowUpdateQuery;
       
  1119         }
       
  1120     else
       
  1121         {
       
  1122         InformRequestObserver(KErrNone);
       
  1123         }
       
  1124 
       
  1125     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::ShowUpdateQueryL() end");
       
  1126     }
       
  1127 
       
  1128 // -----------------------------------------------------------------------------
       
  1129 // IAUpdateEngine::HideApplicationInFSWL
       
  1130 // 
       
  1131 // -----------------------------------------------------------------------------
       
  1132 //  
       
  1133 void IAUpdateEngine::HideApplicationInFSWL(bool aHide) const
       
  1134     {
       
  1135     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HideApplicationInFSW() begin");
       
  1136     IAUPDATE_TRACE_1("[IAUPDATE] hide: %d", aHide );
       
  1137     int id = iEikEnv->RootWin().Identifier();
       
  1138 
       
  1139     CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(
       
  1140             iEikEnv->WsSession(), id);
       
  1141 
       
  1142     wgName->SetHidden(aHide);
       
  1143     wgName->SetWindowGroupName(iEikEnv->RootWin());
       
  1144     CleanupStack::PopAndDestroy(wgName);
       
  1145     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::HideApplicationInFSW() end");
       
  1146     }
       
  1147 
       
  1148 // ---------------------------------------------------------------------------
       
  1149 // IAUpdateEngine::UpdateQueryCallbackL
       
  1150 // ---------------------------------------------------------------------------
       
  1151 //
       
  1152 TInt IAUpdateEngine::UpdateQueryCallbackL(TAny* aPtr)
       
  1153     {
       
  1154     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::UpdateQueryCallbackL() begin");
       
  1155     IAUpdateEngine* engine = static_cast<IAUpdateEngine*> (aPtr);
       
  1156     //TRAPD( err, engine->ShowUpdateQueryL() );
       
  1157     TRAP_IGNORE( engine->ShowUpdateQueryL() );
       
  1158     //if ( err != KErrNone )
       
  1159     //    {
       
  1160     //    appUI->HandleLeaveErrorL( err );
       
  1161     //    }
       
  1162     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::UpdateQueryCallbackL() end");
       
  1163     return KErrNone;
       
  1164     }
       
  1165 
       
  1166 // ---------------------------------------------------------------------------
       
  1167 // IAUpdateEngine::AutomaticCheckCallbackL
       
  1168 // ---------------------------------------------------------------------------
       
  1169 //    
       
  1170 
       
  1171 TInt IAUpdateEngine::AutomaticCheckCallbackL(TAny* aPtr)
       
  1172     {
       
  1173     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::AutomaticCheckCallbackL() begin");
       
  1174     IAUpdateEngine* engine = static_cast<IAUpdateEngine*> (aPtr);
       
  1175 
       
  1176     int err = KErrNone;
       
  1177     if (!engine->iAutomaticCheck)
       
  1178         {
       
  1179         TRAP( err, engine->iAutomaticCheck = CIAUpdateAutomaticCheck::NewL() );
       
  1180         }
       
  1181     if (err != KErrNone)
       
  1182         {
       
  1183         engine->HandleLeaveErrorL(err);
       
  1184         }
       
  1185     else
       
  1186         {
       
  1187         TRAP( err, engine->iAutomaticCheck->AcceptAutomaticCheckL() );
       
  1188         if (err != KErrNone)
       
  1189             {
       
  1190             engine->HandleLeaveErrorL(err);
       
  1191             }
       
  1192         }
       
  1193 
       
  1194     IAUPDATE_TRACE("[IAUPDATE] IAUpdateEngine::AutomaticCheckCallbackL() end");
       
  1195     return KErrNone;
       
  1196     }
       
  1197 
       
  1198 // ---------------------------------------------------------------------------
       
  1199 // IAUpdateEngine::DoPossibleApplicationClose()
       
  1200 // ---------------------------------------------------------------------------
       
  1201 //  
       
  1202 bool IAUpdateEngine::DoPossibleApplicationClose()
       
  1203     {
       
  1204     //exit from result view if there are no update left
       
  1205     bool toBeClosed = false;
       
  1206     if (iController->Nodes().Count() == 0 && iController->FwNodes().Count()
       
  1207             == 0)
       
  1208         {
       
  1209         toBeClosed = true;
       
  1210         }
       
  1211     else if (mStartedFromApplication
       
  1212             && iController->ResultsInfo().iCountCancelled == 0
       
  1213             && iController->ResultsInfo().iCountFailed == 0)
       
  1214         {
       
  1215         toBeClosed = true;
       
  1216         }
       
  1217     if (toBeClosed)
       
  1218         {
       
  1219         qApp->quit();
       
  1220         }
       
  1221     return toBeClosed;
       
  1222     }
       
  1223