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 #include "vvideolive.h"
35 VLiveBanner* VLiveBanner::instance = NULL;
37 VLiveBanner::VLiveBanner(VVideoLive* tvvideoLive, Channel* channel, bool bannerTakesCommands)
41 vvideoLive = tvvideoLive;
42 takeCommands = bannerTakesCommands;
51 if (Video::getInstance()->getFormat() == Video::PAL)
53 setPosition(124, 410);
57 setPosition(114, 320);
62 setTitleBarColour(Colour::TITLEBARBACKGROUND);
64 sl.setPosition(0, 30);
65 sl.setSize(area.w, area.h - 60);
72 VLiveBanner::~VLiveBanner()
75 Timers::getInstance()->cancelTimer(this, 1);
76 Timers::getInstance()->cancelTimer(this, 2);
80 VLiveBanner* VLiveBanner::getInstance()
85 void VLiveBanner::delData()
89 int eventListSize = eventList->size();
90 for(int i = 0; i < eventListSize; i++)
92 delete (*eventList)[i];
101 void VLiveBanner::setChannel(Channel* tChannel)
104 currentChannel = tChannel;
107 int numberWidth = (int)VDR::getInstance()->getChannelNumberWidth();
109 char ttitleText[100];
110 SNPRINTF(ttitleText, 99, "%0*lu - %s", numberWidth, currentChannel->number, currentChannel->name);
112 setTitleText(ttitleText);
113 eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
117 sl.addOption(tr("No channel data available"), 0, 1);
121 sort(eventList->begin(), eventList->end(), EventSorter());
123 char tempString[300];
124 char tempString2[300];
128 int eventListSize = eventList->size();
129 for(int i = 0; i < eventListSize; i++)
131 event = (*eventList)[i];
133 //btime = localtime((time_t*)&event->time);
134 time_t etime = event->time;
135 btime = localtime(&etime);
137 strftime(tempString2, 299, "%0H:%0M ", btime);
139 strftime(tempString2, 299, "%H:%M ", btime);
141 SNPRINTF(tempString, 299, "%s %s", tempString2, event->title);
142 sl.addOption(tempString, (ULONG)event, first);
147 // Reset the timer as it probably took 1-2 seconds to change the channel
148 Timers::getInstance()->setTimerD(this, 1, 4);
151 void VLiveBanner::draw()
154 rectangle(0, area.h - 30, area.w, 30, titleBarColour);
156 rectangle(7, area.h - 24, 18, 16, Colour::RED);
157 drawText(tr("EPG"), 32, area.h - 25, Colour::LIGHTTEXT);
159 rectangle(110, area.h - 24, 18, 16, Colour::GREEN);
160 drawText(tr("info"), 135, area.h - 25, Colour::LIGHTTEXT);
165 int VLiveBanner::handleCommand(int command)
172 Timers::getInstance()->cancelTimer(this, 1); // if it exists
177 if (!takeCommands) return 0; // banner was auto, old remote
178 } // else drop through
184 BoxStack::getInstance()->update(this);
186 // Arrows pressed, go to an 8s timer
187 Timers::getInstance()->setTimerD(this, 1, 8);
191 case Remote::DF_DOWN:
193 if (!takeCommands) return 0; // banner was auto, old remote
194 } // else drop through
200 BoxStack::getInstance()->update(this);
202 // Arrows pressed, go to an 8s timer
203 Timers::getInstance()->setTimerD(this, 1, 8);
207 case Remote::CHANNELUP:
209 // cancel timer so this view is still here later
210 Timers::getInstance()->cancelTimer(this, 1); // if it exists
211 vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::UP);
214 case Remote::CHANNELDOWN:
216 // cancel timer so this view is still here later
217 Timers::getInstance()->cancelTimer(this, 1); // if it exists
218 vvideoLive->channelChange(VVideoLive::OFFSET, VVideoLive::DOWN);
224 if (!eventList) return 2;
225 Event* event = (Event*)sl.getCurrentOptionData();
226 Log::getInstance()->log("VLiveBanner", Log::DEBUG, "Found the option you pointed at. %s", event->title);
227 // First, cancel my delete timer
228 Timers::getInstance()->cancelTimer(this, 1); // if it exists
230 VInfo* vi = new VInfo();
231 vi->setTitleText(event->title);
234 if (event->description) vi->setMainText(event->description);
235 else vi->setMainText(tr("Summary unavailable"));
236 if (Video::getInstance()->getFormat() == Video::PAL)
238 vi->setPosition(120, 130);
242 vi->setPosition(110, 90);
244 vi->setSize(510, 270);
248 BoxStack::getInstance()->add(vi);
249 BoxStack::getInstance()->update(vi);
257 Timers::getInstance()->cancelTimer(this, 1); // if it exists
258 Message* m = new Message(); // Must be done after this view deleted
259 m->message = Message::EPG;
262 Command::getInstance()->postMessageNoLock(m);
270 void VLiveBanner::timercall(int clientReference)
272 if (clientReference == 1)
275 Message* m = new Message(); // Delete self
276 m->message = Message::CLOSE_ME;
277 m->to = BoxStack::getInstance();
279 Command::getInstance()->postMessageFromOuterSpace(m);
281 else if (clientReference == 2)
285 Message* m = new Message();
286 m->message = Message::REDRAW;
287 m->to = BoxStack::getInstance();
289 m->parameter = (ULONG)&clockRegion;
290 Command::getInstance()->postMessageFromOuterSpace(m);
294 void VLiveBanner::drawClock()
296 // Blank the area first
297 rectangle(area.w - 60, 0, 60, 30, titleBarColour);
302 struct tm* tms = localtime(&t);
303 strftime(timeString, 19, "%H:%M", tms);
304 drawTextRJ(timeString, 490, 5, Colour::LIGHTTEXT);
306 time_t dt = 60 - (t % 60); // seconds to the next minute
307 if (dt == 0) dt = 60; // advance a whole minute if necessary
308 dt += t; // get a time_t value for it rather than using duration
309 // (so it will occur at the actual second and not second and a half)
311 Timers::getInstance()->setTimerT(this, 2, dt);
314 void VLiveBanner::processMessage(Message* m)
316 if (m->message == Message::MOUSE_MOVE)
318 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
321 BoxStack::getInstance()->update(this);
324 else if (m->message == Message::MOUSE_LBDOWN)
326 //check if press is outside this view! then simulate cancel
327 int x=(m->parameter>>16)-getScreenX();
328 int y=(m->parameter&0xFFFF)-getScreenY();
329 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
331 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
333 else if (y>=(int)area.h-24 && y<=(int)area.h-6)
335 //y coordinate is right!
338 BoxStack::getInstance()->handleCommand(Remote::RED); //simulate red press
340 else if (x>=110 &&x<=128)
342 BoxStack::getInstance()->handleCommand(Remote::GREEN); //simulate red press