Extract layout code to ui file
[vlp.git] / src / kernel / kernel.cpp
index 086ed6349bb68367c24d23203a35253898d080eb..98debb07475a8446070aaeb5d7985e0d386d32b9 100644 (file)
 ************************************************************/
 
 
-#include <qpixmap.h>
-//#include <qwindow.h>
-#include <qapp.h>
-#include <qframe.h>
-#include <qmlined.h>
-#include <qpainter.h>
-#include <qcolor.h>
-#include <qbrush.h>
-#include <qmenubar.h>
-#include <qpopmenu.h>
-#include <qfont.h>
-#include <qmsgbox.h>
-#include <qfiledlg.h>
-#include <qtabdlg.h>
-#include <qstring.h>
-#include <qrect.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 <QtGui/QApplication>
+#include <QtGui/QMainWindow>
+#include <QtGui/QTextEdit>
+#include <QtGui/QMenuBar>
+#include <QtGui/QMessageBox>
+#include <QtGui/QFileDialog>
+#include <QtGui/QDialog>
+#include <QtCore/QString>
+#include <QtGui/QLabel>
+#include <QtGui/QLineEdit>
+#include <QtGui/QPushButton>
+#include <QtGui/QRadioButton>
+#include <QtGui/QGroupBox>
+#include <QtGui/QVBoxLayout>
+#include <QtCore/QList>
+#include <QtGui/QListWidget>
 #include <qfile.h>
 #include <qcursor.h>
-#include <qcombo.h>
-#include <qsocknot.h>
+#include <QtCore/QSocketNotifier>
+#include <QtGui/QCloseEvent>
 #include <qdir.h>
-#include <qwindowsstyle.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
 
 #include "genint1.h"
-#include "comm.h"
 #include "socu.h"
 #include <netinet/in.h>
 
 #include <libconfig.h>
 
-#define GPATH "loggr"
-#define IPATH "logi"
-#define NPATH "logn"
-#define REMOTE_PATH "REMOTE"
-#define MAXINTERP 20
-#define MAXINSTANCES 256 
+#include "kernel.h"
+#include "kernelwindow.h"
 
-
-#define MESG_COL       0
-#define WARN_COL       1
-#define NORM_COL       2
+/* File resides in top directory (where are Makefiles)*/
+#include "../../config.h"
 
 
 char CharLine[25] = "________________________";
 char myargs[5][255];
 
+//QApplication *app;
 
-/* --------------- interpreter slot -----------------*/
-class InterpEntry {
-public:
-       /* INT identifier */
-       int ID;
-       /* Am I remote ? */
-       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 INT info */
-       ctx_struct p_ctx;
-};
-/*++++++++++++++++++++++++++++++++++++++++++*/
-
-/*----------------- connection slot -------------*/
-class ConnectEntry {
-public:
-       char addr[256];
-       
-       ConnectEntry(char *s) {
-               strcpy(addr, s);
-       };
-};
-
-/* ++++++++++++++++++++++++++++++++++++++++++  */
-
-QApplication *app;
-
-
-/* ---------------------------------------------------------- */
-/*                 KERNEL CLASS DEFINITION                    */
-/* ---------------------------------------------------------- */
-
-class QKernel : public QFrame {
-       Q_OBJECT
-public:
-       QMultiLineEdit *desktop;                        
-       QMenuBar *bar;  
-       QPopupMenu *p;
-       QPopupMenu *p1;
-       QPopupMenu *p2;
-       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;
-       QListBox *connections;
-       
-       /**
-        * number of working interpreters
-        */
-       int Tasks;
-       
-       /**
-        * number of connected VLPs
-        */
-       int ActiveConnections;
-       bool LOCKED;
-       bool synchro;
-       bool wait_for_info;
-       char LockPasswd[25];
-       int lockid;
-       int unlockid;
-       int qid;
-       int cwid;
-       int optid;
-       int prid;
-       int mid;
-       int msgid;
-       int toolsid;
-       int 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*);
-};
-/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
-
-void QKernel::closeEvent (QCloseEvent * e)
+/**
+ * Event invoked on program close.
+ * Closes application. Displays additional window to confirm exit.
+ */
+void QKernel::closeEvent(QCloseEvent * e)
 {
        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);
