Mercurial > hg > easyhg
diff common.cpp @ 79:aaeabc920ca8
* Some work toward doing the Right Thing with each possible combination of existing/nonexisting directories in Open dialog
author | Chris Cannam |
---|---|
date | Mon, 22 Nov 2010 12:30:40 +0000 |
parents | 07405f3a428b |
children | 32fa40c3d174 |
line wrap: on
line diff
--- a/common.cpp Mon Nov 22 10:03:15 2010 +0000 +++ b/common.cpp Mon Nov 22 12:30:40 2010 +0000 @@ -177,3 +177,55 @@ } #endif } + +FolderStatus getFolderStatus(QString path) +{ + QFileInfo fi(path); + if (fi.exists()) { + QDir dir(path); + if (!dir.exists()) { // returns false for files + return FolderIsFile; + } + if (QDir(dir.filePath(".hg")).exists()) { + return FolderHasRepo; + } + return FolderExists; + } else { + QDir parent = fi.dir(); + if (parent.exists()) { + return FolderParentExists; + } + return FolderUnknown; + } +} + +QString getContainingRepoFolder(QString path) +{ + if (getFolderStatus(path) == FolderHasRepo) return ""; + + QFileInfo me(path); + QFileInfo parent(me.dir().absolutePath()); + + while (me != parent) { + QString parentPath = parent.filePath(); + if (getFolderStatus(parentPath) == FolderHasRepo) { + return parentPath; + } + me = parent; + parent = me.dir().absolutePath(); + } + + return ""; +} + +QString xmlEncode(QString s) +{ + s + .replace("&", "&") + .replace("<", "<") + .replace(">", ">") + .replace("\"", """) + .replace("'", "'"); + + return s; +}