homescreenpluginsrv/hspsmanager/src/hspsautoinstaller.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:  Server side installation of SISX imports
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hsps_builds_cfg.hrh"
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 #include "hspsthemeserver.h"
       
    24 #include "hspsautoinstaller.h"
       
    25 #include "hspsinstallationhandler.h"
       
    26 #include "hspsmaintenancehandler.h"
       
    27 #include "hspsuimanagererrorcodes.h"
       
    28 #include "hspsodt.h"
       
    29 #include "hspsresult.h"
       
    30 #include "hspsthememanagement.h"
       
    31 
       
    32 _LIT( KThemeDirectory,"c:\\private\\200159c0\\themes\\"); 
       
    33 _LIT ( KDoubleBackSlash, "\\" );
       
    34 
       
    35 // ========================= MEMBER FUNCTIONS ==================================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // ChspsAutoInstaller::NewL()
       
    39 // Two-phased constructor.
       
    40 // -----------------------------------------------------------------------------
       
    41 ChspsAutoInstaller* ChspsAutoInstaller::NewL( ChspsThemeServer& aThemeServer )
       
    42     {
       
    43     ChspsAutoInstaller* self = NewLC( aThemeServer );
       
    44     CleanupStack::Pop( self );
       
    45     return( self ) ;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // ChspsAutoInstaller::NewLC()
       
    50 // Two-phased constructor.
       
    51 // -----------------------------------------------------------------------------
       
    52 ChspsAutoInstaller* ChspsAutoInstaller::NewLC( ChspsThemeServer& aThemeServer )
       
    53     {
       
    54     ChspsAutoInstaller* self = new ( ELeave ) ChspsAutoInstaller( aThemeServer );
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     return self;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // ChspsAutoInstaller::ConstructL()
       
    62 // Symbian 2nd phase constructor can leave.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void ChspsAutoInstaller::ConstructL()
       
    66     {
       
    67     iResult = ChspsResult::NewL();
       
    68     iInstallationHandler = ChspsInstallationHandler::NewL( iThemeServer );
       
    69     iMaintenanceHandler = ChspsMaintenanceHandler::NewL( iThemeServer );    
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // ChspsAutoInstaller::ChspsAutoInstaller()
       
    74 // C++ default constructor can NOT contain any code, that might leave.
       
    75 // -----------------------------------------------------------------------------
       
    76 ChspsAutoInstaller::ChspsAutoInstaller( ChspsThemeServer& aThemeServer )
       
    77 : CActive( EPriorityStandard ), iThemeServer( aThemeServer )
       
    78     {
       
    79     CActiveScheduler::Add( this );
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // ChspsAutoInstaller::~ChspsAutoInstaller()
       
    84 // Destructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 ChspsAutoInstaller::~ChspsAutoInstaller()
       
    88     {
       
    89     Cancel(); // Causes call to DoCancel()
       
    90     delete iResult;
       
    91     delete iInstallationHandler;
       
    92     delete iMaintenanceHandler;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // ChspsAutoInstaller::UnInstallTheme
       
    97 // Calls the ChspsMaintenanceHandler to remove theme
       
    98 // (other items were commented in a header).
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void ChspsAutoInstaller::UnInstallThemeL( const TDesC& aPathFile )
       
   102     {
       
   103     // Strip app_/plugin_ prefix from the filename
       
   104     TPtrC fixedName;
       
   105     const TChar KCharUnderscore('_');    
       
   106     TInt offset = aPathFile.Locate( KCharUnderscore );
       
   107     if( offset )
       
   108         {                    
       
   109         TPtrC filePrefix( aPathFile.Left(offset+1) );                
       
   110     	fixedName.Set( aPathFile.Mid( filePrefix.Length() ) );    
       
   111         }    
       
   112     if ( !fixedName.Length() )
       
   113     	{
       
   114     	// TODO handle failure        
       
   115         iThemeServer.HandleAutoInstallerEvent( EhspsRemoveThemeFailed );
       
   116     	return;
       
   117     	}                   
       
   118     
       
   119     TParsePtrC parsePtr( fixedName );                
       
   120     TPtrC fileName( parsePtr.Name() );
       
   121                         
       
   122     HBufC* path = HBufC::NewLC( KMaxFileName );
       
   123     TPtr pathPtr( path->Des() );    
       
   124     pathPtr.Append( KThemeDirectory );
       
   125     
       
   126     // Generate a file path from the file name by replacing underscores with backslashes and
       
   127     // by converting subdirectory names from hex format to int values 
       
   128     TLex lex( fileName );            
       
   129     lex.Mark();
       
   130     while( !lex.Eos() )
       
   131         {
       
   132         if( lex.Peek() == TChar( '_' ) )
       
   133             {            
       
   134             TPtrC token( lex.MarkedToken() );            
       
   135             TLex tmp( token );            
       
   136             
       
   137             TInt64 val( 0 );
       
   138             tmp.Val( val, EHex );            
       
   139             
       
   140             pathPtr.AppendNum( val );
       
   141             lex.Inc();             
       
   142             pathPtr.Append( KDoubleBackSlash );
       
   143             lex.Mark();
       
   144             }            
       
   145         else 
       
   146             {
       
   147             lex.Inc();      
       
   148             }       
       
   149         }
       
   150 
       
   151     // Last token is the theme version string            
       
   152     TPtrC token( lex.MarkedToken() );            
       
   153     pathPtr.Append( token );                           
       
   154     pathPtr.Append( KDoubleBackSlash );            
       
   155                    
       
   156     ChspsODT* odt = ChspsODT::NewL();
       
   157     CleanupStack::PushL( odt );
       
   158                               
       
   159     iThemeServer.DefinitionRepository().GetOdtHeaderL( pathPtr, ELangTest /* not used */, *odt );
       
   160     
       
   161     ThspsServiceCompletedMessage ret = iMaintenanceHandler->hspsRemoveThemeL( *odt );                                 
       
   162         
       
   163     if( ret != EhspsRemoveThemeSuccess )        
       
   164         {
       
   165         // Use brute force to remove the theme. This should not happen
       
   166         iThemeServer.DefinitionRepository().RemoveThemeL( *odt );
       
   167         }
       
   168     
       
   169     // It is success
       
   170     iThemeServer.HandleAutoInstallerEvent( EhspsRemoveThemeSuccess );
       
   171     
       
   172     CleanupStack::PopAndDestroy( 2, path ); // odt, path            
       
   173     }
       
   174     
       
   175 // -----------------------------------------------------------------------------
       
   176 // ChspsAutoInstaller::InstallThemeL
       
   177 // Calls the hspsInstallationHandlers hspsInstallTheme and hspsInstallNextPhase methods
       
   178 // (other items were commented in a header).
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 TInt ChspsAutoInstaller::InstallThemeL( const TDesC& aManifestFileName )
       
   182     {
       
   183     ThspsServiceCompletedMessage ret = 
       
   184         iInstallationHandler->hspsInstallTheme( aManifestFileName, iHeaderData );    
       
   185         
       
   186     // without security check, EhspsInstallThemeSuccess is returned insteads of EhspsInstallPhaseSuccess
       
   187 #ifndef __WINS__   
       
   188     if ( !iInstallationHandler->CheckAutoInstallationValidityL() )
       
   189         {
       
   190         iThemeServer.HandleAutoInstallerEvent( EhspsInstallThemeFailed );
       
   191         return KErrGeneral;
       
   192         }
       
   193 #endif
       
   194             
       
   195     if ( ret == EhspsInstallThemeSuccess && !IsActive() )
       
   196         {
       
   197         SetActive();
       
   198         iInstallationHandler->hspsInstallNextPhaseL( iHeaderData, iStatus  );
       
   199         }
       
   200     else
       
   201         {
       
   202         if ( iInstallationHandler->iResult->iXuikonError == KErrXmlFileNotFound
       
   203                 || iInstallationHandler->iResult->iXuikonError == KErrCssFileNotFound
       
   204                 || iInstallationHandler->iResult->iXuikonError == KErrDtdFileNotFound
       
   205                 || iInstallationHandler->iResult->iXuikonError == KErrResourceFileNotFound )
       
   206             {
       
   207             return KErrNotFound;
       
   208             }
       
   209         iThemeServer.HandleAutoInstallerEvent( EhspsInstallThemeFailed );
       
   210         }
       
   211     return KErrNone;
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // ChspsAutoInstaller::SetLogBus()
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 #ifdef HSPS_LOG_ACTIVE        
       
   219 void ChspsAutoInstaller::SetLogBus( ChspsLogBus* aLogBus )
       
   220     {
       
   221     iLogBus = aLogBus;
       
   222     iInstallationHandler->SetLogBus( aLogBus );
       
   223     }
       
   224 #endif
       
   225    
       
   226 // -----------------------------------------------------------------------------
       
   227 // ChspsRequestClient::GethspsResultL
       
   228 // Gets the installation result status
       
   229 // (other items were commented in a header).
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 ChspsResult& ChspsAutoInstaller::hspsResult()
       
   233     {
       
   234     return *iInstallationHandler->iResult;
       
   235     }  
       
   236                    
       
   237 // -----------------------------------------------------------------------------
       
   238 // ChspsAutoInstaller::RunError
       
   239 // From CActive. Called when error occurred in asynchronous request
       
   240 // Notifies the observer
       
   241 // (other items were commented in a header).
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 TInt ChspsAutoInstaller::RunError( TInt /*aError*/ )
       
   245     {
       
   246     iThemeServer.HandleAutoInstallerEvent( EhspsServiceRequestError );
       
   247     return KErrNone;
       
   248     }  
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // ChspsAutoInstaller::RunL()
       
   252 // From CActive. Called when asynchronous request is completed. 
       
   253 // (other items were commented in a header).
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void ChspsAutoInstaller::RunL()
       
   257     {
       
   258     switch ( iStatus.Int() )
       
   259         {
       
   260         case EhspsInstallThemeSuccess:
       
   261         	{
       
   262           iThemeServer.HandleAutoInstallerEvent( EhspsInstallThemeSuccess );
       
   263         	}
       
   264             break;         
       
   265     
       
   266         case EhspsInstallPhaseSuccess:
       
   267         	{
       
   268             iThemeServer.HandleAutoInstallerEvent( EhspsInstallPhaseSuccess );
       
   269             // it cannot be active anymore in here, however..
       
   270             if ( !IsActive() )
       
   271                 {
       
   272                 SetActive();
       
   273                 iInstallationHandler->hspsInstallNextPhaseL( iHeaderData, iStatus  );
       
   274                 }
       
   275             else
       
   276                 {
       
   277                 iThemeServer.HandleAutoInstallerEvent( EhspsInstallThemeFailed );
       
   278                 }
       
   279         	}
       
   280             break;         
       
   281         
       
   282         default:
       
   283             {
       
   284             iThemeServer.HandleAutoInstallerEvent( (ThspsServiceCompletedMessage)iStatus.Int() );
       
   285             }
       
   286             break;
       
   287         }
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // ChspsAutoInstaller::DoCancel()
       
   292 // Cancels any outstanding operation.
       
   293 // (other items were commented in a header).
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 void ChspsAutoInstaller::DoCancel()
       
   297     {
       
   298     // nothing to do  
       
   299     }
       
   300         
       
   301 // End of File