125
|
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 |
|
|
19 |
#include "tswindowgroupsmonitorimp.h"
|
|
20 |
#include "tsrunningappstorageimp.h"
|
|
21 |
#include "tsresourcemanager.h"
|
127
|
22 |
#include "tsvisibilitymsg.h"
|
125
|
23 |
|
|
24 |
const int KOrdinalPositionNoZOrder(-1);
|
|
25 |
// -----------------------------------------------------------------------------
|
|
26 |
//
|
|
27 |
// -----------------------------------------------------------------------------
|
|
28 |
//
|
|
29 |
CTsWindowGroupsMonitor* CTsWindowGroupsMonitor::NewL(MTsResourceManager &resources)
|
|
30 |
{
|
|
31 |
CTsWindowGroupsMonitor* self = new (ELeave) CTsWindowGroupsMonitor(resources);
|
|
32 |
CleanupStack::PushL(self);
|
|
33 |
self->ConstructL();
|
|
34 |
CleanupStack::Pop(self);
|
|
35 |
return self;
|
|
36 |
}
|
|
37 |
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
// -----------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
CTsWindowGroupsMonitor::CTsWindowGroupsMonitor(MTsResourceManager &resources)
|
|
43 |
:
|
|
44 |
CActive(EPriorityStandard),
|
|
45 |
iResources(resources)
|
|
46 |
{
|
|
47 |
CActiveScheduler::Add(this);
|
|
48 |
}
|
|
49 |
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
void CTsWindowGroupsMonitor::ConstructL()
|
|
55 |
{
|
|
56 |
|
|
57 |
// Initial window group
|
|
58 |
iWg = RWindowGroup (iResources.WsSession());
|
|
59 |
User::LeaveIfError (iWg.Construct ((TUint32)&iWg, EFalse));
|
|
60 |
iWg.SetOrdinalPosition (KOrdinalPositionNoZOrder);
|
|
61 |
iWg.EnableReceiptOfFocus (EFalse);
|
|
62 |
|
|
63 |
// Hide window
|
|
64 |
CApaWindowGroupName* wn = CApaWindowGroupName::NewLC(iResources.WsSession());
|
|
65 |
wn->SetHidden (ETrue);
|
|
66 |
wn->SetWindowGroupName (iWg);
|
|
67 |
CleanupStack::PopAndDestroy (wn);
|
|
68 |
|
|
69 |
// Window group change event
|
|
70 |
User::LeaveIfError (iWg.EnableGroupListChangeEvents());
|
127
|
71 |
|
|
72 |
iCache = CTsRunningAppStorage::NewL();
|
|
73 |
RefreshCacheL();
|
125
|
74 |
Subscribe();
|
|
75 |
}
|
|
76 |
|
|
77 |
// -----------------------------------------------------------------------------
|
|
78 |
//
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
CTsWindowGroupsMonitor::~CTsWindowGroupsMonitor()
|
127
|
82 |
{
|
125
|
83 |
CActive::Cancel();
|
|
84 |
iWg.Close();
|
127
|
85 |
}
|
125
|
86 |
|
|
87 |
// -----------------------------------------------------------------------------
|
|
88 |
//
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
void CTsWindowGroupsMonitor::SubscribeL(MTsWindowGroupsObserver &observer)
|
127
|
92 |
{
|
|
93 |
if(KErrNotFound != iObservers.Find(&observer))
|
|
94 |
{
|
|
95 |
User::Leave(KErrAlreadyExists);
|
|
96 |
}
|
|
97 |
iObservers.InsertL(&observer, 0);
|
|
98 |
observer.HandleWindowGroupChanged(iResources, *iCache);
|
|
99 |
}
|
125
|
100 |
|
|
101 |
// -----------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
// -----------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
void CTsWindowGroupsMonitor::Cancel(MTsWindowGroupsObserver & observer)
|
127
|
106 |
{
|
125
|
107 |
const TInt offset(iObservers.Find(&observer));
|
127
|
108 |
if(KErrNotFound != offset)
|
|
109 |
{
|
125
|
110 |
iObservers.Remove(offset);
|
127
|
111 |
}
|
125
|
112 |
}
|
127
|
113 |
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
/**
|
|
116 |
* @see MTsWindowGroupsMonitor::Storage
|
|
117 |
*/
|
|
118 |
const MTsRunningApplicationStorage& CTsWindowGroupsMonitor::Storage() const
|
|
119 |
{
|
|
120 |
return *iCache;
|
|
121 |
}
|
|
122 |
// -----------------------------------------------------------------------------
|
|
123 |
TBool CTsWindowGroupsMonitor::IsSupported(TInt aFunction) const
|
|
124 |
{
|
|
125 |
return ( VisibilityChange == aFunction );
|
|
126 |
}
|
|
127 |
|
|
128 |
// -----------------------------------------------------------------------------
|
|
129 |
void CTsWindowGroupsMonitor::HandleDataL(TInt aFunction, RReadStream& aDataStream)
|
|
130 |
{
|
|
131 |
if(VisibilityChange == aFunction)
|
|
132 |
{
|
|
133 |
CTsVisibilitMsg* msg = CTsVisibilitMsg::NewLC(aDataStream);
|
|
134 |
const TBool hide (Invisible == msg->visibility());
|
|
135 |
bool changed = false;
|
|
136 |
for(TInt offset(0); offset < iCache->Count(); ++offset)
|
|
137 |
{
|
|
138 |
if( msg->windowGroupId() == (*iCache)[offset].WindowGroupId() )
|
|
139 |
{
|
|
140 |
(*iCache)[offset].SetHidden(hide);
|
|
141 |
offset = iCache->Count();
|
|
142 |
changed = true;
|
|
143 |
}
|
|
144 |
}
|
|
145 |
if(changed)
|
|
146 |
{
|
|
147 |
for( TInt iter(0); iter < iObservers.Count(); ++iter )
|
|
148 |
{
|
|
149 |
iObservers[iter]->HandleWindowGroupChanged( iResources, *iCache );
|
|
150 |
}
|
|
151 |
}
|
|
152 |
CleanupStack::PopAndDestroy(msg);
|
|
153 |
}
|
125
|
154 |
}
|
|
155 |
|
|
156 |
// -----------------------------------------------------------------------------
|
|
157 |
//
|
|
158 |
// -----------------------------------------------------------------------------
|
|
159 |
//
|
|
160 |
void CTsWindowGroupsMonitor::RunL()
|
|
161 |
{
|
|
162 |
User::LeaveIfError(iStatus.Int());
|
|
163 |
ProvideEventL();
|
|
164 |
Subscribe();
|
|
165 |
}
|
|
166 |
|
|
167 |
// -----------------------------------------------------------------------------
|
|
168 |
//
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
void CTsWindowGroupsMonitor::DoCancel()
|
|
172 |
{
|
|
173 |
if (IsActive()) {
|
|
174 |
iResources.WsSession().EventReadyCancel();
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
|
178 |
// -----------------------------------------------------------------------------
|
|
179 |
//
|
|
180 |
// -----------------------------------------------------------------------------
|
|
181 |
//
|
|
182 |
TInt CTsWindowGroupsMonitor::RunError(TInt error)
|
|
183 |
{
|
|
184 |
if (!IsActive() && KErrCancel != error) {
|
|
185 |
Subscribe();
|
|
186 |
}
|
|
187 |
return KErrNone;
|
|
188 |
}
|
|
189 |
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
//
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
//
|
|
194 |
void CTsWindowGroupsMonitor::Subscribe()
|
|
195 |
{
|
|
196 |
iResources.WsSession().EventReady( &iStatus );
|
|
197 |
SetActive();
|
|
198 |
}
|
|
199 |
|
|
200 |
// -----------------------------------------------------------------------------
|
|
201 |
void CTsWindowGroupsMonitor::ProvideEventL()
|
127
|
202 |
{
|
125
|
203 |
TWsEvent wsEvent;
|
|
204 |
iResources.WsSession().GetEvent(wsEvent);
|
|
205 |
if( EEventWindowGroupListChanged == wsEvent.Type() )
|
|
206 |
{
|
127
|
207 |
RefreshCacheL();
|
125
|
208 |
}
|
127
|
209 |
}
|
|
210 |
|
|
211 |
// -----------------------------------------------------------------------------
|
|
212 |
void CTsWindowGroupsMonitor::RefreshCacheL()
|
|
213 |
{
|
|
214 |
RArray<RWsSession::TWindowGroupChainInfo> filteredWgInfo, fullWgInfo;
|
|
215 |
CleanupClosePushL(filteredWgInfo);
|
|
216 |
CleanupClosePushL(fullWgInfo);
|
|
217 |
User::LeaveIfError(iResources.WsSession().WindowGroupList(0, &filteredWgInfo));
|
|
218 |
User::LeaveIfError(iResources.WsSession().WindowGroupList(&fullWgInfo));
|
|
219 |
iCache->HandleWindowGroupChanged(iResources,
|
|
220 |
fullWgInfo.Array(),
|
|
221 |
filteredWgInfo.Array());
|
|
222 |
CleanupStack::PopAndDestroy( &fullWgInfo );
|
|
223 |
CleanupStack::PopAndDestroy( &filteredWgInfo );
|
|
224 |
|
|
225 |
for( TInt iter(0); iter < iObservers.Count(); ++iter )
|
|
226 |
{
|
|
227 |
iObservers[iter]->HandleWindowGroupChanged( iResources, *iCache );
|
|
228 |
}
|
|
229 |
}
|