]> git.vomp.tv Git - vompclient.git/blob - vrecording.cc
New recordings menu
[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(70, area.h - 40);
78   buttonResume.setPosition(180, area.h - 40);
79   buttonMove.setPosition(290, area.h - 40);
80   buttonDelete.setPosition(400, area.h - 40);
81   
82   buttonRegion.x = 70;
83   buttonRegion.y = area.h - 40;
84   buttonRegion.w = 460;
85   buttonRegion.h = Surface::getFontHeight();
86
87   buttonPlay.setText(tr("Play"));
88   buttonResume.setText(tr("Resume"));
89   buttonMove.setText(tr("Move"));
90   buttonDelete.setText(tr("Delete"));
91   
92   add(&buttonPlay);
93   add(&buttonResume);    
94   add(&buttonMove);
95   add(&buttonDelete);
96   
97   buttonPlay.setActive(1);
98   selected = 1;
99 }
100
101 VRecording::~VRecording()
102 {
103 }
104
105 void VRecording::setParent(VRecordingList* tvRecList)
106 {
107   vRecList = tvRecList;
108 }
109
110 void VRecording::draw()
111 {
112   TBBoxx::draw();
113 }
114
115 int VRecording::handleCommand(int command)
116 {
117   switch(command)
118   {
119     case Remote::LEFT:
120     case Remote::DF_UP:
121     case Remote::UP:
122     {
123       doLeft();
124       return 2;
125     }
126     case Remote::RIGHT:
127     case Remote::DF_DOWN:
128     case Remote::DOWN:
129     {
130       doRight();
131       return 2;
132     }
133     case Remote::OK:
134     {
135
136       if (selected == 1)
137       {
138         Message* m = new Message(); // Must be done after this view deleted
139         m->from = this;
140         m->to = vRecList;
141         m->message = Message::PLAY_SELECTED_RECORDING;
142         Command::getInstance()->postMessageNoLock(m);
143         return 4;
144       }
145
146       if (selected == 2)
147       {
148         Message* m = new Message(); // Must be done after this view deleted
149         m->from = this;
150         m->to = vRecList;
151         m->message = Message::RESUME_SELECTED_RECORDING;
152         Command::getInstance()->postMessageNoLock(m);
153         return 4;
154       }
155
156       if (selected == 3)
157       {
158         VRecMove* vrm = new VRecMove(recman);
159         vrm->setParent(this);
160         vrm->draw();
161         BoxStack::getInstance()->add(vrm);
162         BoxStack::getInstance()->update(vrm);
163         return 2;
164       }
165
166       if (selected == 4)
167       {
168         VQuestion* v = new VQuestion(this);
169         v->setSize(260, 180);
170         v->createBuffer();
171         v->setTitleBarColour(Colour::DANGER);
172         v->setTitleBarOn(1);
173         v->setBorderOn(1);
174         v->setTitleText(tr("Delete recording"));
175         v->setMainText(tr("Are you sure you want to delete this recording?"));
176         v->setDefault(VQuestion::NO);
177         if (Video::getInstance()->getFormat() == Video::PAL)
178         {
179           v->setPosition(230, 160);
180         }
181         else
182         {
183           v->setPosition(220, 140);
184         }
185
186         v->draw();
187         BoxStack::getInstance()->add(v);
188         BoxStack::getInstance()->update(v);
189         return 2;
190       }
191     }
192
193     case Remote::BACK:
194     {
195       return 4;
196     }
197   }
198   // stop command getting to any more views
199   return 1;
200 }
201
202 void VRecording::doRight()
203 {
204   switch(selected)
205   {
206     case 1:
207       buttonPlay.setActive(0);
208       buttonResume.setActive(1);
209       buttonPlay.draw();
210       buttonResume.draw();
211       break;
212     case 2:
213       buttonResume.setActive(0);
214       buttonMove.setActive(1);
215       buttonResume.draw();
216       buttonMove.draw();
217       break;
218     case 3:
219       buttonMove.setActive(0);
220       buttonDelete.setActive(1);
221       buttonMove.draw();
222       buttonDelete.draw();
223       break;
224     case 4:
225       buttonDelete.setActive(0);
226       buttonPlay.setActive(1);
227       buttonDelete.draw();
228       buttonPlay.draw();
229       break;
230   }
231   
232   if (++selected == 5) selected = 1;
233   
234   BoxStack::getInstance()->update(this, &buttonRegion);
235 }
236
237 void VRecording::doLeft()
238 {
239   switch(selected)
240   {
241     case 1:
242       buttonPlay.setActive(0);
243       buttonDelete.setActive(1);
244       buttonPlay.draw();
245       buttonDelete.draw();
246       break;
247     case 2:
248       buttonResume.setActive(0);
249       buttonPlay.setActive(1);
250       buttonResume.draw();
251       buttonPlay.draw();
252       break;
253     case 3:
254       buttonMove.setActive(0);
255       buttonResume.setActive(1);
256       buttonMove.draw();
257       buttonResume.draw();
258       break;
259     case 4:
260       buttonDelete.setActive(0);
261       buttonMove.setActive(1);
262       buttonDelete.draw();
263       buttonMove.draw();
264       break;
265   }
266   
267   if (--selected == 0) selected = 4;
268   
269   BoxStack::getInstance()->update(this, &buttonRegion);
270 }
271
272 void VRecording::processMessage(Message* m)
273 {
274 /*
275   if (m->message == Message::MOUSE_MOVE)
276   {
277     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
278     {
279       sl.draw();
280       BoxStack::getInstance()->update(this);
281     }
282   }
283   else if (m->message == Message::MOUSE_LBDOWN)
284   {
285     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
286     {
287       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
288     }
289     else
290     {
291       //check if press is outside this view! then simulate cancel
292       int x=(m->parameter>>16)-getScreenX();
293       int y=(m->parameter&0xFFFF)-getScreenY();
294       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
295       {
296         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
297       }
298     }
299   }
300   */
301   if (m->message == Message::QUESTION_YES)
302   {
303     if (selected == 4)
304     {
305       Message* m2 = new Message(); // Delete self
306       m2->from = this;
307       m2->to = BoxStack::getInstance();
308       m2->message = Message::CLOSE_ME;
309       Command::getInstance()->postMessageNoLock(m2);
310
311       m2 = new Message(); // OK. Want this to delete before this message does its job
312       m2->from = this;
313       m2->to = vRecList;
314       m2->message = Message::DELETE_SELECTED_RECORDING;
315       Command::getInstance()->postMessageNoLock(m2);
316     }
317   }
318   else if (m->message == Message::MOVE_RECORDING)
319   {
320     Message* m2 = new Message(); // Delete self
321     m2->from = this;
322     m2->to = BoxStack::getInstance();
323     m2->message = Message::CLOSE_ME;
324     Command::getInstance()->postMessageNoLock(m2);
325
326     m2 = new Message();
327     m2->from = this;
328     m2->to = vRecList;
329     m2->message = Message::MOVE_RECORDING;
330     m2->parameter = m->parameter;
331     Command::getInstance()->postMessageNoLock(m2);
332   }
333 }
334