Move LockDialog layout code into separate ui file
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Thu, 21 Jan 2016 19:32:35 +0000 (20:32 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Thu, 21 Jan 2016 19:32:35 +0000 (20:32 +0100)
Makefile.am
src/kernel/kernel.cpp
src/kernel/lock.cpp [new file with mode: 0644]
src/kernel/lock.h [new file with mode: 0644]
src/kernel/lock_dialog.ui [new file with mode: 0644]

index 5a902a5ed06d9b02dac9f2bb2557feb1ee4ed317..9120555bc098f4b0fe61dde3b9106414756da2d3 100644 (file)
@@ -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 = \
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, "");
diff --git a/src/kernel/lock.cpp b/src/kernel/lock.cpp
new file mode 100644 (file)
index 0000000..f7aea1f
--- /dev/null
@@ -0,0 +1,24 @@
+#include <QtGui/QDialog>
+
+#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 (file)
index 0000000..a940d4b
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef _VLP_KERNEL_LOCKDIALOG_H
+#define _VLP_KERNEL_LOCKDIALOG_H
+
+#include <QtGui/QDialog>
+
+#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 (file)
index 0000000..c39a1a2
--- /dev/null
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LockDialog</class>
+ <widget class="QDialog" name="LockDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>275</width>
+    <height>90</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="minimumSize">
+   <size>
+    <width>0</width>
+    <height>0</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>Lock console</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="spacing">
+    <number>0</number>
+   </property>
+   <property name="sizeConstraint">
+    <enum>QLayout::SetMinimumSize</enum>
+   </property>
+   <property name="leftMargin">
+    <number>3</number>
+   </property>
+   <property name="topMargin">
+    <number>3</number>
+   </property>
+   <property name="rightMargin">
+    <number>3</number>
+   </property>
+   <property name="bottomMargin">
+    <number>3</number>
+   </property>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <property name="sizeConstraint">
+      <enum>QLayout::SetMinimumSize</enum>
+     </property>
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Password</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLineEdit" name="lineEdit">
+       <property name="echoMode">
+        <enum>QLineEdit::Password</enum>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>LockDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>LockDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>