appinstall_plat/sifui_api/src/sifuiprivate.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
       
     2 * Copyright (c) 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:  Implementation of CSifUiPrivate class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "sifuiprivate.h"                       // CSifUiPrivate
       
    19 #include "sifuicertificateinfo.h"               // CSifUiCertificateInfo
       
    20 #include "sifuiappinfo.h"                       // CSifUiAppInfo
       
    21 #include "sifuierrorinfo.h"                     // CSifUiErrorInfo
       
    22 #include "sifuiinstallindicatordefinitions.h"   // indicator type label and parameter names
       
    23 #include <hb/hbcore/hbsymbianvariant.h>         // CHbSymbianVariantMap
       
    24 #include <hb/hbwidgets/hbdevicenotificationdialogsymbian.h> // CHbDeviceNotificationDialogSymbian
       
    25 #include <apgicnfl.h>                           // CApaMaskedBitmap
       
    26 #include <s32mem.h>                             // RDesReadStream
       
    27 #include <e32property.h>                        // RProperty
       
    28 
       
    29 const TInt KDriveLettersLen = 32;
       
    30 const TInt KBufferGranularity = 1024;
       
    31 const TInt KProgFull = 100;                     // 100%
       
    32 
       
    33 const TUid KInstallIndicatorCategory = { 0x20022FC5 };
       
    34 const TUint KInstallIndicatorStatus = 0x2002E690;
       
    35 
       
    36 _LIT( KSifUiDefaultApplicationIcon, "qtg_large_application" );
       
    37 
       
    38 // TODO: replace with proper logging
       
    39 #ifdef _DEBUG
       
    40 #define FLOG(x)         RDebug::Print(x);
       
    41 #define FLOG_1(x,y)     RDebug::Print(x, y);
       
    42 #define FLOG_2(x,y,z)   RDebug::Print(x, y, z);
       
    43 #define FLOG_3(x,y,z,v) RDebug::Print(x, y, z, v);
       
    44 #else
       
    45 #define FLOG(x)
       
    46 #define FLOG_1(x,y)
       
    47 #define FLOG_2(x,y,z)
       
    48 #define FLOG_3(x,y,z,v)
       
    49 #endif
       
    50 
       
    51 
       
    52 // ======== MEMBER FUNCTIONS ========
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CSifUiPrivate::NewL()
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CSifUiPrivate* CSifUiPrivate::NewL()
       
    59     {
       
    60     FLOG( _L("CSifUiPrivate::NewL") );
       
    61 
       
    62     CSifUiPrivate* self = new( ELeave ) CSifUiPrivate();
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL();
       
    65     CleanupStack::Pop( self );
       
    66     return self;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CSifUiPrivate::~CSifUiPrivate()
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CSifUiPrivate::~CSifUiPrivate()
       
    74     {
       
    75     FLOG( _L("CSifUiPrivate::~CSifUiPrivate") );
       
    76 
       
    77     Cancel();
       
    78     delete iWait;
       
    79     delete iDeviceDialog;
       
    80     delete iVariantMap;
       
    81     delete iIndicator;
       
    82     delete iAppInfo;
       
    83     delete iSelectableDrives;
       
    84     delete iCertificateBuffer;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CSifUiPrivate::ShowPreparingL()
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CSifUiPrivate::ShowPreparingL()
       
    92     {
       
    93     // TODO: implement
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CSifUiPrivate::SetMemorySelectionL()
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CSifUiPrivate::SetMemorySelectionL( const RArray<TInt>& aDriveNumbers )
       
   101     {
       
   102     FLOG( _L("CSifUiPrivate::SetMemorySelectionL") );
       
   103 
       
   104     if( iSelectableDrives )
       
   105         {
       
   106         delete iSelectableDrives;
       
   107         iSelectableDrives = NULL;
       
   108         }
       
   109 
       
   110     TInt driveCount = aDriveNumbers.Count();
       
   111     if( driveCount > 0 )
       
   112         {
       
   113         const TChar KComma = ',';
       
   114         TBuf<KDriveLettersLen> driveList;
       
   115         for( TInt index = 0; index < driveCount; ++index )
       
   116             {
       
   117             TChar driveLetter;
       
   118             TInt err = RFs::DriveToChar( aDriveNumbers[ index ], driveLetter );
       
   119             FLOG_3( _L("CSifUiPrivate::SetMemorySelectionL, index %d, drive %d, err %d"),
       
   120                     index, aDriveNumbers[ index ], err );
       
   121             if( !err )
       
   122                 {
       
   123                 driveList.Append( driveLetter );
       
   124                 driveList.Append( KComma );
       
   125                 }
       
   126             }
       
   127         iSelectableDrives = driveList.AllocL();
       
   128         }
       
   129     FLOG_1( _L("CSifUiPrivate::SetMemorySelectionL, iSelectableDrives=%S"), iSelectableDrives );
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CSifUiPrivate::SetCertificateInfoL()
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CSifUiPrivate::SetCertificateInfoL(
       
   137         const RPointerArray<CSifUiCertificateInfo>& aCertificates )
       
   138     {
       
   139     FLOG( _L("CSifUiPrivate::SetCertificateInfoL") );
       
   140 
       
   141     if( iCertificateBuffer )
       
   142         {
       
   143         delete iCertificateBuffer;
       
   144         iCertificateBuffer = NULL;
       
   145         }
       
   146     if( aCertificates.Count() )
       
   147         {
       
   148         iCertificateBuffer = CBufFlat::NewL( KBufferGranularity );
       
   149         RBufWriteStream writeStream( *iCertificateBuffer );
       
   150         CleanupClosePushL( writeStream );
       
   151 
       
   152         TInt32 count = aCertificates.Count();
       
   153         writeStream.WriteInt32L( count );
       
   154         for( TInt index = 0; index < count; ++index )
       
   155            {
       
   156            aCertificates[ index ]->ExternalizeL( writeStream );
       
   157            }
       
   158 
       
   159         CleanupStack::PopAndDestroy( &writeStream );
       
   160         }
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CSifUiPrivate::ShowConfirmationL()
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 TBool CSifUiPrivate::ShowConfirmationL( const CSifUiAppInfo& aAppInfo )
       
   168     {
       
   169     FLOG( _L("CSifUiPrivate::ShowConfirmationL") );
       
   170 
       
   171     ChangeNoteTypeL( ESifUiConfirmationQuery );
       
   172 
       
   173     AddParamsAppInfoL( aAppInfo );
       
   174     if( iSelectableDrives )
       
   175         {
       
   176         AddParamL( KSifUiMemorySelection, *iSelectableDrives );
       
   177         }
       
   178     AddParamsCertificatesL();
       
   179 
       
   180     UpdateDialogAndWaitForResponseL();
       
   181     return( iDialogReturnValue == KErrNone );
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CSifUiPrivate::SelectedDrive()
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 TInt CSifUiPrivate::SelectedDrive( TInt& aDriveNumber )
       
   189     {
       
   190     FLOG( _L("CSifUiPrivate::SelectedDrive") );
       
   191 
       
   192     if( iSelectedDriveSet )
       
   193         {
       
   194         TInt err = RFs::CharToDrive( iSelectedDrive, aDriveNumber );
       
   195         FLOG_2( _L("CSifUiPrivate::SelectedDrive, aDriveNumber=%d, err=%d"), aDriveNumber, err );
       
   196         return err;
       
   197         }
       
   198     FLOG( _L("CSifUiPrivate::SelectedDrive, KErrNotFound") );
       
   199     return KErrNotFound;
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CSifUiPrivate::ShowProgressL()
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CSifUiPrivate::ShowProgressL( const CSifUiAppInfo& aAppInfo,
       
   207         TInt aProgressBarFinalValue, CSifUi::TInstallingPhase aPhase )
       
   208     {
       
   209     FLOG( _L("CSifUiPrivate::ShowProgressL") );
       
   210 
       
   211     ChangeNoteTypeL( ESifUiProgressNote );
       
   212 
       
   213     AddParamsAppInfoL( aAppInfo );
       
   214     AddParamL( KSifUiProgressNoteFinalValue, aProgressBarFinalValue );
       
   215     iProgressBarFinalValue = aProgressBarFinalValue;
       
   216     AddParamL( KSifUiProgressNotePhase, aPhase );
       
   217     iInstallingPhase = aPhase;
       
   218     AddParamsHiddenButtonsL();
       
   219 
       
   220     UpdateDialogOrIndicatorWithoutWaitingL();
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // CSifUiPrivate::IncreaseProgressBarValueL()
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CSifUiPrivate::IncreaseProgressBarValueL( TInt aNewValue )
       
   228     {
       
   229     FLOG_1( _L("CSifUiPrivate::IncreaseProgressBarValueL, aNewValue=%d"), aNewValue );
       
   230 
       
   231     ChangeNoteTypeL( ESifUiProgressNote );
       
   232 
       
   233     AddParamL( KSifUiProgressNoteValue, aNewValue );
       
   234     iProgressBarCurrentValue += aNewValue;
       
   235     AddParamsHiddenButtonsL();
       
   236 
       
   237     UpdateDialogOrIndicatorWithoutWaitingL();
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // CSifUiPrivate::IsCancelled()
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 TBool CSifUiPrivate::IsCancelled()
       
   245     {
       
   246     return( iDialogReturnValue == KErrCancel );
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // CSifUiPrivate::ShowCompleteL()
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void CSifUiPrivate::ShowCompleteL()
       
   254     {
       
   255     FLOG( _L("CSifUiPrivate::ShowCompleteL") );
       
   256 
       
   257     ChangeNoteTypeL( ESifUiCompleteNote );
       
   258 
       
   259     AddParamsHiddenButtonsL();
       
   260 
       
   261     CompleteDialogOrIndicatorAndWaitForResponseL( KErrNone );
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // CSifUiPrivate::ShowFailedL()
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CSifUiPrivate::ShowFailedL( const CSifUiErrorInfo& aErrorInfo )
       
   269     {
       
   270     FLOG_1( _L("CSifUiPrivate::ShowFailedL, aErrorCode=%d"), aErrorInfo.ErrorCode() );
       
   271 
       
   272     ChangeNoteTypeL( ESifUiErrorNote );
       
   273 
       
   274     AddParamL( KSifUiErrorCategory, aErrorInfo.ErrorCategory() );
       
   275     AddParamL( KSifUiErrorCode, aErrorInfo.ErrorCode() );
       
   276     AddParamL( KSifUiErrorCodeExtended, aErrorInfo.ExtendedErrorCode() );
       
   277     AddParamL( KSifUiErrorMessage, aErrorInfo.ErrorMessage() );
       
   278     AddParamL( KSifUiErrorDetails, aErrorInfo.ErrorMessageDetails() );
       
   279     AddParamsHiddenButtonsL();
       
   280 
       
   281     CompleteDialogOrIndicatorAndWaitForResponseL( aErrorInfo.ErrorCode() );
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CSifUiPrivate::SetButtonVisible()
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void CSifUiPrivate::SetButtonVisible( CSifUi::TOptionalButton aButton, TBool aIsVisible )
       
   289     {
       
   290     FLOG( _L("CSifUiPrivate::SetButtonVisible") );
       
   291 
       
   292     switch( aButton )
       
   293         {
       
   294         case CSifUi::EHideProgressButton:
       
   295             iNoHideProgressButton = !aIsVisible;
       
   296             break;
       
   297         case CSifUi::ECancelProgressButton:
       
   298             iNoCancelProgressButton = !aIsVisible;
       
   299             break;
       
   300         case CSifUi::EShowInAppLibButton:
       
   301             iNoShowInAppLibButton = !aIsVisible;
       
   302             break;
       
   303         case CSifUi::EErrorDetailsButton:
       
   304             iNoErrorDetailsButton = !aIsVisible;
       
   305             break;
       
   306         default:
       
   307             break;
       
   308         }
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CSifUiPrivate::ShowGrantCapabilitiesL()
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 TBool CSifUiPrivate::ShowGrantCapabilitiesL( const TCapabilitySet& aCapabilities )
       
   316     {
       
   317     TPckg<TCapabilitySet> capabilitySetPckg( aCapabilities );
       
   318     AddParamPckgL( KSifUiGrantCapabilities, capabilitySetPckg );
       
   319     UpdateDialogAndWaitForResponseL();
       
   320     return( iDialogReturnValue == KErrNone );
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // CSifUiPrivate::ShowSelectLanguageL()
       
   325 // ---------------------------------------------------------------------------
       
   326 //
       
   327 TInt CSifUiPrivate::ShowSelectLanguageL( const RArray<TLanguage>& aLanguages )
       
   328     {
       
   329     CBufFlat* buffer = CBufFlat::NewL( KBufferGranularity );
       
   330     CleanupStack::PushL( buffer );
       
   331 
       
   332     RBufWriteStream writeStream( *buffer );
       
   333     CleanupClosePushL( writeStream );
       
   334     TPckg< const RArray<TLanguage> > languagesPckg( aLanguages );
       
   335     writeStream.WriteL( languagesPckg );
       
   336     writeStream.CommitL();
       
   337     CleanupStack::PopAndDestroy( &writeStream );
       
   338 
       
   339     AddParamBinaryL( KSifUiSelectableLanguages, *buffer );
       
   340     CleanupStack::PopAndDestroy( buffer );
       
   341     UpdateDialogAndWaitForResponseL();
       
   342     if( iDialogReturnValue == KErrNone )
       
   343         {
       
   344         return iSelectedLanguage;
       
   345         }
       
   346     return iDialogReturnValue;
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------------------------
       
   350 // CSifUiPrivate::ShowSelectOptionsL()
       
   351 // ---------------------------------------------------------------------------
       
   352 //
       
   353 TBool CSifUiPrivate::ShowSelectOptionsL( const MDesCArray& aSelectableItems,
       
   354         RArray<TInt>& aSelectedIndexes )
       
   355     {
       
   356     AddParamListL( KSifUiSelectableOptions, aSelectableItems );
       
   357     iSelectedOptions.Reset();
       
   358     UpdateDialogAndWaitForResponseL();
       
   359     if( iSelectedOptions.Count() )
       
   360         {
       
   361         aSelectedIndexes = iSelectedOptions;
       
   362         }
       
   363     return( iDialogReturnValue == KErrNone );
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // CSifUiPrivate::DoCancel()
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void CSifUiPrivate::DoCancel()
       
   371     {
       
   372     FLOG( _L("CSifUiPrivate::DoCancel") );
       
   373     if( iDeviceDialog )
       
   374         {
       
   375         iDeviceDialog->Cancel();        // Closes the device dialog.
       
   376         }
       
   377 
       
   378     // Cancelled device dialog does not call DeviceDialogClosed() hence have
       
   379     // to complete the request now. CActive::Cancel() waits until the request
       
   380     // is completed.
       
   381     TRequestStatus* status( &iStatus );
       
   382     User::RequestComplete( status, KErrCancel );
       
   383 
       
   384     // Normally User::RequestComplete() invokes RunL(), but not now, because
       
   385     // the object is not active any more (after it has been cancelled). Hence,
       
   386     // have to stop CActiveSchedulerWait too.
       
   387     iWaitCompletionCode = KErrCancel;
       
   388     if( iWait && iWait->IsStarted() )
       
   389         {
       
   390         iWait->AsyncStop();
       
   391         }
       
   392     }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CSifUiPrivate::RunL()
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 void CSifUiPrivate::RunL()
       
   399     {
       
   400     FLOG_1( _L("CSifUiPrivate::RunL, iStatus.Int()=%d"), iStatus.Int() );
       
   401 
       
   402     if( iWait && iWait->IsStarted() )
       
   403         {
       
   404         iWait->AsyncStop();
       
   405         }
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CSifUiPrivate::DataReceived()
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 void CSifUiPrivate::DataReceived( CHbSymbianVariantMap& aData )
       
   413     {
       
   414     FLOG( _L("CSifUiPrivate::DataReceived") );
       
   415 
       
   416     const CHbSymbianVariant* selectedDriveVariant = aData.Get( KSifUiSelectedMemory );
       
   417     if( selectedDriveVariant )
       
   418         {
       
   419         iSelectedDrive = *( selectedDriveVariant->Value<TChar>() );
       
   420         iSelectedDriveSet = ETrue;
       
   421         FLOG_1( _L("CSifUiPrivate::DataReceived, iSelectedDrive=%d"), (TUint)iSelectedDrive );
       
   422         }
       
   423 
       
   424     const CHbSymbianVariant* selectedLangVariant = aData.Get( KSifUiSelectedLanguageIndex );
       
   425     if( selectedLangVariant )
       
   426         {
       
   427         iSelectedLanguage = *( selectedLangVariant->Value<TInt>() );
       
   428         FLOG_1( _L("CSifUiPrivate::DataReceived, iSelectedLanguage=%d"), iSelectedLanguage );
       
   429         }
       
   430 
       
   431     const CHbSymbianVariant* selectedOptsVariant = aData.Get( KSifUiSelectedOptions );
       
   432     if( selectedOptsVariant )
       
   433         {
       
   434         const TDesC8 *dataPtr = reinterpret_cast< const TDesC8* >( selectedOptsVariant->Data() );
       
   435         RMemReadStream readStream( selectedOptsVariant->Data(), dataPtr->Size() );
       
   436         CleanupClosePushL( readStream );
       
   437         TPckg< RArray<TInt> > selectedOptionsPckg( iSelectedOptions );
       
   438         readStream.ReadL( selectedOptionsPckg );
       
   439         CleanupStack::PopAndDestroy( &readStream );
       
   440         FLOG_1( _L("CSifUiPrivate::DataReceived, iSelectedOptions.Count()=%d"),
       
   441             iSelectedOptions.Count() );
       
   442         }
       
   443 
       
   444     const CHbSymbianVariant* variant = aData.Get( KSifUiQueryReturnValue );
       
   445     if( variant )
       
   446         {
       
   447         TInt* value = variant->Value<TInt>();
       
   448         if( value )
       
   449             {
       
   450             TSifUiDeviceDialogReturnValue returnValue =
       
   451                     static_cast<TSifUiDeviceDialogReturnValue>( *value );
       
   452             switch( returnValue )
       
   453                 {
       
   454                 case ESifUiContinue:
       
   455                     iDialogReturnValue = KErrNone;
       
   456                     WaitedResponseReceived( KErrNone );
       
   457                     break;
       
   458                 case ESifUiCancel:
       
   459                     iDialogReturnValue = KErrCancel;
       
   460                     WaitedResponseReceived( KErrNone );
       
   461                     break;
       
   462                 case ESifUiIndicator:
       
   463                     ActivateInstallIndicatorL();
       
   464                     break;
       
   465                 default:
       
   466                     __ASSERT_DEBUG( EFalse, User::Invariant() );
       
   467                     break;
       
   468                 }
       
   469             }
       
   470         else
       
   471             {
       
   472             __ASSERT_DEBUG( EFalse, User::Invariant() );
       
   473             }
       
   474         }
       
   475     }
       
   476 
       
   477 // ---------------------------------------------------------------------------
       
   478 // CSifUiPrivate::DeviceDialogClosed()
       
   479 // ---------------------------------------------------------------------------
       
   480 //
       
   481 void CSifUiPrivate::DeviceDialogClosed( TInt aCompletionCode )
       
   482     {
       
   483     FLOG_1( _L("CSifUiPrivate::DeviceDialogClosed, aCompletionCode=%d"), aCompletionCode );
       
   484 
       
   485     iIsDisplayingDialog = EFalse;
       
   486     WaitedResponseReceived( aCompletionCode );
       
   487     }
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 // CSifUiPrivate::IndicatorUserActivated()
       
   491 // ---------------------------------------------------------------------------
       
   492 //
       
   493 void CSifUiPrivate::IndicatorUserActivated( const TDesC& aType,
       
   494         CHbSymbianVariantMap& /*aData*/ )
       
   495     {
       
   496     FLOG( _L("CSifUiPrivate::IndicatorUserActivated") );
       
   497 
       
   498     if( aType == KSifUiInstallIndicatorType )
       
   499         {
       
   500         CloseInstallIndicator();
       
   501         iIsFirstTimeToDisplay = ETrue;
       
   502         TRAP_IGNORE( DisplayDeviceDialogL() );
       
   503         }
       
   504     }
       
   505 
       
   506 // ---------------------------------------------------------------------------
       
   507 // CSifUiPrivate::CSifUiPrivate()
       
   508 // ---------------------------------------------------------------------------
       
   509 //
       
   510 CSifUiPrivate::CSifUiPrivate() : CActive( CActive::EPriorityStandard ),
       
   511         iIsFirstTimeToDisplay( ETrue )
       
   512     {
       
   513     CActiveScheduler::Add( this );
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // CSifUiPrivate::ConstructL()
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 void CSifUiPrivate::ConstructL()
       
   521     {
       
   522     iWait = new( ELeave ) CActiveSchedulerWait;
       
   523     // iDeviceDialog is created later, in the first call of DisplayDeviceDialogL()
       
   524     // iIndicator is also created later, in the first call of ActivateInstallIndicator()
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // CSifUiPrivate::ClearParams()
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 void CSifUiPrivate::ClearParams()
       
   532     {
       
   533     if( iVariantMap )
       
   534         {
       
   535         delete iVariantMap;
       
   536         iVariantMap = NULL;
       
   537         }
       
   538     }
       
   539 
       
   540 // ---------------------------------------------------------------------------
       
   541 // CSifUiPrivate::VariantMapL()
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 CHbSymbianVariantMap* CSifUiPrivate::VariantMapL()
       
   545     {
       
   546     if( !iVariantMap )
       
   547         {
       
   548         iVariantMap = CHbSymbianVariantMap::NewL();
       
   549         }
       
   550     return iVariantMap;
       
   551     }
       
   552 
       
   553 // ---------------------------------------------------------------------------
       
   554 // CSifUiPrivate::ChangeNoteTypeL()
       
   555 // ---------------------------------------------------------------------------
       
   556 //
       
   557 void CSifUiPrivate::ChangeNoteTypeL( TInt aType )
       
   558     {
       
   559     ClearParams();
       
   560     AddParamL( KSifUiDialogType, aType );
       
   561     iDialogType = static_cast< TSifUiDeviceDialogType >( aType );
       
   562     }
       
   563 
       
   564 // ---------------------------------------------------------------------------
       
   565 // CSifUiPrivate::AddParamL()
       
   566 // ---------------------------------------------------------------------------
       
   567 //
       
   568 void CSifUiPrivate::AddParamL( const TDesC& aKey, TInt aValue )
       
   569     {
       
   570     CHbSymbianVariant* variant = NULL;
       
   571     variant = CHbSymbianVariant::NewL( &aValue, CHbSymbianVariant::EInt );
       
   572     User::LeaveIfError( VariantMapL()->Add( aKey, variant ) );
       
   573     }
       
   574 
       
   575 // ---------------------------------------------------------------------------
       
   576 // CSifUiPrivate::AddParamL()
       
   577 // ---------------------------------------------------------------------------
       
   578 //
       
   579 void CSifUiPrivate::AddParamL( const TDesC& aKey, const TDesC& aValue )
       
   580     {
       
   581     CHbSymbianVariant* variant = NULL;
       
   582     variant = CHbSymbianVariant::NewL( &aValue, CHbSymbianVariant::EDes );
       
   583     User::LeaveIfError( VariantMapL()->Add( aKey, variant ) );
       
   584     }
       
   585 
       
   586 // ---------------------------------------------------------------------------
       
   587 // CSifUiPrivate::AddParamListL()
       
   588 // ---------------------------------------------------------------------------
       
   589 //
       
   590 void CSifUiPrivate::AddParamListL( const TDesC& aKey, const MDesCArray& aList )
       
   591     {
       
   592     CHbSymbianVariant* variant = NULL;
       
   593     variant = CHbSymbianVariant::NewL( &aList, CHbSymbianVariant::EDesArray );
       
   594     User::LeaveIfError( VariantMapL()->Add( aKey, variant ) );
       
   595     }
       
   596 
       
   597 // ---------------------------------------------------------------------------
       
   598 // CSifUiPrivate::AddParamBinaryL()
       
   599 // ---------------------------------------------------------------------------
       
   600 //
       
   601 void CSifUiPrivate::AddParamBinaryL( const TDesC& aKey, const CBufBase& aBinary )
       
   602     {
       
   603     CHbSymbianVariant* variant = NULL;
       
   604     const TPtrC8 ptr( const_cast<CBufBase&>( aBinary ).Ptr( 0 ).Ptr(), aBinary.Size() );
       
   605     variant = CHbSymbianVariant::NewL( &ptr, CHbSymbianVariant::EBinary );
       
   606     CleanupStack::PushL( variant );
       
   607     User::LeaveIfError( VariantMapL()->Add( aKey, variant ) );
       
   608     CleanupStack::Pop( variant );
       
   609     }
       
   610 
       
   611 // ---------------------------------------------------------------------------
       
   612 // CSifUiPrivate::AddParamPckgL()
       
   613 // ---------------------------------------------------------------------------
       
   614 //
       
   615 void CSifUiPrivate::AddParamPckgL( const TDesC& aKey, const TDesC8& aPckg )
       
   616     {
       
   617     CHbSymbianVariant* variant = NULL;
       
   618     variant = CHbSymbianVariant::NewL( &aPckg, CHbSymbianVariant::EBinary );
       
   619     User::LeaveIfError( VariantMapL()->Add( aKey, variant ) );
       
   620     }
       
   621 
       
   622 // ---------------------------------------------------------------------------
       
   623 // CSifUiPrivate::AddParamsAppInfoL()
       
   624 // ---------------------------------------------------------------------------
       
   625 //
       
   626 void CSifUiPrivate::AddParamsAppInfoL( const CSifUiAppInfo& aAppInfo )
       
   627     {
       
   628     AddParamL( KSifUiApplicationName, aAppInfo.Name() );
       
   629     const TVersion& version( aAppInfo.Version() );
       
   630     if( version.iMajor || version.iMinor )
       
   631         {
       
   632         TVersionName versionName;
       
   633         versionName.AppendNum( version.iMajor );
       
   634         versionName.Append( TChar('.') );
       
   635         versionName.AppendNum( version.iMinor );
       
   636         AddParamL( KSifUiApplicationVersion, versionName );
       
   637         }
       
   638     if( aAppInfo.Vendor().Length() )
       
   639         {
       
   640         AddParamL( KSifUiApplicationDetails, aAppInfo.Vendor() );
       
   641         }
       
   642     if( aAppInfo.Size() > 0 )
       
   643         {
       
   644         AddParamL( KSifUiApplicationSize, aAppInfo.Size() );
       
   645         }
       
   646     // TODO: icons missing, could use binary transfer as in certificates
       
   647 
       
   648     if( iAppInfo != &aAppInfo )
       
   649         {
       
   650         if( iAppInfo )
       
   651             {
       
   652             delete iAppInfo;
       
   653             iAppInfo = NULL;
       
   654             }
       
   655         iAppInfo = CSifUiAppInfo::NewL( aAppInfo );
       
   656         }
       
   657     }
       
   658 
       
   659 // ---------------------------------------------------------------------------
       
   660 // CSifUiPrivate::AddParamsCertificatesL()
       
   661 // ---------------------------------------------------------------------------
       
   662 //
       
   663 void CSifUiPrivate::AddParamsCertificatesL()
       
   664     {
       
   665     if( iCertificateBuffer )
       
   666         {
       
   667         AddParamBinaryL( KSifUiCertificates, *iCertificateBuffer );
       
   668         }
       
   669     }
       
   670 
       
   671 // ---------------------------------------------------------------------------
       
   672 // CSifUiPrivate::AddParamsHiddenButtonsL()
       
   673 // ---------------------------------------------------------------------------
       
   674 //
       
   675 void CSifUiPrivate::AddParamsHiddenButtonsL()
       
   676     {
       
   677     CHbSymbianVariant* variant = NULL;
       
   678     if( iNoHideProgressButton )
       
   679         {
       
   680         variant = CHbSymbianVariant::NewL( &iNoHideProgressButton, CHbSymbianVariant::EBool );
       
   681         TInt err = VariantMapL()->Add( KSifUiProgressNoteIsHideButtonHidden, variant );
       
   682         User::LeaveIfError( err );
       
   683         }
       
   684     if( iNoCancelProgressButton )
       
   685         {
       
   686         variant = CHbSymbianVariant::NewL( &iNoCancelProgressButton, CHbSymbianVariant::EBool );
       
   687         TInt err = VariantMapL()->Add( KSifUiProgressNoteIsCancelButtonHidden, variant );
       
   688         User::LeaveIfError( err );
       
   689         }
       
   690     if( iNoShowInAppLibButton )
       
   691         {
       
   692         variant = CHbSymbianVariant::NewL( &iNoShowInAppLibButton, CHbSymbianVariant::EBool );
       
   693         TInt err = VariantMapL()->Add( KSifUiCompleteNoteIsShowButtonHidden, variant );
       
   694         User::LeaveIfError( err );
       
   695         }
       
   696     if( iNoErrorDetailsButton )
       
   697         {
       
   698         variant = CHbSymbianVariant::NewL( &iNoErrorDetailsButton, CHbSymbianVariant::EBool );
       
   699         TInt err = VariantMapL()->Add( KSifUiErrorNoteIsDetailsButtonHidden, variant );
       
   700         User::LeaveIfError( err );
       
   701         }
       
   702     }
       
   703 
       
   704 // ---------------------------------------------------------------------------
       
   705 // CSifUiPrivate::ResendAllInstallationDetailsL()
       
   706 // ---------------------------------------------------------------------------
       
   707 //
       
   708 void CSifUiPrivate::ResendAllInstallationDetailsL()
       
   709     {
       
   710     AddParamL( KSifUiDialogType, iDialogType );
       
   711     if( iAppInfo )
       
   712         {
       
   713         AddParamsAppInfoL( *iAppInfo );
       
   714         }
       
   715     AddParamsCertificatesL();
       
   716     if( iProgressBarFinalValue )
       
   717         {
       
   718         AddParamL( KSifUiProgressNoteFinalValue, iProgressBarFinalValue );
       
   719         }
       
   720     if( iProgressBarCurrentValue )
       
   721         {
       
   722         AddParamL( KSifUiProgressNoteValue, iProgressBarCurrentValue );
       
   723         }
       
   724     AddParamL( KSifUiProgressNotePhase, iInstallingPhase );
       
   725     AddParamsHiddenButtonsL();
       
   726     // TODO: AddParamsIconL();
       
   727     }
       
   728 
       
   729 // ---------------------------------------------------------------------------
       
   730 // CSifUiPrivate::ActivateInstallIndicatorL()
       
   731 // ---------------------------------------------------------------------------
       
   732 //
       
   733 void CSifUiPrivate::ActivateInstallIndicatorL()
       
   734     {
       
   735     if( !iIndicator )
       
   736         {
       
   737         iIndicator = CHbIndicatorSymbian::NewL();
       
   738         iIndicator->SetObserver( this );
       
   739         }
       
   740 
       
   741     UpdateInstallIndicatorProgressL();
       
   742     }
       
   743 
       
   744 // ---------------------------------------------------------------------------
       
   745 // CSifUiPrivate::UpdateInstallIndicatorProgressL()
       
   746 // ---------------------------------------------------------------------------
       
   747 //
       
   748 void CSifUiPrivate::UpdateInstallIndicatorProgressL()
       
   749     {
       
   750     CHbSymbianVariantMap* parameters = CHbSymbianVariantMap::NewL();
       
   751     CleanupStack::PushL( parameters );
       
   752 
       
   753     CHbSymbianVariant* param = NULL;
       
   754 
       
   755     if( iAppInfo && iAppInfo->Name().Length() )
       
   756         {
       
   757         TPtrC appName = iAppInfo->Name();
       
   758         param = CHbSymbianVariant::NewL( &appName, CHbSymbianVariant::EDes );
       
   759         parameters->Add( KSifUiInstallIndicatorAppName, param );
       
   760         }
       
   761     if( iInstallingPhase )
       
   762         {
       
   763         param = CHbSymbianVariant::NewL( &iInstallingPhase, CHbSymbianVariant::EInt );
       
   764         parameters->Add( KSifUiInstallIndicatorPhase, param );
       
   765         }
       
   766     if( iProgressBarFinalValue )
       
   767         {
       
   768         TInt progressPercent = KProgFull * iProgressBarCurrentValue / iProgressBarFinalValue;
       
   769         param = CHbSymbianVariant::NewL( &progressPercent, CHbSymbianVariant::EInt );
       
   770         parameters->Add( KSifUiInstallIndicatorProgress, param );
       
   771         }
       
   772 
       
   773     // TODO: should both install indicator and device dialog use the same variant map?
       
   774 
       
   775     param = CHbSymbianVariant::NewL( parameters, CHbSymbianVariant::EVariantMap );
       
   776     CleanupStack::Pop( parameters );
       
   777     CleanupStack::PushL( param );
       
   778     iIndicator->Activate( KSifUiInstallIndicatorType, param );
       
   779     CleanupStack::PopAndDestroy( param );
       
   780     }
       
   781 
       
   782 // ---------------------------------------------------------------------------
       
   783 // CSifUiPrivate::CloseInstallIndicator()
       
   784 // ---------------------------------------------------------------------------
       
   785 //
       
   786 void CSifUiPrivate::CloseInstallIndicator()
       
   787     {
       
   788     if( iIndicator )
       
   789         {
       
   790         iIndicator->Deactivate( KSifUiInstallIndicatorType );
       
   791         delete iIndicator;
       
   792         iIndicator = NULL;
       
   793         }
       
   794     }
       
   795 
       
   796 // ---------------------------------------------------------------------------
       
   797 // CSifUiPrivate::IsIndicatorActive()
       
   798 // ---------------------------------------------------------------------------
       
   799 //
       
   800 TBool CSifUiPrivate::IsIndicatorActive()
       
   801     {
       
   802     TBool isActive = EFalse;
       
   803 
       
   804     if( iIndicator )
       
   805         {
       
   806         TInt value = 0;
       
   807         TInt err = RProperty::Get( KInstallIndicatorCategory, KInstallIndicatorStatus,
       
   808             value );
       
   809         if( !err )
       
   810             {
       
   811             isActive = ( value > 0 );
       
   812             }
       
   813         }
       
   814 
       
   815     return isActive;
       
   816     }
       
   817 
       
   818 // ---------------------------------------------------------------------------
       
   819 // CSifUiPrivate::ShowInstallIndicatorCompleteL()
       
   820 // ---------------------------------------------------------------------------
       
   821 //
       
   822 void CSifUiPrivate::ShowInstallIndicatorCompleteL( TInt aErrorCode )
       
   823     {
       
   824     CHbDeviceNotificationDialogSymbian* completeNote =
       
   825             CHbDeviceNotificationDialogSymbian::NewL();
       
   826     CleanupStack::PushL( completeNote );
       
   827     completeNote->SetIconNameL( KSifUiDefaultApplicationIcon );
       
   828     if( aErrorCode == KErrNone )
       
   829         {
       
   830         // TODO: use HbTextResolverSymbian to get localized text
       
   831         _LIT( KInstalled, "Installed" );
       
   832         completeNote->SetTitleL( KInstalled );
       
   833         }
       
   834     else
       
   835         {
       
   836         // TODO: use HbTextResolverSymbian to get localized text
       
   837         _LIT( KInstallationFailed, "Installation failed" );
       
   838         completeNote->SetTitleL( KInstallationFailed );
       
   839         }
       
   840     completeNote->ShowL();
       
   841     CleanupStack::PopAndDestroy( completeNote );
       
   842     }
       
   843 
       
   844 // ---------------------------------------------------------------------------
       
   845 // CSifUiPrivate::UpdateDialogAndWaitForResponseL()
       
   846 // ---------------------------------------------------------------------------
       
   847 //
       
   848 void CSifUiPrivate::UpdateDialogAndWaitForResponseL()
       
   849     {
       
   850     CloseInstallIndicator();
       
   851     DisplayDeviceDialogL();
       
   852     WaitForResponseL();
       
   853     }
       
   854 
       
   855 // ---------------------------------------------------------------------------
       
   856 // CSifUiPrivate::UpdateDialogOrIndicatorWithoutWaitingL()
       
   857 // ---------------------------------------------------------------------------
       
   858 //
       
   859 void CSifUiPrivate::UpdateDialogOrIndicatorWithoutWaitingL()
       
   860     {
       
   861     if( IsIndicatorActive() )
       
   862         {
       
   863         UpdateInstallIndicatorProgressL();
       
   864         }
       
   865     else
       
   866         {
       
   867         DisplayDeviceDialogL();
       
   868         }
       
   869     }
       
   870 
       
   871 // ---------------------------------------------------------------------------
       
   872 // CSifUiPrivate::CompleteDialogOrIndicatorAndWaitForResponseL()
       
   873 // ---------------------------------------------------------------------------
       
   874 //
       
   875 void CSifUiPrivate::CompleteDialogOrIndicatorAndWaitForResponseL( TInt aErrorCode )
       
   876     {
       
   877     if( !IsCancelled() )
       
   878         {
       
   879         if( IsIndicatorActive() )
       
   880             {
       
   881             UpdateInstallIndicatorProgressL();
       
   882             ShowInstallIndicatorCompleteL( aErrorCode );
       
   883             CloseInstallIndicator();
       
   884             }
       
   885         else
       
   886             {
       
   887             DisplayDeviceDialogL();
       
   888             WaitForResponseL();
       
   889             }
       
   890         }
       
   891     }
       
   892 
       
   893 // ---------------------------------------------------------------------------
       
   894 // CSifUiPrivate::DisplayDeviceDialogL()
       
   895 // ---------------------------------------------------------------------------
       
   896 //
       
   897 void CSifUiPrivate::DisplayDeviceDialogL()
       
   898     {
       
   899     if( iDeviceDialog && iIsDisplayingDialog )
       
   900         {
       
   901         User::LeaveIfError( iDeviceDialog->Update( *VariantMapL() ) );
       
   902         }
       
   903     else
       
   904         {
       
   905         if( !iDeviceDialog )
       
   906             {
       
   907             iDeviceDialog = CHbDeviceDialogSymbian::NewL();
       
   908             }
       
   909         if( !iIsFirstTimeToDisplay )
       
   910             {
       
   911             ResendAllInstallationDetailsL();
       
   912             }
       
   913         User::LeaveIfError( iDeviceDialog->Show( KSifUiDeviceDialog, *VariantMapL(), this ) );
       
   914         iIsDisplayingDialog = ETrue;
       
   915         }
       
   916     iIsFirstTimeToDisplay = EFalse;
       
   917     }
       
   918 
       
   919 // ---------------------------------------------------------------------------
       
   920 // CSifUiPrivate::WaitForResponseL()
       
   921 // ---------------------------------------------------------------------------
       
   922 //
       
   923 void CSifUiPrivate::WaitForResponseL()
       
   924     {
       
   925     iWaitCompletionCode = KErrInUse;    // changed in WaitedResponseReceived() or in DoCancel()
       
   926     iDialogReturnValue = KErrUnknown;   // changed in DataReceived()
       
   927     if( !IsActive() && iWait && !iWait->IsStarted() )
       
   928         {
       
   929         iStatus = KRequestPending;
       
   930         SetActive();
       
   931         iWait->Start();
       
   932         }
       
   933     User::LeaveIfError( iWaitCompletionCode );
       
   934     }
       
   935 
       
   936 // ---------------------------------------------------------------------------
       
   937 // CSifUiPrivate::WaitedResponseReceived()
       
   938 // ---------------------------------------------------------------------------
       
   939 //
       
   940 void CSifUiPrivate::WaitedResponseReceived( TInt aCompletionCode )
       
   941     {
       
   942     if( IsActive() )
       
   943         {
       
   944         iWaitCompletionCode = aCompletionCode;
       
   945         TRequestStatus* status( &iStatus );
       
   946         User::RequestComplete( status, KErrNone );
       
   947         }
       
   948     }
       
   949