]> git.vomp.tv Git - vompclient.git/blob - vrecording.cc
Compile fixes for stretch
[vompclient.git] / vrecording.cc
1 /*
2     Copyright 2004-2008 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vrecording.h"
22
23 #include "remote.h"
24 #include "recinfo.h"
25 #include "vquestion.h"
26 #include "vinfo.h"
27 #include "vdr.h"
28 #include "colour.h"
29 #include "video.h"
30 #include "i18n.h"
31 #include "command.h"
32 #include "vrecmove.h"
33 #include "boxstack.h"
34 #include "recman.h"
35 #include "vrecordinglist.h"
36 #include "recording.h"
37 #include "message.h"
38 #include "log.h"
39 #include "wmovieview.h"
40 #include "wseriesview.h"
41 #include "wpictureview.h"
42
43 VRecording::VRecording(RecMan* trecman, Recording* trec)
44 {
45   rec = trec;
46   recman = trecman;
47   buttons = true;
48   selected = RESUME;
49   
50   Log::getInstance()->log("VRecording", Log::DEBUG, "%s", rec->getProgName());
51   rec->loadRecInfo();
52   Log::getInstance()->log("VRecording", Log::DEBUG, "%s", rec->getProgName());
53
54
55   if (Video::getInstance()->getFormat() == Video::PAL)
56   {
57     setSize(640, 500);
58         createBuffer();
59   }
60   else
61   {
62         setSize(560, 400);
63         createBuffer();
64   }
65   setPosition(40, 40);
66
67   setTitleBarOn(1);
68   setBorderOn(1);
69   if (rec->recInfo && strlen(rec->recInfo->title))
70           setTitleText(rec->recInfo->title);
71   else
72           setTitleText(rec->getProgName());
73   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
74
75   tabbar.setPosition(10+130+10, 30 + 5);
76   tabbar.setSize(area.w - 20-10-130, area.h - 30 - 10);
77   add(&tabbar);
78
79
80
81
82   WTextbox * summary=new WTextbox();
83   summary->setParaMode(true);
84
85   if (rec->recInfo && strlen(rec->recInfo->summary))
86     summary->setText(rec->recInfo->summary);
87   else
88     summary->setText(tr("Summary unavailable"));
89
90   OsdVector *osdv=dynamic_cast<OsdVector*>(Osd::getInstance());
91
92   tabbar.addTab(tr("EPG"), summary);
93   if (rec->movieInfo) {
94           WMovieView *movieview = new WMovieView(rec->movieInfo);
95           movieview->setParaMode(true);
96           tabbar.addTab(tr("TheTVDB Info"), movieview);
97           if (osdv) {
98                   if (rec->movieInfo->actors.size() > 0 && osdv)
99                   {
100                           WActorGallery *gallery= new WActorGallery(rec->movieInfo->actors);
101                           tabbar.addTab(tr("Cast"),gallery);
102                   }
103                   WArtworkGallery *artgallery= new WArtworkGallery(*rec->movieInfo);
104                   tabbar.addTab(tr("Gallery"),artgallery);
105           }
106   } else if (rec->seriesInfo) {
107           WSeriesView *seriesview = new WSeriesView(rec->seriesInfo);
108           seriesview->setParaMode(true);
109           tabbar.addTab(tr("TheTVDB Info"), seriesview);
110           if (osdv) {
111                   if (rec->seriesInfo->actors.size() > 0 && osdv)
112                   {
113                           WActorGallery *gallery= new WActorGallery(rec->seriesInfo->actors);
114                           tabbar.addTab(tr("Cast"),gallery);
115                   }
116                   WArtworkGallery *artgallery= new WArtworkGallery(*rec->seriesInfo);
117                   tabbar.addTab(tr("Gallery"),artgallery);
118           }
119
120   }
121
122
123   
124   int sfh = getFontHeight();
125   buttonRegion.x = 10;
126   buttonRegion.y = 10+30;
127   buttonRegion.w = 130;
128   buttonRegion.h = sfh*2*last;
129
130   button[PLAY].setText(tr("Play"));
131   button[RESUME].setText(tr("Resume"));
132   button[MOVE].setText(tr("Move"));
133   button[A_DELETE].setText(tr("Delete"));
134   
135   for (int i=PLAY, ver=10+30; i<last; i++, ver+= sfh*2)
136   {
137     button[i].setPosition(10, ver);
138     button[i].setSize(130, sfh);
139     add(&button[i]);
140   }
141   
142
143   button[selected].setActive(1);
144   tabbar.activateFocus(false);
145 }
146
147 VRecording::~VRecording()
148 {
149 }
150
151 void VRecording::setParent(VRecordingList* tvRecList)
152 {
153   vRecList = tvRecList;
154 }
155
156 void VRecording::draw()
157 {
158   TBBoxx::draw();
159   OsdVector *osdv=dynamic_cast<OsdVector*>(Osd::getInstance());
160   if (osdv) {
161           TVMedia poster;
162           if (rec->movieInfo) {
163                   poster=rec->movieInfo->poster;
164           }
165           if (rec->seriesInfo) {
166                   if (rec->seriesInfo->seasonposter.height) {
167                           poster=rec->seriesInfo->seasonposter;
168                   }
169                   else
170                   if (rec->seriesInfo->posters.size()) {
171                           poster=rec->seriesInfo->posters[0];
172                   }
173           }
174           if (poster.height) {
175                  // float aspect=((float)poster.height)/((float)poster.width)/Osd::getInstance()->getPixelAspect();
176                   drawTVMedia(poster.info,buttonRegion.x,
177                                          tabbar.getY2()-3,
178                                                 buttonRegion.w,/*buttonRegion.w*aspect*/0.f,BottomLeft);
179           }
180   }
181
182 }
183
184 int VRecording::handleCommand(int command)
185 {
186         if (command==Remote::BACK) {
187                 return 4;
188         }
189         if (buttons) {
190                 switch(command)
191                 {
192                 case Remote::DF_UP:
193                 case Remote::UP:
194                 {
195                         tabbar.activateFocus(false);
196                         moveCursor(LEFT);
197                         return 2;
198                 }
199
200                 case Remote::DF_DOWN:
201                 case Remote::DOWN:
202                 {
203                         tabbar.activateFocus(false);
204                         moveCursor(RIGHT);
205                         return 2;
206                 }
207                 case Remote::LEFT:
208                 case Remote::DF_LEFT:
209                 case Remote::RIGHT:
210                 case Remote::DF_RIGHT:
211                 {
212                         buttons = false;
213                         button[selected].setActive(0);
214                         tabbar.activateFocus(true);
215                         button[selected].draw();
216                         tabbar.draw();
217                         BoxStack::getInstance()->update(this);
218                         return 2;
219                 }
220                 case Remote::OK:
221                 {
222
223                         if (selected == PLAY)
224                         {
225                                 Message* m = new Message(); // Must be done after this view deleted
226                                 m->from = this;
227                                 m->to = vRecList;
228                                 m->message = Message::PLAY_SELECTED_RECORDING;
229                                 Command::getInstance()->postMessageNoLock(m);
230                                 return 4;
231                         }
232
233                         if (selected == RESUME)
234                         {
235                                 Message* m = new Message(); // Must be done after this view deleted
236                                 m->from = this;
237                                 m->to = vRecList;
238                                 m->message = Message::RESUME_SELECTED_RECORDING;
239                                 Command::getInstance()->postMessageNoLock(m);
240                                 return 4;
241                         }
242
243                         if (selected == MOVE)
244                         {
245                                 VRecMove* vrm = new VRecMove(recman);
246                                 vrm->setParent(this);
247                                 vrm->draw();
248                                 BoxStack::getInstance()->add(vrm);
249                                 BoxStack::getInstance()->update(vrm);
250                                 return 2;
251                         }
252
253                         if (selected == A_DELETE)
254                         {
255                                 VQuestion* v = new VQuestion(this);
256                                 v->setSize(260, 180);
257                                 v->createBuffer();
258                                 v->setTitleBarColour(DrawStyle::DANGER);
259                                 v->setTitleBarOn(1);
260                                 v->setBorderOn(1);
261                                 v->setTitleText(tr("Delete recording"));
262                                 v->setMainText(tr("Are you sure you want to delete this recording?"));
263                                 v->setDefault(VQuestion::NO);
264                                 if (Video::getInstance()->getFormat() == Video::PAL)
265                                 {
266                                         v->setPosition(230, 160);
267                                 }
268                                 else
269                                 {
270                                         v->setPosition(220, 140);
271                                 }
272
273                                 v->draw();
274                                 BoxStack::getInstance()->add(v);
275                                 BoxStack::getInstance()->update(v);
276                                 return 2;
277                         }
278                 }
279                 }
280         } else {
281                 // Pass to tabbar
282                 int retval = tabbar.handleCommand(command);
283                 if (retval == 1)
284                 {
285                         BoxStack::getInstance()->update(this);
286                         return 2;
287                 }
288                 else if (retval == 2)
289                 {
290                         // command was taken and actively ignored
291                         if (command==Remote::LEFT || command==Remote::DF_LEFT
292                                         || command==Remote::RIGHT || command==Remote::DF_RIGHT)
293                         {
294                                 buttons=true;
295                                 button[selected].setActive(1);
296                                 tabbar.activateFocus(false);
297                                 button[selected].draw();
298                                 tabbar.draw();
299                                 BoxStack::getInstance()->update(this);
300                         }
301                         return 2;
302                 }
303         }
304
305
306         // stop command getting to any more views
307         return 1;
308 }
309
310 void VRecording::moveCursor(Direction direction)
311 {
312   button[selected].setActive(0);
313   button[selected].draw();
314   if (direction == RIGHT)
315   { 
316     if (++selected == last) selected = PLAY;
317   }
318   else
319   {
320     if (--selected < 0) selected = last - 1;
321   }
322   button[selected].setActive(1);
323   button[selected].draw();
324   BoxStack::getInstance()->update(this, &buttonRegion);
325 }
326
327 void VRecording::processMessage(Message* m)
328 {
329   if (m->message == Message::MOUSE_MOVE)
330   {
331     for (int i = PLAY; i < last; i++)
332     {
333           if (button[i].mouseMove((m->parameter.num >> 16) - getScreenX(), (m->parameter.num & 0xFFFF) - getScreenY()))
334       {
335         for (int j = PLAY; j < last; j++)
336           button[j].setActive(0);
337         button[i].setActive(1);
338                 tabbar.activateFocus(false);
339                 buttons = true;
340         selected=i;
341         draw();
342         BoxStack::getInstance()->update(this);
343         break;
344       }
345     }
346         if (tabbar.mouseMove((m->parameter.num >> 16) - getScreenX(), (m->parameter.num & 0xFFFF) - getScreenY()))
347         {
348                 BoxStack::getInstance()->update(this);
349                 return;
350         }
351   }
352   else if (m->message == Message::MOUSE_SCROLL)
353   {
354           if (tabbar.mouseAndroidScroll((m->tag >> 16) - getScreenX(), (m->tag & 0xFFFF) - getScreenY(),
355                   (short)(m->parameter.num >> 16), (short) (m->parameter.num & 0xFFFF)))
356           {
357                   BoxStack::getInstance()->update(this);
358                   return;
359           }
360   }
361   else if (m->message == Message::MOUSE_LBDOWN)
362   {
363     int cancel = true;
364     for (int i = PLAY; i < last; i++)
365     {
366       if (button[i].mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
367       {
368         BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
369                 buttons = true;
370         cancel = false;
371         break;
372       }
373     }
374         if (cancel && tabbar.mouseLBDOWN((m->parameter.num >> 16) - getScreenX(), (m->parameter.num & 0xFFFF) - getScreenY()))
375         {
376                 buttons = false;
377                 button[selected].setActive(0);
378
379                 BoxStack::getInstance()->update(this);
380                 cancel = false;
381         }
382     if (cancel)
383     {
384       //check if press is outside this view! then simulate cancel
385       int x=(m->parameter.num>>16)-getScreenX();
386       int y=(m->parameter.num&0xFFFF)-getScreenY();
387       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
388       {
389         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
390       }
391     }
392   }
393   else if (m->message == Message::QUESTION_YES)
394   {
395     if (selected == A_DELETE)
396     {
397       Message* m2 = new Message(); // Delete self
398       m2->from = this;
399       m2->to = BoxStack::getInstance();
400       m2->message = Message::CLOSE_ME;
401       Command::getInstance()->postMessageNoLock(m2);
402
403       m2 = new Message(); // OK. Want this to delete before this message does its job
404       m2->from = this;
405       m2->to = vRecList;
406       m2->message = Message::DELETE_SELECTED_RECORDING;
407       Command::getInstance()->postMessageNoLock(m2);
408     }
409   }
410   else if (m->message == Message::MOVE_RECORDING)
411   {
412     Message* m2 = new Message(); // Delete self
413     m2->from = this;
414     m2->to = BoxStack::getInstance();
415     m2->message = Message::CLOSE_ME;
416     Command::getInstance()->postMessageNoLock(m2);
417
418     m2 = new Message();
419     m2->from = this;
420     m2->to = vRecList;
421     m2->message = Message::MOVE_RECORDING;
422     m2->parameter.num = m->parameter.num;
423     Command::getInstance()->postMessageNoLock(m2);
424   }
425 }
426