widgets/widgetinstaller/src/WidgetUIOperationsWatcher.cpp
changeset 16 a359256acfc6
parent 0 dd21522fd290
child 17 c8a366e56285
equal deleted inserted replaced
13:10e98eab6f85 16:a359256acfc6
    24 #include <zipfile.h>
    24 #include <zipfile.h>
    25 
    25 
    26 #include <SWInstTaskManager.h>
    26 #include <SWInstTaskManager.h>
    27 #include <SWInstTask.h>
    27 #include <SWInstTask.h>
    28 #include <SWInstLogTaskParam.h>
    28 #include <SWInstLogTaskParam.h>
    29 
    29 #include <apacmdln.h>
    30 
    30 #include <s32mem.h>
    31 
    31 
       
    32 #include <widgetappdefs.rh>
    32 #include "WidgetUIOperationsWatcher.h"
    33 #include "WidgetUIOperationsWatcher.h"
    33 #include "WidgetUIConfigHandler.h" // info.plist parser
    34 #include "WidgetUIConfigHandler.h" // info.plist parser
    34 #include "WidgetRegistrationManager.h" // interface to "shell"
    35 #include "WidgetRegistrationManager.h" // interface to "shell"
    35 
    36 
    36 // CONSTANTS
    37 // CONSTANTS
    88 // @since 3.1
    89 // @since 3.1
    89 // ============================================================================
    90 // ============================================================================
    90 //
    91 //
    91 CWidgetUIOperationsWatcher::CWidgetUIOperationsWatcher()
    92 CWidgetUIOperationsWatcher::CWidgetUIOperationsWatcher()
    92     : CActive( CActive::EPriorityStandard ),
    93     : CActive( CActive::EPriorityStandard ),
    93       iPropertyValues( EWidgetPropertyIdCount )
    94       iPropertyValues( EWidgetPropertyIdCount ),
       
    95       iWidgetInHS( EFalse )
    94     {
    96     {
    95     CActiveScheduler::Add( this );
    97     CActiveScheduler::Add( this );
    96     }
    98     }
    97 
    99 
    98 // ============================================================================
   100 // ============================================================================
   435         {
   437         {
   436         // replacement for currently installed widget
   438         // replacement for currently installed widget
   437         *(iPropertyValues[EUid]) = iRegistry.GetWidgetUidL(
   439         *(iPropertyValues[EUid]) = iRegistry.GetWidgetUidL(
   438             *(iPropertyValues[EBundleIdentifier]));
   440             *(iPropertyValues[EBundleIdentifier]));
   439         found = ETrue;
   441         found = ETrue;
   440         if ( iRegistry.IsWidgetRunning( 
   442         TUid aUid = TUid::Uid( *(iPropertyValues[EUid]) );
   441                 TUid::Uid( *(iPropertyValues[EUid]) )) )
   443         iWidgetInHS = iRegistry.IsWidgetInMiniView( aUid );
       
   444         if ( iRegistry.IsWidgetRunning( aUid ) )
   442             {
   445             {
   443             iUIHandler->CloseProgressDialogL();
   446             //Runnning widget should be first closed
   444             User::Leave( KErrInUse );
   447             RApaLsSession apaLsSession;
       
   448             apaLsSession.Connect();
       
   449             TApaAppInfo info;
       
   450                         
       
   451             User::LeaveIfError( apaLsSession.GetAppInfo( info, aUid ) );
       
   452             iWidgetName = info.iFullName;
       
   453             HBufC *widgetName = iWidgetName.AllocLC();
       
   454             HandleWidgetCommandL(apaLsSession, *widgetName, aUid, Deactivate);
       
   455                         
       
   456             CleanupStack::PopAndDestroy( widgetName );
       
   457             apaLsSession.Close();
   445             }
   458             }
   446         // get original install dir from registry in case user
   459         // get original install dir from registry in case user
   447         // decides to "overrite" to another memory location
   460         // decides to "overrite" to another memory location
   448         iOriginalDir = *( iRegistry.GetWidgetPropertyValueL(
   461         iOriginalDir = *( iRegistry.GetWidgetPropertyValueL(
   449                               TUid::Uid( *(iPropertyValues[EUid]) ),
   462                               TUid::Uid( *(iPropertyValues[EUid]) ),
   727         {
   740         {
   728         if ( iOverwriting )
   741         if ( iOverwriting )
   729             {
   742             {
   730             TUid uid = TUid::Uid( *(iPropertyValues[EUid]) );
   743             TUid uid = TUid::Uid( *(iPropertyValues[EUid]) );
   731             iRegistry.DeRegisterWidgetL( uid );
   744             iRegistry.DeRegisterWidgetL( uid );
   732             iAppManager->DeregisterWidgetL( uid );
       
   733             }
   745             }
   734 
   746 
   735         // TODO if registration steps fail does it leave inconsistent state???
   747         // TODO if registration steps fail does it leave inconsistent state???
   736 
   748 
   737         iRegistry.RegisterWidgetL( iPropertyValues );
   749         iRegistry.RegisterWidgetL( iPropertyValues );
   744 
   756 
   745         if ( iOverwriting )
   757         if ( iOverwriting )
   746             {
   758             {
   747             // delete backup
   759             // delete backup
   748             (void)iFileMgr->RmDir( iBackupDir );
   760             (void)iFileMgr->RmDir( iBackupDir );
       
   761             
       
   762             // if widget was in home screen, add it back to home screen
       
   763             if ( iWidgetInHS )
       
   764                 {
       
   765                 RApaLsSession apaLsSession;
       
   766                 apaLsSession.Connect();
       
   767        
       
   768                 HBufC* widgetName = iWidgetName.AllocLC();
       
   769                 HandleWidgetCommandL(apaLsSession, *widgetName, TUid::Uid( *(iPropertyValues[EUid]) ), WidgetRestart);
       
   770                 CleanupStack::PopAndDestroy( widgetName );
       
   771 
       
   772                 apaLsSession.Close();
       
   773                 }
   749             }
   774             }
   750 
   775 
   751         iUIHandler->CloseFinalizeDialogL();
   776         iUIHandler->CloseFinalizeDialogL();
   752         iUIHandler->DisplayCompleteL();
   777         iUIHandler->DisplayCompleteL();
   753 
   778 
   906     iUIHandler =
   931     iUIHandler =
   907         CWidgetUIHandler::NewL( CWidgetUIHandler::EModeUninstall, this );
   932         CWidgetUIHandler::NewL( CWidgetUIHandler::EModeUninstall, this );
   908 
   933 
   909     // save client status to use in finish uninstall
   934     // save client status to use in finish uninstall
   910     iRequestStatus = &aRequestStatus;
   935     iRequestStatus = &aRequestStatus;
   911 
   936     
   912     // TODO currently don't uninstall if running but in future should
       
   913     // stop widget and then uninstall
       
   914     if ( iRegistry.IsWidgetRunning( aUid ) )
       
   915         {
       
   916         FinishUninstallL( KErrInUse );
       
   917         return;
       
   918         }
       
   919 
       
   920     TBuf<KWidgetRegistryVal> bundleName;
   937     TBuf<KWidgetRegistryVal> bundleName;
   921     iRegistry.GetWidgetBundleName( aUid, bundleName );
   938     iRegistry.GetWidgetBundleName( aUid, bundleName );
   922 
   939 
   923     if( bundleName.Length() <= 0 )
   940     if( bundleName.Length() <= 0 )
   924         {
   941         {
   925         FinishUninstallL( KErrCorrupt );
   942         FinishUninstallL( KErrCorrupt );
   926         return;
   943         return;
   927         }
   944         }
   928 
   945             
       
   946     TBool widgetinHomeScreen(EFalse);
       
   947     widgetinHomeScreen = iRegistry.IsWidgetInMiniView( aUid ); 
   929     // prompt user to uninstall
   948     // prompt user to uninstall
   930     if( iUIHandler->DisplayUninstallL( bundleName ) )
   949     if( iUIHandler->DisplayUninstallL( bundleName,widgetinHomeScreen ) )
   931         {
   950         {
       
   951         if(iRegistry.IsWidgetRunning( aUid ))
       
   952         //Runnning widget should be first closed    
       
   953             {
       
   954             RApaLsSession apaLsSession;
       
   955             apaLsSession.Connect();
       
   956             TApaAppInfo info;
       
   957             
       
   958             User::LeaveIfError( apaLsSession.GetAppInfo( info, aUid ) );
       
   959             HBufC* widgetName = info.iFullName.AllocLC();        
       
   960             HandleWidgetCommandL(apaLsSession,*widgetName,aUid,Deactivate);
       
   961             
       
   962             CleanupStack::PopAndDestroy( widgetName );
       
   963             apaLsSession.Close();            
       
   964             }
   932         iUIHandler->DisplayUninstallInProgressL();
   965         iUIHandler->DisplayUninstallInProgressL();
   933         TBuf<KWidgetRegistryVal> widgetPath;
   966         TBuf<KWidgetRegistryVal> widgetPath;
   934         iRegistry.GetWidgetPath( aUid, widgetPath );
   967         iRegistry.GetWidgetPath( aUid, widgetPath );
   935         TBool aVendor = *(iRegistry.GetWidgetPropertyValueL(aUid, ENokiaWidget));
   968         TBool aVendor = *(iRegistry.GetWidgetPropertyValueL(aUid, ENokiaWidget));
   936         
   969         
  1260     iTaskManager->AddTaskL( task );
  1293     iTaskManager->AddTaskL( task );
  1261     iTaskManager->CommitL();
  1294     iTaskManager->CommitL();
  1262     
  1295     
  1263     CleanupStack::Pop(task);
  1296     CleanupStack::Pop(task);
  1264     }
  1297     }
       
  1298 
       
  1299 // ============================================================================
       
  1300 //
       
  1301 // CWidgetUIOperationsWatcher::HandleWidgetCommandL
       
  1302 //
       
  1303 // ============================================================================
       
  1304 void CWidgetUIOperationsWatcher::HandleWidgetCommandL( RApaLsSession& aSession,const TDesC& aWidget,const TUid& aUid,TUint32 aOperation )
       
  1305     {
       
  1306     const TInt size( 2* aWidget.Length() + 3*sizeof( TUint32 ) );
       
  1307     
       
  1308     // Message format is <filenameLength><unicode_filename><someintegervalue>
       
  1309     CApaCommandLine* cmd( CApaCommandLine::NewLC() );
       
  1310     HBufC8* opaque( HBufC8::NewLC( size ) );
       
  1311     
       
  1312     RDesWriteStream stream;
       
  1313     TPtr8 des( opaque->Des() );
       
  1314     
       
  1315     stream.Open( des );
       
  1316     CleanupClosePushL( stream );
       
  1317     
       
  1318     // Generate the command.
       
  1319     stream.WriteUint32L( aUid.iUid );
       
  1320     stream.WriteUint32L( aWidget.Length() );
       
  1321     stream.WriteL( reinterpret_cast< const TUint8* >( aWidget.Ptr() ),
       
  1322                    aWidget.Size() );
       
  1323     
       
  1324     stream.WriteInt32L( aOperation );
       
  1325     
       
  1326     CleanupStack::PopAndDestroy( &stream );
       
  1327     
       
  1328     // Generate command.
       
  1329     cmd->SetCommandL( EApaCommandBackgroundAndWithoutViews );
       
  1330     cmd->SetOpaqueDataL( *opaque );    
       
  1331 
       
  1332     CleanupStack::PopAndDestroy( opaque );
       
  1333     
       
  1334     cmd->SetExecutableNameL( KLauncherApp );
       
  1335     
       
  1336     User::LeaveIfError( aSession.StartApp( *cmd ) );
       
  1337     CleanupStack::PopAndDestroy( cmd );    
       
  1338     }
  1265 //  End of File
  1339 //  End of File