vlp-27 Added move OptionsDialog to the QtDesigner generated one.
[vlp.git] / src / kernel / kernel.cpp
index 8321476ff915e4c37d017939894065d160f132e9..0ac3ba7f21806a3a9198d38ceecc30f2b7ec47c0 100644 (file)
@@ -66,6 +66,7 @@
 #include "kernel.h"
 #include "send-message.h"
 #include "kill-interpreter.h"
+#include "options.h"
 
 /* File resides in top directory (where are Makefiles)*/
 #include "../../config.h"
@@ -431,50 +432,6 @@ void QKernel::QuitProc()
        QApplication::instance()->quit();
 }
 
-/**
- * Adds IP address to the configuration.
- * Additional window is displayed to add address to the list
- */
-void QKernel::AddAddress()
-{
-       QDialog d(this, Qt::Dialog);
-       QLabel lab("IP Address:", &d);
-       QLineEdit ed("", &d);
-       QPushButton ob("", &d);
-       QPushButton cb("", &d);
-
-       if (connections) {
-               ob.setGeometry(30, 60, 80, 30);
-               ob.setText("Ok");
-               ob.setDefault(TRUE);
-               lab.setGeometry(10, 10, 60, 30);
-               lab.setText("Address");
-               ed.setGeometry(70, 10, 140, 30);
-               cb.setGeometry(130, 60, 80, 30);
-               cb.setText("Cancel");
-               d.resize(240, 100);
-               connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
-               connect(&cb, SIGNAL(clicked()), &d, SLOT(reject())); 
-               if (d.exec())
-                       if (strcmp(ed.text().toAscii().data(), "") != 0) {
-                               connections->addItem(ed.text());
-                       }
-       }
-}
-
-/**
- * Deletes current address from available connections.
- */
-void QKernel::DelAddress()
-{
-       if (connections) {
-               if (connections->currentRow() != -1) {
-                       /* TODO: Checki if this work correctly after porting */
-                       connections->removeItemWidget(connections->currentItem());
-               }
-       }
-}
-
 /**
  * Sends message to node.
  * Additional window is displayed to set Node Number of node where send message,
@@ -759,92 +716,20 @@ void QKernel::on_actionInfo_messages_triggered()
  */
 void QKernel::on_actionOptions_triggered()
 {
-       QDialog dlg(this, Qt::Dialog);
-       dlg.setWindowTitle("Options");
+       OptionsDialog * dlg = new OptionsDialog(this, Qt::Dialog);
        ConnectEntry *e;
+       QListWidget *connections;
        unsigned int i;
 
-       QLineEdit* progs;
-       progs = new QLineEdit(progdir, &dlg);
-       progs->setGeometry(150, 20, 180, 30);
-
-       QLabel* tmpQLabel;
-       tmpQLabel = new QLabel("Programs directory", &dlg);
-       tmpQLabel->setGeometry(30, 20, 120, 30);
-
-       QFrame* tmpQFrame;
-       tmpQFrame = new QFrame(&dlg);
-       tmpQFrame->setGeometry(10, 60, 380, 30);
-       tmpQFrame->setFrameStyle(52);
+       dlg->setDefaultNodeNumber(NodeNumber);
+       dlg->setDefaultProgramsDirectory(progdir);
 
-       tmpQLabel = new QLabel("Virtual Processor properties (activated after "
-                                               "restarting VLP):", &dlg);
-       tmpQLabel->setGeometry(10, 80, 340, 30);
-
-       QLineEdit *nn;
-       char nns[256];
-       sprintf(nns, "%d", NodeNumber);
-       nn = new QLineEdit(nns, &dlg);
-       nn->setGeometry(110, 110, 40, 30);
-
-       tmpQLabel = new QLabel("Node number:", &dlg);
-       tmpQLabel->setGeometry(20, 110, 90, 30);
-
-       QRadioButton *exp, *reg;
-       exp = new QRadioButton("Explicit", &dlg);
-       exp->setGeometry(30, 170, 100, 30);
-       exp->setChecked(TRUE);
-
-       reg = new QRadioButton("Registration", &dlg);
-       reg->setGeometry(30, 200, 100, 30);
-       reg->setEnabled(FALSE);
-
-       connections = new QListWidget(&dlg);
-       connections->setGeometry(170, 140, 130, 100);
-
-       for (int i = 0; i < ConnectList.size(); i++) {
+       for (i = 0; i < ConnectList.size(); i++) {
                e = ConnectList.at(i);
-               connections->addItem(e->addr);
+               dlg->addConnection(e);
        }
 
-       tmpQLabel = new QLabel("Connection list:", &dlg);
-       tmpQLabel->setGeometry(170, 110, 100, 30);
-
-       QPushButton *addbtn;
-       QPushButton *delbtn;
-       QPushButton *okbtn;
-       QPushButton *cancelbtn;
-       addbtn = new QPushButton("Add", &dlg);
-       addbtn->setGeometry(310, 150, 60, 30);
-       connect(addbtn, SIGNAL(clicked()), this, SLOT(AddAddress()));
-
-       delbtn = new QPushButton("Del", &dlg);
-       delbtn->setGeometry(310, 200, 60, 30);
-       connect(delbtn, SIGNAL(clicked()), this, SLOT(DelAddress()));
-
-       okbtn = new QPushButton("Ok", &dlg);
-       okbtn->setGeometry(80, 260, 100, 30);
-       okbtn->setDefault(TRUE);
-       connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       cancelbtn = new QPushButton("Cancel", &dlg);
-       cancelbtn->setGeometry(210, 260, 100, 30);
-       connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
-
-       QGroupBox* group;
-       group = new QGroupBox("Connection type", &dlg);
-       group->setGeometry(20, 150, 120, 90);
-       group->setAlignment(Qt::AlignLeft);
-       group->lower();
-
-       QVBoxLayout *vbox = new QVBoxLayout();
-       vbox->addWidget(exp);
-       vbox->addWidget(reg);
-       vbox->addStretch(1);
-       group->setLayout(vbox);
-
-       dlg.resize(400, 310);
-       if (dlg.exec()) {
+       if (dlg->exec()) {
                config_t cfg;
                config_setting_t *root;
                config_setting_t *setting;
@@ -854,12 +739,12 @@ void QKernel::on_actionOptions_triggered()
 
                setting = config_setting_add(root, "progdir",
                                                        CONFIG_TYPE_STRING);
-               config_setting_set_string(setting, progs->text().toAscii().data());
-               strcpy(progdir, progs->text().toAscii().data());
+               strcpy(progdir, dlg->getProgramsDirectory().toAscii().data());
+               config_setting_set_string(setting, progdir);
 
                setting = config_setting_add(root, "node_number",
                                                        CONFIG_TYPE_INT);
-               config_setting_set_int(setting, atoi(nn->text().toAscii().data()));
+               config_setting_set_int(setting, dlg->getNodeNumber());
 
                setting = config_setting_add(root, "homedir",
                                                        CONFIG_TYPE_STRING);
@@ -867,12 +752,15 @@ void QKernel::on_actionOptions_triggered()
 
                setting = config_setting_add(root, "type",
                                                        CONFIG_TYPE_STRING);
-               if (exp->isChecked()) {
+               if (strcmp(dlg->getConnectionType().toLower().toAscii().data(),
+                                                       "explicit") == 0) {
                        config_setting_set_string(setting, "explicit");
 
                        config_setting_t *hosts = NULL;
                        hosts = config_setting_add(root, "host",
                                                        CONFIG_TYPE_ARRAY);
+                       
+                       connections = dlg->getConnectionList();
                        for(i = 0; i < connections->count(); i++) {
                                setting = config_setting_add(hosts, NULL,
                                                        CONFIG_TYPE_STRING);