1515#include < QDir>
1616#include < cmath>
1717#include < cstdlib>
18+ #include < QObject>
19+ #include < QProcess>
20+ #include < QTableWidget>
21+ #include < QTableWidgetItem>
22+ #include < QJsonObject>
23+ #include < QJsonArray>
24+ #include < QJsonDocument>
1825
1926
2027LTM::LTM (QWidget *parent)
@@ -29,6 +36,15 @@ LTM::LTM(QWidget *parent)
2936 connect (ui->actionInfo ,&QAction::triggered,this , <M::printInfo);
3037
3138
39+ // Setup headers once
40+ ui->systemdTable ->setColumnCount (5 );
41+ ui->systemdTable ->setHorizontalHeaderLabels ({" UNIT" , " LOAD" , " ACTIVE" , " SUB" , " DESCRIPTION" });
42+ ui->systemdTable ->horizontalHeader ()->setSectionResizeMode (QHeaderView::Stretch);
43+ connect (&serviceUpdater, &QTimer::timeout, this , <M::load_services);
44+ serviceUpdater.setInterval (1000 );
45+ serviceUpdater.start ();
46+
47+
3248
3349 // setting up plots
3450 try {
@@ -246,7 +262,8 @@ void LTM::printInfo()
246262 ui->tabWidget ->setCurrentIndex (0 );
247263
248264 ui->updateText ->appendPlainText (" Authored by Juergen Kratochwill 2020" );
249- ui->updateText ->appendPlainText (" Published under GPLv3" );
265+ ui->updateText ->appendPlainText (" Version 3.1.0" );
266+ ui->updateText ->appendPlainText (" Published under GPLv3, no liabilites or whatsover are taken" );
250267 ui->updateText ->appendPlainText (" All Linux and QT related Licesing info can be accesed under: " );
251268 QDir license (qApp->applicationDirPath ());
252269 license.cdUp ();
@@ -389,3 +406,42 @@ void LTM::on_butKillProcess_clicked()
389406 QString terminateID = ui->tableWProcess ->selectedItems ()[0 ]->data (Qt::DisplayRole).toString ();
390407 system ((std::string (" kill -9 " )+ terminateID.toStdString ()).c_str ());
391408}
409+
410+ void LTM::load_services () {
411+ QProcess process;
412+ process.start (" systemctl" , {" list-units" , " --type=service" , " --all" , " --no-pager" , " --output=json" });
413+ if (!process.waitForFinished (5000 )) {
414+ // handle error
415+ return ;
416+ }
417+
418+ QByteArray jsonOutput = process.readAllStandardOutput ();
419+ QJsonDocument doc = QJsonDocument::fromJson (jsonOutput);
420+
421+ if (!doc.isArray ()) return ;
422+
423+ QJsonArray array = doc.array ();
424+ ui->systemdTable ->clearContents ();
425+ ui->systemdTable ->setRowCount (array.size ());
426+
427+ int row = 0 ;
428+ for (const QJsonValue& val : array) {
429+ if (!val.isObject ()) continue ;
430+ QJsonObject obj = val.toObject ();
431+
432+ QString unit = obj[" unit" ].toString ();
433+ QString load = obj[" load" ].toString ();
434+ QString active = obj[" active" ].toString ();
435+ QString sub = obj[" sub" ].toString ();
436+ QString description = obj[" description" ].toString ();
437+
438+ ui->systemdTable ->setItem (row, 0 , new QTableWidgetItem (unit));
439+ ui->systemdTable ->setItem (row, 1 , new QTableWidgetItem (load));
440+ ui->systemdTable ->setItem (row, 2 , new QTableWidgetItem (active));
441+ ui->systemdTable ->setItem (row, 3 , new QTableWidgetItem (sub));
442+ ui->systemdTable ->setItem (row, 4 , new QTableWidgetItem (description));
443+ row++;
444+ }
445+
446+ ui->systemdTable ->setRowCount (row); // In case some rows were skipped
447+ }
0 commit comments