appinstall_plat/sifui_api/src/sifuiprivate.cpp
changeset 29 26b6f0522fd8
child 33 8110bf1194d1
equal deleted inserted replaced
25:98b66e4fb0be 29:26b6f0522fd8
       
     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 RSifUiCli class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "sifuiprivate.h"                       // CSifUiPrivate
       
    19 #include "sifuidefs.h"                          // SIF UI device dialog parameters
       
    20 #include <hb/hbcore/hbsymbiandevicedialog.h>    // CHbDeviceDialog
       
    21 #include <hb/hbcore/hbsymbianvariant.h>         // CHbSymbianVariantMap
       
    22 #include <swi/msisuihandlers.h>                 // Swi::CAppInfo
       
    23 #include <apgicnfl.h>                           // CApaMaskedBitmap
       
    24 
       
    25 const TInt KDriveLettersLen = 32;
       
    26 
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CSifUiPrivate::NewL()
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CSifUiPrivate* CSifUiPrivate::NewL()
       
    35     {
       
    36     CSifUiPrivate* self = new( ELeave ) CSifUiPrivate();
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CSifUiPrivate::~CSifUiPrivate()
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CSifUiPrivate::~CSifUiPrivate()
       
    48     {
       
    49     Cancel();
       
    50     delete iWait;
       
    51     delete iDeviceDialog;
       
    52     delete iVariantMap;
       
    53     delete iBitmap;
       
    54     delete iSelectableDrives;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CSifUiPrivate::ShowConfirmationL()
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 TBool CSifUiPrivate::ShowConfirmationL( const Swi::CAppInfo& aAppInfo,
       
    62     TInt aAppSize, const CApaMaskedBitmap* aAppIcon )
       
    63 	{
       
    64 	ChangeNoteTypeL( ESifUiConfirmationQuery );
       
    65 
       
    66 	AddParamsAppInfoAndSizeL( aAppInfo, aAppSize );
       
    67 	if( aAppIcon )
       
    68 		{
       
    69 		AddParamsIconL( aAppIcon );
       
    70 		}
       
    71 	if( iSelectableDrives )
       
    72 		{
       
    73 		AddParamL( KSifUiMemorySelection, *iSelectableDrives );
       
    74 		}
       
    75 
       
    76 	DisplayDeviceDialogL();
       
    77 	User::LeaveIfError( WaitForResponse() );
       
    78 	return( iReturnValue == KErrNone );
       
    79 	}
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CSifUiPrivate::SetMemorySelectionL()
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CSifUiPrivate::SetMemorySelectionL( const RArray<TInt>& aDriveNumbers )
       
    86 	{
       
    87 	if( iSelectableDrives )
       
    88 		{
       
    89 		delete iSelectableDrives;
       
    90 		iSelectableDrives = NULL;
       
    91 		}
       
    92 
       
    93 	TInt driveCount = aDriveNumbers.Count();
       
    94 	if( driveCount > 0 )
       
    95 		{
       
    96 		const TChar KComma = ',';
       
    97 		TBuf<KDriveLettersLen> driveList;
       
    98 		for( TInt index = 0; index < driveCount; ++index )
       
    99 			{
       
   100 			TChar driveLetter;
       
   101 			TInt err = RFs::DriveToChar( aDriveNumbers[ index ], driveLetter );
       
   102 			if( !err )
       
   103 				{
       
   104 				driveList.Append( driveLetter );
       
   105 				driveList.Append( KComma );
       
   106 				}
       
   107 			}
       
   108 		iSelectableDrives = driveList.AllocL();
       
   109 		}
       
   110 	}
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CSifUiPrivate::SelectedDrive()
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 TInt CSifUiPrivate::SelectedDrive( TInt& aDriveNumber )
       
   117 	{
       
   118     if( iSelectedDriveSet )
       
   119         {
       
   120         return RFs::CharToDrive( iSelectedDrive, aDriveNumber );
       
   121         }
       
   122     return KErrNotFound;
       
   123 	}
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CSifUiPrivate::SetCertificateInfoL()
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CSifUiPrivate::SetCertificateInfoL(
       
   130         const RPointerArray<Swi::CCertificateInfo>& aCertificates )
       
   131 	{
       
   132    if( aCertificates.Count() )
       
   133 		{
       
   134 		AddParamsCertificatesL( aCertificates );
       
   135 		}
       
   136 	}
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CSifUiPrivate::ShowProgressL()
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CSifUiPrivate::ShowProgressL( const Swi::CAppInfo& aAppInfo,
       
   143         TInt aAppSize, TInt aProgressBarFinalValue )
       
   144     {
       
   145     ChangeNoteTypeL( ESifUiProgressNote );
       
   146 
       
   147     AddParamsAppInfoAndSizeL( aAppInfo, aAppSize );
       
   148     AddParamL( KSifUiProgressNoteFinalValue, aProgressBarFinalValue );
       
   149 
       
   150     DisplayDeviceDialogL();
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CSifUiPrivate::IncreaseProgressBarValueL()
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 void CSifUiPrivate::IncreaseProgressBarValueL( TInt aNewValue )
       
   158     {
       
   159     ChangeNoteTypeL( ESifUiProgressNote );
       
   160 
       
   161     AddParamL( KSifUiProgressNoteValue, aNewValue );
       
   162 
       
   163     DisplayDeviceDialogL();
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CSifUiPrivate::ShowCompleteL()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CSifUiPrivate::ShowCompleteL()
       
   171     {
       
   172     ChangeNoteTypeL( ESifUiCompleteNote );
       
   173     DisplayDeviceDialogL();
       
   174     User::LeaveIfError( WaitForResponse() );
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CSifUiPrivate::ShowFailedL()
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CSifUiPrivate::ShowFailedL( TInt aErrorCode, const TDesC& aErrorMessage,
       
   182         const TDesC& aErrorDetails )
       
   183     {
       
   184     ChangeNoteTypeL( ESifUiErrorNote );
       
   185 
       
   186     AddParamL( KSifUiErrorCode, aErrorCode );
       
   187     AddParamL( KSifUiErrorMessage, aErrorMessage );
       
   188     if( aErrorDetails != KNullDesC )
       
   189         {
       
   190         AddParamL( KSifUiErrorDetails, aErrorDetails );
       
   191         }
       
   192 
       
   193     DisplayDeviceDialogL();
       
   194     User::LeaveIfError( WaitForResponse() );
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CSifUiPrivate::DoCancel()
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void CSifUiPrivate::DoCancel()
       
   202     {
       
   203     if( iWait && iWait->IsStarted() && iWait->CanStopNow() )
       
   204         {
       
   205         iCompletionCode = KErrCancel;
       
   206         iWait->AsyncStop();
       
   207         }
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CSifUiPrivate::RunL()
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void CSifUiPrivate::RunL()
       
   215     {
       
   216     if( iWait )
       
   217         {
       
   218         iWait->AsyncStop();
       
   219         }
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CSifUiPrivate::DataReceived()
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CSifUiPrivate::DataReceived( CHbSymbianVariantMap& aData )
       
   227     {
       
   228     const CHbSymbianVariant* selectedDriveVariant = aData.Get( KSifUiSelectedMemory );
       
   229     if( selectedDriveVariant )
       
   230     	{
       
   231 		iSelectedDrive = *( selectedDriveVariant->Value<TChar>() );
       
   232 		iSelectedDriveSet = ETrue;
       
   233     	}
       
   234 
       
   235     const CHbSymbianVariant* acceptedVariant = aData.Get( KSifUiQueryAccepted );
       
   236     if( acceptedVariant )
       
   237         {
       
   238         TBool* acceptedValue = acceptedVariant->Value<TBool>();
       
   239         if( acceptedValue && *acceptedValue )
       
   240             {
       
   241             iReturnValue = KErrNone;
       
   242             }
       
   243         else
       
   244             {
       
   245             iReturnValue = KErrCancel;
       
   246             }
       
   247         ResponseReceived( KErrNone );
       
   248         }
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CSifUiPrivate::DeviceDialogClosed()
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 void CSifUiPrivate::DeviceDialogClosed( TInt aCompletionCode )
       
   256     {
       
   257     iIsDisplayingDialog = EFalse;
       
   258     ResponseReceived( aCompletionCode );
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CSifUiPrivate::CSifUiPrivate()
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 CSifUiPrivate::CSifUiPrivate() : CActive( CActive::EPriorityStandard )
       
   266     {
       
   267     CActiveScheduler::Add( this );
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // CSifUiPrivate::ConstructL()
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 void CSifUiPrivate::ConstructL()
       
   275     {
       
   276     iWait = new( ELeave ) CActiveSchedulerWait;
       
   277     // iDeviceDialog is allocated later, first call of DisplayDeviceDialogL()
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CSifUiPrivate::ClearParamsL()
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 void CSifUiPrivate::ClearParamsL()
       
   285     {
       
   286     if( iVariantMap )
       
   287         {
       
   288         delete iVariantMap;
       
   289         iVariantMap = NULL;
       
   290         }
       
   291     iVariantMap = CHbSymbianVariantMap::NewL();
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CSifUiPrivate::ChangeNoteTypeL()
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void CSifUiPrivate::ChangeNoteTypeL( TInt aType )
       
   299     {
       
   300     ClearParamsL();
       
   301     AddParamL( KSifUiDialogType, aType );
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CSifUiPrivate::AddParamL()
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 void CSifUiPrivate::AddParamL( const TDesC& aKey, TInt aValue )
       
   309     {
       
   310     CHbSymbianVariant* variant = NULL;
       
   311     variant = CHbSymbianVariant::NewL( &aValue, CHbSymbianVariant::EInt );
       
   312     iVariantMap->Add( aKey, variant );
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CSifUiPrivate::AddParamL()
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 void CSifUiPrivate::AddParamL( const TDesC& aKey, const TDesC& aValue )
       
   320     {
       
   321     CHbSymbianVariant* variant = NULL;
       
   322     variant = CHbSymbianVariant::NewL( &aValue, CHbSymbianVariant::EDes );
       
   323     iVariantMap->Add( aKey, variant );
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CSifUiPrivate::AddParamListL()
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 void CSifUiPrivate::AddParamListL( const TDesC& aKey, const MDesCArray& aList )
       
   331     {
       
   332     CHbSymbianVariant* variant = NULL;
       
   333     variant = CHbSymbianVariant::NewL( &aList, CHbSymbianVariant::EDesArray );
       
   334     iVariantMap->Add( aKey, variant );
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // CSifUiPrivate::AddParamsAppInfoAndSizeL()
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 void CSifUiPrivate::AddParamsAppInfoAndSizeL( const Swi::CAppInfo& aAppInfo, TInt aAppSize )
       
   342     {
       
   343     AddParamL( KSifUiApplicationName, aAppInfo.AppName() );
       
   344     const TVersion& version( aAppInfo.AppVersion() );
       
   345     if( version.iBuild || version.iMajor || version.iMinor )
       
   346         {
       
   347         AddParamL( KSifUiApplicationVersion, version.Name() );
       
   348         }
       
   349     if( aAppInfo.AppVendor().Length() )
       
   350         {
       
   351         AddParamL( KSifUiApplicationDetails, aAppInfo.AppVendor() );
       
   352         }
       
   353     if( aAppSize > 0 )
       
   354         {
       
   355         AddParamL( KSifUiApplicationSize, aAppSize );
       
   356         }
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // CSifUiPrivate::AddParamsIconL()
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 void CSifUiPrivate::AddParamsIconL( const CApaMaskedBitmap* aIcon )
       
   364     {
       
   365     if( aIcon )
       
   366         {
       
   367         if( iBitmap )
       
   368             {
       
   369             delete iBitmap;
       
   370             iBitmap = NULL;
       
   371             }
       
   372         iBitmap = CApaMaskedBitmap::NewL( aIcon );
       
   373 
       
   374         CHbSymbianVariant* variant = NULL;
       
   375         TInt bitmapHandle = iBitmap->Handle();
       
   376         variant = CHbSymbianVariant::NewL( &bitmapHandle, CHbSymbianVariant::EInt );
       
   377         iVariantMap->Add( KSifUiApplicationIconHandle, variant );
       
   378         TInt bitmapMaskHandle = iBitmap->Mask()->Handle();
       
   379         variant = CHbSymbianVariant::NewL( &bitmapMaskHandle, CHbSymbianVariant::EInt );
       
   380         iVariantMap->Add( KSifUiApplicationIconMaskHandle, variant );
       
   381         }
       
   382     }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // CSifUiPrivate::AddParamsCertificatesL()
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 void CSifUiPrivate::AddParamsCertificatesL( const RPointerArray<Swi::CCertificateInfo>& /*aCertificates*/ )
       
   389     {
       
   390     // TODO: implement
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // CSifUiPrivate::DisplayDeviceDialogL()
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 void CSifUiPrivate::DisplayDeviceDialogL()
       
   398     {
       
   399     if( iDeviceDialog && iIsDisplayingDialog )
       
   400         {
       
   401         iDeviceDialog->Update( *iVariantMap );
       
   402         }
       
   403     else
       
   404         {
       
   405         if( !iDeviceDialog )
       
   406             {
       
   407             iDeviceDialog = CHbDeviceDialog::NewL();
       
   408             }
       
   409         iDeviceDialog->Show( KSifUiDeviceDialog, *iVariantMap, this );
       
   410         iIsDisplayingDialog = ETrue;
       
   411         }
       
   412     }
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // CSifUiPrivate::WaitForResponse()
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 TInt CSifUiPrivate::WaitForResponse()
       
   419     {
       
   420     iCompletionCode = KErrInUse;
       
   421     iReturnValue = KErrUnknown;
       
   422     if( !IsActive() && iWait && !iWait->IsStarted() )
       
   423         {
       
   424         iStatus = KRequestPending;
       
   425         SetActive();
       
   426         iWait->Start();
       
   427         }
       
   428     return iCompletionCode;
       
   429     }
       
   430 
       
   431 // ---------------------------------------------------------------------------
       
   432 // CSifUiPrivate::ResponseReceived()
       
   433 // ---------------------------------------------------------------------------
       
   434 //
       
   435 void CSifUiPrivate::ResponseReceived( TInt aCompletionCode )
       
   436     {
       
   437     if( IsActive() )
       
   438         {
       
   439         iCompletionCode = aCompletionCode;
       
   440         TRequestStatus* status( &iStatus );
       
   441         User::RequestComplete( status, KErrNone );
       
   442         }
       
   443     }
       
   444