stifui/stifui/src/TestSetStartedCasesContainer.cpp
branchRCL_3
changeset 9 404ad6c9bc20
parent 8 87e9ebfbe96a
child 11 454d022d514b
equal deleted inserted replaced
8:87e9ebfbe96a 9:404ad6c9bc20
     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: This file contains CTestSetStartedCasesContainer 
       
    15 * class definition.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <aknlists.h>  // ListBox
       
    22 #include <AknIconArray.h>  // CAknIconArray
       
    23 #include <badesca.h> // CDesCArray
       
    24 #include <eikclbd.h> // CColumnListBoxData
       
    25 #include <aknnotewrappers.h>
       
    26 
       
    27 #include <Stifui.rsg>
       
    28 
       
    29 //#include "UIStoreIf.h"         
       
    30 //#include "UIStore.h"            
       
    31 //#include "UIEngine.h"           
       
    32 //#include "UIEngineContainer.h"  
       
    33 
       
    34 #include <stifinternal/UIStoreIf.h>
       
    35 #include <stifinternal/UIStore.h>
       
    36 #include <stifinternal/UIEngine.h>
       
    37 #include <stifinternal/UIEngineContainer.h>
       
    38 
       
    39 #include "TestSetStartedCasesContainer.h"
       
    40 #include "ShowStartedCasesContainer.h"
       
    41 #include "Stifui.hrh"
       
    42 #include "AppUIAppUi.h"
       
    43 
       
    44 #include "MenuListBox.h"
       
    45 
       
    46 // ================= MEMBER FUNCTIONS =======================
       
    47 // ----------------------------------------------------------------------------
       
    48 // CTestSetStartedCasesContainer::ConstructL
       
    49 // 
       
    50 // Symbian OS two phased constructor.
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 void CTestSetStartedCasesContainer::ConstructL(const TRect& aRect, MEikListBoxObserver* aListBoxObserver)
       
    54     {
       
    55     CreateWindowL();
       
    56 
       
    57     iUIStore = ( (CAppUIAppUi*)iCoeEnv->AppUi() )->UIStoreHandler();
       
    58     
       
    59 	iListBox = CMenuListBox::NewL(ETestSetStartedCasesViewId); /*CAknSingleStyleListBox();*/
       
    60 	iListBox->SetContainerWindowL( *this );
       
    61 	iListBox->SetListBoxObserver( aListBoxObserver );
       
    62     iListBox->ConstructL(this, EAknListBoxSelectionList);
       
    63 
       
    64     //Create Scroller control for ListBox and set its visibility
       
    65     iListBox->CreateScrollBarFrameL(ETrue);
       
    66     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);
       
    67 
       
    68     if ( iUIStore )
       
    69         {
       
    70         
       
    71         iListBoxModel = CStartedTestsListBoxModel::NewL( &iStartedTestsPtrs );
       
    72         iListBox->Model()->SetItemTextArray(iListBoxModel);
       
    73         ConstructListBoxModelL();
       
    74         iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
       
    75         iListBox->HandleItemAdditionL();
       
    76 
       
    77         }
       
    78     else
       
    79         {
       
    80         //User::Leave( syy?? )
       
    81         }
       
    82 	iListBox->ActivateL();
       
    83 	((CMenuListBox*)iListBox)->SetPreviousFocus();
       
    84 
       
    85     SetRect(aRect);
       
    86     ActivateL();
       
    87 
       
    88     }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // CTestSetStartedCasesContainer::ConstructListBoxModelL
       
    92 // 
       
    93 // Constructs list box model without any filtering.
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 void CTestSetStartedCasesContainer::ConstructListBoxModelL()
       
    97     {
       
    98     TInt items(0);
       
    99     TInt index = ((CAppUIAppUi*)iCoeEnv->AppUi())->iStartedTestSet;
       
   100     
       
   101     // Check if there is started test sets and if there is,
       
   102     // show test setīs info.
       
   103     if ( index != -1 )
       
   104         {
       
   105         const RRefArray<CStartedTestCase>* startedTestCases;
       
   106         CStartedTestSet* startedTestSet =
       
   107      	    &iUIStore->StartedTestSetL( index );
       
   108         startedTestCases = &startedTestSet->TestCases();
       
   109         
       
   110         const TInt KStartedCaseCount = startedTestCases->Count();
       
   111 
       
   112         items = iStartedTestsPtrs.Count();
       
   113         iStartedTestsPtrs.Reset(); // Remove all pointers (does not delete objects)
       
   114         iListBox->HandleItemRemovalL();
       
   115         
       
   116         const TInt KSelectedMode = ((CAppUIAppUi*)iCoeEnv->AppUi())->iShowStartedCasesMode;
       
   117         
       
   118         // Loop through all started cases
       
   119         for( TInt i=0; i < KStartedCaseCount; i++ )
       
   120             {
       
   121             switch ( KSelectedMode )
       
   122                 {
       
   123                 case EShowAllStartedCases:
       
   124                     {
       
   125                     iStartedTestsPtrs.Append( startedTestCases->operator[](i) );
       
   126                     break;
       
   127                     }
       
   128                 case EShowOngoingCases:
       
   129                     {
       
   130                     // Note: PAUSE IS ALSO RUNNIN STATUS
       
   131                     if ( startedTestCases->operator[](i).Status() & CUIStoreIf::EStatusRunning )
       
   132                         {
       
   133                         iStartedTestsPtrs.Append( startedTestCases->operator[](i) );
       
   134                         }
       
   135                     break;
       
   136                     }
       
   137                 case EShowPassedCases:
       
   138                     {
       
   139                     if ( startedTestCases->operator[](i).Status() & CUIStoreIf::EStatusPassed )
       
   140                         {
       
   141                         iStartedTestsPtrs.Append( startedTestCases->operator[](i) );
       
   142                         }
       
   143                     break;
       
   144                     }
       
   145                 case EShowPausedCases:
       
   146                     {
       
   147                     if ( startedTestCases->operator[](i).Status() & CUIStoreIf::EStatusRunning )
       
   148                         {
       
   149                         if( startedTestCases->operator[](i).UIEngineContainer().State() == CUIEngineContainer::EPaused )
       
   150                             {
       
   151                             iStartedTestsPtrs.Append( startedTestCases->operator[](i) );
       
   152                             }
       
   153                         }
       
   154                     break;
       
   155                     }
       
   156                 case EShowFailedCases:
       
   157                     {
       
   158                     if ( startedTestCases->operator[](i).Status() & CUIStoreIf::EStatusFailed )
       
   159                         {
       
   160                         iStartedTestsPtrs.Append( startedTestCases->operator[](i) );
       
   161                         }
       
   162                     break;
       
   163                     }
       
   164                 case EShowCrashedAbortedCases:
       
   165                     {
       
   166                     if ( startedTestCases->operator[](i).Status() & CUIStoreIf::EStatusAborted
       
   167                     		||
       
   168                     	 startedTestCases->operator[](i).Status() & CUIStoreIf::EStatusCrashed)
       
   169                         {
       
   170                         iStartedTestsPtrs.Append( startedTestCases->operator[](i) );
       
   171                         }
       
   172                     break;
       
   173                     }
       
   174                 }
       
   175         }   
       
   176 
       
   177         if ( items < iStartedTestsPtrs.Count() )
       
   178             {
       
   179             iListBox->HandleItemAdditionL();
       
   180             }
       
   181         else
       
   182             {
       
   183             iListBox->HandleItemRemovalL();
       
   184             }
       
   185            
       
   186         }
       
   187     }
       
   188 
       
   189 // ----------------------------------------------------------------------------
       
   190 // CTestSetStartedCasesContainer::~CTestSetStartedCasesContainer
       
   191 // 
       
   192 // Destructor.
       
   193 // ----------------------------------------------------------------------------
       
   194 //
       
   195 CTestSetStartedCasesContainer::~CTestSetStartedCasesContainer()
       
   196     {
       
   197     delete iListBox;
       
   198     
       
   199     iStartedTestsPtrs.Close(); // does not delete objects whose pointers are contained in the array
       
   200     
       
   201     }
       
   202 
       
   203 // ----------------------------------------------------------------------------
       
   204 // CTestSetStartedCasesContainer::SizeChanged
       
   205 // 
       
   206 // Called by framework when the view size is changed.
       
   207 // ----------------------------------------------------------------------------
       
   208 //
       
   209 void CTestSetStartedCasesContainer::SizeChanged()
       
   210     {
       
   211     if ( iListBox )
       
   212 		{
       
   213 		iListBox->SetRect( Rect() ); // Sets rectangle of listbox.
       
   214 		}
       
   215     }
       
   216 
       
   217 // ----------------------------------------------------------------------------
       
   218 // CTestSetStartedCasesContainer::CountComponentControls
       
   219 // 
       
   220 // Gets a count of the component controls of this list box control.
       
   221 // ----------------------------------------------------------------------------
       
   222 //
       
   223 TInt CTestSetStartedCasesContainer::CountComponentControls() const
       
   224     {
       
   225     return 1; // return nbr of controls inside this container
       
   226     }
       
   227 
       
   228 // ----------------------------------------------------------------------------
       
   229 // CTestSetStartedCasesContainer::ComponentControl
       
   230 // 
       
   231 // Gets a pointer to the specified component control.
       
   232 // ----------------------------------------------------------------------------
       
   233 //
       
   234 CCoeControl* CTestSetStartedCasesContainer::ComponentControl(TInt aIndex) const
       
   235     {
       
   236     switch ( aIndex )
       
   237         {
       
   238 		case 0: 
       
   239 			return iListBox;
       
   240         default:
       
   241             return NULL;
       
   242         }
       
   243     }
       
   244 
       
   245 // ----------------------------------------------------------------------------
       
   246 // CTestSetStartedCasesContainer::Draw
       
   247 // 
       
   248 // Draw a control, called by window server.
       
   249 // ----------------------------------------------------------------------------
       
   250 //
       
   251 void CTestSetStartedCasesContainer::Draw(const TRect& /*aRect*/) const
       
   252     {
       
   253     // CWindowGc& gc = SystemGc();
       
   254     }
       
   255 
       
   256 // ----------------------------------------------------------------------------
       
   257 // CTestSetStartedCasesContainer::OfferKeyEventL
       
   258 // 
       
   259 // Handles key events.
       
   260 // ----------------------------------------------------------------------------
       
   261 //
       
   262 TKeyResponse CTestSetStartedCasesContainer::OfferKeyEventL(
       
   263 	const TKeyEvent& aKeyEvent, TEventCode aType)
       
   264     {
       
   265     if (aType != EEventKey)
       
   266     {
       
   267 		return EKeyWasNotConsumed;
       
   268 	}
       
   269 
       
   270 	if (iListBox)
       
   271 		{
       
   272 		return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   273 		}
       
   274 	else
       
   275 		{
       
   276 		return EKeyWasNotConsumed;
       
   277 		}
       
   278 
       
   279     }
       
   280 
       
   281 // ----------------------------------------------------------------------------
       
   282 // CTestSetStartedCasesContainer::SelectedTestCase
       
   283 // 
       
   284 // Returns reference to currently selected test case in view (listbox).
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 CStartedTestCase* CTestSetStartedCasesContainer::SelectedTestCase()
       
   288     {
       
   289     if ( iStartedTestsPtrs.Count() > 0 )
       
   290         {
       
   291         return &(iStartedTestsPtrs[ iListBox->CurrentItemIndex() ]);
       
   292         }
       
   293     else
       
   294         {
       
   295         return NULL;
       
   296         }
       
   297 /*
       
   298     //if ( iListBox->ItemExists(0)  ) // Check that list box is not empty
       
   299     if ( ((CStartedTestsListBoxModel*)iListBox->Model())->MdcaCount()  ) // Check that list box is not empty
       
   300         {
       
   301         return &(iStartedTestsPtrs[ iListBox->CurrentItemIndex() ]);
       
   302         }
       
   303     else
       
   304         {
       
   305         return NULL;
       
   306         }
       
   307 */
       
   308     }
       
   309 
       
   310 // ----------------------------------------------------------------------------
       
   311 // CTestSetStartedCasesContainer::DrawListBox
       
   312 // 
       
   313 // Draws the list box.
       
   314 // ----------------------------------------------------------------------------
       
   315 //
       
   316 void CTestSetStartedCasesContainer::DrawListBox()
       
   317     {
       
   318     if ( iListBox )
       
   319         {
       
   320         iListBox->DrawNow();
       
   321         }
       
   322 
       
   323     }
       
   324 
       
   325 // ----------------------------------------------------------------------------
       
   326 // CTestSetStartedCasesContainer::HandleItemAdditionL
       
   327 // 
       
   328 // Handles the addition of an item to the model.
       
   329 // ----------------------------------------------------------------------------
       
   330 //
       
   331 void CTestSetStartedCasesContainer::HandleItemAdditionL()
       
   332     {
       
   333     iListBox->HandleItemAdditionL();
       
   334 
       
   335     }
       
   336 
       
   337 // ----------------------------------------------------------------------------
       
   338 // CTestSetStartedCasesContainer::HandleItemRemovalL
       
   339 // 
       
   340 // Handles the removal of an item from the model.
       
   341 // ----------------------------------------------------------------------------
       
   342 //
       
   343 void CTestSetStartedCasesContainer::HandleItemRemovalL()
       
   344     {
       
   345     //TInt itemIndexBeforeRemoval = iListBox->CurrentItemIndex();
       
   346 
       
   347     iListBox->HandleItemRemovalL();
       
   348 
       
   349     // HandleItemRemovalL "loses selection" if current item is removed
       
   350     // -> we have to check it and set one item as current item to make it possible for
       
   351     // user to select one item from items left after remove
       
   352     if ( iListBox->CurrentItemIndex() == -1 ) // No item selected
       
   353         if ( ((CStartedTestsListBoxModel*)iListBox->Model())->MdcaCount() > 0 ) // there are items
       
   354             SetCurrentItemIndex(0);
       
   355 
       
   356     }
       
   357 
       
   358 // ----------------------------------------------------------------------------
       
   359 // CTestSetStartedCasesContainer::TestsInViewCount
       
   360 // 
       
   361 // Returns count of test cases in view.
       
   362 // ----------------------------------------------------------------------------
       
   363 //
       
   364 TInt CTestSetStartedCasesContainer::TestsInViewCount()
       
   365     {
       
   366     return ((CStartedTestsListBoxModel*)iListBox->Model())->MdcaCount();
       
   367 
       
   368     }
       
   369 
       
   370 // ----------------------------------------------------------------------------
       
   371 // CTestSetStartedCasesContainer::CurrentTestCase
       
   372 // 
       
   373 // Returns pointer to currently selected test case.
       
   374 // ----------------------------------------------------------------------------
       
   375 //
       
   376 CStartedTestCase* CTestSetStartedCasesContainer::CurrentTestCase()
       
   377     {
       
   378     return &iStartedTestsPtrs[ iListBox->CurrentItemIndex() ];
       
   379     }
       
   380 
       
   381 // ----------------------------------------------------------------------------
       
   382 // CTestSetStartedCasesContainer::CurrentItemIndex
       
   383 // 
       
   384 // Gets the index number of the current item in the view.
       
   385 // ----------------------------------------------------------------------------
       
   386 //
       
   387 TInt CTestSetStartedCasesContainer::CurrentItemIndex()
       
   388     {
       
   389     return iListBox->CurrentItemIndex();
       
   390 
       
   391     }
       
   392 
       
   393 // ----------------------------------------------------------------------------
       
   394 // CTestSetStartedCasesContainer::SetCurrentItemIndex
       
   395 // 
       
   396 // Sets the current item.
       
   397 // ----------------------------------------------------------------------------
       
   398 //
       
   399 void CTestSetStartedCasesContainer::SetCurrentItemIndex(TInt aIndex)
       
   400     {
       
   401     TInt itemCount = ((CStartedTestsListBoxModel*)iListBox->Model())->MdcaCount();
       
   402     if ( aIndex < itemCount )
       
   403         {
       
   404         iListBox->SetCurrentItemIndex(aIndex);
       
   405         }
       
   406     else
       
   407         {
       
   408         iListBox->SetCurrentItemIndex(itemCount);
       
   409         }
       
   410 
       
   411     }
       
   412 
       
   413 // ----------------------------------------------------------------------------
       
   414 // CTestSetStartedCasesContainer::ResetListBox
       
   415 // 
       
   416 // Resets the selection indices, top and current item indices,
       
   417 // the selection, and the horizontal scroll offset of this list box.
       
   418 // This function does not redraw the list box.
       
   419 // ----------------------------------------------------------------------------
       
   420 //
       
   421 void CTestSetStartedCasesContainer::ResetListBox()
       
   422     {
       
   423     iListBox->Reset();
       
   424 
       
   425     }
       
   426 
       
   427 // ----------------------------------------------------------------------------
       
   428 // CTestSetStartedCasesContainer::RemoveSelectedExecutionsL
       
   429 // 
       
   430 // Removes items from list box.
       
   431 // ----------------------------------------------------------------------------
       
   432 //
       
   433 void CTestSetStartedCasesContainer::RemoveSelectedExecutionsL()
       
   434     {
       
   435     TInt indexOfRemovedExecution = 0;
       
   436     iStartedTestsPtrs.Remove(indexOfRemovedExecution);
       
   437     HandleItemRemovalL();
       
   438 
       
   439     }
       
   440 
       
   441 // ----------------------------------------------------------------------------
       
   442 // CTestSetStartedCasesContainer::RemoveAllExecutionsInViewL
       
   443 // 
       
   444 // Removes all started test cases from list box.
       
   445 // ----------------------------------------------------------------------------
       
   446 //
       
   447 void CTestSetStartedCasesContainer::RemoveAllExecutionsInViewL()
       
   448     {
       
   449     TInt exutionsInViewCount = iStartedTestsPtrs.Count();
       
   450     iStartedTestsPtrs.Reset(); //Empties the array, does not delete the objects whose pointers are contained in the array
       
   451     HandleItemRemovalL();
       
   452 
       
   453     }
       
   454 
       
   455 // ----------------------------------------------------------------------------
       
   456 // CTestSetStartedCasesContainer::SaveActiveLine
       
   457 //
       
   458 // Makes the iListBox member save its focus position
       
   459 // ----------------------------------------------------------------------------
       
   460 //	
       
   461 void CTestSetStartedCasesContainer::SaveActiveLine()
       
   462 	{
       
   463 	((CMenuListBox*)iListBox)->SaveFocusPosition();
       
   464 	}
       
   465 
       
   466 // End of File