summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Eefting <edwin@datux.nl>2011-09-24 23:22:17 (GMT)
committer Edwin Eefting <edwin@datux.nl>2011-09-24 23:22:17 (GMT)
commit61420d7fc2f9d7569b8cd90e494d7507d6c0dfd0 (patch)
treeee153888de76006a746e3b89b5f3c1897829950a
parentd2c79eacf4eb4a071d9c8ba910247ed7c25f0d0a (diff)
fixed the playlist traverser. it finally seems to work correctly under all circumstances
-rw-r--r--modules/pl.module/module.cpp119
1 files changed, 67 insertions, 52 deletions
diff --git a/modules/pl.module/module.cpp b/modules/pl.module/module.cpp
index 8122e9d..8da9ee5 100644
--- a/modules/pl.module/module.cpp
+++ b/modules/pl.module/module.cpp
@@ -217,8 +217,8 @@ namespace pl
//rootPath is the highest path, it can never be escaped.
path movePath(path rootPath, path currentPath, string sortField, Edirection direction, Erecursion recursion, CsortedDir::Efiletype filetype)
{
- DEB("rootpath:" << rootPath);
- DEB("currentpath:" << currentPath);
+// DEB("rootpath:" << rootPath);
+// DEB("currentpath:" << currentPath);
//determine the path we should get the initial listing of:
path listPath;
@@ -227,7 +227,7 @@ namespace pl
else
listPath=currentPath.parent_path();
- path startPath=listPath;
+ path startPath=currentPath;
CsortedDir::iterator dirI;
do
@@ -235,78 +235,93 @@ namespace pl
//get sorted directory listing
CsortedDir sortedDir(listPath, sortField, filetype);
- //try to find the current path:
- if (!currentPath.empty())
- dirI=find(sortedDir.begin(), sortedDir.end(), currentPath.filename());
- else
- dirI=sortedDir.end();
-
- //currentPath not found?
- if (dirI==sortedDir.end())
+ if (!sortedDir.empty())
{
- //start at the first or last entry depending on direction
- if (direction==NEXT)
- dirI=sortedDir.begin();
+
+ //try to find the current path:
+ if (!currentPath.empty())
+ dirI=find(sortedDir.begin(), sortedDir.end(), currentPath.filename());
else
- {
dirI=sortedDir.end();
- dirI--;
- }
- }
- else
- {
- //move one step in the correct direction
- if (direction==NEXT)
+
+ //currentPath not found?
+ if (dirI==sortedDir.end())
{
- dirI++;
+ //start at the first or last entry depending on direction
+ if (direction==NEXT)
+ dirI=sortedDir.begin();
+ else
+ {
+ dirI=sortedDir.end();
+ dirI--;
+ }
}
- //PREVIOUS:
else
{
- if (dirI==sortedDir.begin())
- dirI=sortedDir.end();
+ //move one step in the correct direction
+ if (direction==NEXT)
+ {
+ dirI++;
+ }
+ //PREVIOUS:
else
- dirI--;
+ {
+ if (dirI==sortedDir.begin())
+ dirI=sortedDir.end();
+ else
+ dirI--;
+ }
}
- }
- //top or bottom was reached
- if (dirI==sortedDir.end())
- {
- //can we one dir higher?
- if (recursion==RECURSE && listPath!=rootPath)
+ //top or bottom was reached
+ if (dirI==sortedDir.end())
{
- //yes, so go one dir higher and continue the loop
- currentPath=listPath;
- listPath=currentPath.parent_path();
+ //can we one dir higher?
+ if (recursion==RECURSE && listPath!=rootPath)
+ {
+ //yes, so go one dir higher and continue the loop
+ currentPath=listPath;
+ listPath=currentPath.parent_path();
+ }
+ else
+ {
+ //no, cant go higher.
+ //clear the current path, so it just gets the first or last entry
+ currentPath.clear();
+ }
}
+ //we found something
else
{
- //no, cant go higher.
- //clear the current path, so it just gets the first or last entry
- currentPath.clear();
+ //should we recurse?
+ if (recursion==RECURSE && is_directory(listPath/(*dirI)))
+ {
+ //enter it
+ listPath=listPath/(*dirI);
+ currentPath.clear();
+ }
+ else
+ {
+ //return the new path
+ return (listPath/(*dirI));
+ }
}
}
- //we found something
else
{
- //should we recurse?
- if (recursion==RECURSE && is_directory(listPath/(*dirI)))
- {
- //enter it
- listPath=listPath/(*dirI);
- currentPath.clear();
- }
- else
+ //list is empty, our last chance is to go one dir higher, otherwise we will exit the loop:
+ if (recursion==RECURSE && listPath!=rootPath)
{
- return (listPath/(*dirI));
+ //go one dir higher and continue the loop
+ currentPath=listPath;
+ listPath=currentPath.parent_path();
}
}
- DEB(listPath << " en " << startPath);
+
}
- while(listPath!=startPath);
+ while(currentPath!=startPath);
- //not found, return currentpath
+ //nothing found, just return currentPath
return(currentPath);
}