memspyui/source/MemSpyViewDriveInfo.cpp
changeset 0 d6fe6244b863
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     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 *
       
    16 */
       
    17 
       
    18 #include "MemSpyViewDriveInfo.h"
       
    19 
       
    20 // System includes
       
    21 #include <memspyui.rsg>
       
    22 
       
    23 // Engine includes
       
    24 #include <memspy/engine/memspyengine.h>
       
    25 #include <memspy/engine/memspyengineobjectprocess.h>
       
    26 #include <memspy/engine/memspyengineobjectthread.h>
       
    27 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    28 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    29 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    30 #include <memspy/engine/memspyenginehelperprocess.h>
       
    31 #include <memspy/engine/memspyenginehelperfilesystem.h>
       
    32 
       
    33 // User includes
       
    34 #include "MemSpyUiUtils.h"
       
    35 #include "MemSpyViewMainMenu.h"
       
    36 
       
    37 
       
    38 
       
    39 CMemSpyViewDriveInfoBase::CMemSpyViewDriveInfoBase( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver )
       
    40 :   CMemSpyViewBase( aEngine, aObserver )
       
    41     {
       
    42     }
       
    43 
       
    44 
       
    45 CMemSpyViewDriveInfoBase::~CMemSpyViewDriveInfoBase()
       
    46     {
       
    47     if  ( iList )
       
    48         {
       
    49         iList->SetObserver( NULL );
       
    50         }
       
    51     //
       
    52     delete iList;
       
    53     }
       
    54 
       
    55 
       
    56 void CMemSpyViewDriveInfoBase::BaseConstructL()
       
    57     {
       
    58     iList = iEngine.HelperFileSystem().DriveListL();
       
    59     }
       
    60 
       
    61 
       
    62 TBool CMemSpyViewDriveInfoBase::HandleCommandL( TInt aCommand )
       
    63     {
       
    64     TBool handled = ETrue;
       
    65     //
       
    66     switch ( aCommand )
       
    67         {
       
    68     default:
       
    69         handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
    70         break;
       
    71         }
       
    72     //
       
    73     return handled;
       
    74     }
       
    75 
       
    76 
       
    77 
       
    78 
       
    79 
       
    80 
       
    81 
       
    82 
       
    83 
       
    84 
       
    85 
       
    86 
       
    87 
       
    88 
       
    89 
       
    90 
       
    91 
       
    92 
       
    93 
       
    94 
       
    95 
       
    96 
       
    97 
       
    98 
       
    99 
       
   100 
       
   101 
       
   102 
       
   103 
       
   104 
       
   105 CMemSpyViewDriveList::CMemSpyViewDriveList( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver )
       
   106 :   CMemSpyViewDriveInfoBase( aEngine, aObserver ), iUseDriveNumber( EFalse ), iDriveNumber( EDriveA )
       
   107     {
       
   108     }
       
   109 
       
   110 
       
   111 CMemSpyViewDriveList::CMemSpyViewDriveList( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver, TDriveNumber aDriveNumber )
       
   112 :   CMemSpyViewDriveInfoBase( aEngine, aObserver ), iUseDriveNumber( ETrue ), iDriveNumber( aDriveNumber )
       
   113     {
       
   114     }
       
   115 
       
   116 
       
   117 void CMemSpyViewDriveList::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
   118     {
       
   119     BaseConstructL();
       
   120 
       
   121     _LIT( KTitle, "Drive Summary" );
       
   122     SetTitleL( KTitle );
       
   123 
       
   124     // Start watching list
       
   125     iList->SetObserver( this );
       
   126 
       
   127     // Finish construction
       
   128     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
   129 
       
   130     if  ( iUseDriveNumber )
       
   131         {
       
   132 #ifdef _DEBUG
       
   133         RDebug::Printf( "CMemSpyViewDriveList::ConstructL() - iDriveNumber: %c:", iDriveNumber + 'A' );
       
   134 #endif
       
   135         iCurrentDrive = iList->EntryByDriveNumber( iDriveNumber );
       
   136 
       
   137 #ifdef _DEBUG
       
   138         RDebug::Printf( "CMemSpyViewDriveList::ConstructL() - iCurrentDrive: 0x%08x", iCurrentDrive );
       
   139 #endif
       
   140         if  ( iCurrentDrive )
       
   141             {
       
   142             const TInt index = iList->ItemIndex( *iCurrentDrive );
       
   143 #ifdef _DEBUG
       
   144             RDebug::Printf( "CMemSpyViewDriveList::ConstructL() - index: %d", index );
       
   145 #endif
       
   146             iListBox->SetCurrentItemIndex( index );
       
   147             HandleListBoxItemSelectedL( index );
       
   148             }
       
   149         }
       
   150     
       
   151     iListBox->DrawDeferred();
       
   152     }
       
   153 
       
   154 
       
   155 TMemSpyViewType CMemSpyViewDriveList::ViewType() const
       
   156     {
       
   157     return EMemSpyViewTypeDriveSummary;
       
   158     }
       
   159 
       
   160 
       
   161 CMemSpyViewBase* CMemSpyViewDriveList::PrepareParentViewL()
       
   162     {
       
   163     CMemSpyViewMainMenu* parent = new(ELeave) CMemSpyViewMainMenu( iEngine, iObserver );
       
   164     CleanupStack::PushL( parent );
       
   165     parent->ConstructL( Rect(), *Parent(), (TAny*) ViewType() );
       
   166     CleanupStack::Pop( parent );
       
   167     //
       
   168     if  ( parent )
       
   169         {
       
   170         iList->SetObserver( NULL );
       
   171         }
       
   172     //
       
   173     return parent;
       
   174     }
       
   175 
       
   176 
       
   177 CMemSpyViewBase* CMemSpyViewDriveList::PrepareChildViewL()
       
   178     {
       
   179     ASSERT( iCurrentDrive );
       
   180     CMemSpyViewBase* child = new(ELeave) CMemSpyViewDriveInfo( iEngine, iObserver, iCurrentDrive->DriveNumber() );
       
   181 
       
   182     // Stop watching list
       
   183     if  ( child )
       
   184         {
       
   185         iList->SetObserver( NULL );
       
   186         }
       
   187 
       
   188     // Ownership is transferred to child. Cleanupstack guarantees it will be destroyed now.
       
   189     // This object is about to die in any case.
       
   190     iList = NULL;
       
   191 
       
   192     CleanupStack::PushL( child );
       
   193     child->ConstructL( Rect(), *Parent() );
       
   194     CleanupStack::Pop( child );
       
   195     return child;
       
   196     }
       
   197 
       
   198 
       
   199 void CMemSpyViewDriveList::RefreshL()
       
   200     {
       
   201     if  ( iList )
       
   202         {
       
   203         iList->SetObserver( NULL );
       
   204         }
       
   205     //
       
   206     CMemSpyEngineDriveList* list = iEngine.HelperFileSystem().DriveListL();
       
   207     delete iList;
       
   208     iList = list;
       
   209     iList->SetObserver( this );
       
   210     //
       
   211     SetListBoxModelL();
       
   212     CMemSpyViewBase::RefreshL();
       
   213     }
       
   214 
       
   215 
       
   216 void CMemSpyViewDriveList::SetListBoxModelL()
       
   217     {
       
   218     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   219     listbox->Model()->SetItemTextArray( iList );
       
   220     listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   221     }
       
   222 
       
   223 
       
   224 void CMemSpyViewDriveList::HandleListBoxItemActionedL( TInt aIndex )
       
   225     {
       
   226     const TInt count = iList->Count();
       
   227     if  ( aIndex >= 0 && aIndex < count )
       
   228         {
       
   229         CMemSpyEngineDriveEntry& entry = iList->At( aIndex );
       
   230         iCurrentDrive = &entry;
       
   231         }
       
   232     else
       
   233         {
       
   234         iCurrentDrive = NULL;
       
   235         }
       
   236 
       
   237     // Notify observer about item selection
       
   238     ReportEventL( MMemSpyViewObserver::EEventItemActioned );
       
   239     }
       
   240 
       
   241 
       
   242 void CMemSpyViewDriveList::HandleListBoxItemSelectedL( TInt aIndex )
       
   243     {
       
   244     const TInt count = iList->Count();
       
   245     if  ( aIndex >= 0 && aIndex < count )
       
   246         {
       
   247         CMemSpyEngineDriveEntry& entry = iList->At( aIndex );
       
   248         iCurrentDrive = &entry;
       
   249         }
       
   250     else
       
   251         {
       
   252         iCurrentDrive = NULL;
       
   253         }
       
   254 
       
   255     // Notify observer about item selection
       
   256     ReportEventL( MMemSpyViewObserver::EEventItemSelected );
       
   257     }
       
   258 
       
   259 
       
   260 void CMemSpyViewDriveList::HandleDriveListChangedL( const CMemSpyEngineDriveList& /*aList*/ )
       
   261     {
       
   262     RefreshL();
       
   263     }
       
   264 
       
   265 
       
   266 
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 
       
   272 
       
   273 
       
   274 
       
   275 
       
   276 
       
   277 
       
   278 
       
   279 
       
   280 
       
   281 
       
   282 
       
   283 
       
   284 
       
   285 
       
   286 
       
   287 
       
   288 
       
   289 
       
   290 
       
   291 
       
   292 
       
   293 
       
   294 
       
   295 
       
   296 
       
   297 CMemSpyViewDriveInfo::CMemSpyViewDriveInfo( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver, TDriveNumber aDriveNumber )
       
   298 :   CMemSpyViewDriveInfoBase( aEngine, aObserver ), iDriveNumber( aDriveNumber )
       
   299     {
       
   300     }
       
   301 
       
   302 
       
   303 void CMemSpyViewDriveInfo::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
   304     {
       
   305     BaseConstructL();
       
   306     //
       
   307     iDriveInfo = iList->EntryByDriveNumber( iDriveNumber );
       
   308     if  ( !iDriveInfo )
       
   309         {
       
   310         User::Leave( KErrNotFound );
       
   311         }
       
   312     iDriveInfo->SetObserver( this );
       
   313 
       
   314     _LIT( KTitleFormat, "Drive %S Info" );
       
   315     const TDriveName name( iDriveInfo->DriveUnit().Name() );
       
   316     TName title;
       
   317     title.Format( KTitleFormat, &name );
       
   318     SetTitleL( title );
       
   319 
       
   320     // Finish construction
       
   321     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
   322     }
       
   323 
       
   324 
       
   325 void CMemSpyViewDriveInfo::RefreshL()
       
   326     {
       
   327     SetListBoxModelL();
       
   328     CMemSpyViewBase::RefreshL();
       
   329     }
       
   330 
       
   331 
       
   332 TMemSpyViewType CMemSpyViewDriveInfo::ViewType() const
       
   333     {
       
   334     return EMemSpyViewTypeDriveInfo;
       
   335     }
       
   336 
       
   337 
       
   338 CMemSpyViewBase* CMemSpyViewDriveInfo::PrepareParentViewL()
       
   339     {
       
   340     ASSERT( iDriveInfo );
       
   341     CMemSpyViewDriveList* parent = new(ELeave) CMemSpyViewDriveList( iEngine, iObserver, iDriveInfo->DriveNumber() );
       
   342     CleanupStack::PushL( parent );
       
   343     parent->ConstructL( Rect(), *Parent() );
       
   344     CleanupStack::Pop( parent );
       
   345     //
       
   346     if  ( parent )
       
   347         {
       
   348         iDriveInfo->SetObserver( NULL );
       
   349         }
       
   350     //
       
   351     return parent;
       
   352     }
       
   353 
       
   354 
       
   355 void CMemSpyViewDriveInfo::SetListBoxModelL()
       
   356     {
       
   357     if  ( iDriveInfo )
       
   358         {
       
   359         CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   360         listbox->Model()->SetItemTextArray( iDriveInfo );
       
   361         listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   362         }
       
   363     }
       
   364 
       
   365 
       
   366 void CMemSpyViewDriveInfo::HandleDriveEntryChangedL( const CMemSpyEngineDriveEntry& /*aEntry*/ )
       
   367     {
       
   368     RefreshL();
       
   369     }
       
   370 
       
   371 
       
   372 
       
   373 
       
   374 
       
   375 
       
   376 
       
   377 
       
   378 
       
   379 
       
   380 
       
   381