From 276d65a9d8d34dc0b33e3ee4c9ca2c569fe37076 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Sat, 9 Sep 2023 14:33:13 +0200 Subject: [PATCH] Add utility isATBQTRunning(). --- utils.cpp | 31 +++++++++++++++++++++++++++++++ utils.h | 1 + 2 files changed, 32 insertions(+) diff --git a/utils.cpp b/utils.cpp index 7640bf3..5496bee 100644 --- a/utils.cpp +++ b/utils.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include int Utils::read1stLineOfFile(QString fileName) { QFile f(fileName); @@ -193,3 +195,32 @@ QString Utils::getParentName() { // get name of parent process } return ""; } + +bool Utils::isATBQTRunning() { + QDirIterator it("/proc", + QStringList() << "status", + QDir::Files, + QDirIterator::Subdirectories); + while (it.hasNext()) { + QString const &nextStatusFile = it.next(); + QFile f(nextStatusFile); + 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") { + if (line[1].trimmed() == "ATBQT") { + return true; + } + } + } + } + } + } + } + return false; +} diff --git a/utils.h b/utils.h index 62f2c38..6dd7dd7 100644 --- a/utils.h +++ b/utils.h @@ -22,6 +22,7 @@ namespace Utils { QString getParentName(); + bool isATBQTRunning(); } #endif // UTILS_H_INCLUDED