]> git.vomp.tv Git - vompclient.git/blob - vrecordingmenu.cc
20 compiler warning fixes
[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 "remote.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 "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(DrawStyle::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         MessageQueue::getInstance()->postMessage(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         MessageQueue::getInstance()->postMessage(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(DrawStyle::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       [[fallthrough]]; // it won't, as long as sl.getCurrentOptionData() is 1-5, but keep the compiler happy
187     }
188     case Remote::BACK:
189     {
190       return 4;
191     }
192   }
193   // stop command getting to any more views
194   return 1;
195 }
196
197 void VRecordingMenu::processMessage(Message* m)
198 {
199   if (m->message == Message::MOUSE_MOVE)
200   {
201     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
202     {
203       sl.draw();
204       BoxStack::getInstance()->update(this);
205     }
206   }
207   else if (m->message == Message::MOUSE_LBDOWN)
208   {
209     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
210     {
211       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
212     }
213     else
214     {
215       //check if press is outside this view! then simulate cancel
216       int x=(m->parameter>>16)-getScreenX();
217       int y=(m->parameter&0xFFFF)-getScreenY();
218       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
219       {
220         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
221       }
222     }
223   }
224   else if (m->message == Message::QUESTION_YES)
225   {
226     if (sl.getCurrentOptionData() == 5)
227     {
228       Message* m2 = new Message(); // Delete self
229       m2->from = this;
230       m2->to = BoxStack::getInstance();
231       m2->message = Message::CLOSE_ME;
232       MessageQueue::getInstance()->postMessage(m2);
233
234       m2 = new Message(); // OK. Want this to delete before this message does its job
235       m2->from = this;
236       m2->to = vRecList;
237       m2->message = Message::DELETE_SELECTED_RECORDING;
238       MessageQueue::getInstance()->postMessage(m2);
239     }
240   }
241   else if (m->message == Message::MOVE_RECORDING)
242   {
243     Message* m2 = new Message(); // Delete self
244     m2->from = this;
245     m2->to = BoxStack::getInstance();
246     m2->message = Message::CLOSE_ME;
247     MessageQueue::getInstance()->postMessage(m2);
248
249     m2 = new Message();
250     m2->from = this;
251     m2->to = vRecList;
252     m2->message = Message::MOVE_RECORDING;
253     m2->parameter = m->parameter;
254     MessageQueue::getInstance()->postMessage(m2);
255   }
256 }