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 class QInstall: public QMainWindow {
43 QList<VLPEntry*> Nodes;
47 bool check_addr(char*);
61 QFont f("Helvetica", 12, QFont::Bold);
64 // infob = new QPushButton(this);
66 setWindowTitle("VLP Configuration Tool");
68 QMenu * programMenu = NULL;
69 programMenu = menuBar()->addMenu("&Program");
70 programMenu->addAction("Configure", this, SLOT(SetOptions()));
71 programMenu->addAction("Quit", app, SLOT(quit()));
73 // bar = new QMenuBar(this);
74 // bar->insertItem("Configure", this, SLOT(SetOptions()));
75 // bar->insertItem("Quit", app, SLOT(quit()));
77 // infob->setGeometry(0, bar->height(), 200, 30);
78 if (mp.load("logo.bmp")) {
79 // infob->setPixmap(mp);
80 // infob->resize(mp.width(), mp.height());
82 // resize(infob->width(), infob->height() + bar->height());
86 bool QInstall::check_id(int id)
94 pom = Nodes.takeFirst();
99 bool QInstall::check_addr(char *addr)
104 while (pom != NULL) {
105 if (strcmp(pom->addr, addr) == 0)
107 pom = Nodes.takeFirst();
113 * @attention Currently not in use
115 void QInstall::Info()
119 void QInstall::AddNode()
123 QLineEdit *id, *addr, *progs, *home;
124 QPushButton *okbtn, *cancelbtn;
128 tmpQLabel = new QLabel(&dlg);
129 tmpQLabel->setGeometry(110, 10, 180, 30);
130 tmpQLabel->setFrameStyle(49);
131 tmpQLabel->setText("Virtual Processor Properties");
133 id = new QLineEdit(&dlg);
134 id->setGeometry(130, 50, 50, 30);
137 tmpQLabel = new QLabel(&dlg);
138 tmpQLabel->setGeometry(20, 50, 90, 30);
139 tmpQLabel->setText("Node number");
141 tmpQLabel = new QLabel(&dlg);
142 tmpQLabel->setGeometry(20, 90, 80, 30);
143 tmpQLabel->setText("IP Address");
145 addr = new QLineEdit(&dlg);
146 addr->setGeometry(130, 90, 120, 30);
149 tmpQLabel = new QLabel(&dlg);
150 tmpQLabel->setGeometry(20, 130, 100, 30);
151 tmpQLabel->setText("Connection type");
153 QComboBox* tmpQComboBox;
154 tmpQComboBox = new QComboBox(&dlg);
155 tmpQComboBox->setGeometry(130, 130, 100, 30);
156 // tmpQComboBox->setSizeLimit(2);
157 // tmpQComboBox->setAutoResize(FALSE);
158 tmpQComboBox->insertItem(0, "Explicit");
160 tmpQLabel = new QLabel(&dlg);
161 tmpQLabel->setGeometry(20, 170, 110, 30);
162 tmpQLabel->setText("Programs directory");
164 progs = new QLineEdit(&dlg);
165 progs->setGeometry(130, 170, 230, 30);
168 tmpQLabel = new QLabel(&dlg);
169 tmpQLabel->setGeometry(20, 210, 100, 30);
170 tmpQLabel->setText("VLP directory");
172 home = new QLineEdit(&dlg);
173 home->setGeometry(130, 210, 230, 30);
176 okbtn = new QPushButton(&dlg);
177 okbtn->setGeometry(80, 250, 100, 30);
178 okbtn->setText("Ok");
179 connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
180 cancelbtn = new QPushButton(&dlg);
181 cancelbtn->setGeometry(210, 250, 100, 30);
182 cancelbtn->setText("Cancel");
183 connect(cancelbtn,SIGNAL(clicked()), &dlg, SLOT(reject()));
184 dlg.resize(380, 300);
187 pom->ID = id->text().toInt();
188 if (check_id(pom->ID)) {
189 strcpy(pom->addr, addr->text().toStdString().c_str());
190 if (check_addr(pom->addr)) {
191 if (tmpQComboBox->currentText() == "Explicit") {
194 strcpy(pom->progdir, progs->text().toStdString().c_str());
195 strcpy(pom->homedir, home->text().toStdString().c_str());
197 sprintf(pomstr, "Node: %d\t"
199 "Home dir: %s", pom->ID, pom->addr, pom->homedir);
200 nodelist->insertItem(pomstr);
201 strcpy(pom->item, pomstr);
203 QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", "Ok");
206 QMessageBox::warning(this, "Error!", "ID must be unique!", "Ok");
211 void QInstall::DelNode()
216 if (nodelist->currentItem() >= 0) {
217 strcpy(pom, nodelist->text(nodelist->currentItem()).toStdString().c_str());
218 vpom = Nodes.first();
219 while (vpom != NULL) {
220 if (strcmp(pom, vpom->item) == 0)
222 vpom = Nodes.takeFirst();
225 if (QMessageBox::question(this, "Delete VLP", "Are you sure?", "Yes", "No")) {
226 nodelist->removeItem(nodelist->currentItem());
227 Nodes.removeOne(vpom);
232 void QInstall::SetOptions()
236 QPushButton *addbtn, *delbtn, *okbtn, *cancelbtn;
241 //dlg.setStyle(WindowsStyle);
242 nodelist = new Q3ListBox(&dlg);
243 nodelist->setGeometry(20, 40, 480, 160);
245 tmpQLabel = new QLabel(&dlg);
246 tmpQLabel->setGeometry(20, 10, 100, 30);
247 tmpQLabel->setText("Nodes:");
249 addbtn = new QPushButton(&dlg);
250 addbtn->setGeometry(30, 210, 100, 30);
251 addbtn->setText("Add VLP");
252 connect(addbtn, SIGNAL(clicked()), this, SLOT(AddNode()));
254 delbtn = new QPushButton(&dlg);
255 delbtn->setGeometry(150, 210, 100, 30);
256 delbtn->setText("Del VLP");
257 connect(delbtn, SIGNAL(clicked()), this, SLOT(DelNode()));
259 okbtn = new QPushButton(&dlg);
260 okbtn->setGeometry(270, 210, 100, 30);
261 okbtn->setText("Save files");
262 connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
264 cancelbtn = new QPushButton(&dlg);
265 cancelbtn->setGeometry(390, 210, 100, 30);
266 cancelbtn->setText("Cancel");
267 connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
269 dlg.resize(520, 260);
272 if (!Nodes.isEmpty()) {
274 while (pom != NULL) {
275 j = Nodes.indexOf(pom);
276 sprintf(pomstr, "%s.cfg", pom->addr);
279 config_setting_t *root, *setting;
282 root = config_root_setting(&cfg);
284 setting = config_setting_get_member(root, "progdir");
286 setting = config_setting_add(root, "progdir", CONFIG_TYPE_STRING);
288 config_setting_set_string(setting, pom->progdir);
290 setting = config_setting_get_member(root, "homedir");
292 setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
294 config_setting_set_string(setting, pom->homedir);
296 setting = config_setting_get_member(root, "node_number");
298 setting = config_setting_add(root, "node_number", CONFIG_TYPE_INT);
300 config_setting_set_int(setting, pom->ID);
302 if (pom->type == 0) {
303 setting = config_setting_get_member(root, "type");
305 setting = config_setting_add(root, "type", CONFIG_TYPE_STRING);
307 config_setting_set_string(setting, "explicit");
309 for (i = 0; i < Nodes.count(); i++) {
310 if (pom != Nodes.at(i)) {
311 setting = config_setting_get_member(root, "host");
313 setting = config_setting_add(root, "host", CONFIG_TYPE_STRING);
315 config_setting_set_string(setting, Nodes.at(i)->addr);
319 if(!config_write_file(&cfg, pomstr)) {
320 fprintf(stderr, "Error while writing to file: %s.\n", pomstr);
322 config_destroy(&cfg);
325 pom = Nodes.takeFirst();
331 #include "lgconfig.moc"
333 int main(int argc, char **argv)
335 app = new QApplication(argc,argv);
337 //app->setStyle(WindowsStyle);
338 // app->setMainWidget(&cfg);