Add utility isATBQTRunning().

This commit is contained in:
Gerhard Hoffmann 2023-09-09 14:33:13 +02:00
parent ba71728979
commit 276d65a9d8
2 changed files with 32 additions and 0 deletions

View File

@ -7,6 +7,8 @@
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QDir>
#include <QDirIterator>
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;
}

View File

@ -22,6 +22,7 @@ namespace Utils {
QString getParentName();
bool isATBQTRunning();
}
#endif // UTILS_H_INCLUDED