photosgallery/viewframework/views/viewbase/src/glxtoolbarcontroller.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 31 Mar 2010 21:31:03 +0300
branchRCL_3
changeset 13 bcb43dc84c44
parent 0 4e91876724a2
child 14 2dac0fdba72b
permissions -rw-r--r--
Revision: 201011 Kit: 201013

/*
* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:    Media item list observer interface 
*
*/




#include "glxtoolbarcontroller.h"
#include <aknbutton.h>
#include <akntoolbar.h>                     // For Toolbar
#include <glxcommandhandlers.hrh>           // For Command ids
#include <glxtracer.h>                         // For Logs
#include <mglxmedialist.h>

#include <glxnavigationalstate.h>
#include <mpxcollectionpath.h>
#include <glxcollectionpluginimageviewer.hrh>
const TInt KGlxToolbarButtonUnLatched = 0;   // As per the states in resource file
const TInt KGlxToolbarButtonLatched = 1 ;

//----------------------------------------------------------------------------------
// NewL
//----------------------------------------------------------------------------------
//
CGlxToolbarController* CGlxToolbarController::NewL()
    {
    TRACER("CGlxToolbarController::NewL");
    
    CGlxToolbarController *self = new( ELeave ) CGlxToolbarController ();
    return self;
    }

//----------------------------------------------------------------------------------
// Default Constructor
//----------------------------------------------------------------------------------
//
CGlxToolbarController::CGlxToolbarController( )
    {
    TRACER("CGlxToolbarController::Default constructor");
    
    }
    
//----------------------------------------------------------------------------------
// AddToObserver
//----------------------------------------------------------------------------------
//
void CGlxToolbarController::AddToObserverL (MGlxMediaList& aList, CAknToolbar* aToolbar)
    {
    TRACER("CGlxToolbarController::AddToObserverL");

    iToolbar = aToolbar;
    iAttributeAvailable = EFalse;
    iToolbar->SetDimmed(ETrue);
    iToolbar->DrawNow();
    aList.AddMediaListObserverL ( this );
    }

//----------------------------------------------------------------------------------
// RemoveFromObserver 
//----------------------------------------------------------------------------------
//
void CGlxToolbarController::RemoveFromObserver (MGlxMediaList& aList)
    {
    TRACER("CGlxToolbarController::RemoveFromObserver");
    
    if( aList.SelectionCount()<= 0 )
        {
        EnableLatch( EGlxCmdStartMultipleMarking, EFalse );
        }

    aList.RemoveMediaListObserver ( this );
    }

//----------------------------------------------------------------------------
// HandleItemAddedL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::HandleItemAddedL(TInt /*aStartIndex*/, TInt /*aEndIndex*/, 
        MGlxMediaList* /*aList*/)
    {
    TRACER("CGlxToolbarController::HandleItemAddedL");
    
    }

//----------------------------------------------------------------------------
// HandleMediaL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::HandleMediaL(TInt /*aListIndex*/, MGlxMediaList* /*aList*/)
    {
    TRACER("CGlxToolbarController::HandleMediaL");
    
    }

//----------------------------------------------------------------------------
// HandleItemRemovedL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::HandleItemRemovedL(TInt /*aStartIndex*/, 
        TInt /*aEndIndex*/, MGlxMediaList* aList)
    {
    TRACER("CGlxToolbarController::HandleItemRemovedL");
    
    if( aList->Count() <= 0 )
        {
        iToolbar->SetDimmed(ETrue);
        iToolbar->DrawNow();
        }
    }

//----------------------------------------------------------------------------
// HandleItemModifiedL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::HandleItemModifiedL(const RArray<TInt>& /*aItemIndexes*/, 
        MGlxMediaList* /*aList*/)
    {
    TRACER("CGlxToolbarController::HandleItemModifiedL");
    
    }

//----------------------------------------------------------------------------
// HandleAttributesAvailableL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::HandleAttributesAvailableL(TInt aItemIndex, 
        const RArray<TMPXAttribute>& /*aAttributes*/, 
        MGlxMediaList* aList)
    {
    TRACER("CGlxToolbarController::HandleAttributesAvailableL");
    
    if( aItemIndex == aList->FocusIndex() )
        {        
        iAttributeAvailable = ETrue;
        SetStatusL(aList);
        }
    }

