summaryrefslogtreecommitdiff
path: root/pages/ibox.ecpp
blob: 7ca60697346de37a50972f0396112d427b82111f (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<%pre>
#include <vdr/plugin.h>
#include <vdr/config.h>
#include <vdr/recording.h>
#include <vdr/channels.h>
#include <vdr/menu.h>
#include <vdr/device.h>

#include "exception.h"
#include "tools.h"
#include "epg_events.h"

using namespace vdrlive;
using namespace std;

</%pre>
<%args>
	int update;
</%args>
<%cpp>
	EpgEvents epgEvents;
	string EMPTY_STR;
	tChannelID prev_chan;
	tChannelID next_chan;

	reply.setContentType( "application/xml" );

	if (cReplayControl::NowReplaying()) {
		cThreadLock RecordingsLock(&Recordings);
		cRecording *Recording = Recordings.GetByName(cReplayControl::NowReplaying());
		if (Recording) {
			const cRecordingInfo* info = Recording->Info();
			if (info) {
				EpgEventPtr epgEvent(new EpgEvent("recording",
												  Recording->Name(),
												  info->Title() ? info->Title() : Recording->Name(),
												  info->ShortText() ? info->ShortText() : "",
												  info->Description() ? info->Description() : "",
												  Recording->start,
												  Recording->start));
				epgEvents.push_back(epgEvent);
			}
		}
	}
	else {
		string CHANNEL_STR("channel");
		ReadLock channelsLock( Channels );

		if (cDevice::CurrentChannel()) {
			const int SKIP_GAP = 1;
			cChannel* Channel = Channels.GetByNumber(cDevice::CurrentChannel());

			cChannel* tmp = Channels.GetByNumber(Channels.GetPrevNormal(cDevice::CurrentChannel()), -SKIP_GAP);
			if (tmp)
				prev_chan = tmp->GetChannelID();
			tmp = Channels.GetByNumber(Channels.GetNextNormal(cDevice::CurrentChannel()), SKIP_GAP);
			if (tmp)
				next_chan = tmp->GetChannelID();

			string chanName(Channel->Name());
			cSchedulesLock schedulesLock;
			const cSchedules* Schedules = cSchedules::Schedules(schedulesLock);
			const cSchedule *Schedule = Schedules->GetSchedule(Channel);

			if (Schedule) {
				const cEvent *Event = Schedule->GetPresentEvent();
				if (Event) {
					EpgEventPtr epgEvent(new EpgEvent(CHANNEL_STR,
													  Event,
													  Channel->Name()));
					epgEvents.push_back(epgEvent);
				}
				else {
					string noInfo(tr("no epg info for current event!"));
					EpgEventPtr epgEvent(new EpgEvent(CHANNEL_STR,
													  chanName,
													  noInfo,
													  EMPTY_STR, EMPTY_STR,
													  time(0),
													  time(0)));
					epgEvents.push_back(epgEvent);
				}
			}
			else {
				string noInfo(tr("no epg info for current channel!"));
				EpgEventPtr epgEvent(new EpgEvent(CHANNEL_STR,
												  Channel->Name(),
												  noInfo,
												  EMPTY_STR, EMPTY_STR,
												  time(0),
												  time(0)));
				epgEvents.push_back(epgEvent);
			}
		}
		else {
			string chanName(tr("no current channel!"));
			EpgEventPtr epgEvent(new EpgEvent(CHANNEL_STR,
											  chanName,
											  chanName,
											  EMPTY_STR, EMPTY_STR,
											  time(0),
											  time(0)));
			epgEvents.push_back(epgEvent);
		}
	}
	if (epgEvents.size() == 0) {
		string ERROR_STR("error");
		string noInfo(tr("error retrieving status info!"));
		string chanName(tr("no current channel!"));
		EpgEventPtr epgEvent(new EpgEvent(ERROR_STR,
										  chanName,
										  noInfo,
										  EMPTY_STR, EMPTY_STR,
										  time(0),
										  time(0)));
		epgEvents.push_back(epgEvent);
	}
	for (vector<EpgEventPtr>::iterator i = epgEvents.begin(); i != epgEvents.end(); ++i) {
		EpgEventPtr epg = *i;
		if (prev_chan.Valid() && next_chan.Valid())
		{
</%cpp>
<& xmlresponse update=(update) type=(epg->Id()) caption=(epg->Caption()) currentTime=(epg->CurrentTime(tr("%I:%M:%S %p"))) duration=(epg->StartTime(tr("%I:%M %p")) + string(" - ") + epg->EndTime(tr("%I:%M %p"))) title=(epg->Title()) elapsed=(epg->Elapsed()) prev_chan=(prev_chan) next_chan=(next_chan) &>
<%cpp>
		}
		else if (prev_chan.Valid()) {
</%cpp>
<& xmlresponse update=(update) type=(epg->Id()) caption=(epg->Caption()) currentTime=(epg->CurrentTime(tr("%I:%M:%S %p"))) duration=(epg->StartTime(tr("%I:%M %p")) + string(" - ") + epg->EndTime(tr("%I:%M %p"))) title=(epg->Title()) elapsed=(epg->Elapsed()) prev_chan=(prev_chan) &>
<%cpp>
		}
		else if (next_chan.Valid()) {
</%cpp>
<& xmlresponse update=(update) type=(epg->Id()) caption=(epg->Caption()) currentTime=(epg->CurrentTime(tr("%I:%M:%S %p"))) duration=(epg->StartTime(tr("%I:%M %p")) + string(" - ") + epg->EndTime(tr("%I:%M %p"))) title=(epg->Title()) elapsed=(epg->Elapsed()) next_chan=(next_chan) &>
<%cpp>
		}
		else {
</%cpp>
<& xmlresponse update=(update) type=(epg->Id()) caption=(epg->Caption()) currentTime=(epg->CurrentTime(tr("%I:%M:%S %p"))) duration=(epg->StartTime(tr("%I:%M %p")) + string(" - ") + epg->EndTime(tr("%I:%M %p"))) title=(epg->Title()) elapsed=(epg->Elapsed()) &>
<%cpp>
		}
		break;
	}
</%cpp>

<%def xmlresponse>
<%args>
	int update;
	string type;
	string currentTime;
	string caption;
	string title;
	string duration;
	int elapsed;
	string prev_chan;
	string next_chan;
</%args>
<?xml version="1.0" encoding="ISO-8859-1"?>
<service>
  <request name="ibox">
	<param name="update"><$ update $></param>
  </request>
  <response>1</response>
  <error></error>
  <values>
	<update><$ update $></update>
	<epginfo>
	  <type><$ type $></type>
	  <caption><$ caption $></caption>
	  <timenow><$ currentTime $></timenow>
	  <name><$ title $></name>
	  <duration><$ duration $></duration>
	  <elapsed><$ elapsed $></elapsed>
	  <nextchan><$ next_chan $></nextchan>
	  <prevchan><$ prev_chan $></prevchan>
	</epginfo>
  </values>
</service>
</%def>