]> git.vomp.tv Git - vompclient.git/blob - vlivebanner.cc
Zero length recording segfault fixed
[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   eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
100
101   if (!eventList)
102   {
103     sl.addOption(tr("No channel data available"), 1);
104   }
105   else
106   {
107     // sort the list
108     Log::getInstance()->log("Banner", Log::DEBUG, "Start sort");
109     sort(eventList->begin(), eventList->end(), EventSorter());
110     Log::getInstance()->log("Banner", Log::DEBUG, "End sort");
111
112     char tempString[300];
113     char tempString2[300];
114     struct tm* btime;
115     Event* event;
116     int first = 1;
117     int eventListSize = eventList->size();
118     for(int i = 0; i < eventListSize; i++)
119     {
120       event = (*eventList)[i];
121
122       btime = localtime((time_t*)&event->time);
123       strftime(tempString2, 299, "%0H:%0M ", btime);
124       snprintf(tempString, 299, "%s %s", tempString2, event->title);
125       event->index = sl.addOption(tempString, first);
126       first = 0;
127     }
128   }
129
130   // Reset the timer as it probably took 1-2 seconds to change the channel
131   Timers::getInstance()->setTimer(this, 1, (struct timespec){4, 0});
132 }
133
134 void VLiveBanner::draw()
135 {
136   View::draw();
137   sl.draw();
138   rectangle(0, area.h - 30, area.w, 30, titleBarColour);
139
140   rectangle(7, area.h - 24, 18, 16, Colour::RED);
141   drawText(tr("EPG"), 32, area.h - 25, Colour::LIGHTTEXT);
142
143   rectangle(110, area.h - 24, 18, 16, Colour::GREEN);
144   drawText(tr("info"), 135, area.h - 25, Colour::LIGHTTEXT);
145
146   drawClock();
147 }
148
149 int VLiveBanner::handleCommand(int command)
150 {
151   switch (command)
152   {
153     case Remote::OK:
154     case Remote::BACK:
155     {
156       Timers::getInstance()->cancelTimer(this, 1); // if it exists
157       return 4;
158     }
159     case Remote::DF_UP:
160     {
161       if (!takeCommands) return 0; // banner was auto, old remote
162     } // else drop through
163     case Remote::UP:
164     {
165       sl.up();
166       sl.draw();
167
168       ViewMan::getInstance()->updateView(this);
169
170       // Arrows pressed, go to an 8s timer
171       Timers::getInstance()->setTimer(this, 1, (struct timespec){8, 0});
172
173       return 2;
174     }
175     case Remote::DF_DOWN:
176     {
177       if (!takeCommands) return 0; // banner was auto, old remote
178     } // else drop through
179     case Remote::DOWN:
180     {
181       sl.down();
182       sl.draw();
183
184       ViewMan::getInstance()->updateView(this);
185
186       // Arrows pressed, go to an 8s timer
187       Timers::getInstance()->setTimer(this, 1, (struct timespec){8, 0});
188
189       return 2;
190     }
191     case Remote::CHANNELUP:
192     {
193       // cancel timer so this view is still here later
194       Timers::getInstance()->cancelTimer(this, 1); // if it exists
195       vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::UP);
196       return 2;
197     }
198     case Remote::CHANNELDOWN:
199     {
200       // cancel timer so this view is still here later
201       Timers::getInstance()->cancelTimer(this, 1); // if it exists
202       vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::DOWN);
203       return 2;
204     }
205     case Remote::GREEN:
206     case Remote::MENU:
207     {
208       if (!eventList) return 2;
209       Event* event;
210       int eventListSize = eventList->size();
211       for(int i = 0; i < eventListSize; i++)
212       {
213         event = (*eventList)[i];
214         if (event->index == sl.getCurrentOption())
215         {
216           Log::getInstance()->log("VLiveBanner", Log::DEBUG, "Found the option you pointed at. %s", event->title);
217           // First, cancel my delete timer
218           Timers::getInstance()->cancelTimer(this, 1); // if it exists
219
220           VInfo* vi = new VInfo();
221           vi->setTitleText(event->title);
222           vi->setBorderOn(1);
223           vi->setExitable();
224           if (event->description) vi->setMainText(event->description);
225           else vi->setMainText(tr("Summary unavailable"));
226           if (Video::getInstance()->getFormat() == Video::PAL)
227           {
228             vi->setScreenPos(120, 130);
229           }
230           else
231           {
232             vi->setScreenPos(110, 90);
233           }
234           vi->create(510, 270);
235           vi->draw();
236
237           ViewMan::getInstance()->add(vi);
238           ViewMan::getInstance()->updateView(vi);
239
240           return 2;
241
242         }
243       }
244       return 2; // should not get here
245     }
246     case Remote::GUIDE:
247     case Remote::RED:
248     {
249       // full epg
250       Timers::getInstance()->cancelTimer(this, 1); // if it exists
251       Message* m = new Message(); // Must be done after this view deleted
252       m->message = Message::EPG;
253       m->to = vvideoLive;
254       m->from = this;
255       ViewMan::getInstance()->postMessage(m);
256       return 4;
257     }
258   }
259
260   return 1;
261 }
262
263 void VLiveBanner::timercall(int clientReference)
264 {
265   if (clientReference == 1)
266   {
267     // delete me!
268     Message* m = new Message();  // Delete self
269     m->message = Message::CLOSE_ME;
270     m->to = ViewMan::getInstance();
271     m->from = this;
272     ViewMan::getInstance()->postMessage(m);
273   }
274   else if (clientReference == 2)
275   {
276     // redraw clock
277     drawClock();
278     ViewMan::getInstance()->updateView(this, &clockRegion);
279   }
280 }
281
282 void VLiveBanner::drawClock()
283 {
284   // Blank the area first
285   rectangle(area.w - 60, 0, 60, 30, titleBarColour);
286
287   char timeString[20];
288   time_t t;
289   time(&t);
290   struct tm* tms = localtime(&t);
291   strftime(timeString, 19, "%H:%M", tms);
292   drawTextRJ(timeString, 490, 5, Colour::LIGHTTEXT);
293
294   time_t dt = 60 - (t % 60);  // seconds to the next minute
295   if (dt == 0) dt = 60; // advance a whole minute if necessary
296   dt += t;  // get a time_t value for it rather than using duration
297   // (so it will occur at the actual second and not second and a half)
298
299   Timers::getInstance()->setTimer(this, 2, dt);
300 }