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