|
1 /* |
|
2 * Copyright (c) 2008 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 #include <apgtask.h> |
|
20 #include <WidgetRegistryClient.h> |
|
21 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
22 |
|
23 #include "mcsrunningappswgmonitor.h" |
|
24 #include "mcsrunningappshandler.h" |
|
25 #include "menueng.h" |
|
26 |
|
27 // --------------------------------------------------------- |
|
28 // CMcsRunningAppsWgMonitor::NewL |
|
29 // --------------------------------------------------------- |
|
30 // |
|
31 CMcsRunningAppsWgMonitor* CMcsRunningAppsWgMonitor::NewL( |
|
32 CMenuEng& aEng, MMcsRunningAppsHandler* aRunningAppsHandler, |
|
33 TInt aPriority ) |
|
34 { |
|
35 CMcsRunningAppsWgMonitor* self = |
|
36 new ( ELeave ) CMcsRunningAppsWgMonitor( aEng, aRunningAppsHandler, |
|
37 aPriority ); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------- |
|
45 // CMcsRunningAppsWgMonitor::~CWindowGroupChangeMonitor |
|
46 // --------------------------------------------------------- |
|
47 // |
|
48 CMcsRunningAppsWgMonitor::~CMcsRunningAppsWgMonitor() |
|
49 { |
|
50 Cancel(); |
|
51 iEng.DequeueOperation( *this ); |
|
52 iRunningApps.Close(); |
|
53 delete iWgName; |
|
54 iWg.Close(); |
|
55 iWidgetSession.Close(); |
|
56 iWsSession.Close(); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CMcsRunningAppsWgMonitor::CMcsRunningAppsWgMonitor |
|
61 // --------------------------------------------------------- |
|
62 // |
|
63 CMcsRunningAppsWgMonitor::CMcsRunningAppsWgMonitor( |
|
64 CMenuEng& aEng, MMcsRunningAppsHandler* aRunningAppsHandler, |
|
65 TInt aPriority ): |
|
66 CActive( aPriority ), |
|
67 iEng(aEng), |
|
68 iRunningAppsHandler(aRunningAppsHandler) |
|
69 { |
|
70 CActiveScheduler::Add( this ); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------- |
|
74 // CMcsRunningAppsWgMonitor::ConstructL |
|
75 // --------------------------------------------------------- |
|
76 // |
|
77 void CMcsRunningAppsWgMonitor::ConstructL() |
|
78 { |
|
79 iOperationInProgress = EFalse; |
|
80 User::LeaveIfError( iWsSession.Connect() ); |
|
81 User::LeaveIfError( iWidgetSession.Connect() ); |
|
82 |
|
83 iWg = RWindowGroup( iWsSession ); |
|
84 |
|
85 // Make a handle from the address of window group obj. |
|
86 User::LeaveIfError( iWg.Construct( |
|
87 reinterpret_cast<TUint32>( &iWg ) ) ); |
|
88 |
|
89 //myWindowGroup.AutoForeground( EFalse ); |
|
90 iWg.DisableFocusChangeEvents(); |
|
91 iWg.DisableModifierChangedEvents(); |
|
92 iWg.DisableOnEvents(); |
|
93 iWg.DisableScreenChangeEvents(); |
|
94 |
|
95 User::LeaveIfError( iWg.EnableGroupListChangeEvents() ); |
|
96 |
|
97 //it makes the soft keys working |
|
98 iWg.EnableReceiptOfFocus( EFalse ); |
|
99 |
|
100 iWgName = CApaWindowGroupName::NewL( iWsSession ); |
|
101 iWgName->SetSystem( ETrue ); |
|
102 iWgName->SetHidden( ETrue ); |
|
103 iWgName->SetWindowGroupName( iWg ); |
|
104 |
|
105 |
|
106 UpdateRunningApplicationsL(); |
|
107 Start(); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // CMcsRunningAppsWgMonitor::Start |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 void CMcsRunningAppsWgMonitor::Start() |
|
115 { |
|
116 if (!IsActive()) |
|
117 { |
|
118 iWsSession.EventReady( &iStatus ); |
|
119 SetActive(); |
|
120 } |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------- |
|
124 // CMcsRunningAppsWgMonitor::DoCancel |
|
125 // --------------------------------------------------------- |
|
126 // |
|
127 void CMcsRunningAppsWgMonitor::DoCancel() |
|
128 { |
|
129 iWsSession.EventReadyCancel(); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------- |
|
133 // CMcsRunningAppsWgMonitor::RunL |
|
134 // --------------------------------------------------------- |
|
135 // |
|
136 void CMcsRunningAppsWgMonitor::RunL() |
|
137 { |
|
138 User::LeaveIfError( iStatus.Int() ); // Handle errors in RunL. |
|
139 // AppArc app scan complete, we have the app list. |
|
140 // Now queue this operation to be executed by the Engine. |
|
141 |
|
142 TWsEvent event; |
|
143 iWsSession.GetEvent(event); |
|
144 Start(); |
|
145 |
|
146 if (!iOperationInProgress && |
|
147 (event.Type() == EEventWindowGroupListChanged )) |
|
148 { |
|
149 iOperationInProgress = ETrue; |
|
150 iEng.QueueOperationL( *this ); |
|
151 } |
|
152 else if ( event.Type() == EEventPowerMgmt ) |
|
153 { |
|
154 TApaSystemEvent systemEvent( *(TApaSystemEvent*)(event.EventData()) ); |
|
155 // System secure shutdown, stop server |
|
156 if ( systemEvent == EApaSystemEventSecureShutdown ) |
|
157 { |
|
158 CActiveScheduler::Stop(); |
|
159 } |
|
160 } |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------- |
|
164 // CMcsRunningAppsWgMonitor::RunError() |
|
165 // --------------------------------------------------------- |
|
166 // |
|
167 TInt CMcsRunningAppsWgMonitor::RunError( TInt /*aError*/ ) |
|
168 { |
|
169 Start(); |
|
170 return KErrNone; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CMcsRunningAppsWgMonitor::RunMenuEngOperationL |
|
175 // --------------------------------------------------------- |
|
176 // |
|
177 void CMcsRunningAppsWgMonitor::RunMenuEngOperationL() |
|
178 { |
|
179 iOperationInProgress = EFalse; |
|
180 UpdateRunningApplicationsL(); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------- |
|
184 // CMcsRunningAppsWgMonitor::CompletedMenuEngOperation |
|
185 // --------------------------------------------------------- |
|
186 // |
|
187 void CMcsRunningAppsWgMonitor::CompletedMenuEngOperation( TInt /*aErr*/ ) |
|
188 { |
|
189 // If there was error, ignore it (what else could we do?). |
|
190 // When next AppArc update occurs, we will run again. |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------- |
|
194 // CMcsRunningAppsWgMonitor::UpdateRunningApplicationsL |
|
195 // --------------------------------------------------------- |
|
196 // |
|
197 void CMcsRunningAppsWgMonitor::UpdateRunningApplicationsL() |
|
198 { |
|
199 iRunningApps.Reset(); |
|
200 |
|
201 RArray<RWsSession::TWindowGroupChainInfo> windowGroupIds; |
|
202 CleanupClosePushL( windowGroupIds ); |
|
203 |
|
204 User::LeaveIfError( iWsSession.WindowGroupList(0, &windowGroupIds) ); |
|
205 const TInt count = windowGroupIds.Count(); |
|
206 |
|
207 for (TInt i=0; i<count; i++) |
|
208 { |
|
209 TInt wgId = windowGroupIds[i].iId; |
|
210 iWgName->ConstructFromWgIdL(wgId); |
|
211 |
|
212 // find the window group id and check that it has no parent |
|
213 if (windowGroupIds[i].iParentId <= 0) |
|
214 { |
|
215 TUid appUid = iWgName->AppUid(); |
|
216 if ( ( appUid.iUid ) && |
|
217 ( iRunningApps.Find( appUid ) == KErrNotFound )) |
|
218 { |
|
219 iRunningApps.AppendL( appUid ); |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 CleanupStack::PopAndDestroy( &windowGroupIds ); |
|
225 |
|
226 UpdateWidgetTaskListL(); |
|
227 |
|
228 iRunningAppsHandler->HandleListUpdateL( iRunningApps, |
|
229 MMcsRunningAppsHandler::ERunningApps ); |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------- |
|
233 // CMcsRunningAppsWgMonitor::UpdateWidgetTaskListL |
|
234 // --------------------------------------------------------- |
|
235 // |
|
236 void CMcsRunningAppsWgMonitor::UpdateWidgetTaskListL( ) |
|
237 { |
|
238 RWidgetInfoArray widgetInfoArr; |
|
239 CleanupResetAndDestroyPushL( widgetInfoArr ); |
|
240 |
|
241 iWidgetSession.RunningWidgetsL( widgetInfoArr ); |
|
242 |
|
243 for (TInt i=0; i<widgetInfoArr.Count(); i++) |
|
244 { |
|
245 TUid wgUid( widgetInfoArr[i]->iUid ); |
|
246 if( iWidgetSession.IsWidgetInFullView( wgUid ) ) |
|
247 { |
|
248 iRunningApps.AppendL( wgUid ); |
|
249 } |
|
250 } |
|
251 |
|
252 CleanupStack::PopAndDestroy( &widgetInfoArr ); // widgetInfoArr |
|
253 } |
|
254 // End of File |