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("/");
33 chronoSortOrder = false;
41 void RecMan::setStats(ULONG ttotalSpace, ULONG tfreeSpace, ULONG tusedPercent)
43 totalSpace = ttotalSpace;
44 freeSpace = tfreeSpace;
45 usedPercent = tusedPercent;
48 void RecMan::addEntry(ULONG startTime, char* name, char* fileName)
50 Recording* rec = new Recording();
51 rec->setStartTime(startTime);
52 rec->setFileName(fileName);
54 // And now for the directory structure & prog name
58 stack<char*> dirNamesStack;
60 bool gotProgName = false;
61 for(c = (name + strlen(name) - 1); c >= name; c--)
63 if ((*c == '~') || (c == name))
65 // Make d point to the start of the string (i.e. move on 1 from ~ if necessary)
66 if (c == name) d = name;
71 rec->setProgName(d); // will copy from d to end of string
78 oneDirName = new char[strlen(d) + 1];
79 strcpy(oneDirName, d);
80 dirNamesStack.push(oneDirName);
86 Directory* targetDirectory = rootDir;
89 while(!dirNamesStack.empty())
91 oneDirName = dirNamesStack.top();
92 if (!oneDirName) break;
94 getDir = targetDirectory->getDirByName(oneDirName);
97 targetDirectory = getDir;
101 getDir = new Directory(oneDirName); // Make a new directory
102 getDir->parent = targetDirectory;
103 targetDirectory->dirList.push_back(getDir); // Put the new directory in the tree
104 targetDirectory = getDir; // Make the new dir the target
111 targetDirectory->recList.push_back(rec);
114 ULONG RecMan::getTotalSpace()
119 ULONG RecMan::getFreeSpace()
124 ULONG RecMan::getUsedPercent()
129 int RecMan::deleteRecording(Recording* rec)
133 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
137 success = VDR::getInstance()->deleteRecording(rec->getFileName());
140 currentDir->recList.erase(i);
150 void RecMan::constructPath(char* target, Directory* dir)
154 constructPath(target, dir->parent);
155 strcat(target, dir->name);
160 int RecMan::moveRecording(Recording* toMove, Directory* toDir)
162 char newPath[PATH_MAX];
163 strcpy(newPath, "/");
164 constructPath(&newPath[1], toDir);
167 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
171 char* newFileName = VDR::getInstance()->moveRecording(toMove->getFileName(), newPath);
176 toMove->setFileName(newFileName);
177 delete[] newFileName;
179 currentDir->recList.erase(i);
180 toDir->recList.push_back(toMove);
181 toDir->sort(chronoSortOrder);
191 bool RecMan::isSubDir()
193 return (currentDir != rootDir);
196 bool RecMan::down(Directory* downDir)
198 // Check dir is in currentDir
199 for(DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
203 currentDir = downDir;
212 if (!isSubDir()) return false;
214 Directory* oldDir = currentDir;
215 currentDir = currentDir->parent;
217 if (oldDir->getNumRecordings() == 0)
221 for (DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
224 if (tempdir == oldDir)
226 currentDir->dirList.erase(i);
236 char* RecMan::getCurDirName()
238 return currentDir->name;
241 DirectoryList* RecMan::getDirectories()
243 return ¤tDir->dirList;
246 RecordingList* RecMan::getRecordings()
248 return ¤tDir->recList;
251 Directory* RecMan::getRootDir()
256 void RecMan::setSortOrderChron()
258 chronoSortOrder = true;
261 void RecMan::toggleSortOrder()
263 chronoSortOrder = !chronoSortOrder;
268 Log::getInstance()->log("RecMan", Log::DEBUG, "Sort");
269 rootDir->sort(chronoSortOrder);