contentstorage/srvsrc/caprogressnotifier.cpp
changeset 102 8b8b34fa9751
parent 100 0920c6a9b6c8
child 106 e78d6e055a5b
equal deleted inserted replaced
100:0920c6a9b6c8 102:8b8b34fa9751
     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 "caprogressnotifier.h"
       
    24 #include "castorageproxy.h"
       
    25 #include "cainnerquery.h"
       
    26 #include "cainnerentry.h"
       
    27 #include "caarraycleanup.inl"
       
    28 
       
    29 using namespace Usif;
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C CCaProgressNotifier* CCaProgressNotifier::NewL(
       
    36         CCaStorageProxy& aCaStorageProxy )
       
    37     {
       
    38     CCaProgressNotifier* self = new ( ELeave ) CCaProgressNotifier(
       
    39             aCaStorageProxy );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CCaProgressNotifier::~CCaProgressNotifier()
       
    51     {
       
    52     delete iNotifier;
       
    53     iResultArrayItems.ResetAndDestroy();
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CCaProgressNotifier::CCaProgressNotifier( CCaStorageProxy& aCaStorageProxy ) :
       
    61     iStorageProxy( aCaStorageProxy )
       
    62     {
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CCaProgressNotifier::ConstructL()
       
    70     {
       
    71     iNotifier = CSifOperationsNotifier::NewL( *this );
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CCaProgressNotifier::StartOperationHandler( TUint aKey,
       
    79         const CSifOperationStartData& aStartData )
       
    80     {
       
    81     TInt err( KErrNone );
       
    82     TComponentId componentId;
       
    83     iResultArrayItems.ResetAndDestroy();
       
    84 
       
    85     TRAP(err, componentId = ComponentIdL( aStartData.GlobalComponentId(),
       
    86                     aStartData.SoftwareType() ));
       
    87     if ( !err )
       
    88         TRAP(err, MarkEntrysForUnistallL(aKey, componentId));
       
    89 
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CCaProgressNotifier::EndOperationHandler(
       
    97         const CSifOperationEndData& aEndData )
       
    98     {
       
    99     TInt err = KErrNone;
       
   100     TRAP(err, EndOperationL(aEndData.ErrorCode()));
       
   101     iResultArrayItems.ResetAndDestroy();
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CCaProgressNotifier::ProgressOperationHandler(
       
   109         const CSifOperationProgressData& aProgressData )
       
   110     {
       
   111     TInt err = KErrNone;
       
   112     TRAP(err, UpdateProgressL(aProgressData));
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CCaProgressNotifier::UpdateProgressL(
       
   120         const CSifOperationProgressData& aProgressData )
       
   121     {
       
   122     RBuf totalProgressBuf;
       
   123     totalProgressBuf.CleanupClosePushL();
       
   124     totalProgressBuf.CreateL( sizeof(TComponentId) + 1 );
       
   125     totalProgressBuf.AppendNum( aProgressData.CurrentProgess() );
       
   126 
       
   127     if ( iResultArrayItems.Count() && aProgressData.Phase() == EUninstalling )
       
   128         {
       
   129         for ( int i = 0; i < iResultArrayItems.Count(); i++ )
       
   130             {
       
   131             iResultArrayItems[i]->AddAttributeL( KCaAppUninstallProgress,
       
   132                     totalProgressBuf );
       
   133             iStorageProxy.AddL( iResultArrayItems[i], ETrue,
       
   134                     EItemUninstallProgressChanged );
       
   135             }
       
   136         }
       
   137 
       
   138     CleanupStack::PopAndDestroy( &totalProgressBuf );
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CCaProgressNotifier::EndOperationL( TInt aError )
       
   146     {
       
   147     if ( aError )
       
   148         {
       
   149         for ( int i = 0; i < iResultArrayItems.Count(); i++ )
       
   150             {
       
   151             iResultArrayItems[i]->SetFlags( iResultArrayItems[i]->GetFlags()
       
   152                     & ~EUninstall );
       
   153             iStorageProxy.AddL( iResultArrayItems[i] );
       
   154             }
       
   155         }
       
   156     iNotifier->CancelSubscribeL( iKey );
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 TComponentId CCaProgressNotifier::ComponentIdL(
       
   164         const TDesC& aGlobalComponentId, const TDesC& aSwType )
       
   165     {
       
   166     RSoftwareComponentRegistry registry;
       
   167     User::LeaveIfError( registry.Connect() );
       
   168     CleanupClosePushL( registry );
       
   169     TComponentId componentId = registry.GetComponentIdL( aGlobalComponentId,
       
   170             aSwType );
       
   171     CleanupStack::PopAndDestroy( &registry ); // registry    
       
   172     return componentId;
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CCaProgressNotifier::MarkEntrysForUnistallL( TUint aKey,
       
   180         TComponentId aComponentId )
       
   181     {
       
   182     RBuf componentIdBuf;
       
   183     componentIdBuf.CleanupClosePushL();
       
   184     componentIdBuf.CreateL( sizeof(TComponentId) + 1 );
       
   185     componentIdBuf.AppendNum( aComponentId );
       
   186 
       
   187     // find entry by componentID
       
   188     CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC();
       
   189     innerQuery->SetRole( CCaInnerQuery::Item );
       
   190     innerQuery->AddAttributeL( KCaAttrComponentId, componentIdBuf );
       
   191 
       
   192     iStorageProxy.GetEntriesL( innerQuery, iResultArrayItems );
       
   193 
       
   194     if ( iResultArrayItems.Count() )
       
   195         {
       
   196         for ( int i = 0; i < iResultArrayItems.Count(); i++ )
       
   197             {
       
   198             iResultArrayItems[i]->SetFlags( iResultArrayItems[i]->GetFlags()
       
   199                     | EUninstall );
       
   200             iStorageProxy.AddL( iResultArrayItems[i] );
       
   201             }
       
   202         // subscribe for progress notifier
       
   203         iKey = aKey;
       
   204         iNotifier->SubscribeL( aKey, ETrue );
       
   205         }
       
   206     CleanupStack::PopAndDestroy( innerQuery );
       
   207     CleanupStack::PopAndDestroy( &componentIdBuf );
       
   208     }