24 #include <libconfig.h>
37 class QInstall: public QFrame {
43 QList<VLPEntry> Nodes;
47 bool check_addr(char*);
61 QFont f("Helvetica", 12, QFont::Bold);
64 infob = new QPushButton(this);
66 bar = new QMenuBar(this);
67 bar->insertItem("Configure", this, SLOT(SetOptions()));
68 bar->insertItem("Quit", app, SLOT(quit()));
70 setCaption("VLP Configuration Tool");
71 infob->setGeometry(0, bar->height(), 200, 30);
72 if (mp.load("logo.bmp")) {
74 infob->resize(mp.width(), mp.height());
76 resize(infob->width(), infob->height() + bar->height());
80 bool QInstall::check_id(int id)
93 bool QInstall::check_addr(char *addr)
99 if (strcmp(pom->addr, addr) == 0)
107 * @attention Currently not in use
109 void QInstall::Info()
113 void QInstall::AddNode()
115 QDialog dlg(this, "", TRUE);
117 QLineEdit *id, *addr, *progs, *home;
118 QPushButton *okbtn, *cancelbtn;
122 tmpQLabel = new QLabel(&dlg, "Label_2");
123 tmpQLabel->setGeometry(110, 10, 180, 30);
124 tmpQLabel->setFrameStyle(49);
125 tmpQLabel->setText("Virtual Processor Properties");
127 id = new QLineEdit(&dlg, "LineEdit_1");
128 id->setGeometry(130, 50, 50, 30);
131 tmpQLabel = new QLabel(&dlg, "Label_3");
132 tmpQLabel->setGeometry(20, 50, 90, 30);
133 tmpQLabel->setText("Node number");
135 tmpQLabel = new QLabel(&dlg, "Label_4");
136 tmpQLabel->setGeometry(20, 90, 80, 30);
137 tmpQLabel->setText("IP Address");
139 addr = new QLineEdit(&dlg, "LineEdit_2");
140 addr->setGeometry(130, 90, 120, 30);
143 tmpQLabel = new QLabel(&dlg, "Label_5");
144 tmpQLabel->setGeometry(20, 130, 100, 30);
145 tmpQLabel->setText("Connection type");
147 QComboBox* tmpQComboBox;
148 tmpQComboBox = new QComboBox(FALSE, &dlg, "ComboBox_1");
149 tmpQComboBox->setGeometry(130, 130, 100, 30);
150 tmpQComboBox->setSizeLimit(2);
151 tmpQComboBox->setAutoResize(FALSE);
152 tmpQComboBox->insertItem("Explicit");
154 tmpQLabel = new QLabel(&dlg, "Label_6");
155 tmpQLabel->setGeometry(20, 170, 110, 30);
156 tmpQLabel->setText("Programs directory");
158 progs = new QLineEdit(&dlg, "LineEdit_4");
159 progs->setGeometry(130, 170, 230, 30);
162 tmpQLabel = new QLabel(&dlg, "Label_7");
163 tmpQLabel->setGeometry(20, 210, 100, 30);
164 tmpQLabel->setText("VLP directory");
166 home = new QLineEdit(&dlg, "LineEdit_5");
167 home->setGeometry(130, 210, 230, 30);
170 okbtn = new QPushButton(&dlg, "PushButton_5");
171 okbtn->setGeometry(80, 250, 100, 30);
172 okbtn->setText("Ok");
173 connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
174 cancelbtn = new QPushButton(&dlg, "PushButton_6");
175 cancelbtn->setGeometry(210, 250, 100, 30);
176 cancelbtn->setText("Cancel");
177 connect(cancelbtn,SIGNAL(clicked()), &dlg, SLOT(reject()));
178 dlg.resize(380, 300);
181 pom->ID = atoi(id->text());
182 if (check_id(pom->ID)) {
183 strcpy(pom->addr, addr->text());
184 if (check_addr(pom->addr)) {
185 if (strcmp(tmpQComboBox->currentText(),
189 strcpy(pom->progdir, progs->text());
190 strcpy(pom->homedir, home->text());
192 sprintf(pomstr, "Node: %d\t"
194 "Home dir: %s", pom->ID, pom->addr, pom->homedir);
195 nodelist->insertItem(pomstr);
196 strcpy(pom->item, pomstr);
198 QMessageBox::message("Error!",
199 "Only one VLP on a single computer!",
203 QMessageBox::message("Error!", "ID must be unique!",
209 void QInstall::DelNode()
214 if (nodelist->currentItem() >= 0) {
215 strcpy(pom, nodelist->text(nodelist->currentItem()));
216 vpom = Nodes.first();
217 while (vpom != NULL) {
218 if (strcmp(pom, vpom->item) == 0)
223 if (QMessageBox::query("Delete VLP", "Are you sure?",
225 nodelist->removeItem(nodelist->currentItem());
231 void QInstall::SetOptions()
233 QDialog dlg(this, "", TRUE);
235 QPushButton *addbtn, *delbtn, *okbtn, *cancelbtn;
240 //dlg.setStyle(WindowsStyle);
241 nodelist = new QListBox(&dlg, "ListBox_1");
242 nodelist->setGeometry(20, 40, 480, 160);
244 tmpQLabel = new QLabel(&dlg, "Label_1");
245 tmpQLabel->setGeometry(20, 10, 100, 30);
246 tmpQLabel->setText("Nodes:");
248 addbtn = new QPushButton(&dlg, "PushButton_1");
249 addbtn->setGeometry(30, 210, 100, 30);
250 addbtn->setText("Add VLP");
251 connect(addbtn, SIGNAL(clicked()), this, SLOT(AddNode()));
253 delbtn = new QPushButton(&dlg, "PushButton_2");
254 delbtn->setGeometry(150, 210, 100, 30);
255 delbtn->setText("Del VLP");
256 connect(delbtn, SIGNAL(clicked()), this, SLOT(DelNode()));
258 okbtn = new QPushButton(&dlg, "PushButton_3");
259 okbtn->setGeometry(270, 210, 100, 30);
260 okbtn->setText("Save files");
261 connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
263 cancelbtn = new QPushButton(&dlg, "PushButton_4");
264 cancelbtn->setGeometry(390, 210, 100, 30);
265 cancelbtn->setText("Cancel");
266 connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
268 dlg.resize(520, 260);
271 if (!Nodes.isEmpty()) {
273 while (pom != NULL) {
275 sprintf(pomstr, "%s.cfg", pom->addr);
278 config_setting_t *root, *setting;
281 root = config_root_setting(&cfg);
283 setting = config_setting_get_member(root, "progdir");
285 setting = config_setting_add(root, "progdir", CONFIG_TYPE_STRING);
287 config_setting_set_string(setting, pom->progdir);
289 setting = config_setting_get_member(root, "homedir");
291 setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
293 config_setting_set_string(setting, pom->homedir);
295 setting = config_setting_get_member(root, "node_number");
297 setting = config_setting_add(root, "node_number", CONFIG_TYPE_INT);
299 config_setting_set_int(setting, pom->ID);
301 if (pom->type == 0) {
302 setting = config_setting_get_member(root, "type");
304 setting = config_setting_add(root, "type", CONFIG_TYPE_STRING);
306 config_setting_set_string(setting, "explicit");
308 for (i = 0; i < Nodes.count(); i++) {
309 if (pom != Nodes.at(i)) {
310 setting = config_setting_get_member(root, "host");
312 setting = config_setting_add(root, "host", CONFIG_TYPE_STRING);
314 config_setting_set_string(setting, Nodes.at(i)->addr);
318 if(!config_write_file(&cfg, pomstr)) {
319 fprintf(stderr, "Error while writing to file: %s.\n", pomstr);
321 config_destroy(&cfg);
330 #include "lgconfig.moc"
332 int main(int argc, char **argv)
334 app = new QApplication(argc,argv);
336 //app->setStyle(WindowsStyle);
337 app->setMainWidget(&cfg);