24 #include <libconfig.h>
30 int type; /* 0 - explicit */
36 class QInstall: public QFrame {
42 QList<VLPEntry> Nodes;
46 bool check_addr(char*);
60 QFont f("Helvetica", 12, QFont::Bold);
63 infob = new QPushButton(this);
65 bar = new QMenuBar(this);
66 bar->insertItem("Configure", this, SLOT(SetOptions()));
67 bar->insertItem("Quit", app, SLOT(quit()));
69 setCaption("VLP Configuration Tool");
70 infob->setGeometry(0, bar->height(), 200, 30);
71 if (mp.load("logo.bmp")) {
73 infob->resize(mp.width(), mp.height());
75 resize(infob->width(), infob->height() + bar->height());
79 bool QInstall::check_id(int id)
92 bool QInstall::check_addr(char *addr)
98 if (strcmp(pom->addr, addr) == 0)
105 void QInstall::Info()
109 void QInstall::AddNode()
111 QDialog dlg(this, "", TRUE);
113 QLineEdit *id, *addr, *progs, *home;
114 QPushButton *okbtn, *cancelbtn;
118 tmpQLabel = new QLabel(&dlg, "Label_2");
119 tmpQLabel->setGeometry(110, 10, 180, 30);
120 tmpQLabel->setFrameStyle(49);
121 tmpQLabel->setText("Virtual Processor Properties");
123 id = new QLineEdit(&dlg, "LineEdit_1");
124 id->setGeometry(130, 50, 50, 30);
127 tmpQLabel = new QLabel(&dlg, "Label_3");
128 tmpQLabel->setGeometry(20, 50, 90, 30);
129 tmpQLabel->setText("Node number");
131 tmpQLabel = new QLabel(&dlg, "Label_4");
132 tmpQLabel->setGeometry(20, 90, 80, 30);
133 tmpQLabel->setText("IP Address");
135 addr = new QLineEdit(&dlg, "LineEdit_2");
136 addr->setGeometry(130, 90, 120, 30);
139 tmpQLabel = new QLabel(&dlg, "Label_5");
140 tmpQLabel->setGeometry(20, 130, 100, 30);
141 tmpQLabel->setText("Connection type");
143 QComboBox* tmpQComboBox;
144 tmpQComboBox = new QComboBox(FALSE, &dlg, "ComboBox_1");
145 tmpQComboBox->setGeometry(130, 130, 100, 30);
146 tmpQComboBox->setSizeLimit(2);
147 tmpQComboBox->setAutoResize(FALSE);
148 tmpQComboBox->insertItem("Explicit");
150 tmpQLabel = new QLabel(&dlg, "Label_6");
151 tmpQLabel->setGeometry(20, 170, 110, 30);
152 tmpQLabel->setText("Programs directory");
154 progs = new QLineEdit(&dlg, "LineEdit_4");
155 progs->setGeometry(130, 170, 230, 30);
158 tmpQLabel = new QLabel(&dlg, "Label_7");
159 tmpQLabel->setGeometry(20, 210, 100, 30);
160 tmpQLabel->setText("VLP directory");
162 home = new QLineEdit(&dlg, "LineEdit_5");
163 home->setGeometry(130, 210, 230, 30);
166 okbtn = new QPushButton(&dlg, "PushButton_5");
167 okbtn->setGeometry(80, 250, 100, 30);
168 okbtn->setText("Ok");
169 connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
170 cancelbtn = new QPushButton(&dlg, "PushButton_6");
171 cancelbtn->setGeometry(210, 250, 100, 30);
172 cancelbtn->setText("Cancel");
173 connect(cancelbtn,SIGNAL(clicked()), &dlg, SLOT(reject()));
174 dlg.resize(380, 300);
177 pom->ID = atoi(id->text());
178 if (check_id(pom->ID)) {
179 strcpy(pom->addr, addr->text());
180 if (check_addr(pom->addr)) {
181 if (strcmp(tmpQComboBox->currentText(),
185 strcpy(pom->progdir, progs->text());
186 strcpy(pom->homedir, home->text());
188 sprintf(pomstr, "Node: %d\t"
190 "Home dir: %s", pom->ID, pom->addr, pom->homedir);
191 nodelist->insertItem(pomstr);
192 strcpy(pom->item, pomstr);
194 QMessageBox::message("Error!",
195 "Only one VLP on a single computer!",
199 QMessageBox::message("Error!", "ID must be unique!",
205 void QInstall::DelNode()
210 if (nodelist->currentItem() >= 0) {
211 strcpy(pom, nodelist->text(nodelist->currentItem()));
212 vpom = Nodes.first();
213 while (vpom != NULL) {
214 if (strcmp(pom, vpom->item) == 0)
219 if (QMessageBox::query("Delete VLP", "Are you sure?",
221 nodelist->removeItem(nodelist->currentItem());
227 void QInstall::SetOptions()
229 QDialog dlg(this, "", TRUE);
231 QPushButton *addbtn, *delbtn, *okbtn, *cancelbtn;
236 //dlg.setStyle(WindowsStyle);
237 nodelist = new QListBox(&dlg, "ListBox_1");
238 nodelist->setGeometry(20, 40, 480, 160);
240 tmpQLabel = new QLabel(&dlg, "Label_1");
241 tmpQLabel->setGeometry(20, 10, 100, 30);
242 tmpQLabel->setText("Nodes:");
244 addbtn = new QPushButton(&dlg, "PushButton_1");
245 addbtn->setGeometry(30, 210, 100, 30);
246 addbtn->setText("Add VLP");
247 connect(addbtn, SIGNAL(clicked()), this, SLOT(AddNode()));
249 delbtn = new QPushButton(&dlg, "PushButton_2");
250 delbtn->setGeometry(150, 210, 100, 30);
251 delbtn->setText("Del VLP");
252 connect(delbtn, SIGNAL(clicked()), this, SLOT(DelNode()));
254 okbtn = new QPushButton(&dlg, "PushButton_3");
255 okbtn->setGeometry(270, 210, 100, 30);
256 okbtn->setText("Save files");
257 connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
259 cancelbtn = new QPushButton(&dlg, "PushButton_4");
260 cancelbtn->setGeometry(390, 210, 100, 30);
261 cancelbtn->setText("Cancel");
262 connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
264 dlg.resize(520, 260);
267 if (!Nodes.isEmpty()) {
269 while (pom != NULL) {
271 sprintf(pomstr, "%s.cfg", pom->addr);
274 config_setting_t *root, *setting;
277 root = config_root_setting(&cfg);
279 setting = config_setting_get_member(root, "progdir");
281 setting = config_setting_add(root, "progdir", CONFIG_TYPE_STRING);
283 config_setting_set_string(setting, pom->progdir);
285 setting = config_setting_get_member(root, "homedir");
287 setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
289 config_setting_set_string(setting, pom->homedir);
291 setting = config_setting_get_member(root, "node_number");
293 setting = config_setting_add(root, "node_number", CONFIG_TYPE_INT);
295 config_setting_set_int(setting, pom->ID);
297 if (pom->type == 0) {
298 setting = config_setting_get_member(root, "type");
300 setting = config_setting_add(root, "type", CONFIG_TYPE_STRING);
302 config_setting_set_string(setting, "explicit");
304 for (i = 0; i < Nodes.count(); i++) {
305 if (pom != Nodes.at(i)) {
306 setting = config_setting_get_member(root, "host");
308 setting = config_setting_add(root, "host", CONFIG_TYPE_STRING);
310 config_setting_set_string(setting, Nodes.at(i)->addr);
314 if(!config_write_file(&cfg, pomstr)) {
315 fprintf(stderr, "Error while writing to file: %s.\n", pomstr);
317 config_destroy(&cfg);
326 #include "lgconfig.moc"
328 int main(int argc, char **argv)
330 app = new QApplication(argc,argv);
332 //app->setStyle(WindowsStyle);
333 app->setMainWidget(&cfg);