Move ListNode dialog layout code into separate ui file
[vlp.git] / src / lgconfig / lgconfig.cpp
index b8036db4797d5ba8163eccb1edbb22af1b6608fe..8739358531aecf8c439917a697d1afd65a079e47 100644 (file)
@@ -14,7 +14,6 @@
 #include <QtGui/QToolTip>
 #include <QtGui/QFont>
 #include <QtGui/QPixmap>
-#include <QtGui/QMessageBox>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -22,7 +21,7 @@
 #include <libconfig.h>
 
 #include "lgconfig.h"
-#include "AddNodeDialog.h"
+#include "NodeListDialog.h"
 
 namespace loglan {
 namespace vlp {
@@ -34,141 +33,15 @@ QInstall::QInstall()
        Nodes.clear();
 }
 
-bool QInstall::check_id(int id)
-{
-       QListIterator<VLPEntry *> nodesIterator(Nodes);
-       VLPEntry *node = NULL;
-
-       while (nodesIterator.hasNext()) {
-               node = nodesIterator.next();
-               if (node->ID == id)
-                       return false;
-       }
-       return true;
-}
-
-bool QInstall::check_addr(QString addr)
-{
-       QListIterator<VLPEntry *> nodesIterator(Nodes);
-       VLPEntry *node = NULL;
-
-       while (nodesIterator.hasNext()) {
-               node = nodesIterator.next();
-               if (node->addr == addr)
-                       return false;
-       }
-       return true;
-}
-
-void QInstall::AddNode()
-{
-       dialog::AddNodeDialog dialog(this);
-
-       if (dialog.exec()) {
-               int nodeId = dialog.getNodeNumber();
-               QString ipAddress = dialog.getIPAddress();
-               if (check_id(nodeId)) {
-                       if (check_addr(ipAddress)) {
-
-                               VLPEntry *pom = new VLPEntry;
-                               pom->ID = nodeId;
-                               if (dialog.getConnectionType() == "Explicit") {
-                                       pom->type = 0;
-                               }
-                               strcpy(pom->addr, ipAddress.toStdString().c_str());
-                               strcpy(pom->progdir, dialog.getProgramsDirectory().toStdString().c_str());
-                               strcpy(pom->homedir, dialog.getVLPDirectory().toStdString().c_str());
-                               
-                               QString info;
-                               info.sprintf("Node: %d\tAddr: %s\tHome dir: %s",
-                                       pom->ID,
-                                       pom->addr,
-                                       pom->homedir
-                               );
-
-                               strcpy(pom->item, info.toStdString().c_str());
-
-                               nodelist->insertItem(info);
-                               Nodes.append(pom);
-                       }
-                       else {
-                               QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", QMessageBox::Ok);
-                       }
-               }
-               else {
-                       QMessageBox::warning(this, "Error!", "ID must be unique!", QMessageBox::Ok);
-               }
-       }
-}
-
-void QInstall::DelNode()
-{
-       if (nodelist->currentItem() >= 0) {
-               VLPEntry *node = NULL;
-               QString currentNodeInfo = nodelist->text(nodelist->currentItem());
-
-               QListIterator<VLPEntry *> nodesIterator(Nodes);
-               
-               while (nodesIterator.hasNext()) {
-                       node = nodesIterator.next();
-                       if (currentNodeInfo == node->item) {
-                               break;
-                       }
-               }
-
-               if (node != NULL) {
-                       if (QMessageBox::question(this,
-                               "Delete VLP",
-                               "Are you sure?",
-                               QMessageBox::Ok | QMessageBox::Cancel
-                       ) == QMessageBox::Ok) {
-                               nodelist->removeItem(nodelist->currentItem());
-                               Nodes.removeOne(node);
-                       }
-               }
-       }
-}
-
 void QInstall::on_actionConfigure_triggered()
 {
-       QDialog dlg(this);
-       QLabel *tmpQLabel;
-       QPushButton *addbtn, *delbtn, *okbtn, *cancelbtn;
+       dialog::NodeListDialog dialog(&Nodes, this);
+
        VLPEntry *pom;
        int i;
        char pomstr[255];
 
-       //dlg.setStyle(WindowsStyle);
-       nodelist = new Q3ListBox(&dlg);
-       nodelist->setGeometry(20, 40, 480, 160);
-
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(20, 10, 100, 30);
-       tmpQLabel->setText("Nodes:");
-
-       addbtn = new QPushButton(&dlg);
-       addbtn->setGeometry(30, 210, 100, 30);
-       addbtn->setText("Add VLP");
-       connect(addbtn, SIGNAL(clicked()), this, SLOT(AddNode()));
-
-       delbtn = new QPushButton(&dlg);
-       delbtn->setGeometry(150, 210, 100, 30);
-       delbtn->setText("Del VLP");
-       connect(delbtn, SIGNAL(clicked()), this, SLOT(DelNode()));
-
-       okbtn = new QPushButton(&dlg);
-       okbtn->setGeometry(270, 210, 100, 30);
-       okbtn->setText("Save files");
-       connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       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 (dialog.exec()) {
                if (!Nodes.isEmpty()) {
                        QListIterator<VLPEntry *> nodesIterator(Nodes);