Changeset View
Changeset View
Standalone View
Standalone View
src/lib/util/blockingapp.cpp
- This file was added.
1 | #include "blockingapp.h" | ||||
---|---|---|---|---|---|
2 | | ||||
3 | #include <QString> | ||||
4 | #include <QProcess> | ||||
5 | #include <QStringList> | ||||
6 | #include <QRegularExpression> | ||||
7 | | ||||
8 | #include "kprocesslist.h" | ||||
9 | | ||||
10 | void BlockingApp::queryBlockingApps(const QString &devicePath) | ||||
11 | { | ||||
12 | QProcess *p = new QProcess; | ||||
13 | | ||||
14 | connect(p, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error), [=](QProcess::ProcessError) { | ||||
15 | emit blockingAppsReady({}); | ||||
16 | p->deleteLater(); | ||||
17 | }); | ||||
18 | | ||||
19 | connect(p, static_cast<void (QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), [=](int /* exitCode */, | ||||
20 | QProcess::ExitStatus /* status*/) { | ||||
21 | QStringList blockApps; | ||||
22 | | ||||
23 | const QString out = QString::fromStdString(p->readAll().toStdString()); | ||||
24 | const QStringList &pidList = out.split(QRegularExpression(QStringLiteral("\\s+")), QString::SkipEmptyParts); | ||||
25 | | ||||
26 | const KProcessList::KProcessInfoList procs = KProcessList::processInfoList(); | ||||
27 | | ||||
28 | QString processName; | ||||
29 | for (const QString &pidStr : pidList) { | ||||
30 | int pid = pidStr.toInt(); | ||||
31 | if (!pid) { | ||||
32 | continue; | ||||
33 | } | ||||
34 | for (const KProcessList::KProcessInfo &proc : procs) { | ||||
35 | if (proc.pid() == pid) { | ||||
36 | processName = proc.name(); | ||||
37 | break; | ||||
38 | } | ||||
39 | } | ||||
40 | if (!blockApps.contains(processName)) { | ||||
41 | blockApps << processName; | ||||
42 | } | ||||
43 | } | ||||
44 | blockApps.removeDuplicates(); | ||||
45 | emit blockingAppsReady(blockApps); | ||||
46 | p->deleteLater(); | ||||
47 | }); | ||||
48 | p->start(QStringLiteral("lsof"), {QStringLiteral("-t"), devicePath}); | ||||
49 | // p.start(QStringLiteral("fuser"), {QStringLiteral("-m"), devicePath}); | ||||
50 | } | ||||
51 | | ||||
52 | | ||||
53 | #include "moc_blockingapp.cpp" |