idlehomescreen/widgetmanager/src/wmwidgetdata.cpp
branchRCL_3
changeset 16 9674c1a575e9
parent 15 ff572dfe6d86
child 30 b8fae6b8a148
--- a/idlehomescreen/widgetmanager/src/wmwidgetdata.cpp	Fri Mar 12 15:41:49 2010 +0200
+++ b/idlehomescreen/widgetmanager/src/wmwidgetdata.cpp	Mon Mar 15 12:39:47 2010 +0200
@@ -85,11 +85,13 @@
     iWidgetType = CWmWidgetData::EUnknown;
     iPublisherUid = KNullUid;
     iLogoSize = aLogoSize;
-    iPeriodic = NULL;
+    iAnimationTimer = NULL;
+    iTimeoutTimer = NULL;
     iAnimationIndex = 0;
     iAsyncUninstalling = EFalse;
     iFireLogoChanged = EFalse;
     iMdcaPoint = NULL;
+    iWidgetName = NULL;
     }
 
 // ---------------------------------------------------------
@@ -100,13 +102,14 @@
         CHsContentInfo* aHsContentInfo,
         RWidgetRegistryClientSession* aRegistryClientSession )
     {
-    InitL( aHsContentInfo, aRegistryClientSession );
-
     // start decoding the icon
     iImageConverter = CWmImageConverter::NewL( this );
     iWait = new (ELeave) CActiveSchedulerWait();
-    iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
+    iAnimationTimer = CPeriodic::NewL( CActive::EPriorityStandard );
+    iTimeoutTimer = CPeriodic::NewL( CActive::EPriorityStandard );
 
+    InitL( aHsContentInfo, aRegistryClientSession );
+    
     // start logo handling
     iImageConverter->SetLogoSize( iLogoSize );
     HandleIconString( HsContentInfo().IconPath() );
@@ -130,16 +133,18 @@
         iWidgetType = CWmWidgetData::ENative;
         }
 
-    // take ownership of the content info
-    iHsContentInfo = aHsContentInfo;
+    // get publisher uid from widget registry
+    FetchPublisherUidL( aHsContentInfo->PublisherId(), 
+                        aRegistryClientSession );
     
     // create iMdcaPoint for listbox    
     _LIT( KFormatStr, "0\t%S");
     iMdcaPoint = HBufC::NewL( 
-            iHsContentInfo->Name().Length() + KFormatStr().Length() );
-    iMdcaPoint->Des().Format( KFormatStr(), &iHsContentInfo->Name() );
-    // get publisher uid from widget registry
-    FetchPublisherUidL( aRegistryClientSession );
+            aHsContentInfo->Name().Length() + KFormatStr().Length() );
+    iMdcaPoint->Des().Format( KFormatStr(), &aHsContentInfo->Name() );
+
+    // take ownership of the content info
+    iHsContentInfo = aHsContentInfo;
     }
 
 // ---------------------------------------------------------
@@ -148,6 +153,14 @@
 //
 CWmWidgetData::~CWmWidgetData()
     {
+    if ( iTimeoutTimer && 
+        iTimeoutTimer->IsActive() )
+        {
+        iTimeoutTimer->Cancel();
+        }
+    delete iTimeoutTimer;
+
+    delete iWidgetName;
     if ( iWait && iWait->IsStarted() )
         {
         iWait->AsyncStop();
@@ -155,7 +168,7 @@
     delete iWait;
     SetObserver( NULL );
     DestroyAnimData();
-    delete iPeriodic;
+    delete iAnimationTimer;
     delete iLogoImage;
     delete iLogoImageMask;
     delete iImageConverter;
@@ -254,7 +267,7 @@
         if ( iFireLogoChanged ) 
             {
             iFireLogoChanged = EFalse;
-            FireDataChanged(); 
+            FireDataChanged();
             }
         }
     }
@@ -299,8 +312,12 @@
     
     // handle result
     if ( KErrNone == err && iWait &&
-        IsPrepairingLogo() )
+        IsPrepairingLogo() && iTimeoutTimer )
         {
+        iTimeoutTimer->Cancel();
+        const TInt tickInterval = 200000;        
+        iTimeoutTimer->Start(
+                tickInterval,tickInterval,TCallBack(TimeoutTick, this));
         iWait->Start();
         }
     else if ( KErrNone != err && iFireLogoChanged )
