Move configuration dialog code into separate class. Extract layout code into separate...
[vlp.git] / src / kernel / kernel.cpp
index 8ab19f17dcbda4cd62500b724e63a2e62e15195a..2f45322ef2cd18c9d162b4814f49ad272bcc236c 100644 (file)
@@ -37,7 +37,7 @@
 #include <QtGui/QMessageBox>
 #include <QtGui/QFileDialog>
 #include <QtGui/QDialog>
-#include <qstring.h>
+#include <QtCore/QString>
 #include <QtGui/QLabel>
 #include <QtGui/QLineEdit>
 #include <QtGui/QPushButton>
@@ -49,6 +49,7 @@
 #include <qfile.h>
 #include <qcursor.h>
 #include <QtCore/QSocketNotifier>
+#include <QtGui/QCloseEvent>
 #include <qdir.h>
 
 #include <stdio.h>
 #include <fcntl.h>
 
 #include "genint1.h"
-#include "comm.h"
 #include "socu.h"
 #include <netinet/in.h>
 
 #include <libconfig.h>
 
+#include "kernel.h"
+#include "kernelwindow.h"
+#include "lock.h"
+#include "options.h"
+
 /* File resides in top directory (where are Makefiles)*/
 #include "../../config.h"
 
-#define GPATH "loggr"
-#define IPATH "logi"
-#define NPATH "logn"
-#define REMOTE_PATH "REMOTE"
-#define MAXINTERP 20
-#define MAXINSTANCES 256 
-
-
-#define MESG_COL       0
-#define WARN_COL       1
-#define NORM_COL       2
-
 
 char CharLine[25] = "________________________";
 char myargs[5][255];
 
