Move kill interpreter dialog code to separate ui file
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Mon, 25 Jan 2016 01:14:53 +0000 (02:14 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Mon, 25 Jan 2016 01:14:53 +0000 (02:14 +0100)
Makefile.am
src/kernel/kernel.cpp
src/kernel/kill_interpreter_dialog.cpp [new file with mode: 0644]
src/kernel/kill_interpreter_dialog.h [new file with mode: 0644]
src/kernel/ui/kill_dialog.ui [new file with mode: 0644]

index 3002f3ac34cbabb4fee2d6e518c67dca8a29154e..c8f536ac5411859c30c8e780488bfd59ef9d8654 100644 (file)
@@ -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
index 43f4efae145864ed7b35f0e865a1cf970ec03f99..2052fed9a47536a9de7512e551592b34ecf9ed77 100644 (file)
@@ -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 (file)
index 0000000..6f97a76
--- /dev/null
@@ -0,0 +1,18 @@
+#include <QtGui/QDialog>
+
+#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 (file)
index 0000000..5511d61
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _VLP_KERNEL_KILLINTERPRETERDIALOG_H
+#define _VLP_KERNEL_KILLINTERPRETERDIALOG_H
+
+#include <QtGui/QDialog>
+
+#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 (file)
index 0000000..32a73d5
--- /dev/null
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>KillInterpreterDialog</class>
+ <widget class="QDialog" name="KillInterpreterDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>184</width>
+    <height>71</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Interp. ID:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QSpinBox" name="interpreterId"/>
+     </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>KillInterpreterDialog</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>KillInterpreterDialog</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>