diff --git a/utils.cpp b/utils.cpp index ce5cdd4..284c95e 100644 --- a/utils.cpp +++ b/utils.cpp @@ -2,7 +2,10 @@ #include "message_handler.h" #include "git/git_client.h" + +#if defined (Q_OS_UNIX) || defined (Q_OS_LINUX) #include "unistd.h" +#endif #include #include @@ -180,18 +183,15 @@ bool Utils::sameFilesInDirs(QDir const &dir1, QDir const &dir2, QString Utils::getParentName() { // get name of parent process QString ppid = QString("/proc/%1/status").arg(getppid()); - QFile f(ppid); - if (f.exists()) { - if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&f); - in.setCodec("UTF-8"); - while(!in.atEnd()) { - // Name: ATBQT - QStringList line = in.readLine().split(':'); - if (line.size() == 2) { - if (line[0].trimmed() == "Name") { - return line[1].trimmed(); - } + std::ifstream f(ppid.toStdString().c_str()); + if (f.is_open()) { + std::string next; + while (std::getline(f, next)) { + QString line = QString(next.c_str()).simplified(); + if (line.startsWith("Name")) { + int const idx = line.indexOf(QChar(':')); + if (idx != -1) { + return line.mid(idx+1).trimmed(); } } }