photosgallery/slideshow/view/src/shwslideshowbacklighttimer.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Feb 2010 22:51:01 +0200
branchRCL_3
changeset 9 6b87b143d312
parent 0 4e91876724a2
child 13 71da52165949
child 16 0bc0ea26031e
permissions -rw-r--r--
Revision: 201003 Kit: 201007

/*
* Copyright (c) 2007-2008 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:    Slideshow backlight timer management..
*
*/




#include "shwslideshowbacklighttimer.h"
#include <centralrepository.h>// for peripheral display timeout setting
#include <settingsinternalcrkeys.h> // display timeout setting keys
#include <glxlog.h>
#include <glxtracer.h>
#include "shwcallback.h"

namespace
	{
	const TInt KMicroSecondsInASecond = 1000000;
    
	// @ref: Minimum slideshow transition delay
	const TInt KMinTimeoutDelay = 2; // secs 
	}

// -----------------------------------------------------------------------------
// CShwSlideshowBackLightTimer::CShwSlideshowBackLightTimer
// C++ default constructor can NOT contain any code, that
// might leave.
// -----------------------------------------------------------------------------
//
CShwSlideshowBackLightTimer::CShwSlideshowBackLightTimer()
    {
    }

// -----------------------------------------------------------------------------
// CShwSlideshowBackLightTimer::NewL
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CShwSlideshowBackLightTimer* CShwSlideshowBackLightTimer::NewL()
	{
	TRACER("CShwSlideshowBackLightTimer::NewL");
	GLX_LOG_INFO("CShwSlideshowBackLightTimer::NewL");
	CShwSlideshowBackLightTimer* self = new( ELeave )
		CShwSlideshowBackLightTimer();

    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop( self );

    return self;
	}

// -----------------------------------------------------------------------------
// Destructor
// -----------------------------------------------------------------------------
//
CShwSlideshowBackLightTimer::~CShwSlideshowBackLightTimer()
    {
    TRACER("CShwSlideshowBackLightTimer::~CShwSlideshowBackLightTimer");
    GLX_LOG_INFO("CShwSlideshowBackLightTimer::~CShwSlideshowBackLightTimer");
	delete iPeriodic;
	}

// -----------------------------------------------------------------------------
// CShwSlideshowBackLightTimer::ConstructL
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CShwSlideshowBackLightTimer::ConstructL()
	{
	TRACER("CShwSlideshowBackLightTimer::ConstructL");
	GLX_LOG_ENTRY_EXIT("CShwSlideshowBackLightTimer::ConstructL");
	
    CRepository* repository = CRepository::NewLC( KCRUidPeripheralSettings );
    // What's the timeout value (in seconds ) for the display light?
    repository->Get( KSettingsDisplayLightsTimeout, iSettingsDelay );
    GLX_LOG_INFO1("CShwSlideshowBackLightTimer, lights timeout = %d",
        iSettingsDelay );
    
    // What's the screen saver's timeout value (in seconds)?
    TInt screenSaverTimeout = 0;
    repository->Get( KSettingsScreenSaverPeriod, screenSaverTimeout );
    GLX_LOG_INFO1("CShwSlideshowBackLightTimer, scr saver timeout = %d",
        screenSaverTimeout );
    CleanupStack::PopAndDestroy( repository );
    
    // Take the smaller of the two timeout values
    iSettingsDelay = Min( iSettingsDelay, screenSaverTimeout );
    
    // Set the timeout delay to minimum value as it can not be zero!
    if (iSettingsDelay == 0)
        {
        iSettingsDelay = KMinTimeoutDelay;
        }
    
    // Convert the value to microseconds
    iSettingsDelay *= KMicroSecondsInASecond;
    // Halve the value to ensure out timer kicks beforehand
    iSettingsDelay /= 2;
    
    // Create a timer
    iPeriodic = CPeriodic::NewL( CPeriodic::EPriorityStandard );
	}

// -----------------------------------------------------------------------------
// CShwSlideshowBackLightTimer::Tick - handler code for the timer
// -----------------------------------------------------------------------------
//
TInt CShwSlideshowBackLightTimer::Tick()
    {
	// Timer must be reset to prevent screen saver to appear
	User::ResetInactivityTime();
	iStartTime.HomeTime();

	return 1; // continues always
    }

// -----------------------------------------------------------------------------
// CShwSlideshowBackLightTimer::StartL
// -----------------------------------------------------------------------------
//
void CShwSlideshowBackLightTimer::StartL()
	{
	TRACER("CShwSlideshowBackLightTimer::StartL()");
    GLX_LOG_INFO("CShwSlideshowBackLightTimer::StartL" );
	iStartTime.HomeTime();
	User::ResetInactivityTime();
    iPeriodic->Cancel(); // in case it actually was running
	iPeriodic->Start( iSettingsDelay, iSettingsDelay,
	    TShwCallBack< CShwSlideshowBackLightTimer, Tick >( this ) );
	}

// -----------------------------------------------------------------------------
// CShwSlideshowBackLightTimer::Cancel
// -----------------------------------------------------------------------------
//
void CShwSlideshowBackLightTimer::Cancel()
	{
	TRACER("CShwSlideshowBackLightTimer::Cancel()");
	GLX_LOG_INFO("CShwSlideshowBackLightTimer::Cancel" );
	User::ResetInactivityTime();
	iPeriodic->Cancel();
	}

// -----------------------------------------------------------------------------
// CShwSlideshowBackLightTimer::IsRunning
// -----------------------------------------------------------------------------
//
TBool CShwSlideshowBackLightTimer::IsRunning()
	{
	TRACER("CShwSlideshowBackLightTimer::IsRunning()");
	GLX_LOG_INFO("CShwSlideshowBackLightTimer::IsRunning" );
	return iPeriodic->IsActive();
	}

// -----------------------------------------------------------------------------
// CShwSlideshowBackLightTimer::Delay
// -----------------------------------------------------------------------------
//
TInt CShwSlideshowBackLightTimer::Delay()
	{
	TRACER("CShwSlideshowBackLightTimer::Delay()");
	GLX_LOG_INFO("CShwSlideshowBackLightTimer::Delay" );
	return iSettingsDelay;
	}