]> git.vomp.tv Git - vompclient.git/blob - vtimeredit.cc
Fix black background for 16:9 live TV on 4:3 screen
[vompclient.git] / vtimeredit.cc
1
2 /*
3     Copyright 2004-2005 Chris Tallon
4
5     This file is part of VOMP.
6
7     VOMP is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     VOMP is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 #include "vtimeredit.h"
22
23 #include "input.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 "vquestion.h"
31 #include "messagequeue.h"
32 #include "staticartwork.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   TVMediaInfo *info= new TVMediaInfo();
61   info->setStaticArtwork(sa_timers);
62   setTitleBarIcon(info);
63 }
64
65 VTimerEdit::~VTimerEdit()
66 {
67 }
68
69 void VTimerEdit::setParent(VTimerList* tvTimerList)
70 {
71   vTimerList = tvTimerList;
72 }
73
74 void VTimerEdit::draw()
75 {
76   TBBoxx::draw();
77
78   int xpos = 20;
79   int ypos = 50;
80   int fontheight=getFontHeight();
81   drawText(tr("Active"), xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
82   drawText(tr("Channel"), xpos, ypos, DrawStyle::LIGHTTEXT);        ypos += fontheight;
83   drawText(tr("Name"), xpos, ypos, DrawStyle::LIGHTTEXT);           ypos += fontheight;
84   drawText(tr("Directory"), xpos, ypos, DrawStyle::LIGHTTEXT);      ypos += fontheight;
85                                                              ypos += fontheight;
86   drawText(tr("Start"), xpos, ypos, DrawStyle::LIGHTTEXT);          ypos += fontheight;
87   drawText(tr("Stop"), xpos, ypos, DrawStyle::LIGHTTEXT);           ypos += fontheight;
88   drawText(tr("Priority"), xpos, ypos, DrawStyle::LIGHTTEXT);       ypos += fontheight;
89   drawText(tr("Lifetime"), xpos, ypos, DrawStyle::LIGHTTEXT);       ypos += fontheight;
90                                                              ypos += fontheight;
91   drawText(tr("Current"), xpos, ypos, DrawStyle::LIGHTTEXT);        ypos += fontheight;
92   drawText(tr("Recording"), xpos, ypos, DrawStyle::LIGHTTEXT);      ypos += fontheight;
93
94
95   // Temp
96   char buffer[1000];
97   struct tm tms;
98   xpos = 150;
99   ypos = 50;
100
101   // Active
102   if (recTimer->active) strcpy(buffer, tr("Yes"));
103   else                  strcpy(buffer, tr("No"));
104   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
105
106   // Channel
107   SNPRINTF(buffer, 999, "%lu", recTimer->channelNumber);
108   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
109
110   // Name
111   SNPRINTF(buffer, 999, "%s", recTimer->getName());
112   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
113
114   // Directory
115   if (recTimer->getDirectory()) SNPRINTF(buffer, 999, "%s", recTimer->getDirectory());
116   else strcpy(buffer, "");
117   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
118                                                            ypos += fontheight;
119
120   // Start
121   time_t rectime = recTimer->startTime;
122   LOCALTIME_R(&rectime, &tms);
123   strftime(buffer, 999, "%d/%m %H:%M", &tms);
124   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
125
126   // Stop
127   rectime = recTimer->stopTime;
128   LOCALTIME_R(&rectime, &tms);
129   strftime(buffer, 999, "%d/%m %H:%M", &tms);
130   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
131
132   // Priority
133   SNPRINTF(buffer, 999, "%lu", recTimer->priority);
134   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
135
136   // Lifetime
137   SNPRINTF(buffer, 999, "%lu", recTimer->lifeTime);
138   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
139                                                            ypos += fontheight;
140
141   // Current
142   if (recTimer->pending) strcpy(buffer, tr("Yes"));
143   else                   strcpy(buffer, tr("No"));
144   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
145
146   // Recording now
147   if (recTimer->recording) strcpy(buffer, "Yes");
148   else                     strcpy(buffer, "No");
149   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
150 }
151
152 void VTimerEdit::swap()
153 {
154   if (selectedButton == 0)
155   {
156     buttonBack.setActive(0);
157     buttonDelete.setActive(1);
158     selectedButton = 1;
159   }
160   else
161   {
162     buttonDelete.setActive(0);
163     buttonBack.setActive(1);
164     selectedButton = 0;
165   }
166 }
167
168 int VTimerEdit::handleCommand(int command)
169 {
170   switch(command)
171   {
172     /*
173     case Input::UP:
174     {
175
176       ViewMan::getInstance()->updateView(this);
177       return 2;
178     }
179     case Input::DOWN:
180     {
181
182       ViewMan::getInstance()->updateView(this);
183       return 2;
184     }
185     */
186     case Input::LEFT:
187     {
188       swap();
189       buttonBack.draw();
190       buttonDelete.draw();
191       BoxStack::getInstance()->update(this);
192       return 2;
193     }
194     case Input::RIGHT:
195     {
196       swap();
197       buttonBack.draw();
198       buttonDelete.draw();
199       BoxStack::getInstance()->update(this);
200       return 2;
201     }
202     case Input::OK:
203     {
204       // Back
205       if (selectedButton == 0) return 4;
206       // Delete
207       VQuestion* v = new VQuestion(this);
208       v->setSize(260, 180);
209       v->createBuffer();
210       v->setTitleBarColour(DrawStyle::DANGER);
211       v->setTitleBarOn(1);
212       v->setBorderOn(1);
213       v->setTitleText(tr("Delete timer"));
214       v->setMainText(tr("Are you sure you want to delete this timer?"));
215       v->setDefault(VQuestion::NO);
216       if (Video::getInstance()->getFormat() == Video::PAL)
217         v->setPosition(230, 160);
218       else
219         v->setPosition(220, 140);
220       v->draw();
221       BoxStack::getInstance()->add(v);
222       BoxStack::getInstance()->update(v);
223       return 2;
224     }
225     case Input::BACK:
226     {
227       return 4;
228     }
229   }
230   // stop command getting to any more views
231   return 1;
232 }
233
234 void VTimerEdit::processMessage(Message* m)
235 {
236   if (m->message == Message::MOUSE_MOVE)
237   {
238       int x=(m->parameter>>16)-getScreenX();
239       int y=(m->parameter&0xFFFF)-getScreenY();
240       if (buttonBack.mouseMove(x,y)) {
241           selectedButton=0;
242           buttonDelete.setActive(false);
243           buttonBack.draw();
244           buttonDelete.draw();
245           BoxStack::getInstance()->update(this);
246       } else if  (buttonDelete.mouseMove(x,y)) {
247           selectedButton=1;
248           buttonBack.setActive(false);
249           buttonBack.draw();
250           buttonDelete.draw();
251           BoxStack::getInstance()->update(this);
252       }
253
254   } else if (m->message == Message::MOUSE_LBDOWN)
255   {
256     BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
257   }
258   else if (m->message == Message::QUESTION_YES)
259   {
260   if (selectedButton == 1)
261     {
262       Message* m2 = new Message(); // Delete self
263       m2->from = this;
264       m2->to = BoxStack::getInstance();
265       m2->message = Message::CLOSE_ME;
266       MessageQueue::getInstance()->postMessage(m2);
267
268       m2 = new Message(); // OK. Want this to delete before this message does its job
269       m2->from = this;
270       m2->to = vTimerList;
271       m2->message = Message::DELETE_SELECTED_TIMER;
272       MessageQueue::getInstance()->postMessage(m2);
273     }
274   }
275 }
276