Move LockDialog layout code into separate ui file
[vlp.git] / src / kernel / kernel.cpp
index 98debb07475a8446070aaeb5d7985e0d386d32b9..094fad62a6e6d084965e70a4d1c2040c0950fae4 100644 (file)
@@ -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, "");