idlehomescreen/widgetmanager/src/wmwidgetloaderao.cpp
branchRCL_3
changeset 12 9674c1a575e9
parent 11 ff572dfe6d86
child 26 1b758917cafc
equal deleted inserted replaced
11:ff572dfe6d86 12:9674c1a575e9
    53 // ---------------------------------------------------------------------------
    53 // ---------------------------------------------------------------------------
    54 //
    54 //
    55 CWmWidgetLoaderAo::CWmWidgetLoaderAo(
    55 CWmWidgetLoaderAo::CWmWidgetLoaderAo(
    56         CWmPlugin& aWmPlugin,
    56         CWmPlugin& aWmPlugin,
    57         CWmListBox& aTargetList )
    57         CWmListBox& aTargetList )
    58     : CAsyncOneShot( EPriorityStandard )
    58     : CAsyncOneShot( EPriorityHigh )
    59     , iWmPlugin( aWmPlugin )
    59     , iWmPlugin( aWmPlugin )
    60     , iWidgetsList( aTargetList )
    60     , iWidgetsList( aTargetList )
    61     {
    61     {
    62     iWidgetRegistry = NULL;
    62     iWidgetRegistry = NULL;
    63     iWidgetOrder = NULL;
    63     iWidgetOrder = NULL;
       
    64     iLoading = EFalse;
    64     }
    65     }
    65 
    66 
    66 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
    67 // CWmWidgetLoaderAo::ConstructL
    68 // CWmWidgetLoaderAo::ConstructL
    68 // ---------------------------------------------------------------------------
    69 // ---------------------------------------------------------------------------
   126 void CWmWidgetLoaderAo::DoLoadWidgetsL()
   127 void CWmWidgetLoaderAo::DoLoadWidgetsL()
   127     {
   128     {
   128     // Check if unistallation is ongoing for for some widget
   129     // Check if unistallation is ongoing for for some widget
   129 	// iUninstallUid is null no uninstallation is ongoing
   130 	// iUninstallUid is null no uninstallation is ongoing
   130     iUninstallUid = iWmPlugin.WmInstaller().UninstallUid();
   131     iUninstallUid = iWmPlugin.WmInstaller().UninstallUid();
       
   132     
       
   133     // connect to widget registry
       
   134     OpenSessionL();
   131     
   135     
   132     // 1. load the widgets array
   136     // 1. load the widgets array
   133     MHsContentController& controller = iWmPlugin.ContentController();    
   137     MHsContentController& controller = iWmPlugin.ContentController();    
   134     CHsContentInfoArray* contentInfoArray = CHsContentInfoArray::NewL();
   138     CHsContentInfoArray* contentInfoArray = CHsContentInfoArray::NewL();
   135     CleanupStack::PushL( contentInfoArray );
   139     CleanupStack::PushL( contentInfoArray );
   136     controller.WidgetListL( *contentInfoArray );
   140     controller.WidgetListL( *contentInfoArray );
   137     
   141     
   138     // 2. load the widget order
   142     // 2. load the widget order
   139     if ( iWidgetOrder ) { Cleanup(); }
   143     if ( iWidgetOrder ) { Cleanup(); }    
   140     iWidgetOrder = CWmPersistentWidgetOrder::NewL( iWmPlugin.FileServer() );
   144     iWidgetOrder = CWmPersistentWidgetOrder::NewL( iWmPlugin.FileServer() );
   141     TRAPD( loadError, iWidgetOrder->LoadL() );
   145     TRAPD( loadError, iWidgetOrder->LoadL() );
   142 
   146     
   143     // 3. prepare the widget data array & sort order array
   147     // 3. prepare the widget data array & sort order array
   144     for( TInt i=0; i<iWidgetsList.WidgetDataCount(); ++i )
   148     for( TInt i=0; i<iWidgetsList.WidgetDataCount(); ++i )
   145         {
   149         {
   146         iWidgetsList.WidgetData(i).SetPersistentWidgetOrder( iWidgetOrder );
   150         iWidgetsList.WidgetData(i).SetPersistentWidgetOrder( iWidgetOrder );
   147         iWidgetsList.WidgetData(i).SetValid( EFalse );
   151         iWidgetsList.WidgetData(i).SetValid( EFalse );
   153     
   157     
   154     // 4. loop through the content array and compare it against the existing
   158     // 4. loop through the content array and compare it against the existing
   155     // widget data.
   159     // widget data.
   156     TInt widgetsAdded = 0;
   160     TInt widgetsAdded = 0;
   157     TInt widgetsChanged = 0;
   161     TInt widgetsChanged = 0;
       
   162     iLoading = ETrue;
   158     while( contentInfoArray->Array().Count() > 0 )
   163     while( contentInfoArray->Array().Count() > 0 )
   159         {
   164         {
   160         CHsContentInfo* contentInfo = contentInfoArray->Array()[0];
   165         CHsContentInfo* contentInfo = contentInfoArray->Array()[0];
   161         if ( !contentInfo ) { break; }
   166         if ( !contentInfo ) { break; }
   162         contentInfoArray->Array().Remove( 0 );
   167         contentInfoArray->Array().Remove( 0 );
   167         CWmWidgetData* existingData = FindWidgetData( *contentInfo );
   172         CWmWidgetData* existingData = FindWidgetData( *contentInfo );
   168         if ( existingData )
   173         if ( existingData )
   169             {
   174             {
   170             // update existing visible widget data
   175             // update existing visible widget data
   171             existingData->SetValid( ETrue );
   176             existingData->SetValid( ETrue );
   172             if ( existingData->ReplaceContentInfoL( contentInfo ) )
   177             if ( existingData->ReplaceContentInfo( contentInfo ) )
   173                 {
   178                 {
   174                 // Update name to order array if name changed
   179                 // Update name to order array if name changed
   175                 for ( TInt i=0; i < iWidgetsList.OrderDataArray().Count(); i++ )
   180                 for ( TInt i=0; i < iWidgetsList.OrderDataArray().Count(); i++ )
   176                     {
   181                     {
   177                     CWmWidgetOrderData* order = iWidgetsList.OrderData(i);
   182                     CWmWidgetOrderData* order = iWidgetsList.OrderData(i);
   178                     if ( order->EqualsTo( 
   183                     if ( order->EqualsTo( 
   179                             existingData->Uid(), existingData->PublisherId() ) )
   184                             existingData->Uid(), existingData->PublisherId() ) )
   180                         {
   185                         {
   181                         order->UpdateNameL( existingData->Name() );
   186                         order->UpdateName( existingData->Name() );
   182                         }
   187                         }
   183                     }
   188                     }
   184                 ++widgetsChanged;
   189                 ++widgetsChanged;
   185                 }
   190                 }
   186             }
   191             }
   187         else
   192         else
   188             {
   193             {
   189             // add a new widget data
   194             // add a new widget data
   190             AddWidgetDataL( contentInfo, widgetsAdded );
   195             TRAP_IGNORE( AddWidgetDataL( contentInfo, widgetsAdded ); );
   191             }
   196             }
   192         }
   197         }
   193 
   198 
   194     // 5: finally, remove all UI widgets that during the loading process were
   199     // 5: finally, remove all UI widgets that during the loading process were
   195     // NOT marked as VALID. those widgets do not exist anymore.
   200     // NOT marked as VALID. those widgets do not exist anymore.
   231         }
   236         }
   232     
   237     
   233     // 8. store list order if necessary
   238     // 8. store list order if necessary
   234     if ( loadError != KErrNone || widgetsAdded > 0 || widgetsRemoved > 0 )
   239     if ( loadError != KErrNone || widgetsAdded > 0 || widgetsRemoved > 0 )
   235         {
   240         {
   236         iWidgetOrder->StoreL( iWidgetsList.OrderDataArray() );
   241         TRAP_IGNORE( iWidgetOrder->StoreL( iWidgetsList.OrderDataArray() ); );
   237         }
   242         }
   238     }
   243     }
   239 
   244 
   240 // ---------------------------------------------------------
   245 // ---------------------------------------------------------
   241 // CWmWidgetLoaderAo::FindWidgetDataL
   246 // CWmWidgetLoaderAo::FindWidgetDataL
   254         }
   259         }
   255     return data;
   260     return data;
   256     }
   261     }
   257 
   262 
   258 // ---------------------------------------------------------
   263 // ---------------------------------------------------------
   259 // CWmWidgetLoaderAo::AddWidgetDataL
   264 // CWmWidgetLoaderAo::OpenSessionL
   260 // ---------------------------------------------------------
   265 // ---------------------------------------------------------
   261 //
   266 //
   262 void CWmWidgetLoaderAo::AddWidgetDataL(
   267 void CWmWidgetLoaderAo::OpenSessionL()
   263         CHsContentInfo* aContentInfo, TInt& aCount )
   268     {
   264     {
       
   265     CleanupStack::PushL( aContentInfo );
       
   266     if ( !iWidgetRegistry )
   269     if ( !iWidgetRegistry )
   267         {
   270         {
   268         iWidgetRegistry = new (ELeave) RWidgetRegistryClientSession();
   271         iWidgetRegistry = new (ELeave) RWidgetRegistryClientSession();
   269         TInt err = iWidgetRegistry->Connect();
   272         TInt err = iWidgetRegistry->Connect();
   270         if ( KErrNone != err )
   273         if ( KErrNone != err )
   272             delete iWidgetRegistry;
   275             delete iWidgetRegistry;
   273             iWidgetRegistry = NULL;
   276             iWidgetRegistry = NULL;
   274             User::Leave( err );
   277             User::Leave( err );
   275             }
   278             }
   276         }
   279         }
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------
       
   283 // CWmWidgetLoaderAo::AddWidgetDataL
       
   284 // ---------------------------------------------------------
       
   285 //
       
   286 void CWmWidgetLoaderAo::AddWidgetDataL(
       
   287         CHsContentInfo* aContentInfo, TInt& aCount )
       
   288     {
       
   289     CleanupStack::PushL( aContentInfo );
   277             
   290             
   278     // Becouse we show only widgets that can be added we need two arrays
   291     // Becouse we show only widgets that can be added we need two arrays
   279     // to maintain order data and visible data. 
   292     // to maintain order data and visible data. 
   280     // All widgets are added to listbox's iOrderDataArray and 
   293     // All widgets are added to listbox's iOrderDataArray and 
   281     // widgets that CanBeAdded are added also to iVisibleWidgetArray.
   294     // widgets that CanBeAdded are added also to iVisibleWidgetArray.
   290     iWidgetsList.AddOrderDataL( order );
   303     iWidgetsList.AddOrderDataL( order );
   291     CleanupStack::Pop( order );
   304     CleanupStack::Pop( order );
   292     
   305     
   293     if ( aContentInfo->CanBeAdded() )
   306     if ( aContentInfo->CanBeAdded() )
   294         {
   307         {
   295 		// widgetdata takes ownership of contentinfo
   308         CWmWidgetData* widgetData = CWmWidgetData::NewL(
   296         CleanupStack::Pop( aContentInfo );
       
   297         
       
   298         CWmWidgetData* widgetData = CWmWidgetData::NewLC(
       
   299                 iWidgetsList.LogoSize(),
   309                 iWidgetsList.LogoSize(),
   300                 iWmPlugin.ResourceLoader(),
   310                 iWmPlugin.ResourceLoader(),
   301                 aContentInfo, iWidgetRegistry );
   311                 aContentInfo, iWidgetRegistry );
       
   312 
       
   313         // widgetdata has taken ownership of contentinfo
       
   314         CleanupStack::Pop( aContentInfo );
       
   315         
       
   316         CleanupStack::PushL( widgetData );
       
   317         
   302         widgetData->SetPersistentWidgetOrder( iWidgetOrder );
   318         widgetData->SetPersistentWidgetOrder( iWidgetOrder );
   303         widgetData->SetValid( ETrue );
   319         widgetData->SetValid( ETrue );
   304         
   320         
   305         // start uninstall animation if this widget
   321         // start uninstall animation if this widget
   306         // is currently been unistalled
   322         // is currently been unistalled
   325 // CWmWidgetLoaderAo::Cleanup
   341 // CWmWidgetLoaderAo::Cleanup
   326 // ---------------------------------------------------------------------------
   342 // ---------------------------------------------------------------------------
   327 //
   343 //
   328 void CWmWidgetLoaderAo::Cleanup()
   344 void CWmWidgetLoaderAo::Cleanup()
   329     {
   345     {
       
   346     iLoading = EFalse;
       
   347     
   330     // disconnect widget registry
   348     // disconnect widget registry
   331     if ( iWidgetRegistry )
   349     if ( iWidgetRegistry )
   332         {
   350         {
   333         iWidgetRegistry->Disconnect();
   351         iWidgetRegistry->Disconnect();
   334         iWidgetRegistry->Close();
   352         iWidgetRegistry->Close();
   362             uid.iUid = (TInt32)id;
   380             uid.iUid = (TInt32)id;
   363             }
   381             }
   364         }
   382         }
   365     return uid;
   383     return uid;
   366     }
   384     }
       
   385 
       
   386 // ----------------------------------------------------
       
   387 // CWmWidgetData::IsLoading
       
   388 // ----------------------------------------------------
       
   389 //
       
   390 TBool CWmWidgetLoaderAo::IsLoading()
       
   391     {
       
   392     return iLoading;
       
   393     }
       
   394 
   367 // end of file
   395 // end of file
   368 
   396