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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/*
# Copyright (c) 2010 - OpenSLX Project, Computer Center University of Freiburg
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# processWidget.cpp
Widget to start/stop processes on a client. This widget is used in
processesDialog.cpp as a tab in the QTabWidget
# -----------------------------------------------------------------------------
*/
#include "processesDialog.h"
#include "processWidget.h"
#include "ui_processWidget.h"
ProcessWidget::ProcessWidget(QWidget *parent, PVSClient *cl):
QWidget(parent),
prowui(new Ui::ProcessWidget)
{
prowui->setupUi(this);
filter = filterSettings.value("RemoteProcessesList/filter").toString();
if (filter == "")
{
filterSettings.setValue("RemoteProcessesList/filter", "pvs pvsgui x11vnc dbus-launch dbus-daemon");
filter = "pvs pvsgui x11vnc dbus-launch dbus-daemon";
}
client = cl;
connect( prowui->startButton, SIGNAL( clicked()), this, SLOT( startProcess()));
connect( prowui->refreshButton, SIGNAL( clicked()), this, SLOT( resendProcessList()));
connect( prowui->stopButton, SIGNAL( clicked()), this, SLOT( stopProcess()));
connect( client, SIGNAL( processVectorReady(bool)), this, SLOT( refrProcessList()));
//tell client we want to see his processes
sendCommand("SHOWPROCESSES", filter);
}
void ProcessWidget::startProcess()
{
QMessageBox::StandardButton start = QMessageBox::question(0,
tr("PVS Start Process"), tr("Do you want to start the process: ") + prowui->processLineEdit->text() +
tr(" on this Client?"),
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
if (start == QMessageBox::Ok)
{
sendCommand("STARTPROCESS", prowui->processLineEdit->text());
sendCommand("SHOWPROCESSES", filter);
}
prowui->processLineEdit->clear();
}
void ProcessWidget::resendProcessList()
{
sendCommand("SHOWPROCESSES", filter);
}
void ProcessWidget::refrProcessList(bool timerEvent)
{
if (timerEvent)
{
if (prowui->processTable->selectedItems().length() > 0)
return;
else
{
resendProcessList();
return;
}
}
//remove every item of our list
for(int i=prowui->processTable->rowCount(); i == 0; i--)
{
prowui->processTable->removeRow(i);
}
prowui->processTable->setRowCount(0);
//read every entry of the vector - split it - and put it to the list
QVector<QString> processes = client->getProcessesVector();
for (int i=0; i<processes.size(); i++)
{
prowui->processTable->setRowCount(i+1);
QStringList processesList = processes.at(i).split(QRegExp("<#>"));
for (int j=0; j<processesList.size()&&j<3; j++)
{
prowui->processTable->setItem(i,j,new QTableWidgetItem(processesList.at(j),0));
}
}
}
void ProcessWidget::stopProcess()
{
if (prowui->processTable->rowCount() > 0)
{
//get a list of all selected items
QList<QTableWidgetItem *> selectedItems = prowui->processTable->selectedItems();
QList<int> rows;
for (int i=0;i<selectedItems.length();i++)
{
//only add rows one time
if (rows.indexOf(selectedItems.at(i)->row()) < 0)
rows.append(selectedItems.at(i)->row());
}
//append names of processes
QString processesMessage = "";
for (int i=0;i<rows.size();i++)
{
if (i==0)
processesMessage.append(QString(tr(" ")));
else
processesMessage.append(QString(tr(",")));
processesMessage.append(prowui->processTable->item(rows.at(i),1)->text());
processesMessage.append(QString(tr(" ")));
}
QMessageBox::StandardButton start = QMessageBox::question(0,
tr("PVS Start Process"), tr("Do you want to stop the process(es):") + processesMessage +
tr("on this Client?"),
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
if (start == QMessageBox::Ok)
{
//send KILLPROCESS for every row
for (int i=0;i<rows.size();i++)
{
sendCommand("KILLPROCESS", prowui->processTable->item(rows.at(i),0)->text());
}
}
//tell client to update his list
sendCommand("SHOWPROCESSES", filter);
}
}
void ProcessWidget::sendCommand(QString ident, QString message)
{
client->sendMessage(PVSCOMMAND, ident, message);
}
ProcessWidget::~ProcessWidget()
{
delete prowui;
}
|