26 #include <libconfig.h>
33 int type; /* 0 - explicit */
34 char progdir[255],homedir[255];
38 class QInstall: public QFrame
45 QList<VLPEntry> Nodes;
49 bool check_addr(char*);
65 QFont f("Helvetica",12,QFont::Bold);
68 infob = new QPushButton(this);
72 bar = new QMenuBar(this);
73 bar->insertItem("Configure",this,SLOT(SetOptions()));
74 bar->insertItem("Quit",app,SLOT(quit()));
76 setCaption("VLP Configuration Tool");
77 infob->setGeometry(0,bar->height(),200,30);
78 if( mp.load("logo.bmp"))
81 infob->resize(mp.width(),mp.height());
84 resize(infob->width(),infob->height()+bar->height());
89 bool QInstall::check_id(int id)
96 if (pom->ID == id) return(FALSE);
104 bool QInstall::check_addr(char *addr)
111 if (strcmp(pom->addr,addr) == 0) return(FALSE);
118 void QInstall::Info()
123 void QInstall::AddNode()
125 QDialog dlg(this,"",TRUE);
127 QLineEdit *id,*addr,*progs,*home;
128 QPushButton *okbtn,*cancelbtn;
132 tmpQLabel = new QLabel( &dlg, "Label_2" );
133 tmpQLabel->setGeometry( 110, 10, 180, 30 );
134 tmpQLabel->setFrameStyle( 49 );
135 tmpQLabel->setText( "Virtual Processor Properties" );
137 id = new QLineEdit( &dlg, "LineEdit_1" );
138 id->setGeometry( 130, 50, 50, 30 );
141 tmpQLabel = new QLabel( &dlg, "Label_3" );
142 tmpQLabel->setGeometry( 20, 50, 90, 30 );
143 tmpQLabel->setText( "Node number" );
145 tmpQLabel = new QLabel( &dlg, "Label_4" );
146 tmpQLabel->setGeometry( 20, 90, 80, 30 );
147 tmpQLabel->setText( "IP Address" );
149 addr = new QLineEdit( &dlg, "LineEdit_2" );
150 addr->setGeometry( 130, 90, 120, 30 );
153 tmpQLabel = new QLabel( &dlg, "Label_5" );
154 tmpQLabel->setGeometry( 20, 130, 100, 30 );
155 tmpQLabel->setText( "Connection type" );
157 QComboBox* tmpQComboBox;
158 tmpQComboBox = new QComboBox( FALSE, &dlg, "ComboBox_1" );
159 tmpQComboBox->setGeometry( 130, 130, 100, 30 );
160 tmpQComboBox->setSizeLimit( 2 );
161 tmpQComboBox->setAutoResize( FALSE );
162 tmpQComboBox->insertItem( "Explicit" );
164 tmpQLabel = new QLabel( &dlg, "Label_6" );
165 tmpQLabel->setGeometry( 20, 170, 110, 30 );
166 tmpQLabel->setText( "Programs directory" );
168 progs = new QLineEdit( &dlg, "LineEdit_4" );
169 progs->setGeometry( 130, 170, 230, 30 );
170 progs->setText( "" );
172 tmpQLabel = new QLabel( &dlg, "Label_7" );
173 tmpQLabel->setGeometry( 20, 210, 100, 30 );
174 tmpQLabel->setText( "VLP directory" );
176 home = new QLineEdit( &dlg, "LineEdit_5" );
177 home->setGeometry( 130, 210, 230, 30 );
180 okbtn = new QPushButton( &dlg, "PushButton_5" );
181 okbtn->setGeometry( 80, 250, 100, 30 );
182 okbtn->setText( "Ok" );
183 connect(okbtn,SIGNAL(clicked()),&dlg,SLOT(accept()));
184 cancelbtn = new QPushButton( &dlg, "PushButton_6" );
185 cancelbtn->setGeometry( 210, 250, 100, 30 );
186 cancelbtn->setText( "Cancel" );
187 connect(cancelbtn,SIGNAL(clicked()),&dlg,SLOT(reject()));
188 dlg.resize( 380, 300 );
192 pom->ID = atoi(id->text());
193 if (check_id(pom->ID))
195 strcpy(pom->addr,addr->text());
196 if (check_addr(pom->addr))
199 if (strcmp(tmpQComboBox->currentText(),"Explicit")==0) pom->type=0;
200 strcpy(pom->progdir,progs->text());
201 strcpy(pom->homedir,home->text());
203 sprintf(pomstr,"Node: %d Addr:%s Home dir: %s",pom->ID,pom->addr,pom->homedir);
204 nodelist->insertItem(pomstr);
205 strcpy(pom->item,pomstr);
206 } else QMessageBox::message("Error!","Only one VLP on a single computer!","Ok");
208 else QMessageBox::message("Error!","ID must be unique!","Ok");
213 void QInstall::DelNode()
218 if (nodelist->currentItem()>=0)
220 strcpy(pom,nodelist->text(nodelist->currentItem()));
221 vpom = Nodes.first();
224 if (strcmp(pom,vpom->item)==0) break;
228 if (QMessageBox::query("Delete VLP","Are you sure?","Yes","No"))
230 nodelist->removeItem(nodelist->currentItem());
237 void QInstall::SetOptions()
239 QDialog dlg(this,"",TRUE);
241 QPushButton *addbtn,*delbtn,*okbtn,*cancelbtn;
246 //dlg.setStyle(WindowsStyle);
247 nodelist = new QListBox( &dlg, "ListBox_1" );
248 nodelist->setGeometry( 20, 40, 480, 160 );
250 tmpQLabel = new QLabel( &dlg, "Label_1" );
251 tmpQLabel->setGeometry( 20, 10, 100, 30 );
252 tmpQLabel->setText( "Nodes:" );
254 addbtn = new QPushButton( &dlg, "PushButton_1" );
255 addbtn->setGeometry( 30, 210, 100, 30 );
256 addbtn->setText( "Add VLP" );
257 connect(addbtn,SIGNAL(clicked()),this,SLOT(AddNode()));
258 delbtn = new QPushButton( &dlg, "PushButton_2" );
259 delbtn->setGeometry( 150, 210, 100, 30 );
260 delbtn->setText( "Del VLP" );
261 connect(delbtn,SIGNAL(clicked()),this,SLOT(DelNode()));
262 okbtn = new QPushButton( &dlg, "PushButton_3" );
263 okbtn->setGeometry( 270, 210, 100, 30 );
264 okbtn->setText( "Save files" );
265 connect(okbtn,SIGNAL(clicked()),&dlg,SLOT(accept()));
266 cancelbtn = new QPushButton( &dlg, "PushButton_4" );
267 cancelbtn->setGeometry( 390, 210, 100, 30 );
268 cancelbtn->setText( "Cancel" );
269 connect(cancelbtn,SIGNAL(clicked()),&dlg,SLOT(reject()));
270 dlg.resize( 520, 260 );
274 if (!Nodes.isEmpty())
280 sprintf(pomstr,"%s.cfg",pom->addr);
283 config_setting_t *root, *setting;
286 root = config_root_setting(&cfg);
288 setting = config_setting_get_member(root, "progdir");
290 setting = config_setting_add(root, "progdir", CONFIG_TYPE_STRING);
292 config_setting_set_string(setting, pom->progdir);
294 setting = config_setting_get_member(root, "homedir");
296 setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
298 config_setting_set_string(setting, pom->homedir);
300 setting = config_setting_get_member(root, "node_number");
302 setting = config_setting_add(root, "node_number", CONFIG_TYPE_INT);
304 config_setting_set_int(setting, pom->ID);
308 setting = config_setting_get_member(root, "type");
310 setting = config_setting_add(root, "type", CONFIG_TYPE_STRING);
312 config_setting_set_string(setting, "explicit");
314 for(i=0;i<Nodes.count();i++)
316 if (pom!=Nodes.at(i))
318 setting = config_setting_get_member(root, "host");
320 setting = config_setting_add(root, "host", CONFIG_TYPE_STRING);
322 config_setting_set_string(setting, Nodes.at(i)->addr);
326 if(!config_write_file(&cfg, pomstr))
328 fprintf(stderr, "Error while writing to file: %s.\n", pomstr);
330 config_destroy(&cfg);
344 #include "lgconfig.moc"
346 int main( int argc, char **argv )
349 app = new QApplication(argc,argv);
351 //app->setStyle(WindowsStyle);
352 app->setMainWidget(&cfg);