Port most of the code to the Qt4
[vlp.git] / src / lgconfig / lgconfig.cpp
index b130153b47e11ceef37ac4d923de6f27a6c4c48b..70a8bbc732902ecc81c15d74cb4283fbc2deec79 100644 (file)
@@ -1,22 +1,22 @@
-#include <qapp.h>
-#include <qframe.h>
-#include <qmlined.h>
-#include <qmenubar.h>
-#include <qpopmenu.h>
-#include <qdialog.h>
-#include <qbttngrp.h>
-#include <qlabel.h>
-#include <qlined.h>
-#include <qlistbox.h>
-#include <qpushbt.h>
-#include <qradiobt.h>
-#include <qlist.h>
-#include <qfile.h>
-#include <qcombo.h>
-#include <qtooltip.h>
-#include <qfont.h>
-#include <qpixmap.h>
-#include <qmsgbox.h>
+#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>
@@ -34,13 +34,13 @@ public:
        char item[255];
 };
 
-class QInstall: public QFrame {
+class QInstall: public QMainWindow {
        Q_OBJECT
 public:
        QMenuBar *bar;
-       QListBox *nodelist;
+       Q3ListBox *nodelist;
        QPushButton *infob;
-       QList<VLPEntry> Nodes;
+       QList<VLPEntry*> Nodes;
 
        QInstall();
        bool check_id(int);
@@ -61,19 +61,25 @@ QInstall::QInstall()
        QFont f("Helvetica", 12, QFont::Bold);
        QPixmap mp;
 
-       infob = new QPushButton(this);
+//     infob = new QPushButton(this);
 
-       bar = new QMenuBar(this);
-       bar->insertItem("Configure", this, SLOT(SetOptions()));
-       bar->insertItem("Quit", app, SLOT(quit()));
-       bar->setFont(f);
-       setCaption("VLP Configuration Tool");
-       infob->setGeometry(0, bar->height(), 200, 30);
+       setWindowTitle("VLP Configuration Tool");
+
+       QMenu * programMenu = NULL;
+       programMenu = menuBar()->addMenu("&Program");
+       programMenu->addAction("Configure", this, SLOT(SetOptions()));
+       programMenu->addAction("Quit", app, SLOT(quit()));
+
+//     bar = new QMenuBar(this);
+//     bar->insertItem("Configure", this, SLOT(SetOptions()));
+//     bar->insertItem("Quit", app, SLOT(quit()));
+//     bar->setFont(f);
+//     infob->setGeometry(0, bar->height(), 200, 30);
        if (mp.load("logo.bmp")) {
-               infob->setPixmap(mp);
-               infob->resize(mp.width(), mp.height());
+//             infob->setPixmap(mp);
+//             infob->resize(mp.width(), mp.height());
        }
-       resize(infob->width(), infob->height() + bar->height());
+//     resize(infob->width(), infob->height() + bar->height());
        Nodes.clear();
 }
 
@@ -85,7 +91,7 @@ bool QInstall::check_id(int id)
        while (pom != NULL) {
                if (pom->ID == id)
                        return FALSE;
-               pom = Nodes.next();
+               pom = Nodes.takeFirst();
        }
        return TRUE;
 }
@@ -98,7 +104,7 @@ bool QInstall::check_addr(char *addr)
        while (pom != NULL) {
                if (strcmp(pom->addr, addr) == 0)
                        return FALSE;
-               pom = Nodes.next();
+               pom = Nodes.takeFirst();
        }
        return TRUE;
 }
