2 Copyright 2006 Chris Tallon
4 This file is part of VOMP.
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.
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.
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
30 rootDir = new Directory("/");
39 void RecMan::setStats(ULONG ttotalSpace, ULONG tfreeSpace, ULONG tusedPercent)
41 totalSpace = ttotalSpace;
42 freeSpace = tfreeSpace;
43 usedPercent = tusedPercent;
46 void RecMan::addEntry(ULONG startTime, char* name, char* fileName)
48 Recording* rec = new Recording();
49 rec->setStartTime(startTime);
50 rec->setFileName(fileName);
52 // And now for the directory structure & prog name
56 stack<char*> dirNamesStack;
58 bool gotProgName = false;
59 for(c = (name + strlen(name) - 1); c >= name; c--)
61 if ((*c == '~') || (c == name))
63 // Make d point to the start of the string (i.e. move on 1 from ~ if necessary)
64 if (c == name) d = name;
69 rec->setProgName(d); // will copy from d to end of string
76 oneDirName = new char[strlen(d) + 1];
77 strcpy(oneDirName, d);
78 dirNamesStack.push(oneDirName);
84 Directory* targetDirectory = rootDir;
87 while(!dirNamesStack.empty())
89 oneDirName = dirNamesStack.top();
90 if (!oneDirName) break;
92 getDir = targetDirectory->getDirByName(oneDirName);
95 targetDirectory = getDir;
99 getDir = new Directory(oneDirName); // Make a new directory
100 getDir->parent = targetDirectory;
101 targetDirectory->dirList.push_back(getDir); // Put the new directory in the tree
102 targetDirectory = getDir; // Make the new dir the target
109 targetDirectory->recList.push_back(rec);
115 ULONG RecMan::getTotalSpace()
120 ULONG RecMan::getFreeSpace()
125 ULONG RecMan::getUsedPercent()
130 int RecMan::deleteRecording(Recording* rec)
134 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
138 success = VDR::getInstance()->deleteRecording(rec->getFileName());
141 currentDir->recList.erase(i);
151 void RecMan::constructPath(char* target, Directory* dir)
155 constructPath(target, dir->parent);
156 strcat(target, dir->name);
161 int RecMan::moveRecording(Recording* toMove, Directory* toDir)
163 char newPath[PATH_MAX];
164 strcpy(newPath, "/");
165 constructPath(&newPath[1], toDir);
168 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
172 char* newFileName = VDR::getInstance()->moveRecording(toMove->getFileName(), newPath);
177 toMove->setFileName(newFileName);
178 delete[] newFileName;
180 currentDir->recList.erase(i);
181 toDir->recList.push_back(toMove);
192 bool RecMan::isSubDir()
194 return (currentDir != rootDir);
197 bool RecMan::down(Directory* downDir)
199 // Check dir is in currentDir
200 for(DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
204 currentDir = downDir;
213 if (!isSubDir()) return false;
215 Directory* oldDir = currentDir;
216 currentDir = currentDir->parent;
218 if (oldDir->getNumRecordings() == 0)
222 for (DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
225 if (tempdir == oldDir)
227 currentDir->dirList.erase(i);
237 char* RecMan::getCurDirName()
239 return currentDir->name;
242 DirectoryList* RecMan::getDirectories()
244 return ¤tDir->dirList;
247 RecordingList* RecMan::getRecordings()
249 return ¤tDir->recList;
252 Directory* RecMan::getRootDir()