]> git.vomp.tv Git - vompclient.git/blob - vlivebanner.cc
New timers code
[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
52 VLiveBanner::~VLiveBanner()
53 {
54   delData();
55 }
56
57 void VLiveBanner::delData()
58 {
59   if (eventList)
60   {
61     int eventListSize = eventList->size();
62     for(int i = 0; i < eventListSize; i++)
63     {
64       delete (*eventList)[i];
65     }
66     eventList->clear();
67     delete eventList;
68
69   }
70   sl.clear();
71 }
72
73 void VLiveBanner::setChannel(Channel* tChannel)
74 {
75   delData();
76   currentChannel = tChannel;
77   // get the data
78
79   setTitleText(currentChannel->name);
80   eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
81
82   if (!eventList)
83   {
84     sl.addOption(tr("No channel data available"), 1);
85   }
86   else
87   {
88     // sort the list
89     Log::getInstance()->log("Banner", Log::DEBUG, "Start sort");
90     sort(eventList->begin(), eventList->end(), EventSorter());
91     Log::getInstance()->log("Banner", Log::DEBUG, "End sort");
92
93     char tempString[300];
94     char tempString2[300];
95     struct tm* btime;
96     Event* event;
97     int first = 1;
98     int eventListSize = eventList->size();
99     for(int i = 0; i < eventListSize; i++)
100     {
101       event = (*eventList)[i];
102
103       btime = localtime((time_t*)&event->time);
104       strftime(tempString2, 299, "%0H:%0M ", btime);
105       snprintf(tempString, 299, "%s %s", tempString2, event->title);
106       event->index = sl.addOption(tempString, first);
107       first = 0;
108     }
109
110     // Reset the timer as it probably took 1-2 seconds to change the channel
111     Timers::getInstance()->cancelTimer(this, 1); // if it exists
112     Timers::getInstance()->setTimer(this, 1, (struct timespec){4, 0});
113   }
114 }
115
116 void VLiveBanner::draw()
117 {
118   View::draw();
119   sl.draw();
120   rectangle(0, area.h - 30, area.w, 30, titleBarColour);
121
122   rectangle(7, area.h - 24, 18, 16, Colour::RED);
123   drawText(tr("info"), 32, area.h - 25, Colour::LIGHTTEXT);
124 }
125
126 int VLiveBanner::handleCommand(int command)
127 {
128   switch (command)
129   {
130     case Remote::OK:
131     case Remote::BACK:
132     {
133       Timers::getInstance()->cancelTimer(this, 1); // if it exists
134       return 4;
135     }
136     case Remote::DF_UP:
137     {
138       if (!takeCommands) return 0; // banner was auto, old remote
139     } // else drop through
140     case Remote::UP:
141     {
142       sl.up();
143       sl.draw();
144
145       show();
146       return 2;
147     }
148     case Remote::DF_DOWN:
149     {
150       if (!takeCommands) return 0; // banner was auto, old remote
151     } // else drop through
152     case Remote::DOWN:
153     {
154       sl.down();
155       sl.draw();
156
157       show();
158       return 2;
159     }
160     case Remote::CHANNELUP:
161     {
162       // cancel timer so this view is still here later
163       Timers::getInstance()->cancelTimer(this, 1); // if it exists
164
165       Message* m = new Message();
166       m->from = this;
167       m->to = parent;
168       m->message = Message::CHANNEL_UP;
169       ViewMan::getInstance()->postMessage(m);
170       return 2;
171     }
172     case Remote::CHANNELDOWN:
173     {
174       // cancel timer so this view is still here later
175       Timers::getInstance()->cancelTimer(this, 1); // if it exists
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()->add(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 }