tstaskmonitor/server/src/tsfswdatalist.cpp
changeset 96 5d243a69bdda
parent 94 dbb8300717f7
child 98 d2f833ab7940
equal deleted inserted replaced
95:c739008478cc 96:5d243a69bdda
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     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  *
     8  *
    16 */
     9  * Initial Contributors:
    17 
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  File containing application list classes
       
    15  *
       
    16  */
    18 
    17 
    19 //INCLUDES:
    18 //INCLUDES:
    20 #define __E32SVR_H__
    19 
    21 #include "tsfswdatalist.h"
    20 #include "tsfswdatalist.h"
    22 #include "tsfswengine.h"
    21 #include "tsfswengine.h"
       
    22 #include "tsentrykeygenerator.h"
    23 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL
    23 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL
    24 #include <featmgr.h>
       
    25 #include <apgwgnam.h>
    24 #include <apgwgnam.h>
    26 #include <AknsUtils.h>
       
    27 #include <gulicon.h>
       
    28 #include <e32debug.h>
       
    29 #include <bitstd.h>
    25 #include <bitstd.h>
    30 #include <AknIconUtils.h> // avkon
    26 #include <AknIconUtils.h> // avkon
    31 #include <APGICNFL.H> // fbsbitmap
    27 #include <apgicnfl.h> // fbsbitmap
    32 #include <akniconsrvclient.h> 
    28 #include <AknIconSrvClient.h> 
       
    29 #include <fbs.h>
       
    30 #include <APGWGNAM.H>
       
    31 
    33 
    32 
    34 // size for the created app icons
    33 // size for the created app icons
    35 const TInt KAppIconWidth = 128;
    34 const TInt KAppIconWidth = 128;
    36 const TInt KAppIconHeight = 128;
    35 const TInt KAppIconHeight = 128;
    37 
    36 
    38 //uids to be hidden
    37 //uids to be hidden
    39 const TUid KHsApplicationUid = {0x20022F35};
    38 const TUid KHsApplicationUid = { 0x20022F35 };
    40 const TUid KTelephoneUid = {0x100058B3};
       
    41 
    39 
    42 // ================= MEMBER FUNCTIONS =======================
    40 // ================= MEMBER FUNCTIONS =======================
    43 
    41 
    44 // --------------------------------------------------------------------------
    42 // --------------------------------------------------------------------------
    45 // CTsFswDataList::NewL
    43 // CTsFswDataList::NewL
    46 // --------------------------------------------------------------------------
    44 // --------------------------------------------------------------------------
    47 //
    45 //
    48 CTsFswDataList* CTsFswDataList::NewL(CTsFswEngine& aEngine)
    46 CTsFswDataList* CTsFswDataList::NewL(MHsDataObserver &observer)
    49     {
    47 {
    50     CTsFswDataList* self = new (ELeave) CTsFswDataList(aEngine);
    48     CTsFswDataList* self = new (ELeave) CTsFswDataList(observer);
    51     CleanupStack::PushL (self );
    49     CleanupStack::PushL(self);
    52     self->ConstructL ( );
    50     self->ConstructL();
    53     CleanupStack::Pop ( self );
    51     CleanupStack::Pop(self);
    54     return self;
    52     return self;
    55     }
    53 }
    56 
    54 
    57 // --------------------------------------------------------------------------
    55 // --------------------------------------------------------------------------
    58 // CTsFswDataList::CTsFswDataList
    56 // CTsFswDataList::CTsFswDataList
    59 // --------------------------------------------------------------------------
    57 // --------------------------------------------------------------------------
    60 //
    58 //
    61 CTsFswDataList::CTsFswDataList(CTsFswEngine& aEngine) :
    59 CTsFswDataList::CTsFswDataList(MHsDataObserver& observer) :
    62     iEngine(aEngine)
    60     mObserver(observer)
    63     {
    61 {
    64     }
    62 }
    65 
    63 
    66 // --------------------------------------------------------------------------
    64 // --------------------------------------------------------------------------
    67 // CTsFswDataList::~CTsFswDataList
    65 // CTsFswDataList::~CTsFswDataList
    68 // --------------------------------------------------------------------------
    66 // --------------------------------------------------------------------------
    69 //
    67 //
    70 CTsFswDataList::~CTsFswDataList( )
    68 CTsFswDataList::~CTsFswDataList()
    71     {
    69 {
    72     iData.ResetAndDestroy();
    70     mData.ResetAndDestroy();
    73     iAppArcSession.Close();
    71     mAppArcSession.Close();
    74     iWsSession.Close();
    72     mWsSession.Close();
    75     iHiddenUids.Close();
    73     mHiddenUids.Close();
       
    74     mAllowedUids.Close();
    76     RFbsSession::Disconnect();
    75     RFbsSession::Disconnect();
    77     RAknIconSrvClient::Disconnect();
    76     RAknIconSrvClient::Disconnect();
    78     }
    77 }
    79 
    78 
    80 // --------------------------------------------------------------------------
    79 // --------------------------------------------------------------------------
    81 // CTsFswDataList::ConstructL
    80 // CTsFswDataList::ConstructL
    82 // --------------------------------------------------------------------------
    81 // --------------------------------------------------------------------------
    83 //
    82 //
    84 void CTsFswDataList::ConstructL( )
    83 void CTsFswDataList::ConstructL()
    85     {
    84 {
    86     User::LeaveIfError( iWsSession.Connect() );
    85     User::LeaveIfError(mWsSession.Connect());
    87     User::LeaveIfError( iAppArcSession.Connect() );
    86     User::LeaveIfError(mAppArcSession.Connect());
    88     iHiddenUids.AppendL( KHsApplicationUid );
    87     mHiddenUids.AppendL(KHsApplicationUid);
    89     iHiddenUids.AppendL( KTelephoneUid );
       
    90     User::LeaveIfError(RFbsSession::Connect());
    88     User::LeaveIfError(RFbsSession::Connect());
    91     RAknIconSrvClient::Connect();
    89     RAknIconSrvClient::Connect();
    92     }
    90 }
    93 
    91 
    94 // --------------------------------------------------------------------------
    92 // --------------------------------------------------------------------------
    95 // CTsFswDataList::FswDataL
    93 // CTsFswDataList::FswDataL
    96 // --------------------------------------------------------------------------
    94 // --------------------------------------------------------------------------
    97 //
    95 //
    98 const RTsFswArray& CTsFswDataList::FswDataL()
    96 const RTsFswArray& CTsFswDataList::FswDataL()
    99     {
    97 {
   100     // check the dirty flag and refresh if needed
    98     return mData;
   101     if ( iTaskListDirty )
    99 }
   102         {
       
   103         CollectTasksL();
       
   104         // dirty flag is cleared in the above call
       
   105         }
       
   106 
       
   107     return iData;
       
   108     }
       
   109 
   100 
   110 // --------------------------------------------------------------------------
   101 // --------------------------------------------------------------------------
   111 // CTsFswDataList::CollectTasksL
   102 // CTsFswDataList::CollectTasksL
   112 // --------------------------------------------------------------------------
   103 // --------------------------------------------------------------------------
   113 //
   104 //
   114 TBool CTsFswDataList::CollectTasksL()
   105 TBool CTsFswDataList::CollectTasksL()
   115     {
   106 {
   116     // clear dirty flag
       
   117     iTaskListDirty = EFalse;
       
   118     TBool changed = EFalse;
   107     TBool changed = EFalse;
   119     
       
   120     RTsFswArray newAppsList;
   108     RTsFswArray newAppsList;
   121     
       
   122     CleanupResetAndDestroyPushL(newAppsList);
   109     CleanupResetAndDestroyPushL(newAppsList);
   123     
       
   124     CollectAppsL(newAppsList);
   110     CollectAppsL(newAppsList);
   125     
   111     changed |= FitDataToListL(newAppsList);
   126     changed |= FitDataToListL(newAppsList, EFalse);
   112     CleanupStack::PopAndDestroy(&newAppsList);
   127     
       
   128     CleanupStack::PopAndDestroy( &newAppsList );
       
   129     
       
   130     return changed;
   113     return changed;
   131     }
   114 }
   132 
       
   133 
       
   134 // --------------------------------------------------------------------------
       
   135 // CTsFswDataList::SetDirty()
       
   136 // --------------------------------------------------------------------------
       
   137 //
       
   138 void CTsFswDataList::SetDirty()
       
   139     {
       
   140     iTaskListDirty = ETrue;
       
   141     }
       
   142 
       
   143 // --------------------------------------------------------------------------
       
   144 // CTsFswDataList::SetAppDataRefreshNeeded()
       
   145 // --------------------------------------------------------------------------
       
   146 //
       
   147 void CTsFswDataList::SetAppDataRefreshNeeded()
       
   148     {
       
   149     iAppDataRefreshNeeded = ETrue;
       
   150     }
       
   151 
       
   152 // --------------------------------------------------------------------------
       
   153 // CTsFswDataList::MoveEntryAtStart
       
   154 // --------------------------------------------------------------------------
       
   155 //
       
   156 void CTsFswDataList::MoveEntryAtStart(TInt aAppId, TBool /*aWidget*/)
       
   157     {
       
   158     TInt appId(0);
       
   159     //check embeded case
       
   160 
       
   161     TInt wgId(0);
       
   162     CApaWindowGroupName::FindByAppUid(TUid::Uid(aAppId), iWsSession, wgId);
       
   163     TInt parentWgId = FindMostTopParentWgId( wgId );
       
   164     if( parentWgId != KErrNotFound )
       
   165         {
       
   166         TUid appUid = TUid::Uid(0);
       
   167         AppUidForWgId(parentWgId, appUid); 
       
   168         appId = appUid.iUid;
       
   169         }
       
   170 
       
   171     
       
   172     if( !appId )
       
   173     	{
       
   174 		appId = aAppId;
       
   175     	}
       
   176     
       
   177     for ( TInt i = 0; i < iData.Count(); ++i )
       
   178        {
       
   179        if( iData[i]->AppUid().iUid == appId )
       
   180            {
       
   181            CTsFswEntry* entry = iData[i];
       
   182            iData.Remove(i);
       
   183            iData.Insert(entry, 0);
       
   184            iOrderChanged = ETrue;
       
   185            break;
       
   186            }
       
   187        }
       
   188     }
       
   189 
   115 
   190 // --------------------------------------------------------------------------
   116 // --------------------------------------------------------------------------
   191 // CTsFswDataList::
   117 // CTsFswDataList::
   192 // --------------------------------------------------------------------------
   118 // --------------------------------------------------------------------------
   193 //
   119 //
   194 void CTsFswDataList::CollectAppsL(RTsFswArray& aAppsList)
   120 void CTsFswDataList::CollectAppsL(RTsFswArray& appsList)
   195     {
   121 {
   196 
   122     // gets allowed uids - running apps without hidden uids, null uids, filtered uid
   197     
   123     GetAllowedUidsL();
   198     // update app data if needed
       
   199     // (usually on startup and when new apps might have been installed)
       
   200     if ( iAppDataRefreshNeeded )
       
   201         {
       
   202 
       
   203         iAppArcSession.GetAllApps();
       
   204         iAppDataRefreshNeeded = EFalse;
       
   205         }
       
   206 
   124 
   207     // get all window groups
   125     // get all window groups
   208     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
   126     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
   209     CleanupClosePushL( allWgIds );
   127     CleanupClosePushL(allWgIds);
   210     User::LeaveIfError( iWsSession.WindowGroupList( 0, &allWgIds ) );
   128     User::LeaveIfError(mWsSession.WindowGroupList(0, &allWgIds));
   211 
   129 
   212     TInt count = allWgIds.Count();
   130     TInt count = allWgIds.Count();
   213     for ( TInt i = 0; i < count; ++i )
   131     for (TInt i = 0; i < count; ++i) {
   214         {
   132         TTsEntryKey key = TsEntryKeyGeneraror::GenerateL(allWgIds[i].iId, allWgIds.Array());
   215         // ignore uninteresting entries (e.g. embedded apps)
   133         //skip this entry if it is already on list
   216         if ( allWgIds[i].iParentId > 0 )
   134         if (FindEntry(appsList, key) >= 0) {
   217             {
       
   218             continue;
   135             continue;
   219             }
   136         }
   220         
   137 
   221         // get window group name
   138         // get window group name
   222         TInt wgId = allWgIds[i].iId;
   139         TInt wgId = key.mParentId;
   223         CApaWindowGroupName* windowName =
   140         CApaWindowGroupName* windowName = CApaWindowGroupName::NewLC(mWsSession, wgId);
   224             CApaWindowGroupName::NewLC( iWsSession, wgId );
       
   225         TUid appUid = windowName->AppUid();
   141         TUid appUid = windowName->AppUid();
   226         
   142 
   227         // ignore entries with null uid
   143         // add item to task list if uid is allowed
   228         if ( !appUid.iUid )
   144         if (mAllowedUids.Find(appUid) >= 0) {
   229             {
   145             AddEntryL(key, appUid, windowName, appsList);
   230             CleanupStack::PopAndDestroy( windowName );
   146         }
   231             continue;
   147         CleanupStack::PopAndDestroy(windowName);
   232             }
   148     }
   233 
   149     CleanupStack::PopAndDestroy(&allWgIds);
   234         // add item to task list if it is not hidden
   150 }
   235         if ( !windowName->Hidden() && !IsHiddenUid(appUid) )
       
   236             {
       
   237             AddEntryL(wgId, appUid, windowName, aAppsList, EFalse);
       
   238             }
       
   239         CleanupStack::PopAndDestroy( windowName );
       
   240         }
       
   241     CleanupStack::PopAndDestroy( &allWgIds );
       
   242     }
       
   243 
   151 
   244 // --------------------------------------------------------------------------
   152 // --------------------------------------------------------------------------
   245 // CTsFswDataList::AddEntryL
   153 // CTsFswDataList::AddEntryL
   246 // --------------------------------------------------------------------------
   154 // --------------------------------------------------------------------------
   247 //
   155 //
   248 TBool CTsFswDataList::AddEntryL( TInt aWgId, const TUid& aAppUid,
   156 void CTsFswDataList::AddEntryL(const TTsEntryKey& key, const TUid& appUid,
   249         CApaWindowGroupName* aWgName, RTsFswArray& aNewList,
   157     CApaWindowGroupName* wgName, RTsFswArray& newList)
   250         TBool /*aIsWidget*/ )
   158 {
   251     {
   159     CTsFswEntry* entry = CTsFswEntry::NewLC(key, &mObserver);
   252     TBool changed = EFalse;
       
   253     CTsFswEntry* entry = CTsFswEntry::NewLC();
       
   254     entry->SetWgId( aWgId );
       
   255     entry->SetAppUid( aAppUid );
       
   256 
   160 
   257     // check if present in old list and if yes then take some of the old data
   161     // check if present in old list and if yes then take some of the old data
   258     TBool found = ConsiderOldDataL( *entry, aAppUid, changed, aNewList );
   162     TBool found = ConsiderOldDataL(key);
   259 
   163 
   260     // if not present previously then find out app name
   164     // if not present previously then find out app name
   261     // and check if screenshot is already available
   165     // and check if screenshot is already available
   262     if ( !found )
   166     if (!found) {
   263         {
   167         entry->SetAppUid(appUid);
   264         // when adding a new entry to the list it is changed for sure
   168         HBufC* name = FindAppNameLC(wgName, appUid, key.mParentId);
   265         changed = ETrue;
   169         if (name) {
   266         HBufC* name = FindAppNameLC( aWgName, aAppUid, aWgId );
   170             entry->SetAppNameL(*name);
   267         if ( name )
   171         }
   268             {
   172         CleanupStack::PopAndDestroy(name);
   269             entry->SetAppNameL( *name );
   173 
   270             }
   174         if (wgName) {
   271         CleanupStack::PopAndDestroy( name );
   175             entry->SetCloseableApp(!wgName->IsSystem());
   272 
   176         }
   273         if ( aWgName )
       
   274             {
       
   275             entry->SetCloseableApp( !aWgName->IsSystem() );
       
   276             }
       
   277         CFbsBitmap* iconBitmap = NULL;
   177         CFbsBitmap* iconBitmap = NULL;
   278         CFbsBitmap* iconMask = NULL;
   178         CFbsBitmap* iconMask = NULL;
   279         GetAppIconL(aAppUid, iconBitmap, iconMask);    
   179         GetAppIconL(appUid, iconBitmap, iconMask);
   280         //transfer ownership to entry
   180         //transfer ownership to entry
   281         entry->SetAppIcon( iconBitmap, iconMask );        
   181         entry->SetAppIcon(iconBitmap, iconMask);
   282         }        
   182     }
   283 
   183 
   284     // add to new list, ownership is transferred
   184     // add to new list, ownership is transferred
   285     aNewList.AppendL( entry );
   185     newList.AppendL(entry);
   286     CleanupStack::Pop( entry );
   186     CleanupStack::Pop(entry);
   287     return changed;
   187 }
   288     }
       
   289 
   188 
   290 // --------------------------------------------------------------------------
   189 // --------------------------------------------------------------------------
   291 // CTsFswDataList::ConsiderOldDataL
   190 // CTsFswDataList::ConsiderOldDataL
   292 // --------------------------------------------------------------------------
   191 // --------------------------------------------------------------------------
   293 //
   192 //
   294 TBool CTsFswDataList::ConsiderOldDataL( CTsFswEntry& aEntry,
   193 TBool CTsFswDataList::ConsiderOldDataL(const TTsEntryKey& key)
   295         const TUid& aAppUid,
   194 {
   296         TBool& aChanged,
   195     for (TInt entryIdx = 0, oldCount = mData.Count(); entryIdx < oldCount; ++entryIdx) {
   297         RTsFswArray& aNewList )
   196         if (mData[entryIdx]->Key() == key) {
   298     {
       
   299     for ( TInt entryIdx = 0, oldCount = iData.Count();
       
   300             entryIdx < oldCount; ++entryIdx )
       
   301         {
       
   302         // Enough to check appuid, no need to bother with wgid as the
       
   303         // screenshot handle is up-to-date or will be updated later anyway.
       
   304         if ( iData[entryIdx]->AppUid() == aAppUid )
       
   305             {
       
   306             iData[entryIdx]->SetWgId( aEntry.WgId());
       
   307             // if positions do not match then the list is different than before
       
   308             if ( entryIdx != aNewList.Count() )
       
   309                 {
       
   310                 aChanged = ETrue;
       
   311                 }
       
   312             CTsFswEntry* oldEntry = iData[entryIdx];
       
   313             aEntry.SetAppNameL( oldEntry->AppName() );            
       
   314             aEntry.SetCloseableApp( oldEntry->CloseableApp() );
       
   315             return ETrue;
   197             return ETrue;
   316             }
   198         }
   317         }
   199     }
   318     return EFalse;
   200     return EFalse;
   319     }
   201 }
   320 
       
   321 
       
   322 // --------------------------------------------------------------------------
       
   323 // CTsFswDataList::FindParentWgId
       
   324 // --------------------------------------------------------------------------
       
   325 //
       
   326 TInt CTsFswDataList::FindParentWgId( TInt aWgId )
       
   327     {
       
   328     TInt parent( KErrNotFound );
       
   329     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
       
   330     // Ask for window group list from RWsSession
       
   331     TInt error = iWsSession.WindowGroupList( 0, &allWgIds );
       
   332     if ( !error )
       
   333         {
       
   334         TInt count( allWgIds.Count() );
       
   335         for ( TInt i( 0 ); i < count; i++ )
       
   336             {
       
   337             RWsSession::TWindowGroupChainInfo info = allWgIds[i];
       
   338             if ( info.iId == aWgId && info.iParentId > 0)
       
   339                 {
       
   340                 parent = info.iParentId;
       
   341                 break;
       
   342                 }
       
   343             }
       
   344         }
       
   345     allWgIds.Close();
       
   346     return parent;
       
   347     }
       
   348 
       
   349 // --------------------------------------------------------------------------
       
   350 // CTsFswDataList::FindMostTopParentWgId
       
   351 // --------------------------------------------------------------------------
       
   352 //
       
   353 TInt CTsFswDataList::FindMostTopParentWgId( TInt aWgId )
       
   354     {
       
   355     TInt parent( KErrNotFound );
       
   356     parent = FindParentWgId( aWgId );
       
   357     if( parent != KErrNotFound)
       
   358         {
       
   359         TInt topParent = FindMostTopParentWgId(parent);
       
   360         if( topParent != KErrNotFound )
       
   361             {
       
   362             parent = topParent;
       
   363             }
       
   364         }
       
   365     return parent;
       
   366     }
       
   367 
   202 
   368 // --------------------------------------------------------------------------
   203 // --------------------------------------------------------------------------
   369 // CTsFswDataList::FindAppNameLC
   204 // CTsFswDataList::FindAppNameLC
   370 // --------------------------------------------------------------------------
   205 // --------------------------------------------------------------------------
   371 //
   206 //
   372 HBufC* CTsFswDataList::FindAppNameLC( CApaWindowGroupName* aWindowName,
   207 HBufC* CTsFswDataList::FindAppNameLC(CApaWindowGroupName* windowName, const TUid& appUid, TInt wgId)
   373                                   const TUid& aAppUid,
   208 {
   374                                   TInt aWgId )
       
   375     {
       
   376     //Retrieve the app name
   209     //Retrieve the app name
   377     TApaAppInfo info;
   210     TApaAppInfo info;
   378     iAppArcSession.GetAppInfo( info, aAppUid );
   211     mAppArcSession.GetAppInfo(info, appUid);
   379     TPtrC caption = info.iShortCaption;
   212     TPtrC caption = info.iShortCaption;
   380 
   213 
   381     HBufC* tempName = 0;
   214     HBufC* tempName = 0;
   382     if ( !caption.Length() && aWindowName ) // if not set - use thread name instead
   215     if (!caption.Length() && windowName) // if not set - use thread name instead
   383         {
   216     {
   384         if ( aWindowName->Caption().Length() )
   217         if (windowName->Caption().Length()) {
   385             {
   218             tempName = windowName->Caption().AllocL();
   386             tempName = aWindowName->Caption().AllocL();
       
   387             //put on cleanupstack after the if
   219             //put on cleanupstack after the if
   388             }
   220         }
   389         else
   221         else {
   390             {
       
   391             TThreadId threadId;
   222             TThreadId threadId;
   392             TInt err = iWsSession.GetWindowGroupClientThreadId(
   223             TInt err = mWsSession.GetWindowGroupClientThreadId(wgId, threadId);
   393                     aWgId, threadId );
   224             if (err == KErrNone) {
   394             if ( err == KErrNone )
       
   395                 {
       
   396                 RThread thread;
   225                 RThread thread;
   397                 CleanupClosePushL( thread );
   226                 CleanupClosePushL(thread);
   398                 err = thread.Open ( threadId );
   227                 err = thread.Open(threadId);
   399                 if ( err==KErrNone )
   228                 if (err == KErrNone) {
   400                     {
       
   401                     tempName = thread.Name().AllocL(); // codescanner::forgottoputptroncleanupstack
   229                     tempName = thread.Name().AllocL(); // codescanner::forgottoputptroncleanupstack
   402                     // tempName put on cleanupstack after the if
   230                     // tempName put on cleanupstack after the if
   403                     }
       
   404                 CleanupStack::PopAndDestroy( &thread );
       
   405                 }
   231                 }
       
   232                 CleanupStack::PopAndDestroy(&thread);
   406             }
   233             }
   407         }
   234         }
   408     else
   235     }
   409         {
   236     else {
   410         tempName = caption.AllocL();
   237         tempName = caption.AllocL();
   411         //put on cleanupstack after the if
   238         //put on cleanupstack after the if
   412         }
   239     }
   413     CleanupStack::PushL( tempName );
   240     CleanupStack::PushL(tempName);
   414     return tempName;
   241     return tempName;
   415     }
   242 }
   416 
       
   417 
   243 
   418 // --------------------------------------------------------------------------
   244 // --------------------------------------------------------------------------
   419 // CTsFswDataList::FitDataToListL
   245 // CTsFswDataList::FitDataToListL
   420 // --------------------------------------------------------------------------
   246 // --------------------------------------------------------------------------
   421 //
   247 //
   422 TBool CTsFswDataList::FitDataToListL(RTsFswArray& aListToFit,
   248 TBool CTsFswDataList::FitDataToListL(RTsFswArray& listToFit)
   423         TBool /*aConsiderWidgets*/)
   249 {
   424     {
       
   425     TBool changed = EFalse;
   250     TBool changed = EFalse;
   426     TInt listCount = aListToFit.Count();
   251     TInt listCount = listToFit.Count();
   427     TInt dataCount = iData.Count();
   252     TInt dataCount = mData.Count();
   428     
       
   429 
   253 
   430     //remove items that dont't exists in newly collected list      
   254     //remove items that dont't exists in newly collected list      
   431     for (TInt i = dataCount -1; i >= 0; --i)
   255     for (TInt i = dataCount - 1; i >= 0; --i) {
   432           {
   256         if (!CheckIfExists(*mData[i], listToFit)) {
   433           if ( !CheckIfExists(*iData[i], aListToFit) )
   257             delete mData[i];
   434               {
   258             mData.Remove(i);
   435               delete iData[i];
   259             changed = ETrue;
   436               iData.Remove(i);
   260         }
   437               changed = ETrue;
   261     }
   438               }
   262     RArray<TTsEntryKey> allKeys;
   439           }
   263 
   440       
       
   441     //add new item at start
   264     //add new item at start
   442     //for (TInt i = 0; i < aListToFit.Count(); ++i)
   265     for (TInt i = listToFit.Count() - 1; i >= 0; --i) {
   443     for (TInt i = aListToFit.Count()-1; i >= 0; --i)
   266         allKeys.Insert(listToFit[i]->Key(), 0);
   444         {
   267         if (!CheckIfExists(*listToFit[i], mData)) {
   445         if (!CheckIfExists(*aListToFit[i], iData))
   268             mData.Insert(listToFit[i], 0);
   446             {
   269             listToFit[i] = 0;
   447             iData.Insert(aListToFit[i], 0);
       
   448             aListToFit[i] = 0;
       
   449             changed = ETrue;
   270             changed = ETrue;
   450             }
   271         }
   451         }
   272     }
   452     changed = changed || iOrderChanged;
   273     //establish order
   453     iOrderChanged = EFalse;
   274     TBool orderChanged = EstablishOrder(allKeys);
       
   275     changed = changed || orderChanged;
       
   276     allKeys.Close();
   454     return changed;
   277     return changed;
   455     }
   278 }
   456 
   279 
   457 // --------------------------------------------------------------------------
   280 // --------------------------------------------------------------------------
   458 // CTsFswDataList::CheckIfExists
   281 // CTsFswDataList::CheckIfExists
   459 // --------------------------------------------------------------------------
   282 // --------------------------------------------------------------------------
   460 //
   283 //
   461 TBool CTsFswDataList::CheckIfExists(const CTsFswEntry& aEntry,
   284 TBool CTsFswDataList::CheckIfExists(const CTsFswEntry& entry, const RTsFswArray& list) const
   462         const RTsFswArray& aList) const
   285 {
   463     {
       
   464     TBool exists(EFalse);
   286     TBool exists(EFalse);
   465     TInt dataCount = aList.Count();
   287     TTsEntryKey key;
   466     for (TInt entryIdx = 0; entryIdx < dataCount; ++entryIdx)
   288     TInt pos = FindEntry(list, entry.Key());
   467         {
   289     if (pos >= 0) {
   468         if (aList[entryIdx]->AppUid() == aEntry.AppUid())
   290         exists = ETrue;
   469             {
   291     }
   470             exists = ETrue;
       
   471             break;
       
   472             }
       
   473         }
       
   474     return exists;
   292     return exists;
   475     }
   293 }
   476 
       
   477 // --------------------------------------------------------------------------
       
   478 // CTsFswDataList::AppUidForWgId
       
   479 // --------------------------------------------------------------------------
       
   480 //
       
   481 TInt CTsFswDataList::AppUidForWgId( TInt aWgId, TUid& aUid )
       
   482     {
       
   483 	TRAPD(err, aUid = AppUidForWgIdL( aWgId ) );
       
   484 	return err;
       
   485     }
       
   486 
       
   487 // --------------------------------------------------------------------------
       
   488 // CTsFswDataList::AppUidForWgIdL
       
   489 // --------------------------------------------------------------------------
       
   490 //
       
   491 TUid CTsFswDataList::AppUidForWgIdL( TInt aWgId )
       
   492     {
       
   493     CApaWindowGroupName* windowName =
       
   494         CApaWindowGroupName::NewLC( iWsSession, aWgId );
       
   495     TUid appUid = windowName->AppUid();
       
   496     CleanupStack::PopAndDestroy( windowName );
       
   497     return appUid;
       
   498     }
       
   499 
   294 
   500 // --------------------------------------------------------------------------
   295 // --------------------------------------------------------------------------
   501 // CTsFswDataList::GetAppIconL
   296 // CTsFswDataList::GetAppIconL
   502 // --------------------------------------------------------------------------
   297 // --------------------------------------------------------------------------
   503 //
   298 //
   504 void CTsFswDataList::GetAppIconL( const TUid& aAppUid,
   299 void CTsFswDataList::GetAppIconL(const TUid& aAppUid, CFbsBitmap*& bitmapArg, CFbsBitmap*& maskArg)
   505         CFbsBitmap*& aBitmap, CFbsBitmap*& aMask )
   300 {
   506     {
   301     bitmapArg = maskArg = NULL;
   507     aBitmap = aMask = NULL;
   302 
   508 
   303     TSize size(KAppIconWidth, KAppIconHeight);
   509     TSize size( KAppIconWidth, KAppIconHeight );
       
   510     CApaMaskedBitmap* apaMaskedBitmap = CApaMaskedBitmap::NewLC();
   304     CApaMaskedBitmap* apaMaskedBitmap = CApaMaskedBitmap::NewLC();
   511     TInt err = iAppArcSession.GetAppIcon( aAppUid, size, *apaMaskedBitmap );
   305     TInt err = mAppArcSession.GetAppIcon(aAppUid, size, *apaMaskedBitmap);
   512     TInt iconsCount(0);
   306     TInt iconsCount(0);
   513     if ( err == KErrNone )
   307     if (err == KErrNone) {
   514         {
   308         err = mAppArcSession.NumberOfOwnDefinedIcons(aAppUid, iconsCount);
   515         err = iAppArcSession.NumberOfOwnDefinedIcons(aAppUid, iconsCount);
   309     }
   516         }
   310 
   517     
   311     if ((err == KErrNone) && (iconsCount > 0)) {
   518     if ( (err == KErrNone) && (iconsCount>0) )
   312         bitmapArg = static_cast<CFbsBitmap*> (apaMaskedBitmap);
   519         {
       
   520         aBitmap = static_cast<CFbsBitmap*>(apaMaskedBitmap);
       
   521         TInt maskHandle = apaMaskedBitmap->Mask()->Handle();
   313         TInt maskHandle = apaMaskedBitmap->Mask()->Handle();
   522         aMask = new (ELeave) CFbsBitmap;
   314         maskArg = new (ELeave) CFbsBitmap;
   523         aMask->Duplicate( maskHandle );
   315         maskArg->Duplicate(maskHandle);
   524         CleanupStack::Pop( apaMaskedBitmap );
   316         CleanupStack::Pop(apaMaskedBitmap);
   525         }
   317     }
   526     else
   318     else {
   527         {
   319         CleanupStack::PopAndDestroy(apaMaskedBitmap);
   528         CleanupStack::PopAndDestroy( apaMaskedBitmap );
       
   529         HBufC* fileNameFromApparc = NULL;
   320         HBufC* fileNameFromApparc = NULL;
   530         TInt err = iAppArcSession.GetAppIcon(aAppUid,fileNameFromApparc);        
   321         TInt err = mAppArcSession.GetAppIcon(aAppUid, fileNameFromApparc);
   531         if ( err == KErrNone ) 
   322         if (err == KErrNone) {
   532             {
       
   533             CleanupStack::PushL(fileNameFromApparc);
   323             CleanupStack::PushL(fileNameFromApparc);
   534             CFbsBitmap *bitamp(0);
   324             CFbsBitmap *bitamp(0);
   535             CFbsBitmap *mask(0);
   325             CFbsBitmap *mask(0);
   536             TInt bitmapIndex = 0;
   326             TInt bitmapIndex = 0;
   537             TInt maskIndex = 1;    
   327             TInt maskIndex = 1;
   538             // it will change bitmap ids if it is mif (checking inside)
   328             // it will change bitmap ids if it is mif (checking inside)
   539             AknIconUtils::ValidateLogicalAppIconId( *fileNameFromApparc, bitmapIndex, maskIndex );
   329             AknIconUtils::ValidateLogicalAppIconId(*fileNameFromApparc, bitmapIndex, maskIndex);
   540             AknIconUtils::CreateIconLC( bitamp, mask, fileNameFromApparc->Des(), bitmapIndex, maskIndex );
   330             AknIconUtils::CreateIconLC(bitamp, mask, fileNameFromApparc->Des(), bitmapIndex,
   541 
   331                 maskIndex);
   542             if (AknIconUtils::IsMifFile(*fileNameFromApparc)) \
   332 
   543                 {
   333             if (AknIconUtils::IsMifFile(*fileNameFromApparc)) {
   544                 AknIconUtils::DisableCompression(bitamp);
   334                 AknIconUtils::DisableCompression(bitamp);
   545                 AknIconUtils::SetSize(bitamp, TSize(KAppIconWidth, KAppIconHeight), EAspectRatioPreservedAndUnusedSpaceRemoved);                                
   335                 AknIconUtils::SetSize(bitamp, TSize(KAppIconWidth, KAppIconHeight),
       
   336                     EAspectRatioPreservedAndUnusedSpaceRemoved);
   546                 // bitmap and icon, AknsUtils::CreateIconLC doesn't specify the order
   337                 // bitmap and icon, AknsUtils::CreateIconLC doesn't specify the order
   547                 CleanupStack::Pop(2);                  
   338                 CleanupStack::Pop(2);
   548                 aBitmap = bitamp;
   339                 bitmapArg = bitamp;
   549                 aMask = mask;
   340                 maskArg = mask;
   550                 }
   341             }
   551             else
   342             else {
   552                 {
   343                 CleanupStack::PopAndDestroy(2);
   553                 CleanupStack::PopAndDestroy(2);                       
   344             }
   554                 }
       
   555             CleanupStack::PopAndDestroy(fileNameFromApparc);
   345             CleanupStack::PopAndDestroy(fileNameFromApparc);
   556             }
   346         }
   557         }
   347     }
   558     }
   348 }
   559 
   349 
   560 // --------------------------------------------------------------------------
   350 // --------------------------------------------------------------------------
   561 // CTsFswDataList::GetAppIconL
   351 // CTsFswDataList::GetAppIconL
   562 // --------------------------------------------------------------------------
   352 // --------------------------------------------------------------------------
   563 //
   353 //
   564 TBool CTsFswDataList::IsHiddenUid( TUid aUid )
   354 TBool CTsFswDataList::IsHiddenUid(TUid uid)
   565     {
   355 {
   566     TInt result = iHiddenUids.Find( aUid );
   356     TInt result = mHiddenUids.Find(uid);
   567     return result >= 0 ? ETrue : EFalse;
   357     return result >= 0 ? ETrue : EFalse;
   568     }
   358 }
       
   359 
       
   360 // --------------------------------------------------------------------------
       
   361 // CTsFswDataList::FindEntry
       
   362 // --------------------------------------------------------------------------
       
   363 //
       
   364 TInt CTsFswDataList::FindEntry(const RTsFswArray& list, const TTsEntryKey& key) const
       
   365 {
       
   366     TInt pos(KErrNotFound);
       
   367     TInt dataCount = list.Count();
       
   368     for (TInt entryIdx = 0; entryIdx < dataCount; ++entryIdx) {
       
   369         if (list[entryIdx]->Key() == key) {
       
   370             pos = entryIdx;
       
   371             break;
       
   372         }
       
   373     }
       
   374     return pos;
       
   375 }
       
   376 
       
   377 // --------------------------------------------------------------------------
       
   378 // CTsFswDataList::SetScreenshotL
       
   379 // --------------------------------------------------------------------------
       
   380 //
       
   381 TBool CTsFswDataList::SetScreenshotL(const CFbsBitmap* bitmap, UpdatePriority priority, TInt wgId)
       
   382 {
       
   383     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
       
   384     CleanupClosePushL(allWgIds);
       
   385     User::LeaveIfError(mWsSession.WindowGroupList(0, &allWgIds));
       
   386     TTsEntryKey key = TsEntryKeyGeneraror::GenerateL(wgId, allWgIds.Array());
       
   387     TInt pos = FindEntry(mData, key);
       
   388     TBool updated(EFalse);
       
   389     if (pos >= 0) {
       
   390         updated = mData[pos]->SetScreenshotL(bitmap, priority);
       
   391     }
       
   392     else {
       
   393         User::Leave(KErrNotFound);
       
   394     }
       
   395     CleanupStack::PopAndDestroy(&allWgIds);
       
   396     return updated;
       
   397 }
       
   398 
       
   399 // --------------------------------------------------------------------------
       
   400 // CTsFswDataList::RemoveScreenshotL
       
   401 // --------------------------------------------------------------------------
       
   402 //
       
   403 TBool CTsFswDataList::RemoveScreenshotL(TInt wgId)
       
   404 {
       
   405     RArray<RWsSession::TWindowGroupChainInfo> allWgIds;
       
   406     CleanupClosePushL(allWgIds);
       
   407     User::LeaveIfError(mWsSession.WindowGroupList(0, &allWgIds));
       
   408     TTsEntryKey key = TsEntryKeyGeneraror::GenerateL(wgId, allWgIds.Array());
       
   409     TInt pos = FindEntry(mData, key);
       
   410     TBool updated(EFalse);
       
   411     if (pos >= 0) {
       
   412         updated = mData[pos]->RemoveScreenshot();
       
   413     }
       
   414     else {
       
   415         User::Leave(KErrNotFound);
       
   416     }
       
   417     CleanupStack::PopAndDestroy(&allWgIds);
       
   418     return updated;
       
   419 }
       
   420 
       
   421 // --------------------------------------------------------------------------
       
   422 // CTsFswDataList::EstablishOrder
       
   423 // --------------------------------------------------------------------------
       
   424 //
       
   425 TBool CTsFswDataList::EstablishOrder(const RArray<TTsEntryKey>& keyList)
       
   426 {
       
   427     TBool changed(EFalse);
       
   428     __ASSERT_ALWAYS(mData.Count() == keyList.Count(), User::Panic(_L("EstablishOrder 1"), KErrBadHandle) );
       
   429     for (TInt i = 0; i < keyList.Count(); i++) {
       
   430         const TTsEntryKey& currentdataKey = mData[i]->Key();
       
   431         const TTsEntryKey& referenceKey = keyList[i];
       
   432         if (!(currentdataKey == referenceKey)) {
       
   433             TInt foundPos = FindEntry(mData, referenceKey);
       
   434             __ASSERT_ALWAYS(foundPos>=0, User::Panic(_L("EstablishOrder 2"), KErrBadHandle) );
       
   435             CTsFswEntry* entry = mData[foundPos];
       
   436             mData.Remove(foundPos);
       
   437             mData.Insert(entry, i);
       
   438             changed = ETrue;
       
   439         }
       
   440     }
       
   441     return changed;
       
   442 }
       
   443 
       
   444 // --------------------------------------------------------------------------
       
   445 // CTsFswDataList::GetAllowedUidsL
       
   446 // --------------------------------------------------------------------------
       
   447 //
       
   448 void CTsFswDataList::GetAllowedUidsL()
       
   449 {
       
   450     mAllowedUids.Close();
       
   451     TApaAppInfo* appInfo = new (ELeave) TApaAppInfo();
       
   452     CleanupStack::PushL(appInfo);
       
   453     TApaAppCapabilityBuf appCap;
       
   454 
       
   455     User::LeaveIfError(mAppArcSession.GetAllApps(0));
       
   456     // for every application get uid, hidden and missing attribute
       
   457     // and add to aArray.
       
   458     while (KErrNone == mAppArcSession.GetNextApp(*appInfo)) {
       
   459         TUid uid = appInfo->iUid;
       
   460         User::LeaveIfError(mAppArcSession.GetAppCapability(appCap, uid));
       
   461         // do not add hidden app and with null uid.
       
   462         if (!appCap().iAppIsHidden && !IsHiddenUid(uid) && uid.iUid) {
       
   463             mAllowedUids.AppendL(uid);
       
   464         }
       
   465     }
       
   466     CleanupStack::PopAndDestroy(appInfo);
       
   467 }
   569 
   468 
   570 // end of file
   469 // end of file