From 50305c94dd907817114568c3fe4f64697efa0f71 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 14 May 2006 18:44:51 +0000 Subject: [PATCH] New recordings managager to support multi level dir structure and more in future --- Makefile | 2 +- directory.cc | 33 +++--- directory.h | 32 ++++-- recman.cc | 213 +++++++++++++++++++++++++++++++++++++++ recman.h | 60 +++++++++++ recording.cc | 63 +++++------- recording.h | 17 ++-- vdr.cc | 76 ++++---------- vdr.h | 32 +----- vrecordinglist.cc | 250 ++++++++++++++++++++++++---------------------- vrecordinglist.h | 19 ++-- vrecordingmenu.cc | 2 +- vvideorec.cc | 2 +- vwelcome.cc | 33 +----- vwelcome.h | 1 - 15 files changed, 527 insertions(+), 308 deletions(-) create mode 100644 recman.cc create mode 100644 recman.h diff --git a/Makefile b/Makefile index 926f887..4213a86 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ CROSSLIBS = ../jpeg-6b/libjpeg.a OBJECTS1 = main.o command.o log.o tcp.o dsock.o thread.o timers.o i18n.o \ message.o messagequeue.o \ - vdr.o recording.o channel.o rectimer.o event.o directory.o \ + vdr.o recman.o recording.o channel.o rectimer.o event.o directory.o \ player.o vfeed.o afeed.o afeedr.o \ demuxer.o demuxervdr.o stream.o draintarget.o \ viewman.o box.o region.o colour.o view.o \ diff --git a/directory.cc b/directory.cc index 6b9d636..b96f458 100644 --- a/directory.cc +++ b/directory.cc @@ -20,21 +20,20 @@ #include "directory.h" -ULONG Directory::totalSpace = 0; -ULONG Directory::freeSpace = 0; -ULONG Directory::usedPercent = 0; - -Directory::Directory() +Directory::Directory(char* newName) { - name = NULL; - - isRoot = 0; index = -1; + + name = new char[strlen(newName) + 1]; + strcpy(name, newName); + + parent = NULL; } Directory::~Directory() { if (name) delete[] name; + name = NULL; index = -1; // just in case UINT i; @@ -51,12 +50,6 @@ Directory::~Directory() recList.clear(); } -void Directory::setName(char* newName) -{ - name = new char[strlen(newName) + 1]; - strcpy(name, newName); -} - Directory* Directory::getDirByName(char* dirName) { for(UINT i = 0; i < dirList.size(); i++) @@ -71,4 +64,14 @@ ULONG Directory::getNumRecordings() return recList.size(); } -// FIXME make an add function in here that adds recs to the end of the list +void Directory::sort() +{ + // Sort the directory order + ::sort(dirList.begin(), dirList.end(), DirectorySorter()); + + // Sort the recordings order + ::sort(recList.begin(), recList.end(), RecordingSorter()); + + // Now get the dirs to sort themselves! oh I love recursion. + for(UINT i = 0; i < dirList.size(); i++) dirList[i]->sort(); +} diff --git a/directory.h b/directory.h index c2cd9da..f70aad1 100644 --- a/directory.h +++ b/directory.h @@ -23,6 +23,7 @@ #include #include +#include using namespace std; #include "defines.h" @@ -35,26 +36,43 @@ typedef vector RecordingList; class Directory { public: - Directory(); + Directory(char* newName); ~Directory(); - void setName(char* newName); Directory* getDirByName(char* dirName); - void setFreeSpace(ULLONG); ULONG getNumRecordings(); + void sort(); - UCHAR isRoot; char* name; int index; + Directory* parent; DirectoryList dirList; RecordingList recList; - static ULONG totalSpace; - static ULONG freeSpace; - static ULONG usedPercent; +}; +struct DirectorySorter +{ + bool operator() (const Directory* a, const Directory* b) + { + int c = strcmp(b->name, a->name); + if (c > 0) return true; + return false; + } +}; + +struct RecordingSorter +{ + bool operator() (const Recording* a, const Recording* b) + { + int c = strcmp(b->getProgName(), a->getProgName()); + if (c > 0) return true; + if (c < 0) return false; + + return a->getStartTime() < b->getStartTime(); + } }; #endif diff --git a/recman.cc b/recman.cc new file mode 100644 index 0000000..0c66350 --- /dev/null +++ b/recman.cc @@ -0,0 +1,213 @@ +/* + Copyright 2006 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "recman.h" +#include "vdr.h" + +RecMan::RecMan() +{ + totalSpace = 0; + freeSpace = 0; + usedPercent = 0; + + rootDir = new Directory("/"); + currentDir = rootDir; +} + +RecMan::~RecMan() +{ + delete rootDir; +} + +void RecMan::setStats(ULONG ttotalSpace, ULONG tfreeSpace, ULONG tusedPercent) +{ + totalSpace = ttotalSpace; + freeSpace = tfreeSpace; + usedPercent = tusedPercent; +} + +void RecMan::addEntry(ULONG startTime, char* name, char* fileName) +{ + Recording* rec = new Recording(); + rec->setStartTime(startTime); + rec->setFileName(fileName); + + // And now for the directory structure & prog name + + printf("%lu %s %s\n", startTime, name, fileName); + + char* c; + char* d; + stack dirNamesStack; + char* oneDirName; + bool gotProgName = false; + for(c = (name + strlen(name) - 1); c >= name; c--) + { + if ((*c == '~') || (c == name)) + { + // Make d point to the start of the string (i.e. move on 1 from ~ if necessary) + if (c == name) d = name; + else d = c + 1; + + if (!gotProgName) + { + printf("Got prog name '%s'\n", d); + rec->setProgName(d); // will copy from d to end of string + *c = '\0'; + gotProgName = true; + } + else + { + // get the dir + oneDirName = new char[strlen(d) + 1]; + strcpy(oneDirName, d); + dirNamesStack.push(oneDirName); + *c = '\0'; + } + } + } + + Directory* targetDirectory = rootDir; + Directory* getDir; + + while(!dirNamesStack.empty()) + { + oneDirName = dirNamesStack.top(); + if (!oneDirName) break; + + getDir = targetDirectory->getDirByName(oneDirName); + if (getDir) + { + targetDirectory = getDir; + } + else + { + printf("making new dir '%s'\n", oneDirName); + getDir = new Directory(oneDirName); // Make a new directory + getDir->parent = targetDirectory; + targetDirectory->dirList.push_back(getDir); // Put the new directory in the tree + targetDirectory = getDir; // Make the new dir the target + } + + dirNamesStack.pop(); + delete[] oneDirName; + } + + targetDirectory->recList.push_back(rec); + + // Sort it all. + rootDir->sort(); +} + +ULONG RecMan::getTotalSpace() +{ + return totalSpace; +} + +ULONG RecMan::getFreeSpace() +{ + return freeSpace; +} + +ULONG RecMan::getUsedPercent() +{ + return usedPercent; +} + +int RecMan::deleteRecording(Recording* rec) +{ + int success = 0; + + for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++) + { + if (*i == rec) + { + success = VDR::getInstance()->deleteRecording(rec->getFileName()); + if (success == 1) + { + currentDir->recList.erase(i); + delete rec; + } + break; + } + } + + return success; +} + +bool RecMan::isSubDir() +{ + return (currentDir != rootDir); +} + +bool RecMan::down(Directory* downDir) +{ + // Check dir is in currentDir + for(DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++) + { + if (*i == downDir) + { + currentDir = downDir; + return true; + } + } + return false; +} + +bool RecMan::up() +{ + if (!isSubDir()) return false; + + Directory* oldDir = currentDir; + currentDir = currentDir->parent; + + if (oldDir->getNumRecordings() == 0) + { + // delete the olddir + Directory* tempdir; + for (DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++) + { + tempdir = *i; + if (tempdir == oldDir) + { + currentDir->dirList.erase(i); + delete tempdir; + break; + } + } + } + + return true; +} + +char* RecMan::getCurDirName() +{ + return currentDir->name; +} + +DirectoryList* RecMan::getDirectories() +{ + return ¤tDir->dirList; +} + +RecordingList* RecMan::getRecordings() +{ + return ¤tDir->recList; +} diff --git a/recman.h b/recman.h new file mode 100644 index 0000000..915cb1d --- /dev/null +++ b/recman.h @@ -0,0 +1,60 @@ +/* + Copyright 2006 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef RECMAN_H +#define RECMAN_H + +#include + +#include "directory.h" +#include "recording.h" + +class RecMan +{ + public: + RecMan(); + ~RecMan(); + + void setStats(ULONG totalSpace, ULONG freeSpace, ULONG usedPercent); + void addEntry(ULONG startTime, char* name, char* filename); // modifies name + int deleteRecording(Recording* rec); + + // State functions + bool isSubDir(); + bool up(); + bool down(Directory* downDir); + char* getCurDirName(); + DirectoryList* getDirectories(); + RecordingList* getRecordings(); + + ULONG getTotalSpace(); + ULONG getFreeSpace(); + ULONG getUsedPercent(); + + private: + ULONG totalSpace; + ULONG freeSpace; + ULONG usedPercent; + + Directory* rootDir; + Directory* currentDir; +}; + +#endif diff --git a/recording.cc b/recording.cc index 2b28d54..365b532 100644 --- a/recording.cc +++ b/recording.cc @@ -23,67 +23,56 @@ Recording::Recording() { start = 0; - dirName = NULL; progName = NULL; fileName = NULL; - index = -1; } Recording::~Recording() { - if (dirName) delete[] dirName; - if (progName) delete[] progName; - if (fileName) delete[] fileName; + if (progName) { free(progName); progName = NULL; } + if (fileName) { free(fileName); fileName = NULL; } index = -1; // just in case } -int Recording::isInDir() +ULONG Recording::getStartTime() const { -// if (strstr(name, "~")) return 1; -// else return 0; - return (dirName != NULL); + return start; } -char* Recording::getDirName() +char* Recording::getProgName() const { -/* char* sub = strstr(name, "~"); - if (!sub) return NULL; + return progName; +} - char* dirName = new char[sub - name + 1]; - memcpy(dirName, name, sub - name); - dirName[sub - name] = '\0'; - return dirName; -*/ - return dirName; +char* Recording::getFileName() const +{ + return fileName; } -char* Recording::getProgName() const +void Recording::setStartTime(ULONG tstartTime) { - return progName; + start = tstartTime; } -void Recording::setName(char* name) +void Recording::setProgName(char* tProgName) { - char* sub = strstr(name, "~"); + if (progName) free(progName); - if (sub) // Its in a dir + if (asprintf(&progName, tProgName) == -1) { - dirName = new char[sub - name + 1]; - memcpy(dirName, name, sub - name); - dirName[sub - name] = '\0'; - - sub++; - int sublen = strlen(sub); - progName = new char[sublen + 1]; - memcpy(progName, sub, strlen(sub)); - progName[sublen] = '\0'; + free(progName); + progName = NULL; } - else +} + +void Recording::setFileName(char* tFileName) +{ + if (fileName) free(fileName); + + if (asprintf(&fileName, tFileName) == -1) { - int len = strlen(name); - progName = new char[len + 1]; - memcpy(progName, name, len); - progName[len] = '\0'; + free(fileName); + fileName = NULL; } } diff --git a/recording.h b/recording.h index 0d65eda..ba6ddd9 100644 --- a/recording.h +++ b/recording.h @@ -22,7 +22,9 @@ #define RECORDING_H #include +#include #include +#include "defines.h" class Recording { @@ -30,20 +32,21 @@ class Recording Recording(); ~Recording(); - void setName(char* name); + void setStartTime(ULONG startTime); + void setProgName(char* progName); + void setFileName(char* fileName); - int isInDir(); - char* getDirName(); + ULONG getStartTime() const; char* getProgName() const; - - unsigned long start; - char* fileName; + char* getFileName() const; int index; private: - char* dirName; + ULONG start; char* progName; + char* fileName; + }; #endif diff --git a/vdr.cc b/vdr.cc index 4ddf1bf..7ec9857 100644 --- a/vdr.cc +++ b/vdr.cc @@ -321,7 +321,7 @@ int VDR::doLogin() return 1; } -Directory* VDR::getRecordingsList() +bool VDR::getRecordingsList(RecMan* recman) { UCHAR buffer[8]; @@ -340,7 +340,7 @@ Directory* VDR::getRecordingsList() { disconnect(); MUTEX_UNLOCK(&mutex); - return NULL; + return false; } // reply @@ -348,73 +348,31 @@ Directory* VDR::getRecordingsList() if (!getPacket()) { MUTEX_UNLOCK(&mutex); - return NULL; + return false; } - Directory* recDir = new Directory(); - recDir->setName("/"); - recDir->isRoot = 1; - - Directory::totalSpace = extractULONG(); - Directory::freeSpace = extractULONG(); - Directory::usedPercent = extractULONG(); + recman->setStats(extractULONG(), extractULONG(), extractULONG()); - char* string; + ULONG start; + char* name; + char* fileName; while (packetPos < packetLength) { - Recording* rec = new Recording(); - - rec->start = extractULONG(); - - string = extractString(); - rec->setName(string); - delete[] string; - - rec->fileName = extractString(); - - if(rec->isInDir()) - { - char* dirName = rec->getDirName(); - - Directory* d = recDir->getDirByName(dirName); - if (!d) - { - d = new Directory(); - d->setName(dirName); -// Log::getInstance()->log("VDR", Log::DEBUG, "Added a new directory = %s", d->name); - recDir->dirList.push_back(d); - } + start = extractULONG(); + name = extractString(); + fileName = extractString(); - d->recList.push_back(rec); - } - else - { - recDir->recList.push_back(rec); - } + recman->addEntry(start, name, fileName); -// Log::getInstance()->log("VDR", Log::DEBUG, "%s", rec->fileName); + delete[] name; + delete[] fileName; } freePacket(); MUTEX_UNLOCK(&mutex); - // Sort the directory order - sort(recDir->dirList.begin(), recDir->dirList.end(), DirectorySorter()); - - // Sort all the sub lists - Directory* sortDir; - DirectoryList::iterator i; - for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++) - { - sortDir = *i; - sort(sortDir->recList.begin(), sortDir->recList.end(), RecordingSorter()); - } - - // Sort the root level list - sort(recDir->recList.begin(), recDir->recList.end(), RecordingSorter()); - - return recDir; + return true; } int VDR::deleteRecording(char* fileName) @@ -649,14 +607,14 @@ UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived) return toReturn; } -ULLONG VDR::streamRecording(Recording* rec) +ULLONG VDR::streamRecording(char* fileName) { - unsigned long totalLength = 8 + strlen(rec->fileName) + 1; + unsigned long totalLength = 8 + strlen(fileName) + 1; UCHAR* buffer = new UCHAR[totalLength]; *(unsigned long*)&buffer[0] = htonl(totalLength - 4); *(unsigned long*)&buffer[4] = htonl(VDR_STREAMRECORDING); - strcpy((char*)&buffer[8], rec->fileName); + strcpy((char*)&buffer[8], fileName); MUTEX_LOCK(&mutex); if (!connected) { MUTEX_UNLOCK(&mutex); return 0; } diff --git a/vdr.h b/vdr.h index aeb7b58..228acdc 100644 --- a/vdr.h +++ b/vdr.h @@ -35,11 +35,10 @@ #include "log.h" #include "dsock.h" #include "tcp.h" -#include "directory.h" -#include "recording.h" #include "channel.h" #include "event.h" #include "rectimer.h" +#include "recman.h" using namespace std; @@ -70,27 +69,6 @@ struct ServerSorter } }; -struct RecordingSorter -{ - bool operator() (const Recording* a, const Recording* b) - { - int c = strcmp(b->getProgName(), a->getProgName()); - if (c > 0) return true; - if (c < 0) return false; - - return a->start < b->start; - } -}; - -struct DirectorySorter -{ - bool operator() (const Directory* a, const Directory* b) - { - int c = strcmp(b->name, a->name); - if (c > 0) return true; - return false; - } -}; class VDR { @@ -135,13 +113,13 @@ class VDR int doLogin(); - Directory* getRecordingsList(); + bool getRecordingsList(RecMan* recman); char* getRecordingSummary(char* fileName); int deleteRecording(char* fileName); - ULLONG streamRecording(Recording* rec); + ULLONG streamRecording(char* fileName); ULLONG rescanRecording(); ULLONG positionFromFrameNumber(ULONG frameNumber); - ULONG frameNumberFromPosition(ULLONG position); + ULONG frameNumberFromPosition(ULLONG position); ChannelList* getChannelsList(ULONG type); int streamChannel(ULONG number); @@ -196,7 +174,7 @@ class VDR const static ULONG VDR_GETTIMERS = 14; const static ULONG VDR_SETTIMER = 15; const static ULONG VDR_POSFROMFRAME = 16; - const static ULONG VDR_FRAMEFROMPOS = 17; + const static ULONG VDR_FRAMEFROMPOS = 17; int getPacket(); void freePacket(); diff --git a/vrecordinglist.cc b/vrecordinglist.cc index 3965fd2..d9ae555 100644 --- a/vrecordinglist.cc +++ b/vrecordinglist.cc @@ -20,11 +20,11 @@ #include "vrecordinglist.h" -VRecordingList::VRecordingList(VRecordingList* tparent, Directory* tdir) +VRecordingList::VRecordingList() { - myParent = tparent; viewman = ViewMan::getInstance(); - recDir = tdir; + recman = NULL; + loading = true; create(570, 420); if (Video::getInstance()->getFormat() == Video::PAL) @@ -47,39 +47,10 @@ VRecordingList::VRecordingList(VRecordingList* tparent, Directory* tdir) VRecordingList::~VRecordingList() { - if (myParent) - { - // if this is a sub, there can only be recordings. if there are none left, get this dir deleted by parent - if (recDir->getNumRecordings() == 0) myParent->zeroCheck(); - // recDir is now deleted if it was empty - } - else - { - // only delete the list if this is not a sub dir window - delete recDir; - } -} - -void VRecordingList::zeroCheck() -{ - // go through to delete 1 empty dir if necessary (there will only ever be 1) - Directory* dir; - DirectoryList::iterator i; - for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++) - { - dir = *i; - if (dir->getNumRecordings() == 0) - { - delete dir; - recDir->dirList.erase(i); - break; - } - } - drawData(); - viewman->updateView(this); + delete recman; } -void VRecordingList::drawData() +void VRecordingList::drawData(bool doIndexPop) { int saveIndex = sl.getCurrentOption(); int saveTop = sl.getTopOption(); @@ -94,89 +65,111 @@ void VRecordingList::drawData() char tempB[300]; // FIXME struct tm* btime; - Directory* dir; + Directory* currentSubDir; DirectoryList::iterator i; - for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++) + DirectoryList* dirList = recman->getDirectories(); + for (i = dirList->begin(); i != dirList->end(); i++) { - dir = *i; - SNPRINTF(tempA, 299, tr(" %lu\t%s"), dir->getNumRecordings(), dir->name); - dir->index = sl.addOption(tempA, first); + currentSubDir = *i; + SNPRINTF(tempA, 299, tr(" %lu\t%s"), currentSubDir->getNumRecordings(), currentSubDir->name); + currentSubDir->index = sl.addOption(tempA, first); first = 0; } // FIXME convert the whole program to time_t's - Recording* rec; - for (UINT j = 0; j < recDir->recList.size(); j++) + Recording* currentRec; + RecordingList::iterator j; + RecordingList* recList = recman->getRecordings(); + for (j = recList->begin(); j != recList->end(); j++) { - rec = recDir->recList[j]; - btime = localtime((time_t*)&rec->start); + currentRec = *j; + time_t recStartTime = (time_t)currentRec->getStartTime(); + btime = localtime(&recStartTime); #ifndef _MSC_VER strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime); #else strftime(tempA, 299, "%d/%m %H:%M ", btime); #endif - sprintf(tempB, "%s\t%s", tempA, rec->getProgName()); - rec->index = sl.addOption(tempB, first); + sprintf(tempB, "%s\t%s", tempA, currentRec->getProgName()); + currentRec->index = sl.addOption(tempB, first); first = 0; } - sl.hintSetCurrent(saveIndex); - sl.hintSetTop(saveTop); + if (doIndexPop) + { + sl.hintSetCurrent(slIndexStack.top()); + slIndexStack.pop(); + } + else + { + sl.hintSetCurrent(saveIndex); + sl.hintSetTop(saveTop); + } sl.draw(); doShowingBar(); } -void VRecordingList::draw() +void VRecordingList::draw(bool doIndexPop) { - char title[300]; - if (myParent) - { - SNPRINTF(title, 299, tr("Recordings - %s"), recDir->name); - setTitleText(title); - } - else + if (!loading) { - setTitleText(tr("Recordings")); + if (recman->isSubDir()) + { + char title[300]; + SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName()); + setTitleText(title); + } + else + { + setTitleText(tr("Recordings")); + } } View::draw(); - char freeSpace[50]; - int gigFree = Directory::freeSpace / 1024; - SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), Directory::usedPercent, gigFree); - drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT); + if (loading) + { + drawText(tr("Loading..."), 240, 180, Colour::LIGHTTEXT); + } + else + { + char freeSpace[50]; + int gigFree = recman->getFreeSpace() / 1024; + SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree); + drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT); - // Symbols + // Symbols - WSymbol w; - w.setSurface(surface); + WSymbol w; + w.setSurface(surface); - w.nextSymbol = WSymbol::UP; - w.setSurfaceOffset(20, 385); - w.draw(); + w.nextSymbol = WSymbol::UP; + w.setSurfaceOffset(20, 385); + w.draw(); - w.nextSymbol = WSymbol::DOWN; - w.setSurfaceOffset(50, 385); - w.draw(); + w.nextSymbol = WSymbol::DOWN; + w.setSurfaceOffset(50, 385); + w.draw(); - w.nextSymbol = WSymbol::SKIPBACK; - w.setSurfaceOffset(85, 385); - w.draw(); + w.nextSymbol = WSymbol::SKIPBACK; + w.setSurfaceOffset(85, 385); + w.draw(); - w.nextSymbol = WSymbol::SKIPFORWARD; - w.setSurfaceOffset(115, 385); - w.draw(); + w.nextSymbol = WSymbol::SKIPFORWARD; + w.setSurfaceOffset(115, 385); + w.draw(); - w.nextSymbol = WSymbol::PLAY; - w.setSurfaceOffset(150, 385); - w.draw(); + w.nextSymbol = WSymbol::PLAY; + w.setSurfaceOffset(150, 385); + w.draw(); - drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT); + drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT); - // All static stuff done + // All static stuff done - drawData(); + drawData(doIndexPop); + } } void VRecordingList::doShowingBar() @@ -215,18 +208,17 @@ void VRecordingList::processMessage(Message* m) void VRecordingList::doDeleteSelected() { - Log::getInstance()->log("VRecordingList", Log::DEBUG, "Parent = %p, isRoot = %i", myParent, recDir->isRoot); Recording* toDelete = getCurrentOptionRecording(); if (toDelete) { - Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->fileName); + Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName()); - VDR* vdr = VDR::getInstance(); - int success = vdr->deleteRecording(toDelete->fileName); - if (!vdr->isConnected()) + int success = recman->deleteRecording(toDelete); + if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); + return; } if (success != 1) @@ -248,23 +240,9 @@ void VRecordingList::doDeleteSelected() } else { - delete toDelete; - - for(RecordingList::iterator i = recDir->recList.begin(); i != recDir->recList.end(); i++) - { - if (*i == toDelete) - { - recDir->recList.erase(i); - break; - } - } - - drawData(); + draw(); viewman->updateView(this); - - if (myParent) myParent->drawData(); // if this is not root get parent to redraw data } - Log::getInstance()->log("VRecordingList", Log::DEBUG, "Parent = %p, isRoot = %i", myParent, recDir->isRoot); } } @@ -287,9 +265,12 @@ int VRecordingList::doPlay() int VRecordingList::doResume() { Recording* toResume = getCurrentOptionRecording(); + + printf("%s\n", toResume->getFileName()); + if (toResume) { - ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName); + ULLONG position = VDR::getInstance()->getResumePoint(toResume->getFileName()); VVideoRec* vidrec = new VVideoRec(toResume); vidrec->draw(); @@ -298,18 +279,22 @@ int VRecordingList::doResume() vidrec->go(position); return 1; } - // should not get to here + +// should not get to here return 0; } Recording* VRecordingList::getCurrentOptionRecording() { - Recording* current; - for (UINT i = 0; i < recDir->recList.size(); i++) + Recording* currentRec; + RecordingList::iterator j; + RecordingList* recList = recman->getRecordings(); + for (j = recList->begin(); j != recList->end(); j++) { - current = recDir->recList[i]; - if (current->index == sl.getCurrentOption()) return current; + currentRec = *j; + if (currentRec->index == sl.getCurrentOption()) return currentRec; } + return NULL; } @@ -365,16 +350,21 @@ int VRecordingList::handleCommand(int command) if (sl.getNumOptions() == 0) return 2; // Check to see if it is a sub directory - Directory* curDir; - for(UINT i = 0; i < recDir->dirList.size(); i++) + Directory* currentSubDir; + DirectoryList::iterator i; + DirectoryList* dirList = recman->getDirectories(); + for (i = dirList->begin(); i != dirList->end(); i++) { - curDir = recDir->dirList[i]; - if (curDir->index == sl.getCurrentOption()) + currentSubDir = *i; + if (currentSubDir->index == sl.getCurrentOption()) { - VRecordingList* sub = new VRecordingList(this, curDir); - sub->draw(); - viewman->add(sub); - viewman->updateView(sub); + if (recman->down(currentSubDir)) + { + slIndexStack.push(sl.getCurrentOption()); + sl.clear(); + draw(); + viewman->updateView(this); + } return 2; } } @@ -383,7 +373,7 @@ int VRecordingList::handleCommand(int command) Recording* current = getCurrentOptionRecording(); if (current) { - Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName); + Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName()); VRecordingMenu* v = new VRecordingMenu(); v->setParent(this); @@ -398,7 +388,18 @@ int VRecordingList::handleCommand(int command) } case Remote::BACK: { - return 4; + if (recman->isSubDir()) + { + recman->up(); + sl.clear(); + draw(true); + viewman->updateView(this); + return 2; + } + else + { + return 4; + } } case Remote::PLAY: { @@ -410,3 +411,18 @@ int VRecordingList::handleCommand(int command) // stop command getting to any more views return 1; } + +bool VRecordingList::load() +{ + recman = new RecMan(); + bool success = VDR::getInstance()->getRecordingsList(recman); + if (success) + { + loading = false; + draw(); + viewman->updateView(this); + } + + return success; +} + diff --git a/vrecordinglist.h b/vrecordinglist.h index 48ff61f..45d920e 100644 --- a/vrecordinglist.h +++ b/vrecordinglist.h @@ -25,8 +25,10 @@ #include #include #include +#include #include "view.h" +#include "recman.h" #include "directory.h" #include "recording.h" #include "wselectlist.h" @@ -44,21 +46,22 @@ class VRecordingList : public View { public: - VRecordingList(VRecordingList* parent, Directory* dir); + VRecordingList(); ~VRecordingList(); int handleCommand(int command); void processMessage(Message* m); - void draw(); - - void drawData(); - void zeroCheck(); + void draw(bool doIndexPop = false); + bool load(); + void drawData(bool doIndexPop = false); private: - VRecordingList* myParent; - Directory* recDir; ViewMan* viewman; + bool loading; + RecMan* recman; + Directory* dir; + WSelectList sl; void doShowingBar(); @@ -66,6 +69,8 @@ class VRecordingList : public View int doPlay(); int doResume(); Recording* getCurrentOptionRecording(); + + stack slIndexStack; }; #endif diff --git a/vrecordingmenu.cc b/vrecordingmenu.cc index 87ee0c3..22533aa 100644 --- a/vrecordingmenu.cc +++ b/vrecordingmenu.cc @@ -113,7 +113,7 @@ int VRecordingMenu::handleCommand(int command) if (sl.getCurrentOption() == 2) { - char* summary = VDR::getInstance()->getRecordingSummary(rec->fileName); + char* summary = VDR::getInstance()->getRecordingSummary(rec->getFileName()); if (!summary && !VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); diff --git a/vvideorec.cc b/vvideorec.cc index 1c55828..a21cd8b 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -95,7 +95,7 @@ void VVideoRec::draw() void VVideoRec::go(ULLONG startPosition) { - ULLONG recLength = vdr->streamRecording(myRec); + ULLONG recLength = vdr->streamRecording(myRec->getFileName()); if (recLength) { doBar(0); diff --git a/vwelcome.cc b/vwelcome.cc index fae90fc..fe41d73 100644 --- a/vwelcome.cc +++ b/vwelcome.cc @@ -250,38 +250,15 @@ void VWelcome::doRadioList() void VWelcome::doRecordingsList() { - VInfo* viewWait = new VInfo(); - viewWait->create(460, 190); - if (Video::getInstance()->getFormat() == Video::PAL) - { - viewWait->setScreenPos(140, 170); - } - else - { - viewWait->setScreenPos(130, 140); - } - viewWait->setOneLiner(tr("Downloading recordings list")); - viewWait->draw(); - viewman->add(viewWait); - viewman->updateView(viewWait); + VRecordingList* vrec = new VRecordingList(); + vrec->draw(); + viewman->add(vrec); + viewman->updateView(vrec); - VDR* vdr = VDR::getInstance(); - Directory* recDir = vdr->getRecordingsList(); - - if (recDir) - { - VRecordingList* vrec = new VRecordingList(NULL, recDir); - vrec->draw(); - - viewman->add(vrec); - viewman->updateView(vrec); - } - else + if (!vrec->load()) { Command::getInstance()->connectionLost(); } - - viewman->removeView(viewWait); } void VWelcome::doTimersList() diff --git a/vwelcome.h b/vwelcome.h index 59ac71b..20c91d1 100644 --- a/vwelcome.h +++ b/vwelcome.h @@ -30,7 +30,6 @@ #include "wjpeg.h" #include "viewman.h" #include "vdr.h" -#include "directory.h" #include "vchannellist.h" #include "vrecordinglist.h" #include "vtimerlist.h" -- 2.39.2