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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 rootDir = new Directory("/");
35 chronoSortOrder = false;
43 void RecMan::setStats(ULONG ttotalSpace, ULONG tfreeSpace, ULONG tusedPercent)
45 totalSpace = ttotalSpace;
46 freeSpace = tfreeSpace;
47 usedPercent = tusedPercent;
50 void RecMan::addEntry(ULONG startTime, char* name, char* fileName)
52 Recording* rec = new Recording();
53 rec->setStartTime(startTime);
54 rec->setFileName(fileName);
56 // And now for the directory structure & prog name
60 stack<char*> dirNamesStack;
62 bool gotProgName = false;
63 for(c = (name + strlen(name) - 1); c >= name; c--)
65 if ((*c == '~') || (c == name))
67 // Make d point to the start of the string (i.e. move on 1 from ~ if necessary)
68 if (c == name) d = name;
73 rec->setProgName(d); // will copy from d to end of string
80 oneDirName = new char[strlen(d) + 1];
81 strcpy(oneDirName, d);
82 dirNamesStack.push(oneDirName);
88 Directory* targetDirectory = rootDir;
91 while(!dirNamesStack.empty())
93 oneDirName = dirNamesStack.top();
94 if (!oneDirName) break;
96 getDir = targetDirectory->getDirByName(oneDirName);
99 targetDirectory = getDir;
103 getDir = new Directory(oneDirName); // Make a new directory
104 getDir->parent = targetDirectory;
105 targetDirectory->dirList.push_back(getDir); // Put the new directory in the tree
106 targetDirectory = getDir; // Make the new dir the target
113 targetDirectory->recList.push_back(rec);
116 ULONG RecMan::getTotalSpace()
121 ULONG RecMan::getFreeSpace()
126 ULONG RecMan::getUsedPercent()
131 int RecMan::deleteRecording(Recording* rec)
135 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
139 success = VDR::getInstance()->deleteRecording(rec->getFileName());
142 currentDir->recList.erase(i);
152 void RecMan::constructPath(char* target, Directory* dir)
156 constructPath(target, dir->parent);
157 strcat(target, dir->name);
162 int RecMan::moveRecording(Recording* toMove, Directory* toDir)
164 char newPath[PATH_MAX];
165 strcpy(newPath, "~");
166 constructPath(&newPath[1], toDir);
169 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
173 char* newFileName = VDR::getInstance()->moveRecording(toMove->getFileName(), newPath);
178 toMove->setFileName(newFileName);
179 delete[] newFileName;
181 currentDir->recList.erase(i);
182 toDir->recList.push_back(toMove);
183 toDir->sort(chronoSortOrder);
193 bool RecMan::isSubDir()
195 return (currentDir != rootDir);
198 bool RecMan::down(Directory* downDir)
200 // Check dir is in currentDir
201 for(DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
205 currentDir = downDir;
214 if (!isSubDir()) return false;
216 Directory* oldDir = currentDir;
217 currentDir = currentDir->parent;
219 if (oldDir->getNumRecordings() == 0)
223 for (DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
226 if (tempdir == oldDir)
228 currentDir->dirList.erase(i);
238 char* RecMan::getCurDirName()
240 return currentDir->name;
243 DirectoryList* RecMan::getDirectories()
245 return ¤tDir->dirList;
248 RecordingList* RecMan::getRecordings()
250 return ¤tDir->recList;
253 Directory* RecMan::getRootDir()
258 void RecMan::setSortOrderChron()
260 chronoSortOrder = true;
263 void RecMan::toggleSortOrder()
265 chronoSortOrder = !chronoSortOrder;
270 Log::getInstance()->log("RecMan", Log::DEBUG, "Sort");
271 rootDir->sort(chronoSortOrder);