|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent - Internal Symbian test code |
|
19 */ |
|
20 |
|
21 |
|
22 #include <barsread.h> |
|
23 #include <s32file.h> |
|
24 #include <gdi.h> |
|
25 #include <gulutil.h> |
|
26 #include <gulicon.h> |
|
27 #include <apgaplst.h> |
|
28 #include <apgicnfl.h> |
|
29 #include <apgcli.h> |
|
30 #include <vwsdef.h> |
|
31 |
|
32 #include <eikenv.h> |
|
33 #include <techview/eikdialg.h> |
|
34 #include <eikappui.h> |
|
35 #include <eikapp.h> |
|
36 #include <eikdoc.h> |
|
37 #include <eikpanic.h> |
|
38 #include <techview/eikhlbx.h> |
|
39 #include <techview/eikhlbm.h> |
|
40 #include <techview/eikhlbi.h> |
|
41 #include <techview/eiktxlbx.h> |
|
42 #include <techview/eiktxlbm.h> |
|
43 #include <techview/eikon.hrh> |
|
44 #include <techview/eikon.rsg> |
|
45 #include <eikon.mbg> |
|
46 #include <eikstart.h> |
|
47 |
|
48 #include "tview4.hrh" |
|
49 #include <tview4.rsg> |
|
50 |
|
51 |
|
52 /** Tests reading of views on system at runtime. Installed apps are shown in hierarchical list. |
|
53 Expanding the list item for an app reveals its views. Toolbar allows link to the view to be |
|
54 followed. |
|
55 */ |
|
56 |
|
57 // |
|
58 // global functions |
|
59 // |
|
60 |
|
61 GLDEF_C void Panic(TEikPanic aPanic) |
|
62 { |
|
63 User::Panic(_L("TVIEW4"), aPanic); |
|
64 } |
|
65 |
|
66 // |
|
67 // class COwnedFilesDialog |
|
68 // |
|
69 |
|
70 class COwnedFilesDialog : public CEikDialog |
|
71 { |
|
72 public: |
|
73 COwnedFilesDialog(TUid aAppUid); |
|
74 private: // framework |
|
75 void PreLayoutDynInitL(); |
|
76 private: |
|
77 TUid iAppUid; |
|
78 }; |
|
79 |
|
80 COwnedFilesDialog::COwnedFilesDialog(TUid aAppUid) |
|
81 : iAppUid(aAppUid) |
|
82 { |
|
83 } |
|
84 |
|
85 void COwnedFilesDialog::PreLayoutDynInitL() |
|
86 { |
|
87 CEikTextListBox* listBox = static_cast<CEikTextListBox*>(Control(EAppDlgOwnedFilesId)); |
|
88 CEikScrollBarFrame* sbFrame = listBox->CreateScrollBarFrameL(); |
|
89 sbFrame->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
90 |
|
91 RApaLsSession ls; |
|
92 CleanupClosePushL(ls); |
|
93 User::LeaveIfError(ls.Connect()); |
|
94 User::LeaveIfError(ls.GetAllApps()); |
|
95 |
|
96 CDesCArray* ownedFileArray=new(ELeave) CDesCArraySeg(2); |
|
97 User::LeaveIfError(ls.GetAppOwnedFiles(*ownedFileArray,iAppUid)); |
|
98 |
|
99 CleanupStack::PopAndDestroy(); // ls |
|
100 |
|
101 listBox->Model()->SetItemTextArray(ownedFileArray); |
|
102 } |
|
103 |
|
104 // |
|
105 // class CAppAndViewListItem |
|
106 // |
|
107 |
|
108 class CAppAndViewListItem : public CHierListItem |
|
109 { |
|
110 public: |
|
111 CAppAndViewListItem(TInt16 aFlags); |
|
112 ~CAppAndViewListItem(); |
|
113 void SetIcon(CGulIcon* aIcon); |
|
114 CGulIcon* Icon() const; |
|
115 void SetAppUid(TUid aUid); |
|
116 TUid AppUid() const; |
|
117 void SetViewUid(TUid aUid); |
|
118 TUid ViewUid() const; |
|
119 private: |
|
120 CGulIcon* iIcon; |
|
121 TUid iAppUid; |
|
122 TUid iViewUid; |
|
123 }; |
|
124 |
|
125 CAppAndViewListItem::CAppAndViewListItem(TInt16 aFlags) |
|
126 : CHierListItem(aFlags), |
|
127 iAppUid(KNullUid), iViewUid(KNullUid) |
|
128 { |
|
129 } |
|
130 |
|
131 CAppAndViewListItem::~CAppAndViewListItem() |
|
132 { |
|
133 delete iIcon; |
|
134 } |
|
135 |
|
136 void CAppAndViewListItem::SetIcon(CGulIcon* aIcon) |
|
137 { |
|
138 iIcon=aIcon; |
|
139 } |
|
140 |
|
141 CGulIcon* CAppAndViewListItem::Icon() const |
|
142 { |
|
143 return iIcon; |
|
144 } |
|
145 |
|
146 void CAppAndViewListItem::SetAppUid(TUid aUid) |
|
147 { |
|
148 iAppUid=aUid; |
|
149 } |
|
150 |
|
151 TUid CAppAndViewListItem::AppUid() const |
|
152 { |
|
153 return iAppUid; |
|
154 } |
|
155 |
|
156 void CAppAndViewListItem::SetViewUid(TUid aUid) |
|
157 { |
|
158 iViewUid=aUid; |
|
159 } |
|
160 |
|
161 TUid CAppAndViewListItem::ViewUid() const |
|
162 { |
|
163 return iViewUid; |
|
164 } |
|
165 |
|
166 |
|
167 // |
|
168 // class CAppAndViewListBoxModel |
|
169 // |
|
170 |
|
171 class CAppAndViewListBoxModel : public CHierarchicalListBoxModel |
|
172 { |
|
173 public: |
|
174 CAppAndViewListBoxModel(); |
|
175 ~CAppAndViewListBoxModel(); |
|
176 void CreateListL(); |
|
177 void ExpandItemL(TInt aNodeToBeExpanded); |
|
178 void UpdateL(); |
|
179 CAppAndViewListItem* AppAndViewItem(TInt aIndex) const; |
|
180 TInt ItemIconHeight() const; |
|
181 private: |
|
182 TInt iItemIconHeight; |
|
183 }; |
|
184 |
|
185 CAppAndViewListBoxModel::CAppAndViewListBoxModel() |
|
186 { |
|
187 } |
|
188 |
|
189 TInt CAppAndViewListBoxModel::ItemIconHeight() const |
|
190 { |
|
191 return iItemIconHeight; |
|
192 } |
|
193 |
|
194 CAppAndViewListItem* CAppAndViewListBoxModel::AppAndViewItem(TInt aIndex) const |
|
195 { |
|
196 return STATIC_CAST(CAppAndViewListItem*,Item(aIndex)); |
|
197 } |
|
198 |
|
199 void CAppAndViewListBoxModel::CreateListL() |
|
200 { |
|
201 RApaLsSession ls; |
|
202 CleanupClosePushL(ls); |
|
203 User::LeaveIfError(ls.Connect()); |
|
204 |
|
205 if (!iHierListArray) |
|
206 iHierListArray=new(ELeave) CArrayFixSeg<CHierListItem*>(5); |
|
207 else |
|
208 RemoveAllItems(); |
|
209 |
|
210 User::LeaveIfError(ls.GetAllApps()); |
|
211 TApaAppInfo info; |
|
212 TInt ret=ls.GetNextApp(info); |
|
213 TInt itemIndex=-1; |
|
214 |
|
215 CApaMaskedBitmap* appBitmap=CApaMaskedBitmap::NewLC(); |
|
216 CAppAndViewListItem* item=NULL; |
|
217 CGulIcon* icon=NULL; |
|
218 |
|
219 while (ret==KErrNone) |
|
220 { |
|
221 item=new(ELeave) CAppAndViewListItem((TInt16)0); |
|
222 CleanupStack::PushL(item); |
|
223 |
|
224 ls.GetAppIcon(info.iUid,0,*appBitmap); |
|
225 icon=CEikonEnv::Static()->CreateIconFromMaskedBitmapL(*appBitmap); |
|
226 item->SetIcon(icon); |
|
227 item->SetTextL(info.iCaption); |
|
228 item->SetAppUid(info.iUid); |
|
229 AddItemL(item,-1,itemIndex++); |
|
230 iItemIconHeight=Max(iItemIconHeight,icon->Bitmap()->SizeInPixels().iHeight); |
|
231 CleanupStack::Pop(); // item |
|
232 |
|
233 ret=ls.GetNextApp(info); |
|
234 } |
|
235 |
|
236 if (ret!=RApaLsSession::ENoMoreAppsInList && ret!=RApaLsSession::EAppListInvalid) |
|
237 User::Leave(ret); |
|
238 |
|
239 CleanupStack::PopAndDestroy(2); // appBitmap, ls |
|
240 } |
|
241 |
|
242 void CAppAndViewListBoxModel::ExpandItemL(TInt aItemToBeExpanded) |
|
243 { |
|
244 const TInt index=aItemToBeExpanded; |
|
245 CAppAndViewListItem* itemToBeExpanded=AppAndViewItem(index); |
|
246 if (itemToBeExpanded->IsExpanded()) |
|
247 return; |
|
248 if (itemToBeExpanded->Level()!=0) |
|
249 return; |
|
250 |
|
251 RApaLsSession ls; |
|
252 CleanupClosePushL(ls); |
|
253 User::LeaveIfError(ls.Connect()); |
|
254 User::LeaveIfError(ls.GetAllApps()); |
|
255 |
|
256 CApaAppViewArray* appViews=new(ELeave) CApaAppViewArray(5); |
|
257 CleanupStack::PushL(appViews); |
|
258 TUid appUid(itemToBeExpanded->AppUid()); |
|
259 ls.GetAppViews(*appViews, appUid); |
|
260 TInt newItemIndex=index; |
|
261 |
|
262 CApaMaskedBitmap* viewBitmap=CApaMaskedBitmap::NewLC(); |
|
263 CGulIcon* icon=NULL; |
|
264 |
|
265 const TInt count=appViews->Count(); |
|
266 for (TInt ii=0; ii<count; ii++) |
|
267 { |
|
268 CAppAndViewListItem* newItem=new(ELeave) CAppAndViewListItem((TInt16)0); |
|
269 CleanupStack::PushL(newItem); |
|
270 const TApaAppViewInfo& viewInfo=(*appViews)[ii]; |
|
271 newItem->SetTextL(viewInfo.iViewCaption); |
|
272 newItem->SetViewUid(viewInfo.iUid); |
|
273 newItem->SetAppUid(appUid); |
|
274 |
|
275 ls.GetAppViewIcon(itemToBeExpanded->AppUid(),viewInfo.iUid,TSize(24,24),*viewBitmap); |
|
276 icon=CEikonEnv::Static()->CreateIconFromMaskedBitmapL(*viewBitmap); |
|
277 newItem->SetIcon(icon); |
|
278 |
|
279 AddItemL(newItem,index,newItemIndex++); |
|
280 CleanupStack::Pop(); // newItem |
|
281 } |
|
282 |
|
283 itemToBeExpanded->SetExpanded(); |
|
284 CleanupStack::PopAndDestroy(3); // ls, appViews, viewBitmap |
|
285 } |
|
286 |
|
287 void CAppAndViewListBoxModel::UpdateL() |
|
288 { |
|
289 // Update not implemented - requires scanning for application installation which is not needed for this test |
|
290 } |
|
291 |
|
292 CAppAndViewListBoxModel::~CAppAndViewListBoxModel() |
|
293 { |
|
294 } |
|
295 |
|
296 |
|
297 |
|
298 // |
|
299 // class CAppAndViewListItemDrawer |
|
300 // |
|
301 |
|
302 class CAppAndViewListItemDrawer : public CHierarchicalListItemDrawer |
|
303 { |
|
304 public: |
|
305 CAppAndViewListItemDrawer(CAppAndViewListBoxModel* aModel,const CFont* aFont, |
|
306 CArrayPtr<CGulIcon>* aIconArray); |
|
307 private: // from CHierarchicalListItemDrawer |
|
308 CGulIcon* ItemIcon(TInt aItemIndex) const; |
|
309 }; |
|
310 |
|
311 CAppAndViewListItemDrawer::CAppAndViewListItemDrawer(CAppAndViewListBoxModel* aModel, |
|
312 const CFont* aFont, |
|
313 CArrayPtr<CGulIcon>* aIconArray) |
|
314 : CHierarchicalListItemDrawer(aModel,aFont,aIconArray) |
|
315 {} |
|
316 |
|
317 CGulIcon* CAppAndViewListItemDrawer::ItemIcon(TInt aItemIndex) const |
|
318 { |
|
319 return STATIC_CAST(CAppAndViewListBoxModel*,iModel)->AppAndViewItem(aItemIndex)->Icon(); |
|
320 } |
|
321 |
|
322 |
|
323 // |
|
324 // class CAppAndViewListBox |
|
325 // |
|
326 |
|
327 |
|
328 class CAppAndViewListBox : public CEikHierarchicalListBox, public MHierarchicalListExpansionObserver |
|
329 { |
|
330 public: |
|
331 CAppAndViewListBox(); |
|
332 ~CAppAndViewListBox(); |
|
333 void ConstructL(const CCoeControl* aParent,TInt aFlags); |
|
334 void CreateListL(); |
|
335 void UpdateL(); |
|
336 CAppAndViewListBoxModel* AppAndViewModel() const; |
|
337 public: // from MHierExpansionObserver |
|
338 void UpdateHierarchyL(TInt aItemIndex); |
|
339 private: |
|
340 void BaseConstructL(); |
|
341 }; |
|
342 |
|
343 |
|
344 CAppAndViewListBox::CAppAndViewListBox() |
|
345 { |
|
346 } |
|
347 |
|
348 CAppAndViewListBox::~CAppAndViewListBox() |
|
349 { |
|
350 } |
|
351 |
|
352 void CAppAndViewListBox::ConstructL(const CCoeControl* aParent,TInt aFlags) |
|
353 { |
|
354 aFlags&=~EIncrementalMatching; // don't want incremental matching |
|
355 iListBoxFlags=aFlags; |
|
356 BaseConstructL(); |
|
357 AppAndViewModel()->ConstructL(); |
|
358 CEikListBox::ConstructL(aParent,aFlags); |
|
359 AppAndViewModel()->SetExpansionObserver(this); |
|
360 } |
|
361 |
|
362 void CAppAndViewListBox::BaseConstructL() |
|
363 { |
|
364 iModel=new(ELeave) CAppAndViewListBoxModel(); |
|
365 iItemDrawer=new(ELeave) CAppAndViewListItemDrawer((CAppAndViewListBoxModel*)iModel,iEikonEnv->NormalFont(),NULL); |
|
366 } |
|
367 |
|
368 void CAppAndViewListBox::UpdateL() |
|
369 { |
|
370 AppAndViewModel()->UpdateL(); |
|
371 View()->CalcBottomItemIndex(); |
|
372 if (AppAndViewModel()->NumberOfItems()>0) |
|
373 SetCurrentItemIndex(0); |
|
374 UpdateScrollBarsL(); |
|
375 } |
|
376 |
|
377 void CAppAndViewListBox::UpdateHierarchyL(TInt aItemIndex) |
|
378 { |
|
379 if (View()->ItemIsVisible(aItemIndex)) |
|
380 { |
|
381 View()->CalcDataWidth(); |
|
382 View()->CalcBottomItemIndex(); |
|
383 DrawNow(); |
|
384 } |
|
385 UpdateScrollBarsL(); |
|
386 } |
|
387 |
|
388 CAppAndViewListBoxModel* CAppAndViewListBox::AppAndViewModel() const |
|
389 { |
|
390 return (CAppAndViewListBoxModel*)iModel; |
|
391 } |
|
392 |
|
393 void CAppAndViewListBox::CreateListL() |
|
394 { |
|
395 Reset(); |
|
396 CAppAndViewListBoxModel* model=AppAndViewModel(); |
|
397 model->CreateListL(); |
|
398 SetItemHeightL(Max(ItemHeight(),model->ItemIconHeight()+2)); |
|
399 iView->CalcBottomItemIndex(); |
|
400 } |
|
401 |
|
402 |
|
403 // |
|
404 // CInstalledViewListContainer |
|
405 // |
|
406 |
|
407 class CInstalledViewListContainer : public CCoeControl |
|
408 { |
|
409 public: |
|
410 CInstalledViewListContainer(); |
|
411 void ConstructL(const TRect& aRect); |
|
412 ~CInstalledViewListContainer(); |
|
413 void ListOwnedFilesL(); |
|
414 private: // from CCoeControl |
|
415 void Draw(const TRect& aRect) const; |
|
416 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType); |
|
417 TInt CountComponentControls() const; |
|
418 CCoeControl* ComponentControl(TInt aIndex) const; |
|
419 private: |
|
420 CAppAndViewListBox* iAppAndViewListBox; |
|
421 }; |
|
422 |
|
423 CInstalledViewListContainer::~CInstalledViewListContainer() |
|
424 { |
|
425 delete iAppAndViewListBox; |
|
426 } |
|
427 |
|
428 CInstalledViewListContainer::CInstalledViewListContainer() |
|
429 {} |
|
430 |
|
431 TInt CInstalledViewListContainer::CountComponentControls() const |
|
432 { |
|
433 return 1; |
|
434 } |
|
435 |
|
436 CCoeControl* CInstalledViewListContainer::ComponentControl(TInt /*aIndex*/) const |
|
437 { |
|
438 return iAppAndViewListBox; |
|
439 } |
|
440 |
|
441 const TInt KXStart = 20; |
|
442 const TInt KYStart = 10; |
|
443 //const TInt KXSpacing = 5; |
|
444 //const TInt KYSpacing = 10; |
|
445 //const TInt KControlWidth = 180; |
|
446 |
|
447 void CInstalledViewListContainer::ConstructL(const TRect& aRect) |
|
448 { |
|
449 CreateWindowL(); |
|
450 Window().SetShadowDisabled(ETrue); |
|
451 Window().SetPointerGrab(ETrue); |
|
452 SetRect(aRect); |
|
453 |
|
454 TInt yPos = KYStart; |
|
455 TInt xPos = KXStart; |
|
456 |
|
457 iAppAndViewListBox = new(ELeave) CAppAndViewListBox; |
|
458 iAppAndViewListBox->ConstructL(this,0); |
|
459 iAppAndViewListBox->CreateScrollBarFrameL(); |
|
460 iAppAndViewListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
461 iAppAndViewListBox->SetExtent(TPoint(xPos, yPos), TSize(Size().iWidth-(2*xPos), Size().iHeight-(2*yPos))); |
|
462 iAppAndViewListBox->CreateListL(); |
|
463 iAppAndViewListBox->HandleItemAdditionL(); |
|
464 iAppAndViewListBox->SetFocus(ETrue); |
|
465 |
|
466 ActivateL(); |
|
467 } |
|
468 |
|
469 void CInstalledViewListContainer::Draw(const TRect& /*aRect*/) const |
|
470 { |
|
471 CWindowGc& gc = SystemGc(); |
|
472 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
473 gc.SetBrushColor(iEikonEnv->ControlColor(EColorControlSurroundBackground,*this)); |
|
474 gc.DrawRect(Rect()); |
|
475 } |
|
476 |
|
477 TKeyResponse CInstalledViewListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
478 { |
|
479 return iAppAndViewListBox->OfferKeyEventL(aKeyEvent, aType); |
|
480 } |
|
481 |
|
482 void CInstalledViewListContainer::ListOwnedFilesL() |
|
483 { |
|
484 |
|
485 CAppAndViewListItem* item=iAppAndViewListBox->AppAndViewModel()->AppAndViewItem(iAppAndViewListBox->CurrentItemIndex()); |
|
486 CEikDialog* dialog = new(ELeave) COwnedFilesDialog(item->AppUid()); |
|
487 dialog->ExecuteLD(R_TVIEW4_OWNED_FILE_DLG); |
|
488 } |
|
489 |
|
490 |
|
491 // |
|
492 // class CTestAppUi |
|
493 // |
|
494 |
|
495 class CTestAppUi : public CEikAppUi |
|
496 { |
|
497 public: |
|
498 CTestAppUi(); |
|
499 void ConstructL(); |
|
500 ~CTestAppUi(); |
|
501 private: // framework |
|
502 void HandleCommandL(TInt aCommand); |
|
503 private: |
|
504 CInstalledViewListContainer* iListContainer; |
|
505 }; |
|
506 |
|
507 |
|
508 CTestAppUi::~CTestAppUi() |
|
509 { |
|
510 RemoveFromStack(iListContainer); |
|
511 delete iListContainer; |
|
512 } |
|
513 |
|
514 CTestAppUi::CTestAppUi() |
|
515 { |
|
516 delete iListContainer; |
|
517 } |
|
518 |
|
519 void CTestAppUi::ConstructL() |
|
520 { |
|
521 BaseConstructL(); |
|
522 |
|
523 iListContainer=new(ELeave) CInstalledViewListContainer; |
|
524 iListContainer->ConstructL(ClientRect()); |
|
525 AddToStackL(iListContainer); |
|
526 } |
|
527 |
|
528 void CTestAppUi::HandleCommandL(TInt aCommand) |
|
529 { |
|
530 switch (aCommand) |
|
531 { |
|
532 case EAppCmdListOwnedFiles: |
|
533 iListContainer->ListOwnedFilesL(); |
|
534 break; |
|
535 case EEikCmdExit: |
|
536 Exit(); |
|
537 break; |
|
538 default: |
|
539 break; |
|
540 } |
|
541 } |
|
542 |
|
543 |
|
544 // |
|
545 // CTestDocument |
|
546 // |
|
547 |
|
548 class CTestDocument : public CEikDocument |
|
549 { |
|
550 public: |
|
551 CTestDocument(CEikApplication& aApp): CEikDocument(aApp) { } |
|
552 private: // from CApaDocument |
|
553 CEikAppUi* CreateAppUiL(); |
|
554 }; |
|
555 |
|
556 CEikAppUi* CTestDocument::CreateAppUiL() |
|
557 { |
|
558 return(new(ELeave) CTestAppUi); |
|
559 } |
|
560 |
|
561 // |
|
562 // CTestApplication |
|
563 // |
|
564 |
|
565 class CTestApplication : public CEikApplication |
|
566 { |
|
567 private: // from CApaApplication |
|
568 CApaDocument* CreateDocumentL(); |
|
569 TUid AppDllUid() const; |
|
570 private: |
|
571 CApaDocument* CreateDocumentL(CApaProcess* a) { return CEikApplication::CreateDocumentL(a); } |
|
572 }; |
|
573 |
|
574 const TUid KUidTestApp={0x10207F70}; |
|
575 |
|
576 TUid CTestApplication::AppDllUid() const |
|
577 { |
|
578 return(KUidTestApp); |
|
579 } |
|
580 |
|
581 CApaDocument* CTestApplication::CreateDocumentL() |
|
582 { |
|
583 return(new(ELeave) CTestDocument(*this)); |
|
584 } |
|
585 |
|
586 // |
|
587 // EXPORTed functions |
|
588 // |
|
589 |
|
590 |
|
591 LOCAL_C CApaApplication* NewApplication() |
|
592 { |
|
593 return new CTestApplication; |
|
594 } |
|
595 |
|
596 GLDEF_C TInt E32Main() |
|
597 { |
|
598 return EikStart::RunApplication(NewApplication); |
|
599 } |
|
600 |
|
601 |
|
602 |