|
1 /* |
|
2 * Copyright (c) 2002-2007 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 |
|
19 #include <eikenv.h> |
|
20 |
|
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include <uikon/eikenvinterface.h> |
|
23 #include <uikon/eiknotifyalert.h> |
|
24 #endif |
|
25 |
|
26 #include "AknNotifierControllerPlugin.h" |
|
27 #include <s32mem.h> |
|
28 #include <eikappui.h> |
|
29 #include <aknkeys.h> |
|
30 #include <coedef.h> |
|
31 #include <uikon/eiksrvui.h> |
|
32 #include <eikon.hrh> |
|
33 #include <apgwgnam.h> |
|
34 #include <AknDlgShut.h> |
|
35 #include <bautils.h> |
|
36 #include <AknNotifySignature.h> |
|
37 #include <AknCapServerDefs.h> |
|
38 |
|
39 const TInt KAknObserverListGranularity = 4; |
|
40 |
|
41 _LIT(KRESOURCEFILE,"z:\\resource\\aknnotpi.rsc"); |
|
42 |
|
43 EXPORT_C void CAknNotifierController::RegisterNotifierControllerPlugin(CAknNotifierWrapper* aMe, |
|
44 TBool aUnregister) |
|
45 { |
|
46 if (!aMe) |
|
47 { |
|
48 return; |
|
49 } |
|
50 |
|
51 if (!aUnregister) |
|
52 { |
|
53 if (FindNotifierWrapperIndex(aMe) == KErrNotFound) |
|
54 { |
|
55 TRAP_IGNORE( iRegisteredList->AppendL(aMe) ); |
|
56 } |
|
57 } |
|
58 else |
|
59 { |
|
60 TInt index = FindNotifierWrapperIndex(aMe); |
|
61 if (index != KErrNotFound) |
|
62 { |
|
63 iRegisteredList->Delete(index); |
|
64 } |
|
65 } |
|
66 } |
|
67 |
|
68 void CAknNotifierController::NotifyAppServers(TInt aCmd) |
|
69 { |
|
70 TUid commonServerUid = {0}; |
|
71 |
|
72 // Do this only once for common notifier server. |
|
73 // Re-use existing session from pre-loaded wrapper, otherwise handle as any other wrapper. |
|
74 if (iPreloadList.Count()) |
|
75 { |
|
76 CAknCommonNotifierWrapper* ccl = iPreloadList[0]; |
|
77 commonServerUid = ccl->AppServerUid(); |
|
78 ccl->DoNotifierControllerCommand(aCmd); |
|
79 } |
|
80 |
|
81 // and for akncapserver |
|
82 RAknUiServer* akncapserverClient = CAknSgcClient::AknSrv(); |
|
83 if ( akncapserverClient && akncapserverClient->Handle() ) |
|
84 { |
|
85 akncapserverClient->DoNotifierControllerCommand(aCmd); |
|
86 } |
|
87 |
|
88 TInt count = iRegisteredList->Count(); |
|
89 for (TInt ii = 0; ii < count; ii++) |
|
90 { |
|
91 CAknNotifierWrapper* nw = (*iRegisteredList)[ii]; |
|
92 TUid appserverUid = nw->AppServerUid(); |
|
93 if ( appserverUid != commonServerUid && appserverUid != KAknCapServerUid) |
|
94 { |
|
95 nw->DoNotifierControllerCommand(aCmd); |
|
96 } |
|
97 } |
|
98 } |
|
99 |
|
100 TInt CAknNotifierController::FindNotifierWrapperIndex(CAknNotifierWrapper* aPtr) |
|
101 { |
|
102 TInt index = KErrNotFound; |
|
103 TInt count = iRegisteredList->Count(); |
|
104 for (TInt ii = 0; ii < count; ii++) |
|
105 { |
|
106 if ( ((*iRegisteredList)[ii]) == aPtr) |
|
107 { |
|
108 index = ii; |
|
109 } |
|
110 } |
|
111 return index; |
|
112 } |
|
113 |
|
114 CAknNotifierController* CAknNotifierController::NewL() |
|
115 { |
|
116 CAknNotifierController* self = new(ELeave)CAknNotifierController(); |
|
117 CleanupStack::PushL(self); |
|
118 self->ConstructL(); |
|
119 CleanupStack::Pop(); //self |
|
120 return self; |
|
121 } |
|
122 |
|
123 void CAknNotifierController::ConstructL() |
|
124 { |
|
125 TFileName resourceFile; |
|
126 resourceFile.Append(KRESOURCEFILE); |
|
127 BaflUtils::NearestLanguageFile(CEikonEnv::Static()->FsSession(),resourceFile); |
|
128 iResourceFileOffset = CEikonEnv::Static()->AddResourceFileL(resourceFile); |
|
129 |
|
130 iObserverList = new(ELeave)CArrayPtrFlat<MAknKeyLockObserver>(KAknObserverListGranularity); |
|
131 iRegisteredList = new(ELeave)CArrayPtrFlat<CAknNotifierWrapper>(KAknObserverListGranularity); |
|
132 iController = new (ELeave) CAknNotifierControllerUtility(0); |
|
133 |
|
134 // Make sure AppUi has a pointer to this (Obsolete, Fix Me !!) |
|
135 STATIC_CAST(CEikServAppUi*,CEikonEnv::Static()->AppUi())->iKeyLockController = this; |
|
136 } |
|
137 |
|
138 CAknNotifierController::CAknNotifierController() |
|
139 :iAllowNotifications(ETrue) |
|
140 { |
|
141 } |
|
142 |
|
143 CAknNotifierController::~CAknNotifierController() |
|
144 { |
|
145 delete iObserverList; |
|
146 iPreloadList.Close(); |
|
147 if (iResourceFileOffset) |
|
148 { |
|
149 CCoeEnv::Static()->DeleteResourceFile(iResourceFileOffset); |
|
150 } |
|
151 } |
|
152 |
|
153 TBool CAknNotifierController::IsKeyLockEnabled() |
|
154 { |
|
155 TBool ret = EFalse; |
|
156 if (KeylockReady()) |
|
157 { |
|
158 ret = iKeylock.IsKeyLockEnabled(); |
|
159 } |
|
160 |
|
161 return ret; |
|
162 } |
|
163 |
|
164 TBool CAknNotifierController::AllowNotifications() |
|
165 { |
|
166 return iAllowNotifications; |
|
167 } |
|
168 |
|
169 void CAknNotifierController::UnlockKeys() |
|
170 { |
|
171 if (KeylockReady()) |
|
172 { |
|
173 iKeylock.DisableKeyLock(); |
|
174 } |
|
175 } |
|
176 |
|
177 void CAknNotifierController::LockKeys(TBool aAutoLockOn) |
|
178 { |
|
179 if (KeylockReady()) |
|
180 { |
|
181 if (!aAutoLockOn) |
|
182 iKeylock.EnableKeyLock(); |
|
183 else |
|
184 iKeylock.EnableAutoLockEmulation(); |
|
185 } |
|
186 } |
|
187 |
|
188 void CAknNotifierController::AddObserverL(MAknKeyLockObserver* aObserver) |
|
189 { |
|
190 #if defined(_DEBUG) |
|
191 TInt count = iObserverList->Count(); |
|
192 for (TInt ii = 0; ii < count; ii++) |
|
193 { |
|
194 if ( ((*iObserverList)[ii]) == aObserver) |
|
195 { |
|
196 User::Invariant(); |
|
197 } |
|
198 } |
|
199 #endif |
|
200 iObserverList->AppendL(aObserver); |
|
201 } |
|
202 |
|
203 void CAknNotifierController::RemoveObserver(MAknKeyLockObserver* aObserver) |
|
204 { |
|
205 TInt count = iObserverList->Count(); |
|
206 for (TInt ii = 0; ii < count; ii++) |
|
207 { |
|
208 if ( ((*iObserverList)[ii]) == aObserver) |
|
209 { |
|
210 iObserverList->Delete(ii); |
|
211 return; |
|
212 } |
|
213 } |
|
214 #if defined(_DEBUG) |
|
215 User::Invariant(); |
|
216 #endif |
|
217 } |
|
218 |
|
219 void CAknNotifierController::NotifyStatusChange(TKeyLockStatus aStatus) |
|
220 { |
|
221 TInt count = iObserverList->Count(); |
|
222 for (TInt ii = count-1; ii >= 0; ii--) |
|
223 { |
|
224 ((*iObserverList)[ii])->KeyLockStatusChange(aStatus); |
|
225 } |
|
226 } |
|
227 |
|
228 void CAknNotifierController::DoAllowNotifications() |
|
229 { |
|
230 TBool lastvalue = iAllowNotifications; |
|
231 iAllowNotifications = ETrue; |
|
232 NotifyStatusChange(EKeyLockAllowNotifications); |
|
233 iController->DoAllowNotifications(); |
|
234 if (!lastvalue) |
|
235 { |
|
236 // Enable FSW (could use direct connect to AknCapServer to do this as well). |
|
237 STATIC_CAST(CEikServAppUi*,CEikonEnv::Static()->AppUi())->SuppressAppSwitching(EFalse); |
|
238 } |
|
239 } |
|
240 |
|
241 void CAknNotifierController::DoStopNotifications() |
|
242 { |
|
243 TBool lastvalue = iAllowNotifications; |
|
244 iAllowNotifications = EFalse; |
|
245 NotifyStatusChange(EKeyLockStopNotifications); |
|
246 iController->DoStopNotifications(); |
|
247 if (lastvalue) |
|
248 { |
|
249 // Disable FSW (could use direct connect to AknCapServer to do this as well). |
|
250 STATIC_CAST(CEikServAppUi*,CEikonEnv::Static()->AppUi())->SuppressAppSwitching(ETrue); |
|
251 } |
|
252 } |
|
253 |
|
254 void CAknNotifierController::DoCancelAllNotificatons() |
|
255 { |
|
256 // Used when end key is pressed, to allow phone app to cancel all |
|
257 // notifications. Global notes / soft notifications that would |
|
258 // not normally be shown (out of priority) are not cancelled. |
|
259 if ( IsKeyLockEnabled() ) |
|
260 { |
|
261 return; |
|
262 } |
|
263 |
|
264 NotifyStatusChange(EKeyLockCancelNotification); |
|
265 |
|
266 // Send cancel key event to all other notifications, and hope they cancel. |
|
267 // Ignore error message - there's nothing more we can do. |
|
268 TRAP_IGNORE(iController->DoCancelAllNotificatonsL()); |
|
269 } |
|
270 |
|
271 TBool CAknNotifierController::KeylockReady() |
|
272 { |
|
273 if (iKeylock.Handle() == 0) |
|
274 { |
|
275 if (iKeylock.Connect() != KErrNone) |
|
276 { |
|
277 return EFalse; |
|
278 } |
|
279 } |
|
280 return ETrue; |
|
281 } |
|
282 |
|
283 EXPORT_C void CAknNotifierController::RegisterPreloadPluginL(CAknCommonNotifierWrapper* aNotifier) |
|
284 { |
|
285 User::LeaveIfError(iPreloadList.Append(aNotifier)); |
|
286 } |
|
287 |
|
288 // end of file |