]> git.vomp.tv Git - vompclient.git/blob - vrecordingmenu.cc
Remove deprecated max() function
[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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "vrecordingmenu.h"
21
22 #include "input.h"
23 #include "recinfo.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 "messagequeue.h"
31 #include "vrecmove.h"
32 #include "boxstack.h"
33 #include "recman.h"
34 #include "recording.h"
35 #include "message.h"
36
37 VRecordingMenu::VRecordingMenu(RecMan* trecman)
38 {
39   rec = NULL;
40   recman = trecman;
41
42   setSize(200, 164);
43   createBuffer();
44   if (Video::getInstance()->getFormat() == Video::PAL)
45   {
46     setPosition(260, 190);
47   }
48   else
49   {
50     setPosition(250, 160);
51   }
52
53   setTitleBarOn(1);
54   setBorderOn(1);
55   setTitleText(tr("Programme menu"));
56   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
57
58   sl.setPosition(10, 30 + 5);
59   sl.setSize(area.w - 20, area.h - 30 - 15);
60   sl.addOption(tr("Play"), reinterpret_cast<void*>(1), 1);
61   sl.addOption(tr("Resume"), reinterpret_cast<void*>(2), 0);
62   sl.addOption(tr("Summary"), reinterpret_cast<void*>(3), 0);
63   sl.addOption(tr("Move"), reinterpret_cast<void*>(4), 0);
64   sl.addOption(tr("Delete"), reinterpret_cast<void*>(5), 0);
65   add(&sl);
66
67   MessageQueue::getInstance()->addReceiver(this);
68 }
69
70 VRecordingMenu::~VRecordingMenu()
71 {
72   MessageQueue::getInstance()->removeReceiver(this);
73 }
74
75 void VRecordingMenu::setParent(MessageReceiver* tvRecList)
76 {
77   vRecList = tvRecList;
78 }
79
80 void VRecordingMenu::setRecording(Recording* trec)
81 {
82   rec = trec;
83 }
84
85 int VRecordingMenu::handleCommand(int command)
86 {
87   switch(command)
88   {
89     case Input::UP:
90     {
91       sl.up();
92       sl.draw();
93       BoxStack::getInstance()->update(this);
94       return BoxStack::COMMAND_HANDLED;
95     }
96     case Input::DOWN:
97     {
98       sl.down();
99       sl.draw();
100       BoxStack::getInstance()->update(this);
101       return BoxStack::COMMAND_HANDLED;
102     }
103     case Input::OK:
104     {
105       ULONG slCurrentOption = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
106       if (slCurrentOption == 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         MessageQueue::getInstance()->postMessage(m);
113         return BoxStack::DELETE_ME;
114       }
115
116       if (slCurrentOption == 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         MessageQueue::getInstance()->postMessage(m);
123         return BoxStack::DELETE_ME;
124       }
125
126       if (slCurrentOption == 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 BoxStack::COMMAND_HANDLED;
149       }
150
151       if (slCurrentOption == 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 BoxStack::COMMAND_HANDLED;
159       }
160
161       if (slCurrentOption == 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 BoxStack::COMMAND_HANDLED;
185       }
186
187       FALLTHROUGH
188       // it won't, as long as sl.getCurrentOptionData() is 1-5, but keep the compiler happy
189     }
190     case Input::BACK:
191     {
192       return BoxStack::DELETE_ME;
193     }
194   }
195   // stop command getting to any more views
196   return BoxStack::ABANDON_COMMAND;
197 }
198
199 void VRecordingMenu::processMessage(Message* m)
200 {
201   if (m->message == Message::MOUSE_MOVE)
202   {
203     if (sl.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
204     {
205       sl.draw();
206       BoxStack::getInstance()->update(this);
207     }
208   }
209   else if (m->message == Message::MOUSE_LBDOWN)
210   {
211     if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
212     {
213       Input::sendInputKey(Input::OK);
214     }
215     else if (coordsOutsideBox(m))
216     {
217       Input::sendInputKey(Input::BACK);
218     }
219   }
220   else if (m->message == Message::QUESTION_YES)
221   {
222     if (reinterpret_cast<ULONG>(sl.getCurrentOptionData()) == 5)
223     {
224       Message* m2 = new Message(); // Delete self
225       m2->from = this;
226       m2->p_to = Message::BOXSTACK;
227       m2->message = Message::CLOSE_ME;
228       MessageQueue::getInstance()->postMessage(m2);
229
230       m2 = new Message(); // OK. Want this to delete before this message does its job
231       m2->from = this;
232       m2->to = vRecList;
233       m2->message = Message::DELETE_SELECTED_RECORDING;
234       MessageQueue::getInstance()->postMessage(m2);
235     }
236   }
237   else if (m->message == Message::MOVE_RECORDING)
238   {
239     Message* m2 = new Message(); // Delete self
240     m2->from = this;
241     m2->p_to = Message::BOXSTACK;
242     m2->message = Message::CLOSE_ME;
243     MessageQueue::getInstance()->postMessage(m2);
244
245     m2 = new Message();
246     m2->from = this;
247     m2->to = vRecList;
248     m2->message = Message::MOVE_RECORDING;
249     m2->parameter = m->parameter;
250     MessageQueue::getInstance()->postMessage(m2);
251   }
252 }