From 15ae31bcd6ed35816cfc9c8b9fb2b4094ad2377a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Mon, 25 Jan 2016 02:14:53 +0100 Subject: [PATCH] Move kill interpreter dialog code to separate ui file --- Makefile.am | 11 +++- src/kernel/kernel.cpp | 69 ++++++----------------- src/kernel/kill_interpreter_dialog.cpp | 18 ++++++ src/kernel/kill_interpreter_dialog.h | 19 +++++++ src/kernel/ui/kill_dialog.ui | 78 ++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 56 deletions(-) create mode 100644 src/kernel/kill_interpreter_dialog.cpp create mode 100644 src/kernel/kill_interpreter_dialog.h create mode 100644 src/kernel/ui/kill_dialog.ui diff --git a/Makefile.am b/Makefile.am index 3002f3a..c8f536a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -68,15 +68,17 @@ bin_logker_SOURCES = \ src/kernel/kernel.moc.cpp \ src/kernel/lock.cpp \ src/kernel/options.cpp \ - src/kernel/options.moc.cpp + src/kernel/options.moc.cpp \ + src/kernel/kill_interpreter_dialog.cpp bin_logker_CPPFLAGS = $(bin_logker_CFLAGS) bin_logker_LDADD = $(bin_logker_LIBS) -lconfig++ -lX11 bin_logkerdir = src/kernel bin_logker_HEADERS = \ src/kernel/kernel.h \ src/kernel/lock.h \ - src/kernel/options.h -src/kernel/kernel.moc.cpp: src/kernel/kernel.h src/kernel/ui/kernelwindow.h src/kernel/ui/lock_dialog.h src/kernel/ui/optionsdialog.h + src/kernel/options.h \ + src/kernel/kill_interpreter_dialog.h +src/kernel/kernel.moc.cpp: src/kernel/kernel.h src/kernel/ui/kernelwindow.h src/kernel/ui/lock_dialog.h src/kernel/ui/optionsdialog.h src/kernel/ui/kill_dialog.h moc-qt4 src/kernel/kernel.h -o src/kernel/kernel.moc.cpp moc-qt4 src/kernel/options.h -o src/kernel/options.moc.cpp # $(MOC) -i src/kernel/kernel.cpp -o src/kernel/kernel.moc @@ -90,6 +92,9 @@ src/kernel/ui/lock_dialog.h: src/kernel/ui/optionsdialog.h: uic src/kernel/ui/optionsdialog.ui -o src/kernel/ui/optionsdialog.h +src/kernel/ui/kill_dialog.h: + uic src/kernel/ui/kill_dialog.ui -o src/kernel/ui/kill_dialog.h + clean-logker-extra: rm -f src/kernel/*.moc diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 43f4efa..2052fed 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -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 { diff --git a/src/kernel/kill_interpreter_dialog.cpp b/src/kernel/kill_interpreter_dialog.cpp new file mode 100644 index 0000000..6f97a76 --- /dev/null +++ b/src/kernel/kill_interpreter_dialog.cpp @@ -0,0 +1,18 @@ +#include + +#include "kill_interpreter_dialog.h" + +KillInterpreterDialog::KillInterpreterDialog(QWidget * parent) + : QDialog(parent, Qt::Dialog) +{ + setupUi(this); +} + +KillInterpreterDialog::~KillInterpreterDialog() +{ +} + +int KillInterpreterDialog::getInterpreterId() +{ + return interpreterId->text().toInt(); +} diff --git a/src/kernel/kill_interpreter_dialog.h b/src/kernel/kill_interpreter_dialog.h new file mode 100644 index 0000000..5511d61 --- /dev/null +++ b/src/kernel/kill_interpreter_dialog.h @@ -0,0 +1,19 @@ +#ifndef _VLP_KERNEL_KILLINTERPRETERDIALOG_H +#define _VLP_KERNEL_KILLINTERPRETERDIALOG_H + +#include + +#include "ui/kill_dialog.h" + +/** + * Kill Interpreter Dialog class + */ +class KillInterpreterDialog : public QDialog, private Ui::KillInterpreterDialog { +public: + KillInterpreterDialog(QWidget * parent = 0); + ~KillInterpreterDialog(); + + int getInterpreterId(); +}; + +#endif /* _VLP_KERNEL_KILLINTERPRETERDIALOG_H */ diff --git a/src/kernel/ui/kill_dialog.ui b/src/kernel/ui/kill_dialog.ui new file mode 100644 index 0000000..32a73d5 --- /dev/null +++ b/src/kernel/ui/kill_dialog.ui @@ -0,0 +1,78 @@ + + + KillInterpreterDialog + + + + 0 + 0 + 184 + 71 + + + + Dialog + + + + + + + + Interp. ID: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + KillInterpreterDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + KillInterpreterDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + -- 2.30.2