menucontentsrv/handlersrc/menutasklist.cpp
branchRCL_3
changeset 18 bd874ee5e5e2
equal deleted inserted replaced
9:d0529222e3f0 18:bd874ee5e5e2
       
     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 
       
    18 #include <apgwgnam.h>
       
    19 
       
    20 #include "menutasklist.h"
       
    21 
       
    22 CMenuTaskList* CMenuTaskList::NewL(RWsSession& aWsSession)
       
    23     {
       
    24     CMenuTaskList* self = NewLC(aWsSession);
       
    25     CleanupStack::Pop(self);
       
    26     return self;
       
    27     }
       
    28 
       
    29 CMenuTaskList* CMenuTaskList::NewLC(RWsSession& aWsSession)
       
    30     {
       
    31     CMenuTaskList* self = new(ELeave) CMenuTaskList(aWsSession);
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL();
       
    34     return self;
       
    35     }
       
    36 
       
    37 CMenuTaskList::CMenuTaskList(RWsSession& aWsSession)
       
    38 : iWs(aWsSession)
       
    39     {
       
    40     }
       
    41 
       
    42 void CMenuTaskList::ConstructL()
       
    43     {
       
    44     UpdateListL();
       
    45     }
       
    46 
       
    47 CMenuTaskList::~CMenuTaskList()
       
    48     {
       
    49     iWgs.Close();
       
    50     }
       
    51 
       
    52 void CMenuTaskList::UpdateListL()
       
    53     {
       
    54     User::LeaveIfError(iWs.WindowGroupList(&iWgs));
       
    55     }
       
    56 
       
    57 
       
    58 TApaTask CMenuTaskList::FindRootApp(TUid aAppUid) const
       
    59     {
       
    60     TApaTask task(iWs);
       
    61     task.SetWgId(0);        // initialise task to non-existant task
       
    62     // wgId = 0 tells FindAppByUid to start looking for apps
       
    63     TInt wgId=0;
       
    64     FOREVER
       
    65         {
       
    66         CApaWindowGroupName::FindByAppUid(aAppUid, iWs, wgId);
       
    67         // KErrNotFound means that no more apps can be found
       
    68         if (wgId == KErrNotFound)
       
    69             break;
       
    70         if (IsRootWindowGroup(wgId))
       
    71             {
       
    72             // Found a root wg with the right app UID, return it.
       
    73             task.SetWgId(wgId);
       
    74             break;
       
    75             }
       
    76         }
       
    77     return task;
       
    78     }
       
    79 
       
    80 TBool CMenuTaskList::IsRootWindowGroup(TInt aWgId) const
       
    81     {
       
    82     TInt count = iWgs.Count();
       
    83     for (TInt ii=0; ii<count; ii++)
       
    84         {
       
    85         const RWsSession::TWindowGroupChainInfo& info = iWgs[ii];
       
    86         // find the window group id and check that it has no parent
       
    87         if (info.iId == aWgId)
       
    88             return (info.iParentId <= 0);
       
    89         }
       
    90     return EFalse;
       
    91     }