]> git.vomp.tv Git - vompclient.git/blob - vrecordingmenu.cc
Windows 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 "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 "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"), reinterpret_cast<void*>(1), 1);
62   sl.addOption(tr("Resume"), reinterpret_cast<void*>(2), 0);
63   sl.addOption(tr("Summary"), reinterpret_cast<void*>(3), 0);
64   sl.addOption(tr("Move"), reinterpret_cast<void*>(4), 0);
65   sl.addOption(tr("Delete"), reinterpret_cast<void*>(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 Input::UP:
88     {
89       sl.up();
90       sl.draw();
91       BoxStack::getInstance()->update(this);
92       return 2;
93     }
94     case Input::DOWN:
95     {
96       sl.down();
97       sl.draw();
98       BoxStack::getInstance()->update(this);
99       return 2;
100     }
101     case Input::OK:
102     {
103       ULONG slCurrentOption = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
104       if (slCurrentOption == 1)
105       {
106         Message* m = new Message(); // Must be done after this view deleted
107         m->from = this;
108         m->to = vRecList;
109         m->message = Message::PLAY_SELECTED_RECORDING;
110         MessageQueue::getInstance()->postMessage(m);
111         return 4;
112       }
113
114       if (slCurrentOption == 2)
115       {
116         Message* m = new Message(); // Must be done after this view deleted
117         m->from = this;
118         m->to = vRecList;
119         m->message = Message::RESUME_SELECTED_RECORDING;
120         MessageQueue::getInstance()->postMessage(m);
121         return 4;
122       }
123
124       if (slCurrentOption == 3)
125       {
126         rec->loadRecInfo();
127
128         VInfo* vi = new VInfo();
129         vi->setSize(490, 300);
130         vi->createBuffer();
131         if (Video::getInstance()->getFormat() == Video::PAL)
132           vi->setPosition(120, 130);
133         else
134           vi->setPosition(110, 90);
135         vi->setTitleText(tr("Programme summary"));
136         vi->setBorderOn(1);
137         vi->setExitable();
138         if (strlen(rec->recInfo->summary))
139           vi->setMainText(rec->recInfo->summary);
140         else
141           vi->setMainText(tr("Summary unavailable"));
142         vi->draw();
143         BoxStack::getInstance()->add(vi);
144         BoxStack::getInstance()->update(vi);
145
146         return 2;
147       }
148
149       if (slCurrentOption == 4)
150       {
151         VRecMove* vrm = new VRecMove(recman);
152         vrm->setParent(this);
153         vrm->draw();
154         BoxStack::getInstance()->add(vrm);
155         BoxStack::getInstance()->update(vrm);
156         return 2;
157       }
158
159       if (slCurrentOption == 5)
160       {
161         VQuestion* v = new VQuestion(this);
162         v->setSize(260, 180);
163         v->createBuffer();
164         v->setTitleBarColour(DrawStyle::DANGER);
165         v->setTitleBarOn(1);
166         v->setBorderOn(1);
167         v->setTitleText(tr("Delete recording"));
168         v->setMainText(tr("Are you sure you want to delete this recording?"));
169         v->setDefault(VQuestion::NO);
170         if (Video::getInstance()->getFormat() == Video::PAL)
171         {
172           v->setPosition(230, 160);
173         }
174         else
175         {
176           v->setPosition(220, 140);
177         }
178
179         v->draw();
180         BoxStack::getInstance()->add(v);
181         BoxStack::getInstance()->update(v);
182         return 2;
183       }
184
185       FALLTHROUGH
186       // it won't, as long as sl.getCurrentOptionData() is 1-5, but keep the compiler happy
187     }
188     case Input::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(Input::OK); //simulate OK press
212     }
213     else if (coordsOutsideBox(m))
214     {
215       BoxStack::getInstance()->handleCommand(Input::BACK); //simulate cancel press
216     }
217   }
218   else if (m->message == Message::QUESTION_YES)
219   {
220     if (reinterpret_cast<ULONG>(sl.getCurrentOptionData()) == 5)
221     {
222       Message* m2 = new Message(); // Delete self
223       m2->from = this;
224       m2->to = BoxStack::getInstance();
225       m2->message = Message::CLOSE_ME;
226       MessageQueue::getInstance()->postMessage(m2);
227
228       m2 = new Message(); // OK. Want this to delete before this message does its job
229       m2->from = this;
230       m2->to = vRecList;
231       m2->message = Message::DELETE_SELECTED_RECORDING;
232       MessageQueue::getInstance()->postMessage(m2);
233     }
234   }
235   else if (m->message == Message::MOVE_RECORDING)
236   {
237     Message* m2 = new Message(); // Delete self
238     m2->from = this;
239     m2->to = BoxStack::getInstance();
240     m2->message = Message::CLOSE_ME;
241     MessageQueue::getInstance()->postMessage(m2);
242
243     m2 = new Message();
244     m2->from = this;
245     m2->to = vRecList;
246     m2->message = Message::MOVE_RECORDING;
247     m2->parameter = m->parameter;
248     MessageQueue::getInstance()->postMessage(m2);
249   }
250 }