]> git.vomp.tv Git - vompclient-marten.git/blob - vrecording.cc
Windows updates
[vompclient-marten.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_UP:
128     case Remote::UP:
129     {
130       doLeft();
131       return 2;
132     }
133     case Remote::RIGHT:
134     case Remote::DF_DOWN:
135     case Remote::DOWN:
136     {
137       doRight();
138       return 2;
139     }
140     case Remote::OK:
141     {
142
143       if (selected == 1)
144       {
145         Message* m = new Message(); // Must be done after this view deleted
146         m->from = this;
147         m->to = vRecList;
148         m->message = Message::PLAY_SELECTED_RECORDING;
149         Command::getInstance()->postMessageNoLock(m);
150         return 4;
151       }
152
153       if (selected == 2)
154       {
155         Message* m = new Message(); // Must be done after this view deleted
156         m->from = this;
157         m->to = vRecList;
158         m->message = Message::RESUME_SELECTED_RECORDING;
159         Command::getInstance()->postMessageNoLock(m);
160         return 4;
161       }
162
163       if (selected == 3)
164       {
165         VRecMove* vrm = new VRecMove(recman);
166         vrm->setParent(this);
167         vrm->draw();
168         BoxStack::getInstance()->add(vrm);
169         BoxStack::getInstance()->update(vrm);
170         return 2;
171       }
172
173       if (selected == 4)
174       {
175         VQuestion* v = new VQuestion(this);
176         v->setSize(260, 180);
177         v->createBuffer();
178         v->setTitleBarColour(Colour::DANGER);
179         v->setTitleBarOn(1);
180         v->setBorderOn(1);
181         v->setTitleText(tr("Delete recording"));
182         v->setMainText(tr("Are you sure you want to delete this recording?"));
183         v->setDefault(VQuestion::NO);
184         if (Video::getInstance()->getFormat() == Video::PAL)
185         {
186           v->setPosition(230, 160);
187         }
188         else
189         {
190           v->setPosition(220, 140);
191         }
192
193         v->draw();
194         BoxStack::getInstance()->add(v);
195         BoxStack::getInstance()->update(v);
196         return 2;
197       }
198     }
199
200     case Remote::BACK:
201     {
202       return 4;
203     }
204   }
205   // stop command getting to any more views
206   return 1;
207 }
208
209 void VRecording::doRight()
210 {
211   switch(selected)
212   {
213     case 1:
214       buttonPlay.setActive(0);
215       buttonResume.setActive(1);
216       buttonPlay.draw();
217       buttonResume.draw();
218       break;
219     case 2:
220       buttonResume.setActive(0);
221       buttonMove.setActive(1);
222       buttonResume.draw();
223       buttonMove.draw();
224       break;
225     case 3:
226       buttonMove.setActive(0);
227       buttonDelete.setActive(1);
228       buttonMove.draw();
229       buttonDelete.draw();
230       break;
231     case 4:
232       buttonDelete.setActive(0);
233       buttonPlay.setActive(1);
234       buttonDelete.draw();
235       buttonPlay.draw();
236       break;
237   }
238   
239   if (++selected == 5) selected = 1;
240   
241   BoxStack::getInstance()->update(this, &buttonRegion);
242 }
243
244 void VRecording::doLeft()
245 {
246   switch(selected)
247   {
248     case 1:
249       buttonPlay.setActive(0);
250       buttonDelete.setActive(1);
251       buttonPlay.draw();
252       buttonDelete.draw();
253       break;
254     case 2:
255       buttonResume.setActive(0);
256       buttonPlay.setActive(1);
257       buttonResume.draw();
258       buttonPlay.draw();
259       break;
260     case 3:
261       buttonMove.setActive(0);
262       buttonResume.setActive(1);
263       buttonMove.draw();
264       buttonResume.draw();
265       break;
266     case 4:
267       buttonDelete.setActive(0);
268       buttonMove.setActive(1);
269       buttonDelete.draw();
270       buttonMove.draw();
271       break;
272   }
273   
274   if (--selected == 0) selected = 4;
275   
276   BoxStack::getInstance()->update(this, &buttonRegion);
277 }
278
279 void VRecording::processMessage(Message* m)
280 {
281   if (m->message == Message::MOUSE_MOVE)
282   {
283     if (buttonPlay.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
284     {
285       buttonPlay.setActive(1);
286       buttonResume.setActive(0);
287       buttonMove.setActive(0);
288       buttonDelete.setActive(0);
289       selected=1;
290       draw();
291       BoxStack::getInstance()->update(this);
292     }
293     else if (buttonResume.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
294     {
295       buttonPlay.setActive(0);
296       buttonResume.setActive(1);
297       buttonMove.setActive(0);
298       buttonDelete.setActive(0);
299       selected=2;
300       draw();
301       BoxStack::getInstance()->update(this);
302     }
303     else if (buttonMove.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
304     {
305       buttonPlay.setActive(0);
306       buttonResume.setActive(0);
307       buttonMove.setActive(1);
308       buttonDelete.setActive(0);
309       selected=3;
310       draw();
311       BoxStack::getInstance()->update(this);
312     }
313     else if (buttonDelete.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
314     {
315       buttonPlay.setActive(0);
316       buttonResume.setActive(0);
317       buttonMove.setActive(0);
318       buttonDelete.setActive(1);
319       selected=4;
320       draw();
321       BoxStack::getInstance()->update(this);
322     }
323   }
324   else if (m->message == Message::MOUSE_LBDOWN)
325   {
326     if (buttonPlay.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
327     {
328       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
329     }
330     else if (buttonResume.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
331     {
332       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
333     }
334     else if (buttonMove.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
335     {
336       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
337     }
338     else if (buttonDelete.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
339     {
340       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
341     }
342     else
343     {
344       //check if press is outside this view! then simulate cancel
345       int x=(m->parameter>>16)-getScreenX();
346       int y=(m->parameter&0xFFFF)-getScreenY();
347       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
348       {
349         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
350       }
351     }
352   }
353   else if (m->message == Message::QUESTION_YES)
354   {
355     if (selected == 4)
356     {
357       Message* m2 = new Message(); // Delete self
358       m2->from = this;
359       m2->to = BoxStack::getInstance();
360       m2->message = Message::CLOSE_ME;
361       Command::getInstance()->postMessageNoLock(m2);
362
363       m2 = new Message(); // OK. Want this to delete before this message does its job
364       m2->from = this;
365       m2->to = vRecList;
366       m2->message = Message::DELETE_SELECTED_RECORDING;
367       Command::getInstance()->postMessageNoLock(m2);
368     }
369   }
370   else if (m->message == Message::MOVE_RECORDING)
371   {
372     Message* m2 = new Message(); // Delete self
373     m2->from = this;
374     m2->to = BoxStack::getInstance();
375     m2->message = Message::CLOSE_ME;
376     Command::getInstance()->postMessageNoLock(m2);
377
378     m2 = new Message();
379     m2->from = this;
380     m2->to = vRecList;
381     m2->message = Message::MOVE_RECORDING;
382     m2->parameter = m->parameter;
383     Command::getInstance()->postMessageNoLock(m2);
384   }
385 }
386