summaryrefslogtreecommitdiff
path: root/channeljump.c
blob: 4dcd20c953aa5aa502e461e8e92222913ac52e99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <vdr/channels.h>
#include "channeljump.h"

cChannelJump::cChannelJump(skindesignerapi::cViewElement *channelJump, int lastValidChannel) {
    this->channelJump = channelJump;
    channel = 0;
    maxChannels = lastValidChannel;
    startTime = 0;
    timeout = Setup.ChannelEntryTimeout;
}

cChannelJump::~cChannelJump(void) {
    channelJump->Clear();
    delete channelJump;
}

void cChannelJump::Draw(void) {
    channelJump->Clear();
    channelJump->ClearTokens();
    string channelString = *BuildChannelString();
    channelJump->AddStringToken("channel", channelString);
    channelJump->Display();
}

void cChannelJump::Set(int key) {
    startTime = cTimeMs::Now();
    if (channel == 0) {
	    channel = key;
	    return;
    }
    int newChannel = channel * 10 + key;
    if (newChannel <= maxChannels)
    	channel = newChannel;
}

cString cChannelJump::BuildChannelString(void) {
	if (channel*10 <= maxChannels)
		return cString::sprintf("%d-", channel);
	else
		return cString::sprintf("%d", channel); 
}

 bool cChannelJump::TimeOut(void) {
 	if ((int)(cTimeMs::Now() - startTime) > timeout)
	 	return true;
	return false;
 }