From: Rafał Długołęcki Date: Thu, 21 Jan 2016 19:32:35 +0000 (+0100) Subject: Move LockDialog layout code into separate ui file X-Git-Tag: 3.4-b1~57 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=7b665056a5881222031cb1aebbae3e84d701a291;p=vlp.git Move LockDialog layout code into separate ui file --- diff --git a/Makefile.am b/Makefile.am index 5a902a5..9120555 100644 --- a/Makefile.am +++ b/Makefile.am @@ -63,23 +63,31 @@ clean-lognet-extra: rm -f bin/modules/lognet rm -f bin/lognet -bin_logker_SOURCES = src/kernel/kernel.cpp src/kernel/kernel.moc.cpp +bin_logker_SOURCES = \ + src/kernel/kernel.cpp \ + src/kernel/kernel.moc.cpp \ + src/kernel/lock.cpp bin_logker_CPPFLAGS = $(bin_logker_CFLAGS) bin_logker_LDADD = $(bin_logker_LIBS) bin_logkerdir = src/kernel bin_logker_HEADERS = \ - src/kernel/kernel.h -src/kernel/kernel.moc.cpp: src/kernel/kernel.h src/kernel/kernelwindow.h + src/kernel/kernel.h \ + src/kernel/lock.h +src/kernel/kernel.moc.cpp: src/kernel/kernel.h src/kernel/kernelwindow.h src/kernel/lock_dialog.h moc-qt4 src/kernel/kernel.h -o src/kernel/kernel.moc.cpp # $(MOC) -i src/kernel/kernel.cpp -o src/kernel/kernel.moc src/kernel/kernelwindow.h: uic src/kernel/kernelwindow.ui -o src/kernel/kernelwindow.h +src/kernel/lock_dialog.h: + uic src/kernel/lock_dialog.ui -o src/kernel/lock_dialog.h + clean-logker-extra: rm -f src/kernel/*.moc rm -f src/kernel/kernelwindow.h + rm -f src/kernel/lock_dialog.h rm -f bin/logker bin_logint_SOURCES = \ diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 98debb0..094fad6 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -65,6 +65,7 @@ #include "kernel.h" #include "kernelwindow.h" +#include "lock.h" /* File resides in top directory (where are Makefiles)*/ #include "../../config.h" @@ -953,43 +954,17 @@ void QKernel::on_actionOptions_triggered() */ 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); + LockDialog lockDialog(this); - QLineEdit ed("", &d); - ed.setGeometry(70, 10, 140, 30); - ed.setEchoMode(QLineEdit::Password); + if (lockDialog.exec()) { + QString password = lockDialog.getPassword(); + if (lockDialog.getPassword().size() > 0) { + strcpy(LockPasswd, password.toAscii().data()); + lockDialog.retype(); - 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(""); - /* - * 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) { + if (lockDialog.exec()) { + password = lockDialog.getPassword(); + if (password == LockPasswd) { setLocked(TRUE); WriteMessage("CONSOLE LOCKED"); } else { @@ -997,6 +972,7 @@ void QKernel::on_actionLock_console_triggered() msg.setText("Not matching!"); msg.setButtonText(0, "Close"); msg.show(); + strcpy(LockPasswd, ""); } } else { strcpy(LockPasswd, ""); diff --git a/src/kernel/lock.cpp b/src/kernel/lock.cpp new file mode 100644 index 0000000..f7aea1f --- /dev/null +++ b/src/kernel/lock.cpp @@ -0,0 +1,24 @@ +#include + +#include "lock.h" + +LockDialog::LockDialog(QWidget * parent) + : QDialog(parent) +{ + setupUi(this); +} + +LockDialog::~LockDialog() +{ +} + +QString LockDialog::getPassword() +{ + return lineEdit->text(); +} + +void LockDialog::retype() +{ + label->setText("Retype"); + lineEdit->setText(""); +} diff --git a/src/kernel/lock.h b/src/kernel/lock.h new file mode 100644 index 0000000..a940d4b --- /dev/null +++ b/src/kernel/lock.h @@ -0,0 +1,20 @@ +#ifndef _VLP_KERNEL_LOCKDIALOG_H +#define _VLP_KERNEL_LOCKDIALOG_H + +#include + +#include "lock_dialog.h" + +/** + * Lock Dialog class + */ +class LockDialog : public QDialog, private Ui::LockDialog { +public: + LockDialog(QWidget * parent = 0); + ~LockDialog(); + + QString getPassword(); + void retype(); +}; + +#endif /* _VLP_KERNEL_LOCKDIALOG_H */ diff --git a/src/kernel/lock_dialog.ui b/src/kernel/lock_dialog.ui new file mode 100644 index 0000000..c39a1a2 --- /dev/null +++ b/src/kernel/lock_dialog.ui @@ -0,0 +1,115 @@ + + + LockDialog + + + + 0 + 0 + 275 + 90 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Lock console + + + + 0 + + + QLayout::SetMinimumSize + + + 3 + + + 3 + + + 3 + + + 3 + + + + + QLayout::SetMinimumSize + + + + + Password + + + + + + + QLineEdit::Password + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + LockDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + LockDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +