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 VEpgSetTimer::VEpgSetTimer(Event* tevent, Channel* tchannel)
39 boxstack = BoxStack::getInstance();
40 vdr = VDR::getInstance();
41 logger = Log::getInstance();
48 if (Video::getInstance()->getFormat() == Video::PAL)
50 setPosition(150, 170);
54 setPosition(140, 140);
58 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
60 setTitleText(tr("Set Timer"));
65 buttonYes.setPosition(80, 40 + (7 * getFontHeight()));
66 buttonNo.setPosition(220, 40 + (7 * getFontHeight()));
68 buttonYes.setText(tr("Yes"));
69 buttonNo.setText(tr("No"));
70 buttonYes.setActive(1);
73 logger->log("VEPGST", Log::DEBUG, "Title: %s", event->title);
74 logger->log("VEPGST", Log::DEBUG, "Time: %lu", event->time);
75 logger->log("VEPGST", Log::DEBUG, "Duration: %lu", event->duration);
76 logger->log("VEPGST", Log::DEBUG, "Channel: %i", channel->number);
79 VEpgSetTimer::~VEpgSetTimer()
83 char* VEpgSetTimer::genTimerString()
86 char* timerString = new char[1024];
102 flags = 1; // hard coded active timer flag
104 char* startMarginConfig = vdr->configLoad("Timers", "Start margin");
105 if (startMarginConfig)
107 strncpy(startMargin, startMarginConfig, 9);
108 delete[] startMarginConfig;
110 else strcpy(startMargin, "5");
112 startTime = event->time - (atoi(startMargin) * 60);
113 LOCALTIME_R(&startTime, &btime);
114 strftime(dateString, 19, "%Y-%m-%d", &btime);
115 strftime(startString, 9, "%H%M", &btime);
117 char* endMarginConfig = vdr->configLoad("Timers", "End margin");
120 strncpy(endMargin, endMarginConfig, 9);
121 delete[] endMarginConfig;
123 else strcpy(endMargin, "5");
125 endTime = event->time + event->duration + (atoi(endMargin) * 60);
126 LOCALTIME_R(&endTime, &btime);
127 strftime(endString, 9, "%H%M", &btime);
129 char* priorityConfig = vdr->configLoad("Timers", "Priority");
132 strncpy(priority, priorityConfig, 9);
133 delete[] priorityConfig;
135 else strcpy(priority, "99");
137 char* lifetimeConfig = vdr->configLoad("Timers", "Lifetime");
140 strncpy(lifetime, lifetimeConfig, 9);
141 delete[] lifetimeConfig;
143 else strcpy(lifetime, "99");
145 eventTitle = new char[strlen(event->title.c_str()) + 1];
146 strcpy(eventTitle, event->title.c_str());
147 for(UINT i=0; i < strlen(eventTitle); i++) if (eventTitle[i] == ':') eventTitle[i] = '|';
149 SNPRINTF(timerString, 1023, "%i:%lu:%s:%s:%s:%s:%s:%s:",
150 flags, channel->number, dateString,
151 startString, endString,
152 priority, lifetime, eventTitle);
159 void VEpgSetTimer::swap()
161 if (selectedOption == NO)
163 selectedOption = YES;
164 buttonYes.setActive(1);
165 buttonNo.setActive(0);
167 else if (selectedOption == YES)
170 buttonYes.setActive(0);
171 buttonNo.setActive(1);
175 void VEpgSetTimer::draw()
178 drawPara(event->title.c_str(), 10, 40, DrawStyle::LIGHTTEXT);
179 drawText(channel->name, 10, 40 + (2 * getFontHeight()), DrawStyle::LIGHTTEXT);
185 time_t eventtime = event->time;
186 LOCALTIME_R(&eventtime, &btime);
188 strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm -
190 strftime(timeString, 9, "%H:%M - ", &btime); // and format it as hh:mm -
192 strcpy(fullString, timeString); // put it in our buffer
193 t = event->time + event->duration; //get programme end time
194 LOCALTIME_R(&t, &btime);
196 strftime(timeString, 9, "%0H:%0M", &btime); // and format it as hh:mm -
198 strftime(timeString, 9, "%H:%M", &btime); // and format it as hh:mm -
201 strcat(fullString, timeString); // put it in our buffer
203 drawText(fullString, 10, 40 + (3 * getFontHeight()), DrawStyle::LIGHTTEXT);
204 drawText(tr("Create this timer?"), 10, 40 + (5 * getFontHeight()), DrawStyle::LIGHTTEXT);
210 int VEpgSetTimer::handleCommand(int command)
218 boxstack->update(this);
225 boxstack->update(this);
234 if (selectedOption != YES) return 4;
244 void VEpgSetTimer::doit()
246 char* timerString = genTimerString();
247 logger->log("VEPGST", Log::DEBUG, "%s", timerString);
249 ULONG ret = vdr->setEventTimer(timerString);
250 delete[] timerString;
252 if (!vdr->isConnected())
254 Control::getInstance()->connectionLost();
257 if (ret == 0) logger->log("VEPGST", Log::DEBUG, "Success");
258 else if (ret == 1) logger->log("VEPGST", Log::DEBUG, "Fail: Timer already set for this event");
259 else if (ret == 2) logger->log("VEPGST", Log::DEBUG, "Fail: General failure setting timer");
261 VInfo* vi = new VInfo();
262 vi->setSize(400, 150);
266 vi->setTitleBarOn(0);
268 if (Video::getInstance()->getFormat() == Video::PAL)
269 vi->setPosition(170, 200);
271 vi->setPosition(160, 150);
273 if (ret == 0) vi->setOneLiner(tr("Timer set successfully"));
274 else if (ret == 1) vi->setOneLiner(tr("There is already a timer for this event"));
275 else if (ret == 2) vi->setOneLiner(tr("Failure setting timer"));
278 Message* m = new Message();
279 m->message = Message::ADD_VIEW;
280 m->p_to = Message::BOXSTACK;
281 m->data = reinterpret_cast<void*>(vi);
282 MessageQueue::getInstance()->postMessage(m);
285 void VEpgSetTimer::processMessage(Message* m)
287 if (m->message == Message::MOUSE_MOVE)
289 if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
291 buttonNo.setActive(0);
292 selectedOption = YES;
294 boxstack->update(this);
296 else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
298 buttonYes.setActive(0);
301 boxstack->update(this);
304 else if (m->message == Message::MOUSE_LBDOWN)
306 if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
308 boxstack->handleCommand(Input::OK); //simulate OK press
310 else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
312 boxstack->handleCommand(Input::OK); //simulate OK press
314 else if (coordsOutsideBox(m))
316 boxstack->handleCommand(Input::BACK); //simulate cancel press