]> git.vomp.tv Git - vompclient-marten.git/blob - vtimeredit.cc
Demuxer changes/fixes/improvements
[vompclient-marten.git] / vtimeredit.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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
19 */
20
21 #include "vtimeredit.h"
22
23 #include "remote.h"
24 #include "wsymbol.h"
25 #include "boxstack.h"
26 #include "vdr.h"
27 #include "colour.h"
28 #include "video.h"
29 #include "i18n.h"
30 #include "timers.h"
31 #include "vquestion.h"
32 #include "command.h"
33
34 VTimerEdit::VTimerEdit(RecTimer* trt)
35 {
36   recTimer = trt;
37
38   setSize(570, 420);
39   createBuffer();
40   if (Video::getInstance()->getFormat() == Video::PAL)
41   {
42     setPosition(80, 70);
43   }
44   else
45   {
46     setPosition(70, 35);
47   }
48   selectedButton = 0;
49   buttonBack.setPosition(30,350);
50   buttonDelete.setPosition(400,350);
51   buttonBack.setText("Back");
52   buttonBack.setActive(1);
53   buttonDelete.setText("Delete");
54   add(&buttonBack);
55   add(&buttonDelete);
56
57   setTitleBarOn(1);
58   setTitleText(tr("Edit Timer"));
59   setTitleBarColour(Colour::TITLEBARBACKGROUND);
60 }
61
62 VTimerEdit::~VTimerEdit()
63 {
64 }
65
66 void VTimerEdit::setParent(VTimerList* tvTimerList)
67 {
68   vTimerList = tvTimerList;
69 }
70
71 void VTimerEdit::draw()
72 {
73   TBBoxx::draw();
74
75   int xpos = 20;
76   int ypos = 50;
77   drawText(tr("Active"), xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
78   drawText(tr("Channel"), xpos, ypos, Colour::LIGHTTEXT);        ypos += surface->getFontHeight();
79   drawText(tr("Name"), xpos, ypos, Colour::LIGHTTEXT);           ypos += surface->getFontHeight();
80   drawText(tr("Directory"), xpos, ypos, Colour::LIGHTTEXT);      ypos += surface->getFontHeight();
81                                                              ypos += surface->getFontHeight();
82   drawText(tr("Start"), xpos, ypos, Colour::LIGHTTEXT);          ypos += surface->getFontHeight();
83   drawText(tr("Stop"), xpos, ypos, Colour::LIGHTTEXT);           ypos += surface->getFontHeight();
84   drawText(tr("Priority"), xpos, ypos, Colour::LIGHTTEXT);       ypos += surface->getFontHeight();
85   drawText(tr("Lifetime"), xpos, ypos, Colour::LIGHTTEXT);       ypos += surface->getFontHeight();
86                                                              ypos += surface->getFontHeight();
87   drawText(tr("Current"), xpos, ypos, Colour::LIGHTTEXT);        ypos += surface->getFontHeight();
88   drawText(tr("Recording"), xpos, ypos, Colour::LIGHTTEXT);      ypos += surface->getFontHeight();
89
90
91   // Temp
92   char buffer[1000];
93   struct tm* tms;
94   xpos = 150;
95   ypos = 50;
96
97   // Active
98   if (recTimer->active) strcpy(buffer, "Yes");
99   else                  strcpy(buffer, "No");
100   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
101
102   // Channel
103   SNPRINTF(buffer, 999, "%lu", recTimer->channelNumber);
104   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
105
106   // Name
107   SNPRINTF(buffer, 999, "%s", recTimer->getName());
108   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
109
110   // Directory
111   if (recTimer->getDirectory()) SNPRINTF(buffer, 999, "%s", recTimer->getDirectory());
112   else strcpy(buffer, "");
113   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
114                                                            ypos += surface->getFontHeight();
115
116   // Start
117   tms = localtime((time_t*)&recTimer->startTime);
118   strftime(buffer, 999, "%d/%m %H:%M", tms);
119   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
120
121   // Stop
122   tms = localtime((time_t*)&recTimer->stopTime);
123   strftime(buffer, 999, "%d/%m %H:%M", tms);
124   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
125
126   // Priority
127   SNPRINTF(buffer, 999, "%lu", recTimer->priority);
128   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
129
130   // Lifetime
131   SNPRINTF(buffer, 999, "%lu", recTimer->lifeTime);
132   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
133                                                            ypos += surface->getFontHeight();
134
135   // Current
136   if (recTimer->pending) strcpy(buffer, "Yes");
137   else                   strcpy(buffer, "No");
138   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
139
140   // Recording now
141   if (recTimer->recording) strcpy(buffer, "Yes");
142   else                     strcpy(buffer, "No");
143   drawText(buffer, xpos, ypos, Colour::LIGHTTEXT);         ypos += surface->getFontHeight();
144 }
145
146 void VTimerEdit::swap()
147 {
148   if (selectedButton == 0)
149   {
150     buttonBack.setActive(0);
151     buttonDelete.setActive(1);
152     selectedButton = 1;
153   }
154   else
155   {
156     buttonDelete.setActive(0);
157     buttonBack.setActive(1);
158     selectedButton = 0;
159   }
160 }
161
162 int VTimerEdit::handleCommand(int command)
163 {
164   switch(command)
165   {
166     /*
167     case Remote::DF_UP:
168     case Remote::UP:
169     {
170
171       ViewMan::getInstance()->updateView(this);
172       return 2;
173     }
174     case Remote::DF_DOWN:
175     case Remote::DOWN:
176     {
177
178       ViewMan::getInstance()->updateView(this);
179       return 2;
180     }
181     */
182     case Remote::LEFT:
183     case Remote::DF_RIGHT:
184     {
185       swap();
186       buttonBack.draw();
187       buttonDelete.draw();
188       BoxStack::getInstance()->update(this);
189       return 2;
190     }
191     case Remote::RIGHT:
192     case Remote::DF_LEFT:
193     {
194       swap();
195       buttonBack.draw();
196       buttonDelete.draw();
197       BoxStack::getInstance()->update(this);
198       return 2;
199     }
200     case Remote::OK:
201     {
202       // Back
203       if (selectedButton == 0) return 4;
204       // Delete
205       VQuestion* v = new VQuestion(this);
206       v->setSize(260, 180);
207       v->createBuffer();
208       v->setTitleBarColour(Colour::DANGER);
209       v->setTitleBarOn(1);
210       v->setBorderOn(1);
211       v->setTitleText("Delete timer");
212       v->setMainText("Are you sure you want to delete this timer?");
213       v->setDefault(VQuestion::NO);
214       if (Video::getInstance()->getFormat() == Video::PAL)
215         v->setPosition(230, 160);
216       else
217         v->setPosition(220, 140);
218       v->draw();
219       BoxStack::getInstance()->add(v);
220       BoxStack::getInstance()->update(v);
221       return 2;
222     }
223     case Remote::BACK:
224     {
225       return 4;
226     }
227   }
228   // stop command getting to any more views
229   return 1;
230 }
231
232 void VTimerEdit::processMessage(Message* m)
233 {
234   if (m->message == Message::MOUSE_MOVE)
235   {
236       int x=(m->parameter>>16)-getScreenX();
237       int y=(m->parameter&0xFFFF)-getScreenY();
238       if (buttonBack.mouseMove(x,y)) {
239           selectedButton=0;
240           buttonDelete.setActive(false);
241           buttonBack.draw();
242           buttonDelete.draw();
243           BoxStack::getInstance()->update(this);
244       } else if  (buttonDelete.mouseMove(x,y)) {
245           selectedButton=1;
246           buttonBack.setActive(false);
247           buttonBack.draw();
248           buttonDelete.draw();
249           BoxStack::getInstance()->update(this);
250       }
251
252   } else if (m->message == Message::MOUSE_LBDOWN)
253   {
254     BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
255   }
256   else if (m->message == Message::QUESTION_YES)
257   {
258   if (selectedButton == 1)
259     {
260       Message* m2 = new Message(); // Delete self
261       m2->from = this;
262       m2->to = BoxStack::getInstance();
263       m2->message = Message::CLOSE_ME;
264       Command::getInstance()->postMessageNoLock(m2);
265
266       m2 = new Message(); // OK. Want this to delete before this message does its job
267       m2->from = this;
268       m2->to = vTimerList;
269       m2->message = Message::DELETE_SELECTED_TIMER;
270       Command::getInstance()->postMessageNoLock(m2);
271     }
272   }
273 }
274