Move kill interpreter dialog code to separate ui file
[vlp.git] / src / kernel / kernel.cpp
index 43f4efae145864ed7b35f0e865a1cf970ec03f99..2052fed9a47536a9de7512e551592b34ecf9ed77 100644 (file)
@@ -68,6 +68,7 @@
 #include "ui/kernelwindow.h"
 #include "lock.h"
 #include "options.h"
+#include "kill_interpreter_dialog.h"
 
 /* File resides in top directory (where are Makefiles)*/
 #include "../../config.h"
@@ -593,41 +594,21 @@ void QKernel::on_actionMessage_triggered()
  */
 void QKernel::on_actionKill_triggered()
 {
-       QDialog *dlg;
-       QLineEdit *nodenr;
-       MESSAGE m;
-       InterpEntry *pom;
-
-       dlg = new QDialog(this, Qt::Dialog);
-       dlg->setWindowTitle("Kill interpreter");
-
-       nodenr = new QLineEdit("", dlg); 
-       nodenr->setGeometry(90, 10, 50, 30);
-
-       QLabel * tmpQLabel = new QLabel("Interp. ID:", dlg);
-       tmpQLabel->setGeometry(10, 10, 77, 30);
-
-       QPushButton * ob = new QPushButton("Kill", dlg);
-       ob->setGeometry( 160, 10, 80, 30);
-       ob->setDefault(TRUE);
+       KillInterpreterDialog dialog(this);
+       dialog.setWindowTitle("Kill interpreter");
 
-       QPushButton * cb = new QPushButton("Cancel", dlg);
-       cb->setGeometry(260, 10, 80, 30);
-       dlg->resize(360, 50);
-
-       connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
-       connect(cb, SIGNAL(clicked()), dlg, SLOT(reject())); 
+       MESSAGE m;
+       InterpEntry *interpreter;
 
-       if (dlg->exec()) {
+       if (dialog.exec()) {
                m.msg_type = MSG_INT;
                m.param.pword[0] = INT_KILL;
-               pom = findINTbyID(atoi(nodenr->text().toAscii().data()));
-               if (pom != NULL) {
-                       if (!(pom->remote))
-                               write(pom->sock, &m, sizeof(MESSAGE));
+               interpreter = findINTbyID(dialog.getInterpreterId());
+               if (interpreter != NULL) {
+                       if (!(interpreter->remote))
+                               write(interpreter->sock, &m, sizeof(MESSAGE));
                        else
-                               WriteMessage("This is a remote instance of "
-                                                               "a program!");
+                               WriteMessage("This is a remote instance of a program!");
                }
                else {
                        WriteMessage("Interpreter not found");
@@ -885,7 +866,7 @@ void QKernel::on_actionLock_console_triggered()
        if (lockDialog.exec()) {
                QString password = lockDialog.getPassword();
                if (lockDialog.getPassword().size() > 0) {
-                       strcpy(LockPasswd, password.toAscii().data());
+                       strcpy(LockPasswd, password.toStdString().c_str());
                        lockDialog.retype();
 
                        if (lockDialog.exec()) {
@@ -914,29 +895,11 @@ void QKernel::on_actionLock_console_triggered()
  */
 void QKernel::on_actionUnlock_console_triggered()
 {
-       QDialog d(this, Qt::Dialog);
-       d.setWindowTitle("Enter password");
-
-       QLabel lab("Password:", &d);
-       lab.setGeometry(10, 10, 60, 30);
-
-       QLineEdit ed("", &d);
-       ed.setGeometry(70, 10, 140, 30);
-       ed.setEchoMode(QLineEdit::Password);
-
-       QPushButton ob("Ok", &d);
-       ob.setGeometry(30, 60, 80, 30);
-       ob.setDefault(TRUE);
-       connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
-
-       QPushButton cb("Cancel", &d);
-       cb.setGeometry(130, 60, 80, 30);
-       connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
-
-       d.resize(240, 100);
+       LockDialog lockDialog(this);
 
-       if (d.exec()) {
-               if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) {
+       if (lockDialog.exec()) {
+               QString password = lockDialog.getPassword();
+               if (strcmp(password.toStdString().c_str(), LockPasswd) == 0) {
                        setLocked(FALSE);
                        WriteMessage("CONSOLE UNLOCKED");
                } else {