taskswitcher/server/src/tswindowgroupsmonitor.cpp
changeset 124 e36b2f4799c0
equal deleted inserted replaced
121:0b3699f6c654 124:e36b2f4799c0
       
     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 <apgwgnam.h>
       
    18 #include "tswindowgroupsobserver.h"
       
    19 #include "tswindowgroupsmonitor.h"
       
    20 #include "tsrunningappstorage.h"
       
    21 
       
    22 
       
    23 const int KOrdinalPositionNoZOrder(-1);
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CTsWindowGroupsMonitor* CTsWindowGroupsMonitor::NewL(MTsResourceManager &resources)
       
    29 {
       
    30     CTsWindowGroupsMonitor* self = new (ELeave) CTsWindowGroupsMonitor(resources);
       
    31     CleanupStack::PushL(self);
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop(self);
       
    34     return self;
       
    35 }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CTsWindowGroupsMonitor::CTsWindowGroupsMonitor(MTsResourceManager &resources)
       
    42 :
       
    43     CActive(EPriorityStandard),
       
    44     iResources(resources)
       
    45 {
       
    46     CActiveScheduler::Add(this);
       
    47 }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CTsWindowGroupsMonitor::ConstructL()
       
    54 {
       
    55     
       
    56     // Initial window group
       
    57     iWg = RWindowGroup (iResources.WsSession());
       
    58     User::LeaveIfError (iWg.Construct ((TUint32)&iWg, EFalse));
       
    59     iWg.SetOrdinalPosition (KOrdinalPositionNoZOrder);
       
    60     iWg.EnableReceiptOfFocus (EFalse);
       
    61     
       
    62     // Hide window
       
    63     CApaWindowGroupName* wn = CApaWindowGroupName::NewLC(iResources.WsSession());
       
    64     wn->SetHidden (ETrue);
       
    65     wn->SetWindowGroupName (iWg);
       
    66     CleanupStack::PopAndDestroy (wn);
       
    67     
       
    68     // Window group change event
       
    69     User::LeaveIfError (iWg.EnableGroupListChangeEvents());
       
    70     Subscribe();
       
    71 }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CTsWindowGroupsMonitor::~CTsWindowGroupsMonitor()
       
    78 {
       
    79     CActive::Cancel();
       
    80     iWg.Close();
       
    81 }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CTsWindowGroupsMonitor::SubscribeL(MTsWindowGroupsObserver &observer)
       
    88 {
       
    89     const TInt offset(iObservers.Find(&observer));
       
    90     KErrNotFound == offset ? iObservers.InsertL(&observer, 0) : 
       
    91                              User::Leave(KErrAlreadyExists);
       
    92 }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CTsWindowGroupsMonitor::Cancel(MTsWindowGroupsObserver & observer)
       
    99 {
       
   100     const TInt offset(iObservers.Find(&observer));
       
   101     if (KErrNotFound != offset) {
       
   102         iObservers.Remove(offset);
       
   103     }
       
   104 }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CTsWindowGroupsMonitor::RunL()
       
   111 {
       
   112     User::LeaveIfError(iStatus.Int());
       
   113     ProvideEventL();
       
   114     Subscribe();
       
   115 }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CTsWindowGroupsMonitor::DoCancel()
       
   122 {
       
   123     if (IsActive()) {
       
   124         iResources.WsSession().EventReadyCancel();
       
   125     }
       
   126 }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 TInt CTsWindowGroupsMonitor::RunError(TInt error)
       
   133 {
       
   134     if (!IsActive() && KErrCancel != error) {
       
   135         Subscribe();
       
   136     }
       
   137     return KErrNone;
       
   138 }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CTsWindowGroupsMonitor::Subscribe()
       
   145 {
       
   146     iResources.WsSession().EventReady( &iStatus );
       
   147     SetActive();
       
   148 }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CTsWindowGroupsMonitor::ProvideEventL()
       
   155 {
       
   156     TWsEvent wsEvent;
       
   157     iResources.WsSession().GetEvent(wsEvent);
       
   158     if( EEventWindowGroupListChanged == wsEvent.Type() )
       
   159         {
       
   160         
       
   161         CTsRunningAppStorage *storage = CTsRunningAppStorage::NewLC();
       
   162         
       
   163         RArray<RWsSession::TWindowGroupChainInfo> filteredWgInfo, fullWgInfo;
       
   164         CleanupClosePushL(filteredWgInfo);
       
   165         CleanupClosePushL(fullWgInfo);
       
   166         User::LeaveIfError(iResources.WsSession().WindowGroupList(0, &filteredWgInfo));
       
   167         User::LeaveIfError(iResources.WsSession().WindowGroupList(&fullWgInfo));
       
   168         storage->HandleWindowGroupChanged(iResources, 
       
   169                                           fullWgInfo.Array(), 
       
   170                                           filteredWgInfo.Array());
       
   171         CleanupStack::PopAndDestroy( &fullWgInfo );
       
   172         CleanupStack::PopAndDestroy( &filteredWgInfo );
       
   173                 
       
   174         for( TInt iter(0); iter < iObservers.Count(); ++iter ) 
       
   175             {
       
   176             iObservers[iter]->HandleWindowGroupChanged( iResources, *storage );
       
   177             }
       
   178         CleanupStack::PopAndDestroy( storage );
       
   179         
       
   180         }
       
   181 }