- Handle paths with (~, ., ..) properly

This commit is contained in:
Christophe Dumez 2009-12-22 10:29:39 +00:00
parent c334439df6
commit 50e620daf2
5 changed files with 67 additions and 33 deletions

View file

@ -317,6 +317,23 @@ public:
return QDateTime::fromTime_t(mktime(&tm)).toString(Qt::DefaultLocaleLongDate);
}
// Replace ~ in path
static QString expandPath(QString path) {
path = path.trimmed();
if(path.isEmpty()) return path;
if(path.length() == 1) {
if(path[0] == '~' ) return QDir::homePath();
}
if(path[0] == '~' && path[1] == QDir::separator()) {
path = path.replace(0, 1, QDir::homePath());
} else {
if(QDir::isAbsolutePath(path)) {
path = QDir(path).absolutePath();
}
}
return QDir::cleanPath(path);
}
// Take a number of seconds and return an user-friendly
// time duration like "1d 2h 10m".
static QString userFriendlyDuration(qlonglong seconds) {