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