+}
+
+/**
+ * Kernel program constructor.
+ * Prepares everything to work.
+ */
 QKernel::QKernel()
 {
-       QFont f("Helvetica", 10, QFont::Bold);
-       QFont f1("Helvetica", 10, QFont::Normal);
-       QFont f2("Times Roman", 10, QFont::Normal);
+       setupUi(this);
+
        QDir q(REMOTE_PATH);
        char ss[255];
 
@@ -239,50 +128,10 @@ QKernel::QKernel()
        info_messages = TRUE;
        wait_for_info = FALSE;
 
-       setCaption("Virtual LOGLAN Processor");
-       setBackgroundColor(white);
-
-       bar = new QMenuBar(this);
-       bar->setFont(f); 
-       p = new QPopupMenu();
-       p->setFont(f2);
-       p->insertItem("Execute", this, SLOT(Run_Prog()));
-       p->insertItem("Kill", this, SLOT(KillInterpreter()));
-       prid = bar->insertItem("&Program", p);
-       p1 = new QPopupMenu();
-       p1->insertItem("Message", this, SLOT(MessageToNode()));
-       p1->insertSeparator();
-       p1->insertItem("Connect", this, SLOT(Connect()));
-       p1->insertItem("Disconnect", this, SLOT(Disconnect()));
-       p1->insertItem("Info", this, SLOT(Info()));
-       p1->setFont(f);
-       mid = bar->insertItem("&Machine", p1);
-
-       p2 = new QPopupMenu();
-       cwid = p2->insertItem("Editor", this, SLOT(Edit()));
-       hid = p2->insertItem("Help", this, SLOT(Help()));
-       p2->insertSeparator(); 
-       optid = p2->insertItem("Options", this, SLOT(SetOptions()));
-       msgid = p2->insertItem("Info messages", this, SLOT(SetMessages()));
-       p2->setItemChecked(msgid, TRUE);
-       p2->insertSeparator(); 
-       lockid = p2->insertItem("Lock console", this, SLOT(LockConsole()));
-       unlockid = p2->insertItem("Unlock console", this, 
-                                                       SLOT(UnlockConsole()));
-       p2->setItemEnabled(unlockid, FALSE);
-       LOCKED = FALSE;
-       p2->setFont(f);
-       toolsid = bar->insertItem("&Tools", p2);
-
-       qid = bar->insertItem("&Quit", this, SLOT(QuitProc()));
-       p->setFont(f);
+       setWindowTitle(PACKAGE_NAME);
 
-       desktop = new QMultiLineEdit(this, "desktop");
-       desktop->setAutoUpdate(TRUE);
-       desktop->setReadOnly(TRUE);
-       desktop->setFont(f1);
+       LOCKED = FALSE;
 
-       resize(400, 200);
        Tasks = 0;
        freeINTid = 1;
        ActiveConnections = 0;
@@ -294,23 +143,19 @@ QKernel::QKernel()
        connect(Net_Notify, SIGNAL(activated(int)), this, SLOT(NetMessage()));
 }
 
-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.
+ */
 void QKernel::n_impl()
 {
        QMessageBox::information(this, "Function info", "This function is not "
                                                "implemented yet...", "Ok");
 }
 
-
-/* ###########     load configuration from file  ############# */
-
+/**
+ * Loads configuration from the given file.
+ * @param fname Filename of the configuration file.
+ */
 void QKernel::LoadConfig(char * fname)
 {
        config_t cfg;
@@ -336,7 +181,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");
@@ -409,24 +254,30 @@ void QKernel::LoadConfig(char * fname)
        config_destroy(&cfg);
        fclose(file);
 }
-/* +++++++++++++++++++++++++++++++++++++++++++++++ */
 
-void QKernel::Run_Prog()
+/**
+ * Executes program.
+ * Additional window id displayed to set which code to execute.
+ */
+void QKernel::on_actionExecute_triggered()
 {
        int i;
-       QString s(QFileDialog::getOpenFileName(progdir, "*.log", this));
-       
+       QString s = QFileDialog::getOpenFileName(this, "Execute", progdir, "*.log");
+
        if (!s.isNull()) {
-               i = s.find(".log");
-               
+               i = s.indexOf(".log");
+
                if (i > 0)
                        s.remove(i, 4);
-                       
-               RunIntModule((char*)s.ascii(), 0);
+
+               RunIntModule((char*)s.toAscii().data(), 0);
        }
 }
 
-void QKernel::Edit()
+/**
+ * Invokes editor program
+ */
+void QKernel::on_actionEditor_triggered()
 {
        char cmd[255];
        sprintf(cmd, "%s/modules/logedit %s %s %s %s %s %s &", HomeDir, HomeDir, 
@@ -434,38 +285,42 @@ void QKernel::Edit()
        system(cmd);
 }
 
-void QKernel::Help()
+/**
+ * Invokes help program
+ */
+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);
 }
 
-
+/**
+ * Invokes graphics module
+ */
 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");
 }
 
-
-
+/**
+ * Invokes net module
+ */
 void QKernel::RunNetModule()
 {
        struct sockaddr_un svr;
        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);
@@ -491,27 +346,30 @@ 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();
        }
 }
 