//----------------------------------------------------------------------------
// HandleFocusChangedL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::HandleFocusChangedL(NGlxListDefs::TFocusChangeType /*aType*/, 
        TInt aNewIndex, TInt /*aOldIndex*/, 
        MGlxMediaList* aList)
    {  
    TRACER("CGlxToolbarController::HandleFocusChangedL");
    
    // If new index is not equal to -1 (i.e., if there are some items present), 
    // then check the media item
    if( (aNewIndex == aList->FocusIndex()) && (KErrNotFound != aNewIndex) )
        {
        //Get the current media item from medialist
        const TGlxMedia& mediaItem = aList->Item(aList->FocusIndex());
        //Check whether media item is a system item, for example Favourites album
        TBool isSystemItem = EFalse;
        mediaItem.GetSystemItem(isSystemItem);
        if( mediaItem.IsStatic() )
            {
            iToolbar->SetDimmed(ETrue);  
            }
        else if( iToolbar->IsDimmed() )
            {
            iToolbar->SetDimmed(EFalse);
            }
        if( isSystemItem )
             {
             iToolbar->SetItemDimmed( EGlxCmdRename, ETrue, ETrue );
             }
        else
             {
             iToolbar->SetItemDimmed( EGlxCmdRename, EFalse, ETrue );   
            }
        }
    //DrawNow must be called since SetDimmed does not redraw the toolbar
    iToolbar->DrawNow();     
    }

//----------------------------------------------------------------------------
// HandleItemSelectedL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::HandleItemSelectedL(TInt /*aIndex*/, TBool /*aSelected*/, 
        MGlxMediaList* aList)
    {
    TRACER("CGlxToolbarController::HandleItemSelectedL");
    
    // If atleast 1 item is marked, or if Mark All is called, then Latch the mark button.
    if((aList->SelectionCount() == 1 ) || (aList->SelectionCount() == aList->Count()))
        {
        EnableLatch( EGlxCmdStartMultipleMarking, ETrue );
        }
    }

//----------------------------------------------------------------------------
// HandleMessageL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::HandleMessageL(const CMPXMessage& /*aMessage*/, 
        MGlxMediaList* /*aList*/)
    {
    TRACER("CGlxToolbarController::HandleMessageL");
    
    }

//----------------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------------
//
CGlxToolbarController::~CGlxToolbarController()
    {
    TRACER("CGlxToolbarController Destructor");
    
    }

//----------------------------------------------------------------------------
// SetStatusOnViewActivationL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::SetStatusOnViewActivationL( MGlxMediaList* aList )
     {
     	TRACER("CGlxToolbarController::SetStatusOnViewActivationL");
     	
     // When going back from fullscreen to grid, when the attributes are already 
     // available in the cache, there is no HandleAttributeAvailable callback. Hence,
     // checking for medialist count.
     if( !iAttributeAvailable && (aList->Count(NGlxListDefs::ECountNonStatic) > 0))
         {
         SetStatusL(aList);
         }    
     }

//----------------------------------------------------------------------------
//SetStatusL
//----------------------------------------------------------------------------
//
void CGlxToolbarController::SetStatusL(MGlxMediaList* aList)
	{
	TRACER("CGlxToolbarController::SetStatusL");
	if(KErrNotFound != aList->FocusIndex())
		{
		//Get the current media item from medialist
		const TGlxMedia& mediaItem = aList->Item(aList->FocusIndex());      

		//Check whether media item is a system item, for example Favourites album
		TBool isSystemItem = EFalse;    
		mediaItem.GetSystemItem(isSystemItem);

		if(!mediaItem.IsStatic() && iToolbar->IsDimmed())
			{
			//Activate (Undim) the toolbar if item in focus is not static
			iToolbar->SetDimmed(EFalse);            
			}    


		if( isSystemItem )
			{
			iToolbar->SetItemDimmed( EGlxCmdRename, ETrue, ETrue );
			}
		else
			{
			iToolbar->SetItemDimmed( EGlxCmdRename, EFalse, ETrue );
			}    
		}    
	
	//DrawNow must be called since SetDimmed does not redraw the toolbar
	iToolbar->DrawNow();
	}

//----------------------------------------------------------------------------
// EnableLatch
//----------------------------------------------------------------------------
//
void CGlxToolbarController::EnableLatch( TInt aCommandId, TInt aLatched )
    {
    CAknButton* toolbarButton = static_cast<CAknButton*>
                                (iToolbar->ControlOrNull( aCommandId ));

    if( toolbarButton )
        {           
        if(aLatched)
            {
            toolbarButton->SetCurrentState( KGlxToolbarButtonLatched, ETrue );
            }
        else
            {
            toolbarButton->SetCurrentState( KGlxToolbarButtonUnLatched, ETrue );
            }
        }
    }
//end of file