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