-void QKernel::Connect()
+/**
+ * Connects to the specified address
+ * Additional window is displayed to connect to the specified address
+ */
+void QKernel::on_actionConnect_triggered()
 {
-       QDialog d(this, "", TRUE);
-       QLabel lab(&d, "IP Address:");
-       QLineEdit ed(&d, "");
-       QPushButton ob(&d, "");
-       QPushButton cb(&d, "");
+       QDialog d(this, Qt::Dialog);
+       QLabel lab("IP Address:", &d);
+       QLineEdit ed("", &d);
+       QPushButton ob("", &d);
+       QPushButton cb("", &d);
        MESSAGE m;
 
-       d.setFont(QFont("Helvetica", 12, QFont::Bold)); 
        ob.setGeometry(30, 60, 80, 30);
        ob.setText("Ok");
        ob.setDefault(TRUE);
@@ -527,12 +385,15 @@ void QKernel::Connect()
        if (d.exec()) {
                m.msg_type = MSG_NET;
                m.param.pword[0] = NET_CONNECT_TO;
-               strcpy(m.param.pstr, ed.text());
+               strcpy(m.param.pstr, ed.text().toAscii().data());
                write(net_sock, &m, sizeof(MESSAGE)); 
        }
 }
 
-void QKernel::Disconnect()
+/**
+ * Disconnects from virtual machine
+ */
+void QKernel::on_actionDisconnect_triggered()
 {
        MESSAGE msg;
 
@@ -544,37 +405,45 @@ void QKernel::Disconnect()
        write(net_sock, &msg, sizeof(MESSAGE));
 }
 
-void QKernel::QuitProc()
+/**
+ * Quits process. Closes VLP. Shows additional window to confirm exit. 
+ */
+void QKernel::on_actionQuit_triggered()
 {
        MESSAGE msg;
 
-       if (QMessageBox::question(this, "Close VLP", "Terminate VLP ?", 
-               QMessageBox::Yes, QMessageBox::No, 0) == QMessageBox::No) {
+       QMessageBox::StandardButton response;
+       response = QMessageBox::question(this, "Close VLP", "Terminate VLP ?",
+               QMessageBox::Ok | QMessageBox::Cancel);
+
+
+       if (response == QMessageBox::Cancel) {
                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();
-       }
+       /*
+       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);*/
+       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, "", TRUE);
-       QLabel lab(&d, "IP Address:");
-       QLineEdit ed(&d, "");
-       QPushButton ob(&d, "");
-       QPushButton cb(&d, "");
+       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);
@@ -589,106 +458,114 @@ void QKernel::AddAddress()
                connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
                connect(&cb, SIGNAL(clicked()), &d, SLOT(reject())); 
                if (d.exec())
-                       if (strcmp(ed.text(), "") != 0) {
-                               connections->insertItem(ed.text());
+                       if (strcmp(ed.text().toAscii().data(), "") != 0) {
+                               connections->addItem(ed.text());
                        }
        }
 }
 
+/**
+ * Deletes current address from available connections.
+ */
 void QKernel::DelAddress()
 {
        if (connections) {
-               if (connections->currentItem() != -1)
-                       connections->removeItem(connections->currentItem());
+               if (connections->currentRow() != -1) {
+                       /* TODO: Checki if this work correctly after porting */
+                       connections->removeItemWidget(connections->currentItem());
+               }
        }
 }
 
-void QKernel::MessageToNode()
+/**
+ * Sends message to node.
+ * Additional window is displayed to set Node Number of node where send message,
+ * and textfield to enter message.
+ */
+void QKernel::on_actionMessage_triggered()
 {
        QDialog *dlg;
        QLineEdit *nodenr;
        MESSAGE m;
 
-       dlg = new QDialog(this, "Message", TRUE);
+       dlg = new QDialog(this, Qt::Dialog);
+       dlg->setWindowTitle("Send message to node");
 
-       nodenr = new QLineEdit(dlg, "number");
+       nodenr = new QLineEdit("number", dlg);
        nodenr->setGeometry(90, 10, 50, 30);
        nodenr->setText("");
 
        QLabel *tmpQLabel;
-       tmpQLabel = new QLabel(dlg, "Label_1");
+       tmpQLabel = new QLabel("Node number:", dlg);
        tmpQLabel->setGeometry(10, 10, 77, 30);
-       tmpQLabel->setText("Node number:");
 
-       tmpQLabel = new QLabel(dlg, "Label_2");
+       tmpQLabel = new QLabel("Message:", dlg);
        tmpQLabel->setGeometry(10, 50, 70, 30);
-       tmpQLabel->setText("Message:");
 
        QLineEdit *msg;
-       msg = new QLineEdit(dlg, "LineEdit_1");
+       msg = new QLineEdit("", dlg);
        msg->setGeometry(80, 60, 330, 30);
-       msg->setText("");
 
        QPushButton *ob;
-       ob = new QPushButton(dlg, "PushButton_1");
+       ob = new QPushButton("Send", dlg);
        ob->setGeometry(230, 10, 80, 30);
-       ob->setText("Send");
        ob->setDefault(TRUE);
        
        QPushButton *cb;
-       cb = new QPushButton(dlg, "PushButton_2");
+       cb = new QPushButton("Cancel", dlg);
        cb->setGeometry(330, 10, 80, 30);
-       cb->setText("Cancel");
        dlg->resize(430, 110);
        connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
-       connect(cb, SIGNAL(clicked()), dlg, SLOT(reject())); 
-       dlg->setCaption("Send message to node");
+       connect(cb, SIGNAL(clicked()), dlg, SLOT(reject()));
 
        if (dlg->exec()) {
                m.msg_type = MSG_NET;
                m.param.pword[0] = NET_PROPAGATE;
                m.param.pword[1] = MSG_VLP;
                m.param.pword[2] = NodeNumber;
-               m.param.pword[4] = atoi(nodenr->text());
+               m.param.pword[4] = atoi(nodenr->text().toAscii().data());
                m.param.pword[6] = VLP_WRITE;
-               strcpy(m.param.pstr, msg->text());
+               strcpy(m.param.pstr, msg->text().toAscii().data());
                write(net_sock, &m, sizeof(MESSAGE));
        }
 }
 
