|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Shortcut plug-in xSP extension server class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <centralrepository.h> |
|
20 #include <apgcli.h> |
|
21 #include <apadef.h> |
|
22 #include <apgwgnam.h> |
|
23 #include <bautils.h> |
|
24 #include <e32property.h> |
|
25 |
|
26 #include <aknmessagequerydialog.h> |
|
27 #include <StringLoader.h> |
|
28 |
|
29 #include <aiscutplugindomaincrkeys.h> |
|
30 #include <aiscutpluginres.rsg> |
|
31 #include <aiscutextdefs.h> |
|
32 |
|
33 #include "caiscutextserver.h" |
|
34 #include "caiscutextsession.h" |
|
35 #include "taiscutparser.h" |
|
36 #include "caiscutextserver.h" |
|
37 #include "activeidle2domainpskeys.h" |
|
38 |
|
39 |
|
40 // Amount of bytes the data buffer increases at a time. |
|
41 const TInt KAppsListDataGranularity = 100; |
|
42 |
|
43 // The length of '0x' in front of a hex literal. |
|
44 const TInt KTokenPrefix = 2; |
|
45 |
|
46 // Index to UID 3 |
|
47 const TInt KUidIndex = 2; |
|
48 |
|
49 // Count of characters one UID occupies in CenRep (prefix + 8 digits + spacer) |
|
50 const TInt KUidStorageLength = KTokenPrefix + 8 + 1; |
|
51 |
|
52 _LIT(KUidFormat, "0x%08X "); |
|
53 |
|
54 _LIT(KResource, "z:\\resource\\aiscutpluginres.rsc"); |
|
55 |
|
56 _LIT(KRomDrive, "z"); |
|
57 |
|
58 |
|
59 CLinkParams::CLinkParams(CAiScutExtServer& aServer, HBufC* aTargetDefinition) |
|
60 : iServer(aServer) |
|
61 { |
|
62 iTargetDefinition = aTargetDefinition; |
|
63 } |
|
64 |
|
65 CLinkParams::~CLinkParams() |
|
66 { |
|
67 delete iTargetDefinition; |
|
68 } |
|
69 |
|
70 // ======== MEMBER FUNCTIONS ======== |
|
71 |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CAiScutExtServer::CAiScutExtServer( MAiScutExtMessageHandler& aObserver, RWsSession& aWsSession ) |
|
78 : CServer2( CActive::EPriorityStandard ), iObserver( aObserver ), iWsSession(aWsSession) |
|
79 { |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CAiScutExtServer::ConstructL() |
|
87 { |
|
88 iIdle = CIdle::NewL( EPriorityStandard ); |
|
89 |
|
90 TFileName fileName( KResource ); |
|
91 CEikonEnv* env = CEikonEnv::Static(); |
|
92 BaflUtils::NearestLanguageFile( env->FsSession(), fileName ); |
|
93 iResourceOffset = env->AddResourceFileL( fileName ); |
|
94 |
|
95 ReadAppListL(); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CAiScutExtServer::~CAiScutExtServer() |
|
103 { |
|
104 if( iIdle ) |
|
105 { |
|
106 iIdle->Cancel(); |
|
107 delete iIdle; |
|
108 } |
|
109 |
|
110 CEikonEnv::Static()->DeleteResourceFile( iResourceOffset ); |
|
111 |
|
112 iShowUids.Close(); |
|
113 iUids.Close(); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 CSession2* CAiScutExtServer::NewSessionL( |
|
121 const TVersion& aVersion, const RMessage2& /*aMessage*/ ) const |
|
122 { |
|
123 TVersion version( |
|
124 KAiScutExtServMajorVersionNumber, |
|
125 KAiScutExtServMinorVersionNumber, |
|
126 KAiScutExtServBuildVersionNumber ); |
|
127 |
|
128 if ( !User::QueryVersionSupported( version, aVersion ) ) |
|
129 { |
|
130 User::Leave( KErrNotSupported ); |
|
131 } |
|
132 CAiScutExtSession* session = new( ELeave ) CAiScutExtSession( iObserver ); |
|
133 return session; |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // Read a list of application UIDs which we must not show the tip. |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 void CAiScutExtServer::ReadAppListL() |
|
141 { |
|
142 CRepository* repository = CRepository::NewL( KCRUidShortcutItems ); |
|
143 CleanupStack::PushL( repository ); |
|
144 |
|
145 RBuf buffer; |
|
146 buffer.CreateL( KAppsListDataGranularity ); |
|
147 buffer.CleanupClosePushL(); |
|
148 |
|
149 TInt err = repository->Get( KAIxSPNoTipAppsList, buffer ); |
|
150 while( err == KErrOverflow ) |
|
151 { |
|
152 buffer.ReAllocL( buffer.MaxLength() + KAppsListDataGranularity ); |
|
153 err = repository->Get( KAIxSPNoTipAppsList, buffer ); |
|
154 } |
|
155 |
|
156 // Handle error silently if reading from Central Repository fails. |
|
157 if( err == KErrNone ) |
|
158 { |
|
159 // Parse application UIDs and put them to list. |
|
160 TLex lex(buffer); |
|
161 |
|
162 while( !lex.Eos() ) |
|
163 { |
|
164 TPtrC token( lex.NextToken() ); |
|
165 if( token.Length() < KTokenPrefix ) |
|
166 { |
|
167 break; |
|
168 } |
|
169 TLex lexUid( token.Right( token.Length() - KTokenPrefix ) ); |
|
170 |
|
171 TUint32 uid; |
|
172 if( lexUid.Val( uid, EHex ) == KErrNone ) |
|
173 { |
|
174 iUids.AppendL( TUid::Uid( uid ) ); |
|
175 } |
|
176 } |
|
177 } |
|
178 |
|
179 CleanupStack::PopAndDestroy(); // buffer |
|
180 CleanupStack::PopAndDestroy( repository ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // Saves the list of applications UIDs. |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CAiScutExtServer::WriteAppListL() |
|
188 { |
|
189 CRepository* repository = CRepository::NewL( KCRUidShortcutItems ); |
|
190 CleanupStack::PushL( repository ); |
|
191 |
|
192 RBuf buffer; |
|
193 buffer.CreateL( iUids.Count() * KUidStorageLength ); |
|
194 buffer.Zero(); |
|
195 buffer.CleanupClosePushL(); |
|
196 |
|
197 TBuf<KUidStorageLength> uidString; |
|
198 |
|
199 for(TInt c = 0; c < iUids.Count(); c++) |
|
200 { |
|
201 uidString.Format( KUidFormat, iUids[c] ); |
|
202 buffer.Append( uidString ); // Ignore error |
|
203 } |
|
204 |
|
205 User::LeaveIfError( repository->Set( KAIxSPNoTipAppsList, buffer ) ); |
|
206 |
|
207 CleanupStack::PopAndDestroy(); // buffer |
|
208 CleanupStack::PopAndDestroy( repository ); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // Tests if the client has connected us before, i.e. determines if |
|
213 // the tip message should be shown. |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 TBool CAiScutExtServer::HasConnectedBefore( TUid& aUid, const RMessage2& aMessage ) |
|
217 { |
|
218 // First test if the current theme supports the xSP feature |
|
219 TInt isXspSupported = EPSAiXspNotSupported; |
|
220 TInt err = RProperty::Get( KPSUidAiInformation, KActiveIdleThemeSupportsXsp, |
|
221 isXspSupported ); |
|
222 |
|
223 if( err != KErrNone || isXspSupported == EPSAiXspNotSupported) |
|
224 { |
|
225 // xSP is not supported so don't show the dialog. Also if we could not |
|
226 // read the P&S key we won't show the dialog. |
|
227 return ETrue; |
|
228 } |
|
229 |
|
230 RThread threadClient; |
|
231 |
|
232 if( aMessage.Client( threadClient ) != KErrNone ) |
|
233 { |
|
234 // In case of error we report that the client has connected us |
|
235 // before in order not to show the dialog. |
|
236 return ETrue; |
|
237 } |
|
238 |
|
239 RProcess processClient; |
|
240 |
|
241 if( threadClient.Process(processClient) != KErrNone ) |
|
242 { |
|
243 // Prevent dialog from showing in case of error. |
|
244 return ETrue; |
|
245 } |
|
246 |
|
247 // See if client application is in ROM |
|
248 TFileName fileName = processClient.FileName(); |
|
249 TPtr processDrive( fileName.LeftTPtr( KRomDrive().Length() ) ); |
|
250 processDrive.LowerCase(); |
|
251 |
|
252 if( processDrive == KRomDrive() ) |
|
253 { |
|
254 // Don't show tip message for ROM clients. |
|
255 return ETrue; |
|
256 } |
|
257 |
|
258 TUidType uidType = processClient.Type(); |
|
259 |
|
260 // UID3 of the client process |
|
261 TUid uid3( uidType[ KUidIndex ] ); |
|
262 aUid = uid3; |
|
263 |
|
264 // See if the uid is already in the list |
|
265 if( iUids.Find( uid3 ) != KErrNotFound ) |
|
266 { |
|
267 return ETrue; |
|
268 } |
|
269 |
|
270 return EFalse; |
|
271 } |
|
272 |
|
273 void CAiScutExtServer::ShowTipMessage( TUid aUid ) |
|
274 { |
|
275 if( iShowUids.Find( aUid ) == KErrNotFound ) |
|
276 { |
|
277 iShowUids.Append( aUid ); |
|
278 iIdle->Cancel(); |
|
279 iIdle->Start( TCallBack( CAiScutExtServer::IdleCallBack, this ) ); |
|
280 } |
|
281 } |
|
282 |
|
283 TInt CAiScutExtServer::IdleCallBack(TAny* aParam) |
|
284 { |
|
285 CAiScutExtServer* p = (CAiScutExtServer*) aParam; |
|
286 |
|
287 p->iIdle->Cancel(); |
|
288 |
|
289 if( p->iIsForeground ) |
|
290 { |
|
291 TRAP_IGNORE( p->DoShowTipMessageL() ); |
|
292 } |
|
293 |
|
294 return KErrNone; |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // Shows a dialog |
|
299 // --------------------------------------------------------------------------- |
|
300 // |
|
301 void CAiScutExtServer::DoShowTipMessageL() |
|
302 { |
|
303 // Find out the name of the application |
|
304 RApaLsSession als; |
|
305 User::LeaveIfError( als.Connect() ); |
|
306 CleanupClosePushL( als ); |
|
307 |
|
308 while( iShowUids.Count() > 0 && !iIsTipMessageVisible) |
|
309 { |
|
310 TUid uid = iShowUids[ 0 ]; |
|
311 TApaAppInfo appInfo; |
|
312 User::LeaveIfError( als.GetAppInfo( appInfo, uid ) ); |
|
313 |
|
314 // Prepare the parameters for the link function |
|
315 HBufC* definitionBuf = HBufC::NewLC( KMaxDefinitionLength ); |
|
316 TPtr definition( definitionBuf->Des() ); |
|
317 definition.Format( KScutFormatApplication, uid ); |
|
318 |
|
319 TBool isInShortcuts = iObserver.HandleIsInShortcutsL( definition ); |
|
320 |
|
321 CLinkParams* params = new( ELeave) CLinkParams( *this, definitionBuf ); |
|
322 CleanupStack::Pop( definitionBuf ); |
|
323 CleanupStack::PushL( params ); |
|
324 |
|
325 TCallBack cb(CAiScutExtServer::LinkCallBack, params); |
|
326 |
|
327 // Read and format tip message from the resource file |
|
328 HBufC* messageBuf = StringLoader::LoadLC( R_AI_SC_QUERY_MODIFY_GS, appInfo.iCaption ); |
|
329 TPtr message( messageBuf->Des() ); |
|
330 |
|
331 // Don't show the tip if the application is already in shortcuts |
|
332 if( !isInShortcuts ) |
|
333 { |
|
334 iIsTipMessageVisible = ETrue; |
|
335 CAknMessageQueryDialog* note = CAknMessageQueryDialog::NewL( message ); |
|
336 params->iNote = note; |
|
337 |
|
338 note->SetLink( cb ); |
|
339 note->ExecuteLD( R_SCUT_XSPTIP_NOTE ); |
|
340 iIsTipMessageVisible = EFalse; |
|
341 } |
|
342 |
|
343 // Update the list so we don't show the tip message |
|
344 // again for this application. |
|
345 iUids.Append( uid ); // Ignore error |
|
346 iShowUids.Remove( 0 ); |
|
347 |
|
348 // Save the list of uids to persistant memory. |
|
349 WriteAppListL(); |
|
350 |
|
351 CleanupStack::PopAndDestroy( messageBuf ); |
|
352 CleanupStack::PopAndDestroy( params ); |
|
353 } |
|
354 |
|
355 CleanupStack::PopAndDestroy(); // als |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 // Opens the shurtcuts settings view |
|
360 // --------------------------------------------------------------------------- |
|
361 // |
|
362 TInt CAiScutExtServer::LinkCallBack(TAny* aParam) |
|
363 { |
|
364 CLinkParams* params = (CLinkParams*) aParam; |
|
365 |
|
366 TRAP_IGNORE( |
|
367 params->iServer.iObserver.HandleIssuePutInShortcutsL( |
|
368 params->iTargetDefinition->Des() ); |
|
369 ); |
|
370 |
|
371 return KErrNone; |
|
372 } |
|
373 |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 // --------------------------------------------------------------------------- |
|
377 // |
|
378 void CAiScutExtServer::ResumeL( TAiTransitionReason aReason ) |
|
379 { |
|
380 switch( aReason ) |
|
381 { |
|
382 case EAiIdleForeground: |
|
383 iIsForeground = ETrue; |
|
384 DoShowTipMessageL(); |
|
385 break; |
|
386 |
|
387 case EAiIdleBackground: |
|
388 iIsForeground = EFalse; |
|
389 break; |
|
390 |
|
391 default: |
|
392 break; |
|
393 } |
|
394 } |
|
395 |
|
396 // End of File. |