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(bool isNew, ULONG startTime, char* name, char* fileName)
52 Recording* rec = new Recording();
54 rec->setStartTime(startTime);
55 rec->setFileName(fileName);
57 // And now for the directory structure & prog name
61 stack<char*> dirNamesStack;
63 bool gotProgName = false;
64 for(c = (name + strlen(name) - 1); c >= name; c--)
66 if ((*c == '~') || (c == name))
68 // Make d point to the start of the string (i.e. move on 1 from ~ if necessary)
69 if (c == name) d = name;
74 rec->setProgName(d); // will copy from d to end of string
81 oneDirName = new char[strlen(d) + 1];
82 strcpy(oneDirName, d);
83 dirNamesStack.push(oneDirName);
89 Directory* targetDirectory = rootDir;
92 while(!dirNamesStack.empty())
94 oneDirName = dirNamesStack.top();
95 if (!oneDirName) break;
97 getDir = targetDirectory->getDirByName(oneDirName);
100 targetDirectory = getDir;
104 getDir = new Directory(oneDirName); // Make a new directory
105 getDir->parent = targetDirectory;
106 targetDirectory->dirList.push_back(getDir); // Put the new directory in the tree
107 targetDirectory = getDir; // Make the new dir the target
114 targetDirectory->recList.push_back(rec);
117 ULONG RecMan::getTotalSpace()
122 ULONG RecMan::getFreeSpace()
127 ULONG RecMan::getUsedPercent()
132 int RecMan::deleteRecording(Recording* rec)
136 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
140 success = VDR::getInstance()->deleteRecording(rec->getFileName());
143 currentDir->recList.erase(i);
153 void RecMan::constructPath(char* target, Directory* dir)
157 constructPath(target, dir->parent);
158 strcat(target, dir->name);
163 int RecMan::moveRecording(Recording* toMove, Directory* toDir)
165 char newPath[PATH_MAX];
166 strcpy(newPath, "~");
167 constructPath(&newPath[1], toDir);
170 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
174 char* newFileName = VDR::getInstance()->moveRecording(toMove->getFileName(), newPath);
179 toMove->setFileName(newFileName);
180 delete[] newFileName;
182 currentDir->recList.erase(i);
183 toDir->recList.push_back(toMove);
184 toDir->sort(chronoSortOrder);
194 bool RecMan::isSubDir()
196 return (currentDir != rootDir);
199 bool RecMan::down(Directory* downDir)
201 // Check dir is in currentDir
202 for(DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
206 currentDir = downDir;
215 if (!isSubDir()) return false;
217 Directory* oldDir = currentDir;
218 currentDir = currentDir->parent;
220 if (oldDir->getNumRecordings() == 0)
224 for (DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
227 if (tempdir == oldDir)
229 currentDir->dirList.erase(i);
239 char* RecMan::getCurDirName()
241 return currentDir->name;
244 DirectoryList* RecMan::getDirectories()
246 return ¤tDir->dirList;
249 RecordingList* RecMan::getRecordings()
251 return ¤tDir->recList;
254 Directory* RecMan::getRootDir()
259 void RecMan::setSortOrderChron()
261 chronoSortOrder = true;
264 void RecMan::toggleSortOrder()
266 chronoSortOrder = !chronoSortOrder;
271 Log::getInstance()->log("RecMan", Log::DEBUG, "Sort");
272 rootDir->sort(chronoSortOrder);