-void QKernel::KillInterpreter()
+/**
+ * Kills interpreter.
+ * Additional window is displayed to get ID of interpreter which should be
+ * killed.
+ */
+void QKernel::on_actionKill_triggered()
 {
        QDialog *dlg;
        QLineEdit *nodenr;
        MESSAGE m;
        InterpEntry *pom;
 
-       dlg = new QDialog(this, "Message", TRUE);
+       dlg = new QDialog(this, Qt::Dialog);
+       dlg->setWindowTitle("Kill interpreter");
 
-       nodenr = new QLineEdit(dlg, "number"); 
+       nodenr = new QLineEdit("", dlg); 
        nodenr->setGeometry(90, 10, 50, 30);
-       nodenr->setText("");
 
-       QLabel* tmpQLabel;
-       tmpQLabel = new QLabel(dlg, "Label_1");
+       QLabel * tmpQLabel = new QLabel("Interp. ID:", dlg);
        tmpQLabel->setGeometry(10, 10, 77, 30);
-       tmpQLabel->setText("Interp. ID:");
-       QPushButton* ob, *cb;
-       ob = new QPushButton(dlg, "PushButton_1");
+
+       QPushButton * ob = new QPushButton("Kill", dlg);
        ob->setGeometry( 160, 10, 80, 30);
-       ob->setText("Kill");
        ob->setDefault(TRUE);
-       cb = new QPushButton(dlg, "PushButton_2");
+
+       QPushButton * cb = new QPushButton("Cancel", dlg);
        cb->setGeometry(260, 10, 80, 30);
-       cb->setText("Cancel");
        dlg->resize(360, 50);
+
        connect(ob, SIGNAL(clicked()), dlg, SLOT(accept()));
        connect(cb, SIGNAL(clicked()), dlg, SLOT(reject())); 
-       dlg->setCaption("Kill interpreter");
+
        if (dlg->exec()) {
                m.msg_type = MSG_INT;
                m.param.pword[0] = INT_KILL;
-               pom = findINTbyID(atoi(nodenr->text()));
+               pom = findINTbyID(atoi(nodenr->text().toAscii().data()));
                if (pom != NULL) {
                        if (!(pom->remote))
                                write(pom->sock, &m, sizeof(MESSAGE));
@@ -702,8 +579,9 @@ void QKernel::KillInterpreter()
        }
 }
 
-
-
+/**
+ * Sends message to the net module.
+ */
 void QKernel::NetMessage()
 {
        
@@ -724,7 +602,7 @@ void QKernel::NetMessage()
                        case MSG_INT:
                                /*  pom = find_link_by_ID(msg.param.pword[5]);
                                msg.msg_type = MSG_NET;
-                               msg.param.pword[0] = NET_PROPAGATE;   
+                               msg.param.pword[0] = NET_PROPAGATE;
                                send_int(pom, &msg);*/
                                break;
                        case MSG_VLP:
@@ -773,7 +651,7 @@ void QKernel::NetMessage()
                                                WriteMessage("Instance not found"); 
                                        }
                                        break; 
-                               } /* VLP switch */        
+                               } /* VLP switch */
                        }/* switch */
                        break;
                case NET_CONNECTIONS:
