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, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vepgsettimer.h"
31 #include "messagequeue.h"
36 VEpgSetTimer::VEpgSetTimer(Event* tevent, Channel* tchannel)
38 boxstack = BoxStack::getInstance();
39 vdr = VDR::getInstance();
40 logger = Log::getInstance();
47 if (Video::getInstance()->getFormat() == Video::PAL)
49 setPosition(150, 170);
53 setPosition(140, 140);
57 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
59 setTitleText(tr("Set Timer"));
64 buttonYes.setPosition(80, 40 + (7 * getFontHeight()));
65 buttonNo.setPosition(220, 40 + (7 * getFontHeight()));
67 buttonYes.setText(tr("Yes"));
68 buttonNo.setText(tr("No"));
69 buttonYes.setActive(1);
72 logger->log("VEPGST", Log::DEBUG, "Title: %s", event->title);
73 logger->log("VEPGST", Log::DEBUG, "Time: %lu", event->time);
74 logger->log("VEPGST", Log::DEBUG, "Duration: %lu", event->duration);
75 logger->log("VEPGST", Log::DEBUG, "Channel: %i", channel->number);
78 VEpgSetTimer::~VEpgSetTimer()
82 char* VEpgSetTimer::genTimerString()
85 char* timerString = new char[1024];
101 flags = 1; // hard coded active timer flag
103 char* startMarginConfig = vdr->configLoad("Timers", "Start margin");
104 if (startMarginConfig)
106 strncpy(startMargin, startMarginConfig, 9);
107 delete[] startMarginConfig;
109 else strcpy(startMargin, "5");
111 startTime = event->time - (atoi(startMargin) * 60);
112 LOCALTIME_R(&startTime, &btime);
113 strftime(dateString, 19, "%Y-%m-%d", &btime);
114 strftime(startString, 9, "%H%M", &btime);
116 char* endMarginConfig = vdr->configLoad("Timers", "End margin");
119 strncpy(endMargin, endMarginConfig, 9);
120 delete[] endMarginConfig;
122 else strcpy(endMargin, "5");
124 endTime = event->time + event->duration + (atoi(endMargin) * 60);
125 LOCALTIME_R(&endTime, &btime);
126 strftime(endString, 9, "%H%M", &btime);
128 char* priorityConfig = vdr->configLoad("Timers", "Priority");
131 strncpy(priority, priorityConfig, 9);
132 delete[] priorityConfig;
134 else strcpy(priority, "99");
136 char* lifetimeConfig = vdr->configLoad("Timers", "Lifetime");
139 strncpy(lifetime, lifetimeConfig, 9);
140 delete[] lifetimeConfig;
142 else strcpy(lifetime, "99");
144 eventTitle = new char[strlen(event->title) + 1];
145 strcpy(eventTitle, event->title);
146 for(UINT i=0; i < strlen(eventTitle); i++) if (eventTitle[i] == ':') eventTitle[i] = '|';
148 SNPRINTF(timerString, 1023, "%i:%lu:%s:%s:%s:%s:%s:%s:",
149 flags, channel->number, dateString,
150 startString, endString,
151 priority, lifetime, eventTitle);
158 void VEpgSetTimer::swap()
160 if (selectedOption == NO)
162 selectedOption = YES;
163 buttonYes.setActive(1);
164 buttonNo.setActive(0);
166 else if (selectedOption == YES)
169 buttonYes.setActive(0);
170 buttonNo.setActive(1);
174 void VEpgSetTimer::draw()
177 drawPara(event->title, 10, 40, DrawStyle::LIGHTTEXT);
178 drawText(channel->name, 10, 40 + (2 * getFontHeight()), DrawStyle::LIGHTTEXT);
184 time_t eventtime = event->time;
185 LOCALTIME_R(&eventtime, &btime);
187 strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm -
189 strftime(timeString, 9, "%H:%M - ", &btime); // and format it as hh:mm -
191 strcpy(fullString, timeString); // put it in our buffer
192 t = event->time + event->duration; //get programme end time
193 LOCALTIME_R(&t, &btime);
195 strftime(timeString, 9, "%0H:%0M", &btime); // and format it as hh:mm -
197 strftime(timeString, 9, "%H:%M", &btime); // and format it as hh:mm -
200 strcat(fullString, timeString); // put it in our buffer
202 drawText(fullString, 10, 40 + (3 * getFontHeight()), DrawStyle::LIGHTTEXT);
203 drawText(tr("Create this timer?"), 10, 40 + (5 * getFontHeight()), DrawStyle::LIGHTTEXT);
209 int VEpgSetTimer::handleCommand(int command)
217 boxstack->update(this);
224 boxstack->update(this);
233 if (selectedOption != YES) return 4;
243 void VEpgSetTimer::doit()
245 char* timerString = genTimerString();
246 logger->log("VEPGST", Log::DEBUG, "%s", timerString);
248 ULONG ret = vdr->setEventTimer(timerString);
249 delete[] timerString;
251 if (!vdr->isConnected())
253 Command::getInstance()->connectionLost();
256 if (ret == 0) logger->log("VEPGST", Log::DEBUG, "Success");
257 else if (ret == 1) logger->log("VEPGST", Log::DEBUG, "Fail: Timer already set for this event");
258 else if (ret == 2) logger->log("VEPGST", Log::DEBUG, "Fail: General failure setting timer");
260 VInfo* vi = new VInfo();
261 vi->setSize(400, 150);
265 vi->setTitleBarOn(0);
267 if (Video::getInstance()->getFormat() == Video::PAL)
268 vi->setPosition(170, 200);
270 vi->setPosition(160, 150);
272 if (ret == 0) vi->setOneLiner(tr("Timer set successfully"));
273 else if (ret == 1) vi->setOneLiner(tr("There is already a timer for this event"));
274 else if (ret == 2) vi->setOneLiner(tr("Failure setting timer"));
277 Message* m = new Message();
278 m->message = Message::ADD_VIEW;
280 m->data = reinterpret_cast<void*>(vi);
281 MessageQueue::getInstance()->postMessage(m);
284 void VEpgSetTimer::processMessage(Message* m)
286 if (m->message == Message::MOUSE_MOVE)
288 if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
290 buttonNo.setActive(0);
291 selectedOption = YES;
293 boxstack->update(this);
295 else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
297 buttonYes.setActive(0);
300 boxstack->update(this);
303 else if (m->message == Message::MOUSE_LBDOWN)
305 if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
307 boxstack->handleCommand(Input::OK); //simulate OK press
309 else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
311 boxstack->handleCommand(Input::OK); //simulate OK press
313 else if (coordsOutsideBox(m))
315 boxstack->handleCommand(Input::BACK); //simulate cancel press