-/**
- * Interpreter slot
- */
-class InterpEntry {
-public:
-       /** Interpreter identifier */
-       int ID;
-       /** Defines if interpreter is remote or not */
-       bool remote;
-       /* Program name */
-       char fullname[255];
-       char shortname[255];
-       
-       /* Socket */
-       int sock;
-       QSocketNotifier *notify;
-       /* IDs of my remote INT modules */
-       int RInstances[MAXINSTANCES];
-       /* Parent interpreter info */
-       ctx_struct p_ctx;
-};
-
-/**
- * Connection slot
- */
-class ConnectEntry {
-public:
-       char addr[256];
-       
-       ConnectEntry(char *s) {
-               strcpy(addr, s);
-       };
-};
-
-QApplication *app;
-
-/**
- * Kernel class
- */
-class QKernel : public QMainWindow {
-       Q_OBJECT
-public:
-       QTextEdit *desktop;
-       QMenuBar *bar;
-       QMenu *programMenu;
-       QMenu *machineMenu;
-       QMenu *toolsMenu;
-       char progdir[256];
-       int NodeNumber;
-       int ConType;
-
-       QKernel();
-
-       virtual void resizeEvent(QResizeEvent *ev);
-
-       void WriteMessage(char* msg);
-       void InitMessage();
-
-public slots:
-       void n_impl();
-       void Run_Prog();
-       void Edit();
-       void Help();
-       void SetOptions();
-       void AddAddress();
-       void DelAddress();
-       void LockConsole();
-       void UnlockConsole();
-       void MessageToNode();
-       void QuitProc();
-       void NetMessage();
-       void IntMessage(int);
-       void KillInterpreter();
-       void Disconnect();
-       void SetMessages();
-       void Connect();
-       void Info();
-
-protected:
-       virtual void closeEvent (QCloseEvent * e);
-
-private:
-       QList<InterpEntry*> Interpreters;
-       QList<ConnectEntry*> ConnectList;
-       QListWidget *connections;
-       
-       /**
-        * number of working interpreters
-        * @attention Currently not in use
-        */
-       int Tasks;
-       
-       /**
-        * number of connected VLPs
-        */
-       int ActiveConnections;
-       bool LOCKED;
-       bool synchro;
-       bool wait_for_info;
-       char LockPasswd[25];
-       QAction * lockid;
-       QAction * unlockid;
-       QAction * qid;
-       QAction * cwid;
-       QAction * optid;
-       QAction * prid;
-       QAction * mid;
-       QAction * msgid;
-       QAction * toolsid;
-       QAction * hid;
-       
-       int net_sock;
-       int freeINTid;
-       QSocketNotifier *Net_Notify;
-       char HomeDir[255];
-       bool info_messages;
-
-       void LoadConfig(char *);
-       void RunGraphModule(char*);
-       void RunNetModule();
-       InterpEntry *findINTbySocket(int);
-       InterpEntry *findINTbyID(int);
-       InterpEntry *RunIntModule(char *ss, int r);
-       void RemoteInstance(InterpEntry*, int);
-       void CloseInstances(InterpEntry*);
-};
+//QApplication *app;
 
 /**
  * Event invoked on program close.
@@ -215,7 +83,32 @@ private:
  */
 void QKernel::closeEvent(QCloseEvent * e)
 {
-       QuitProc();
+       e->ignore();
+
+       if (!LOCKED) {
+               on_actionQuit_triggered();
+       }
+}
+
+void QKernel::setLocked(bool locked)
+{
+       LOCKED = locked;
+
+       actionQuit->setDisabled(locked);
+
+       actionExecute->setDisabled(locked);
+       actionKill->setDisabled(locked);
+       actionMessage->setDisabled(locked);
+       actionConnect->setDisabled(locked);
+       actionDisconnect->setDisabled(locked);
+       actionInfo->setDisabled(locked);
+
+
+       /* Enable only menu entry for unlocking */
+       actionEditor->setDisabled(locked);
+       actionOptions->setDisabled(locked);
+       actionLock_console->setDisabled(locked);
+       actionUnlock_console->setDisabled(!locked);
 }
 
 /**
@@ -224,6 +117,8 @@ void QKernel::closeEvent(QCloseEvent * e)
  */
 QKernel::QKernel()
 {
+       setupUi(this);
+
        QDir q(REMOTE_PATH);
        char ss[255];
 
@@ -237,46 +132,8 @@ QKernel::QKernel()
 
        setWindowTitle(PACKAGE_NAME);
 
-       QMenu * programMenu = NULL;
-       programMenu = menuBar()->addMenu("&Program");
-       programMenu->addAction("Execute", this, SLOT(Run_Prog()));
-       programMenu->addAction("Kill", this, SLOT(KillInterpreter()));
-       
-
-       machineMenu = menuBar()->addMenu("&Machine");
-       machineMenu->addAction("Message", this, SLOT(MessageToNode()));
-       machineMenu->addSeparator();
-       machineMenu->addAction("Connect", this, SLOT(Connect()));
-       machineMenu->addAction("Disconnect", this, SLOT(Disconnect()));
-       machineMenu->addAction("Info", this, SLOT(Info()));
-
-       toolsMenu = menuBar()->addMenu("&Tools");
-       cwid = toolsMenu->addAction("Editor", this, SLOT(Edit()));
-       hid = toolsMenu->addAction("Help", this, SLOT(Help()));
-       toolsMenu->addSeparator(); 
-       optid = toolsMenu->addAction("Options", this, SLOT(SetOptions()));
-       msgid = toolsMenu->addAction("Info messages", this, SLOT(SetMessages()));
-       msgid->setCheckable(TRUE);
-       msgid->setChecked(TRUE);
-       toolsMenu->addSeparator(); 
-       lockid = toolsMenu->addAction("Lock console", this, SLOT(LockConsole()));
-       unlockid = toolsMenu->addAction("Unlock console", this, 
-                                                       SLOT(UnlockConsole()));
-       unlockid->setDisabled(TRUE);
        LOCKED = FALSE;
 
-       qid = menuBar()->addAction("&Quit", this, SLOT(QuitProc()));
-
-       desktop = new QTextEdit(this);
-       desktop->setReadOnly(TRUE);
-       QVBoxLayout * layout = new QVBoxLayout();
-       layout->setContentsMargins (3, 0, 3, 0);
-       layout->addWidget(desktop);
-       QWidget *window = new QWidget();
-       window->setLayout(layout);
-       setCentralWidget(window);
-
-       resize(400, 200);
        Tasks = 0;
        freeINTid = 1;
        ActiveConnections = 0;
@@ -288,18 +145,6 @@ QKernel::QKernel()
        connect(Net_Notify, SIGNAL(activated(int)), this, SLOT(NetMessage()));
 }
 
