2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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/>.
30 #include "messagequeue.h"
35 #include "vepgsettimer.h"
37 static const char* TAG = "VEPGST";
39 VEpgSetTimer::VEpgSetTimer(Event* tevent, Channel* tchannel)
41 boxstack = BoxStack::getInstance();
42 vdr = VDR::getInstance();
43 logger = LogNT::getInstance();
50 if (Video::getInstance()->getFormat() == Video::PAL)
52 setPosition(150, 170);
56 setPosition(140, 140);
60 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
62 setTitleText(tr("Set Timer"));
67 buttonYes.setPosition(80, 40 + (7 * getFontHeight()));
68 buttonNo.setPosition(220, 40 + (7 * getFontHeight()));
70 buttonYes.setText(tr("Yes"));
71 buttonNo.setText(tr("No"));
72 buttonYes.setActive(1);
75 logger->debug(TAG, "Title: {}", event->title);
76 logger->debug(TAG, "Time: {}", event->time);
77 logger->debug(TAG, "Duration: {}", event->duration);
78 logger->debug(TAG, "Channel: {}", channel->number);
80 MessageQueue::getInstance()->addReceiver(this);
83 VEpgSetTimer::~VEpgSetTimer()
85 MessageQueue::getInstance()->removeReceiver(this);
88 char* VEpgSetTimer::genTimerString()
91 char* timerString = new char[1024];
107 flags = 1; // hard coded active timer flag
109 char* startMarginConfig = vdr->configLoad("Timers", "Start margin"); // NCONFIG
110 if (startMarginConfig)
112 strncpy(startMargin, startMarginConfig, 9);
113 delete[] startMarginConfig;
115 else strcpy(startMargin, "5");
117 startTime = event->time - (atoi(startMargin) * 60);
118 LOCALTIME_R(&startTime, &btime);
119 strftime(dateString, 19, "%Y-%m-%d", &btime);
120 strftime(startString, 9, "%H%M", &btime);
122 char* endMarginConfig = vdr->configLoad("Timers", "End margin");
125 strncpy(endMargin, endMarginConfig, 9);
126 delete[] endMarginConfig;
128 else strcpy(endMargin, "5");
130 endTime = event->time + event->duration + (atoi(endMargin) * 60);
131 LOCALTIME_R(&endTime, &btime);
132 strftime(endString, 9, "%H%M", &btime);
134 char* priorityConfig = vdr->configLoad("Timers", "Priority");
137 strncpy(priority, priorityConfig, 9);
138 delete[] priorityConfig;
140 else strcpy(priority, "99");
142 char* lifetimeConfig = vdr->configLoad("Timers", "Lifetime");
145 strncpy(lifetime, lifetimeConfig, 9);
146 delete[] lifetimeConfig;
148 else strcpy(lifetime, "99");
150 eventTitle = new char[strlen(event->title.c_str()) + 1];
151 strcpy(eventTitle, event->title.c_str());
152 for(UINT i=0; i < strlen(eventTitle); i++) if (eventTitle[i] == ':') eventTitle[i] = '|';
154 SNPRINTF(timerString, 1023, "%i:%lu:%s:%s:%s:%s:%s:%s:",
155 flags, channel->number, dateString,
156 startString, endString,
157 priority, lifetime, eventTitle);
164 void VEpgSetTimer::swap()
166 if (selectedOption == NO)
168 selectedOption = YES;
169 buttonYes.setActive(1);
170 buttonNo.setActive(0);
172 else if (selectedOption == YES)
175 buttonYes.setActive(0);
176 buttonNo.setActive(1);
180 void VEpgSetTimer::draw()
183 drawPara(event->title.c_str(), 10, 40, DrawStyle::LIGHTTEXT);
184 drawText(channel->name, 10, 40 + (2 * getFontHeight()), DrawStyle::LIGHTTEXT);
190 time_t eventtime = event->time;
191 LOCALTIME_R(&eventtime, &btime);
193 strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm -
195 strftime(timeString, 9, "%H:%M - ", &btime); // and format it as hh:mm -
197 strcpy(fullString, timeString); // put it in our buffer
198 t = event->time + event->duration; //get programme end time
199 LOCALTIME_R(&t, &btime);
201 strftime(timeString, 9, "%0H:%0M", &btime); // and format it as hh:mm -
203 strftime(timeString, 9, "%H:%M", &btime); // and format it as hh:mm -
206 strcat(fullString, timeString); // put it in our buffer
208 drawText(fullString, 10, 40 + (3 * getFontHeight()), DrawStyle::LIGHTTEXT);
209 drawText(tr("Create this timer?"), 10, 40 + (5 * getFontHeight()), DrawStyle::LIGHTTEXT);
215 int VEpgSetTimer::handleCommand(int command)
223 boxstack->update(this);
224 return BoxStack::COMMAND_HANDLED;
230 boxstack->update(this);
231 return BoxStack::COMMAND_HANDLED;
235 return BoxStack::DELETE_ME;
239 if (selectedOption != YES) return 4;
241 return BoxStack::DELETE_ME;
245 return BoxStack::ABANDON_COMMAND;
249 void VEpgSetTimer::doit()
251 char* timerString = genTimerString();
252 logger->debug(TAG, "{}", timerString);
254 ULONG ret = vdr->setEventTimer(timerString);
255 delete[] timerString;
257 if (!vdr->isConnected())
259 Control::getInstance()->connectionLost();
262 if (ret == 0) logger->debug(TAG, "Success");
263 else if (ret == 1) logger->debug(TAG, "Fail: Timer already set for this event");
264 else if (ret == 2) logger->debug(TAG, "Fail: General failure setting timer");
266 VInfo* vi = new VInfo();
267 vi->setSize(400, 150);
271 vi->setTitleBarOn(0);
273 if (Video::getInstance()->getFormat() == Video::PAL)
274 vi->setPosition(170, 200);
276 vi->setPosition(160, 150);
278 if (ret == 0) vi->setOneLiner(tr("Timer set successfully"));
279 else if (ret == 1) vi->setOneLiner(tr("There is already a timer for this event"));
280 else if (ret == 2) vi->setOneLiner(tr("Failure setting timer"));
283 Message* m = new Message();
284 m->message = Message::ADD_VIEW;
285 m->p_to = Message::BOXSTACK;
286 m->data = reinterpret_cast<void*>(vi);
287 MessageQueue::getInstance()->postMessage(m);
290 void VEpgSetTimer::processMessage(Message* m)
292 if (m->message == Message::MOUSE_MOVE)
294 if (buttonYes.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
296 buttonNo.setActive(0);
297 selectedOption = YES;
299 boxstack->update(this);
301 else if (buttonNo.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
303 buttonYes.setActive(0);
306 boxstack->update(this);
309 else if (m->message == Message::MOUSE_LBDOWN)
311 if (buttonYes.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
313 Input::sendInputKey(Input::OK);
315 else if (buttonNo.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
317 Input::sendInputKey(Input::OK);
319 else if (coordsOutsideBox(m))
321 Input::sendInputKey(Input::BACK);