@@ -788,11 +666,11 @@ void QKernel::NetMessage()
                                QString poms, poms1, poms2;
                                poms.sprintf("%s", msg.param.pstr);
                                while (poms.length() > 0) {
-                                       cnt = poms.find(';');
+                                       cnt = poms.indexOf(';');
                                        if (cnt!=-1) {
                                                poms1 = poms.left(cnt);
                                                poms = poms.right(poms.length() - cnt - 1);
-                                               cnt = poms1.find('=');
+                                               cnt = poms1.indexOf('=');
                                                if (cnt != -1) {
                                                        poms2 = poms1.left(cnt);
                                                        poms1 = poms1.right(
@@ -813,6 +691,10 @@ void QKernel::NetMessage()
        }
 }
 
+/**
+ * Sends message to the interpreter program.
+ * @param sock Interpreter socket to whom the message will be send.
+ */
 void QKernel::IntMessage(int sock)
 {
        MESSAGE msg;
@@ -851,8 +733,9 @@ void QKernel::IntMessage(int sock)
                                if (e->remote == 0)
                                        CloseInstances(e);
                                delete e->notify;
-                               ::close(e->sock);   
-                               Interpreters.remove(e);
+                               ::close(e->sock);
+                               /* TODO: Check this */
+                               Interpreters.removeOne(e);
                                delete e;
 
                                if (info_messages) {
@@ -874,17 +757,22 @@ void QKernel::IntMessage(int sock)
                                write(sock, &msg, sizeof(MESSAGE)); 
                                break;
                        };
-                       break; /* switch param.pword[0] */
-               } /* switch type */
-       } /* if */
+                       break;
+               }
+       }
 }
 
