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 btime = localtime((time_t*)&event->time);
103 strftime(dateString, 19, "%Y-%m-%d", btime);
105 char* startMarginConfig = vdr->configLoad("Timers", "Start margin");
106 if (startMarginConfig)
108 strncpy(startMargin, startMarginConfig, 9);
109 delete[] startMarginConfig;
111 else strcpy(startMargin, "5");
113 startTime = event->time - (atoi(startMargin) * 60);
114 btime = localtime(&startTime);
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 btime = localtime(&endTime);
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) + 1];
146 strcpy(eventTitle, event->title);
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, 10, 40, Colour::LIGHTTEXT);
179 drawText(channel->name, 10, 40 + (2 * surface->getFontHeight()), Colour::LIGHTTEXT);
185 btime = localtime((time_t*)&event->time);
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 btime = localtime(&t);
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 * surface->getFontHeight()), Colour::LIGHTTEXT);
203 drawText(tr("Create this timer?"), 10, 40 + (5 * surface->getFontHeight()), Colour::LIGHTTEXT);
209 int VEpgSetTimer::handleCommand(int command)
213 case Remote::DF_LEFT:
218 boxstack->update(this);
221 case Remote::DF_RIGHT:
226 boxstack->update(this);
235 if (selectedOption != YES) return 4;
245 void VEpgSetTimer::doit()
247 char* timerString = genTimerString();
248 logger->log("VEPGST", Log::DEBUG, "%s", timerString);
250 ULONG ret = vdr->setEventTimer(timerString);
251 delete[] timerString;
253 if (!vdr->isConnected())
255 Command::getInstance()->connectionLost();
258 if (ret == 0) logger->log("VEPGST", Log::DEBUG, "Success");
259 else if (ret == 1) logger->log("VEPGST", Log::DEBUG, "Fail: Timer already set for this event");
260 else if (ret == 2) logger->log("VEPGST", Log::DEBUG, "Fail: General failure setting timer");
262 VInfo* vi = new VInfo();
263 vi->setSize(400, 150);
267 vi->setTitleBarOn(0);
269 if (Video::getInstance()->getFormat() == Video::PAL)
270 vi->setPosition(170, 200);
272 vi->setPosition(160, 150);
274 if (ret == 0) vi->setOneLiner(tr("Timer set successfully"));
275 else if (ret == 1) vi->setOneLiner(tr("There is already a timer for this event"));
276 else if (ret == 2) vi->setOneLiner(tr("Failure setting timer"));
279 Message* m = new Message();
280 m->message = Message::ADD_VIEW;
282 m->parameter = (ULONG)vi;
283 Command::getInstance()->postMessageNoLock(m);
286 void VEpgSetTimer::processMessage(Message* m)
288 if (m->message == Message::MOUSE_MOVE)
290 if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
292 buttonNo.setActive(0);
293 selectedOption = YES;
295 boxstack->update(this);
297 else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
299 buttonYes.setActive(0);
302 boxstack->update(this);
305 else if (m->message == Message::MOUSE_LBDOWN)
307 if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
309 boxstack->handleCommand(Remote::OK); //simulate OK press
311 else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
313 boxstack->handleCommand(Remote::OK); //simulate OK press
317 //check if press is outside this view! then simulate cancel
318 int x=(m->parameter>>16)-getScreenX();
319 int y=(m->parameter&0xFFFF)-getScreenY();
320 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
322 boxstack->handleCommand(Remote::BACK); //simulate cancel press