114
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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: Profile plug-in publisher
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <ecom/ecom.h>
|
|
20 |
#include <ecom/implementationproxy.h>
|
|
21 |
#include <PUAcodes.hrh>
|
|
22 |
#include <AknUtils.h>
|
|
23 |
|
|
24 |
// User includes
|
|
25 |
#include <aiprofilepluginuids.hrh>
|
|
26 |
#include <aicontentobserver.h>
|
|
27 |
#include <aiutility.h>
|
|
28 |
|
|
29 |
#include "aiprofileplugincontentmodel.h"
|
|
30 |
#include "caiprofileplugin.h"
|
|
31 |
#include "caiprofileengine.h"
|
|
32 |
#include "aipluginsettings.h"
|
|
33 |
|
|
34 |
// Constants
|
|
35 |
|
|
36 |
// PUA code for the timed profile, missing from PUAcodes.hrh
|
|
37 |
#define KAiTimedProfilePUA 0xF815
|
|
38 |
#define KAiRTL 0x200F
|
|
39 |
|
|
40 |
const TImplementationProxy KImplementationTable[] =
|
|
41 |
{
|
|
42 |
IMPLEMENTATION_PROXY_ENTRY( KImplUidProfilePlugin, CAiProfilePlugin::NewL )
|
|
43 |
};
|
|
44 |
|
|
45 |
// ======== LOCAL FUNCTIONS ========
|
|
46 |
|
|
47 |
// ======== MEMBER FUNCTIONS ========
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
// CAiProfilePlugin::NewL
|
|
50 |
//
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
CAiProfilePlugin* CAiProfilePlugin::NewL()
|
|
54 |
{
|
|
55 |
CAiProfilePlugin* self = new ( ELeave ) CAiProfilePlugin;
|
|
56 |
CleanupStack::PushL( self );
|
|
57 |
self->ConstructL();
|
|
58 |
CleanupStack::Pop( self );
|
|
59 |
|
|
60 |
return self;
|
|
61 |
}
|
|
62 |
|
|
63 |
// ---------------------------------------------------------------------------
|
|
64 |
// CAiProfilePlugin::CAiProfilePlugin()
|
|
65 |
//
|
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
//
|
|
68 |
CAiProfilePlugin::CAiProfilePlugin()
|
|
69 |
{
|
|
70 |
}
|
|
71 |
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
// CAiProfilePlugin::ConstructL
|
|
74 |
//
|
|
75 |
// ---------------------------------------------------------------------------
|
|
76 |
//
|
|
77 |
void CAiProfilePlugin::ConstructL()
|
|
78 |
{
|
|
79 |
iContent =
|
|
80 |
AiUtility::CreateContentItemArrayIteratorL( KAiProfileContent );
|
|
81 |
|
|
82 |
iEvents =
|
|
83 |
AiUtility::CreateContentItemArrayIteratorL( KAiProfileEvents );
|
|
84 |
|
|
85 |
iResources =
|
|
86 |
AiUtility::CreateContentItemArrayIteratorL( KAiProfileResources );
|
|
87 |
|
|
88 |
iEngine = CAiProfileEngine::NewL( this );
|
|
89 |
|
|
90 |
iEngine->UpdateProfileNamesL();
|
|
91 |
}
|
|
92 |
|
|
93 |
// ---------------------------------------------------------------------------
|
|
94 |
// CAiProfilePlugin::~CAiProfilePlugin
|
|
95 |
// Deletes all data created to heap
|
|
96 |
// ---------------------------------------------------------------------------
|
|
97 |
//
|
|
98 |
CAiProfilePlugin::~CAiProfilePlugin()
|
|
99 |
{
|
|
100 |
Release( iContent );
|
|
101 |
Release( iEvents );
|
|
102 |
Release( iResources );
|
|
103 |
|
|
104 |
delete iActiveProfileAndChar;
|
|
105 |
delete iPreviousProfileNameAndChar;
|
|
106 |
delete iEngine;
|
|
107 |
|
|
108 |
iObservers.Close();
|
|
109 |
}
|
|
110 |
|
|
111 |
// ---------------------------------------------------------------------------
|
|
112 |
// CAiProfilePlugin::PublishL
|
|
113 |
// Publishes the profiles
|
|
114 |
// ---------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
void CAiProfilePlugin::PublishL()
|
|
117 |
{
|
|
118 |
TInt err( KErrNone );
|
|
119 |
TInt observers( iObservers.Count() );
|
|
120 |
TInt transactionId ( reinterpret_cast<TInt>( this ) );
|
|
121 |
|
|
122 |
iCurrentCount = iEngine->NumberOfProfiles();
|
|
123 |
|
|
124 |
for ( TInt i = 0; i < observers; i++ )
|
|
125 |
{
|
|
126 |
MAiContentObserver* observer( iObservers[i] );
|
|
127 |
|
|
128 |
err = observer->StartTransaction( transactionId );
|
|
129 |
|
|
130 |
if ( err == KErrNotSupported )
|
|
131 |
{
|
|
132 |
// The observer does not support transactions, check for real errors.
|
|
133 |
return;
|
|
134 |
}
|
|
135 |
|
|
136 |
//Active Profile name
|
|
137 |
if ( observer->CanPublish( *this, EAiProfileContentActiveProfileName, EAiProfileContentActiveProfileName ) )
|
|
138 |
{
|
|
139 |
observer->Publish( *this, EAiProfileContentActiveProfileName, iEngine->ActiveProfileName(), EAiProfileContentActiveProfileName );
|
|
140 |
}
|
|
141 |
|
|
142 |
if ( observer->CanPublish( *this, EAiProfileActiveProfileNameAndIconChar, 0 ) )
|
|
143 |
{
|
|
144 |
delete iActiveProfileAndChar;
|
|
145 |
iActiveProfileAndChar = NULL;
|
|
146 |
|
|
147 |
// silent/non-silent icon + timed icon + space + possible RTL*2 = 5
|
|
148 |
TInt maxChars( iEngine->ActiveProfileName().Length() + 5 );
|
|
149 |
|
|
150 |
iActiveProfileAndChar = HBufC::NewL( maxChars );
|
|
151 |
TPtr profileNamePtr( iActiveProfileAndChar->Des() );
|
|
152 |
|
|
153 |
if( AknLayoutUtils::LayoutMirrored() )
|
|
154 |
{
|
|
155 |
profileNamePtr.Append( KAiRTL );
|
|
156 |
}
|
|
157 |
|
|
158 |
if ( iEngine->IsActiveProfileTimedL() )
|
|
159 |
{
|
|
160 |
profileNamePtr.Append( KAiTimedProfilePUA );
|
|
161 |
}
|
|
162 |
|
|
163 |
if ( iEngine->IsActiveProfileSilentL() )
|
|
164 |
{
|
|
165 |
profileNamePtr.Append( KPuaCodeSilentSymbol );
|
|
166 |
}
|
|
167 |
else
|
|
168 |
{
|
|
169 |
profileNamePtr.Append( KPuaCodeAprofSound );
|
|
170 |
}
|
|
171 |
|
|
172 |
_LIT( KSpace, " " );
|
|
173 |
|
|
174 |
profileNamePtr.Append( KSpace );
|
|
175 |
|
|
176 |
if ( AknLayoutUtils::LayoutMirrored() )
|
|
177 |
{
|
|
178 |
profileNamePtr.Append( KAiRTL );
|
|
179 |
}
|
|
180 |
|
|
181 |
profileNamePtr.Append( iEngine->ActiveProfileName() );
|
|
182 |
|
|
183 |
if ( !iPreviousProfileNameAndChar ||
|
|
184 |
iPreviousProfileNameAndChar->CompareC( *iActiveProfileAndChar ) != 0 )
|
|
185 |
{
|
|
186 |
delete iPreviousProfileNameAndChar;
|
|
187 |
iPreviousProfileNameAndChar = NULL;
|
|
188 |
observer->Publish( *this, EAiProfileActiveProfileNameAndIconChar, profileNamePtr, 0 );
|
|
189 |
|
|
190 |
iPreviousProfileNameAndChar = iActiveProfileAndChar->AllocL();
|
|
191 |
}
|
|
192 |
}
|
|
193 |
|
|
194 |
//Swap Profile name ( 1.phase: General or Silent )
|
|
195 |
if ( observer->CanPublish( *this, EAiProfileContentSwapProfileName, EAiProfileContentSwapProfileName ) )
|
|
196 |
{
|
|
197 |
observer->Publish( *this, EAiProfileContentSwapProfileName, iEngine->SwapProfileName(), EAiProfileContentSwapProfileName );
|
|
198 |
}
|
|
199 |
|
|
200 |
//All profile names
|
|
201 |
// clean profiles that are already deleted.
|
|
202 |
// Cleans the array blindly from the end, because in the next
|
|
203 |
// step all the profiles are republished
|
|
204 |
if ( iPreviousCount > iCurrentCount )
|
|
205 |
{
|
|
206 |
for( TInt k = iCurrentCount; k < iPreviousCount; k++ )
|
|
207 |
{
|
|
208 |
observer->Clean( *this, EAiProfileContentProfileName, k + 1 );
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
for ( TInt j = 0; j < iCurrentCount; j++ )
|
|
213 |
{
|
|
214 |
if ( observer->CanPublish( *this, EAiProfileContentProfileName, j + 1 ) )
|
|
215 |
{
|
|
216 |
observer->Publish(*this, EAiProfileContentProfileName, iEngine->ProfileNameByIndex( j ), j + 1 );
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
//Active Profile silent indicator char
|
|
221 |
if ( observer->CanPublish( *this, EAiProfileActiveProfileSilentChar, EAiProfileActiveProfileSilentChar ) )
|
|
222 |
{
|
|
223 |
if ( iEngine->IsActiveProfileSilentL() )
|
|
224 |
{
|
|
225 |
TBuf<1> silent; // one character
|
|
226 |
silent.Append( KPuaCodeSilentSymbol );
|
|
227 |
|
|
228 |
observer->Publish( *this, EAiProfileActiveProfileSilentChar, silent, EAiProfileActiveProfileSilentChar );
|
|
229 |
}
|
|
230 |
else
|
|
231 |
{
|
|
232 |
observer->Clean( *this, EAiProfileActiveProfileSilentChar, EAiProfileActiveProfileSilentChar );
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
|
236 |
//Active Profile silent indicator resource
|
|
237 |
if ( observer->CanPublish( *this, EAiProfileActiveProfileIcon, EAiProfileActiveProfileIcon ) )
|
|
238 |
{
|
|
239 |
observer->Clean( *this, EAiProfileActiveProfileIcon, EAiProfileActiveProfileSilentIconResource );
|
|
240 |
observer->Clean( *this, EAiProfileActiveProfileIcon, EAiProfileActiveProfileGeneralIconResource );
|
|
241 |
observer->Clean( *this, EAiProfileActiveProfileIcon, EAiProfileActiveProfileTimedIconResource );
|
|
242 |
|
|
243 |
if ( iEngine->IsActiveProfileTimedL() )
|
|
244 |
{
|
|
245 |
observer->Publish( *this,
|
|
246 |
EAiProfileActiveProfileIcon,
|
|
247 |
EAiProfileActiveProfileTimedIconResource,
|
|
248 |
EAiProfileActiveProfileTimedIconResource );
|
|
249 |
}
|
|
250 |
else if ( iEngine->IsActiveProfileSilentL() )
|
|
251 |
{
|
|
252 |
observer->Publish( *this,
|
|
253 |
EAiProfileActiveProfileIcon,
|
|
254 |
EAiProfileActiveProfileSilentIconResource,
|
|
255 |
EAiProfileActiveProfileSilentIconResource );
|
|
256 |
}
|
|
257 |
else
|
|
258 |
{
|
|
259 |
observer->Publish( *this,
|
|
260 |
EAiProfileActiveProfileIcon,
|
|
261 |
EAiProfileActiveProfileGeneralIconResource,
|
|
262 |
EAiProfileActiveProfileGeneralIconResource );
|
|
263 |
}
|
|
264 |
}
|
|
265 |
|
|
266 |
// in case of Offline profile profile indicator is not shown
|
|
267 |
if ( observer->CanPublish( *this, EAiProfileContentActiveProfileName, EAiProfileContentActiveProfileName ) &&
|
|
268 |
iEngine->IsOffline() )
|
|
269 |
{
|
|
270 |
observer->Clean( *this, EAiProfileActiveProfileSilentChar, EAiProfileActiveProfileSilentChar );
|
|
271 |
observer->Clean( *this, EAiProfileActiveProfileIcon, 1 );
|
|
272 |
observer->Clean( *this, EAiProfileActiveProfileIcon, 2 );
|
|
273 |
|
|
274 |
// uncomment also this and respective policy lines in profiles.xml if whole widget needs to be hidden in AI3
|
|
275 |
//observer->Clean( *this, EAiProfileContentActiveProfileName, EAiProfileContentActiveProfileName );
|
|
276 |
}
|
|
277 |
|
|
278 |
if ( err == KErrNone )
|
|
279 |
{
|
|
280 |
err = observer->Commit( transactionId );
|
|
281 |
|
|
282 |
if ( err == KErrNotSupported)
|
|
283 |
{
|
|
284 |
return;
|
|
285 |
}
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
iPreviousCount = iCurrentCount;
|
|
290 |
}
|
|
291 |
|
|
292 |
// ---------------------------------------------------------------------------
|
|
293 |
// CAiProfilePlugin::Start
|
|
294 |
//
|
|
295 |
// ---------------------------------------------------------------------------
|
|
296 |
//
|
|
297 |
void CAiProfilePlugin::Start( TStartReason /*aReason*/ )
|
|
298 |
{
|
|
299 |
iPublishRequired = ETrue;
|
|
300 |
}
|
|
301 |
|
|
302 |
// ---------------------------------------------------------------------------
|
|
303 |
// CAiProfilePlugin::Stop
|
|
304 |
//
|
|
305 |
// ---------------------------------------------------------------------------
|
|
306 |
//
|
|
307 |
void CAiProfilePlugin::Stop( TStopReason /*aReason*/ )
|
|
308 |
{
|
|
309 |
CleanPublishedProfileNames();
|
|
310 |
}
|
|
311 |
|
|
312 |
// ---------------------------------------------------------------------------
|
|
313 |
// CAiProfilePlugin::Resume
|
|
314 |
//
|
|
315 |
// ---------------------------------------------------------------------------
|
|
316 |
//
|
|
317 |
void CAiProfilePlugin::Resume( TResumeReason aReason )
|
|
318 |
{
|
|
319 |
if ( aReason == EForeground )
|
|
320 |
{
|
|
321 |
TRAP_IGNORE( DoResumeL() );
|
|
322 |
}
|
|
323 |
}
|
|
324 |
|
|
325 |
// ---------------------------------------------------------------------------
|
|
326 |
// CAiProfilePlugin::Suspend
|
|
327 |
//
|
|
328 |
// ---------------------------------------------------------------------------
|
|
329 |
//
|
|
330 |
void CAiProfilePlugin::Suspend( TSuspendReason /*aReason*/ )
|
|
331 |
{
|
|
332 |
}
|
|
333 |
|
|
334 |
// ---------------------------------------------------------------------------
|
|
335 |
// CAiProfilePlugin::SubscribeL
|
|
336 |
//
|
|
337 |
// ---------------------------------------------------------------------------
|
|
338 |
//
|
|
339 |
void CAiProfilePlugin::SubscribeL( MAiContentObserver& aObserver )
|
|
340 |
{
|
|
341 |
iObservers.AppendL( &aObserver );
|
|
342 |
}
|
|
343 |
|
|
344 |
// ---------------------------------------------------------------------------
|
|
345 |
// CAiProfilePlugin::ConfigureL
|
|
346 |
//
|
|
347 |
// ---------------------------------------------------------------------------
|
|
348 |
//
|
|
349 |
void CAiProfilePlugin::ConfigureL( RAiSettingsItemArray& /*aSettings*/ )
|
|
350 |
{
|
|
351 |
}
|
|
352 |
|
|
353 |
// ---------------------------------------------------------------------------
|
|
354 |
// CAiProfilePlugin::GetProperty
|
|
355 |
//
|
|
356 |
// ---------------------------------------------------------------------------
|
|
357 |
//
|
|
358 |
TAny* CAiProfilePlugin::GetProperty( TProperty aProperty )
|
|
359 |
{
|
|
360 |
if ( aProperty == EPublisherContent )
|
|
361 |
{
|
|
362 |
return static_cast< MAiContentItemIterator* >( iContent );
|
|
363 |
}
|
|
364 |
else if ( aProperty == EPublisherEvents )
|
|
365 |
{
|
|
366 |
return static_cast< MAiContentItemIterator* >( iEvents );
|
|
367 |
}
|
|
368 |
else if ( aProperty == EPublisherResources )
|
|
369 |
{
|
|
370 |
return static_cast< MAiContentItemIterator* >( iResources );
|
|
371 |
}
|
|
372 |
|
|
373 |
return NULL;
|
|
374 |
}
|
|
375 |
|
|
376 |
// ---------------------------------------------------------------------------
|
|
377 |
// CAiProfilePlugin::HandleEvent
|
|
378 |
//
|
|
379 |
// ---------------------------------------------------------------------------
|
|
380 |
//
|
|
381 |
void CAiProfilePlugin::HandleEvent( TInt aEvent, const TDesC& aParam )
|
|
382 |
{
|
|
383 |
TRAP_IGNORE( iEngine->HandleAiEventL( aEvent, aParam ) );
|
|
384 |
}
|
|
385 |
|
|
386 |
// ---------------------------------------------------------------------------
|
|
387 |
// CAiProfilePlugin::DoResumeL
|
|
388 |
//
|
|
389 |
// ---------------------------------------------------------------------------
|
|
390 |
//
|
|
391 |
void CAiProfilePlugin::DoResumeL()
|
|
392 |
{
|
|
393 |
if ( iPublishRequired )
|
|
394 |
{
|
|
395 |
iPublishRequired = EFalse;
|
|
396 |
|
|
397 |
PublishL();
|
|
398 |
}
|
|
399 |
}
|
|
400 |
|
|
401 |
// ---------------------------------------------------------------------------
|
|
402 |
// CAiProfilePlugin::NotifyContentUpdate()
|
|
403 |
// This method is called from the engine, when the profile data has changed
|
|
404 |
// ---------------------------------------------------------------------------
|
|
405 |
//
|
|
406 |
void CAiProfilePlugin::NotifyContentUpdate()
|
|
407 |
{
|
|
408 |
iPublishRequired = ETrue;
|
|
409 |
|
|
410 |
TRAP_IGNORE( DoResumeL() );
|
|
411 |
}
|
|
412 |
|
|
413 |
// ---------------------------------------------------------------------------
|
|
414 |
// CAiProfilePlugin::CleanPublishedProfileNames
|
|
415 |
// Clean profile names from content
|
|
416 |
// ---------------------------------------------------------------------------
|
|
417 |
//
|
|
418 |
void CAiProfilePlugin::CleanPublishedProfileNames()
|
|
419 |
{
|
|
420 |
TInt obsCount( iObservers.Count() );
|
|
421 |
|
|
422 |
for ( TInt i( 0 ); i < obsCount; i++ )
|
|
423 |
{
|
|
424 |
MAiContentObserver* observer( iObservers[i] );
|
|
425 |
|
|
426 |
for ( TInt j( 0 ); j < iCurrentCount && observer; j++ )
|
|
427 |
{
|
|
428 |
observer->Clean( *this, EAiProfileContentProfileName, j + 1 );
|
|
429 |
}
|
|
430 |
}
|
|
431 |
|
|
432 |
delete iPreviousProfileNameAndChar;
|
|
433 |
iPreviousProfileNameAndChar = NULL;
|
|
434 |
|
|
435 |
iPreviousCount = 0;
|
|
436 |
}
|
|
437 |
|
|
438 |
// ======== GLOBAL FUNCTIONS ========
|
|
439 |
// ---------------------------------------------------------------------------
|
|
440 |
// Constructs and returns an application object.
|
|
441 |
// ---------------------------------------------------------------------------
|
|
442 |
//
|
|
443 |
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
|
|
444 |
TInt& aTableCount )
|
|
445 |
{
|
|
446 |
aTableCount = sizeof( KImplementationTable ) /
|
|
447 |
sizeof( TImplementationProxy );
|
|
448 |
|
|
449 |
return KImplementationTable;
|
|
450 |
}
|