]> git.vomp.tv Git - vompclient.git/blob - vrecordinglist.cc
Clean up of all video init system, NTSC/PAL, screen size functions.
[vompclient.git] / vrecordinglist.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 "vrecordinglist.h"
22
23 VRecordingList::VRecordingList()
24 {
25   if (Video::getInstance()->getFormat() == Video::PAL)
26   {
27     setScreenPos(80, 70);
28   }
29   else
30   {
31     setScreenPos(70, 35);
32   }
33
34   setDimensions(420, 570);
35
36   setBackgroundColour(Colour::VIEWBACKGROUND);
37   setTitleBarOn(1);
38   setTitleBarColour(Colour::TITLEBARBACKGROUND);
39
40   sl.setScreenPos(screenX + 10, screenY + 30 + 5);
41   sl.setDimensions(height - 30 - 15 - 30, width - 20);
42 }
43
44 VRecordingList::~VRecordingList()
45 {
46   // only delete the list if this is not a sub dir window
47   if (recDir->isRoot) delete recDir;
48 }
49
50 void VRecordingList::setDir(Directory* tdir)
51 {
52   recDir = tdir;
53   int first = 1;
54
55   char tempA[300]; // FIXME  this is guesswork!
56   char tempB[300]; // FIXME
57   struct tm* btime;
58
59   char spaces[13];
60   char theNumber[10];
61   int theNumberLength;
62
63   Directory* dir;
64   recDir->dirList->reset();
65   while((dir = (Directory*)recDir->dirList->getCurrent()))
66   {
67     strcpy(spaces, "            ");
68     theNumberLength = snprintf(theNumber, 9, "%lu", dir->getNumRecordings());
69
70     spaces[11 - theNumberLength] = '\0';
71
72     //snprintf(tempA, 299, "<dir>            %s", dir->name);
73     snprintf(tempA, 299, "<dir> %s%s%s", theNumber, spaces, dir->name);
74     //int numSize = snprintf(tempA
75
76     dir->index = sl.addOption(tempA, first);
77     first = 0;
78     recDir->dirList->next();
79   }
80
81   // temp FIXME
82   List* recList = recDir->recList;
83
84   // FIXME convert the whole program to time_t's
85
86
87   Recording* rec;
88   recList->reset();
89   while((rec = (Recording*)recList->getCurrent()))
90   {
91     btime = localtime((time_t*)&rec->start);
92     strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
93     sprintf(tempB, "%s %s", tempA, rec->getProgName());
94     rec->index = sl.addOption(tempB, first);
95     first = 0;
96     recList->next();
97   }
98
99   if (!recDir->isRoot)
100   {
101     snprintf(tempA, 299, "Recordings - %s", recDir->name);
102     setTitleText(tempA);
103   }
104   else
105   {
106     setTitleText("Recordings");
107   }
108 }
109
110 void VRecordingList::draw()
111 {
112   View::draw();
113   sl.draw();
114
115   // Put the status stuff at the bottom
116
117   WSymbol w;
118
119   w.nextSymbol = WSymbol::UP;
120   w.setScreenPos(screenX + 20, screenY + 385);
121   w.draw();
122
123   w.nextSymbol = WSymbol::DOWN;
124   w.setScreenPos(screenX + 50, screenY + 385);
125   w.draw();
126
127   w.nextSymbol = WSymbol::SKIPBACK;
128   w.setScreenPos(screenX + 85, screenY + 385);
129   w.draw();
130
131   w.nextSymbol = WSymbol::SKIPFORWARD;
132   w.setScreenPos(screenX + 115, screenY + 385);
133   w.draw();
134
135   w.nextSymbol = WSymbol::PLAY;
136   w.setScreenPos(screenX + 150, screenY + 385);
137   w.draw();
138
139   // FIXME Right justify this!
140   drawText("[ok] = menu", 450, 385, Colour::LIGHTTEXT);
141
142   doShowingBar();
143
144   char freeSpace[50];
145   int gigFree = Directory::freeSpace / 1024;
146   snprintf(freeSpace, 49, "%lu%%, %iGB free", Directory::usedPercent, gigFree);
147   drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
148 }
149
150 void VRecordingList::doShowingBar()
151 {
152   int topOption = sl.getTopOption() + 1;
153   if (sl.getNumOptions() == 0) topOption = 0;
154
155   char showing[200];
156   sprintf(showing, "%i to %i of %i", topOption, sl.getBottomOption(), sl.getNumOptions());
157   Box b;
158   b.setScreenPos(screenX + 220, screenY + 385);
159   b.setDimensions(25, 160);
160   b.fillColour(Colour::VIEWBACKGROUND);
161   b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
162 }
163
164
165
166 void VRecordingList::processMessage(Message* m)
167 {
168   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
169   if (m->message == Message::DELETE_SELECTED_RECORDING)
170   {
171     Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
172     doDeleteSelected();
173     return;
174   }
175
176   if (m->message == Message::PLAY_SELECTED_RECORDING)
177   {
178     doPlay();
179     return;
180   }
181
182   if (m->message == Message::RESUME_SELECTED_RECORDING)
183   {
184     doResume();
185     return;
186   }
187 }
188
189 void VRecordingList::doDeleteSelected()
190 {
191   Recording* toDelete = getCurrentOptionRecording();
192
193   int saveIndex;
194   int saveTop;
195
196   if (toDelete)
197   {
198     saveIndex = toDelete->index;
199     saveTop = sl.getTopOption();
200     Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s\n", toDelete->index, toDelete->getProgName(), toDelete->fileName);
201     recDir->recList->remove(toDelete);
202     Log::getInstance()->log("VRecordingList", Log::DEBUG, "I have removed: %s %s\n", toDelete->getProgName(), toDelete->fileName);
203
204     VDR* vdr = VDR::getInstance();
205     vdr->deleteRecording(toDelete->fileName);
206
207     delete toDelete;
208
209     sl.clear();
210     setDir(recDir);
211     sl.hintSetCurrent(saveIndex);
212     sl.hintSetTop(saveTop);
213     draw();
214   }
215
216   Message* m2 = new Message();
217   m2->from = this;
218   m2->to = ViewMan::getInstance();
219   m2->message = Message::UPDATE_SCREEN;
220   ViewMan::getInstance()->postMessage(m2);
221 }
222
223 int VRecordingList::doPlay()
224 {
225   Recording* toPlay = getCurrentOptionRecording();
226   if (toPlay)
227   {
228     VVideoRec* vidrec = new VVideoRec(toPlay);
229     ViewMan::getInstance()->addNoLock(vidrec);
230     vidrec->draw();
231     vidrec->show();
232     vidrec->go(0);
233     return 1;
234   }
235   // should not get to here
236   return 0;
237 }
238
239 int VRecordingList::doResume()
240 {
241   Recording* toResume = getCurrentOptionRecording();
242   if (toResume)
243   {
244     ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
245
246     VVideoRec* vidrec = new VVideoRec(toResume);
247     ViewMan::getInstance()->addNoLock(vidrec);
248     vidrec->draw();
249     vidrec->show();
250     vidrec->go(position);
251     return 1;
252   }
253   // should not get to here
254   return 0;
255 }
256
257 Recording* VRecordingList::getCurrentOptionRecording()
258 {
259   Recording* current;
260   for(recDir->recList->reset(); (current = (Recording*)recDir->recList->getCurrent()); recDir->recList->next())
261   {
262     if (current->index == sl.getCurrentOption()) return current;
263   }
264   return NULL;
265 }
266
267 int VRecordingList::handleCommand(int command)
268 {
269   if (command == Remote::UP)
270   {
271     sl.up();
272     sl.draw();
273
274     doShowingBar();
275     show();
276     return 2;
277   }
278   else if (command == Remote::DOWN)
279   {
280     sl.down();
281     sl.draw();
282
283     doShowingBar();
284     show();
285     return 2;
286   }
287   else if (command == Remote::SKIPBACK)
288   {
289     sl.pageUp();
290     sl.draw();
291
292     doShowingBar();
293     show();
294     return 2;
295   }
296   else if (command == Remote::SKIPFORWARD)
297   {
298     sl.pageDown();
299     sl.draw();
300
301     doShowingBar();
302     show();
303     return 2;
304   }
305   else if (command == Remote::OK)
306   {
307     if (sl.getNumOptions() == 0) return 2;
308
309     // Check to see if it is a sub directory
310     Directory* curDir;
311     for(recDir->dirList->reset(); (curDir = (Directory*)recDir->dirList->getCurrent()); recDir->dirList->next())
312     {
313       if (curDir->index == sl.getCurrentOption())
314       {
315         VRecordingList* sub = new VRecordingList();
316         sub->setDir(curDir);
317         ViewMan::getInstance()->addNoLock(sub);
318
319         sub->draw();
320         sub->show();
321
322         return 2;
323       }
324     }
325
326     // check to see if it's a recording
327     Recording* current;
328     for(recDir->recList->reset(); (current = (Recording*)recDir->recList->getCurrent()); recDir->recList->next())
329     {
330       if (current->index == sl.getCurrentOption())
331       {
332         Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
333
334         VRecordingMenu* v = new VRecordingMenu();
335         v->setParent(this);
336         v->setRecording(current);
337         ViewMan::getInstance()->addNoLock(v);
338         v->draw();
339         v->show();
340         return 2;
341       }
342     }
343     // should not get to here
344     return 1;
345   }
346   else if (command == Remote::BACK)
347   {
348     return 4;
349   }
350   else if (command == Remote::PLAY)
351   {
352     if (doPlay()) return 2;
353     return 1;
354   }
355
356   // stop command getting to any more views
357   return 1;
358 }