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 "tsbackstepping.h" |
|
19 |
|
20 #include <w32std.h>// key event |
|
21 #include <apgwgnam.h>// for CApaWindowGroupName |
|
22 #include <apgtask.h> |
|
23 #include <coedef.h> |
|
24 #include <e32property.h> |
|
25 #include <e32debug.h> |
|
26 |
|
27 #include <homescreendomainpskeys.h> |
|
28 #include <afactivitylauncher.h> |
|
29 |
|
30 #include "tsbacksteppingfilter.h" |
|
31 #include "tsrunningapp.h" |
|
32 #include "tsrunningappstorage.h" |
|
33 #include "tsresourcemanager.h" |
|
34 /** |
|
35 * String to switch hsapplication to IDLE state using activity framework |
|
36 */ |
|
37 _LIT(KHsActivactionUri, "appto://20022F35?activityname=HsIdleView&activityinbackground=true"); |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 /** |
|
41 * Symbian two-phases constructor. Allocate create and initialize backstepping engine |
|
42 * Instance is pushed int cleanup stack. |
|
43 * @param aMonitor - window group changes monitor |
|
44 * @return address to backstepping engine |
|
45 */ |
|
46 CTsBackstepping* CTsBackstepping::NewL( MTsWindowGroupsMonitor& aMonitor ) |
|
47 { |
|
48 CTsBackstepping* self = CTsBackstepping::NewLC( aMonitor ); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 /** |
|
55 * Symbian two-phases constructor. Allocate create and initialize backstepping engine |
|
56 * @param aMonitor - window group changes monitor |
|
57 * @return address to backstepping engine |
|
58 */ |
|
59 CTsBackstepping* CTsBackstepping::NewLC( MTsWindowGroupsMonitor& aMonitor ) |
|
60 { |
|
61 CTsBackstepping* self = new (ELeave) CTsBackstepping( aMonitor ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 /** |
|
69 * Constructor. |
|
70 * @param aMonitor - window group changes monitor |
|
71 */ |
|
72 CTsBackstepping::CTsBackstepping( MTsWindowGroupsMonitor &aMonitor ) |
|
73 : |
|
74 CTsWindowGroupsObserverBase( aMonitor ), iHsWasFirst(ETrue) |
|
75 { |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 /** |
|
80 * CTsBackstepping::~CTsBackstepping |
|
81 * deconstructor |
|
82 */ |
|
83 CTsBackstepping::~CTsBackstepping() |
|
84 { |
|
85 delete iFilter; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 /** |
|
90 * Symbian second-phase constructor. |
|
91 * Subscribe to window group monitor events (using BaseConstructL) and allocate |
|
92 * filtering list |
|
93 */ |
|
94 void CTsBackstepping::ConstructL () |
|
95 { |
|
96 BaseConstructL(); |
|
97 iFilter = CTsBacksteppingFilter::NewL(); |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 /** |
|
102 * Analyzes window stack and move homescreen to proper position |
|
103 * Interface implementation. |
|
104 * @see MTsWindowGroupsObserver::HandleWindowGroupChanged |
|
105 */ |
|
106 void CTsBackstepping::HandleWindowGroupChanged( |
|
107 MTsResourceManager &aResources, |
|
108 const MTsRunningApplicationStorage& aStorage ) |
|
109 |
|
110 { |
|
111 RDebug::Print(_L("[Backstepping] started")); |
|
112 TRAP_IGNORE( HandleWindowGroupChangedL( aResources, aStorage ) ); |
|
113 RDebug::Print(_L("[Backstepping] finished")); |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 /** |
|
118 * Analyzes window stack and move homescreen to proper position |
|
119 * @see MTsWindowGroupsObserver::HandleWindowGroupChanged from param info |
|
120 */ |
|
121 void CTsBackstepping::HandleWindowGroupChangedL( |
|
122 MTsResourceManager &aResources, |
|
123 const MTsRunningApplicationStorage& aStorage ) |
|
124 { |
|
125 // calculate the desired position of Homescreen |
|
126 const TInt currentHsOffset( HomescreenOffsetL( aStorage ) ); |
|
127 TInt optimalOffset(1); |
|
128 TInt targetHsOffset(currentHsOffset); |
|
129 TBool isFirst(ETrue); |
|
130 for( TInt offset(0); offset < currentHsOffset; ++offset ) |
|
131 { |
|
132 RDebug::Print( _L("[Backstepping] application: %08x"), |
|
133 aStorage[offset].UidL().iUid ); |
|
134 if( TUid::Null() != aStorage[offset].UidL() ) |
|
135 { |
|
136 isFirst = EFalse; |
|
137 if( aStorage[offset].IsEmbeded()) |
|
138 { |
|
139 targetHsOffset = aStorage.ParentIndex(aStorage[offset])+ 1; |
|
140 } |
|
141 else if (!iFilter->isBlocked( aStorage[offset].UidL() )) |
|
142 { |
|
143 if(offset + 1 < currentHsOffset && |
|
144 aStorage[offset+1].UidL() == TUid::Null() ) |
|
145 { |
|
146 ++optimalOffset; |
|
147 } |
|
148 targetHsOffset = optimalOffset; |
|
149 } |
|
150 break; |
|
151 } |
|
152 else |
|
153 { |
|
154 ++optimalOffset; |
|
155 } |
|
156 } |
|
157 SwitchToIdleStateL(aResources, isFirst); |
|
158 // change windows order if necessary |
|
159 if(targetHsOffset != currentHsOffset) |
|
160 { |
|
161 RDebug::Print(_L("[Backstepping] about to change window groups order")); |
|
162 aResources.WsSession().SetWindowGroupOrdinalPosition( |
|
163 aStorage[currentHsOffset].WindowGroupId(), |
|
164 targetHsOffset ); |
|
165 } |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 /** |
|
170 * Find and return current position of hsapplication on window server stack |
|
171 * @param aStorage - storage with running app info |
|
172 * @return position of hsapplication on window server stack |
|
173 */ |
|
174 TInt CTsBackstepping::HomescreenOffsetL( |
|
175 const MTsRunningApplicationStorage& aStorage ) const |
|
176 { |
|
177 TInt offset( KErrNotFound ); |
|
178 for( TInt iter(0); KErrNotFound == offset && iter < aStorage.Count(); ++iter ) |
|
179 { |
|
180 if( KHsCategoryUid == aStorage[iter].UidL() ) |
|
181 { |
|
182 offset = iter; |
|
183 } |
|
184 } |
|
185 User::LeaveIfError( offset ); |
|
186 return offset; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 /** |
|
191 * Change hsapplication state to IDLE if moves to background |
|
192 * @param aResources - OS resources manager |
|
193 * @param aIsFrst - flag to inform if hsapplication is in foreground |
|
194 */ |
|
195 void CTsBackstepping::SwitchToIdleStateL(MTsResourceManager& aResources, |
|
196 TBool aIsFirst) |
|
197 { |
|
198 // switch Homescreen to Idle state if Homescreen is not in foreground and is in different state |
|
199 if( iHsWasFirst && !aIsFirst ) |
|
200 { |
|
201 TInt hsState( EHomeScreenIdleState ); |
|
202 User::LeaveIfError(RProperty::Get( KHsCategoryUid, |
|
203 KHsCategoryStateKey, |
|
204 hsState ) ); |
|
205 if(!(hsState & EHomeScreenWidgetViewActive ) ) |
|
206 { |
|
207 RDebug::Print(_L("[Backstepping] about to switch HS activity")); |
|
208 CAfActivityLauncher *activityEnabler = |
|
209 CAfActivityLauncher::NewLC( aResources.ApaSession(), |
|
210 aResources.WsSession() ); |
|
211 activityEnabler->launchActivityL( KHsActivactionUri ); |
|
212 CleanupStack::PopAndDestroy( activityEnabler ); |
|
213 } |
|
214 } |
|
215 iHsWasFirst = aIsFirst; |
|
216 } |
|
217 |
|
218 // end of file |
|