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