+/**
+ * Writes message to kernel logger.
+ * @parame msg String with message to log
+ */
 void QKernel::WriteMessage(char *msg)
 {
        int x;
        int y;
+       x = desktop->textCursor().blockNumber();
+       y = desktop->textCursor().columnNumber();
 
-       desktop->getCursorPosition(&x, &y);
        if (x > 100) {
                desktop->clear();
        }
@@ -892,117 +780,123 @@ void QKernel::WriteMessage(char *msg)
        desktop->setReadOnly(FALSE);
        desktop->append(msg);
        desktop->setReadOnly(TRUE);
-       desktop->setCursorPosition(desktop->numLines(), 1);
+
+       QTextCursor tmpCursor = desktop->textCursor();
+       tmpCursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
+       desktop->setTextCursor(tmpCursor);
+
        desktop->repaint();
        
-       if (desktop->numLines() > 100) {
+       if (desktop->document()->blockCount() > 100) {
                desktop->clear();
        }
 }
 
-void QKernel::SetMessages()
+/**
+ * Adds checkbox to menu item. If it is checked additional info messages are
+ * shown.
+ */
+void QKernel::on_actionInfo_messages_triggered()
 {
-       if (p2 != NULL) {
-               if (p2->isItemChecked(msgid)) {
-                       p2->setItemChecked(msgid, FALSE);
-                       info_messages=FALSE;
-               } else {
-                       p2->setItemChecked(msgid, TRUE);  
-                       info_messages=TRUE;
-               }
-       } /* !=NULL */
-       /* bar->repaint(); */
+       if (toolsMenu != NULL) {
+               actionInfo_messages->setChecked(!actionInfo_messages->isChecked());
+//             actionInfo_messages->toggle();
+               info_messages = actionInfo_messages->isChecked();
+               fprintf(stderr, "Info is checked? %s\n", actionInfo_messages->isChecked() ? "yes" : "no");
+       }
+//     menuBar()->repaint();
 }
 
-void QKernel::SetOptions()
+/**
+ * Allows to set options in GUI window.
+ * Additional window is displayed to set kernel options which are saved in 
+ * vlp.cfg file in kernel executable directory.
+ */
+void QKernel::on_actionOptions_triggered()
 {
-       QDialog dlg(this, "Options", TRUE);
+       QDialog dlg(this, Qt::Dialog);
+       dlg.setWindowTitle("Options");
        ConnectEntry *e;
        unsigned int i;
 
        QLineEdit* progs;
-       progs = new QLineEdit(&dlg, "progs");
+       progs = new QLineEdit(progdir, &dlg);
        progs->setGeometry(150, 20, 180, 30);
-       progs->setText(progdir);
 
        QLabel* tmpQLabel;
-       tmpQLabel = new QLabel(&dlg, "Label_1");
+       tmpQLabel = new QLabel("Programs directory", &dlg);
        tmpQLabel->setGeometry(30, 20, 120, 30);
-       tmpQLabel->setText("Programs directory");
 
        QFrame* tmpQFrame;
-       tmpQFrame = new QFrame(&dlg, "Frame_2");
+       tmpQFrame = new QFrame(&dlg);
        tmpQFrame->setGeometry(10, 60, 380, 30);
        tmpQFrame->setFrameStyle(52);
 
-       tmpQLabel = new QLabel(&dlg, "Label_2");
+       tmpQLabel = new QLabel("Virtual Processor properties (activated after "
+                                               "restarting VLP):", &dlg);
        tmpQLabel->setGeometry(10, 80, 340, 30);
-       tmpQLabel->setText("Virtual Processor properties (activated after "
-                                                       "restarting VLP):");
 
        QLineEdit *nn;
        char nns[256];
-       nn = new QLineEdit(&dlg, "LineEdit_2");
-       nn->setGeometry(110, 110, 40, 30);
        sprintf(nns, "%d", NodeNumber);
-       nn->setText(nns);
+       nn = new QLineEdit(nns, &dlg);
+       nn->setGeometry(110, 110, 40, 30);
 
-       tmpQLabel = new QLabel(&dlg, "Label_3");
+       tmpQLabel = new QLabel("Node number:", &dlg);
        tmpQLabel->setGeometry(20, 110, 90, 30);
-       tmpQLabel->setText("Node number:");
 
        QRadioButton *exp, *reg;
-       exp = new QRadioButton(&dlg, "RadioButton_3");
+       exp = new QRadioButton("Explicit", &dlg);
        exp->setGeometry(30, 170, 100, 30);
-       exp->setText("Explicit");
        exp->setChecked(TRUE);
 
-       reg = new QRadioButton(&dlg, "RadioButton_4");
+       reg = new QRadioButton("Registration", &dlg);
        reg->setGeometry(30, 200, 100, 30);
-       reg->setText("Registration");
        reg->setEnabled(FALSE);
 
-       connections = new QListBox(&dlg, "ListBox_1");
+       connections = new QListWidget(&dlg);
        connections->setGeometry(170, 140, 130, 100);
-       e = ConnectList.first();
-       while(e != NULL) {
-               connections->insertItem(e->addr);
-               e = ConnectList.next();
+
+       for (int i = 0; i < ConnectList.size(); i++) {
+               e = ConnectList.at(i);
+               connections->addItem(e->addr);
        }
 
-       tmpQLabel = new QLabel(&dlg, "Label_5");
+       tmpQLabel = new QLabel("Connection list:", &dlg);
        tmpQLabel->setGeometry(170, 110, 100, 30);
-       tmpQLabel->setText("Connection list:");
 
        QPushButton *addbtn;
        QPushButton *delbtn;
        QPushButton *okbtn;
        QPushButton *cancelbtn;
-       addbtn = new QPushButton(&dlg, "PushButton_1");
+       addbtn = new QPushButton("Add", &dlg);
        addbtn->setGeometry(310, 150, 60, 30);
-       addbtn->setText("Add");
-       delbtn = new QPushButton(&dlg, "PushButton_2");
-       delbtn->setGeometry(310, 200, 60, 30);
-       delbtn->setText("Del");
        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(&dlg, "PushButton_3");
+
+       okbtn = new QPushButton("Ok", &dlg);
        okbtn->setGeometry(80, 260, 100, 30);
-       okbtn->setText("Ok");
        okbtn->setDefault(TRUE);
-       cancelbtn = new QPushButton(&dlg, "PushButton_4");
-       cancelbtn->setGeometry(210, 260, 100, 30);
-       cancelbtn->setText("Cancel");
        connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
-       connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));        
-       QButtonGroup* group;
-       group = new QButtonGroup(&dlg, "ButtonGroup_1");
+
+       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->setTitle("Connection type");
-       group->setAlignment(1);
+       group->setAlignment(Qt::AlignLeft);
        group->lower();
-       group->insert(exp, 1);
-       group->insert(reg, 2);  
+
+       QVBoxLayout *vbox = new QVBoxLayout();
+       vbox->addWidget(exp);
+       vbox->addWidget(reg);
+       vbox->addStretch(1);
+       group->setLayout(vbox);
 
        dlg.resize(400, 310);
        if (dlg.exec()) {
@@ -1015,12 +909,12 @@ void QKernel::SetOptions()
 
                setting = config_setting_add(root, "progdir",
                                                        CONFIG_TYPE_STRING);
-               config_setting_set_string(setting, progs->text().ascii());
-               strcpy(progdir, progs->text());
+               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()));
+               config_setting_set_int(setting, atoi(nn->text().toAscii().data()));
 
                setting = config_setting_add(root, "homedir",
                                                        CONFIG_TYPE_STRING);
@@ -1038,7 +932,7 @@ void QKernel::SetOptions()
                                setting = config_setting_add(hosts, NULL,
                                                        CONFIG_TYPE_STRING);
                                config_setting_set_string(setting,
-                                               connections->text(i).ascii());
+                                               connections->item(i)->text().toAscii().data());
                        }
                } else {
                        config_setting_set_string(setting, "register");
@@ -1052,51 +946,58 @@ void QKernel::SetOptions()
        }
 }
 
