From 12c2d89eef8d87e6ff2150ce7f43eba0ac1112f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Mon, 28 Oct 2013 20:13:26 +0100 Subject: [PATCH] VLP-28 Block remaining menu entries on console lock. --- src/kernel/kernel.cpp | 104 ++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 39 deletions(-) diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 8ab19f1..969156f 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -187,10 +188,13 @@ private: QAction * qid; QAction * cwid; QAction * optid; - QAction * prid; - QAction * mid; + QAction * programExecuteAction; + QAction * programKillAction; + QAction * machineMessageAction; + QAction * machineConnectAction; + QAction * machineDisconnectAction; + QAction * machineInfoAction; QAction * msgid; - QAction * toolsid; QAction * hid; int net_sock; @@ -215,7 +219,11 @@ private: */ void QKernel::closeEvent(QCloseEvent * e) { - QuitProc(); + e->ignore(); + + if (!LOCKED) { + QuitProc(); + } } /** @@ -239,16 +247,15 @@ QKernel::QKernel() QMenu * programMenu = NULL; programMenu = menuBar()->addMenu("&Program"); - programMenu->addAction("Execute", this, SLOT(Run_Prog())); - programMenu->addAction("Kill", this, SLOT(KillInterpreter())); - + programExecuteAction = programMenu->addAction("Execute", this, SLOT(Run_Prog())); + programKillAction = programMenu->addAction("Kill", this, SLOT(KillInterpreter())); machineMenu = menuBar()->addMenu("&Machine"); - machineMenu->addAction("Message", this, SLOT(MessageToNode())); + machineMessageAction = 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())); + machineConnectAction = machineMenu->addAction("Connect", this, SLOT(Connect())); + machineDisconnectAction = machineMenu->addAction("Disconnect", this, SLOT(Disconnect())); + machineInfoAction = machineMenu->addAction("Info", this, SLOT(Info())); toolsMenu = menuBar()->addMenu("&Tools"); cwid = toolsMenu->addAction("Editor", this, SLOT(Edit())); @@ -571,24 +578,25 @@ void QKernel::QuitProc() { 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);*/ + app->quit(); } /** @@ -1140,15 +1148,29 @@ void QKernel::LockConsole() 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().toAscii().data(), LockPasswd)==0) { - qid->setEnabled(FALSE); - prid->setEnabled(FALSE); - mid->setEnabled(FALSE); + if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) { + qid->setDisabled(TRUE); + programExecuteAction->setDisabled(TRUE); + programKillAction->setDisabled(TRUE); + machineMessageAction->setDisabled(TRUE); + machineConnectAction->setDisabled(TRUE); + machineDisconnectAction->setDisabled(TRUE); + machineInfoAction->setDisabled(TRUE); + unlockid->setEnabled(TRUE); - lockid->setEnabled(FALSE); - cwid->setEnabled(FALSE); - optid->setEnabled(FALSE); + lockid->setDisabled(TRUE); + cwid->setDisabled(TRUE); + optid->setDisabled(TRUE); WriteMessage("CONSOLE LOCKED"); LOCKED = TRUE; } else { @@ -1195,8 +1217,12 @@ void QKernel::UnlockConsole() if (d.exec()) { if (strcmp(ed.text().toAscii().data(), LockPasswd) == 0) { qid->setEnabled(TRUE); - prid->setEnabled(TRUE); - mid->setEnabled(TRUE); + programExecuteAction->setEnabled(TRUE); + programKillAction->setEnabled(TRUE); + machineMessageAction->setEnabled(TRUE); + machineConnectAction->setEnabled(TRUE); + machineDisconnectAction->setEnabled(TRUE); + machineInfoAction->setEnabled(TRUE); unlockid->setEnabled(FALSE); lockid->setEnabled(TRUE); cwid->setEnabled(TRUE); @@ -1331,7 +1357,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 +1366,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 +1445,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); -- 2.30.2