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"
23 VEpgSetTimer::VEpgSetTimer(Event* tevent, Channel* tchannel)
25 viewman = ViewMan::getInstance();
26 vdr = VDR::getInstance();
27 logger = Log::getInstance();
33 if (Video::getInstance()->getFormat() == Video::PAL)
35 setScreenPos(150, 170);
39 setScreenPos(140, 140);
42 setBackgroundColour(Colour::VIEWBACKGROUND);
44 setTitleBarColour(Colour::TITLEBARBACKGROUND);
46 setTitleText(tr("Set Timer"));
48 buttonYes.setSurface(surface);
49 buttonNo.setSurface(surface);
50 buttonYes.setSurfaceOffset(80, 40 + (7 * surface->getFontHeight()));
51 buttonNo.setSurfaceOffset(220, 40 + (7 * surface->getFontHeight()));
53 buttonYes.setText(tr("Yes"));
54 buttonNo.setText(tr("No"));
55 buttonYes.setActive(1);
58 logger->log("VEPGST", Log::DEBUG, "Title: %s", event->title);
59 logger->log("VEPGST", Log::DEBUG, "Time: %lu", event->time);
60 logger->log("VEPGST", Log::DEBUG, "Duration: %lu", event->duration);
61 logger->log("VEPGST", Log::DEBUG, "Channel: %i", channel->number);
64 VEpgSetTimer::~VEpgSetTimer()
68 char* VEpgSetTimer::genTimerString()
71 char* timerString = new char[1024];
87 flags = 1; // hard coded active timer flag
89 btime = localtime((time_t*)&event->time);
90 strftime(dateString, 19, "%Y-%m-%d", btime);
92 char* startMarginConfig = vdr->configLoad("Timers", "Start margin");
93 if (startMarginConfig)
95 strncpy(startMargin, startMarginConfig, 9);
96 delete[] startMarginConfig;
98 else strcpy(startMargin, "5");
100 startTime = event->time - (atoi(startMargin) * 60);
101 btime = localtime(&startTime);
102 strftime(startString, 9, "%H%M", btime);
104 char* endMarginConfig = vdr->configLoad("Timers", "End margin");
107 strncpy(endMargin, endMarginConfig, 9);
108 delete[] endMarginConfig;
110 else strcpy(endMargin, "5");
112 endTime = event->time + event->duration + (atoi(endMargin) * 60);
113 btime = localtime(&endTime);
114 strftime(endString, 9, "%H%M", btime);
116 char* priorityConfig = vdr->configLoad("Timers", "Priority");
119 strncpy(priority, priorityConfig, 9);
120 delete[] priorityConfig;
122 else strcpy(priority, "99");
124 char* lifetimeConfig = vdr->configLoad("Timers", "Lifetime");
127 strncpy(lifetime, lifetimeConfig, 9);
128 delete[] lifetimeConfig;
130 else strcpy(lifetime, "99");
132 eventTitle = new char[strlen(event->title) + 1];
133 strcpy(eventTitle, event->title);
134 for(UINT i=0; i < strlen(eventTitle); i++) if (eventTitle[i] == ':') eventTitle[i] = '|';
136 SNPRINTF(timerString, 1023, "%i:%lu:%s:%s:%s:%s:%s:%s:",
137 flags, channel->number, dateString,
138 startString, endString,
139 priority, lifetime, eventTitle);
146 void VEpgSetTimer::swap()
148 if (selectedOption == NO)
150 selectedOption = YES;
151 buttonYes.setActive(1);
152 buttonNo.setActive(0);
154 else if (selectedOption == YES)
157 buttonYes.setActive(0);
158 buttonNo.setActive(1);
162 void VEpgSetTimer::draw()
165 drawPara(event->title, 10, 40, Colour::LIGHTTEXT);
166 drawText(channel->name, 10, 40 + (2 * surface->getFontHeight()), Colour::LIGHTTEXT);
172 btime = localtime((time_t*)&event->time);
174 strftime(timeString, 9, "%0H:%0M - ", btime); // and format it as hh:mm -
176 strftime(timeString, 9, "%H:%M - ", btime); // and format it as hh:mm -
178 strcpy(fullString, timeString); // put it in our buffer
179 t = event->time + event->duration; //get programme end time
180 btime = localtime(&t);
182 strftime(timeString, 9, "%0H:%0M", btime); // and format it as hh:mm -
184 strftime(timeString, 9, "%H:%M", btime); // and format it as hh:mm -
187 strcat(fullString, timeString); // put it in our buffer
189 drawText(fullString, 10, 40 + (3 * surface->getFontHeight()), Colour::LIGHTTEXT);
190 drawText(tr("Create this timer?"), 10, 40 + (5 * surface->getFontHeight()), Colour::LIGHTTEXT);
196 int VEpgSetTimer::handleCommand(int command)
200 case Remote::DF_LEFT:
205 ViewMan::getInstance()->updateView(this);
208 case Remote::DF_RIGHT:
213 ViewMan::getInstance()->updateView(this);
222 if (selectedOption != YES) return 4;
232 void VEpgSetTimer::doit()
234 char* timerString = genTimerString();
235 logger->log("VEPGST", Log::DEBUG, "%s", timerString);
237 ULONG ret = vdr->setEventTimer(timerString);
238 delete[] timerString;
240 if (!vdr->isConnected())
242 Command::getInstance()->connectionLost();
245 if (ret == 0) logger->log("VEPGST", Log::DEBUG, "Success");
246 else if (ret == 1) logger->log("VEPGST", Log::DEBUG, "Fail: Timer already set for this event");
247 else if (ret == 2) logger->log("VEPGST", Log::DEBUG, "Fail: General failure setting timer");
249 VInfo* vi = new VInfo();
250 vi->create(400, 150);
253 vi->setTitleBarOn(0);
255 if (Video::getInstance()->getFormat() == Video::PAL)
256 vi->setScreenPos(170, 200);
258 vi->setScreenPos(160, 150);
260 if (ret == 0) vi->setOneLiner(tr("Timer set successfully"));
261 else if (ret == 1) vi->setOneLiner(tr("There is already a timer for this event"));
262 else if (ret == 2) vi->setOneLiner(tr("Failure setting timer"));
265 Message* m = new Message();
266 m->message = Message::ADD_VIEW;
268 m->parameter = (ULONG)vi;
270 viewman->postMessage(m);