1 #include <QtGui/QApplication>
2 #include <QtGui/QMainWindow>
3 #include <Qt3Support/q3multilineedit.h>
4 #include <QtGui/QMenuBar>
5 // #include <qpopmenu.h>
6 #include <QtGui/QDialog>
7 #include <QtGui/QButtonGroup>
8 #include <QtGui/QLabel>
9 #include <QtGui/QLineEdit>
10 #include <Qt3Support/Q3ListBox>
11 #include <QtGui/QPushButton>
12 #include <QtGui/QRadioButton>
13 #include <QtCore/QList>
14 #include <QtCore/qfile.h>
15 #include <QtGui/qcombobox.h>
16 #include <QtGui/QToolTip>
17 #include <QtGui/QFont>
18 #include <QtGui/QPixmap>
19 #include <QtGui/QMessageBox>
24 #include <libconfig.h>
37 bool QInstall::check_id(int id)
40 QListIterator<VLPEntry *> nodesIterator(Nodes);
42 while (nodesIterator.hasNext()) {
43 pom = nodesIterator.next();
50 bool QInstall::check_addr(char *addr)
53 QListIterator<VLPEntry *> nodesIterator(Nodes);
55 while (nodesIterator.hasNext()) {
56 pom = nodesIterator.next();
57 if (strcmp(pom->addr, addr) == 0)
63 void QInstall::AddNode()
67 QLineEdit *id, *addr, *progs, *home;
68 QPushButton *okbtn, *cancelbtn;
72 tmpQLabel = new QLabel(&dlg);
73 tmpQLabel->setGeometry(110, 10, 180, 30);
74 tmpQLabel->setFrameStyle(49);
75 tmpQLabel->setText("Virtual Processor Properties");
77 id = new QLineEdit(&dlg);
78 id->setGeometry(130, 50, 50, 30);
81 tmpQLabel = new QLabel(&dlg);
82 tmpQLabel->setGeometry(20, 50, 90, 30);
83 tmpQLabel->setText("Node number");
85 tmpQLabel = new QLabel(&dlg);
86 tmpQLabel->setGeometry(20, 90, 80, 30);
87 tmpQLabel->setText("IP Address");
89 addr = new QLineEdit(&dlg);
90 addr->setGeometry(130, 90, 120, 30);
93 tmpQLabel = new QLabel(&dlg);
94 tmpQLabel->setGeometry(20, 130, 100, 30);
95 tmpQLabel->setText("Connection type");
97 QComboBox* tmpQComboBox;
98 tmpQComboBox = new QComboBox(&dlg);
99 tmpQComboBox->setGeometry(130, 130, 100, 30);
100 tmpQComboBox->insertItem(0, "Explicit");
102 tmpQLabel = new QLabel(&dlg);
103 tmpQLabel->setGeometry(20, 170, 110, 30);
104 tmpQLabel->setText("Programs directory");
106 progs = new QLineEdit(&dlg);
107 progs->setGeometry(130, 170, 230, 30);
110 tmpQLabel = new QLabel(&dlg);
111 tmpQLabel->setGeometry(20, 210, 100, 30);
112 tmpQLabel->setText("VLP directory");
114 home = new QLineEdit(&dlg);
115 home->setGeometry(130, 210, 230, 30);
118 okbtn = new QPushButton(&dlg);
119 okbtn->setGeometry(80, 250, 100, 30);
120 okbtn->setText("Ok");
121 connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
122 cancelbtn = new QPushButton(&dlg);
123 cancelbtn->setGeometry(210, 250, 100, 30);
124 cancelbtn->setText("Cancel");
125 connect(cancelbtn,SIGNAL(clicked()), &dlg, SLOT(reject()));
126 dlg.resize(380, 300);
129 pom->ID = id->text().toInt();
130 if (check_id(pom->ID)) {
131 strcpy(pom->addr, addr->text().toStdString().c_str());
132 if (check_addr(pom->addr)) {
133 if (tmpQComboBox->currentText() == "Explicit") {
136 strcpy(pom->progdir, progs->text().toStdString().c_str());
137 strcpy(pom->homedir, home->text().toStdString().c_str());
139 sprintf(pomstr, "Node: %d\t"
141 "Home dir: %s", pom->ID, pom->addr, pom->homedir);
142 nodelist->insertItem(pomstr);
143 strcpy(pom->item, pomstr);
145 QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", "Ok");
148 QMessageBox::warning(this, "Error!", "ID must be unique!", "Ok");
153 void QInstall::DelNode()
158 if (nodelist->currentItem() >= 0) {
159 strcpy(pom, nodelist->text(nodelist->currentItem()).toStdString().c_str());
161 QListIterator<VLPEntry *> nodesIterator(Nodes);
163 while (nodesIterator.hasNext()) {
164 vpom = nodesIterator.next();
165 if (strcmp(pom, vpom->item) == 0)
169 if (QMessageBox::question(this, "Delete VLP", "Are you sure?", "Yes", "No")) {
170 nodelist->removeItem(nodelist->currentItem());
171 Nodes.removeOne(vpom);
176 void QInstall::on_actionConfigure_triggered()
180 QPushButton *addbtn, *delbtn, *okbtn, *cancelbtn;
185 //dlg.setStyle(WindowsStyle);
186 nodelist = new Q3ListBox(&dlg);
187 nodelist->setGeometry(20, 40, 480, 160);
189 tmpQLabel = new QLabel(&dlg);
190 tmpQLabel->setGeometry(20, 10, 100, 30);
191 tmpQLabel->setText("Nodes:");
193 addbtn = new QPushButton(&dlg);
194 addbtn->setGeometry(30, 210, 100, 30);
195 addbtn->setText("Add VLP");
196 connect(addbtn, SIGNAL(clicked()), this, SLOT(AddNode()));
198 delbtn = new QPushButton(&dlg);
199 delbtn->setGeometry(150, 210, 100, 30);
200 delbtn->setText("Del VLP");
201 connect(delbtn, SIGNAL(clicked()), this, SLOT(DelNode()));
203 okbtn = new QPushButton(&dlg);
204 okbtn->setGeometry(270, 210, 100, 30);
205 okbtn->setText("Save files");
206 connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
208 cancelbtn = new QPushButton(&dlg);
209 cancelbtn->setGeometry(390, 210, 100, 30);
210 cancelbtn->setText("Cancel");
211 connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
213 dlg.resize(520, 260);
216 if (!Nodes.isEmpty()) {
217 QListIterator<VLPEntry *> nodesIterator(Nodes);
219 while (nodesIterator.hasNext()) {
220 pom = nodesIterator.next();
221 i = Nodes.indexOf(pom);
222 sprintf(pomstr, "%s.cfg", pom->addr);
225 config_setting_t *root, *setting;
228 root = config_root_setting(&cfg);
230 setting = config_setting_get_member(root, "progdir");
232 setting = config_setting_add(root, "progdir", CONFIG_TYPE_STRING);
234 config_setting_set_string(setting, pom->progdir);
236 setting = config_setting_get_member(root, "homedir");
238 setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
240 config_setting_set_string(setting, pom->homedir);
242 setting = config_setting_get_member(root, "node_number");
244 setting = config_setting_add(root, "node_number", CONFIG_TYPE_INT);
246 config_setting_set_int(setting, pom->ID);
248 if (pom->type == 0) {
249 setting = config_setting_get_member(root, "type");
251 setting = config_setting_add(root, "type", CONFIG_TYPE_STRING);
253 config_setting_set_string(setting, "explicit");
255 for (auto node : Nodes) {
257 setting = config_setting_get_member(root, "host");
259 setting = config_setting_add(root, "host", CONFIG_TYPE_STRING);
261 config_setting_set_string(setting, node->addr);
265 if(!config_write_file(&cfg, pomstr)) {
266 fprintf(stderr, "Error while writing to file: %s.\n", pomstr);
268 config_destroy(&cfg);
277 void QInstall::on_actionQuit_triggered()
279 QApplication::instance()->quit();
283 int main(int argc, char **argv)
285 app = new QApplication(argc,argv);