]> git.vomp.tv Git - vompclient.git/blob - vlivebanner.cc
New timers system. New program structure for handling buttons/timers
[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(View* tparent, Channel* channel, bool bannerTakesCommands)
24 {
25   eventList = NULL;
26   parent = tparent;
27   takeCommands = bannerTakesCommands;
28
29   create(500, 120);
30   if (Video::getInstance()->getFormat() == Video::PAL)
31   {
32     setScreenPos(125, 410);
33   }
34   else
35   {
36     setScreenPos(115, 320);
37   }
38
39
40   setBackgroundColour(Colour::VIEWBACKGROUND);
41   setTitleBarOn(1);
42   setTitleBarColour(Colour::TITLEBARBACKGROUND);
43
44   sl.setSurface(surface);
45   sl.setSurfaceOffset(0, 30);
46   sl.setDimensions(area.w, area.h - 60);
47   sl.setNoLoop();
48
49   setChannel(channel);
50
51   // set a timer for deleting view
52   Timers::getInstance()->setTimer(this, 1, (struct timespec){4, 0});
53 }
54
55 VLiveBanner::~VLiveBanner()
56 {
57   delData();
58 }
59
60 void VLiveBanner::delData()
61 {
62   if (eventList)
63   {
64     int eventListSize = eventList->size();
65     for(int i = 0; i < eventListSize; i++)
66     {
67       delete (*eventList)[i];
68     }
69     eventList->clear();
70     delete eventList;
71
72   }
73   sl.clear();
74 }
75
76 void VLiveBanner::setChannel(Channel* tChannel)
77 {
78   delData();
79   currentChannel = tChannel;
80   // get the data
81
82   setTitleText(currentChannel->name);
83   eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
84
85   if (!eventList)
86   {
87     sl.addOption(tr("No channel data available"), 1);
88   }
89   else
90   {
91     // sort the list
92     Log::getInstance()->log("Banner", Log::DEBUG, "Start sort");
93     sort(eventList->begin(), eventList->end(), EventSorter());
94     Log::getInstance()->log("Banner", Log::DEBUG, "End sort");
95
96     char tempString[300];
97     char tempString2[300];
98     struct tm* btime;
99     Event* event;
100     int first = 1;
101     int eventListSize = eventList->size();
102     for(int i = 0; i < eventListSize; i++)
103     {
104       event = (*eventList)[i];
105
106       btime = localtime((time_t*)&event->time);
107       strftime(tempString2, 299, "%0H:%0M ", btime);
108       snprintf(tempString, 299, "%s %s", tempString2, event->title);
109       event->index = sl.addOption(tempString, first);
110       first = 0;
111     }
112
113     // Reset the timer as it probably took 1-2 seconds to change the channel
114     Timers::getInstance()->cancelTimer(this, 1); // if it exists
115     Timers::getInstance()->setTimer(this, 1, (struct timespec){4, 0});
116   }
117 }
118
119 void VLiveBanner::draw()
120 {
121   View::draw();
122   sl.draw();
123   rectangle(0, area.h - 30, area.w, 30, titleBarColour);
124
125   rectangle(7, area.h - 24, 18, 16, Colour::RED);
126   drawText(tr("info"), 32, area.h - 25, Colour::LIGHTTEXT);
127 }
128
129 int VLiveBanner::handleCommand(int command)
130 {
131   switch (command)
132   {
133     case Remote::OK:
134     case Remote::BACK:
135     {
136       return 4;
137     }
138     case Remote::DF_UP:
139     {
140       if (!takeCommands) return 0; // banner was auto, old remote
141     } // else drop through
142     case Remote::UP:
143     {
144       sl.up();
145       sl.draw();
146
147       show();
148       return 2;
149     }
150     case Remote::DF_DOWN:
151     {
152       if (!takeCommands) return 0; // banner was auto, old remote
153     } // else drop through
154     case Remote::DOWN:
155     {
156       sl.down();
157       sl.draw();
158
159       show();
160       return 2;
161     }
162     case Remote::CHANNELUP:
163     {
164       ViewMan::getInstance()->timedDelete(this, 0, 0); // cancel timer so this view is still here later
165
166       Message* m = new Message();
167       m->from = this;
168       m->to = parent;
169       m->message = Message::CHANNEL_UP;
170       ViewMan::getInstance()->postMessage(m);
171       return 2;
172     }
173     case Remote::CHANNELDOWN:
174     {
175       ViewMan::getInstance()->timedDelete(this, 0, 0);
176
177       Message* m = new Message();
178       m->from = this;
179       m->to = parent;
180       m->message = Message::CHANNEL_DOWN;
181       ViewMan::getInstance()->postMessage(m);
182       return 2;
183     }
184     case Remote::RED:
185     case Remote::MENU:
186     {
187       if (!eventList) return 2;
188       Event* event;
189       int eventListSize = eventList->size();
190       for(int i = 0; i < eventListSize; i++)
191       {
192         event = (*eventList)[i];
193         if (event->index == sl.getCurrentOption())
194         {
195           Log::getInstance()->log("VLiveBanner", Log::DEBUG, "Found the option you pointed at. %s", event->title);
196           // First, cancel my delete timer
197           Timers::getInstance()->cancelTimer(this, 1); // if it exists
198
199           VInfo* vi = new VInfo();
200           vi->setTitleText(event->title);
201           vi->setBorderOn(1);
202           vi->setExitable();
203           if (event->description) vi->setMainText(event->description);
204           else vi->setMainText(tr("Summary unavailable"));
205           if (Video::getInstance()->getFormat() == Video::PAL)
206           {
207             vi->setScreenPos(120, 130);
208           }
209           else
210           {
211             vi->setScreenPos(110, 90);
212           }
213           vi->create(510, 270);
214
215           ViewMan::getInstance()->addNoLock(vi);
216           vi->draw();
217           vi->show();
218
219           return 2;
220
221         }
222       }
223       return 2; // should not get here
224     }
225   }
226
227   return 1;
228 }
229
230 void VLiveBanner::timercall(int clientReference)
231 {
232   // delete me!
233   Message* m = new Message();
234   m->message = Message::CLOSE_ME;
235   m->to = ViewMan::getInstance();
236   m->from = this;
237   ViewMan::getInstance()->postMessage(m);
238 }