summaryrefslogtreecommitdiffstats
path: root/src/gui/processesStartDialog.cpp
blob: e0a62862b654cfcc13888ebe3ec4a6af96f6ce2f (plain) (blame)
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
/*
# 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/
# -----------------------------------------------------------------------------
# processesStartDialog.cpp
	Dialog to get process to send to clients
# -----------------------------------------------------------------------------
*/

#include "processesStartDialog.h"
#include "ui_processesStartDialog.h"
#include <src/gui/mainWindow.h>

ProcessesStartDialog::ProcessesStartDialog(QWidget *parent) :
    QDialog(parent),
    procStartUi(new Ui::ProcessesStartDialog)
{
	procStartUi->setupUi(this);
    connect( procStartUi->sendButton, SIGNAL( clicked()), this, SLOT( send()));
    connect( procStartUi->cancelButton, SIGNAL( clicked()), this, SLOT( notSend()));
    connect( procStartUi->saveButton, SIGNAL( clicked()), this, SLOT ( save()));

    //if we click or double click one of our items we put it in our message
    connect( procStartUi->processesList, SIGNAL( cellDoubleClicked(int,int)), this, SLOT ( itemClicked(int,int)));
    connect( procStartUi->processesList, SIGNAL( cellClicked(int,int)), this, SLOT ( itemClicked(int,int)));

    listProcesses();
}

ProcessesStartDialog::~ProcessesStartDialog()
{
	//
}

void ProcessesStartDialog::send()
{
	QString procd = procStartUi->message->text();
	save(); //save (if we made changes to our list)
	if (procd.length()>0)
	{
		QMessageBox::StandardButton start = QMessageBox::question(0,
				tr("PVS Start Process"), tr("Do you want to start the process: ") + procd +
				tr(" on the selected Clients?"),
				QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);

		if (start == QMessageBox::Ok)
		{
			//write name of process to setProcessesDialog
			MainWindow::getWindow()->setProcessesDialog(procd);
			procStartUi->message->clear();
			emit accept();
		}
	}
}

void ProcessesStartDialog::notSend()
{
	procStartUi->message->clear();
	emit reject();
}

void ProcessesStartDialog::listProcesses()
{
	/*settings.beginWriteArray("RemoteProcessesList");
	settings.setArrayIndex(0);
	settings.setValue("command", "oowriter");
	settings.setValue("description", "Open Office Writer");
	settings.setArrayIndex(1);
	settings.setValue("command", "oocalc");
	settings.setValue("description", "Open Office Calc");
	settings.endArray();*/

	//read from settings
	int size = settings.beginReadArray("RemoteProcessesList");
	for (int i = 0; i < size; ++i)
	{
		settings.setArrayIndex(i);
		procStartUi->processesList->setRowCount(i+1);
		procStartUi->processesList->setItem(i, 0, new QTableWidgetItem(settings.value("command").toString(),0));
		procStartUi->processesList->setItem(i, 1, new QTableWidgetItem(settings.value("description").toString(),0));
	}
	settings.endArray();

	//add empty items to our List
	QString empty = " ";
	procStartUi->processesList->setRowCount(procStartUi->processesList->rowCount()+1);
	procStartUi->processesList->setItem(procStartUi->processesList->rowCount()-1, 0, new QTableWidgetItem(empty,0));
	procStartUi->processesList->setItem(procStartUi->processesList->rowCount()-1, 1, new QTableWidgetItem(empty,0));
}

void ProcessesStartDialog::save()
{
	//if we delete items from our list we increment our decrement - to decrement our arrayindex
	int decrement = 0;

	// if both our last elements are empty dont read them
	// we need this if we have added new elements
	if ((procStartUi->processesList->item(procStartUi->processesList->rowCount()-1, 0) != 0) &&
					(procStartUi->processesList->item(procStartUi->processesList->rowCount()-1, 1) != 0))
	{
		settings.beginWriteArray("RemoteProcessesList");
		for (int i = 0; i < procStartUi->processesList->rowCount(); ++i)
		{
			//if elements are only whitespaces we ignore them
			if ((procStartUi->processesList->item(i, 0)->text().remove(QRegExp("\\s"))  != "") &&
					(procStartUi->processesList->item(i, 1)->text().remove(QRegExp("\\s"))  != ""))
			{
				settings.setArrayIndex(i-decrement);
				settings.setValue("command", procStartUi->processesList->item(i, 0)->text());
				settings.setValue("description", procStartUi->processesList->item(i, 1)->text());
			} else decrement++; //and increment our decrement
		}
		settings.endArray();
	}
	else
	{
		settings.beginWriteArray("RemoteProcessesList");
		for (int i = 0; i < procStartUi->processesList->rowCount()-1; ++i)
		{
			if ((procStartUi->processesList->item(i, 0)->text().remove(QRegExp("\\s")) != "") &&
					(procStartUi->processesList->item(i, 1)->text().remove(QRegExp("\\s"))  != ""))
			{
				settings.setArrayIndex(i-decrement);
				settings.setValue("command", procStartUi->processesList->item(i, 0)->text());
				settings.setValue("description", procStartUi->processesList->item(i, 1)->text());
			} else decrement++;
		}
		settings.endArray();
	}
	listProcesses();
}

void ProcessesStartDialog::itemClicked(int row, int column)
{
	//if last item exists we put it in our message
	if (procStartUi->processesList->item(row, 0) != 0)
		procStartUi->message->setText(procStartUi->processesList->item(row, 0)->text());
}