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