@@ -356,14 +373,15 @@
 // ----------------------------------------------------
 //
 void CWmWidgetData::FetchPublisherUidL( 
+            const TDesC& aPublisherId,
             RWidgetRegistryClientSession* aRegistryClientSession )
     {
     if ( iPublisherUid == KNullUid && 
-        PublisherId() != KNullDesC &&
+        aPublisherId != KNullDesC &&
         iWidgetType != CWmWidgetData::ENative &&
         aRegistryClientSession )
         {
-        TInt widgetUid = aRegistryClientSession->GetWidgetUidL( PublisherId() );
+        TInt widgetUid = aRegistryClientSession->GetWidgetUidL( aPublisherId );
         if ( widgetUid != 0 )
             {
             // WRT widget
@@ -414,10 +432,10 @@
     }
 
 // ---------------------------------------------------------
-// CWmWidgetData::ReplaceContentInfoL
+// CWmWidgetData::ReplaceContentInfo
 // ---------------------------------------------------------
 //
-TBool CWmWidgetData::ReplaceContentInfoL(
+TBool CWmWidgetData::ReplaceContentInfo(
         CHsContentInfo* aHsContentInfo )
     {
     TBool sameAppearance = (
@@ -430,10 +448,15 @@
     // delete the old content info
     delete iHsContentInfo;
     iHsContentInfo = NULL;
-
-    // re-init the object
-    InitL( aHsContentInfo, NULL );
-
+    
+    // re-init the object, take care about leave.
+    TRAPD( err, InitL( aHsContentInfo, NULL ); );
+    if ( KErrNone != err )
+        {
+        delete aHsContentInfo;
+        aHsContentInfo = NULL;
+        }
+   
     if ( !sameAppearance )
         {
         // fire change event -> widget redrawn
@@ -473,12 +496,19 @@
     DestroyAnimData();
     PrepairAnimL();
     
-    iHsContentInfo->SetNameL( iWmResourceLoader.Uninstalling() );
+    // set copy of widget name for uninstallation error case.
+    if ( iHsContentInfo->Name().Compare( iWmResourceLoader.Uninstalling() ) !=
+        KErrNone )
+        {
+        iWidgetName = iHsContentInfo->Name().AllocL();
+        iHsContentInfo->SetNameL( iWmResourceLoader.Uninstalling() );
+        }
+
     iAsyncUninstalling = ETrue;
     iAnimationIndex = 0;
     const TInt tickInterval = 400000;
-    iPeriodic->Start(
-            tickInterval,tickInterval,TCallBack(Tick, this));
+    iAnimationTimer->Start(
+            tickInterval,tickInterval,TCallBack(AnimationTick, this));
     }
 
 // ---------------------------------------------------------
@@ -521,9 +551,9 @@
 //
 void CWmWidgetData::DestroyAnimData()
     {
-    if ( iPeriodic && iPeriodic->IsActive() )
+    if ( iAnimationTimer && iAnimationTimer->IsActive() )
         {
-        iPeriodic->Cancel();
+        iAnimationTimer->Cancel();
         }
         
     for( TInt i=0; i < iUninstallAnimIcons.Count(); i++ )
@@ -535,10 +565,10 @@
     }
 
 // ---------------------------------------------------------
-// CWmWidgetData::Tick
+// CWmWidgetData::AnimationTick
 // ---------------------------------------------------------
 //
-TInt CWmWidgetData::Tick( TAny* aPtr )
+TInt CWmWidgetData::AnimationTick( TAny* aPtr )
     {
     CWmWidgetData* self = static_cast< CWmWidgetData* >( aPtr );
     self->iAnimationIndex += 2;
@@ -551,6 +581,21 @@
     }
 
 // ---------------------------------------------------------
+// CWmWidgetData::TimeoutTick
+// ---------------------------------------------------------
+//
+TInt CWmWidgetData::TimeoutTick( TAny* aPtr )
+    {
+    CWmWidgetData* self = static_cast< CWmWidgetData* >( aPtr );
+    self->iTimeoutTimer->Cancel();
+    if ( self->iWait && self->iWait->IsStarted() )
+        {
+        self->iWait->AsyncStop();
+        }
+    return 1;
+    }
+
+// ---------------------------------------------------------
 // CWmWidgetData::AnimationBitmap
 // ---------------------------------------------------------
 //
@@ -619,5 +664,24 @@
         return KNullDesC;
     }
 
+// ---------------------------------------------------------
+// CWmWidgetData::StopUninstallAnimation
+// ---------------------------------------------------------
+//
+void CWmWidgetData::StopUninstallAnimationL()
+    {
+    DestroyAnimData();
+    // restore widget name
+    if ( iWidgetName )
+        {
+        iHsContentInfo->SetNameL( iWidgetName->Des() );
+        delete iWidgetName;
+        iWidgetName = NULL;
+        }
+    
+    FireDataChanged(); //redraw
+    iAsyncUninstalling = EFalse;
+    }
+
 // End of file