photosgallery/slideshow/view/src/shwslideshowbacklighttimer.cpp
changeset 0 4e91876724a2
child 9 6b87b143d312
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:    Slideshow backlight timer management..
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "shwslideshowbacklighttimer.h"
       
    22 #include <centralrepository.h>// for peripheral display timeout setting
       
    23 #include <settingsinternalcrkeys.h> // display timeout setting keys
       
    24 #include <glxlog.h>
       
    25 #include <glxtracer.h>
       
    26 #include "shwcallback.h"
       
    27 
       
    28 namespace
       
    29 	{
       
    30 	const TInt KMicroSecondsInASecond = 1000000;
       
    31 	}
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CShwSlideshowBackLightTimer::CShwSlideshowBackLightTimer
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CShwSlideshowBackLightTimer::CShwSlideshowBackLightTimer()
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CShwSlideshowBackLightTimer::NewL
       
    45 // Two-phased constructor.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CShwSlideshowBackLightTimer* CShwSlideshowBackLightTimer::NewL()
       
    49 	{
       
    50 	TRACER("CShwSlideshowBackLightTimer::NewL");
       
    51 	GLX_LOG_INFO("CShwSlideshowBackLightTimer::NewL");
       
    52 	CShwSlideshowBackLightTimer* self = new( ELeave )
       
    53 		CShwSlideshowBackLightTimer();
       
    54 
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop( self );
       
    58 
       
    59     return self;
       
    60 	}
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // Destructor
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CShwSlideshowBackLightTimer::~CShwSlideshowBackLightTimer()
       
    67     {
       
    68     TRACER("CShwSlideshowBackLightTimer::~CShwSlideshowBackLightTimer");
       
    69     GLX_LOG_INFO("CShwSlideshowBackLightTimer::~CShwSlideshowBackLightTimer");
       
    70 	delete iPeriodic;
       
    71 	}
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CShwSlideshowBackLightTimer::ConstructL
       
    75 // Symbian 2nd phase constructor can leave.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CShwSlideshowBackLightTimer::ConstructL()
       
    79 	{
       
    80 	TRACER("CShwSlideshowBackLightTimer::ConstructL");
       
    81 	GLX_LOG_ENTRY_EXIT("CShwSlideshowBackLightTimer::ConstructL");
       
    82 	
       
    83     CRepository* repository = CRepository::NewLC( KCRUidPeripheralSettings );
       
    84     // What's the timeout value (in seconds ) for the display light?
       
    85     repository->Get( KSettingsDisplayLightsTimeout, iSettingsDelay );
       
    86     GLX_LOG_INFO1("CShwSlideshowBackLightTimer, lights timeout = %d",
       
    87         iSettingsDelay );
       
    88     
       
    89     // What's the screen saver's timeout value (in seconds)?
       
    90     TInt screenSaverTimeout = 0;
       
    91     repository->Get( KSettingsScreenSaverPeriod, screenSaverTimeout );
       
    92     GLX_LOG_INFO1("CShwSlideshowBackLightTimer, scr saver timeout = %d",
       
    93         screenSaverTimeout );
       
    94     CleanupStack::PopAndDestroy( repository );
       
    95     
       
    96     // Take the smaller of the two timeout values
       
    97     iSettingsDelay = Min( iSettingsDelay, screenSaverTimeout );
       
    98     // Convert the value to microseconds
       
    99     iSettingsDelay *= KMicroSecondsInASecond;
       
   100     // Halve the value to ensure out timer kicks beforehand
       
   101     iSettingsDelay /= 2;
       
   102     
       
   103     // Create a timer
       
   104     iPeriodic = CPeriodic::NewL( CPeriodic::EPriorityStandard );
       
   105 	}
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CShwSlideshowBackLightTimer::Tick - handler code for the timer
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 TInt CShwSlideshowBackLightTimer::Tick()
       
   112     {
       
   113 	// Timer must be reset to prevent screen saver to appear in 
       
   114 	// Aalto when the slide is closed. Should not cause any side effects.
       
   115 	User::ResetInactivityTime();
       
   116 	iStartTime.HomeTime();
       
   117 
       
   118 	return 1; // continues always
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CShwSlideshowBackLightTimer::StartL
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CShwSlideshowBackLightTimer::StartL()
       
   126 	{
       
   127 	TRACER("CShwSlideshowBackLightTimer::StartL()");
       
   128     GLX_LOG_INFO("CShwSlideshowBackLightTimer::StartL" );
       
   129 	iStartTime.HomeTime();
       
   130 	User::ResetInactivityTime();
       
   131     iPeriodic->Cancel(); // in case it actually was running
       
   132 	iPeriodic->Start( iSettingsDelay, iSettingsDelay,
       
   133 	    TShwCallBack< CShwSlideshowBackLightTimer, Tick >( this ) );
       
   134 	}
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CShwSlideshowBackLightTimer::Cancel
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CShwSlideshowBackLightTimer::Cancel()
       
   141 	{
       
   142 	TRACER("CShwSlideshowBackLightTimer::Cancel()");
       
   143 	GLX_LOG_INFO("CShwSlideshowBackLightTimer::Cancel" );
       
   144 	User::ResetInactivityTime();
       
   145 	iPeriodic->Cancel();
       
   146 	}
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CShwSlideshowBackLightTimer::IsRunning
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 TBool CShwSlideshowBackLightTimer::IsRunning()
       
   153 	{
       
   154 	TRACER("CShwSlideshowBackLightTimer::IsRunning()");
       
   155 	GLX_LOG_INFO("CShwSlideshowBackLightTimer::IsRunning" );
       
   156 	return iPeriodic->IsActive();
       
   157 	}
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CShwSlideshowBackLightTimer::Delay
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 TInt CShwSlideshowBackLightTimer::Delay()
       
   164 	{
       
   165 	TRACER("CShwSlideshowBackLightTimer::Delay()");
       
   166 	GLX_LOG_INFO("CShwSlideshowBackLightTimer::Delay" );
       
   167 	return iSettingsDelay;
       
   168 	}