]> git.vomp.tv Git - vompclient.git/blob - vrecording.cc
*** empty log message ***
[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
40 VRecording::VRecording(RecMan* trecman, Recording* trec)
41 {
42   rec = trec;
43   recman = trecman;
44   
45   Log::getInstance()->log("VRecording", Log::DEBUG, "%s", rec->getProgName());
46   rec->loadRecInfo();
47   Log::getInstance()->log("VRecording", Log::DEBUG, "%s", rec->getProgName());
48
49   setSize(570, 420);
50   createBuffer();
51   if (Video::getInstance()->getFormat() == Video::PAL)
52   {
53     setPosition(80, 70);
54   }
55   else
56   {
57     setPosition(70, 35);
58   }
59
60   setTitleBarOn(1);
61   setBorderOn(1);
62   setTitleText(rec->getProgName());
63   setTitleBarColour(Colour::TITLEBARBACKGROUND);
64
65   summary.setPosition(10, 30 + 5);
66   summary.setSize(area.w - 20, area.h - 30 - 15 - 50);
67   summary.setParaMode(true);
68
69   if (strlen(rec->recInfo->summary))
70     summary.setText(rec->recInfo->summary);
71   else
72     summary.setText(tr("Summary unavailable"));
73
74   add(&summary);
75   
76   
77   buttonPlay.setPosition(10, area.h - 40);
78   buttonResume.setPosition(150, area.h - 40);
79   buttonMove.setPosition(290, area.h - 40);
80   buttonDelete.setPosition(430, area.h - 40);
81   
82   int sfh = Surface::getFontHeight();
83   
84   buttonPlay.setSize(130, sfh);
85   buttonResume.setSize(130, sfh);
86   buttonMove.setSize(130, sfh);
87   buttonDelete.setSize(130, sfh);
88   
89   buttonRegion.x = 10;
90   buttonRegion.y = area.h - 40;
91   buttonRegion.w = 550;
92   buttonRegion.h = sfh;
93
94   buttonPlay.setText(tr("Play"));
95   buttonResume.setText(tr("Resume"));
96   buttonMove.setText(tr("Move"));
97   buttonDelete.setText(tr("Delete"));
98   
99   add(&buttonPlay);
100   add(&buttonResume);    
101   add(&buttonMove);
102   add(&buttonDelete);
103   
104   buttonPlay.setActive(1);
105   selected = 1;
106 }
107
108 VRecording::~VRecording()
109 {
110 }
111
112 void VRecording::setParent(VRecordingList* tvRecList)
113 {
114   vRecList = tvRecList;
115 }
116
117 void VRecording::draw()
118 {
119   TBBoxx::draw();
120 }
121
122 int VRecording::handleCommand(int command)
123 {
124   switch(command)
125   {
126     case Remote::LEFT:
127     case Remote::DF_LEFT:
128     case Remote::DF_UP:
129     case Remote::UP:
130     {
131       doLeft();
132       return 2;
133     }
134     case Remote::RIGHT:
135     case Remote::DF_RIGHT:
136     case Remote::DF_DOWN:
137     case Remote::DOWN:
138     {
139       doRight();
140       return 2;
141     }
142     case Remote::OK:
143     {
144
145       if (selected == 1)
146       {
147         Message* m = new Message(); // Must be done after this view deleted
148         m->from = this;
149         m->to = vRecList;
150         m->message = Message::PLAY_SELECTED_RECORDING;
151         Command::getInstance()->postMessageNoLock(m);
152         return 4;
153       }
154
155       if (selected == 2)
156       {
157         Message* m = new Message(); // Must be done after this view deleted
158         m->from = this;
159         m->to = vRecList;
160         m->message = Message::RESUME_SELECTED_RECORDING;
161         Command::getInstance()->postMessageNoLock(m);
162         return 4;
163       }
164
165       if (selected == 3)
166       {
167         VRecMove* vrm = new VRecMove(recman);
168         vrm->setParent(this);
169         vrm->draw();
170         BoxStack::getInstance()->add(vrm);
171         BoxStack::getInstance()->update(vrm);
172         return 2;
173       }
174
175       if (selected == 4)
176       {
177         VQuestion* v = new VQuestion(this);
178         v->setSize(260, 180);
179         v->createBuffer();
180         v->setTitleBarColour(Colour::DANGER);
181         v->setTitleBarOn(1);
182         v->setBorderOn(1);
183         v->setTitleText(tr("Delete recording"));
184         v->setMainText(tr("Are you sure you want to delete this recording?"));
185         v->setDefault(VQuestion::NO);
186         if (Video::getInstance()->getFormat() == Video::PAL)
187         {
188           v->setPosition(230, 160);
189         }
190         else
191         {
192           v->setPosition(220, 140);
193         }
194
195         v->draw();
196         BoxStack::getInstance()->add(v);
197         BoxStack::getInstance()->update(v);
198         return 2;
199       }
200     }
201
202     case Remote::BACK:
203     {
204       return 4;
205     }
206   }
207   // stop command getting to any more views
208   return 1;
209 }
210
211 void VRecording::doRight()
212 {
213   switch(selected)
214   {
215     case 1:
216       buttonPlay.setActive(0);
217       buttonResume.setActive(1);
218       buttonPlay.draw();
219       buttonResume.draw();
220       break;
221     case 2:
222       buttonResume.setActive(0);
223       buttonMove.setActive(1);
224       buttonResume.draw();
225       buttonMove.draw();
226       break;
227     case 3:
228       buttonMove.setActive(0);
229       buttonDelete.setActive(1);
230       buttonMove.draw();
231       buttonDelete.draw();
232       break;
233     case 4:
234       buttonDelete.setActive(0);
235       buttonPlay.setActive(1);
236       buttonDelete.draw();
237       buttonPlay.draw();
238       break;
239   }
240   
241   if (++selected == 5) selected = 1;
242   
243   BoxStack::getInstance()->update(this, &buttonRegion);
244 }
245
246 void VRecording::doLeft()
247 {
248   switch(selected)
249   {
250     case 1:
251       buttonPlay.setActive(0);
252       buttonDelete.setActive(1);
253       buttonPlay.draw();
254       buttonDelete.draw();
255       break;
256     case 2:
257       buttonResume.setActive(0);
258       buttonPlay.setActive(1);
259       buttonResume.draw();
260       buttonPlay.draw();
261       break;
262     case 3:
263       buttonMove.setActive(0);
264       buttonResume.setActive(1);
265       buttonMove.draw();
266       buttonResume.draw();
267       break;
268     case 4:
269       buttonDelete.setActive(0);
270       buttonMove.setActive(1);
271       buttonDelete.draw();
272       buttonMove.draw();
273       break;
274   }
275   
276   if (--selected == 0) selected = 4;
277   
278   BoxStack::getInstance()->update(this, &buttonRegion);
279 }
280
281 void VRecording::processMessage(Message* m)
282 {
283   if (m->message == Message::MOUSE_MOVE)
284   {
285     if (buttonPlay.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
286     {
287       buttonPlay.setActive(1);
288       buttonResume.setActive(0);
289       buttonMove.setActive(0);
290       buttonDelete.setActive(0);
291       selected=1;
292       draw();
293       BoxStack::getInstance()->update(this);
294     }
295     else if (buttonResume.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
296     {
297       buttonPlay.setActive(0);
298       buttonResume.setActive(1);
299       buttonMove.setActive(0);
300       buttonDelete.setActive(0);
301       selected=2;
302       draw();
303       BoxStack::getInstance()->update(this);
304     }
305     else if (buttonMove.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
306     {
307       buttonPlay.setActive(0);
308       buttonResume.setActive(0);
309       buttonMove.setActive(1);
310       buttonDelete.setActive(0);
311       selected=3;
312       draw();
313       BoxStack::getInstance()->update(this);
314     }
315     else if (buttonDelete.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
316     {
317       buttonPlay.setActive(0);
318       buttonResume.setActive(0);
319       buttonMove.setActive(0);
320       buttonDelete.setActive(1);
321       selected=4;
322       draw();
323       BoxStack::getInstance()->update(this);
324     }
325   }
326   else if (m->message == Message::MOUSE_LBDOWN)
327   {
328     if (buttonPlay.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
329     {
330       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
331     }
332     else if (buttonResume.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
333     {
334       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
335     }
336     else if (buttonMove.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
337     {
338       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
339     }
340     else if (buttonDelete.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
341     {
342       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
343     }
344     else
345     {
346       //check if press is outside this view! then simulate cancel
347       int x=(m->parameter>>16)-getScreenX();
348       int y=(m->parameter&0xFFFF)-getScreenY();
349       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
350       {
351         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
352       }
353     }
354   }
355   else if (m->message == Message::QUESTION_YES)
356   {
357     if (selected == 4)
358     {
359       Message* m2 = new Message(); // Delete self
360       m2->from = this;
361       m2->to = BoxStack::getInstance();
362       m2->message = Message::CLOSE_ME;
363       Command::getInstance()->postMessageNoLock(m2);
364
365       m2 = new Message(); // OK. Want this to delete before this message does its job
366       m2->from = this;
367       m2->to = vRecList;
368       m2->message = Message::DELETE_SELECTED_RECORDING;
369       Command::getInstance()->postMessageNoLock(m2);
370     }
371   }
372   else if (m->message == Message::MOVE_RECORDING)
373   {
374     Message* m2 = new Message(); // Delete self
375     m2->from = this;
376     m2->to = BoxStack::getInstance();
377     m2->message = Message::CLOSE_ME;
378     Command::getInstance()->postMessageNoLock(m2);
379
380     m2 = new Message();
381     m2->from = this;
382     m2->to = vRecList;
383     m2->message = Message::MOVE_RECORDING;
384     m2->parameter = m->parameter;
385     Command::getInstance()->postMessageNoLock(m2);
386   }
387 }
388