]> git.vomp.tv Git - vompclient.git/blob - vtimeredit.cc
WIP
[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 "remote.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 "timers.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((time_t*)&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((time_t*)&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 Remote::DF_UP:
174     case Remote::UP:
175     {
176
177       ViewMan::getInstance()->updateView(this);
178       return 2;
179     }
180     case Remote::DF_DOWN:
181     case Remote::DOWN:
182     {
183
184       ViewMan::getInstance()->updateView(this);
185       return 2;
186     }
187     */
188     case Remote::LEFT:
189     case Remote::DF_RIGHT:
190     {
191       swap();
192       buttonBack.draw();
193       buttonDelete.draw();
194       BoxStack::getInstance()->update(this);
195       return 2;
196     }
197     case Remote::RIGHT:
198     case Remote::DF_LEFT:
199     {
200       swap();
201       buttonBack.draw();
202       buttonDelete.draw();
203       BoxStack::getInstance()->update(this);
204       return 2;
205     }
206     case Remote::OK:
207     {
208       // Back
209       if (selectedButton == 0) return 4;
210       // Delete
211       VQuestion* v = new VQuestion(this);
212       v->setSize(260, 180);
213       v->createBuffer();
214       v->setTitleBarColour(DrawStyle::DANGER);
215       v->setTitleBarOn(1);
216       v->setBorderOn(1);
217       v->setTitleText(tr("Delete timer"));
218       v->setMainText(tr("Are you sure you want to delete this timer?"));
219       v->setDefault(VQuestion::NO);
220       if (Video::getInstance()->getFormat() == Video::PAL)
221         v->setPosition(230, 160);
222       else
223         v->setPosition(220, 140);
224       v->draw();
225       BoxStack::getInstance()->add(v);
226       BoxStack::getInstance()->update(v);
227       return 2;
228     }
229     case Remote::BACK:
230     {
231       return 4;
232     }
233   }
234   // stop command getting to any more views
235   return 1;
236 }
237
238 void VTimerEdit::processMessage(Message* m)
239 {
240   if (m->message == Message::MOUSE_MOVE)
241   {
242       int x=(m->parameter>>16)-getScreenX();
243       int y=(m->parameter&0xFFFF)-getScreenY();
244       if (buttonBack.mouseMove(x,y)) {
245           selectedButton=0;
246           buttonDelete.setActive(false);
247           buttonBack.draw();
248           buttonDelete.draw();
249           BoxStack::getInstance()->update(this);
250       } else if  (buttonDelete.mouseMove(x,y)) {
251           selectedButton=1;
252           buttonBack.setActive(false);
253           buttonBack.draw();
254           buttonDelete.draw();
255           BoxStack::getInstance()->update(this);
256       }
257
258   } else if (m->message == Message::MOUSE_LBDOWN)
259   {
260     BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
261   }
262   else if (m->message == Message::QUESTION_YES)
263   {
264   if (selectedButton == 1)
265     {
266       Message* m2 = new Message(); // Delete self
267       m2->from = this;
268       m2->to = BoxStack::getInstance();
269       m2->message = Message::CLOSE_ME;
270       MessageQueue::getInstance()->postMessageNoLock(m2);
271
272       m2 = new Message(); // OK. Want this to delete before this message does its job
273       m2->from = this;
274       m2->to = vTimerList;
275       m2->message = Message::DELETE_SELECTED_TIMER;
276       MessageQueue::getInstance()->postMessageNoLock(m2);
277     }
278   }
279 }
280