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);
81 VEpgSetTimer::~VEpgSetTimer()
85 char* VEpgSetTimer::genTimerString()
88 char* timerString = new char[1024];
104 flags = 1; // hard coded active timer flag
106 char* startMarginConfig = vdr->configLoad("Timers", "Start margin"); // NCONFIG
107 if (startMarginConfig)
109 strncpy(startMargin, startMarginConfig, 9);
110 delete[] startMarginConfig;
112 else strcpy(startMargin, "5");
114 startTime = event->time - (atoi(startMargin) * 60);
115 LOCALTIME_R(&startTime, &btime);
116 strftime(dateString, 19, "%Y-%m-%d", &btime);
117 strftime(startString, 9, "%H%M", &btime);
119 char* endMarginConfig = vdr->configLoad("Timers", "End margin");
122 strncpy(endMargin, endMarginConfig, 9);
123 delete[] endMarginConfig;
125 else strcpy(endMargin, "5");
127 endTime = event->time + event->duration + (atoi(endMargin) * 60);
128 LOCALTIME_R(&endTime, &btime);
129 strftime(endString, 9, "%H%M", &btime);
131 char* priorityConfig = vdr->configLoad("Timers", "Priority");
134 strncpy(priority, priorityConfig, 9);
135 delete[] priorityConfig;
137 else strcpy(priority, "99");
139 char* lifetimeConfig = vdr->configLoad("Timers", "Lifetime");
142 strncpy(lifetime, lifetimeConfig, 9);
143 delete[] lifetimeConfig;
145 else strcpy(lifetime, "99");
147 eventTitle = new char[strlen(event->title.c_str()) + 1];
148 strcpy(eventTitle, event->title.c_str());
149 for(UINT i=0; i < strlen(eventTitle); i++) if (eventTitle[i] == ':') eventTitle[i] = '|';
151 SNPRINTF(timerString, 1023, "%i:%lu:%s:%s:%s:%s:%s:%s:",
152 flags, channel->number, dateString,
153 startString, endString,
154 priority, lifetime, eventTitle);
161 void VEpgSetTimer::swap()
163 if (selectedOption == NO)
165 selectedOption = YES;
166 buttonYes.setActive(1);
167 buttonNo.setActive(0);
169 else if (selectedOption == YES)
172 buttonYes.setActive(0);
173 buttonNo.setActive(1);
177 void VEpgSetTimer::draw()
180 drawPara(event->title.c_str(), 10, 40, DrawStyle::LIGHTTEXT);
181 drawText(channel->name, 10, 40 + (2 * getFontHeight()), DrawStyle::LIGHTTEXT);
187 time_t eventtime = event->time;
188 LOCALTIME_R(&eventtime, &btime);
190 strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm -
192 strftime(timeString, 9, "%H:%M - ", &btime); // and format it as hh:mm -
194 strcpy(fullString, timeString); // put it in our buffer
195 t = event->time + event->duration; //get programme end time
196 LOCALTIME_R(&t, &btime);
198 strftime(timeString, 9, "%0H:%0M", &btime); // and format it as hh:mm -
200 strftime(timeString, 9, "%H:%M", &btime); // and format it as hh:mm -
203 strcat(fullString, timeString); // put it in our buffer
205 drawText(fullString, 10, 40 + (3 * getFontHeight()), DrawStyle::LIGHTTEXT);
206 drawText(tr("Create this timer?"), 10, 40 + (5 * getFontHeight()), DrawStyle::LIGHTTEXT);
212 int VEpgSetTimer::handleCommand(int command)
220 boxstack->update(this);
227 boxstack->update(this);
236 if (selectedOption != YES) return 4;
246 void VEpgSetTimer::doit()
248 char* timerString = genTimerString();
249 logger->debug(TAG, "{}", timerString);
251 ULONG ret = vdr->setEventTimer(timerString);
252 delete[] timerString;
254 if (!vdr->isConnected())
256 Control::getInstance()->connectionLost();
259 if (ret == 0) logger->debug(TAG, "Success");
260 else if (ret == 1) logger->debug(TAG, "Fail: Timer already set for this event");
261 else if (ret == 2) logger->debug(TAG, "Fail: General failure setting timer");
263 VInfo* vi = new VInfo();
264 vi->setSize(400, 150);
268 vi->setTitleBarOn(0);
270 if (Video::getInstance()->getFormat() == Video::PAL)
271 vi->setPosition(170, 200);
273 vi->setPosition(160, 150);
275 if (ret == 0) vi->setOneLiner(tr("Timer set successfully"));
276 else if (ret == 1) vi->setOneLiner(tr("There is already a timer for this event"));
277 else if (ret == 2) vi->setOneLiner(tr("Failure setting timer"));
280 Message* m = new Message();
281 m->message = Message::ADD_VIEW;
282 m->p_to = Message::BOXSTACK;
283 m->data = reinterpret_cast<void*>(vi);
284 MessageQueue::getInstance()->postMessage(m);
287 void VEpgSetTimer::processMessage(Message* m)
289 if (m->message == Message::MOUSE_MOVE)
291 if (buttonYes.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
293 buttonNo.setActive(0);
294 selectedOption = YES;
296 boxstack->update(this);
298 else if (buttonNo.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
300 buttonYes.setActive(0);
303 boxstack->update(this);
306 else if (m->message == Message::MOUSE_LBDOWN)
308 if (buttonYes.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
310 boxstack->handleCommand(Input::OK); //simulate OK press
312 else if (buttonNo.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
314 boxstack->handleCommand(Input::OK); //simulate OK press
316 else if (coordsOutsideBox(m))
318 boxstack->handleCommand(Input::BACK); //simulate cancel press