Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Minimise non-portable code.
  • Loading branch information
rburchell committed Feb 18, 2012
1 parent cfc5833 commit c3d6d5c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions main.cpp
Expand Up @@ -308,22 +308,27 @@ class Utils : public QObject
Q_INVOKABLE static QStringList pathsToHome()
{
QStringList paths;

#ifdef Q_OS_UNIX
QByteArray rawPathToHome = qgetenv("HOME");
QString pathToHome = QFile::decodeName(rawPathToHome);
QString pathToHome = QDir::homePath();
QDir tmp;

if (pathToHome.isEmpty() || !tmp.exists(pathToHome)) {
qWarning() << Q_FUNC_INFO << "Home path empty or nonexistent: " << rawPathToHome;
qWarning() << Q_FUNC_INFO << "Home path empty or nonexistent: " << pathToHome;
#ifdef Q_OS_UNIX
pathToHome = QLatin1String("/");
#else
#error "only ported to UNIX at present"
#endif
}

QDir d(pathToHome);

if (!d.isReadable()) {
qWarning() << Q_FUNC_INFO << "Home path " << pathToHome << " not readable";
#ifdef Q_OS_UNIX
pathToHome = QLatin1String("/");
#else
#error "only ported to UNIX at present"
#endif
d = QDir(pathToHome);

// if / isn't readable, we're all going to die anyway
Expand All @@ -332,9 +337,6 @@ class Utils : public QObject
do {
paths.append(d.path());
} while (d.cdUp());
#else
#error "only ported to UNIX at present"
#endif

// get them in order for QML to instantiate things from
std::reverse(paths.begin(), paths.end());
Expand Down

0 comments on commit c3d6d5c

Please sign in to comment.