taskswitcher/contextengine/tsfswserver/engine/src/tsfswdatalist.cpp
branchRCL_3
changeset 30 b8fae6b8a148
child 38 79311d856354
equal deleted inserted replaced
16:9674c1a575e9 30:b8fae6b8a148
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  File containing application list classes
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 //INCLUDES:
       
    20 #include "tsfswdatalist.h"
       
    21 #include "tsfswengine.h"
       
    22 #include "tsfsalwaysshownapplist.h"
       
    23 #include "tsfshiddenapplist.h"
       
    24 #include "tsfswidgetlist.h"
       
    25 #include "tsfswiconcache.h"
       
    26 #include "enginelogging.h"
       
    27 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL
       
    28 #include <featmgr.h>
       
    29 #include <apgwgnam.h>
       
    30 
       
    31 
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // --------------------------------------------------------------------------
       
    36 // CTsFswDataList::NewL
       
    37 // --------------------------------------------------------------------------
       
    38 //
       
    39 CTsFswDataList* CTsFswDataList::NewL(CTsFswEngine& aEngine)
       
    40     {
       
    41     CTsFswDataList* self = new (ELeave) CTsFswDataList(aEngine);
       
    42     CleanupStack::PushL (self );
       
    43     self->ConstructL ( );
       
    44     CleanupStack::Pop ( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // --------------------------------------------------------------------------
       
    49 // CTsFswDataList::CTsFswDataList
       
    50 // --------------------------------------------------------------------------
       
    51 //
       
    52 CTsFswDataList::CTsFswDataList(CTsFswEngine& aEngine) :
       
    53     iEngine(aEngine)
       
    54     {
       
    55     }
       
    56 
       
    57 // --------------------------------------------------------------------------
       
    58 // CTsFswDataList::~CTsFswDataList
       
    59 // --------------------------------------------------------------------------
       
    60 //
       
    61 CTsFswDataList::~CTsFswDataList( )
       
    62     {
       
    63     // delete the bitmaps as the hash map cannot do that
       
    64     THashMapIter<TInt, CFbsBitmap*> iter( iScreenshots );
       
    65     while ( const TInt* key = iter.NextKey() )
       
    66         {
       
    67         CFbsBitmap** value = iter.CurrentValue();
       
    68         delete *value;
       
    69         }
       
    70     iScreenshots.Close();
       
    71     delete iAppIcons;
       
    72 
       
    73     iData.ResetAndDestroy();
       
    74 
       
    75     delete iHiddenAppList;
       
    76     delete iAlwaysShownAppList;
       
    77     delete iWidgetList;
       
    78     iAppArcSession.Close();
       
    79     iWsSession.Close();
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // CTsFswDataList::ConstructL
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 void CTsFswDataList::ConstructL( )
       
    87     {
       
    88     User::LeaveIfError( iWsSession.Connect() );
       
    89     User::LeaveIfError( iAppArcSession.Connect() );
       
    90     iHiddenAppList = CTsFsHiddenAppList::NewL( iEngine );
       
    91     iAlwaysShownAppList = CTsFsAlwaysShownAppList::NewL();
       
    92 
       
    93     iWidgetsSupported = FeatureManager::FeatureSupported( KFeatureIdWebWidgets );
       
    94     if ( iWidgetsSupported )
       
    95         {
       
    96         iWidgetList = CTsFsWidgetList::NewL();
       
    97         }
       
    98 
       
    99     // create app icon retriever instance
       
   100     iAppIcons = CTsFswIconCache::NewL();
       
   101     }
       
   102 
       
   103 // --------------------------------------------------------------------------
       
   104 // CTsFswDataList::FswDataL
       
   105 // --------------------------------------------------------------------------
       
   106 //
       
   107 const RTsFswArray& CTsFswDataList::FswDataL()
       
   108     {
       
   109     TSLOG_CONTEXT( FswDataL, TSLOG_LOCAL );
       
   110     TSLOG1_IN( "dirty flag = %d", iTaskListDirty );
       
   111 
       
   112     // check the dirty flag and refresh if needed
       
   113     if ( iTaskListDirty )
       
   114         {
       
   115         CollectTasksL();
       
   116         // dirty flag is cleared in the above call
       
   117         }
       
   118     
       
   119     // Get app icon for entries without screenshot,
       
   120     // do this only here as the app icon is not needed in case a screenshot
       
   121     // is already available.
       
   122     for ( TInt i = 0, ie = iData.Count(); i != ie; ++i )
       
   123         {
       
   124         if ( !iData[i]->ScreenshotHandle() )
       
   125             {
       
   126             CFbsBitmap* bmp;
       
   127             CFbsBitmap* mask;
       
   128             TUid appUid = iData[i]->AppUid();
       
   129             // this will leave with -46 in case of widgets if we do not have AllFiles cap
       
   130             TRAPD( err, iAppIcons->GetIconL( appUid, bmp, mask ) );
       
   131             if ( err == KErrNone && bmp )
       
   132                 {
       
   133                 iData[i]->SetAppIconHandles( bmp->Handle(),
       
   134                     mask ? mask->Handle() : 0 );
       
   135                 }
       
   136             else
       
   137                 {
       
   138                 iAppIcons->DefaultIcon( bmp, mask );
       
   139                 iData[i]->SetAppIconHandles( bmp->Handle(),
       
   140                     mask ? mask->Handle() : 0 );
       
   141                 }
       
   142             }
       
   143         }
       
   144 
       
   145     TSLOG_OUT();
       
   146     return iData;
       
   147     }
       
   148 
       
   149 // --------------------------------------------------------------------------
       
   150 // CTsFswDataList::CollectTasksL
       
   151 // --------------------------------------------------------------------------
       
   152 //
       
   153 TBool CTsFswDataList::CollectTasksL()
       
   154     {
       
   155     // clear dirty flag
       
   156     iTaskListDirty = EFalse;
       
   157     TBool changed = EFalse;
       
   158     
       
   159     RTsFswArray newAppsList;
       
   160     RTsFswArray newWidgetsList;
       
   161     
       
   162     CleanupResetAndDestroyPushL(newAppsList);
       
   163     CleanupResetAndDestroyPushL(newWidgetsList);
       
   164     
       
   165     CollectAppsL(newAppsList);
       
   166     CollectWidgetsL(newWidgetsList);
       
   167     
       
   168     changed |= FitDataToListL(newAppsList, EFalse);
       
   169     changed |= FitDataToListL(newWidgetsList, ETrue);
       
   170     
       
   171     CleanupStack::PopAndDestroy( &newWidgetsList );
       
   172     CleanupStack::PopAndDestroy( &newAppsList );
       
   173     
       
   174     return changed;
       
   175     }
       
   176 
       
   177 
       
   178 // --------------------------------------------------------------------------
       
   179 // CTsFswDataList::AlwaysShown()
       
   180 // --------------------------------------------------------------------------
       
   181 //
       
   182 CTsFsAlwaysShownAppList* CTsFswDataList::AlwaysShownApps()
       
   183     {
       
   184     return iAlwaysShownAppList;
       
   185     }
       
   186 
       
   187 // --------------------------------------------------------------------------
       
   188 // CTsFswDataList::HiddenApps()
       
   189 // --------------------------------------------------------------------------
       
   190 //
       
   191 CTsFsHiddenAppList* CTsFswDataList::HiddenApps()
       
   192     {
       
   193     return iHiddenAppList;
       
   194     }
       
   195 
       
   196 // --------------------------------------------------------------------------
       
   197 // CTsFswDataList::Widgets()
       
   198 // --------------------------------------------------------------------------
       
   199 //
       
   200 CTsFsWidgetList* CTsFswDataList::Widgets()
       
   201     {
       
   202     return iWidgetList;
       
   203     }
       
   204 
       
   205 // --------------------------------------------------------------------------
       
   206 // CTsFswDataList::SetDirty()
       
   207 // --------------------------------------------------------------------------
       
   208 //
       
   209 void CTsFswDataList::SetDirty()
       
   210     {
       
   211     iTaskListDirty = ETrue;
       
   212     }
       
   213 
       
   214 // --------------------------------------------------------------------------
       
   215 // CTsFswDataList::SetAppDataRefreshNeeded()
       
   216 // --------------------------------------------------------------------------
       
   217 //
       
   218 void CTsFswDataList::SetAppDataRefreshNeeded()
       
   219     {
       
   220     iAppDataRefreshNeeded = ETrue;
       
   221     }
       
   222 
       
   223 // --------------------------------------------------------------------------
       
   224 // CTsFswDataList::ForwardScreenshot
       
   225 // --------------------------------------------------------------------------
       
   226 //
       
   227 TBool CTsFswDataList::StoreScreenshot(TInt aId, CFbsBitmap* aBmp)
       
   228     {
       
   229     TBool changed = EFalse;
       
   230     CFbsBitmap** oldbmp = iScreenshots.Find( aId );
       
   231     if ( oldbmp )
       
   232         {
       
   233         delete *oldbmp;
       
   234         }
       
   235     if ( iScreenshots.Insert( aId, aBmp ) != KErrNone )
       
   236         {
       
   237         delete aBmp;
       
   238         iScreenshots.Remove( aId );
       
   239         }
       
   240     else
       
   241         {
       
   242         changed = AssignScreenshotHandle( aId, aBmp->Handle() );
       
   243         }
       
   244     return changed;
       
   245     }
       
   246 
       
   247 // --------------------------------------------------------------------------
       
   248 // CTsFswDataList::RemoveScreenshotByWgId
       
   249 // --------------------------------------------------------------------------
       
   250 //
       
   251 TBool CTsFswDataList::RemoveScreenshot(TInt aId)
       
   252     {
       
   253     TBool changed = EFalse;
       
   254     CFbsBitmap** bmp = iScreenshots.Find( aId );
       
   255     if ( bmp )
       
   256         {
       
   257         delete *bmp;
       
   258         iScreenshots.Remove( aId );
       
   259         changed = AssignScreenshotHandle( aId, 0 );
       
   260         }
       
   261     return changed;
       
   262     }
       
   263 
       
   264 // --------------------------------------------------------------------------
       
   265 // CTsFswDataList::FindScreenshotByWgId
       
   266 // --------------------------------------------------------------------------
       
   267 //
       
   268 CFbsBitmap** CTsFswDataList::FindScreenshot(TInt aId)
       
   269     {
       
   270     CFbsBitmap** result = 0;
       
   271 	result = iScreenshots.Find( aId );
       
   272     return result; 
       
   273     }
       
   274 
       
   275 // --------------------------------------------------------------------------
       
   276 // CTsFswDataList::MoveEntryAtStart
       
   277 // --------------------------------------------------------------------------
       
   278 //
       
   279 void CTsFswDataList::MoveEntryAtStart(TInt aAppId, TBool aWidget)
       
   280     {
       
   281     TSLOG_CONTEXT( MoveEntryAtStart, TSLOG_LOCAL );
       
   282     
       
   283     for ( TInt i = 0; i < iData.Count(); ++i )
       
   284         {
       
   285         if( iData[i]->AppUid().iUid == aAppId && iData[i]->Widget() == aWidget)
       
   286             {
       
   287             CTsFswEntry* entry = iData[i];
       
   288             iData.Remove(i);
       
   289             iData.Insert(entry, 0);
       
   290             break;
       
   291             }
       
   292         }
       
   293     TSLOG_OUT();
       
   294     }
       
   295 
       
   296 // --------------------------------------------------------------------------
       
   297 // CTsFswDataList::
       
   298 // --------------------------------------------------------------------------
       
   299 //
       
   300 void CTsFswDataList::CollectAppsL(RTsFswArray& aAppsList)
       
   301     {
       
   302     TSLOG_CONTEXT( CollectTasksL, TSLOG_LOCAL );
       
   303     TSLOG_IN();
       
   304     // clear dirty flag
       
   305     iTaskListDirty = EFalse;
       
   306     
       
   307     // update app data if needed
       
   308     // (usually on startup and when new apps might have been installed)
       
   309     if ( iAppDataRefreshNeeded )
       
   310         {
       
   311         TSLOG0( TSLOG_INFO, "refreshing app data" );
       
   312         iAppArcSession.GetAllApps();
       
   313         iAlwaysShownAppList->InitializeAlwaysShownListL();
       
   314         iAppDataRefreshNeeded = EFalse;
       
   315         }
       
   316 
       
   317     // get all window groups
       
   318     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
       
   319     CleanupClosePushL( allWgIds );
       
   320     User::LeaveIfError( iWsSession.WindowGroupList( 0, &allWgIds ) );
       
   321 
       
   322     TInt count = allWgIds.Count();
       
   323     for ( TInt i = 0; i < count; ++i )
       
   324         {
       
   325         // ignore uninteresting entries (e.g. embedded apps)
       
   326         if ( allWgIds[i].iParentId > 0 )
       
   327             {
       
   328             continue;
       
   329             }
       
   330         
       
   331         // get window group name
       
   332         TInt wgId = allWgIds[i].iId;
       
   333         CApaWindowGroupName* windowName =
       
   334             CApaWindowGroupName::NewLC( iWsSession, wgId );
       
   335         TUid appUid = windowName->AppUid();
       
   336         
       
   337         // ignore entries with null uid
       
   338         if ( !appUid.iUid )
       
   339             {
       
   340             CleanupStack::PopAndDestroy( windowName );
       
   341             continue;
       
   342             }
       
   343         
       
   344         // will append the task to our own list only if it is not hidden
       
   345         TBool onHiddenList = iHiddenAppList->IsHiddenL(
       
   346             appUid, iWsSession, wgId );
       
   347 
       
   348         // get screen number (-1=console, 0=main screen, 1=cover ui)
       
   349         TInt appScreen = 0;
       
   350         TInt scrNumErr = iAppArcSession.GetDefaultScreenNumber( appScreen, appUid );
       
   351 
       
   352         // check if it is on always-shown list
       
   353         TBool mustShow = iAlwaysShownAppList->IsAlwaysShownApp( appUid );
       
   354 
       
   355 #ifdef _DEBUG
       
   356         const TDesC& captionDbg( windowName->Caption() );
       
   357         TSLOG4( TSLOG_INFO, "[%d] wgid=%d appuid=%x (%S)", i, wgId,
       
   358             appUid.iUid, &captionDbg );
       
   359         TSLOG4( TSLOG_INFO, "hidden=%d onhiddenlist=%d mustshow=%d scrno=%d",
       
   360             windowName->Hidden(), onHiddenList, mustShow, appScreen );
       
   361 #endif
       
   362         if ( iWidgetsSupported && appUid.iUid == KWidgetAppUidValue )
       
   363             {
       
   364             //continue, leave widgetui, do nothing
       
   365             }
       
   366         // add item to task list if it is always-shown OR it is not hidden
       
   367         // and it is not on cover ui
       
   368         else if (mustShow || (!onHiddenList && !windowName->Hidden() && (appScreen
       
   369                 == 0 || appScreen == -1) && scrNumErr == KErrNone))
       
   370             {
       
   371             AddEntryL(wgId, appUid, windowName, aAppsList, EFalse);
       
   372             }
       
   373         CleanupStack::PopAndDestroy( windowName );
       
   374         }
       
   375     CleanupStack::PopAndDestroy( &allWgIds );
       
   376     TSLOG_OUT();
       
   377     }
       
   378 
       
   379 // --------------------------------------------------------------------------
       
   380 // CTsFswDataList::AddEntryL
       
   381 // --------------------------------------------------------------------------
       
   382 //
       
   383 TBool CTsFswDataList::AddEntryL( TInt aWgId, const TUid& aAppUid,
       
   384         CApaWindowGroupName* aWgName, RTsFswArray& aNewList,
       
   385         TBool aIsWidget )
       
   386     {
       
   387     TBool changed = EFalse;
       
   388     CTsFswEntry* entry = CTsFswEntry::NewLC();
       
   389     entry->SetWgId( aWgId );
       
   390     entry->SetAppUid( aAppUid );
       
   391     entry->SetWidget( aIsWidget );
       
   392 
       
   393     // check if present in old list and if yes then take some of the old data
       
   394     TBool found = ConsiderOldDataL( *entry, aAppUid, changed, aNewList );
       
   395 
       
   396     // if not present previously then find out app name
       
   397     // and check if screenshot is already available
       
   398     if ( !found )
       
   399         {
       
   400         // when adding a new entry to the list it is changed for sure
       
   401         changed = ETrue;
       
   402         HBufC* name = FindAppNameLC( aWgName, aAppUid, aWgId );
       
   403         if ( name )
       
   404             {
       
   405             entry->SetAppNameL( *name );
       
   406             }
       
   407         CleanupStack::PopAndDestroy( name );
       
   408 
       
   409         entry->SetAlwaysShown( iAlwaysShownAppList->IsAlwaysShownApp( aAppUid ) );
       
   410         if ( aWgName )
       
   411             {
       
   412             entry->SetSystemApp( aWgName->IsSystem() );
       
   413             }
       
   414         }
       
   415     TInt h = LookupScreenshotHandle( aWgId );
       
   416     if ( h )
       
   417         {
       
   418         entry->SetScreenshotHandle( h );
       
   419         }
       
   420     // add to new list, ownership is transferred
       
   421     aNewList.AppendL( entry );
       
   422     CleanupStack::Pop( entry );
       
   423     return changed;
       
   424     }
       
   425 
       
   426 // --------------------------------------------------------------------------
       
   427 // CTsFswDataList::ConsiderOldDataL
       
   428 // --------------------------------------------------------------------------
       
   429 //
       
   430 TBool CTsFswDataList::ConsiderOldDataL( CTsFswEntry& aEntry,
       
   431         const TUid& aAppUid,
       
   432         TBool& aChanged,
       
   433         RTsFswArray& aNewList )
       
   434     {
       
   435     for ( TInt entryIdx = 0, oldCount = iData.Count();
       
   436             entryIdx < oldCount; ++entryIdx )
       
   437         {
       
   438         // Enough to check appuid, no need to bother with wgid as the
       
   439         // screenshot handle is up-to-date or will be updated later anyway.
       
   440         if ( iData[entryIdx]->AppUid() == aAppUid )
       
   441             {
       
   442             iData[entryIdx]->SetWgId( aEntry.WgId());
       
   443             // if positions do not match then the list is different than before
       
   444             if ( entryIdx != aNewList.Count() )
       
   445                 {
       
   446                 aChanged = ETrue;
       
   447                 }
       
   448             CTsFswEntry* oldEntry = iData[entryIdx];
       
   449             aEntry.SetAppNameL( oldEntry->AppName() );
       
   450             aEntry.SetScreenshotHandle( oldEntry->ScreenshotHandle() );
       
   451             aEntry.SetAlwaysShown( oldEntry->AlwaysShown() );
       
   452             aEntry.SetSystemApp( oldEntry->SystemApp() );
       
   453             return ETrue;
       
   454             }
       
   455         }
       
   456     return EFalse;
       
   457     }
       
   458 // --------------------------------------------------------------------------
       
   459 // CTsFswDataList::CollectWidgetsL
       
   460 // --------------------------------------------------------------------------
       
   461 //
       
   462 void CTsFswDataList::CollectWidgetsL(RTsFswArray& aWidgetsList)
       
   463     {
       
   464     if( iWidgetsSupported )
       
   465         {
       
   466         iWidgetList->InitializeWidgetListL();
       
   467         const RWidgetInfoArray& arr( iWidgetList->RunningWidgets() );
       
   468         for ( TInt i = 0, ie = arr.Count(); i != ie; ++i )
       
   469             {
       
   470             //verify if widget is working in full screen mode
       
   471             if( arr[i]->iFileSize )
       
   472                 {
       
   473                 // wgid will be a special negative value
       
   474                 // windowgroupname is not needed here so pass NULL
       
   475                 AddEntryL( -(i+1), arr[i]->iUid, 0, aWidgetsList, ETrue );
       
   476                 }
       
   477             }
       
   478         }
       
   479 	}
       
   480 
       
   481 // --------------------------------------------------------------------------
       
   482 // CTsFswDataList::FindParentWgId
       
   483 // --------------------------------------------------------------------------
       
   484 //
       
   485 TInt CTsFswDataList::FindParentWgId( TInt aWgId )
       
   486     {
       
   487     TInt parent( KErrNotFound );
       
   488     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
       
   489     // Ask for window group list from RWsSession
       
   490     TInt error = iWsSession.WindowGroupList( 0, &allWgIds );
       
   491     if ( !error )
       
   492         {
       
   493         TInt count( allWgIds.Count() );
       
   494         for ( TInt i( 0 ); i < count; i++ )
       
   495             {
       
   496             RWsSession::TWindowGroupChainInfo info = allWgIds[i];
       
   497             if ( info.iId == aWgId && info.iParentId > 0)
       
   498                 {
       
   499                 parent = info.iParentId;
       
   500                 break;
       
   501                 }
       
   502             }
       
   503         }
       
   504     allWgIds.Close();
       
   505     return parent;
       
   506     }
       
   507 
       
   508 // --------------------------------------------------------------------------
       
   509 // CTsFswDataList::FindMostTopParentWgId
       
   510 // --------------------------------------------------------------------------
       
   511 //
       
   512 TInt CTsFswDataList::FindMostTopParentWgId( TInt aWgId )
       
   513     {
       
   514     TInt parent( KErrNotFound );
       
   515     parent = FindParentWgId( aWgId );
       
   516     if( parent != KErrNotFound)
       
   517         {
       
   518         TInt topParent = FindMostTopParentWgId(parent);
       
   519         if( topParent != KErrNotFound )
       
   520             {
       
   521             parent = topParent;
       
   522             }
       
   523         }
       
   524     return parent;
       
   525     }
       
   526 
       
   527 // --------------------------------------------------------------------------
       
   528 // CTsFswDataList::FindAppNameLC
       
   529 // --------------------------------------------------------------------------
       
   530 //
       
   531 HBufC* CTsFswDataList::FindAppNameLC( CApaWindowGroupName* aWindowName,
       
   532                                   const TUid& aAppUid,
       
   533                                   TInt aWgId )
       
   534     {
       
   535     //Retrieve the app name
       
   536     TApaAppInfo info;
       
   537     iAppArcSession.GetAppInfo( info, aAppUid );
       
   538     TPtrC caption = info.iShortCaption;
       
   539 
       
   540     HBufC* tempName = 0;
       
   541     if ( !caption.Length() && aWindowName ) // if not set - use thread name instead
       
   542         {
       
   543         if ( aWindowName->Caption().Length() )
       
   544             {
       
   545             tempName = aWindowName->Caption().AllocL();
       
   546             //put on cleanupstack after the if
       
   547             }
       
   548         else
       
   549             {
       
   550             TThreadId threadId;
       
   551             TInt err = iWsSession.GetWindowGroupClientThreadId(
       
   552                     aWgId, threadId );
       
   553             if ( err == KErrNone )
       
   554                 {
       
   555                 RThread thread;
       
   556                 CleanupClosePushL( thread );
       
   557                 err = thread.Open ( threadId );
       
   558                 if ( err==KErrNone )
       
   559                     {
       
   560                     tempName = thread.Name().AllocL(); // codescanner::forgottoputptroncleanupstack
       
   561                     // tempName put on cleanupstack after the if
       
   562                     }
       
   563                 CleanupStack::PopAndDestroy( &thread );
       
   564                 }
       
   565             }
       
   566         }
       
   567     else
       
   568         {
       
   569         tempName = caption.AllocL();
       
   570         //put on cleanupstack after the if
       
   571         }
       
   572     CleanupStack::PushL( tempName );
       
   573     return tempName;
       
   574     }
       
   575 
       
   576 // --------------------------------------------------------------------------
       
   577 // CTsFswDataList::AssignScreenshotHandle
       
   578 // Called when a screenshot arrives to check if there is a corresponding
       
   579 // application in the task list. Firstly try to match screenshot into parental
       
   580 // application then into standalone one.
       
   581 // --------------------------------------------------------------------------
       
   582 //
       
   583 TBool CTsFswDataList::AssignScreenshotHandle( TInt aWgIdForScreenshot,
       
   584         TInt aBitmapHandle )
       
   585     {
       
   586 //            aWgIdForScreenshot, aBitmapHandle);
       
   587     TBool changed = EFalse;
       
   588     TInt parentWgId = FindMostTopParentWgId( aWgIdForScreenshot );
       
   589     // now parentWgId is a valid wgid or KErrNotFound (-1)
       
   590     if (parentWgId != KErrNotFound)
       
   591         {
       
   592         AssignScreenshotHandle( parentWgId, aBitmapHandle, changed );
       
   593         }
       
   594     if (!changed)
       
   595         {
       
   596         AssignScreenshotHandle( aWgIdForScreenshot, aBitmapHandle, changed );
       
   597         }
       
   598     return changed;
       
   599     }
       
   600 
       
   601 // --------------------------------------------------------------------------
       
   602 // CTsFswDataList::AssignScreenshotHandle
       
   603 // Called when a screenshot arrives to check if there is a corresponding
       
   604 // application in the task list. It might be tried to be match into parental 
       
   605 // or standalone application.
       
   606 // --------------------------------------------------------------------------
       
   607 //
       
   608 void CTsFswDataList::AssignScreenshotHandle(TInt aWgIdForScreenshot,
       
   609         TInt aBitmapHandle, TBool& aAsigned)
       
   610     {
       
   611     aAsigned = EFalse;
       
   612     for (TInt i = 0, ie = iData.Count(); i != ie; ++i)
       
   613         {
       
   614         if (iData[i]->Widget())
       
   615             {
       
   616             TInt widgetId = iData[i]->AppUid().iUid;
       
   617             if (widgetId == aWgIdForScreenshot)
       
   618                 {
       
   619                 iData[i]->SetScreenshotHandle(aBitmapHandle);
       
   620                 aAsigned = ETrue;
       
   621                 break;
       
   622                 }  
       
   623 			continue;          
       
   624             }
       
   625         TInt appWgId = iData[i]->WgId();
       
   626         if (appWgId == aWgIdForScreenshot)
       
   627             {
       
   628             iData[i]->SetScreenshotHandle(aBitmapHandle);
       
   629             aAsigned = ETrue;
       
   630             break;
       
   631             }
       
   632         }
       
   633     }
       
   634 
       
   635 // --------------------------------------------------------------------------
       
   636 // CTsFswDataList::LookupScreenshotHandle
       
   637 // Called to check if there is a screenshot already stored for the given
       
   638 // app. (or a screenshot with a wgid for which aWgIdForApp is the parent)
       
   639 // --------------------------------------------------------------------------
       
   640 //
       
   641 TInt CTsFswDataList::LookupScreenshotHandle( TInt aWgIdForApp )
       
   642     {
       
   643     CFbsBitmap** bmp = NULL;
       
   644 
       
   645     if ( aWgIdForApp > 0 )
       
   646         {
       
   647         // must check if there is a screenshot for which aWgIdForApp is the parent
       
   648         THashMapIter<TInt, CFbsBitmap*> iter( iScreenshots );
       
   649         while ( const TInt* wgid = iter.NextKey() )
       
   650             {
       
   651             if ( FindMostTopParentWgId( *wgid ) == aWgIdForApp )
       
   652                 {
       
   653                 THashMapIter<TInt, CFbsBitmap*> iter2( iScreenshots );
       
   654                 TBool hasChild = false;
       
   655                 while ( const TInt* wgid2 = iter2.NextKey() )
       
   656                     {
       
   657                     if ( FindParentWgId( *wgid2 ) == *wgid )
       
   658                         {
       
   659                         hasChild = true;
       
   660                         break;
       
   661                         }
       
   662                     }
       
   663                 if ( !hasChild )
       
   664                     {
       
   665                     bmp = iter.CurrentValue();
       
   666                     if ( bmp )
       
   667                         {
       
   668                         return (*bmp)->Handle();
       
   669                         }
       
   670                     }
       
   671                 }
       
   672             }
       
   673         if ( !bmp )
       
   674             {
       
   675             bmp = iScreenshots.Find( aWgIdForApp );
       
   676             if ( bmp )
       
   677                 {
       
   678                 // there is a screenshot stored for this wgid
       
   679                 return (*bmp)->Handle();
       
   680                 }
       
   681             }
       
   682         }
       
   683     else if ( aWgIdForApp < 0 )
       
   684         {
       
   685         // Must be a widget, wgid is useless in this case.
       
   686         // Do not do anything for now => no screenshot for widgets.
       
   687         }
       
   688     return 0;
       
   689     }
       
   690 
       
   691 // --------------------------------------------------------------------------
       
   692 // CTsFswDataList::FitDataToListL
       
   693 // --------------------------------------------------------------------------
       
   694 //
       
   695 TBool CTsFswDataList::FitDataToListL(RTsFswArray& aListToFit,
       
   696         TBool aConsiderWidgets)
       
   697     {
       
   698     TSLOG_CONTEXT( FitDataToListL, TSLOG_LOCAL );
       
   699     TBool changed = EFalse;
       
   700     TInt listCount = aListToFit.Count();
       
   701     TInt dataCount = iData.Count();
       
   702     
       
   703     //remove items that dont't exists in newly collected list
       
   704     //consider widget and non-widget type
       
   705     for (TInt i = dataCount -1; i >= 0; --i)
       
   706         {
       
   707         if ( (iData[i]->Widget() == aConsiderWidgets) &&
       
   708             !CheckIfExists(*iData[i], aListToFit) )
       
   709             {
       
   710             delete iData[i];
       
   711             iData.Remove(i);
       
   712             changed = ETrue;
       
   713             }
       
   714         }
       
   715     
       
   716     //add new item at start
       
   717     for (TInt i = 0; i < aListToFit.Count(); ++i)
       
   718         {
       
   719         if (!CheckIfExists(*aListToFit[i], iData))
       
   720             {
       
   721             iData.Insert(aListToFit[i], 0);
       
   722             aListToFit[i] = 0;
       
   723             changed = ETrue;
       
   724             }
       
   725         }
       
   726     
       
   727     TSLOG1_OUT( "change flag = %d", changed );
       
   728     return changed;
       
   729     }
       
   730 
       
   731 // --------------------------------------------------------------------------
       
   732 // CTsFswDataList::CheckIfExists
       
   733 // --------------------------------------------------------------------------
       
   734 //
       
   735 TBool CTsFswDataList::CheckIfExists(const CTsFswEntry& aEntry,
       
   736         const RTsFswArray& aList) const
       
   737     {
       
   738     TSLOG_CONTEXT( FitDataToListL, TSLOG_LOCAL );
       
   739     TBool exists(EFalse);
       
   740     TInt dataCount = aList.Count();
       
   741     for (TInt entryIdx = 0; entryIdx < dataCount; ++entryIdx)
       
   742         {
       
   743         if (aList[entryIdx]->AppUid() == aEntry.AppUid())
       
   744             {
       
   745             exists = ETrue;
       
   746             break;
       
   747             }
       
   748         }
       
   749     TSLOG_OUT();
       
   750     return exists;
       
   751     }
       
   752 
       
   753 // end of file