contentstorage/casoftwareregistry/s60/src/caprogresscanner.cpp
changeset 107 b34d53f6acdf
child 112 dbfb5e38438b
equal deleted inserted replaced
106:e78d6e055a5b 107:b34d53f6acdf
       
     1 /*
       
     2  * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  ?Description
       
    15  *
       
    16  */
       
    17 
       
    18 #include <s32mem.h>
       
    19 
       
    20 #include <usif/scr/scr.h>
       
    21 #include <usif/scr/screntries.h>
       
    22 
       
    23 #include "caprogresscanner.h"
       
    24 #include "caarraycleanup.inl"
       
    25 
       
    26 using namespace Usif;
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 EXPORT_C CCaProgresScanner* CCaProgresScanner::NewL( IUninstallObserver* aObserver )
       
    33     {
       
    34     CCaProgresScanner* self = new ( ELeave ) CCaProgresScanner( aObserver );
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop( self );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CCaProgresScanner::~CCaProgresScanner()
       
    46     {
       
    47     delete iNotifier;
       
    48     iSoftwareRegistry.Close();
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CCaProgresScanner::CCaProgresScanner( IUninstallObserver* aObserver ) :
       
    56     iObserver( aObserver )
       
    57     {
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CCaProgresScanner::ConstructL()
       
    65     {
       
    66     iNotifier = CSifOperationsNotifier::NewL( *this );
       
    67     User::LeaveIfError( iSoftwareRegistry.Connect() );//user leave if error.
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void CCaProgresScanner::StartOperationHandler( TUint aKey,
       
    75         const CSifOperationStartData& aStartData )
       
    76     {
       
    77     //TODO: temporary solution. Some error in scr was found
       
    78     if( aStartData.OperationPhase() == EUninstalling 
       
    79             || aStartData.OperationPhase() == EInstalling )
       
    80         {
       
    81         TRAP_IGNORE(
       
    82                 iComponentId = iSoftwareRegistry.GetComponentIdL(
       
    83                         aStartData.GlobalComponentId(), 
       
    84                         aStartData.SoftwareType() );
       
    85                 SubscribeL( aKey ) );
       
    86         }
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CCaProgresScanner::EndOperationHandler(
       
    94         const CSifOperationEndData& aEndData )
       
    95     {
       
    96     TRAP_IGNORE( EndOperationL( aEndData.ErrorCode() ) );
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CCaProgresScanner::ProgressOperationHandler(
       
   104         const CSifOperationProgressData& aProgressData )
       
   105     {
       
   106     TRAP_IGNORE( UpdateProgressL( aProgressData ) );
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CCaProgresScanner::UpdateProgressL(
       
   114         const CSifOperationProgressData& aProgressData )
       
   115     {
       
   116     if( aProgressData.Phase() == EUninstalling )
       
   117         {
       
   118         iObserver->progressChange( iComponentId, aProgressData.CurrentProgess() );
       
   119         }
       
   120     else
       
   121     	{
       
   122         //TODO: temporary solution. Some error in scr was found
       
   123         //Progress should be remove for different operation
       
   124         iObserver->progressChange( iComponentId, -1 );
       
   125 		CancelSubscribeL();
       
   126     	}
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CCaProgresScanner::EndOperationL( TInt aError )
       
   134     {
       
   135     if( aError == KErrNone )
       
   136         {
       
   137         iObserver->progressChange( iComponentId, 100 );
       
   138         }
       
   139     else
       
   140         {
       
   141         //information for observer that uninstallation was failed
       
   142         iObserver->progressChange( iComponentId, aError ); 
       
   143         }
       
   144     CancelSubscribeL();
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CCaProgresScanner::CancelSubscribeL()
       
   152 	{
       
   153 	iNotifier->CancelSubscribeL( iKey );
       
   154 	}
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void CCaProgresScanner::SubscribeL( TUint aKey )
       
   161     {
       
   162     iKey = aKey;
       
   163     iNotifier->SubscribeL( aKey, ETrue );
       
   164     iObserver->progressChange( iComponentId, 0 );
       
   165     }