widgets/widgetinstaller/src/WidgetUIOperationsWatcher.cpp
branchRCL_3
changeset 49 919f36ff910f
parent 48 79859ed3eea9
equal deleted inserted replaced
48:79859ed3eea9 49:919f36ff910f
    27 #include <SWInstTaskManager.h>
    27 #include <SWInstTaskManager.h>
    28 #include <SWInstTask.h>
    28 #include <SWInstTask.h>
    29 #include <SWInstLogTaskParam.h>
    29 #include <SWInstLogTaskParam.h>
    30 #include <apacmdln.h>
    30 #include <apacmdln.h>
    31 #include <s32mem.h>
    31 #include <s32mem.h>
       
    32 #include <e32property.h>
    32 
    33 
    33 #include <widgetappdefs.rh>
    34 #include <widgetappdefs.rh>
    34 #include "WidgetUIOperationsWatcher.h"
    35 #include "WidgetUIOperationsWatcher.h"
    35 #include "WidgetUIConfigHandler.h" // info.plist parser
    36 #include "WidgetUIConfigHandler.h" // info.plist parser
    36 #include "WidgetRegistrationManager.h" // interface to "shell"
    37 #include "WidgetRegistrationManager.h" // interface to "shell"
    58 // not drive).  The widget bundle must contain relative paths.  The
    59 // not drive).  The widget bundle must contain relative paths.  The
    59 // drive letter is separated because support for multiple drives and
    60 // drive letter is separated because support for multiple drives and
    60 // removable memory cards means that drive letters may change.
    61 // removable memory cards means that drive letters may change.
    61 
    62 
    62 
    63 
       
    64 static void NotifyCommandHandled()
       
    65     {
       
    66     const TUid KMyPropertyCat = { 0x10282E5A };
       
    67     enum TMyPropertyKeys { EMyPropertyState = 109 };
       
    68     TInt state( 3 );
       
    69     RProperty::Set( KMyPropertyCat, EMyPropertyState , state );
       
    70     }
       
    71 
    63 using namespace SwiUI;
    72 using namespace SwiUI;
    64 
    73 
    65 // =========================== MEMBER FUNCTIONS ===============================
    74 // =========================== MEMBER FUNCTIONS ===============================
    66 
    75 
    67 
    76 
   122     for ( ; i < EWidgetPropertyIdCount; ++i )
   131     for ( ; i < EWidgetPropertyIdCount; ++i )
   123         {
   132         {
   124         CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
   133         CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
   125         User::LeaveIfError( iPropertyValues.Insert( value, i ) );
   134         User::LeaveIfError( iPropertyValues.Insert( value, i ) );
   126         }
   135         }
   127     *(iPropertyValues[EWidgetPropertyListVersion]) = WIDGETPROPERTYLISTVERSION;
   136     *(iPropertyValues[EWidgetPropertyListVersion]) = KWidgetPropertyListVersion71;
   128 
   137 
   129     iTaskManager = CTaskManager::NewL();
   138     iTaskManager = CTaskManager::NewL();
   130     }
   139     }
   131 
   140 
   132 // ============================================================================
   141 // ============================================================================
   174 // ============================================================================
   183 // ============================================================================
   175 //
   184 //
   176 void CWidgetUIOperationsWatcher::SilentInstallL(
   185 void CWidgetUIOperationsWatcher::SilentInstallL(
   177     RFile& aFile,
   186     RFile& aFile,
   178     const TDesC8& aMIME,
   187     const TDesC8& aMIME,
       
   188     TChar& aDrive,
   179     TRequestStatus& aRequestStatus )
   189     TRequestStatus& aRequestStatus )
   180     {
   190     {
   181     iSilent = ETrue;
   191     iSilent = ETrue;
       
   192     iRfs.CharToDrive(aDrive,iDrive);
   182     InstallL( aFile, aMIME, aRequestStatus );
   193     InstallL( aFile, aMIME, aRequestStatus );
   183     }
   194     }
   184 
   195 
   185 // ============================================================================
   196 // ============================================================================
   186 // CWidgetUIOperationsWatcher::InstallSubfunctionL()
   197 // CWidgetUIOperationsWatcher::InstallSubfunctionL()
   204     TBool replaceExisting = PreprocessWidgetBundleL();
   215     TBool replaceExisting = PreprocessWidgetBundleL();
   205 
   216 
   206     if ( PromptUserForInstallL( replaceExisting )
   217     if ( PromptUserForInstallL( replaceExisting )
   207          && PromptUserForUntrustedWidgetL( ) )
   218          && PromptUserForUntrustedWidgetL( ) )
   208         {
   219         {
       
   220         if ( replaceExisting )
       
   221             {
       
   222             //Runnning widget should be first closed
       
   223             RApaLsSession apaLsSession;
       
   224             apaLsSession.Connect();
       
   225             TApaAppInfo info;
       
   226             TUid aUid = TUid::Uid( *(iPropertyValues[EUid]) );
       
   227                         
       
   228             User::LeaveIfError( apaLsSession.GetAppInfo( info, aUid ) );
       
   229             iWidgetName = info.iFullName;
       
   230             HBufC *widgetName = iWidgetName.AllocLC();
       
   231             if(iWidgetInHS)
       
   232                 NotifyCommandHandled();
       
   233             
       
   234             HandleWidgetCommandL(apaLsSession, *widgetName, aUid, Deactivate);
       
   235                         
       
   236             CleanupStack::PopAndDestroy( widgetName );
       
   237             apaLsSession.Close();
       
   238             }
       
   239         
       
   240         
   209         // reinitialize
   241         // reinitialize
   210         delete iMembers;
   242         delete iMembers;
   211         iMembers = NULL;
   243         iMembers = NULL;
   212         iMembers = iZipFile->GetMembersL();
   244         iMembers = iZipFile->GetMembersL();
   213 
   245 
   271         userCancel = ETrue;
   303         userCancel = ETrue;
   272 
   304 
   273         if ( !iSilent ) { iUIHandler->DisplayCancelL(); }
   305         if ( !iSilent ) { iUIHandler->DisplayCancelL(); }
   274 
   306 
   275         TRequestStatus* status = &aRequestStatus;
   307         TRequestStatus* status = &aRequestStatus;
   276         User::RequestComplete( status, KErrNone );
   308         User::RequestComplete( status, KErrCancel );
   277         }
   309         }
   278     }
   310     }
   279 
   311 
   280 // ============================================================================
   312 // ============================================================================
   281 // CWidgetUIOperationsWatcher::InstallL()
   313 // CWidgetUIOperationsWatcher::InstallL()
   445         *(iPropertyValues[EUid]) = iRegistry.GetWidgetUidL(
   477         *(iPropertyValues[EUid]) = iRegistry.GetWidgetUidL(
   446             *(iPropertyValues[EBundleIdentifier]));
   478             *(iPropertyValues[EBundleIdentifier]));
   447         found = ETrue;
   479         found = ETrue;
   448         TUid aUid = TUid::Uid( *(iPropertyValues[EUid]) );
   480         TUid aUid = TUid::Uid( *(iPropertyValues[EUid]) );
   449         iWidgetInHS = iRegistry.IsWidgetInMiniView( aUid );
   481         iWidgetInHS = iRegistry.IsWidgetInMiniView( aUid );
   450         if ( iRegistry.IsWidgetRunning( aUid ) )
       
   451             {
       
   452             //Runnning widget should be first closed
       
   453             RApaLsSession apaLsSession;
       
   454             apaLsSession.Connect();
       
   455             TApaAppInfo info;
       
   456 
       
   457             User::LeaveIfError( apaLsSession.GetAppInfo( info, aUid ) );
       
   458             iWidgetName = info.iFullName;
       
   459             HBufC *widgetName = iWidgetName.AllocLC();
       
   460             HandleWidgetCommandL(apaLsSession, *widgetName, aUid, Deactivate);
       
   461 
       
   462             CleanupStack::PopAndDestroy( widgetName );
       
   463             apaLsSession.Close();
       
   464             }
       
   465         // get original install dir from registry in case user
   482         // get original install dir from registry in case user
   466         // decides to "overrite" to another memory location
   483         // decides to "overrite" to another memory location
   467         iOriginalDir = *( iRegistry.GetWidgetPropertyValueL(
   484         CWidgetPropertyValue *propValue = iRegistry.GetWidgetPropertyValueL(
   468                               TUid::Uid( *(iPropertyValues[EUid]) ),
   485                               TUid::Uid( *(iPropertyValues[EUid]) ),
   469                               EBasePath ) );
   486                               EBasePath );
       
   487                               
       
   488         iOriginalDir.Zero();
       
   489         if(propValue)
       
   490             iOriginalDir = *propValue;
       
   491             
       
   492         delete propValue;
   470         }
   493         }
   471     // uid for a new widget will be gotten once install location (c: or
   494     // uid for a new widget will be gotten once install location (c: or
   472     // e:) is selected
   495     // e:) is selected
   473 
   496 
   474     // see if main.html is in zip bundle
   497     // see if main.html is in zip bundle
   751     if ( !iCancelled )
   774     if ( !iCancelled )
   752         {
   775         {
   753         if ( iOverwriting )
   776         if ( iOverwriting )
   754             {
   777             {
   755             TUid uid = TUid::Uid( *(iPropertyValues[EUid]) );
   778             TUid uid = TUid::Uid( *(iPropertyValues[EUid]) );
       
   779             iAppManager->DeregisterWidgetL( uid );
   756             iRegistry.DeRegisterWidgetL( uid );
   780             iRegistry.DeRegisterWidgetL( uid );
   757             iAppManager->DeregisterWidgetL( uid );
       
   758             }
   781             }
   759 
   782 
   760         // TODO if registration steps fail does it leave inconsistent state???
   783         // TODO if registration steps fail does it leave inconsistent state???
   761 
   784 
   762         iRegistry.RegisterWidgetL( iPropertyValues );
       
   763 
   785 
   764         iAppManager->RegisterWidgetL( *(iPropertyValues[EMainHTML]),
   786         iAppManager->RegisterWidgetL( *(iPropertyValues[EMainHTML]),
   765                                       *(iPropertyValues[EBundleDisplayName]),
   787                                       *(iPropertyValues[EBundleDisplayName]),
   766                                       *(iPropertyValues[EIconPath]),
   788                                       *(iPropertyValues[EIconPath]),
   767                                       *(iPropertyValues[EDriveName]),
   789                                       *(iPropertyValues[EDriveName]),
   768                                       TUid::Uid( *(iPropertyValues[EUid]) ) );
   790                                       TUid::Uid( *(iPropertyValues[EUid]) ) );
   769 
   791 
       
   792         iRegistry.RegisterWidgetL( iPropertyValues );
       
   793 
       
   794 
       
   795 
   770         if ( iOverwriting )
   796         if ( iOverwriting )
   771             {
   797             {
   772             // delete backup
   798             // delete backup
   773             (void)iFileMgr->RmDir( iBackupDir );
   799             (void)iFileMgr->RmDir( iBackupDir );            
   774             if ( iWidgetInHS )
       
   775                 {
       
   776                 RApaLsSession apaLsSession;
       
   777                 apaLsSession.Connect();
       
   778 
       
   779                 HBufC* widgetName = iWidgetName.AllocLC();
       
   780                 HandleWidgetCommandL(apaLsSession, *widgetName, TUid::Uid( *(iPropertyValues[EUid]) ), WidgetRestart);
       
   781                 CleanupStack::PopAndDestroy( widgetName );
       
   782 
       
   783                 apaLsSession.Close();
       
   784                 }
       
   785             }
   800             }
   786         if ( !iSilent )
   801         if ( !iSilent )
   787             {
   802             {
   788             iUIHandler->CloseFinalizeDialogL();
   803             iUIHandler->CloseFinalizeDialogL();
   789             iUIHandler->DisplayCompleteL();
   804             iUIHandler->DisplayCompleteL();
   790             }
   805             }
   791 
   806         
   792         HandleLogsL(*(iPropertyValues[EBundleDisplayName]), TUid::Uid( *(iPropertyValues[EUid]) ), *(iPropertyValues[ENokiaWidget]), SwiUI::ELogTaskActionInstall);
   807         HandleLogsL(*(iPropertyValues[EBundleDisplayName]), TUid::Uid( *(iPropertyValues[EUid]) ), *(iPropertyValues[ENokiaWidget]), *(iPropertyValues[EBundleVersion]), SwiUI::ELogTaskActionInstall);
   793         }
   808         }
   794     else // cancelled
   809     else // cancelled
   795         {
   810         {
   796         // delete what was being installed, and restore previous
   811         // delete what was being installed, and restore previous
   797         (void)iFileMgr->RmDir( *(iPropertyValues[EBasePath]) );
   812         (void)iFileMgr->RmDir( *(iPropertyValues[EBasePath]) );
   988             apaLsSession.Close();
  1003             apaLsSession.Close();
   989             }
  1004             }
   990         if ( !iSilent ) { iUIHandler->DisplayUninstallInProgressL(); }
  1005         if ( !iSilent ) { iUIHandler->DisplayUninstallInProgressL(); }
   991         TBuf<KWidgetRegistryVal> widgetPath;
  1006         TBuf<KWidgetRegistryVal> widgetPath;
   992         iRegistry.GetWidgetPath( aUid, widgetPath );
  1007         iRegistry.GetWidgetPath( aUid, widgetPath );
   993         TBool aVendor = *(iRegistry.GetWidgetPropertyValueL(aUid, ENokiaWidget));
  1008         
   994 
  1009         CWidgetPropertyValue* propValue = iRegistry.GetWidgetPropertyValueL(aUid, ENokiaWidget);
       
  1010         TBool aVendor = propValue && *(propValue);
       
  1011         delete propValue;
       
  1012         propValue = NULL; 
       
  1013         propValue = iRegistry.GetWidgetPropertyValueL(aUid,EBundleVersion);
       
  1014         TBuf<KWidgetRegistryVal> version;
       
  1015         if(propValue)
       
  1016             version = (const TDesC& )*propValue;
       
  1017         delete propValue;
   995 
  1018 
   996         // TODO if any of next steps leave does state become inconsistent?
  1019         // TODO if any of next steps leave does state become inconsistent?
   997 
  1020 
   998         // remove the dir for the widget
  1021         // remove the dir for the widget
   999         // TODO why this validation?
  1022         // TODO why this validation?
  1011             ptr.Insert(pos+1,buf1);
  1034             ptr.Insert(pos+1,buf1);
  1012             iRfs.Delete(ptr);
  1035             iRfs.Delete(ptr);
  1013             CleanupStack::PopAndDestroy(fileName);
  1036             CleanupStack::PopAndDestroy(fileName);
  1014             }
  1037             }
  1015 
  1038 
       
  1039         iAppManager->DeregisterWidgetL( aUid );
  1016         iRegistry.DeRegisterWidgetL( aUid );
  1040         iRegistry.DeRegisterWidgetL( aUid );
  1017         iAppManager->DeregisterWidgetL( aUid );
       
  1018         TInt err = KErrNone;
  1041         TInt err = KErrNone;
  1019         TRAP(err, FinishUninstallL( KErrNone ));
  1042         TRAP(err, FinishUninstallL( KErrNone ));
  1020         if(err == KErrNone)
  1043         if(err == KErrNone)
  1021            {
  1044            {
  1022            HandleLogsL(bundleName, aUid, aVendor, SwiUI::ELogTaskActionUninstall);
  1045            HandleLogsL(bundleName, aUid, aVendor, version, SwiUI::ELogTaskActionUninstall);
  1023            }
  1046            }
  1024         }
  1047         }
  1025     else
  1048     else
  1026         {
  1049         {
  1027         if ( !iSilent ) { iUIHandler->DisplayCancelL(); }
  1050         if ( !iSilent ) { iUIHandler->DisplayCancelL(); }
  1208             userAnswer = SelectMemoryL();
  1231             userAnswer = SelectMemoryL();
  1209             }
  1232             }
  1210         }
  1233         }
  1211     else
  1234     else
  1212             {
  1235             {
  1213             TDriveUnit selectedDrive(_L("C"));        // in real should be read from install options which are ignore too at the moment.
  1236             TDriveUnit selectedDrive(iDrive);            
  1214             UpdateWidgetBasePathL( selectedDrive );
  1237             UpdateWidgetBasePathL( selectedDrive );
  1215             *(iPropertyValues[EDriveName]) = selectedDrive.Name();
  1238             *(iPropertyValues[EDriveName]) = selectedDrive.Name();
  1216             }
  1239             }
  1217 
  1240 
  1218     return userAnswer;
  1241     return userAnswer;
  1306 // ============================================================================
  1329 // ============================================================================
  1307 //
  1330 //
  1308 // CWidgetUIOperationsWatcher::HandleLogsL
  1331 // CWidgetUIOperationsWatcher::HandleLogsL
  1309 //
  1332 //
  1310 // ============================================================================
  1333 // ============================================================================
  1311 void CWidgetUIOperationsWatcher::HandleLogsL(const TDesC& aWidgetName, const TUid &aUid, TBool aVender, SwiUI::TLogTaskAction aAction)
  1334 void CWidgetUIOperationsWatcher::HandleLogsL(const TDesC& aWidgetName, const TUid &aUid, TBool aVender, const TDesC& aVersion, SwiUI::TLogTaskAction aAction)
  1312     {
  1335     {
  1313     CTask* task = CTask::NewL( KLogTaskImplUid, EFalse );
  1336     CTask* task = CTask::NewL( KLogTaskImplUid, EFalse );
  1314     CleanupStack::PushL(task);
  1337     CleanupStack::PushL(task);
  1315 
  1338 
  1316     TLogTaskParam params;
  1339     TLogTaskParam params;
  1320     params.iVendor.Copy((aVender ? _L("Nokia") : _L("Non-Nokia")));
  1343     params.iVendor.Copy((aVender ? _L("Nokia") : _L("Non-Nokia")));
  1321 
  1344 
  1322     TTime time;
  1345     TTime time;
  1323     time.UniversalTime();
  1346     time.UniversalTime();
  1324     params.iTime = time;
  1347     params.iTime = time;
  1325 
  1348     
       
  1349     TLex lex(aVersion);
       
  1350     TInt i[] = {0,0,0}, j = 0;
       
  1351     while((lex.Get()) != 0 )
       
  1352         {
       
  1353         TInt num = 0; 
       
  1354         while ( lex.Peek() && (lex.Peek()) != '.')
       
  1355             lex.Inc();
       
  1356         TLex toNum(lex.MarkedToken());
       
  1357         toNum.Val(num);
       
  1358         i[j++] = num;
       
  1359         lex.Inc();
       
  1360         lex.Mark();
       
  1361         }
       
  1362     params.iVersion.iMajor = i[0];
       
  1363     params.iVersion.iMinor = i[1];
       
  1364     params.iVersion.iBuild = i[2];
       
  1365     
  1326     TLogTaskParamPckg pckg( params );
  1366     TLogTaskParamPckg pckg( params );
  1327     task->SetParameterL( pckg, 0 );
  1367     task->SetParameterL( pckg, 0 );
  1328     iTaskManager->AddTaskL( task );
  1368     iTaskManager->AddTaskL( task );
  1329     iTaskManager->CommitL();
  1369     iTaskManager->CommitL();
  1330 
  1370