summaryrefslogblamecommitdiffstats
path: root/src/gui/processWidget.cpp
blob: df865a44156d08f4ad79447c12c4ab47c61e28ae (plain) (tree)
























                                                                               
 
 
                              
                                                                               
 





                                                                                                                   


                                                                                       
                                                                                          


                                                                                        
                                              
                                         





                                                                                                                 
                                   




                                                                     
                                             



                                     

                                       
                                             

 
                                                    
 










                                                                       
                                       




                                                                
 

                                                                            








                                                                                                       





                                                 

































                                                                                                                            
                                                     











                                                               
/*
# 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;
}