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