mirror of https://github.com/cutefishos/core
Notification support icon
parent
6f9f8406c0
commit
9337102924
@ -0,0 +1,31 @@
|
||||
#include "utils.h"
|
||||
#include <QFile>
|
||||
|
||||
Utils::Utils(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString Utils::processNameFromPid(uint pid)
|
||||
{
|
||||
QFile file(QString("/proc/%1/cmdline").arg(pid));
|
||||
QString name;
|
||||
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QByteArray cmd = file.readAll();
|
||||
|
||||
if (!cmd.isEmpty()) {
|
||||
// extract non-truncated name from cmdline
|
||||
int zeroIndex = cmd.indexOf('\0');
|
||||
int processNameStart = cmd.lastIndexOf('/', zeroIndex);
|
||||
if (processNameStart == -1) {
|
||||
processNameStart = 0;
|
||||
} else {
|
||||
processNameStart++;
|
||||
}
|
||||
name = QString::fromLocal8Bit(cmd.mid(processNameStart, zeroIndex - processNameStart));
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Utils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Utils(QObject *parent = nullptr);
|
||||
|
||||
static QString processNameFromPid(uint pid);
|
||||
};
|
||||
|
||||
#endif // UTILS_H
|
||||
Loading…
Reference in New Issue