-/**
- * Event invoked on resizing kernel application window.
- * @copydoc QWidget::resizeEvent(QResizeEvent*)
- */
-void QKernel::resizeEvent(QResizeEvent *ev)
-{
-//     QFrame::resizeEvent(ev);
-//     if (desktop)
-//             desktop->setGeometry(0, bar->height(), width(), 
-//                                             height() - bar->height());
-}
-
 /**
  * Displays window with information about not implemented functionality.
  */
@@ -338,7 +183,7 @@ void QKernel::LoadConfig(char * fname)
                        config_error_line(&cfg));
                config_destroy(&cfg);
                fclose(file);
-               exit(3);/* from original code. */
+               exit(3);
        }
 
        setting = config_lookup(&cfg, "node_number");
@@ -416,7 +261,7 @@ void QKernel::LoadConfig(char * fname)
  * Executes program.
  * Additional window id displayed to set which code to execute.
  */
-void QKernel::Run_Prog()
+void QKernel::on_actionExecute_triggered()
 {
        int i;
        QString s = QFileDialog::getOpenFileName(this, "Execute", progdir, "*.log");
@@ -434,7 +279,7 @@ void QKernel::Run_Prog()
 /**
  * Invokes editor program
  */
-void QKernel::Edit()
+void QKernel::on_actionEditor_triggered()
 {
        char cmd[255];
        sprintf(cmd, "%s/modules/logedit %s %s %s %s %s %s &", HomeDir, HomeDir, 
@@ -445,10 +290,10 @@ void QKernel::Edit()
 /**
  * Invokes help program
  */
-void QKernel::Help()
+void QKernel::on_actionHelp_triggered()
 {
        char cmd[255];
-       sprintf(cmd, "%s/modules/loghelp %s/doc %s %s %s %s %s &", HomeDir, 
+       sprintf(cmd, "%s/modules/loghelp %s/doc %s %s %s %s %s &", HomeDir,
                HomeDir, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
        system(cmd);
 }
@@ -460,9 +305,8 @@ void QKernel::RunGraphModule(char *sk)
 {
        char cmd[255];
 
-       sprintf(cmd, "%s/modules/loggraph %s %s %s %s %s %s", HomeDir, sk, 
-                       myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
-       strcat(cmd, " &");
+       sprintf(cmd, "%s/modules/loggraph %s %s %s %s %s %s &", HomeDir,
+               sk, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
 
        if (system(cmd) != 0)
                WriteMessage("Cannot connect GRAPH resources");
@@ -477,9 +321,8 @@ void QKernel::RunNetModule()
        int len, on;
        int sock;
        char cmd[255];
-       sprintf(cmd, "%s/modules/lognet %s %s %s %s %s %s", HomeDir, NPATH, 
-                       myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
-       strcat(cmd, " &");
+       sprintf(cmd, "%s/modules/lognet %s %s %s %s %s %s &", HomeDir,
+               NPATH, myargs[0], myargs[1], myargs[2], myargs[3], myargs[4]);
 
        /* -------- socket for NET module -------- */
        unlink(NPATH);
@@ -505,14 +348,14 @@ void QKernel::RunNetModule()
                        WriteMessage("Cannot connect NETWORK resources");
                        WriteMessage("Exiting...");
                        sleep(2);
-                       QuitProc(); 
+                       on_actionQuit_triggered();
                }
        /* system OK */
        } else {
                WriteMessage("Cannot connect NETWORK resources");
                WriteMessage("Exiting...");
                sleep(2);
-               QuitProc(); 
+               on_actionQuit_triggered();
        }
 }
 
@@ -520,7 +363,7 @@ void QKernel::RunNetModule()
  * Connects to the specified address
  * Additional window is displayed to connect to the specified address
  */
-void QKernel::Connect()
+void QKernel::on_actionConnect_triggered()
 {
        QDialog d(this, Qt::Dialog);
        QLabel lab("IP Address:", &d);
@@ -552,7 +395,7 @@ void QKernel::Connect()
 /**
  * Disconnects from virtual machine
  */
-void QKernel::Disconnect()
+void QKernel::on_actionDisconnect_triggered()
 {
        MESSAGE msg;
 
@@ -567,72 +410,31 @@ void QKernel::Disconnect()
 /**
  * Quits process. Closes VLP. Shows additional window to confirm exit. 
  */
-void QKernel::QuitProc()
+void QKernel::on_actionQuit_triggered()
 {
        MESSAGE msg;
 
-       if (QMessageBox::question(this, "Close VLP", "Terminate VLP ?", 
-               QMessageBox::Yes, QMessageBox::No, 0) == QMessageBox::No) {
-               return;
-       }
-       
-       if (!LOCKED) {
-               /* 
-               msg.msg_type = MSG_NET;
-               msg.param.pword[0] = NET_DISCONNECT;
-               write(net_sock, &msg, sizeof(MESSAGE));*/
-               delete Net_Notify;
-
-               msg.msg_type = MSG_NET;
-               msg.param.pword[0] = NET_EXIT;
-               write(net_sock, &msg, sizeof(MESSAGE));
-               /*  ::close(net_sock);*/
-               app->quit();
-       }
-}
+       QMessageBox::StandardButton response = QMessageBox::question(this,
+               "Close VLP",
+               "Terminate VLP ?",
+               QMessageBox::Ok | QMessageBox::Cancel
+       );
 
-/**
- * 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());
-                       }
+       if (response == QMessageBox::Cancel) {
+               return;
        }
-}
+       /*
+       msg.msg_type = MSG_NET;
+       msg.param.pword[0] = NET_DISCONNECT;
+       write(net_sock, &msg, sizeof(MESSAGE));*/
+       delete Net_Notify;
 
-/**
- * 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());
-               }
-       }
+       msg.msg_type = MSG_NET;
+       msg.param.pword[0] = NET_EXIT;
+       write(net_sock, &msg, sizeof(MESSAGE));
+       /*  ::close(net_sock);*/
+       QApplication::instance()->quit();
 }
 
 /**
@@ -640,7 +442,7 @@ void QKernel::DelAddress()
  * Additional window is displayed to set Node Number of node where send message,
  * and textfield to enter message.
  */
-void QKernel::MessageToNode()
+void QKernel::on_actionMessage_triggered()
 {
        QDialog *dlg;
        QLineEdit *nodenr;
@@ -693,7 +495,7 @@ void QKernel::MessageToNode()
  * Additional window is displayed to get ID of interpreter which should be
  * killed.
  */
-void QKernel::KillInterpreter()
+void QKernel::on_actionKill_triggered()
 {
        QDialog *dlg;
        QLineEdit *nodenr;
@@ -831,10 +633,8 @@ void QKernel::NetMessage()
                                                cnt = poms1.indexOf('=');
                                                if (cnt != -1) {
                                                        poms2 = poms1.left(cnt);
-                                                       poms1 = poms1.right(
-                                                               poms1.length() -
-                                                               cnt - 1);
-                                                       sprintf(ss, "Node: %s Addr: %s", poms2.data(), poms1.data());
+                                                       poms1 = poms1.right(poms1.length() - cnt - 1);
+                                                       sprintf(ss, "Node: %s Addr: %s", poms2.toStdString().c_str(), poms1.toStdString().c_str());
                                                        WriteMessage(ss); 
                                                }
                                        } 
@@ -954,18 +754,13 @@ void QKernel::WriteMessage(char *msg)
  * Adds checkbox to menu item. If it is checked additional info messages are
  * shown.
  */
-void QKernel::SetMessages()
+void QKernel::on_actionInfo_messages_triggered()
 {
        if (toolsMenu != NULL) {
-               if (msgid->isChecked()) {
-                       msgid->setChecked(FALSE);
-                       info_messages = FALSE;
-               } else {
-                       msgid->setChecked(TRUE);
-                       info_messages = TRUE;
-               }
+               info_messages = !actionInfo_messages->isChecked();
+               actionInfo_messages->setChecked(info_messages);
+               fprintf(stderr, "Info is checked? %s\n", info_messages ? "yes" : "no");
        }
-       /* bar->repaint(); */
 }
 
 /**
@@ -973,137 +768,12 @@ void QKernel::SetMessages()
  * Additional window is displayed to set kernel options which are saved in 
  * vlp.cfg file in kernel executable directory.
  */
-void QKernel::SetOptions()
+void QKernel::on_actionOptions_triggered()
 {
-       QDialog dlg(this, Qt::Dialog);
-       dlg.setWindowTitle("Options");
-       ConnectEntry *e;
-       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);
-
-       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++) {
-               e = ConnectList.at(i);
-               connections->addItem(e->addr);
-       }
-
-       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()) {
-               config_t cfg;
-               config_setting_t *root;
-               config_setting_t *setting;
-               config_init(&cfg);
-
-               root = config_root_setting(&cfg);
-
-               setting = config_setting_add(root, "progdir",
-                                                       CONFIG_TYPE_STRING);
-               config_setting_set_string(setting, progs->text().toAscii().data());
-               strcpy(progdir, progs->text().toAscii().data());
-
-               setting = config_setting_add(root, "node_number",
-                                                       CONFIG_TYPE_INT);
-               config_setting_set_int(setting, atoi(nn->text().toAscii().data()));
-
-               setting = config_setting_add(root, "homedir",
-                                                       CONFIG_TYPE_STRING);
-               config_setting_set_string(setting, HomeDir);
-
-               setting = config_setting_add(root, "type",
-                                                       CONFIG_TYPE_STRING);
-               if (exp->isChecked()) {
-                       config_setting_set_string(setting, "explicit");
-
-                       config_setting_t *hosts = NULL;
-                       hosts = config_setting_add(root, "host",
-                                                       CONFIG_TYPE_ARRAY);
-                       for(i = 0; i < connections->count(); i++) {
-                               setting = config_setting_add(hosts, NULL,
-                                                       CONFIG_TYPE_STRING);
-                               config_setting_set_string(setting,
-                                               connections->item(i)->text().toAscii().data());
-                       }
-               } else {
-                       config_setting_set_string(setting, "register");
-               }
-
-               if (!config_write_file(&cfg, "vlp.cfg")) {
-                       fprintf(stderr, "Error while writing to file: %s.\n", 
-                                                               "vlp.cfg");
-               }
-               config_destroy(&cfg);
+       OptionsDialog optionsDialog(this);
+       if (optionsDialog.exec()) {
+               optionsDialog.saveConfig("vlp.cfg");
+               LoadConfig("vlp.cfg");
        }
 }
 
@@ -1112,50 +782,27 @@ void QKernel::SetOptions()
  * Additional window is displayed to enter password and retype it. If both are
  * same kernel window is locked.
  */
-void QKernel::LockConsole()
+void QKernel::on_actionLock_console_triggered()
 {
-       QDialog d(this, Qt::Dialog);
-       d.setWindowTitle("Lock console");
-
-       QPushButton ob("Ok", &d);
-       ob.setGeometry(30, 60, 80, 30);
-       ob.setDefault(TRUE);
-       connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
-
-       QLabel lab("Password:", &d);
-       lab.setGeometry(10, 10, 60, 30);
-
-       QLineEdit ed("", &d);
-       ed.setGeometry(70, 10, 140, 30);
-       ed.setEchoMode(QLineEdit::Password);
-
-       QPushButton cb("Cancel", &d);
-       cb.setGeometry(130, 60, 80, 30);
-       connect(&cb, SIGNAL(clicked()), &d, SLOT(reject())); 
-
-       d.resize(240, 100);
-
-       if (d.exec()) {
-               if (strcmp(ed.text().toAscii().data(), "") != 0) {
-                       strcpy(LockPasswd, ed.text().toAscii().data());
-                       lab.setText("Retype:");
-                       ed.setText("");
-                       if (d.exec()) {
-                               if (strcmp(ed.text().toAscii().data(), LockPasswd)==0) {
-                                       qid->setEnabled(FALSE);
-                                       prid->setEnabled(FALSE);
-                                       mid->setEnabled(FALSE);
-                                       unlockid->setEnabled(TRUE);
-                                       lockid->setEnabled(FALSE);
-                                       cwid->setEnabled(FALSE);
-                                       optid->setEnabled(FALSE);
+       LockDialog lockDialog(this);
+
+       if (lockDialog.exec()) {
+               QString password = lockDialog.getPassword();
+               if (lockDialog.getPassword().size() > 0) {
+                       strcpy(LockPasswd, password.toAscii().data());
+                       lockDialog.retype();
+
+                       if (lockDialog.exec()) {
+                               password = lockDialog.getPassword();
+                               if (password == LockPasswd) {
+                                       setLocked(TRUE);
                                        WriteMessage("CONSOLE LOCKED");
-                                       LOCKED = TRUE;
                                } else {
                                        QMessageBox msg(this);
                                        msg.setText("Not matching!");
                                        msg.setButtonText(0, "Close");
                                        msg.show();
+                                       strcpy(LockPasswd, "");
                                }
                        } else {
                                strcpy(LockPasswd, "");
@@ -1169,7 +816,7 @@ void QKernel::LockConsole()
  * Additional window is displayed to enter password. If it is correct, kernel 
  * window is unlocked
  */
-void QKernel::UnlockConsole()
+void QKernel::on_actionUnlock_console_triggered()
 {
        QDialog d(this, Qt::Dialog);
        d.setWindowTitle("Enter password");
@@ -1188,21 +835,14 @@ void QKernel::UnlockConsole()
 
        QPushButton cb("Cancel", &d);
        cb.setGeometry(130, 60, 80, 30);
-       connect(&cb, SIGNAL(clicked()), &d, SLOT(reject())); 
+       connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
 
        d.resize(240, 100);
 
        if (d.exec()) {
                if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) {
-                       qid->setEnabled(TRUE);
-                       prid->setEnabled(TRUE);
-                       mid->setEnabled(TRUE);
-                       unlockid->setEnabled(FALSE);
-                       lockid->setEnabled(TRUE);
-                       cwid->setEnabled(TRUE);
-                       optid->setEnabled(TRUE);
+                       setLocked(FALSE);
                        WriteMessage("CONSOLE UNLOCKED");
-                       LOCKED = FALSE;
                } else {
                        QMessageBox msg(this);
                        msg.setText("Wrong password!");
@@ -1271,7 +911,8 @@ InterpEntry *QKernel::RunIntModule(char *ss, int r)
 {
        char a[256], b[255];
        struct sockaddr_un svr;
-       int len, sock, i, on;
+       int len, sock, on;
+       unsigned int i;
        int newint=-1;
        char cmd[255];
        FILE *cf;
@@ -1331,7 +972,7 @@ InterpEntry *QKernel::RunIntModule(char *ss, int r)
        len = strlen(svr.sun_path)+sizeof(svr.sun_family);
        bind(sock, (struct sockaddr*)&svr, len);
        listen(sock, 5);
-       system(cmd); 
+       system(cmd);
        newINT->sock = accept(sock, (struct sockaddr*)0, (unsigned int *)0);
        //::close(sock);
 
@@ -1340,7 +981,7 @@ InterpEntry *QKernel::RunIntModule(char *ss, int r)
                                O_NONBLOCK|fcntl(newINT->sock, F_GETFL, 0));
                on=1; 
                setsockopt(newINT->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on,
-                                                               sizeof(on)); 
+                                                               sizeof(on));
                if (r)
                        newINT->remote = 1;
                else 
@@ -1419,7 +1060,7 @@ void QKernel::RemoteInstance(InterpEntry *interp, int on)
                                interp->RInstances[on] = m.param.pword[7];
                                break;
                        }
-                       read(net_sock, &m, sizeof(MESSAGE));  
+                       read(net_sock, &m, sizeof(MESSAGE));
                }
 
                Net_Notify->setEnabled(TRUE);
@@ -1468,7 +1109,7 @@ void QKernel::CloseInstances(InterpEntry *e)
 /**
  * Displays information about virtual machine
  */
-void QKernel::Info()
+void QKernel::on_actionInfo_triggered()
 {
        MESSAGE m;
 
@@ -1480,8 +1121,6 @@ void QKernel::Info()
        wait_for_info = TRUE;
 }
 
-#include "kernel.moc"
-
 /**
  * Program main function
  * All program arguments but the first one (argv[0]: program name) are saved and
@@ -1499,7 +1138,7 @@ int main(int argc, char **argv)
                strcpy(myargs[i - 1], argv[i]);
        }
 
-       app = new QApplication(argc, argv);
+       QApplication * app = new QApplication(argc, argv);
        QKernel kernel;
        kernel.show();
        kernel.InitMessage();