-void QKernel::LockConsole()
+/**
+ * Locks kernel program.
+ * Additional window is displayed to enter password and retype it. If both are
+ * same kernel window is locked.
+ */
+void QKernel::on_actionLock_console_triggered()
 {
-       QDialog d(this, "Enter password", TRUE);
-       QLabel lab(&d, "Password");
-       QLineEdit ed(&d, "");
-       QPushButton ob(&d, "");
-       QPushButton cb(&d, "");
+       QDialog d(this, Qt::Dialog);
+       d.setWindowTitle("Lock console");
 
-       d.setCaption("Lock console"); 
+       QPushButton ob("Ok", &d);
        ob.setGeometry(30, 60, 80, 30);
-       ob.setText("Ok");
        ob.setDefault(TRUE);
+       connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
+
+       QLabel lab("Password:", &d);
        lab.setGeometry(10, 10, 60, 30);
-       lab.setText("Password:");
+
+       QLineEdit ed("", &d);
        ed.setGeometry(70, 10, 140, 30);
        ed.setEchoMode(QLineEdit::Password);
+
+       QPushButton cb("Cancel", &d);
        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())); 
 
+       d.resize(240, 100);
+
        if (d.exec()) {
-               if (strcmp(ed.text(), "") != 0) {
-                       strcpy(LockPasswd, ed.text());
+               if (strcmp(ed.text().toAscii().data(), "") != 0) {
+                       strcpy(LockPasswd, ed.text().toAscii().data());
                        lab.setText("Retype:");
                        ed.setText("");
+                       /*
+                        * Following exec(), could produce error:
+                        * X Error: BadWindow (invalid Window parameter) 3
+                        *   Major opcode: 3 (X_GetWindowAttributes)
+                        *
+                        * This is not error in our code. Basing on:
+                        * https://bugreports.qt-project.org/browse/QTBUG-1782
+                        * this happens only on Qt 4.3 - 4.4.
+                        */
                        if (d.exec()) {
-                               if (strcmp(ed.text(), LockPasswd)==0) {
-                                       bar->setItemEnabled(qid, FALSE);
-                                       bar->setItemEnabled(prid, FALSE);
-                                       bar->setItemEnabled(mid, FALSE);
-                                       p2->setItemEnabled(unlockid, TRUE);
-                                       p2->setItemEnabled(lockid, FALSE);
-                                       p2->setItemEnabled(cwid, FALSE);
-                                       p2->setItemEnabled(optid, FALSE);
-                                       bar->repaint();
+                               if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) {
+                                       setLocked(TRUE);
                                        WriteMessage("CONSOLE LOCKED");
-                                       LOCKED = TRUE;
                                } else {
                                        QMessageBox msg(this);
                                        msg.setText("Not matching!");
                                        msg.setButtonText(0, "Close");
                                        msg.show();
-                               }   
+                               }
                        } else {
                                strcpy(LockPasswd, "");
                        }
@@ -1104,82 +1005,102 @@ void QKernel::LockConsole()
        }
 }
 
-void QKernel::UnlockConsole()
+/**
+ * Unlocks kernel program.
+ * Additional window is displayed to enter password. If it is correct, kernel 
+ * window is unlocked
+ */
+void QKernel::on_actionUnlock_console_triggered()
 {
-       QDialog d(this, "Enter password", TRUE);
-       QLabel lab(&d, "Password");
-       QLineEdit ed(&d, "");
-       QPushButton ob(&d, "");
-       QPushButton cb(&d, "");
+       QDialog d(this, Qt::Dialog);
+       d.setWindowTitle("Enter password");
 
-       ob.setGeometry(30, 60, 80, 30);
-       ob.setText("Ok");
-       ob.setDefault(TRUE);
+       QLabel lab("Password:", &d);
        lab.setGeometry(10, 10, 60, 30);
-       lab.setText("Password:");
+
+       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);
-       cb.setText("Cancel");
+       connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
+
        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(), LockPasswd) == 0) {
-                       bar->setItemEnabled(qid, TRUE);
-                       bar->setItemEnabled(prid, TRUE);
-                       bar->setItemEnabled(mid, TRUE);
-                       p2->setItemEnabled(unlockid, FALSE);
-                       p2->setItemEnabled(lockid, TRUE);
-                       p2->setItemEnabled(cwid, TRUE);
-                       p2->setItemEnabled(optid, TRUE);
-                       bar->repaint();
+               if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) {
+                       setLocked(FALSE);
                        WriteMessage("CONSOLE UNLOCKED");
-                       LOCKED = FALSE;         
                } else {
                        QMessageBox msg(this);
                        msg.setText("Wrong password!");
                        msg.setButtonText(0, "Close");
                        msg.show();
-               }      
+               }
        }
 }
 
+/**
+ * Writes init message in kernel
+ */
 void QKernel::InitMessage()
 {
-       WriteMessage("\n Virtual LOGLAN Processor - ver 1.9: READY \n");
+       WriteMessage("\n " PACKAGE_STRING ": READY \n");
 }
 