@@ -112,82 +118,81 @@ void QInstall::Info()
 
 void QInstall::AddNode()
 {
-       QDialog dlg(this, "", TRUE);
+       QDialog dlg(this);
        QLabel *tmpQLabel;
        QLineEdit *id, *addr, *progs, *home;
        QPushButton *okbtn, *cancelbtn;
        VLPEntry *pom;
        char pomstr[255];
 
-       tmpQLabel = new QLabel(&dlg, "Label_2");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(110, 10, 180, 30);
        tmpQLabel->setFrameStyle(49);
        tmpQLabel->setText("Virtual Processor Properties");
 
-       id = new QLineEdit(&dlg, "LineEdit_1");
+       id = new QLineEdit(&dlg);
        id->setGeometry(130, 50, 50, 30);
        id->setText("");
 
-       tmpQLabel = new QLabel(&dlg, "Label_3");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(20, 50, 90, 30);
        tmpQLabel->setText("Node number");
 
-       tmpQLabel = new QLabel(&dlg, "Label_4");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(20, 90, 80, 30);
        tmpQLabel->setText("IP Address");
 
-       addr = new QLineEdit(&dlg, "LineEdit_2");
+       addr = new QLineEdit(&dlg);
        addr->setGeometry(130, 90, 120, 30);
        addr->setText("");
 
-       tmpQLabel = new QLabel(&dlg, "Label_5");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(20, 130, 100, 30);
        tmpQLabel->setText("Connection type");
 
        QComboBox* tmpQComboBox;
-       tmpQComboBox = new QComboBox(FALSE, &dlg, "ComboBox_1");
+       tmpQComboBox = new QComboBox(&dlg);
        tmpQComboBox->setGeometry(130, 130, 100, 30);
-       tmpQComboBox->setSizeLimit(2);
-       tmpQComboBox->setAutoResize(FALSE);
-       tmpQComboBox->insertItem("Explicit");
+//     tmpQComboBox->setSizeLimit(2);
+//     tmpQComboBox->setAutoResize(FALSE);
+       tmpQComboBox->insertItem(0, "Explicit");
 
-       tmpQLabel = new QLabel(&dlg, "Label_6");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(20, 170, 110, 30);
        tmpQLabel->setText("Programs directory");
 
-       progs = new QLineEdit(&dlg, "LineEdit_4");
+       progs = new QLineEdit(&dlg);
        progs->setGeometry(130, 170, 230, 30);
        progs->setText("");
 
-       tmpQLabel = new QLabel(&dlg, "Label_7");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(20, 210, 100, 30);
        tmpQLabel->setText("VLP directory");
 
-       home = new QLineEdit(&dlg, "LineEdit_5");
+       home = new QLineEdit(&dlg);
        home->setGeometry(130, 210, 230, 30);
        home->setText("");
 
-       okbtn = new QPushButton(&dlg, "PushButton_5");
+       okbtn = new QPushButton(&dlg);
        okbtn->setGeometry(80, 250, 100, 30);
        okbtn->setText("Ok");
        connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
-       cancelbtn = new QPushButton(&dlg, "PushButton_6");
+       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 = atoi(id->text());
+               pom->ID = id->text().toInt();
                if (check_id(pom->ID)) {
-                       strcpy(pom->addr, addr->text());
+                       strcpy(pom->addr, addr->text().toStdString().c_str());
                        if (check_addr(pom->addr)) {
-                               if (strcmp(tmpQComboBox->currentText(),
-                                                       "Explicit") == 0) {
+                               if (tmpQComboBox->currentText() == "Explicit") {
                                        pom->type=0;
                                }
-                               strcpy(pom->progdir, progs->text());
-                               strcpy(pom->homedir, home->text());
+                               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"
@@ -195,13 +200,10 @@ void QInstall::AddNode()
                                nodelist->insertItem(pomstr);
                                strcpy(pom->item, pomstr);
                        } else {
-                               QMessageBox::message("Error!",
-                                       "Only one VLP on a single computer!",
-                                       "Ok");
+                               QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", "Ok");
                        }
                } else {
-                       QMessageBox::message("Error!", "ID must be unique!",
-                                                                       "Ok");
+                       QMessageBox::warning(this, "Error!", "ID must be unique!", "Ok");
                }
        }
 }
@@ -212,25 +214,24 @@ void QInstall::DelNode()
        VLPEntry *vpom;
 
        if (nodelist->currentItem() >= 0) {
-               strcpy(pom, nodelist->text(nodelist->currentItem()));
+               strcpy(pom, nodelist->text(nodelist->currentItem()).toStdString().c_str());
                vpom = Nodes.first();
                while (vpom != NULL) {
                        if (strcmp(pom, vpom->item) == 0)
                                break;
-                       vpom = Nodes.next();
+                       vpom = Nodes.takeFirst();
                }
                if (vpom != NULL)
-                       if (QMessageBox::query("Delete VLP", "Are you sure?",
-                                                               "Yes", "No")) {
+                       if (QMessageBox::question(this, "Delete VLP", "Are you sure?", "Yes", "No")) {
                                nodelist->removeItem(nodelist->currentItem());
-                               Nodes.remove(vpom);
+                               Nodes.removeOne(vpom);
                        }
        }
 }
 
 void QInstall::SetOptions()
 {
-       QDialog dlg(this, "", TRUE);
+       QDialog dlg(this);
        QLabel *tmpQLabel;
        QPushButton *addbtn, *delbtn, *okbtn, *cancelbtn;
        VLPEntry *pom;
@@ -238,29 +239,29 @@ void QInstall::SetOptions()
        char pomstr[255];
 
        //dlg.setStyle(WindowsStyle);
-       nodelist = new QListBox(&dlg, "ListBox_1");
+       nodelist = new Q3ListBox(&dlg);
        nodelist->setGeometry(20, 40, 480, 160);
 
-       tmpQLabel = new QLabel(&dlg, "Label_1");
+       tmpQLabel = new QLabel(&dlg);
        tmpQLabel->setGeometry(20, 10, 100, 30);
        tmpQLabel->setText("Nodes:");
 
-       addbtn = new QPushButton(&dlg, "PushButton_1");
+       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, "PushButton_2");
+       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, "PushButton_3");
+       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, "PushButton_4");
+       cancelbtn = new QPushButton(&dlg);
        cancelbtn->setGeometry(390, 210, 100, 30);
        cancelbtn->setText("Cancel");
        connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
@@ -271,7 +272,7 @@ void QInstall::SetOptions()
                if (!Nodes.isEmpty()) {
                        pom = Nodes.first();
                        while (pom != NULL) {
-                               j = Nodes.at();
+                               j = Nodes.indexOf(pom);
                                sprintf(pomstr, "%s.cfg", pom->addr);
 
                                config_t cfg;
@@ -321,7 +322,7 @@ void QInstall::SetOptions()
                                config_destroy(&cfg);
 
                                pom = Nodes.at(j);
-                               pom = Nodes.next();
+                               pom = Nodes.takeFirst();
                        }
                }
        }
@@ -334,7 +335,7 @@ int main(int argc, char **argv)
        app = new QApplication(argc,argv);
        QInstall cfg;
        //app->setStyle(WindowsStyle);
-       app->setMainWidget(&cfg);
+//     app->setMainWidget(&cfg);
        cfg.show();
        return app->exec();
 }