coreapplicationuis/SysAp/Src/SysApTaskList.cpp
changeset 48 2222076f5c60
equal deleted inserted replaced
40:951aeeb3da43 48:2222076f5c60
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 #include "SysApTaskList.h"
       
    18 #include <apgwgnam.h>
       
    19 
       
    20 CSysApTaskList* CSysApTaskList::NewL(RWsSession& aWsSession)
       
    21 	{
       
    22 	CSysApTaskList* self = NewLC(aWsSession);
       
    23 	CleanupStack::Pop(self);
       
    24 	return self;
       
    25 	}
       
    26 
       
    27  CSysApTaskList* CSysApTaskList::NewLC(RWsSession& aWsSession)
       
    28 	{
       
    29 	CSysApTaskList* self = new(ELeave) CSysApTaskList(aWsSession);
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL();
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 CSysApTaskList::CSysApTaskList(RWsSession& aWsSession)
       
    36 : iWs(aWsSession)
       
    37 	{
       
    38 	}
       
    39 
       
    40 void CSysApTaskList::ConstructL()
       
    41 	{
       
    42 	UpdateListL();
       
    43 	}
       
    44 
       
    45  CSysApTaskList::~CSysApTaskList()
       
    46 	{
       
    47 	iWgs.Close();
       
    48 	}
       
    49 
       
    50  void CSysApTaskList::UpdateListL()
       
    51 	{
       
    52 	User::LeaveIfError(iWs.WindowGroupList(0, &iWgs));
       
    53 	}
       
    54 
       
    55  const RArray<RWsSession::TWindowGroupChainInfo>& CSysApTaskList::WgArray() const
       
    56 	{
       
    57 	return iWgs;
       
    58 	}
       
    59 
       
    60  TApaTask CSysApTaskList::FindRootApp(TUid aAppUid) const
       
    61 	{
       
    62 	TApaTask task(iWs);
       
    63 	task.SetWgId(0);		// initialise task to non-existant task
       
    64 	// wgId = 0 tells FindAppByUid to start looking for apps
       
    65 	TInt wgId=0;
       
    66 	FOREVER
       
    67 		{
       
    68 	 	CApaWindowGroupName::FindByAppUid(aAppUid, iWs, wgId);
       
    69 	 	// KErrNotFound means that no more apps can be found
       
    70 	 	if (wgId == KErrNotFound)
       
    71 	 		break;
       
    72 	 	if (IsRootWindowGroup(wgId))
       
    73 	 		{
       
    74 	 		// Found a root wg with the right app UID, return it.
       
    75 	 		task.SetWgId(wgId);
       
    76 	 		break;
       
    77 	 		}
       
    78 		}
       
    79 	return task;
       
    80 	}
       
    81 
       
    82  TBool CSysApTaskList::IsRootWindowGroup(TInt aWgId) const
       
    83 	{
       
    84 	TInt count = iWgs.Count();
       
    85 	for (TInt ii=0; ii<count; ii++)
       
    86 		{
       
    87         const RWsSession::TWindowGroupChainInfo& info = iWgs[ii];
       
    88         // find the window group id and check that it has no parent
       
    89         if (info.iId == aWgId)
       
    90         	return (info.iParentId <= 0);
       
    91 		}
       
    92 	return EFalse;
       
    93 	}
       
    94 
       
    95  TInt CSysApTaskList::FindParentWgId(TInt aWgId) const
       
    96 	{
       
    97 	TInt count = iWgs.Count();
       
    98 	for (TInt ii=0; ii<count; ii++)
       
    99 		{
       
   100         const RWsSession::TWindowGroupChainInfo& info = iWgs[ii];
       
   101         if (info.iId == aWgId && info.iParentId > 0 && info.iParentId != info.iId)
       
   102         	return info.iParentId;
       
   103 		}
       
   104 	return 0;
       
   105 	}
       
   106 
       
   107  TInt CSysApTaskList::FindChildWgId(TInt aWgId) const
       
   108 	{
       
   109 	TInt count = iWgs.Count();
       
   110 	for (TInt ii=0; ii<count; ii++)
       
   111 		{
       
   112         const RWsSession::TWindowGroupChainInfo& info = iWgs[ii];
       
   113         if (info.iParentId == aWgId && info.iId > 0 && info.iParentId != info.iId)
       
   114         	return info.iId;
       
   115 		}
       
   116 	return 0;
       
   117 	}
       
   118 
       
   119 
       
   120 
       
   121 
       
   122