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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "vepgsettimer.h"
35 VEpgSetTimer::VEpgSetTimer(Event* tevent, Channel* tchannel)
37 boxstack = BoxStack::getInstance();
38 vdr = VDR::getInstance();
39 logger = Log::getInstance();
46 if (Video::getInstance()->getFormat() == Video::PAL)
48 setPosition(150, 170);
52 setPosition(140, 140);
56 setTitleBarColour(Colour::TITLEBARBACKGROUND);
58 setTitleText(tr("Set Timer"));
63 buttonYes.setPosition(80, 40 + (7 * surface->getFontHeight()));
64 buttonNo.setPosition(220, 40 + (7 * surface->getFontHeight()));
66 buttonYes.setText(tr("Yes"));
67 buttonNo.setText(tr("No"));
68 buttonYes.setActive(1);
71 logger->log("VEPGST", Log::DEBUG, "Title: %s", event->title);
72 logger->log("VEPGST", Log::DEBUG, "Time: %lu", event->time);
73 logger->log("VEPGST", Log::DEBUG, "Duration: %lu", event->duration);
74 logger->log("VEPGST", Log::DEBUG, "Channel: %i", channel->number);
77 VEpgSetTimer::~VEpgSetTimer()
81 char* VEpgSetTimer::genTimerString()
84 char* timerString = new char[1024];
100 flags = 1; // hard coded active timer flag
102 char* startMarginConfig = vdr->configLoad("Timers", "Start margin");
103 if (startMarginConfig)
105 strncpy(startMargin, startMarginConfig, 9);
106 delete[] startMarginConfig;
108 else strcpy(startMargin, "5");
110 startTime = event->time - (atoi(startMargin) * 60);
111 btime = localtime(&startTime);
112 strftime(dateString, 19, "%Y-%m-%d", btime);
113 strftime(startString, 9, "%H%M", btime);
115 char* endMarginConfig = vdr->configLoad("Timers", "End margin");
118 strncpy(endMargin, endMarginConfig, 9);
119 delete[] endMarginConfig;
121 else strcpy(endMargin, "5");
123 endTime = event->time + event->duration + (atoi(endMargin) * 60);
124 btime = localtime(&endTime);
125 strftime(endString, 9, "%H%M", btime);
127 char* priorityConfig = vdr->configLoad("Timers", "Priority");
130 strncpy(priority, priorityConfig, 9);
131 delete[] priorityConfig;
133 else strcpy(priority, "99");
135 char* lifetimeConfig = vdr->configLoad("Timers", "Lifetime");
138 strncpy(lifetime, lifetimeConfig, 9);
139 delete[] lifetimeConfig;
141 else strcpy(lifetime, "99");
143 eventTitle = new char[strlen(event->title) + 1];
144 strcpy(eventTitle, event->title);
145 for(UINT i=0; i < strlen(eventTitle); i++) if (eventTitle[i] == ':') eventTitle[i] = '|';
147 SNPRINTF(timerString, 1023, "%i:%lu:%s:%s:%s:%s:%s:%s:",
148 flags, channel->number, dateString,
149 startString, endString,
150 priority, lifetime, eventTitle);
157 void VEpgSetTimer::swap()
159 if (selectedOption == NO)
161 selectedOption = YES;
162 buttonYes.setActive(1);
163 buttonNo.setActive(0);
165 else if (selectedOption == YES)
168 buttonYes.setActive(0);
169 buttonNo.setActive(1);
173 void VEpgSetTimer::draw()
176 drawPara(event->title, 10, 40, Colour::LIGHTTEXT);
177 drawText(channel->name, 10, 40 + (2 * surface->getFontHeight()), Colour::LIGHTTEXT);
183 btime = localtime((time_t*)&event->time);
185 strftime(timeString, 9, "%0H:%0M - ", btime); // and format it as hh:mm -
187 strftime(timeString, 9, "%H:%M - ", btime); // and format it as hh:mm -
189 strcpy(fullString, timeString); // put it in our buffer
190 t = event->time + event->duration; //get programme end time
191 btime = localtime(&t);
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 -
198 strcat(fullString, timeString); // put it in our buffer
200 drawText(fullString, 10, 40 + (3 * surface->getFontHeight()), Colour::LIGHTTEXT);
201 drawText(tr("Create this timer?"), 10, 40 + (5 * surface->getFontHeight()), Colour::LIGHTTEXT);
207 int VEpgSetTimer::handleCommand(int command)
211 case Remote::DF_LEFT:
216 boxstack->update(this);
219 case Remote::DF_RIGHT:
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->parameter = (ULONG)vi;
281 Command::getInstance()->postMessageNoLock(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(Remote::OK); //simulate OK press
309 else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
311 boxstack->handleCommand(Remote::OK); //simulate OK press
315 //check if press is outside this view! then simulate cancel
316 int x=(m->parameter>>16)-getScreenX();
317 int y=(m->parameter&0xFFFF)-getScreenY();
318 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
320 boxstack->handleCommand(Remote::BACK); //simulate cancel press