|
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 * Active object to load widgets into list |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "wmcommon.h" |
|
21 #include "wmplugin.h" |
|
22 #include "wmresourceloader.h" |
|
23 #include "wmpersistentwidgetorder.h" |
|
24 #include "wmlistbox.h" |
|
25 #include "wmwidgetloaderao.h" |
|
26 #include "wminstaller.h" |
|
27 #include "wmwidgetorderdata.h" |
|
28 |
|
29 #include <hscontentcontroller.h> // content control api |
|
30 #include <hscontentinfoarray.h> // content control api |
|
31 #include <widgetregistryclient.h> // widget reqistry |
|
32 #include <avkon.rsg> // avkon resources |
|
33 #include <barsread.h> // TResourceReader |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // CWmWidgetLoaderAo::NewL |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CWmWidgetLoaderAo* CWmWidgetLoaderAo::NewL( |
|
40 CWmPlugin& aWmPlugin, |
|
41 CWmListBox& aTargetList ) |
|
42 { |
|
43 CWmWidgetLoaderAo* self = new (ELeave) CWmWidgetLoaderAo( |
|
44 aWmPlugin, aTargetList ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CWmWidgetLoaderAo::NewL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CWmWidgetLoaderAo::CWmWidgetLoaderAo( |
|
56 CWmPlugin& aWmPlugin, |
|
57 CWmListBox& aTargetList ) |
|
58 : CActive( EPriorityNormal ) |
|
59 , iWmPlugin( aWmPlugin ) |
|
60 , iWidgetsList( aTargetList ) |
|
61 { |
|
62 iWidgetRegistry = NULL; |
|
63 iWidgetOrder = NULL; |
|
64 iLoading = EFalse; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CWmWidgetLoaderAo::ConstructL |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CWmWidgetLoaderAo::ConstructL() |
|
72 { |
|
73 CActiveScheduler::Add( this ); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CWmWidgetLoaderAo::~CWmWidgetLoaderAo |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CWmWidgetLoaderAo::~CWmWidgetLoaderAo() |
|
81 { |
|
82 // cancel ongoing operation |
|
83 Cancel(); |
|
84 |
|
85 // cleanup and close session |
|
86 Cleanup(); |
|
87 CloseSession(); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CWmWidgetLoaderAo::StartLoading |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CWmWidgetLoaderAo::StartLoading() |
|
95 { |
|
96 if ( IsActive() ) |
|
97 { |
|
98 return; // already active |
|
99 } |
|
100 |
|
101 // call itself |
|
102 iStatus = KRequestPending; |
|
103 TRequestStatus *pS = (&iStatus); |
|
104 User::RequestComplete( pS, KErrNone ); |
|
105 SetActive(); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CWmWidgetLoaderAo::RunL |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CWmWidgetLoaderAo::RunL() |
|
113 { |
|
114 DoLoadWidgetsL(); |
|
115 Cleanup(); |
|
116 CloseSession(); |
|
117 if ( iObserver ) |
|
118 { |
|
119 iObserver->LoadDoneL( iWidgetListChanged ); |
|
120 } |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CWmWidgetLoaderAo::RunError |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 TInt CWmWidgetLoaderAo::RunError( TInt /*aError*/ ) |
|
128 { |
|
129 Cleanup(); |
|
130 CloseSession(); |
|
131 return KErrNone; |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------- |
|
135 // CWmWidgetLoaderAo::DoCancel |
|
136 // --------------------------------------------------------- |
|
137 // |
|
138 void CWmWidgetLoaderAo::DoCancel() |
|
139 { |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // CWmWidgetLoaderAo::DoLoadWidgetsL |
|
144 // --------------------------------------------------------- |
|
145 // |
|
146 void CWmWidgetLoaderAo::DoLoadWidgetsL() |
|
147 { |
|
148 iWidgetListChanged = EFalse; |
|
149 // Check if unistallation is ongoing for for some widget |
|
150 // iUninstallUid is null no uninstallation is ongoing |
|
151 iUninstallUid = iWmPlugin.WmInstaller().UninstallUid(); |
|
152 |
|
153 // connect to widget registry |
|
154 OpenSessionL(); |
|
155 |
|
156 // 1. load the widgets array |
|
157 MHsContentController& controller = iWmPlugin.ContentController(); |
|
158 CHsContentInfoArray* contentInfoArray = CHsContentInfoArray::NewL(); |
|
159 CleanupStack::PushL( contentInfoArray ); |
|
160 controller.WidgetListL( *contentInfoArray ); |
|
161 |
|
162 // 2. load the widget order |
|
163 if ( iWidgetOrder ) { Cleanup(); } |
|
164 iWidgetOrder = CWmPersistentWidgetOrder::NewL( iWmPlugin.FileServer() ); |
|
165 TRAPD( loadError, iWidgetOrder->LoadL() ); |
|
166 |
|
167 // 3. prepare the widget data array & sort order array |
|
168 for( TInt i=0; i<iWidgetsList.WidgetDataCount(); ++i ) |
|
169 { |
|
170 iWidgetsList.WidgetData(i, ETrue ).SetPersistentWidgetOrder( iWidgetOrder ); |
|
171 iWidgetsList.WidgetData(i, ETrue ).SetValid( EFalse ); |
|
172 } |
|
173 for( TInt i = 0; i < iWidgetsList.OrderDataArray().Count(); ++i ) |
|
174 { |
|
175 iWidgetsList.OrderData(i)->SetPersistentWidgetOrder( iWidgetOrder ); |
|
176 } |
|
177 |
|
178 // 4. loop through the content array and compare it against the existing |
|
179 // widget data. |
|
180 TInt widgetsAdded = 0; |
|
181 TInt widgetsChanged = 0; |
|
182 iLoading = ETrue; |
|
183 while( contentInfoArray->Array().Count() > 0 ) |
|
184 { |
|
185 CHsContentInfo* contentInfo = contentInfoArray->Array()[0]; |
|
186 if ( !contentInfo ) { break; } |
|
187 contentInfoArray->Array().Remove( 0 ); |
|
188 |
|
189 // check if this widget exists. |
|
190 // if it does, keep the existing one |
|
191 // if it does not, add it |
|
192 CWmWidgetData* existingData = FindWidgetData( *contentInfo ); |
|
193 if ( existingData ) |
|
194 { |
|
195 // update existing visible widget data |
|
196 existingData->SetValid( ETrue ); |
|
197 if ( existingData->ReplaceContentInfo( contentInfo ) ) |
|
198 { |
|
199 // Update name to order array if name changed |
|
200 for ( TInt i=0; i < iWidgetsList.OrderDataArray().Count(); i++ ) |
|
201 { |
|
202 CWmWidgetOrderData* order = iWidgetsList.OrderData(i); |
|
203 if ( order->EqualsTo( |
|
204 existingData->Uid(), existingData->PublisherId() ) ) |
|
205 { |
|
206 order->UpdateName( existingData->Name() ); |
|
207 } |
|
208 } |
|
209 ++widgetsChanged; |
|
210 } |
|
211 } |
|
212 else |
|
213 { |
|
214 // add a new widget data |
|
215 TRAP_IGNORE( AddWidgetDataL( contentInfo, widgetsAdded ); ); |
|
216 } |
|
217 } |
|
218 |
|
219 // 5: finally, remove all UI widgets that during the loading process were |
|
220 // NOT marked as VALID. those widgets do not exist anymore. |
|
221 TInt widgetsRemoved = 0; |
|
222 for( TInt i=0; i<iWidgetsList.WidgetDataCount(); i++ ) |
|
223 { |
|
224 if( !iWidgetsList.WidgetData(i, ETrue ).IsValid() ) |
|
225 { |
|
226 iWidgetsList.RemoveWidgetData( i, ETrue ); |
|
227 ++widgetsRemoved; |
|
228 } |
|
229 } |
|
230 |
|
231 // update listbox |
|
232 if ( widgetsAdded > 0 && !iWidgetsList.IsFindPaneIsVisible() ) |
|
233 { |
|
234 iWidgetsList.HandleItemAdditionL(); |
|
235 } |
|
236 |
|
237 if ( widgetsRemoved > 0 || widgetsAdded > 0 || |
|
238 widgetsChanged > 0 ) |
|
239 { |
|
240 if ( !iWidgetsList.IsFindPaneIsVisible() ) |
|
241 { |
|
242 iWidgetsList.DrawDeferred(); |
|
243 } |
|
244 iWidgetListChanged = ETrue; |
|
245 } |
|
246 // 6: cleanup |
|
247 CleanupStack::PopAndDestroy( contentInfoArray ); |
|
248 |
|
249 // 7. check list empty condition |
|
250 if ( iWidgetsList.WidgetDataCount() == 0 ) |
|
251 { |
|
252 TResourceReader rr; |
|
253 CEikonEnv::Static()->CreateResourceReaderLC( |
|
254 rr, R_AVKON_LISTBOX_DEFAULT_EMPTY_TEXT ); |
|
255 TPtrC empty= rr.ReadTPtrC(); |
|
256 iWidgetsList.View()->SetListEmptyTextL( empty ); |
|
257 CleanupStack::PopAndDestroy(); |
|
258 iWidgetsList.DrawDeferred(); |
|
259 } |
|
260 |
|
261 // 8. store list order if necessary |
|
262 if ( loadError != KErrNone || widgetsAdded > 0 || widgetsRemoved > 0 ) |
|
263 { |
|
264 TRAP_IGNORE( iWidgetOrder->StoreL( iWidgetsList.OrderDataArray() ); ); |
|
265 } |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------- |
|
269 // CWmWidgetLoaderAo::FindWidgetDataL |
|
270 // --------------------------------------------------------- |
|
271 // |
|
272 CWmWidgetData* CWmWidgetLoaderAo::FindWidgetData( |
|
273 CHsContentInfo& aContentInfo ) |
|
274 { |
|
275 CWmWidgetData* data = NULL; |
|
276 for( TInt i=0; i<iWidgetsList.WidgetDataCount() && !data; ++i ) |
|
277 { |
|
278 if ( iWidgetsList.WidgetData(i, ETrue ).EqualsTo( aContentInfo ) ) |
|
279 { |
|
280 data = &iWidgetsList.WidgetData(i, ETrue ); |
|
281 } |
|
282 } |
|
283 return data; |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------- |
|
287 // CWmWidgetLoaderAo::OpenSessionL |
|
288 // --------------------------------------------------------- |
|
289 // |
|
290 void CWmWidgetLoaderAo::OpenSessionL() |
|
291 { |
|
292 if ( !iWidgetRegistry ) |
|
293 { |
|
294 iWidgetRegistry = new (ELeave) RWidgetRegistryClientSession(); |
|
295 TInt err = iWidgetRegistry->Connect(); |
|
296 if ( KErrNone != err ) |
|
297 { |
|
298 delete iWidgetRegistry; |
|
299 iWidgetRegistry = NULL; |
|
300 User::Leave( err ); |
|
301 } |
|
302 } |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------- |
|
306 // CWmWidgetLoaderAo::CloseSession |
|
307 // --------------------------------------------------------- |
|
308 // |
|
309 void CWmWidgetLoaderAo::CloseSession() |
|
310 { |
|
311 // disconnect widget registry |
|
312 if ( iWidgetRegistry ) |
|
313 { |
|
314 iWidgetRegistry->Disconnect(); |
|
315 iWidgetRegistry->Close(); |
|
316 delete iWidgetRegistry; |
|
317 iWidgetRegistry = NULL; |
|
318 } |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------- |
|
322 // CWmWidgetLoaderAo::AddWidgetDataL |
|
323 // --------------------------------------------------------- |
|
324 // |
|
325 void CWmWidgetLoaderAo::AddWidgetDataL( |
|
326 CHsContentInfo* aContentInfo, TInt& aCount ) |
|
327 { |
|
328 CleanupStack::PushL( aContentInfo ); |
|
329 |
|
330 // Becouse we show only widgets that can be added we need two arrays |
|
331 // to maintain order data and visible data. |
|
332 // All widgets are added to listbox's iOrderDataArray and |
|
333 // widgets that CanBeAdded are added also to iVisibleWidgetArray. |
|
334 CWmWidgetOrderData* order = CWmWidgetOrderData::NewLC( |
|
335 aContentInfo->PublisherId(), |
|
336 UidFromString( aContentInfo->Uid() ), |
|
337 aContentInfo->Name(), |
|
338 iWidgetOrder |
|
339 ); |
|
340 |
|
341 // add to order data |
|
342 iWidgetsList.AddOrderDataL( order ); |
|
343 CleanupStack::Pop( order ); |
|
344 |
|
345 if ( aContentInfo->CanBeAdded() ) |
|
346 { |
|
347 CWmWidgetData* widgetData = CWmWidgetData::NewL( |
|
348 iWidgetsList.LogoSize(), |
|
349 iWmPlugin.ResourceLoader(), |
|
350 aContentInfo, iWidgetRegistry ); |
|
351 |
|
352 // widgetdata has taken ownership of contentinfo |
|
353 CleanupStack::Pop( aContentInfo ); |
|
354 |
|
355 CleanupStack::PushL( widgetData ); |
|
356 |
|
357 widgetData->SetPersistentWidgetOrder( iWidgetOrder ); |
|
358 widgetData->SetValid( ETrue ); |
|
359 |
|
360 // start uninstall animation if this widget |
|
361 // is currently been unistalled |
|
362 if ( iUninstallUid != KNullUid && |
|
363 iUninstallUid == widgetData->PublisherUid() ) |
|
364 { |
|
365 widgetData->VisualizeUninstallL(); |
|
366 } |
|
367 // add to visible data |
|
368 iWidgetsList.AddWidgetDataL( widgetData, EFalse ); |
|
369 CleanupStack::Pop( widgetData ); |
|
370 aCount++; |
|
371 } |
|
372 else |
|
373 { |
|
374 //delete aContentInfo when it's not added to iVisibleWidgetArray |
|
375 CleanupStack::PopAndDestroy( aContentInfo ); |
|
376 } |
|
377 } |
|
378 |
|
379 // --------------------------------------------------------------------------- |
|
380 // CWmWidgetLoaderAo::Cleanup |
|
381 // --------------------------------------------------------------------------- |
|
382 // |
|
383 void CWmWidgetLoaderAo::Cleanup() |
|
384 { |
|
385 iLoading = EFalse; |
|
386 |
|
387 // delete widget order and references to it |
|
388 for( TInt i=0; i<iWidgetsList.WidgetDataCount(); ++i ) |
|
389 { |
|
390 iWidgetsList.WidgetData(i, ETrue ).SetPersistentWidgetOrder( NULL ); |
|
391 } |
|
392 delete iWidgetOrder; |
|
393 iWidgetOrder = NULL; |
|
394 } |
|
395 |
|
396 // ---------------------------------------------------- |
|
397 // CWmWidgetData::UidFromString |
|
398 // ---------------------------------------------------- |
|
399 // |
|
400 TUid CWmWidgetLoaderAo::UidFromString( const TDesC8& aUidString ) const |
|
401 { |
|
402 TUid uid( KNullUid ); |
|
403 const TInt KHexPrefixLength = 2; |
|
404 if ( aUidString.Length() > KHexPrefixLength ) |
|
405 { |
|
406 TUint id = 0; |
|
407 TLex8 lex( aUidString.Mid( KHexPrefixLength ) ); |
|
408 if ( lex.Val( id, EHex ) == KErrNone ) |
|
409 { |
|
410 uid.iUid = (TInt32)id; |
|
411 } |
|
412 } |
|
413 return uid; |
|
414 } |
|
415 |
|
416 // ---------------------------------------------------- |
|
417 // CWmWidgetData::IsLoading |
|
418 // ---------------------------------------------------- |
|
419 // |
|
420 TBool CWmWidgetLoaderAo::IsLoading() |
|
421 { |
|
422 return iLoading; |
|
423 } |
|
424 |
|
425 // ---------------------------------------------------- |
|
426 // CWmWidgetData::SetObserver |
|
427 // ---------------------------------------------------- |
|
428 // |
|
429 void CWmWidgetLoaderAo::SetObserver( MWmWidgetloaderObserver* aObserver ) |
|
430 { |
|
431 iObserver = aObserver; |
|
432 } |
|
433 |
|
434 // end of file |
|
435 |