idlehomescreen/widgetmanager/src/wmwidgetloaderao.cpp
changeset 2 08c6ee43b396
parent 1 5315654608de
child 5 c743ef5928ba
equal deleted inserted replaced
1:5315654608de 2:08c6ee43b396
   121 // CWmWidgetLoaderAo::DoLoadWidgetsL
   121 // CWmWidgetLoaderAo::DoLoadWidgetsL
   122 // ---------------------------------------------------------
   122 // ---------------------------------------------------------
   123 //
   123 //
   124 void CWmWidgetLoaderAo::DoLoadWidgetsL()
   124 void CWmWidgetLoaderAo::DoLoadWidgetsL()
   125     {
   125     {
   126     // 1. mark all the existing widgets initially non-valid
   126     // 1. load the widgets array
   127     for( TInt i=0; i<iWidgetsList.WidgetDataCount(); ++i )
       
   128         iWidgetsList.WidgetData(i).SetValid( EFalse );
       
   129 
       
   130     // 2. load the widgets array
       
   131     MHsContentController& controller = iWmPlugin.ContentController();    
   127     MHsContentController& controller = iWmPlugin.ContentController();    
   132     CHsContentInfoArray* contentInfoArray = CHsContentInfoArray::NewL();
   128     CHsContentInfoArray* contentInfoArray = CHsContentInfoArray::NewL();
   133     CleanupStack::PushL( contentInfoArray );
   129     CleanupStack::PushL( contentInfoArray );
   134     controller.WidgetListL( *contentInfoArray );
   130     controller.WidgetListL( *contentInfoArray );
   135     
   131     
   136     // 3. load the widget order
   132     // 2. load the widget order
   137     iWidgetOrder = CWmPersistentWidgetOrder::NewL( iWmPlugin.FileServer() );
   133     iWidgetOrder = CWmPersistentWidgetOrder::NewL( iWmPlugin.FileServer() );
   138     TRAPD( loadError, iWidgetOrder->LoadL() );
   134     TRAPD( loadError, iWidgetOrder->LoadL() );
       
   135 
       
   136     // 3. prepare the widget data list
       
   137     for( TInt i=0; i<iWidgetsList.WidgetDataCount(); ++i )
       
   138         {
       
   139         iWidgetsList.WidgetData(i).SetPersistentWidgetOrder( iWidgetOrder );
       
   140         iWidgetsList.WidgetData(i).SetValid( EFalse );
       
   141         }
   139 
   142 
   140     // 4. loop through the content array and compare it against the existing
   143     // 4. loop through the content array and compare it against the existing
   141     // widget data.
   144     // widget data.
   142     TInt widgetsAdded = 0;
   145     TInt widgetsAdded = 0;
   143     TInt widgetsChanged = 0;
   146     TInt widgetsChanged = 0;
   176             {
   179             {
   177             iWidgetsList.RemoveWidgetData( i );
   180             iWidgetsList.RemoveWidgetData( i );
   178             ++widgetsRemoved;
   181             ++widgetsRemoved;
   179             }
   182             }
   180         }
   183         }
   181     if ( widgetsRemoved > 0 )
   184     
       
   185     // update listbox
       
   186     if ( widgetsAdded > 0 )
       
   187         {
       
   188         iWidgetsList.HandleItemAdditionL();
       
   189         }
       
   190     
       
   191     if ( widgetsRemoved > 0 || widgetsAdded > 0 ||
       
   192         widgetsChanged > 0 )
   182         {
   193         {
   183         iWidgetsList.DrawDeferred();
   194         iWidgetsList.DrawDeferred();
   184         }
   195         }
   185 
   196 
   186     // 6: cleanup
   197     // 6: cleanup
   201     // 8. store list order if necessary
   212     // 8. store list order if necessary
   202     if ( loadError != KErrNone || widgetsAdded > 0 || widgetsRemoved > 0 )
   213     if ( loadError != KErrNone || widgetsAdded > 0 || widgetsRemoved > 0 )
   203         {
   214         {
   204         iWidgetOrder->StoreL( iWidgetsList.WidgetDataArray() );
   215         iWidgetOrder->StoreL( iWidgetsList.WidgetDataArray() );
   205         }
   216         }
   206     
   217 
   207     }
   218     }
   208 
   219 
   209 // ---------------------------------------------------------
   220 // ---------------------------------------------------------
   210 // CWmWidgetLoaderAo::FindWidgetDataL
   221 // CWmWidgetLoaderAo::FindWidgetDataL
   211 // ---------------------------------------------------------
   222 // ---------------------------------------------------------
   238         User::LeaveIfError( iWidgetRegistry->Connect() );
   249         User::LeaveIfError( iWidgetRegistry->Connect() );
   239         }
   250         }
   240     CleanupStack::Pop( aContentInfo );
   251     CleanupStack::Pop( aContentInfo );
   241     
   252     
   242     CWmWidgetData* widgetData = CWmWidgetData::NewLC( 
   253     CWmWidgetData* widgetData = CWmWidgetData::NewLC( 
       
   254             iWidgetsList.LogoSize(),
       
   255             iWmPlugin.ResourceLoader(),
   243             aContentInfo, iWidgetRegistry );
   256             aContentInfo, iWidgetRegistry );
   244     widgetData->SetPersistentWidgetOrder( iWidgetOrder );
   257     widgetData->SetPersistentWidgetOrder( iWidgetOrder );
   245     widgetData->SetValid( ETrue );
   258     widgetData->SetValid( ETrue );
   246     iWidgetsList.AddWidgetDataL( widgetData );
   259     iWidgetsList.AddWidgetDataL( widgetData, EFalse );
   247     CleanupStack::Pop( widgetData );
   260     CleanupStack::Pop( widgetData );
   248     }
   261     }
   249 
   262 
   250 // ---------------------------------------------------------------------------
   263 // ---------------------------------------------------------------------------
   251 // CWmWidgetLoaderAo::Cleanup
   264 // CWmWidgetLoaderAo::Cleanup
   260         iWidgetRegistry->Close();
   273         iWidgetRegistry->Close();
   261         delete iWidgetRegistry;
   274         delete iWidgetRegistry;
   262         iWidgetRegistry = NULL;
   275         iWidgetRegistry = NULL;
   263         }
   276         }
   264     
   277     
   265     // delete widget order
   278     // delete widget order and references to it
       
   279     for( TInt i=0; i<iWidgetsList.WidgetDataCount(); ++i )
       
   280         {
       
   281         iWidgetsList.WidgetData(i).SetPersistentWidgetOrder( NULL );
       
   282         }
   266     delete iWidgetOrder;
   283     delete iWidgetOrder;
   267     iWidgetOrder = NULL;
   284     iWidgetOrder = NULL;
   268     }
   285     }
   269 
   286 
   270 // end of file
   287 // end of file