|
1 /* |
|
2 * Copyright (c) 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: This module contains the implementation of |
|
15 * CDynamicThemeModifier class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "dynamicthememodifier.h" |
|
24 #include <aisystemuids.hrh> |
|
25 #include "xnodt.h" |
|
26 #include "xndomdocument.h" |
|
27 #include "xndomattribute.h" |
|
28 #include "xndomnode.h" |
|
29 #include "xndomlist.h" |
|
30 #include "xndomdepthiterator.h" |
|
31 #include <activeidle2domaincrkeys.h> |
|
32 |
|
33 // CONSTANTS |
|
34 #define NEWS_TICKER_GENERAL_SETTINGS_UID 0x10207196 |
|
35 const TUid KCRUidNewsTicker = {NEWS_TICKER_GENERAL_SETTINGS_UID}; |
|
36 |
|
37 /** |
|
38 * KGSNewsTickerStatus |
|
39 * CenRep key for "NewsTicker activated" |
|
40 * Off = 0 |
|
41 * On = 1 |
|
42 */ |
|
43 const TUint32 KGSNewsTickerStatus = 0x00000004; |
|
44 |
|
45 /** |
|
46 * KAINTInTheme |
|
47 * CenRep key for "NewsTicker implemented in AI2 theme" |
|
48 * No = 0 |
|
49 * Yes = 1 |
|
50 */ |
|
51 const TUint32 KAiNTInTheme = 0x00000800; |
|
52 const TInt KThemeArrayGranularity = 4; |
|
53 |
|
54 _LIT8( KProperty, "property" ); |
|
55 _LIT8( KControl, "control" ); |
|
56 _LIT8( KName, "name" ); |
|
57 _LIT8( KValue, "value" ); |
|
58 _LIT8( KBlock, "block" ); |
|
59 _LIT8( KNone, "none" ); |
|
60 |
|
61 using namespace AiXmlUiController; |
|
62 |
|
63 // ============================ MEMBER FUNCTIONS =============================== |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CDynamicThemeModifier::CDynamicThemeModifier |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CDynamicThemeModifier::CDynamicThemeModifier() |
|
70 { |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CDynamicThemeModifier::ConstructL |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void CDynamicThemeModifier::ConstructL() |
|
78 { |
|
79 // NT is not shown in theme by default. |
|
80 // This is overridden later if it really is implemented (some other theme |
|
81 // Basic activated) |
|
82 iAiCenRep = CRepository::NewL( TUid::Uid( KCRUidActiveIdleLV ) ); |
|
83 User::LeaveIfError( iAiCenRep->Set( KAiNTInTheme, 0 ) ); |
|
84 |
|
85 // Check if NT settings are visible in GS |
|
86 iNTCenRep = CRepository::NewL( KCRUidNewsTicker ); |
|
87 User::LeaveIfError( iNTCenRep->Get( KGSNewsTickerStatus, iEnabledInCenRep ) ); |
|
88 |
|
89 iNTCenRepObserver = CCenRepNotifyHandler::NewL( *this, |
|
90 *iNTCenRep, |
|
91 CCenRepNotifyHandler::EIntKey, |
|
92 KGSNewsTickerStatus ); |
|
93 iNTCenRepObserver->StartListeningL(); |
|
94 |
|
95 LoadThemesL(); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CDynamicThemeModifier::NewL |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 CDynamicThemeModifier* CDynamicThemeModifier::NewL() |
|
103 { |
|
104 CDynamicThemeModifier* self = new( ELeave ) CDynamicThemeModifier; |
|
105 |
|
106 CleanupStack::PushL( self ); |
|
107 self->ConstructL(); |
|
108 CleanupStack::Pop(); |
|
109 |
|
110 return self; |
|
111 } |
|
112 |
|
113 |
|
114 // Destructor |
|
115 CDynamicThemeModifier::~CDynamicThemeModifier() |
|
116 { |
|
117 if( iThemeArray ) |
|
118 { |
|
119 iThemeArray->ResetAndDestroy(); |
|
120 delete iThemeArray; |
|
121 } |
|
122 delete iOdt; |
|
123 delete iDomDocument; |
|
124 delete iXnResult; |
|
125 delete iXnRequestClient; |
|
126 delete iXnContentAccessClient; |
|
127 delete iXnClient; |
|
128 if( iNTCenRepObserver ) |
|
129 { |
|
130 iNTCenRepObserver->StopListening(); |
|
131 delete iNTCenRepObserver; |
|
132 } |
|
133 delete iNTCenRep; |
|
134 delete iAiCenRep; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // CDynamicThemeModifier::LoadThemesL |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CDynamicThemeModifier::LoadThemesL() |
|
142 { |
|
143 const TUid KUidAI2 = TUid::Uid( AI_UID3_AIFW_EXE ); |
|
144 |
|
145 iXnClient = CXnClient::NewL( *this ); |
|
146 // we're only interested in AI2 themes |
|
147 iXnContentAccessClient = CXnContentAccessClient::NewL( *this, |
|
148 KUidAI2.iUid ); |
|
149 iXnRequestClient = CXnRequestClient::NewL( *this, KUidAI2.iUid ); |
|
150 iXnResult = CXnResult::NewL(); |
|
151 |
|
152 CXnODT* odt = CXnODT::NewL(); |
|
153 CleanupStack::PushL( odt ); |
|
154 |
|
155 odt->SetAppUid( KUidAI2.iUid ); |
|
156 |
|
157 iThemeArray = new( ELeave ) CArrayPtrFlat<CXnODT>( KThemeArrayGranularity ); |
|
158 |
|
159 // theme array gets filled up by XnClient after this |
|
160 // HandleXnClientMessage() is a callback method that we're interested in |
|
161 TXnServiceCompletedMessage ret = |
|
162 iXnClient->XnGetListHeaders( *odt, *iThemeArray ); |
|
163 |
|
164 if( ret == EXnGetListHeadersSuccess || ret == EXnGetListHeadersEmpty ) |
|
165 { |
|
166 iXnClient->GetXnResult( *iXnResult ); |
|
167 iNumberOfHeaders = iXnResult->iIntValue1; |
|
168 iXnClient->XnGetNextHeader(); |
|
169 } |
|
170 |
|
171 CleanupStack::PopAndDestroy( odt ); |
|
172 } |
|
173 |
|
174 |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CDynamicThemeModifier::HandleXnClientMessage |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CDynamicThemeModifier::HandleXnClientMessage( |
|
181 TXnServiceCompletedMessage aMessage ) |
|
182 { |
|
183 // wait until all themes are fetched before loading settings |
|
184 if( ( aMessage == EXnGetListHeadersUpdate ) && |
|
185 ( iThemeArray->Count() == iNumberOfHeaders ) ) |
|
186 { |
|
187 TRAP_IGNORE( LoadSettingsFromThemeL() ); |
|
188 } |
|
189 |
|
190 else if( aMessage == EXnGetListHeadersFailed ) |
|
191 { |
|
192 if (iXnClient) |
|
193 { |
|
194 iXnClient->XnCancelGetListHeaders(); |
|
195 } |
|
196 |
|
197 if ( iThemeArray ) |
|
198 { |
|
199 iThemeArray->ResetAndDestroy(); |
|
200 delete iThemeArray; |
|
201 iThemeArray = NULL; |
|
202 } |
|
203 } |
|
204 |
|
205 } |
|
206 |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CDynamicThemeModifier::LoadSettingsFromThemeL |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CDynamicThemeModifier::LoadSettingsFromThemeL() |
|
213 { |
|
214 for( TInt i = 0; i < iThemeArray->Count(); i++ ) |
|
215 { |
|
216 CXnODT* odt = iThemeArray->At( i ); |
|
217 |
|
218 // activated theme found -> load settings |
|
219 if( odt->Flags() & EXnThemeStatusActive ) |
|
220 { |
|
221 delete iDomDocument; |
|
222 iDomDocument = NULL; |
|
223 iDomDocument = CXnDomDocument::NewL(); |
|
224 |
|
225 TXnServiceCompletedMessage ret = |
|
226 iXnContentAccessClient->XnLoadSettings( *odt, *iDomDocument ); |
|
227 if( ret == EXnSettingsLoaded ) |
|
228 { |
|
229 delete iOdt; |
|
230 iOdt = NULL; |
|
231 iOdt = odt->CloneL(); |
|
232 odt = NULL; |
|
233 // update theme to match CenRep value |
|
234 EnableNewsTickerL( TBool( iEnabledInCenRep ) ); |
|
235 break; |
|
236 } |
|
237 } |
|
238 } |
|
239 } |
|
240 |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CDynamicThemeModifier::EnableNewsTickerL |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CDynamicThemeModifier::EnableNewsTickerL( TBool aEnabled ) |
|
247 { |
|
248 TInt found = 0; |
|
249 CXnDomDepthIterator* iterator = |
|
250 CXnDomDepthIterator::NewL( *iDomDocument->RootNode() ); |
|
251 CleanupStack::PushL( iterator ); |
|
252 |
|
253 CXnDomNode* node = iterator->First(); |
|
254 |
|
255 if( !node ) |
|
256 { |
|
257 CleanupStack::PopAndDestroy( iterator ); |
|
258 return; |
|
259 } |
|
260 |
|
261 // find <control> tag |
|
262 while( node ) |
|
263 { |
|
264 if( !node->Name().Compare( KControl ) ) |
|
265 { |
|
266 break; |
|
267 } |
|
268 node = iterator->NextL(); |
|
269 } |
|
270 |
|
271 if( !node->Name().Compare( KControl ) ) |
|
272 { |
|
273 node = iterator->NextL(); |
|
274 |
|
275 while( node ) |
|
276 { |
|
277 // look for <property> tag... |
|
278 if( !node->Name().Compare( KProperty ) ) |
|
279 { |
|
280 // ...with attribute "value"... |
|
281 if( !node->AttributeValue( KName ).Compare( KValue ) ) |
|
282 { |
|
283 found = 1; |
|
284 CXnDomAttribute* attr = static_cast<CXnDomAttribute*> |
|
285 ( node->AttributeList().FindByName( KValue) ); |
|
286 |
|
287 // ...update it accordingly... |
|
288 if( aEnabled ) |
|
289 { |
|
290 attr->SetValueL( KBlock ); |
|
291 } |
|
292 else |
|
293 { |
|
294 attr->SetValueL( KNone ); |
|
295 } |
|
296 } |
|
297 } |
|
298 node = iterator->NextL(); |
|
299 } |
|
300 |
|
301 // ...and communicate the changes via Content Access API. |
|
302 for( TInt i = 0; i < iThemeArray->Count(); i++ ) |
|
303 { |
|
304 CXnODT* odt = iThemeArray->At( i ); |
|
305 |
|
306 // This might return an error if settings were not found from theme. |
|
307 // However, we don't need to take any actions since appropriate |
|
308 // theme is left untouched in that case anyway |
|
309 iXnContentAccessClient->XnUpdateSettings( *odt, *iDomDocument ); |
|
310 } |
|
311 |
|
312 // if found == 1, then NT is implemented in theme |
|
313 // -> NT settings can be shown in GS |
|
314 User::LeaveIfError( iAiCenRep->Set( KAiNTInTheme, found ) ); |
|
315 CleanupStack::PopAndDestroy( iterator ); |
|
316 } |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CDynamicThemeModifier::HandleNotifyInt |
|
321 // Callback method for observing CenRep changes |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 void CDynamicThemeModifier::HandleNotifyInt( TUint32 /*aId*/, TInt aNewValue ) |
|
325 { |
|
326 iEnabledInCenRep = TBool( aNewValue ); |
|
327 TRAP_IGNORE( EnableNewsTickerL( iEnabledInCenRep ) ); |
|
328 ; |
|
329 } |
|
330 |
|
331 // End of File |