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
31 rootDir = new Directory("/");
34 chronoSortOrder = false;
42 void RecMan::setStats(ULONG ttotalSpace, ULONG tfreeSpace, ULONG tusedPercent)
44 totalSpace = ttotalSpace;
45 freeSpace = tfreeSpace;
46 usedPercent = tusedPercent;
49 void RecMan::addEntry(ULONG startTime, char* name, char* fileName)
51 Recording* rec = new Recording();
52 rec->setStartTime(startTime);
53 rec->setFileName(fileName);
55 // And now for the directory structure & prog name
59 stack<char*> dirNamesStack;
61 bool gotProgName = false;
62 for(c = (name + strlen(name) - 1); c >= name; c--)
64 if ((*c == '~') || (c == name))
66 // Make d point to the start of the string (i.e. move on 1 from ~ if necessary)
67 if (c == name) d = name;
72 rec->setProgName(d); // will copy from d to end of string
79 oneDirName = new char[strlen(d) + 1];
80 strcpy(oneDirName, d);
81 dirNamesStack.push(oneDirName);
87 Directory* targetDirectory = rootDir;
90 while(!dirNamesStack.empty())
92 oneDirName = dirNamesStack.top();
93 if (!oneDirName) break;
95 getDir = targetDirectory->getDirByName(oneDirName);
98 targetDirectory = getDir;
102 getDir = new Directory(oneDirName); // Make a new directory
103 getDir->parent = targetDirectory;
104 targetDirectory->dirList.push_back(getDir); // Put the new directory in the tree
105 targetDirectory = getDir; // Make the new dir the target
112 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);
182 toDir->sort(chronoSortOrder);
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()
257 void RecMan::setSortOrderChron()
259 chronoSortOrder = true;
262 void RecMan::toggleSortOrder()
264 chronoSortOrder = !chronoSortOrder;
269 Log::getInstance()->log("RecMan", Log::DEBUG, "Sort");
270 rootDir->sort(chronoSortOrder);