widgets/widgetinstaller/src/WidgetUIHandler.cpp
changeset 0 dd21522fd290
child 16 a359256acfc6
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 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 the License "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:  This file contains the header file of the CMidletUI class.
       
    15 *
       
    16 *                This class implements the ECom SWInstUIPluginAPI interface
       
    17 *                for midlet installation.
       
    18 *
       
    19 */
       
    20 
       
    21 #include <Avkon.rsg>
       
    22 #include <WidgetInstallerUI.rsg>
       
    23 #include <stringloader.h>
       
    24 #include <PathInfo.h>
       
    25 #include <aknnotewrappers.h>
       
    26 #include "SWInstWidgetUid.h"
       
    27 #include "WidgetInstallerInternalCRKeys.h"
       
    28 #include "WidgetUIHandler.h"
       
    29 
       
    30 
       
    31 // CONSTANTS
       
    32 const TInt KB = 1024;
       
    33 
       
    34 using namespace SwiUI;
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // ============================================================================
       
    39 // CWidgetUIHandler::NewL()
       
    40 // two-phase constructor
       
    41 //
       
    42 // @since 3.1
       
    43 // ============================================================================
       
    44 //
       
    45 CWidgetUIHandler* CWidgetUIHandler::NewL( TInstallMode aMode,
       
    46                                           MWidgetUICancelObserver* aCancelObserver )
       
    47     {
       
    48     CWidgetUIHandler* self = new( ELeave ) CWidgetUIHandler( aMode, aCancelObserver );
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop( self );
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ============================================================================
       
    56 // CWidgetUIHandler:CWidgetUIHandler()
       
    57 // C++ default constructor
       
    58 //
       
    59 // @since 3.1
       
    60 // ============================================================================
       
    61 //
       
    62 CWidgetUIHandler::CWidgetUIHandler( TInstallMode aMode,
       
    63                                     MWidgetUICancelObserver* aCancelObserver )
       
    64     :iCancelObserver( aCancelObserver ),
       
    65      iMode( aMode )
       
    66     {
       
    67     }
       
    68 
       
    69 // ============================================================================
       
    70 // CWidgetUIHandler:ConstructL()
       
    71 // Symbian default constructor
       
    72 //
       
    73 // @since 3.1
       
    74 // ============================================================================
       
    75 //
       
    76 void CWidgetUIHandler::ConstructL()
       
    77     {
       
    78     iCommonDialogs = CommonUI::CCUIDialogs::NewL();
       
    79     if ( iMode == EModeInstall )
       
    80          {
       
    81          iProgressNumbers = new ( ELeave ) CArrayFixFlat<TInt>( 2 );
       
    82          iProgressNumbers->ResizeL( 2 );
       
    83          iCommonDialogs->ShowWaitDialogL( R_WIDGETUI_PREPARE, this, R_AVKON_SOFTKEYS_EMPTY );
       
    84          }
       
    85     }
       
    86 
       
    87 // ============================================================================
       
    88 // CWidgetUIHandler::~CWidgetUIHandler()
       
    89 // destructor
       
    90 //
       
    91 // @since 3.1
       
    92 // ============================================================================
       
    93 //
       
    94 CWidgetUIHandler::~CWidgetUIHandler()
       
    95     {
       
    96     delete iProgressNumbers;
       
    97     delete iCommonDialogs;
       
    98     }
       
    99 
       
   100 
       
   101 // ============================================================================
       
   102 // CWidgetUIHandler::DisplayInstallL()
       
   103 // Displays a dialog at the beginning of an installation
       
   104 //
       
   105 // @since 3.1
       
   106 // ============================================================================
       
   107 //
       
   108 TBool CWidgetUIHandler::DisplayInstallL(
       
   109     const TDesC& aWidgetName
       
   110     )
       
   111     {
       
   112     iShowingDialog = ETrue;
       
   113 
       
   114     // Close the preparing wait dialog
       
   115     iCommonDialogs->CloseWaitDialogL();
       
   116 
       
   117     TBool result( EFalse );
       
   118 
       
   119     HBufC* prompt = StringLoader::LoadLC( R_WIDGETUI_INSTALL_PROMPT, aWidgetName );
       
   120     if ( iCommonDialogs->ShowConfirmationQueryL( *prompt, R_AVKON_SOFTKEYS_YES_NO ) )
       
   121         {
       
   122         result = ETrue;
       
   123         }
       
   124     else
       
   125         {
       
   126         // Make sure no notes are shown after this
       
   127         iShownFinalNote = ETrue;
       
   128         }
       
   129 
       
   130     CleanupStack::PopAndDestroy( prompt );
       
   131 
       
   132     iShowingDialog = EFalse;
       
   133     return result;
       
   134     }
       
   135 
       
   136 // ============================================================================
       
   137 // CWidgetUIHandler::DisplayOverwriteL()
       
   138 // Displays a dialog at the beginning of an update
       
   139 //
       
   140 // @since 3.1
       
   141 // ============================================================================
       
   142 //
       
   143 TBool CWidgetUIHandler::DisplayOverwriteL(
       
   144     const TDesC& aWidgetName
       
   145     )
       
   146     {
       
   147     iShowingDialog = ETrue;
       
   148 
       
   149     // Close the preparing wait dialog
       
   150     iCommonDialogs->CloseWaitDialogL();
       
   151 
       
   152     TBool result( EFalse ); // false means user says no/cancel/stop
       
   153 
       
   154     HBufC* prompt = StringLoader::LoadLC( R_WIDGETUI_OVERWRITE_PROMPT, aWidgetName );
       
   155     if ( iCommonDialogs->ShowConfirmationQueryL( *prompt, R_AVKON_SOFTKEYS_YES_NO ) )
       
   156         {
       
   157         result = ETrue;
       
   158         }
       
   159     else
       
   160         {
       
   161         // Make sure no notes are shown after this
       
   162         iShownFinalNote = ETrue;
       
   163         }
       
   164 
       
   165     CleanupStack::PopAndDestroy( prompt );
       
   166 
       
   167     iShowingDialog = EFalse;
       
   168     return result;
       
   169     }
       
   170 
       
   171 
       
   172 // ============================================================================
       
   173 // CWidgetUIHandler::DisplayUpgradeL()
       
   174 // Displays a dialog asking whether we want to upgrade an application present on the device.
       
   175 //
       
   176 // @since 3.1
       
   177 // ============================================================================
       
   178 //
       
   179 TBool CWidgetUIHandler::DisplayUpgradeL( const Swi::CAppInfo& /*aAppInfo*/,
       
   180                                const Swi::CAppInfo& /*aExistingAppInfo*/ )
       
   181     {
       
   182     return ETrue;
       
   183     }
       
   184 
       
   185 // ============================================================================
       
   186 // CWidgetUIHandler::DisplayUninstallL()
       
   187 // Displays a dialog at the start of the uninstallation with
       
   188 // information about the application to be uninstalled.
       
   189 //
       
   190 // @since 3.1
       
   191 // ============================================================================
       
   192 //
       
   193 TBool CWidgetUIHandler::DisplayUninstallL( const TDesC& aWidgetName )
       
   194     {
       
   195     iShowingDialog = ETrue;
       
   196 
       
   197     // Close the preparing wait dialog
       
   198     iCommonDialogs->CloseWaitDialogL();
       
   199 
       
   200     TBool result( EFalse );
       
   201 
       
   202     HBufC* prompt = StringLoader::LoadLC( R_WIDGETUI_UNINSTALL_PROMPT, aWidgetName );
       
   203     if ( iCommonDialogs->ShowConfirmationQueryL( *prompt, R_AVKON_SOFTKEYS_YES_NO ) )
       
   204         {
       
   205         result = ETrue;
       
   206         }
       
   207     else
       
   208         {
       
   209         // Make sure no notes are shown after this
       
   210         iShownFinalNote = ETrue;
       
   211         }
       
   212 
       
   213     CleanupStack::PopAndDestroy( prompt );
       
   214 
       
   215     iShowingDialog = EFalse;
       
   216     return result;
       
   217     }
       
   218 
       
   219 // ============================================================================
       
   220 // CWidgetUIHandler::DisplayTextL()
       
   221 // Displays a dialog with given text
       
   222 //
       
   223 // @since 3.1
       
   224 // ============================================================================
       
   225 //
       
   226 TBool CWidgetUIHandler::DisplayTextL( const TDesC& /*aText*/ )
       
   227     {
       
   228     return ETrue;
       
   229     }
       
   230 
       
   231 // ============================================================================
       
   232 // CWidgetUIHandler::DisplayErrorL()
       
   233 // Displays a dialog with given error
       
   234 //
       
   235 // @since 3.1
       
   236 // ============================================================================
       
   237 //
       
   238 void CWidgetUIHandler::DisplayErrorL( TInt aErr )
       
   239     {
       
   240     iShowingDialog = ETrue;
       
   241     HBufC* prompt = NULL;
       
   242 
       
   243     switch ( aErr )
       
   244         {
       
   245         case KErrNotSupported:
       
   246             prompt = StringLoader::LoadLC( R_WIDGETUI_UNSUPPORTED );
       
   247             break;
       
   248         case KErrCorrupt:
       
   249             prompt = StringLoader::LoadLC( R_WIDGETUI_CORRUPTED );
       
   250             break;
       
   251         case KErrNoMemory:
       
   252             prompt = StringLoader::LoadLC( R_WIDGETUI_NO_MEMORY );
       
   253             break;
       
   254         case KErrInUse:
       
   255             prompt = StringLoader::LoadLC( R_WIDGETUI_ERR_INUSE );
       
   256             break;
       
   257         default:
       
   258             prompt = StringLoader::LoadLC( R_WIDGETUI_ERR_GENERAL );
       
   259             break;
       
   260         }
       
   261 
       
   262     iCommonDialogs->ShowErrorNoteL( prompt->Des() );
       
   263     CleanupStack::PopAndDestroy(); // prompt
       
   264 
       
   265     iShowingDialog = EFalse;
       
   266     }
       
   267 
       
   268 // ============================================================================
       
   269 // CWidgetUIHandler::DisplayApplicationsInUseL()
       
   270 // Displays a dialog with information that the widget is already in use
       
   271 //
       
   272 // @since 3.1
       
   273 // ============================================================================
       
   274 //
       
   275 TBool CWidgetUIHandler::DisplayApplicationsInUseL( const Swi::CAppInfo& /*aAppInfo*/,
       
   276                                          const RPointerArray<TDesC>& /*aAppNames*/ )
       
   277     {
       
   278     return ETrue;
       
   279     }
       
   280 
       
   281 // ============================================================================
       
   282 // CWidgetUIHandler::HandleDialogExitL()
       
   283 //  when user click softkey during progress dialog
       
   284 //
       
   285 // @since 3.1
       
   286 // ============================================================================
       
   287 //
       
   288 TBool CWidgetUIHandler::HandleDialogExitL( TInt aButtonId )
       
   289     {
       
   290     TBool result( EFalse );
       
   291 
       
   292     if ( aButtonId == EAknSoftkeyCancel )
       
   293         {
       
   294         result = ETrue;
       
   295         iCancelObserver->UserCancelL( EFalse );
       
   296         }
       
   297 
       
   298     return result;
       
   299     }
       
   300 
       
   301 // ============================================================================
       
   302 // CWidgetUIHandler::UpdateProgessDialogL
       
   303 // Increments installation progress
       
   304 //
       
   305 // @since 3.1
       
   306 // ============================================================================
       
   307 //
       
   308 void CWidgetUIHandler::UpdateProgressDialogL( TInt aSize )
       
   309 {
       
   310     iInstalledSize += aSize;
       
   311 
       
   312     // rest just updates strings showing kilobytes processed
       
   313     if ( KB < iUncompressedSize ) // if less than 1K then dialog is meaningless
       
   314         {
       
   315         iCommonDialogs->UpdateProgressDialogValueL( aSize );
       
   316         (*iProgressNumbers)[0] = iInstalledSize / KB;
       
   317         HBufC* displayString = StringLoader::LoadLC( R_WIDGETUI_PROGRESS, *iProgressNumbers );
       
   318         iCommonDialogs->ShowProgressDialogL( *displayString, this ); // just updates size strings
       
   319         CleanupStack::PopAndDestroy();  // displayString
       
   320         }
       
   321 }
       
   322 
       
   323 // ============================================================================
       
   324 // CWidgetUIHandler::DisplayProgessDialogL
       
   325 // Starts installation progress dialog display
       
   326 //
       
   327 // @since 3.1
       
   328 // ============================================================================
       
   329 //
       
   330 void CWidgetUIHandler::DisplayProgressDialogL()
       
   331     {
       
   332     iInstalledSize = 0;
       
   333 
       
   334     if ( KB < iUncompressedSize ) // if less than 1K then dialog is meaningless
       
   335         {
       
   336         (*iProgressNumbers)[0] = 0;
       
   337         (*iProgressNumbers)[1] = iUncompressedSize / KB;
       
   338         HBufC* displayString = StringLoader::LoadLC( R_WIDGETUI_PROGRESS, *iProgressNumbers );
       
   339         iCommonDialogs->ShowProgressDialogL( *displayString, this );
       
   340         iCommonDialogs->SetProgressDialogFinalValueL( iUncompressedSize );
       
   341         CleanupStack::PopAndDestroy();  // displayString
       
   342         }
       
   343 }
       
   344 
       
   345 
       
   346 // ============================================================================
       
   347 // CWidgetUIHandler::SelectDriveL
       
   348 // Asks the UI for a drive to select.
       
   349 // (other items were commented in a header).
       
   350 //
       
   351 // @since 3.1
       
   352 // ============================================================================
       
   353 //
       
   354 TBool CWidgetUIHandler::SelectDriveL( RFs& aFs,
       
   355                                       TDriveUnit& aDrive,
       
   356                                       TBool& aSufficientSpace,
       
   357                                       TInt aTotalSize)
       
   358     {
       
   359     aSufficientSpace = EFalse;
       
   360     TBool result( EFalse );
       
   361 
       
   362     iShowingDialog = ETrue;
       
   363     iUncompressedSize = aTotalSize;
       
   364 
       
   365     TInt error = KErrNone;
       
   366 
       
   367     // List of all possible installation detination drives
       
   368     RArray<TDriveUnit> driveUnits;
       
   369     CleanupClosePushL( driveUnits );
       
   370     // and free memory space in those drives
       
   371     RArray<TInt64> driveSpaces;
       
   372     CleanupClosePushL( driveSpaces );
       
   373 
       
   374     // List all drives in the system
       
   375     TDriveList driveList;
       
   376     User::LeaveIfError( aFs.DriveList(driveList) );
       
   377 
       
   378     // Check all drives
       
   379     for ( TInt driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++ )
       
   380         {
       
   381         if ( EDriveD == driveNumber)
       
   382             {
       
   383             // The drive is not suitable for installation
       
   384             continue;
       
   385             }
       
   386 
       
   387         if ( !driveList[driveNumber] )
       
   388             {
       
   389             // Not a recognised drive
       
   390             continue;
       
   391             }
       
   392 
       
   393         TVolumeInfo volInfo;
       
   394         if ( aFs.Volume( volInfo, driveNumber ) != KErrNone )
       
   395             {
       
   396             // The volume is not usable (e.g. no media card inserted)
       
   397             continue;
       
   398             }
       
   399 
       
   400         if ( volInfo.iDrive.iType==EMediaNotPresent ||
       
   401              volInfo.iDrive.iType==EMediaRom ||
       
   402              volInfo.iDrive.iType==EMediaRemote )
       
   403             {
       
   404             // Exclude drives not suitable for installation
       
   405             continue;
       
   406             }
       
   407 
       
   408         // Exclude read only and substituted drives
       
   409         if ( volInfo.iDrive.iDriveAtt & KDriveAttRom ||
       
   410              volInfo.iDrive.iDriveAtt & KDriveAttSubsted )
       
   411             {
       
   412             continue;
       
   413             }
       
   414 
       
   415         // Check whether the drive is usable for installation! E.g. not a
       
   416         // temporary ram drive. This is vendor-implemented function which is
       
   417         // device-specific.
       
   418 // PlpVariant library doesn't have any implementation for DriveStatusL() yet
       
   419 //       if (PlpVariant::DriveStatusL(static_cast<TDriveNumber>(driveNumber)) !=
       
   420 //           static_cast<TUint32> (KErrNone))
       
   421 
       
   422         TInt64 volSpace = volInfo.iFree;  // bytes
       
   423         User::LeaveIfError( driveUnits.Append( TDriveUnit( driveNumber ) ) );
       
   424         User::LeaveIfError( driveSpaces.Append( volSpace / KB ) );
       
   425         }
       
   426 
       
   427     TInt selection( 0 );
       
   428 
       
   429     error = iCommonDialogs->ShowDriveSelectionDialogL( aTotalSize,
       
   430                                                        driveUnits,
       
   431                                                        driveSpaces,
       
   432                                                        selection );
       
   433     if ( error == KErrNoMemory )
       
   434         {
       
   435         // The engine will call us with proper ota status ( no memory )
       
   436         aSufficientSpace = EFalse;
       
   437         result = ETrue;
       
   438         }
       
   439     else if ( error == KErrCancel )
       
   440         {
       
   441         // User cancelled the query
       
   442         aSufficientSpace = ETrue;
       
   443         result = EFalse;
       
   444         }
       
   445     else
       
   446         {
       
   447         // OK To install
       
   448         result = ETrue;
       
   449         aDrive = driveUnits[selection];
       
   450         aSufficientSpace = ETrue;
       
   451         }
       
   452 
       
   453     CleanupStack::PopAndDestroy( 2 ); // &driveSpaces, &driveUnits
       
   454 
       
   455     iShowingDialog = EFalse;
       
   456 
       
   457     return result;
       
   458     }
       
   459 
       
   460 // ============================================================================
       
   461 // CWidgetUIInstallHandler::DisplayCompleteL()
       
   462 // Display install completed information
       
   463 //
       
   464 // @since 3.1
       
   465 // ============================================================================
       
   466 //
       
   467 void CWidgetUIHandler::DisplayCompleteL()
       
   468     {
       
   469     if ( !iShownFinalNote )
       
   470         {
       
   471         HBufC* string = NULL;
       
   472         if ( iMode == EModeInstall )
       
   473             {
       
   474             string = StringLoader::LoadLC( R_WIDGETUI_INSTALL_COMPLETED );
       
   475             }
       
   476         else
       
   477             {
       
   478             string = StringLoader::LoadLC( R_WIDGETUI_UNINSTALL_COMPLETED );
       
   479             }
       
   480 
       
   481         CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( ETrue );
       
   482         note->ExecuteLD( *string );
       
   483         CleanupStack::PopAndDestroy( string );
       
   484         }
       
   485 
       
   486     iShownFinalNote = ETrue;
       
   487     }
       
   488 
       
   489 // ============================================================================
       
   490 // CWidgetUIInstallHandler::DisplayCancelL()
       
   491 // Display install canceled information
       
   492 //
       
   493 // @since 3.1
       
   494 // ============================================================================
       
   495 //
       
   496 void CWidgetUIHandler::DisplayCancelL()
       
   497 {
       
   498     HBufC* string = NULL;
       
   499     if ( iMode == EModeInstall )
       
   500     {
       
   501         string = StringLoader::LoadLC( R_WIDGETUI_INSTALL_CANCELED );
       
   502     }
       
   503     else
       
   504     {
       
   505         string = StringLoader::LoadLC( R_WIDGETUI_UNINSTALL_CANCELED );
       
   506     }
       
   507 
       
   508     CAknConfirmationNote* note = new ( ELeave ) CAknConfirmationNote( ETrue );
       
   509     note->ExecuteLD( *string );
       
   510     CleanupStack::PopAndDestroy( string );
       
   511 }
       
   512 
       
   513 // ============================================================================
       
   514 // CWidgetUIInstallHandler::DisplayFinalizeDialogL()
       
   515 // Display the finalize dialog
       
   516 //
       
   517 // @since 3.1
       
   518 // ============================================================================
       
   519 //
       
   520 void CWidgetUIHandler::DisplayFinalizeDialogL()
       
   521     {
       
   522     iCommonDialogs->ShowWaitDialogL( R_WIDGETUI_FINALIZE_INSTALL,
       
   523                                      this, R_AVKON_SOFTKEYS_EMPTY );
       
   524     }
       
   525 
       
   526 // ============================================================================
       
   527 // CWidgetUIInstallHandler::DisplayUninstallInProgressL()
       
   528 // Display the finalize dialog
       
   529 //
       
   530 // @since 5.0
       
   531 // ============================================================================
       
   532 //
       
   533 void CWidgetUIHandler::DisplayUninstallInProgressL()
       
   534     {
       
   535     iCommonDialogs->ShowWaitDialogL( R_WIDGETUI_UNINSTALL_PROGRESS,
       
   536                                      this, R_AVKON_SOFTKEYS_EMPTY );
       
   537     }
       
   538     
       
   539 // ============================================================================
       
   540 // CWidgetUIInstallHandler::DisplayUntrustedSecurityDialogL()
       
   541 // Display the untrusted widget dialog
       
   542 //
       
   543 // @since 5.0
       
   544 // ============================================================================
       
   545 //
       
   546 TBool CWidgetUIHandler::DisplayUntrustedSecurityDialogL()
       
   547     {
       
   548     // Untrusted Widget Installation dialog
       
   549     TInt securityPrompt(0);
       
   550     TBool resp(ETrue);
       
   551     TRAP_IGNORE(
       
   552         CRepository* rep = CRepository::NewL( TUid::Uid( KSWInstWidgetUIUid ) );
       
   553         rep->Get( KWidgetSecurityPromptUntrustedInstall, securityPrompt );
       
   554         delete rep; );
       
   555         
       
   556     if (securityPrompt)
       
   557         {
       
   558         resp = iCommonDialogs->ShowSecurityWarningDialogL();
       
   559         }
       
   560     return resp;
       
   561     }
       
   562     
       
   563 //  End of File