idlehomescreen/widgetmanager/src/wmwidgetloaderao.cpp
branchRCL_3
changeset 11 ff572dfe6d86
parent 9 f966699dea19
child 12 9674c1a575e9
equal deleted inserted replaced
9:f966699dea19 11:ff572dfe6d86
    22 #include "wmresourceloader.h"
    22 #include "wmresourceloader.h"
    23 #include "wmpersistentwidgetorder.h"
    23 #include "wmpersistentwidgetorder.h"
    24 #include "wmlistbox.h"
    24 #include "wmlistbox.h"
    25 #include "wmwidgetloaderao.h"
    25 #include "wmwidgetloaderao.h"
    26 #include "wminstaller.h"
    26 #include "wminstaller.h"
       
    27 #include "wmwidgetorderdata.h"
    27 
    28 
    28 #include <hscontentcontroller.h> // content control api
    29 #include <hscontentcontroller.h> // content control api
    29 #include <hscontentinfoarray.h> // content control api
    30 #include <hscontentinfoarray.h> // content control api
    30 #include <widgetregistryclient.h> // widget reqistry
    31 #include <widgetregistryclient.h> // widget reqistry
    31 #include <avkon.rsg> // avkon resources
    32 #include <avkon.rsg> // avkon resources
   137     // 2. load the widget order
   138     // 2. load the widget order
   138     if ( iWidgetOrder ) { Cleanup(); }
   139     if ( iWidgetOrder ) { Cleanup(); }
   139     iWidgetOrder = CWmPersistentWidgetOrder::NewL( iWmPlugin.FileServer() );
   140     iWidgetOrder = CWmPersistentWidgetOrder::NewL( iWmPlugin.FileServer() );
   140     TRAPD( loadError, iWidgetOrder->LoadL() );
   141     TRAPD( loadError, iWidgetOrder->LoadL() );
   141 
   142 
   142     // 3. prepare the widget data list
   143     // 3. prepare the widget data array & sort order array
   143     for( TInt i=0; i<iWidgetsList.WidgetDataCount(); ++i )
   144     for( TInt i=0; i<iWidgetsList.WidgetDataCount(); ++i )
   144         {
   145         {
   145         iWidgetsList.WidgetData(i).SetPersistentWidgetOrder( iWidgetOrder );
   146         iWidgetsList.WidgetData(i).SetPersistentWidgetOrder( iWidgetOrder );
   146         iWidgetsList.WidgetData(i).SetValid( EFalse );
   147         iWidgetsList.WidgetData(i).SetValid( EFalse );
   147         }
   148         }
   148 
   149     for( TInt i = 0; i < iWidgetsList.OrderDataArray().Count(); ++i )
       
   150         {
       
   151         iWidgetsList.OrderData(i)->SetPersistentWidgetOrder( iWidgetOrder );
       
   152         }
       
   153     
   149     // 4. loop through the content array and compare it against the existing
   154     // 4. loop through the content array and compare it against the existing
   150     // widget data.
   155     // widget data.
   151     TInt widgetsAdded = 0;
   156     TInt widgetsAdded = 0;
   152     TInt widgetsChanged = 0;
   157     TInt widgetsChanged = 0;
   153     while( contentInfoArray->Array().Count() > 0 )
   158     while( contentInfoArray->Array().Count() > 0 )
   160         // if it does, keep the existing one
   165         // if it does, keep the existing one
   161         // if it does not, add it
   166         // if it does not, add it
   162         CWmWidgetData* existingData = FindWidgetData( *contentInfo );
   167         CWmWidgetData* existingData = FindWidgetData( *contentInfo );
   163         if ( existingData )
   168         if ( existingData )
   164             {
   169             {
   165             // update existing widget data
   170             // update existing visible widget data
   166             existingData->SetValid( ETrue );
   171             existingData->SetValid( ETrue );
   167             if ( existingData->ReplaceContentInfoL( contentInfo ) )
   172             if ( existingData->ReplaceContentInfoL( contentInfo ) )
   168                 {
   173                 {
       
   174                 // Update name to order array if name changed
       
   175                 for ( TInt i=0; i < iWidgetsList.OrderDataArray().Count(); i++ )
       
   176                     {
       
   177                     CWmWidgetOrderData* order = iWidgetsList.OrderData(i);
       
   178                     if ( order->EqualsTo( 
       
   179                             existingData->Uid(), existingData->PublisherId() ) )
       
   180                         {
       
   181                         order->UpdateNameL( existingData->Name() );
       
   182                         }
       
   183                     }
   169                 ++widgetsChanged;
   184                 ++widgetsChanged;
   170                 }
   185                 }
   171             }
   186             }
   172         else
   187         else
   173             {
   188             {
   174             // add a new widget data
   189             // add a new widget data
   175             AddWidgetDataL( contentInfo );
   190             AddWidgetDataL( contentInfo, widgetsAdded );
   176             ++widgetsAdded;
       
   177             }
   191             }
   178         }
   192         }
   179 
   193 
   180     // 5: finally, remove all UI widgets that during the loading process were
   194     // 5: finally, remove all UI widgets that during the loading process were
   181     // NOT marked as VALID. those widgets do not exist anymore.
   195     // NOT marked as VALID. those widgets do not exist anymore.
   217         }
   231         }
   218     
   232     
   219     // 8. store list order if necessary
   233     // 8. store list order if necessary
   220     if ( loadError != KErrNone || widgetsAdded > 0 || widgetsRemoved > 0 )
   234     if ( loadError != KErrNone || widgetsAdded > 0 || widgetsRemoved > 0 )
   221         {
   235         {
   222         iWidgetOrder->StoreL( iWidgetsList.WidgetDataArray() );
   236         iWidgetOrder->StoreL( iWidgetsList.OrderDataArray() );
   223         }
   237         }
   224 
       
   225     }
   238     }
   226 
   239 
   227 // ---------------------------------------------------------
   240 // ---------------------------------------------------------
   228 // CWmWidgetLoaderAo::FindWidgetDataL
   241 // CWmWidgetLoaderAo::FindWidgetDataL
   229 // ---------------------------------------------------------
   242 // ---------------------------------------------------------
   245 // ---------------------------------------------------------
   258 // ---------------------------------------------------------
   246 // CWmWidgetLoaderAo::AddWidgetDataL
   259 // CWmWidgetLoaderAo::AddWidgetDataL
   247 // ---------------------------------------------------------
   260 // ---------------------------------------------------------
   248 //
   261 //
   249 void CWmWidgetLoaderAo::AddWidgetDataL(
   262 void CWmWidgetLoaderAo::AddWidgetDataL(
   250         CHsContentInfo* aContentInfo )
   263         CHsContentInfo* aContentInfo, TInt& aCount )
   251     {
   264     {
   252     CleanupStack::PushL( aContentInfo );
   265     CleanupStack::PushL( aContentInfo );
   253     if ( !iWidgetRegistry )
   266     if ( !iWidgetRegistry )
   254         {
   267         {
   255         iWidgetRegistry = new (ELeave) RWidgetRegistryClientSession();
   268         iWidgetRegistry = new (ELeave) RWidgetRegistryClientSession();
   256         User::LeaveIfError( iWidgetRegistry->Connect() );
   269         TInt err = iWidgetRegistry->Connect();
   257         }
   270         if ( KErrNone != err )
   258     CleanupStack::Pop( aContentInfo );
   271             {
   259     
   272             delete iWidgetRegistry;
   260     CWmWidgetData* widgetData = CWmWidgetData::NewLC(
   273             iWidgetRegistry = NULL;
   261             iWidgetsList.LogoSize(),
   274             User::Leave( err );
   262             iWmPlugin.ResourceLoader(),
   275             }
   263             aContentInfo, iWidgetRegistry );
   276         }
   264     widgetData->SetPersistentWidgetOrder( iWidgetOrder );
   277             
   265     widgetData->SetValid( ETrue );
   278     // Becouse we show only widgets that can be added we need two arrays
   266        
   279     // to maintain order data and visible data. 
   267     if ( iUninstallUid != KNullUid &&
   280     // All widgets are added to listbox's iOrderDataArray and 
   268         iUninstallUid == widgetData->PublisherUid() )
   281     // widgets that CanBeAdded are added also to iVisibleWidgetArray.
   269         {
   282     CWmWidgetOrderData* order = CWmWidgetOrderData::NewLC(
   270         widgetData->VisualizeUninstallL();
   283             aContentInfo->PublisherId(), 
   271         }
   284             UidFromString( aContentInfo->Uid() ), 
   272     
   285             aContentInfo->Name(),
   273     iWidgetsList.AddWidgetDataL( widgetData, EFalse );
   286             iWidgetOrder
   274     CleanupStack::Pop( widgetData );
   287             );
       
   288     
       
   289     // add to order data
       
   290     iWidgetsList.AddOrderDataL( order );
       
   291     CleanupStack::Pop( order );
       
   292     
       
   293     if ( aContentInfo->CanBeAdded() )
       
   294         {
       
   295 		// widgetdata takes ownership of contentinfo
       
   296         CleanupStack::Pop( aContentInfo );
       
   297         
       
   298         CWmWidgetData* widgetData = CWmWidgetData::NewLC(
       
   299                 iWidgetsList.LogoSize(),
       
   300                 iWmPlugin.ResourceLoader(),
       
   301                 aContentInfo, iWidgetRegistry );
       
   302         widgetData->SetPersistentWidgetOrder( iWidgetOrder );
       
   303         widgetData->SetValid( ETrue );
       
   304         
       
   305         // start uninstall animation if this widget
       
   306         // is currently been unistalled
       
   307         if ( iUninstallUid != KNullUid &&
       
   308             iUninstallUid == widgetData->PublisherUid() )
       
   309             {
       
   310             widgetData->VisualizeUninstallL();
       
   311             }
       
   312         // add to visible data
       
   313         iWidgetsList.AddWidgetDataL( widgetData, EFalse );
       
   314         CleanupStack::Pop( widgetData );
       
   315 		aCount++;
       
   316         }
       
   317     else
       
   318         {
       
   319         //delete aContentInfo when it's not added to iVisibleWidgetArray
       
   320         CleanupStack::PopAndDestroy( aContentInfo );
       
   321         }
   275     }
   322     }
   276 
   323 
   277 // ---------------------------------------------------------------------------
   324 // ---------------------------------------------------------------------------
   278 // CWmWidgetLoaderAo::Cleanup
   325 // CWmWidgetLoaderAo::Cleanup
   279 // ---------------------------------------------------------------------------
   326 // ---------------------------------------------------------------------------
   296         }
   343         }
   297     delete iWidgetOrder;
   344     delete iWidgetOrder;
   298     iWidgetOrder = NULL;
   345     iWidgetOrder = NULL;
   299     }
   346     }
   300 
   347 
       
   348 // ----------------------------------------------------
       
   349 // CWmWidgetData::UidFromString
       
   350 // ----------------------------------------------------
       
   351 //
       
   352 TUid CWmWidgetLoaderAo::UidFromString( const TDesC8& aUidString ) const
       
   353     {
       
   354     TUid uid( KNullUid );
       
   355     const TInt KHexPrefixLength = 2;
       
   356     if ( aUidString.Length() > KHexPrefixLength )
       
   357         {
       
   358         TUint id = 0;
       
   359         TLex8 lex( aUidString.Mid( KHexPrefixLength ) );
       
   360         if ( lex.Val( id, EHex ) == KErrNone )
       
   361             {
       
   362             uid.iUid = (TInt32)id;
       
   363             }
       
   364         }
       
   365     return uid;
       
   366     }
   301 // end of file
   367 // end of file
   302 
   368