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