#include <QtGui/QApplication>
-#include <QtGui/QMainWindow>
-#include <Qt3Support/q3multilineedit.h>
-#include <QtGui/QMenuBar>
-// #include <qpopmenu.h>
-#include <QtGui/QDialog>
-#include <QtGui/QButtonGroup>
-#include <QtGui/QLabel>
-#include <QtGui/QLineEdit>
-#include <Qt3Support/Q3ListBox>
-#include <QtGui/QPushButton>
-#include <QtGui/QRadioButton>
#include <QtCore/QList>
-#include <QtCore/qfile.h>
-#include <QtGui/qcombobox.h>
-#include <QtGui/QToolTip>
-#include <QtGui/QFont>
-#include <QtGui/QPixmap>
-#include <QtGui/QMessageBox>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libconfig.h>
#include "lgconfig.h"
+#include "NodeListDialog.h"
+#include "vlp/config.h"
-QApplication *app;
+namespace loglan {
+namespace vlp {
QInstall::QInstall()
{
setupUi(this);
-
- Nodes.clear();
-}
-
-bool QInstall::check_id(int id)
-{
- VLPEntry *pom;
- QListIterator<VLPEntry *> nodesIterator(Nodes);
-
- while (nodesIterator.hasNext()) {
- pom = nodesIterator.next();
- if (pom->ID == id)
- return FALSE;
- }
- return TRUE;
-}
-
-bool QInstall::check_addr(char *addr)
-{
- VLPEntry *pom;
- QListIterator<VLPEntry *> nodesIterator(Nodes);
-
- while (nodesIterator.hasNext()) {
- pom = nodesIterator.next();
- if (strcmp(pom->addr, addr) == 0)
- return FALSE;
- }
- return TRUE;
-}
-
-void QInstall::AddNode()
-{
- QDialog dlg(this);
- QLabel *tmpQLabel;
- QLineEdit *id, *addr, *progs, *home;
- QPushButton *okbtn, *cancelbtn;
- VLPEntry *pom;
- char pomstr[255];
-
- tmpQLabel = new QLabel(&dlg);
- tmpQLabel->setGeometry(110, 10, 180, 30);
- tmpQLabel->setFrameStyle(49);
- tmpQLabel->setText("Virtual Processor Properties");
-
- id = new QLineEdit(&dlg);
- id->setGeometry(130, 50, 50, 30);
- id->setText("");
-
- tmpQLabel = new QLabel(&dlg);
- tmpQLabel->setGeometry(20, 50, 90, 30);
- tmpQLabel->setText("Node number");
-
- tmpQLabel = new QLabel(&dlg);
- tmpQLabel->setGeometry(20, 90, 80, 30);
- tmpQLabel->setText("IP Address");
-
- addr = new QLineEdit(&dlg);
- addr->setGeometry(130, 90, 120, 30);
- addr->setText("");
-
- tmpQLabel = new QLabel(&dlg);
- tmpQLabel->setGeometry(20, 130, 100, 30);
- tmpQLabel->setText("Connection type");
-
- QComboBox* tmpQComboBox;
- tmpQComboBox = new QComboBox(&dlg);
- tmpQComboBox->setGeometry(130, 130, 100, 30);
- tmpQComboBox->insertItem(0, "Explicit");
-
- tmpQLabel = new QLabel(&dlg);
- tmpQLabel->setGeometry(20, 170, 110, 30);
- tmpQLabel->setText("Programs directory");
-
- progs = new QLineEdit(&dlg);
- progs->setGeometry(130, 170, 230, 30);
- progs->setText("");
-
- tmpQLabel = new QLabel(&dlg);
- tmpQLabel->setGeometry(20, 210, 100, 30);
- tmpQLabel->setText("VLP directory");
-
- home = new QLineEdit(&dlg);
- home->setGeometry(130, 210, 230, 30);
- home->setText("");
-
- okbtn = new QPushButton(&dlg);
- okbtn->setGeometry(80, 250, 100, 30);
- okbtn->setText("Ok");
- connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
- cancelbtn = new QPushButton(&dlg);
- cancelbtn->setGeometry(210, 250, 100, 30);
- cancelbtn->setText("Cancel");
- connect(cancelbtn,SIGNAL(clicked()), &dlg, SLOT(reject()));
- dlg.resize(380, 300);
- if (dlg.exec()) {
- pom = new VLPEntry;
- pom->ID = id->text().toInt();
- if (check_id(pom->ID)) {
- strcpy(pom->addr, addr->text().toStdString().c_str());
- if (check_addr(pom->addr)) {
- if (tmpQComboBox->currentText() == "Explicit") {
- pom->type=0;
- }
- strcpy(pom->progdir, progs->text().toStdString().c_str());
- strcpy(pom->homedir, home->text().toStdString().c_str());
- Nodes.append(pom);
- sprintf(pomstr, "Node: %d\t"
- "Addr: %s\t"
- "Home dir: %s", pom->ID, pom->addr, pom->homedir);
- nodelist->insertItem(pomstr);
- strcpy(pom->item, pomstr);
- } else {
- QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", "Ok");
- }
- } else {
- QMessageBox::warning(this, "Error!", "ID must be unique!", "Ok");
- }
- }
-}
-
-void QInstall::DelNode()
-{
- char pom[255];
- VLPEntry *vpom;
-
- if (nodelist->currentItem() >= 0) {
- strcpy(pom, nodelist->text(nodelist->currentItem()).toStdString().c_str());
-
- QListIterator<VLPEntry *> nodesIterator(Nodes);
-
- while (nodesIterator.hasNext()) {
- vpom = nodesIterator.next();
- if (strcmp(pom, vpom->item) == 0)
- break;
- }
- if (vpom != NULL)
- if (QMessageBox::question(this, "Delete VLP", "Are you sure?", "Yes", "No")) {
- nodelist->removeItem(nodelist->currentItem());
- Nodes.removeOne(vpom);
- }
- }
}
void QInstall::on_actionConfigure_triggered()
{
- QDialog dlg(this);
- QLabel *tmpQLabel;
- QPushButton *addbtn, *delbtn, *okbtn, *cancelbtn;
- VLPEntry *pom;
- int i;
- char pomstr[255];
-
- //dlg.setStyle(WindowsStyle);
- nodelist = new Q3ListBox(&dlg);
- nodelist->setGeometry(20, 40, 480, 160);
+ dialog::NodeListDialog dialog(nodes, this);
- tmpQLabel = new QLabel(&dlg);
- tmpQLabel->setGeometry(20, 10, 100, 30);
- tmpQLabel->setText("Nodes:");
+ if (dialog.exec()) {
+ nodes = dialog.getNodes();
- addbtn = new QPushButton(&dlg);
- addbtn->setGeometry(30, 210, 100, 30);
- addbtn->setText("Add VLP");
- connect(addbtn, SIGNAL(clicked()), this, SLOT(AddNode()));
+ if (!nodes.isEmpty()) {
- delbtn = new QPushButton(&dlg);
- delbtn->setGeometry(150, 210, 100, 30);
- delbtn->setText("Del VLP");
- connect(delbtn, SIGNAL(clicked()), this, SLOT(DelNode()));
+ VLPEntry *pom;
+ int i;
+ char pomstr[255];
- okbtn = new QPushButton(&dlg);
- okbtn->setGeometry(270, 210, 100, 30);
- okbtn->setText("Save files");
- connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
+ QListIterator<VLPEntry *> nodesIterator(nodes);
- cancelbtn = new QPushButton(&dlg);
- cancelbtn->setGeometry(390, 210, 100, 30);
- cancelbtn->setText("Cancel");
- connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
-
- dlg.resize(520, 260);
-
- if (dlg.exec()) {
- if (!Nodes.isEmpty()) {
- QListIterator<VLPEntry *> nodesIterator(Nodes);
-
while (nodesIterator.hasNext()) {
pom = nodesIterator.next();
- i = Nodes.indexOf(pom);
+ i = nodes.indexOf(pom);
sprintf(pomstr, "%s.cfg", pom->addr);
- config_t cfg;
- config_setting_t *root, *setting;
- config_init(&cfg);
+
+ loglan::vlp::Config config;
- root = config_root_setting(&cfg);
+ config.setProgramDir(pom->progdir);
+ config.setNodeNumber(pom->ID);
+ config.setConnectionType(
+ (pom->type == 0) ? EXPLICIT : REGISTER
+ );
- setting = config_setting_get_member(root, "progdir");
- if(!setting) {
- setting = config_setting_add(root, "progdir", CONFIG_TYPE_STRING);
- }
- config_setting_set_string(setting, pom->progdir);
-
- setting = config_setting_get_member(root, "homedir");
- if(!setting) {
- setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
- }
- config_setting_set_string(setting, pom->homedir);
-
- setting = config_setting_get_member(root, "node_number");
- if(!setting) {
- setting = config_setting_add(root, "node_number", CONFIG_TYPE_INT);
- }
- config_setting_set_int(setting, pom->ID);
-
- if (pom->type == 0) {
- setting = config_setting_get_member(root, "type");
- if(!setting) {
- setting = config_setting_add(root, "type", CONFIG_TYPE_STRING);
- }
- config_setting_set_string(setting, "explicit");
- }
- for (auto node : Nodes) {
+ std::vector<std::string> hosts;
+ for (auto node : nodes) {
if (pom != node) {
- setting = config_setting_get_member(root, "host");
- if (!setting) {
- setting = config_setting_add(root, "host", CONFIG_TYPE_STRING);
- }
- config_setting_set_string(setting, node->addr);
+ hosts.push_back(node->addr);
}
}
+ config.setHosts(hosts);
+
+ config.save(pomstr);
+
+// TODO: add handling of homedir or remove it at all
+// setting = config_setting_get_member(root, "homedir");
+// if(!setting) {
+// setting = config_setting_add(root, "homedir", CONFIG_TYPE_STRING);
+// }
+// config_setting_set_string(setting, pom->homedir);
- if(!config_write_file(&cfg, pomstr)) {
- fprintf(stderr, "Error while writing to file: %s.\n", pomstr);
- }
- config_destroy(&cfg);
- pom = Nodes.at(i);
+ pom = nodes.at(i);
}
}
}
QApplication::instance()->quit();
}
+}
+}
+
int main(int argc, char **argv)
{
- app = new QApplication(argc,argv);
- QInstall cfg;
+ QApplication *app = new QApplication(argc,argv);
+ loglan::vlp::QInstall cfg;
cfg.show();
return app->exec();
}