2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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
21 #include "vlivebanner.h"
23 VLiveBanner* VLiveBanner::instance = NULL;
25 VLiveBanner::VLiveBanner(VVideoLive* tvvideoLive, Channel* channel, bool bannerTakesCommands)
29 vvideoLive = tvvideoLive;
30 takeCommands = bannerTakesCommands;
38 if (Video::getInstance()->getFormat() == Video::PAL)
40 setScreenPos(124, 410);
44 setScreenPos(114, 320);
48 setBackgroundColour(Colour::VIEWBACKGROUND);
50 setTitleBarColour(Colour::TITLEBARBACKGROUND);
52 sl.setSurface(surface);
53 sl.setSurfaceOffset(0, 30);
54 sl.setDimensions(area.w, area.h - 60);
60 VLiveBanner::~VLiveBanner()
63 Timers::getInstance()->cancelTimer(this, 1);
64 Timers::getInstance()->cancelTimer(this, 2);
68 VLiveBanner* VLiveBanner::getInstance()
73 void VLiveBanner::delData()
77 int eventListSize = eventList->size();
78 for(int i = 0; i < eventListSize; i++)
80 delete (*eventList)[i];
89 void VLiveBanner::setChannel(Channel* tChannel)
92 currentChannel = tChannel;
95 int numberWidth = (int)VDR::getInstance()->getChannelNumberWidth();
98 SNPRINTF(ttitleText, 99, "%0*lu - %s", numberWidth, currentChannel->number, currentChannel->name);
100 setTitleText(ttitleText);
101 eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
105 sl.addOption(tr("No channel data available"), 0, 1);
109 sort(eventList->begin(), eventList->end(), EventSorter());
111 char tempString[300];
112 char tempString2[300];
116 int eventListSize = eventList->size();
117 for(int i = 0; i < eventListSize; i++)
119 event = (*eventList)[i];
121 //btime = localtime((time_t*)&event->time);
122 time_t etime = event->time;
123 btime = localtime(&etime);
125 strftime(tempString2, 299, "%0H:%0M ", btime);
127 strftime(tempString2, 299, "%H:%M ", btime);
129 SNPRINTF(tempString, 299, "%s %s", tempString2, event->title);
130 sl.addOption(tempString, (ULONG)event, first);
135 // Reset the timer as it probably took 1-2 seconds to change the channel
136 Timers::getInstance()->setTimerD(this, 1, 4);
139 void VLiveBanner::draw()
143 rectangle(0, area.h - 30, area.w, 30, titleBarColour);
145 rectangle(7, area.h - 24, 18, 16, Colour::RED);
146 drawText(tr("EPG"), 32, area.h - 25, Colour::LIGHTTEXT);
148 rectangle(110, area.h - 24, 18, 16, Colour::GREEN);
149 drawText(tr("info"), 135, area.h - 25, Colour::LIGHTTEXT);
154 int VLiveBanner::handleCommand(int command)
161 Timers::getInstance()->cancelTimer(this, 1); // if it exists
166 if (!takeCommands) return 0; // banner was auto, old remote
167 } // else drop through
173 ViewMan::getInstance()->updateView(this);
175 // Arrows pressed, go to an 8s timer
176 Timers::getInstance()->setTimerD(this, 1, 8);
180 case Remote::DF_DOWN:
182 if (!takeCommands) return 0; // banner was auto, old remote
183 } // else drop through
189 ViewMan::getInstance()->updateView(this);
191 // Arrows pressed, go to an 8s timer
192 Timers::getInstance()->setTimerD(this, 1, 8);
196 case Remote::CHANNELUP:
198 // cancel timer so this view is still here later
199 Timers::getInstance()->cancelTimer(this, 1); // if it exists
200 vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::UP);
203 case Remote::CHANNELDOWN:
205 // cancel timer so this view is still here later
206 Timers::getInstance()->cancelTimer(this, 1); // if it exists
207 vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::DOWN);
213 if (!eventList) return 2;
214 Event* event = (Event*)sl.getCurrentOptionData();
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
219 VInfo* vi = new VInfo();
220 vi->setTitleText(event->title);
223 if (event->description) vi->setMainText(event->description);
224 else vi->setMainText(tr("Summary unavailable"));
225 if (Video::getInstance()->getFormat() == Video::PAL)
227 vi->setScreenPos(120, 130);
231 vi->setScreenPos(110, 90);
233 vi->create(510, 270);
236 ViewMan::getInstance()->add(vi);
237 ViewMan::getInstance()->updateView(vi);
245 Timers::getInstance()->cancelTimer(this, 1); // if it exists
246 Message* m = new Message(); // Must be done after this view deleted
247 m->message = Message::EPG;
250 Command::getInstance()->postMessageNoLock(m);
258 void VLiveBanner::timercall(int clientReference)
260 if (clientReference == 1)
263 Message* m = new Message(); // Delete self
264 m->message = Message::CLOSE_ME;
265 m->to = ViewMan::getInstance();
267 Command::getInstance()->postMessageFromOuterSpace(m);
269 else if (clientReference == 2)
273 Message* m = new Message();
274 m->message = Message::REDRAW;
275 m->to = ViewMan::getInstance();
277 m->parameter = (ULONG)&clockRegion;
278 Command::getInstance()->postMessageFromOuterSpace(m);
282 void VLiveBanner::drawClock()
284 // Blank the area first
285 rectangle(area.w - 60, 0, 60, 30, titleBarColour);
290 struct tm* tms = localtime(&t);
291 strftime(timeString, 19, "%H:%M", tms);
292 drawTextRJ(timeString, 490, 5, Colour::LIGHTTEXT);
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)
299 Timers::getInstance()->setTimerT(this, 2, dt);
302 void VLiveBanner::processMessage(Message* m)
304 if (m->message == Message::MOUSE_MOVE)
306 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
309 ViewMan::getInstance()->updateView(this);
312 else if (m->message == Message::MOUSE_LBDOWN)
314 //check if press is outside this view! then simulate cancel
315 int x=(m->parameter>>16)-getScreenX();
316 int y=(m->parameter&0xFFFF)-getScreenY();
317 if (x<0 || y <0 || x>getWidth() || y>getHeight())
319 ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
321 else if (y>=(int)area.h-24 && y<=(int)area.h-6)
323 //y coordinate is right!
326 ViewMan::getInstance()->handleCommand(Remote::RED); //simulate red press
328 else if (x>=110 &&x<=128)
330 ViewMan::getInstance()->handleCommand(Remote::GREEN); //simulate red press