+/**
+ * Finds Interpreter by its socket
+ * @param _id ID of the socket
+ * @return returns pointer to the found interpreter slot. NULL otherwise
+ */
 InterpEntry *QKernel::findINTbySocket(int _id)
 {
-       InterpEntry *pom;
-       pom = Interpreters.first();
-
-       while (pom != NULL) {
-               if (pom->sock == _id)
+       InterpEntry *pom = NULL;
+       
+       for (int i = 0; i < Interpreters.size(); i++) {
+               if (Interpreters.at(i)->sock == _id) {
+                       pom = Interpreters.at(i);
                        break;
-
-               pom = Interpreters.next();
+               }
        }
-       return(pom);
+
+       return pom;
 }
 
+/**
+ * Finds Interpreter by its ID.
+ * @param _id ID of the interpreter
+ * @return returns pointer to the found interpreter slot. NULL otherwise
+ */
 InterpEntry *QKernel::findINTbyID(int _id)
 {
-       InterpEntry *pom;
-       pom = Interpreters.first();
-       while (pom != NULL) {
-               if (pom->ID == _id)
+       InterpEntry *pom = NULL;
+       
+       for (int i = 0; i < Interpreters.size(); i++) {
+               if (Interpreters.at(i)->ID == _id) {
+                       pom = Interpreters.at(i);
                        break;
-               pom = Interpreters.next();
+               }
        }
-       return(pom);
-}
 
+       return pom;
+}
 
-/* ------------------ Connect INT module -----------------*/
 
+/**
+ * Connects interpreter
+ * @param ss full filepath with filename but without extension of the loglan
+ *           program to run.
+ * @param r Interpreter execution mode. 0 if it will be local instance, 1 if
+ *          remote
+ * @return Returns pointer to newly created interpreter slot, or NULL on error.
+ */
 InterpEntry *QKernel::RunIntModule(char *ss, int r)
 {
        char a[256], b[255];
@@ -1196,7 +1117,7 @@ InterpEntry *QKernel::RunIntModule(char *ss, int r)
        cf = fopen(a, "r");
        if (cf == NULL) {
                WriteMessage("File not found: no .ccd file");
-               return(NULL);
+               return NULL;
        }
        fclose(cf);
 
@@ -1205,7 +1126,7 @@ InterpEntry *QKernel::RunIntModule(char *ss, int r)
        cf = fopen(a, "r");
        if (cf == NULL) {
                WriteMessage("File not found: no .pcd file");
-               return(NULL);
+               return NULL;
        }
        fclose(cf);
 
@@ -1244,7 +1165,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);
 
@@ -1253,7 +1174,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 
@@ -1280,9 +1201,11 @@ InterpEntry *QKernel::RunIntModule(char *ss, int r)
        return newINT;
 }
 
-/* ---------------------------------------------------------*/
-/*            Allocate remote instance                      */
-
+/**
+ * Allocates remote instance of interpreter
+ * @param interp Interpreter slot 
+ * @param on Node Number
+ */
 void QKernel::RemoteInstance(InterpEntry *interp, int on)
 {
        MESSAGE m;
@@ -1330,7 +1253,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);
@@ -1352,10 +1275,9 @@ void QKernel::RemoteInstance(InterpEntry *interp, int on)
        }
 }
 
-
-/*-----------------------------------------------*/
-/*           Close all remote instances         */
-
+/**
+ * Closes all remote instances
+ */
 void QKernel::CloseInstances(InterpEntry *e)
 {
        MESSAGE msg;
@@ -1377,8 +1299,10 @@ void QKernel::CloseInstances(InterpEntry *e)
                }
 }
 
-
-void QKernel::Info()
+/**
+ * Displays information about virtual machine
+ */
+void QKernel::on_actionInfo_triggered()
 {
        MESSAGE m;
 
@@ -1390,23 +1314,27 @@ 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
+ * passed to all dependent programs on their invocation.
+ * @param argc Number of program arguments
+ * @param argv Program arguments
+ */
 int main(int argc, char **argv)
 {
        int i;
-       for(i=0; i < 5; i++) {
+       for(i = 0; i < 5; i++) {
                strcpy(myargs[i], "");
        }
-       for(i=1; i < argc; i++) {
-               strcpy(myargs[i-1], argv[i]);
+       for(i = 1; i < argc; i++) {
+               strcpy(myargs[i - 1], argv[i]);
        }
 
-       app = new QApplication(argc, argv);
-       app->setStyle(new QWindowsStyle());
+       QApplication * app = new QApplication(argc, argv);
        QKernel kernel;
-       app->setMainWidget(&kernel);
        kernel.show();
        kernel.InitMessage();
+       
        return app->exec();
 }