commonuis/CommonUi/src/DocAppInstHandler.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Implementation of app installer handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "DocAppInstHandler.h"
       
    21 #include "DocAppInstLauncher.h"
       
    22 #include <charconv.h>
       
    23 #include <utf.h>
       
    24 
       
    25 
       
    26 // ================= MEMBER FUNCTIONS =======================
       
    27 
       
    28 // C++ default constructor can NOT contain any code, that
       
    29 // might leave.
       
    30 //
       
    31 CDocAppInstHandler::CDocAppInstHandler(
       
    32     const TDataType& aDataType,
       
    33     const TUid& aUid,
       
    34     CDocumentHandler* aDocDispatcher,
       
    35     TDocServiceMode aServiceMode ) : 
       
    36         CDocDefaultHandler( aDataType, aUid, aDocDispatcher, aServiceMode ),
       
    37         iCallWithParams( EFalse ),
       
    38         iHeapURL( NULL ),
       
    39         iParamDescriptor( NULL ),
       
    40         iUseDescriptor( EFalse )
       
    41     {
       
    42     } 
       
    43 
       
    44 // Two-phased constructor.
       
    45 //
       
    46 CDocAppInstHandler* CDocAppInstHandler::NewL(
       
    47     const TDataType& aDataType,
       
    48     const TUid& aUid,
       
    49     CDocumentHandler* aDocDispatcher,
       
    50     TDocServiceMode aServiceMode )
       
    51     {
       
    52     CDocAppInstHandler *self = 
       
    53         new ( ELeave ) CDocAppInstHandler( aDataType,  
       
    54                                            aUid, aDocDispatcher, 
       
    55                                            aServiceMode ); 
       
    56     CleanupStack::PushL( self );
       
    57     self->BaseConstructL();
       
    58     CleanupStack::Pop();
       
    59     return self;
       
    60     }
       
    61         
       
    62 // Destructor
       
    63 //
       
    64 CDocAppInstHandler::~CDocAppInstHandler()
       
    65     {
       
    66     if ( iLauncher )
       
    67         {
       
    68         iLauncher->Cancel();
       
    69         }
       
    70     delete iLauncher;  
       
    71     delete iParamPckg;  
       
    72     delete iHeapURL; //URL
       
    73     delete iParamDescriptor; //Params+URL
       
    74     }
       
    75     
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CDocAppInstHandler::AddToParamListL()
       
    79 // Add parameters (gives as parameter) to installer spesific parameter list
       
    80 // ---------------------------------------------------------
       
    81 //    
       
    82 void CDocAppInstHandler::AddToParamListL(const CAiwGenericParamList& aParams)
       
    83     {
       
    84     TInt index = 0;
       
    85     const TAiwGenericParam* param = NULL;
       
    86     SwiUI::TInstallReq params; 
       
    87     
       
    88     iCallWithParams = EFalse;
       
    89     iUseDescriptor = EFalse;
       
    90        
       
    91     // Installer wants some parameters from Browser. Convert parameters 
       
    92     // (if there are any) from aParams to installer used format.
       
    93     if ( aParams.Count() ) 
       
    94         {
       
    95         //TInstallReq.iCharsetId
       
    96         param = aParams.FindFirst(index, EGenericParamCharSet, EVariantTypeDesC);
       
    97         if (index >= 0 && param)
       
    98             {
       
    99             TPtrC charset;
       
   100             param->Value().Get(charset);
       
   101             
       
   102             HBufC8* charset8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( charset );
       
   103             
       
   104             CCnvCharacterSetConverter* conv = CCnvCharacterSetConverter::NewLC();            
       
   105             params.iCharsetId = conv->ConvertStandardNameOfCharacterSetToIdentifierL( *charset8, iFs );
       
   106             CleanupStack::PopAndDestroy();   // conv
       
   107             
       
   108             delete charset8;
       
   109             iCallWithParams = ETrue;
       
   110             }
       
   111         //TInstallReq.iIAP;	
       
   112         index = 0;
       
   113         param = aParams.FindFirst(index, EGenericParamAccessPoint, EVariantTypeTInt32);
       
   114         if (index >= 0 && param)
       
   115             {
       
   116             TInt32 accesspoint;
       
   117             param->Value().Get(accesspoint);
       
   118             params.iIAP = accesspoint;
       
   119             iCallWithParams = ETrue;
       
   120             }	
       
   121         //TInstallReq.iSourceURL;
       
   122         index = 0;	
       
   123         param = aParams.FindFirst(index, EGenericParamURL, EVariantTypeDesC);
       
   124         if (index >= 0 && param)
       
   125             {
       
   126             TPtrC sourceURL;
       
   127             param->Value().Get(sourceURL);      	
       
   128             // params.iSourceURL = sourceURL; // removed because TSW JROL-7B8K6H
       
   129             iCallWithParams = ETrue;
       
   130             // Alloc URL from heap.
       
   131             iHeapURL = sourceURL.AllocL();
       
   132             iUseDescriptor = ETrue;
       
   133             }	
       
   134         //TInstallReq.iMIME;
       
   135         if ( iCallWithParams )
       
   136             {
       
   137             params.iMIME = iDataType.Des8();
       
   138             }	
       
   139 
       
   140         // Ok we have all params + url in the descriptor.
       
   141         if ( iUseDescriptor )
       
   142             {
       
   143             // Set params to pckg buffer.
       
   144             SwiUI::TInstallReqPckg regPckg( params );
       
   145             // Alloc heap buffer: 800bytes + 4bytes + size of URL
       
   146             iParamDescriptor = HBufC8::NewL(
       
   147                 sizeof( regPckg ) +
       
   148                 sizeof( TInt32 ) +
       
   149                 iHeapURL->Size() );
       
   150 
       
   151             TPtr8 iParamDesPtr = iParamDescriptor->Des();
       
   152             // Copy parameters to 8-bit descriptor
       
   153             RDesWriteStream stream( iParamDesPtr );
       
   154             CleanupClosePushL( stream );
       
   155             stream.WriteL( regPckg );
       
   156             // Note length must be set always. Even if it is zero.
       
   157             stream.WriteInt32L( iHeapURL->Length() );
       
   158             stream.WriteL( *iHeapURL );
       
   159             CleanupStack::PopAndDestroy( &stream );
       
   160             }
       
   161         }
       
   162     iParamPckg = new ( ELeave ) SwiUI::TInstallReqPckg (params);
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------
       
   166 // CDocAppInstHandler::OpenFileEmbeddedL(RFile& aFileHandle)
       
   167 // 
       
   168 // ---------------------------------------------------------
       
   169 //        
       
   170 TInt CDocAppInstHandler::OpenFileEmbeddedL(RFile& aFileHandle)
       
   171     {
       
   172     // Installer won't be embedded -> Forward to stand-alone version
       
   173     return OpenFileL(aFileHandle);
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // CDocAppInstHandler::OpenFileEmbeddedL(RFile& aFileHandle)
       
   178 // 
       
   179 // ---------------------------------------------------------
       
   180 //        
       
   181 TInt CDocAppInstHandler::OpenFileL(RFile& aFileHandle)
       
   182     {
       
   183     #ifdef _DEBUG        
       
   184     RDebug::Print( _L("DocumentHandler: CDocAppInstHandler::OpenFileL Called"));
       
   185     #endif 
       
   186     
       
   187     iLauncher = CDocAppInstLauncher::NewL();  
       
   188     iLauncher->SetExitObserver( this );  
       
   189     
       
   190     if ( iCallWithParams )
       
   191         {
       
   192         if ( iUseDescriptor )
       
   193             {
       
   194             iLauncher->InstallL( aFileHandle, *iParamDescriptor );
       
   195             }
       
   196         else
       
   197             {
       
   198             iLauncher->InstallL( aFileHandle, *iParamPckg );
       
   199             }
       
   200         }
       
   201     else
       
   202         {
       
   203         iLauncher->InstallL( aFileHandle ); 
       
   204         } 
       
   205          
       
   206     #ifdef _DEBUG        
       
   207     RDebug::Print( _L("DocumentHandler: CDocAppInstHandler::OpenFileL Returns.")) ;
       
   208     #endif 
       
   209     return SetAndReturnStatus( KErrNone );  // If we're still here, everything is ok.
       
   210     }
       
   211 
       
   212 //  End of File