]> git.vomp.tv Git - vompclient.git/blob - vrecordingmenu.cc
Fix resuming recording directly after stopping it
[vompclient.git] / vrecordingmenu.cc
1 /*
2     Copyright 2004-2005 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 "vrecordingmenu.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
39 VRecordingMenu::VRecordingMenu(RecMan* trecman)
40 {
41   rec = NULL;
42   recman = trecman;
43
44   setSize(200, 164);
45   createBuffer();
46   if (Video::getInstance()->getFormat() == Video::PAL)
47   {
48     setPosition(260, 190);
49   }
50   else
51   {
52     setPosition(250, 160);
53   }
54
55   setTitleBarOn(1);
56   setBorderOn(1);
57   setTitleText(tr("Programme menu"));
58   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
59
60   sl.setPosition(10, 30 + 5);
61   sl.setSize(area.w - 20, area.h - 30 - 15);
62   sl.addOption(tr("Play"), 1, 1);
63   sl.addOption(tr("Resume"), 2, 0);
64   sl.addOption(tr("Summary"), 3, 0);
65   sl.addOption(tr("Move"), 4, 0);
66   sl.addOption(tr("Delete"), 5, 0);
67   add(&sl);
68 }
69
70 VRecordingMenu::~VRecordingMenu()
71 {
72 }
73
74 void VRecordingMenu::setParent(VRecordingList* tvRecList)
75 {
76   vRecList = tvRecList;
77 }
78
79 void VRecordingMenu::setRecording(Recording* trec)
80 {
81   rec = trec;
82 }
83
84 int VRecordingMenu::handleCommand(int command)
85 {
86   switch(command)
87   {
88     case Remote::DF_UP:
89     case Remote::UP:
90     {
91       sl.up();
92       sl.draw();
93       BoxStack::getInstance()->update(this);
94       return 2;
95     }
96     case Remote::DF_DOWN:
97     case Remote::DOWN:
98     {
99       sl.down();
100       sl.draw();
101       BoxStack::getInstance()->update(this);
102       return 2;
103     }
104     case Remote::OK:
105     {
106       if (sl.getCurrentOptionData() == 1)
107       {
108         Message* m = new Message(); // Must be done after this view deleted
109         m->from = this;
110         m->to = vRecList;
111         m->message = Message::PLAY_SELECTED_RECORDING;
112         Command::getInstance()->postMessageNoLock(m);
113         return 4;
114       }
115
116       if (sl.getCurrentOptionData() == 2)
117       {
118         Message* m = new Message(); // Must be done after this view deleted
119         m->from = this;
120         m->to = vRecList;
121         m->message = Message::RESUME_SELECTED_RECORDING;
122         Command::getInstance()->postMessageNoLock(m);
123         return 4;
124       }
125
126       if (sl.getCurrentOptionData() == 3)
127       {
128         rec->loadRecInfo();
129
130         VInfo* vi = new VInfo();
131         vi->setSize(490, 300);
132         vi->createBuffer();
133         if (Video::getInstance()->getFormat() == Video::PAL)
134           vi->setPosition(120, 130);
135         else
136           vi->setPosition(110, 90);
137         vi->setTitleText(tr("Programme summary"));
138         vi->setBorderOn(1);
139         vi->setExitable();
140         if (strlen(rec->recInfo->summary))
141           vi->setMainText(rec->recInfo->summary);
142         else
143           vi->setMainText(tr("Summary unavailable"));
144         vi->draw();
145         BoxStack::getInstance()->add(vi);
146         BoxStack::getInstance()->update(vi);
147
148         return 2;
149       }
150
151       if (sl.getCurrentOptionData() == 4)
152       {
153         VRecMove* vrm = new VRecMove(recman);
154         vrm->setParent(this);
155         vrm->draw();
156         BoxStack::getInstance()->add(vrm);
157         BoxStack::getInstance()->update(vrm);
158         return 2;
159       }
160
161       if (sl.getCurrentOptionData() == 5)
162       {
163         VQuestion* v = new VQuestion(this);
164         v->setSize(260, 180);
165         v->createBuffer();
166         v->setTitleBarColour(DrawStyle::DANGER);
167         v->setTitleBarOn(1);
168         v->setBorderOn(1);
169         v->setTitleText(tr("Delete recording"));
170         v->setMainText(tr("Are you sure you want to delete this recording?"));
171         v->setDefault(VQuestion::NO);
172         if (Video::getInstance()->getFormat() == Video::PAL)
173         {
174           v->setPosition(230, 160);
175         }
176         else
177         {
178           v->setPosition(220, 140);
179         }
180
181         v->draw();
182         BoxStack::getInstance()->add(v);
183         BoxStack::getInstance()->update(v);
184         return 2;
185       }
186     }
187     case Remote::BACK:
188     {
189       return 4;
190     }
191   }
192   // stop command getting to any more views
193   return 1;
194 }
195
196 void VRecordingMenu::processMessage(Message* m)
197 {
198   if (m->message == Message::MOUSE_MOVE)
199   {
200     if (sl.mouseMove((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
201     {
202       sl.draw();
203       BoxStack::getInstance()->update(this);
204     }
205   }
206   else if (m->message == Message::MOUSE_LBDOWN)
207   {
208     if (sl.mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
209     {
210       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
211     }
212     else
213     {
214       //check if press is outside this view! then simulate cancel
215       int x=(m->parameter.num>>16)-getScreenX();
216       int y=(m->parameter.num&0xFFFF)-getScreenY();
217       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
218       {
219         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
220       }
221     }
222   }
223   else if (m->message == Message::QUESTION_YES)
224   {
225     if (sl.getCurrentOptionData() == 5)
226     {
227       Message* m2 = new Message(); // Delete self
228       m2->from = this;
229       m2->to = BoxStack::getInstance();
230       m2->message = Message::CLOSE_ME;
231       Command::getInstance()->postMessageNoLock(m2);
232
233       m2 = new Message(); // OK. Want this to delete before this message does its job
234       m2->from = this;
235       m2->to = vRecList;
236       m2->message = Message::DELETE_SELECTED_RECORDING;
237       Command::getInstance()->postMessageNoLock(m2);
238     }
239   }
240   else if (m->message == Message::MOVE_RECORDING)
241   {
242     Message* m2 = new Message(); // Delete self
243     m2->from = this;
244     m2->to = BoxStack::getInstance();
245     m2->message = Message::CLOSE_ME;
246     Command::getInstance()->postMessageNoLock(m2);
247
248     m2 = new Message();
249     m2->from = this;
250     m2->to = vRecList;
251     m2->message = Message::MOVE_RECORDING;
252     m2->parameter.num = m->parameter.num;
253     Command::getInstance()->postMessageNoLock(m2);
254   }
255 }