-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_tab.cpp
48 lines (44 loc) · 1.56 KB
/
process_tab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <QLabel>
#include <QListWidgetItem>
#include <QVBoxLayout>
#include "process_tab.h"
ProcessTab::ProcessTab(QWidget* parent): QWidget(parent)
{
QLabel* label(new QLabel(tr("Running processes:"), this));
process_list = new QListView(this);
model = new QStandardItemModel(this);
process_list->setModel(model);
QStyledItemDelegate* delegate = new ProcessInfo(process_list);
process_list->setItemDelegate(delegate);
QVBoxLayout* layout(new QVBoxLayout(this));
layout->addWidget(label);
layout->addWidget(process_list);
setLayout(layout);
}
void ProcessTab::add_process(const QString& process_name)
{
QStandardItem* item = new QStandardItem(QIcon(":/icons/download"), QString("<b>" + process_name + "</b><br>Starting..."));
model->appendRow(item);
}
void ProcessTab::update_process(const QString& process_name, const QByteArray& output)
{
if (auto item = model->findItems("<b>" + process_name + "</b>", Qt::MatchStartsWith).first())
{
item->setData(QString("<b>" + process_name + "</b><br>" + QString::fromUtf8(output)), Qt::DisplayRole);
}
else
{
qDebug() << "BUG: feedback from an unlisted process:" << process_name;
}
}
void ProcessTab::finish_process(const QString& process_name, int status)
{
if (auto item = model->findItems("<b>" + process_name + "</b>", Qt::MatchStartsWith).first())
{
item->setData(QIcon(status ? ":/icons/alert" : ":/icons/ok"), Qt::DecorationRole);
}
else
{
qDebug() << "BUG: feedback from an unlisted process:" << process_name;
}
}