summaryrefslogtreecommitdiff
path: root/sdDisplayReplay.cpp
blob: 8e67904c4294e5a2f5b92ac3c5b8b0ec238d078b (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "sdDisplayReplay.h"
#include "plexSdOsd.h"

cSdDisplayReplay::cSdDisplayReplay(plexclient::Video Video, cHlsPlayerControl* Control)
{
	m_video = Video;
	m_pContol = Control;
	m_pRootView = NULL;
	m_lastsecond = 0;
}

cSdDisplayReplay::~cSdDisplayReplay()
{
	delete m_pRootView;
}

void cSdDisplayReplay::Show(void)
{
	bool skinDesignerAvailable = InitSkindesignerInterface("plex");
	if (!skinDesignerAvailable) {
		return;
	}

	m_pRootView = GetOsdView(eViews::viReplay);
	if (!m_pRootView) {
		esyslog("[plex]: used skindesigner skin does not support plex");
		return;
	}
	m_pInfo = std::shared_ptr<skindesignerapi::cViewElement>(m_pRootView->GetViewElement(eElements::Info));
	m_pReplay = std::shared_ptr<skindesignerapi::cViewElement>(m_pRootView->GetViewElement(eElements::Replay));
	m_pTime =  std::shared_ptr<skindesignerapi::cViewElement>(m_pRootView->GetViewElement(eElements::Time));
	m_pBackground = std::shared_ptr<skindesignerapi::cViewElement>(m_pRootView->GetViewElement(eElements::Background));
}

//eOSState cSdDisplayReplay::ProcessKey(eKeys Key)
//{
//}

void cSdDisplayReplay::DrawInfo()
{
	m_pInfo->Clear();
	m_video.AddTokens(m_pInfo);
}

void cSdDisplayReplay::DrawReplay()
{
	m_pReplay->ClearTokens();
	m_video.AddTokens(m_pReplay, false);

	int current, total;
	m_pContol->GetIndex(current, total);

	m_pReplay->AddIntToken("progresstotal", total / m_pContol->FramesPerSecond());
	m_pReplay->AddIntToken("progresscurrent", current / m_pContol->FramesPerSecond());

	bool play, forward;
	int speed;
	m_pContol->GetReplayMode(play, forward, speed);

	m_pReplay->AddIntToken("playing", speed >= 0);
	m_pReplay->AddIntToken("pausing", !play);
	//m_pReplay->AddIntToken("seeking", 0);
	m_pReplay->AddStringToken("totaltime", IndexToHMS(total));
	m_pReplay->AddStringToken("currenttime", IndexToHMS(current));
	m_pReplay->AddStringToken("endtime", "hh:mm");
}

void cSdDisplayReplay::Flush()
{
	m_pInfo->Display();
	m_pReplay->Display();
	m_pRootView->Display();
}

bool cSdDisplayReplay::DrawTime()
{
	time_t t = time(0);   // get time now
	struct tm * now = localtime(&t);
	int sec = now->tm_sec;
	if (sec == m_lastsecond)
		return false;

	int min = now->tm_min;
	int hour = now->tm_hour;
	int hourMinutes = hour%12 * 5 + min / 12;

	char monthname[20];
	char monthshort[10];
	strftime(monthshort, sizeof(monthshort), "%b", now);
	strftime(monthname, sizeof(monthname), "%B", now);

	m_pTime->Clear();
	m_pTime->ClearTokens();
	m_pTime->AddIntToken("sec", sec);
	m_pTime->AddIntToken("min", min);
	m_pTime->AddIntToken("hour", hour);
	m_pTime->AddIntToken("hmins", hourMinutes);
	m_pTime->AddIntToken("year", now->tm_year + 1900);
	m_pTime->AddIntToken("day", now->tm_mday);
	m_pTime->AddStringToken("time", *TimeString(t));
	m_pTime->AddStringToken("monthname", monthname);
	m_pTime->AddStringToken("monthnameshort", monthshort);
	m_pTime->AddStringToken("month", *cString::sprintf("%02d", now->tm_mon + 1));
	m_pTime->AddStringToken("dayleadingzero", *cString::sprintf("%02d", now->tm_mday));
	m_pTime->AddStringToken("dayname", *WeekDayNameFull(now->tm_wday));
	m_pTime->AddStringToken("daynameshort", *WeekDayName(now->tm_wday));
	m_pTime->Display();

	m_lastsecond = sec;
	return true;
}

std::string cSdDisplayReplay::IndexToHMS(int Index, bool WithSeconds)
{
	std::stringstream ss;
	if (Index < 0) {
		Index = -Index;
		ss << "-";
	}
	
	int s = Index / m_pContol->FramesPerSecond();
	int m = s / 60 % 60;
	int h = s / 3600;
	s %= 60;
	ss << h << ":" << m;
	
	if(WithSeconds) {
		ss << ":" << s;
	}
	return ss.str();
}