26
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// CScreensaverActivityManager class
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "screensaveractivitymanager.h"
|
|
19 |
|
|
20 |
CScreensaverActivityManager* CScreensaverActivityManager::NewL(TInt aPriority)
|
|
21 |
{
|
|
22 |
CScreensaverActivityManager* self = new (ELeave) CScreensaverActivityManager(aPriority);
|
|
23 |
CleanupStack::PushL(self);
|
|
24 |
self->ConstructL();
|
|
25 |
CActiveScheduler::Add(self);
|
|
26 |
CleanupStack::Pop(self);
|
|
27 |
return self;
|
|
28 |
}
|
|
29 |
|
|
30 |
CScreensaverActivityManager::CScreensaverActivityManager(TInt aPriority)
|
|
31 |
: CTimer(aPriority), iInactiveCallback(0,0), iActiveCallback(0,0), iState(EStNotActive)
|
|
32 |
{
|
|
33 |
}
|
|
34 |
|
|
35 |
|
|
36 |
CScreensaverActivityManager::~CScreensaverActivityManager()
|
|
37 |
{
|
|
38 |
}
|
|
39 |
|
|
40 |
|
|
41 |
void CScreensaverActivityManager::Start(TTimeIntervalSeconds aInterval,
|
|
42 |
TCallBack aInactiveCallback, TCallBack aActiveCallback)
|
|
43 |
{
|
|
44 |
iInterval = aInterval;
|
|
45 |
iInactiveCallback = aInactiveCallback;
|
|
46 |
iActiveCallback = aActiveCallback;
|
|
47 |
|
|
48 |
if (iInterval.Int() < 0)
|
|
49 |
{
|
|
50 |
iInterval = TTimeIntervalSeconds(0);
|
|
51 |
}
|
|
52 |
|
|
53 |
// Cancel outstanding timer, if any
|
|
54 |
CTimer::Cancel();
|
|
55 |
|
|
56 |
if (iState == EStNotActive || iState == EStMonForInactivity)
|
|
57 |
{
|
|
58 |
// Begin or contine monitoring for user inactivity
|
|
59 |
MonitorInactivity();
|
|
60 |
}
|
|
61 |
else
|
|
62 |
{
|
|
63 |
// Continue monitoring for user activity
|
|
64 |
Inactivity(0);
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
|
|
69 |
void CScreensaverActivityManager::SetInactivityTimeout(TTimeIntervalSeconds aInterval)
|
|
70 |
{
|
|
71 |
if (iState <= EStNotActive)
|
|
72 |
{
|
|
73 |
}
|
|
74 |
Start(aInterval, iInactiveCallback, iActiveCallback);
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
void CScreensaverActivityManager::MonitorInactivity()
|
|
79 |
{
|
|
80 |
if (User::InactivityTime() >= iInterval)
|
|
81 |
{
|
|
82 |
// Already inactive enough, monitor for activity
|
|
83 |
iState = EStMonForActivity;
|
|
84 |
// Monitor for activity, set timer before callback to avoid missing any
|
|
85 |
// user activity should callback take some time.
|
|
86 |
Inactivity(0);
|
|
87 |
// Inform client that the inactivity interval has ended.
|
|
88 |
(void) iInactiveCallback.CallBack();
|
|
89 |
}
|
|
90 |
else
|
|
91 |
{
|
|
92 |
// Monitor for Inactivity
|
|
93 |
iState = EStMonForInactivity;
|
|
94 |
Inactivity(iInterval);
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
void CScreensaverActivityManager::RunL()
|
|
100 |
{
|
|
101 |
if (iStatus == KErrNone)
|
|
102 |
{
|
|
103 |
if (iState == EStMonForInactivity)
|
|
104 |
{
|
|
105 |
// Looking for Inactivity, found it
|
|
106 |
// Monitor for activity, set timer before callback to avoid missing
|
|
107 |
// any user activity should callback take some time.
|
|
108 |
iState = EStMonForActivity;
|
|
109 |
Inactivity(0);
|
|
110 |
// Inform client that the inactivity interval has ended.
|
|
111 |
(void) iInactiveCallback.CallBack();
|
|
112 |
}
|
|
113 |
else if (iState == EStMonForActivity)
|
|
114 |
{
|
|
115 |
// Looking for activity, found it
|
|
116 |
// Monitor for activity unless MonitorInactivity overrides it
|
|
117 |
iState = EStMonForInactivity;
|
|
118 |
MonitorInactivity();
|
|
119 |
(void) iActiveCallback.CallBack();
|
|
120 |
}
|
|
121 |
else
|
|
122 |
{ // Must never happen, indicates internal state of object incorrect.
|
|
123 |
|
|
124 |
}
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
TBool CScreensaverActivityManager::IsMonitoringForActivity()
|
|
129 |
{
|
|
130 |
return ( iState == EStMonForActivity );
|
|
131 |
}
|