]> git.vomp.tv Git - vompclient.git/blob - vtimeredit.cc
Message queue fix for VVideoRec
[vompclient.git] / vtimeredit.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 "vtimeredit.h"
21
22 #include "input.h"
23 #include "wsymbol.h"
24 #include "boxstack.h"
25 #include "vdr.h"
26 #include "colour.h"
27 #include "video.h"
28 #include "i18n.h"
29 #include "vquestion.h"
30 #include "messagequeue.h"
31 #include "staticartwork.h"
32
33 VTimerEdit::VTimerEdit(RecTimer* trt)
34 {
35   recTimer = trt;
36
37   setSize(570, 420);
38   createBuffer();
39   if (Video::getInstance()->getFormat() == Video::PAL)
40   {
41     setPosition(80, 70);
42   }
43   else
44   {
45     setPosition(70, 35);
46   }
47   selectedButton = 0;
48   buttonBack.setPosition(30,350);
49   buttonDelete.setPosition(400,350);
50   buttonBack.setText(tr("Back"));
51   buttonBack.setActive(1);
52   buttonDelete.setText(tr("Delete"));
53   add(&buttonBack);
54   add(&buttonDelete);
55
56   setTitleBarOn(1);
57   setTitleText(tr("Edit Timer"));
58   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
59   TVMediaInfo *info= new TVMediaInfo();
60   info->setStaticArtwork(sa_timers);
61   setTitleBarIcon(info);
62   MessageQueue::getInstance()->addReceiver(this);
63 }
64
65 VTimerEdit::~VTimerEdit()
66 {
67   MessageQueue::getInstance()->removeReceiver(this);
68 }
69
70 void VTimerEdit::setParent(MessageReceiver* tvTimerList)
71 {
72   vTimerList = tvTimerList;
73 }
74
75 void VTimerEdit::draw()
76 {
77   TBBoxx::draw();
78
79   int xpos = 20;
80   int ypos = 50;
81   int fontheight=getFontHeight();
82   drawText(tr("Active"), xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
83   drawText(tr("Channel"), xpos, ypos, DrawStyle::LIGHTTEXT);        ypos += fontheight;
84   drawText(tr("Name"), xpos, ypos, DrawStyle::LIGHTTEXT);           ypos += fontheight;
85   drawText(tr("Directory"), xpos, ypos, DrawStyle::LIGHTTEXT);      ypos += fontheight;
86                                                              ypos += fontheight;
87   drawText(tr("Start"), xpos, ypos, DrawStyle::LIGHTTEXT);          ypos += fontheight;
88   drawText(tr("Stop"), xpos, ypos, DrawStyle::LIGHTTEXT);           ypos += fontheight;
89   drawText(tr("Priority"), xpos, ypos, DrawStyle::LIGHTTEXT);       ypos += fontheight;
90   drawText(tr("Lifetime"), xpos, ypos, DrawStyle::LIGHTTEXT);       ypos += fontheight;
91                                                              ypos += fontheight;
92   drawText(tr("Current"), xpos, ypos, DrawStyle::LIGHTTEXT);        ypos += fontheight;
93   drawText(tr("Recording"), xpos, ypos, DrawStyle::LIGHTTEXT);      ypos += fontheight;
94
95
96   // Temp
97   char buffer[1000];
98   struct tm tms;
99   xpos = 150;
100   ypos = 50;
101
102   // Active
103   if (recTimer->active) strcpy(buffer, tr("Yes"));
104   else                  strcpy(buffer, tr("No"));
105   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
106
107   // Channel
108   SNPRINTF(buffer, 999, "%lu", recTimer->channelNumber);
109   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
110
111   // Name
112   SNPRINTF(buffer, 999, "%s", recTimer->getName());
113   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
114
115   // Directory
116   if (recTimer->getDirectory()) SNPRINTF(buffer, 999, "%s", recTimer->getDirectory());
117   else strcpy(buffer, "");
118   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
119                                                            ypos += fontheight;
120
121   // Start
122   time_t rectime = recTimer->startTime;
123   LOCALTIME_R(&rectime, &tms);
124   strftime(buffer, 999, "%d/%m %H:%M", &tms);
125   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
126
127   // Stop
128   rectime = recTimer->stopTime;
129   LOCALTIME_R(&rectime, &tms);
130   strftime(buffer, 999, "%d/%m %H:%M", &tms);
131   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
132
133   // Priority
134   SNPRINTF(buffer, 999, "%lu", recTimer->priority);
135   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
136
137   // Lifetime
138   SNPRINTF(buffer, 999, "%lu", recTimer->lifeTime);
139   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
140                                                            ypos += fontheight;
141
142   // Current
143   if (recTimer->pending) strcpy(buffer, tr("Yes"));
144   else                   strcpy(buffer, tr("No"));
145   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
146
147   // Recording now
148   if (recTimer->recording) strcpy(buffer, "Yes");
149   else                     strcpy(buffer, "No");
150   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
151 }
152
153 void VTimerEdit::swap()
154 {
155   if (selectedButton == 0)
156   {
157     buttonBack.setActive(0);
158     buttonDelete.setActive(1);
159     selectedButton = 1;
160   }
161   else
162   {
163     buttonDelete.setActive(0);
164     buttonBack.setActive(1);
165     selectedButton = 0;
166   }
167 }
168
169 int VTimerEdit::handleCommand(int command)
170 {
171   switch(command)
172   {
173     /*
174     case Input::UP:
175     {
176
177       ViewMan::getInstance()->updateView(this);
178       return BoxStack::COMMAND_HANDLED;
179     }
180     case Input::DOWN:
181     {
182
183       ViewMan::getInstance()->updateView(this);
184       return BoxStack::COMMAND_HANDLED;
185     }
186     */
187     case Input::LEFT:
188     {
189       swap();
190       buttonBack.draw();
191       buttonDelete.draw();
192       BoxStack::getInstance()->update(this);
193       return BoxStack::COMMAND_HANDLED;
194     }
195     case Input::RIGHT:
196     {
197       swap();
198       buttonBack.draw();
199       buttonDelete.draw();
200       BoxStack::getInstance()->update(this);
201       return BoxStack::COMMAND_HANDLED;
202     }
203     case Input::OK:
204     {
205       // Back
206       if (selectedButton == 0) return BoxStack::DELETE_ME;
207       // Delete
208       VQuestion* v = new VQuestion(this);
209       v->setSize(260, 180);
210       v->createBuffer();
211       v->setTitleBarColour(DrawStyle::DANGER);
212       v->setTitleBarOn(1);
213       v->setBorderOn(1);
214       v->setTitleText(tr("Delete timer"));
215       v->setMainText(tr("Are you sure you want to delete this timer?"));
216       v->setDefault(VQuestion::NO);
217       if (Video::getInstance()->getFormat() == Video::PAL)
218         v->setPosition(230, 160);
219       else
220         v->setPosition(220, 140);
221       v->draw();
222       BoxStack::getInstance()->add(v);
223       BoxStack::getInstance()->update(v);
224       return BoxStack::COMMAND_HANDLED;
225     }
226     case Input::BACK:
227     {
228       return BoxStack::DELETE_ME;
229     }
230   }
231   // stop command getting to any more views
232   return BoxStack::ABANDON_COMMAND;
233 }
234
235 void VTimerEdit::processMessage(Message* m)
236 {
237   if (m->message == Message::MOUSE_MOVE)
238   {
239       int x = m->parameter - getScreenX();
240       int y = m->tag - getScreenY();
241       if (buttonBack.mouseMove(x,y)) {
242           selectedButton=0;
243           buttonDelete.setActive(false);
244           buttonBack.draw();
245           buttonDelete.draw();
246           BoxStack::getInstance()->update(this);
247       } else if  (buttonDelete.mouseMove(x,y)) {
248           selectedButton=1;
249           buttonBack.setActive(false);
250           buttonBack.draw();
251           buttonDelete.draw();
252           BoxStack::getInstance()->update(this);
253       }
254
255   } else if (m->message == Message::MOUSE_LBDOWN)
256   {
257     Input::sendInputKey(Input::OK);
258   }
259   else if (m->message == Message::QUESTION_YES)
260   {
261   if (selectedButton == 1)
262     {
263       Message* m2 = new Message(); // Delete self
264       m2->from = this;
265       m2->p_to = Message::BOXSTACK;
266       m2->message = Message::CLOSE_ME;
267       MessageQueue::getInstance()->postMessage(m2);
268
269       m2 = new Message(); // OK. Want this to delete before this message does its job
270       m2->from = this;
271       m2->to = vTimerList;
272       m2->message = Message::DELETE_SELECTED_TIMER;
273       MessageQueue::getInstance()->postMessage(m2);
274     }
275   }
276 }
277