]> git.vomp.tv Git - vompclient.git/blob - vlivebanner.cc
Connection failure detection
[vompclient.git] / vlivebanner.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vlivebanner.h"
22
23 VLiveBanner* VLiveBanner::instance = NULL;
24
25 VLiveBanner::VLiveBanner(VVideoLive* tvvideoLive, Channel* channel, bool bannerTakesCommands)
26 {
27   instance = this;
28   eventList = NULL;
29   vvideoLive = tvvideoLive;
30   takeCommands = bannerTakesCommands;
31
32   clockRegion.x = 440;
33   clockRegion.y = 0;
34   clockRegion.w = 60;
35   clockRegion.h = 30;
36
37   create(500, 120);
38   if (Video::getInstance()->getFormat() == Video::PAL)
39   {
40     setScreenPos(124, 410);
41   }
42   else
43   {
44     setScreenPos(114, 320);
45   }
46
47
48   setBackgroundColour(Colour::VIEWBACKGROUND);
49   setTitleBarOn(1);
50   setTitleBarColour(Colour::TITLEBARBACKGROUND);
51
52   sl.setSurface(surface);
53   sl.setSurfaceOffset(0, 30);
54   sl.setDimensions(area.w, area.h - 60);
55   sl.setNoLoop();
56
57   setChannel(channel);
58 }
59
60 VLiveBanner::~VLiveBanner()
61 {
62   instance = NULL;
63   Timers::getInstance()->cancelTimer(this, 1);
64   Timers::getInstance()->cancelTimer(this, 2);
65   delData();
66 }
67
68 VLiveBanner* VLiveBanner::getInstance()
69 {
70   return instance;
71 }
72
73 void VLiveBanner::delData()
74 {
75   if (eventList)
76   {
77     int eventListSize = eventList->size();
78     for(int i = 0; i < eventListSize; i++)
79     {
80       delete (*eventList)[i];
81     }
82     eventList->clear();
83     delete eventList;
84
85   }
86   sl.clear();
87 }
88
89 void VLiveBanner::setChannel(Channel* tChannel)
90 {
91   delData();
92   currentChannel = tChannel;
93   // get the data
94
95   char ttitleText[100];
96   snprintf(ttitleText, 99, "%03lu - %s", currentChannel->number, currentChannel->name);
97
98   setTitleText(ttitleText);
99     Log::getInstance()->log("Banner", Log::DEBUG, "Start get ch");
100   eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
101     Log::getInstance()->log("Banner", Log::DEBUG, "End get ch");
102
103   if (!eventList)
104   {
105     sl.addOption(tr("No channel data available"), 1);
106   }
107   else
108   {
109     sort(eventList->begin(), eventList->end(), EventSorter());
110
111     char tempString[300];
112     char tempString2[300];
113     struct tm* btime;
114     Event* event;
115     int first = 1;
116     int eventListSize = eventList->size();
117     for(int i = 0; i < eventListSize; i++)
118     {
119       event = (*eventList)[i];
120
121       btime = localtime((time_t*)&event->time);
122       strftime(tempString2, 299, "%0H:%0M ", btime);
123       snprintf(tempString, 299, "%s %s", tempString2, event->title);
124       event->index = sl.addOption(tempString, first);
125       first = 0;
126     }
127   }
128
129   // Reset the timer as it probably took 1-2 seconds to change the channel
130   Timers::getInstance()->setTimer(this, 1, (struct timespec){4, 0});
131 }
132
133 void VLiveBanner::draw()
134 {
135   View::draw();
136   sl.draw();
137   rectangle(0, area.h - 30, area.w, 30, titleBarColour);
138
139   rectangle(7, area.h - 24, 18, 16, Colour::RED);
140   drawText(tr("EPG"), 32, area.h - 25, Colour::LIGHTTEXT);
141
142   rectangle(110, area.h - 24, 18, 16, Colour::GREEN);
143   drawText(tr("info"), 135, area.h - 25, Colour::LIGHTTEXT);
144
145   drawClock();
146 }
147
148 int VLiveBanner::handleCommand(int command)
149 {
150   switch (command)
151   {
152     case Remote::OK:
153     case Remote::BACK:
154     {
155       Timers::getInstance()->cancelTimer(this, 1); // if it exists
156       return 4;
157     }
158     case Remote::DF_UP:
159     {
160       if (!takeCommands) return 0; // banner was auto, old remote
161     } // else drop through
162     case Remote::UP:
163     {
164       sl.up();
165       sl.draw();
166
167       ViewMan::getInstance()->updateView(this);
168
169       // Arrows pressed, go to an 8s timer
170       Timers::getInstance()->setTimer(this, 1, (struct timespec){8, 0});
171
172       return 2;
173     }
174     case Remote::DF_DOWN:
175     {
176       if (!takeCommands) return 0; // banner was auto, old remote
177     } // else drop through
178     case Remote::DOWN:
179     {
180       sl.down();
181       sl.draw();
182
183       ViewMan::getInstance()->updateView(this);
184
185       // Arrows pressed, go to an 8s timer
186       Timers::getInstance()->setTimer(this, 1, (struct timespec){8, 0});
187
188       return 2;
189     }
190     case Remote::CHANNELUP:
191     {
192       // cancel timer so this view is still here later
193       Timers::getInstance()->cancelTimer(this, 1); // if it exists
194       vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::UP);
195       return 2;
196     }
197     case Remote::CHANNELDOWN:
198     {
199       // cancel timer so this view is still here later
200       Timers::getInstance()->cancelTimer(this, 1); // if it exists
201       vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::DOWN);
202       return 2;
203     }
204     case Remote::GREEN:
205     case Remote::MENU:
206     {
207       if (!eventList) return 2;
208       Event* event;
209       int eventListSize = eventList->size();
210       for(int i = 0; i < eventListSize; i++)
211       {
212         event = (*eventList)[i];
213         if (event->index == sl.getCurrentOption())
214         {
215           Log::getInstance()->log("VLiveBanner", Log::DEBUG, "Found the option you pointed at. %s", event->title);
216           // First, cancel my delete timer
217           Timers::getInstance()->cancelTimer(this, 1); // if it exists
218
219           VInfo* vi = new VInfo();
220           vi->setTitleText(event->title);
221           vi->setBorderOn(1);
222           vi->setExitable();
223           if (event->description) vi->setMainText(event->description);
224           else vi->setMainText(tr("Summary unavailable"));
225           if (Video::getInstance()->getFormat() == Video::PAL)
226           {
227             vi->setScreenPos(120, 130);
228           }
229           else
230           {
231             vi->setScreenPos(110, 90);
232           }
233           vi->create(510, 270);
234           vi->draw();
235
236           ViewMan::getInstance()->add(vi);
237           ViewMan::getInstance()->updateView(vi);
238
239           return 2;
240
241         }
242       }
243       return 2; // should not get here
244     }
245     case Remote::GUIDE:
246     case Remote::RED:
247     {
248       // full epg
249       Timers::getInstance()->cancelTimer(this, 1); // if it exists
250       Message* m = new Message(); // Must be done after this view deleted
251       m->message = Message::EPG;
252       m->to = vvideoLive;
253       m->from = this;
254       ViewMan::getInstance()->postMessage(m);
255       return 4;
256     }
257   }
258
259   return 1;
260 }
261
262 void VLiveBanner::timercall(int clientReference)
263 {
264   if (clientReference == 1)
265   {
266     // delete me!
267     Message* m = new Message();  // Delete self
268     m->message = Message::CLOSE_ME;
269     m->to = ViewMan::getInstance();
270     m->from = this;
271     ViewMan::getInstance()->postMessage(m);
272   }
273   else if (clientReference == 2)
274   {
275     // redraw clock
276     drawClock();
277     ViewMan::getInstance()->updateView(this, &clockRegion);
278   }
279 }
280
281 void VLiveBanner::drawClock()
282 {
283   // Blank the area first
284   rectangle(area.w - 60, 0, 60, 30, titleBarColour);
285
286   char timeString[20];
287   time_t t;
288   time(&t);
289   struct tm* tms = localtime(&t);
290   strftime(timeString, 19, "%H:%M", tms);
291   drawTextRJ(timeString, 490, 5, Colour::LIGHTTEXT);
292
293   time_t dt = 60 - (t % 60);  // seconds to the next minute
294   if (dt == 0) dt = 60; // advance a whole minute if necessary
295   dt += t;  // get a time_t value for it rather than using duration
296   // (so it will occur at the actual second and not second and a half)
297
298   Timers::getInstance()->setTimer(this, 2, dt);
299 }