From 8849f9b808821b280514f23a8a26394963d97a77 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Tue, 29 Oct 2013 21:38:09 +0100 Subject: [PATCH] vlp-27 Moving kernel to use QtDesigner files. Important note: need to use uic-qt4 from now. --- Makefile.am | 28 +++- configure.ac | 2 +- data/kernel/dialogs/connect.ui | 42 ++++++ data/kernel/dialogs/kill-interpreter.ui | 44 +++++++ data/kernel/dialogs/options.ui | 144 ++++++++++++++++++++ data/kernel/dialogs/send-message.ui | 56 ++++++++ data/kernel/main-window.ui | 167 ++++++++++++++++++++++++ src/kernel/kernel.cpp | 149 +++++---------------- src/kernel/kernel.h | 48 +++---- src/kernel/send-message.h | 77 +++++++++++ 10 files changed, 606 insertions(+), 151 deletions(-) create mode 100644 data/kernel/dialogs/connect.ui create mode 100644 data/kernel/dialogs/kill-interpreter.ui create mode 100644 data/kernel/dialogs/options.ui create mode 100644 data/kernel/dialogs/send-message.ui create mode 100644 data/kernel/main-window.ui create mode 100644 src/kernel/send-message.h diff --git a/Makefile.am b/Makefile.am index 782199d..1dd212b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,10 +65,32 @@ clean-lognet-extra: bin_logker_SOURCES = src/kernel/kernel.cpp src/kernel/kernel.moc.cpp bin_logker_CPPFLAGS = $(bin_logker_CFLAGS) bin_logker_LDADD = $(bin_logker_LIBS) -bin_logkerdir = src/kernel +bin_logkerdir = src/kernel src/kernel/ui src/kernel/ui/dialogs bin_logker_HEADERS = \ - src/kernel/kernel.h -src/kernel/kernel.moc.cpp: src/kernel/kernel.h + src/kernel/kernel.h \ + src/kernel/ui/main-window.h \ + src/kernel/ui/dialogs/connect.h \ + src/kernel/ui/dialogs/options.h \ + src/kernel/ui/dialogs/kill-interpreter.h \ + src/kernel/ui/dialogs/send-message.h + +src/kernel/ui/main-window.h: data/kernel/main-window.ui + if [ ! -d src/kernel/ui ]; then mkdir -p src/kernel/ui; fi + uic-qt4 data/kernel/main-window.ui -o src/kernel/ui/main-window.h +src/kernel/ui/dialogs/connect.h: data/kernel/dialogs/connect.ui + if [ ! -d src/kernel/ui/dialogs ]; then mkdir -p src/kernel/ui/dialogs; fi + uic-qt4 data/kernel/dialogs/connect.ui -o src/kernel/ui/dialogs/connect.h +src/kernel/ui/dialogs/options.h: data/kernel/dialogs/options.ui + if [ ! -d src/kernel/ui/dialogs ]; then mkdir -p src/kernel/ui/dialogs; fi + uic-qt4 data/kernel/dialogs/options.ui -o src/kernel/ui/dialogs/options.h +src/kernel/ui/dialogs/kill-interpreter.h: data/kernel/dialogs/kill-interpreter.ui + if [ ! -d src/kernel/ui/dialogs ]; then mkdir -p src/kernel/ui/dialogs; fi + uic-qt4 data/kernel/dialogs/kill-interpreter.ui -o src/kernel/ui/dialogs/kill-interpreter.h +src/kernel/ui/dialogs/send-message.h: data/kernel/dialogs/send-message.ui + if [ ! -d src/kernel/ui/dialogs ]; then mkdir -p src/kernel/ui/dialogs; fi + uic-qt4 data/kernel/dialogs/send-message.ui -o src/kernel/ui/dialogs/send-message.h + +src/kernel/kernel.moc.cpp: $(bin_logker_HEADERS) moc-qt4 src/kernel/kernel.h -o src/kernel/kernel.moc.cpp # $(MOC) -i src/kernel/kernel.cpp -o src/kernel/kernel.moc diff --git a/configure.ac b/configure.ac index 859f94e..01ebe59 100644 --- a/configure.ac +++ b/configure.ac @@ -13,7 +13,7 @@ AC_CONFIG_FILES([Makefile]) # qt3-dev-tools:i386 PKG_CHECK_MODULES([bin_loggraph], [qt-mt < 4.0]) PKG_CHECK_MODULES([bin_lognet], [qt-mt < 4.0 libconfig]) -PKG_CHECK_MODULES([bin_logker], [QtCore >= 4.0 QtGui >= 4.0 libconfig]) +PKG_CHECK_MODULES([bin_logker], [QtCore >= 4.0 QtGui >= 4.0 QtUiTools libconfig]) #PKG_CHECK_MODULES([bin_logint], [qt-mt < 4.0]) PKG_CHECK_MODULES([bin_logedit], [QtCore >= 4.0 QtGui >= 4.0 ]) PKG_CHECK_MODULES([bin_lgconfig], [qt-mt < 4.0 libconfig]) diff --git a/data/kernel/dialogs/connect.ui b/data/kernel/dialogs/connect.ui new file mode 100644 index 0000000..f05d882 --- /dev/null +++ b/data/kernel/dialogs/connect.ui @@ -0,0 +1,42 @@ + + + connectDialog + + + + 0 + 0 + 259 + 105 + + + + Connect + + + + + + + + Address + + + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/data/kernel/dialogs/kill-interpreter.ui b/data/kernel/dialogs/kill-interpreter.ui new file mode 100644 index 0000000..433b023 --- /dev/null +++ b/data/kernel/dialogs/kill-interpreter.ui @@ -0,0 +1,44 @@ + + + killInterpreterDialog + + + + 0 + 0 + 383 + 45 + + + + + 0 + 0 + + + + Kill interpreter + + + + + + Interp. ID + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/data/kernel/dialogs/options.ui b/data/kernel/dialogs/options.ui new file mode 100644 index 0000000..af16c99 --- /dev/null +++ b/data/kernel/dialogs/options.ui @@ -0,0 +1,144 @@ + + + optionsDialog + + + + 0 + 0 + 412 + 308 + + + + Options + + + + + + + + Programs directory + + + + + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + Virtual Processor properties + + + + + + + + + + + + Node number: + + + + + + + + + + + + Qt::ImhExclusiveInputMask + + + GroupBox + + + + + + Explicit + + + + + + + Registration + + + + + + + + + + + + + + Connection list: + + + + + + + + + + + + + + Add + + + + + + + Del + + + + + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/data/kernel/dialogs/send-message.ui b/data/kernel/dialogs/send-message.ui new file mode 100644 index 0000000..7238898 --- /dev/null +++ b/data/kernel/dialogs/send-message.ui @@ -0,0 +1,56 @@ + + + sendMessageDialog + + + + 0 + 0 + 385 + 270 + + + + Send message to node + + + + + + + + Node number + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + Message + + + + + + + + + + + + + diff --git a/data/kernel/main-window.ui b/data/kernel/main-window.ui new file mode 100644 index 0000000..816ebb8 --- /dev/null +++ b/data/kernel/main-window.ui @@ -0,0 +1,167 @@ + + + MainWindow + + + + 0 + 0 + 386 + 217 + + + + MainWindow + + + + true + + + + 0 + 0 + + + + + 0 + + + 0 + + + + + true + + + false + + + true + + + false + + + + + + + + + 0 + 0 + 386 + 20 + + + + + Program + + + + + + + Machine + + + + + + + + + + Tools + + + + + + + + + + + + + + + + + + Execute + + + + + Kill + + + + + Connect + + + + + Disconnect + + + + + Info + + + + + Editor + + + + + Help + + + + + Options + + + + + true + + + true + + + Info messages + + + + + Lock console + + + + + false + + + Unlock console + + + + + Message + + + + + + diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index d2521ab..6c0f27c 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -64,6 +64,7 @@ #include #include "kernel.h" +#include "send-message.h" /* File resides in top directory (where are Makefiles)*/ #include "../../config.h" @@ -91,27 +92,29 @@ void QKernel::setLocked(bool locked) { LOCKED = locked; - quitAction->setDisabled(locked); - programExecuteAction->setDisabled(locked); - programKillAction->setDisabled(locked); - machineMessageAction->setDisabled(locked); - machineConnectAction->setDisabled(locked); - machineDisconnectAction->setDisabled(locked); - machineInfoAction->setDisabled(locked); + actionExecute->setDisabled(locked); + actionKill->setDisabled(locked); + actionConnect->setDisabled(locked); + actionDisconnect->setDisabled(locked); + actionInfo_messages->setDisabled(locked); + actionMessage->setDisabled(locked); /* Enable only menu entry for unlocking */ - toolsEditorAction->setDisabled(locked); - toolsOptionsAction->setDisabled(locked); - toolsLockAction->setDisabled(locked); - toolsUnlockAction->setEnabled(locked); + actionEditor->setDisabled(locked); + actionOptions->setDisabled(locked); + actionLock_Console->setDisabled(locked); + actionUnlock_console->setEnabled(locked); } /** * Kernel program constructor. * Prepares everything to work. */ -QKernel::QKernel() +QKernel::QKernel(QWidget *parent) + : QMainWindow(parent) { + setupUi(this); + QDir q(REMOTE_PATH); char ss[255]; @@ -125,45 +128,7 @@ QKernel::QKernel() setWindowTitle(PACKAGE_NAME); - QMenu * programMenu = NULL; - programMenu = menuBar()->addMenu("&Program"); - programExecuteAction = programMenu->addAction("Execute", this, SLOT(Run_Prog())); - programKillAction = programMenu->addAction("Kill", this, SLOT(KillInterpreter())); - - machineMenu = menuBar()->addMenu("&Machine"); - machineMessageAction = machineMenu->addAction("Message", this, SLOT(MessageToNode())); - machineMenu->addSeparator(); - machineConnectAction = machineMenu->addAction("Connect", this, SLOT(Connect())); - machineDisconnectAction = machineMenu->addAction("Disconnect", this, SLOT(Disconnect())); - machineInfoAction = machineMenu->addAction("Info", this, SLOT(Info())); - - toolsMenu = menuBar()->addMenu("&Tools"); - toolsEditorAction = toolsMenu->addAction("Editor", this, SLOT(Edit())); - toolsMenu->addAction("Help", this, SLOT(Help())); - toolsMenu->addSeparator(); - toolsOptionsAction = toolsMenu->addAction("Options", this, SLOT(SetOptions())); - toolsInfoAction = toolsMenu->addAction("Info messages", this, SLOT(SetMessages())); - toolsInfoAction->setCheckable(TRUE); - toolsInfoAction->setChecked(TRUE); - toolsMenu->addSeparator(); - toolsLockAction = toolsMenu->addAction("Lock console", this, SLOT(LockConsole())); - toolsUnlockAction = toolsMenu->addAction("Unlock console", this, - SLOT(UnlockConsole())); - toolsUnlockAction->setDisabled(TRUE); LOCKED = FALSE; - - quitAction = menuBar()->addAction("&Quit", this, SLOT(QuitProc())); - - desktop = new QTextEdit(this); - desktop->setReadOnly(TRUE); - QVBoxLayout * layout = new QVBoxLayout(); - layout->setContentsMargins (3, 0, 3, 0); - layout->addWidget(desktop); - QWidget *window = new QWidget(); - window->setLayout(layout); - setCentralWidget(window); - - resize(400, 200); Tasks = 0; freeINTid = 1; ActiveConnections = 0; @@ -175,18 +140,6 @@ QKernel::QKernel() connect(Net_Notify, SIGNAL(activated(int)), this, SLOT(NetMessage())); } -/** - * Event invoked on resizing kernel application window. - * @copydoc QWidget::resizeEvent(QResizeEvent*) - */ -void QKernel::resizeEvent(QResizeEvent *ev) -{ -// QFrame::resizeEvent(ev); -// if (desktop) -// desktop->setGeometry(0, bar->height(), width(), -// height() - bar->height()); -} - /** * Displays window with information about not implemented functionality. */ @@ -303,7 +256,7 @@ void QKernel::LoadConfig(char * fname) * Executes program. * Additional window id displayed to set which code to execute. */ -void QKernel::Run_Prog() +void QKernel::on_actionExecute_triggered() { int i; QString s = QFileDialog::getOpenFileName(this, "Execute", progdir, "*.log"); @@ -321,7 +274,7 @@ void QKernel::Run_Prog() /** * Invokes editor program */ -void QKernel::Edit() +void QKernel::on_actionEditor_triggered() { char cmd[255]; sprintf(cmd, "%s/modules/logedit %s %s %s %s %s %s &", HomeDir, HomeDir, @@ -332,7 +285,7 @@ void QKernel::Edit() /** * Invokes help program */ -void QKernel::Help() +void QKernel::on_actionHelp_triggered() { char cmd[255]; sprintf(cmd, "%s/modules/loghelp %s/doc %s %s %s %s %s &", HomeDir, @@ -405,7 +358,7 @@ void QKernel::RunNetModule() * Connects to the specified address * Additional window is displayed to connect to the specified address */ -void QKernel::Connect() +void QKernel::on_actionConnect_triggered() { QDialog d(this, Qt::Dialog); QLabel lab("IP Address:", &d); @@ -437,7 +390,7 @@ void QKernel::Connect() /** * Disconnects from virtual machine */ -void QKernel::Disconnect() +void QKernel::on_actionDisconnect_triggered() { MESSAGE msg; @@ -526,50 +479,20 @@ void QKernel::DelAddress() * Additional window is displayed to set Node Number of node where send message, * and textfield to enter message. */ -void QKernel::MessageToNode() +void QKernel::on_actionMessage_triggered() { - QDialog *dlg; - QLineEdit *nodenr; MESSAGE m; - - dlg = new QDialog(this, Qt::Dialog); - dlg->setWindowTitle("Send message to node"); - - nodenr = new QLineEdit("number", dlg); - nodenr->setGeometry(90, 10, 50, 30); - nodenr->setText(""); - - QLabel *tmpQLabel; - tmpQLabel = new QLabel("Node number:", dlg); - tmpQLabel->setGeometry(10, 10, 77, 30); - - tmpQLabel = new QLabel("Message:", dlg); - tmpQLabel->setGeometry(10, 50, 70, 30); - - QLineEdit *msg; - msg = new QLineEdit("", dlg); - msg->setGeometry(80, 60, 330, 30); - - QPushButton *ob; - ob = new QPushButton("Send", dlg); - ob->setGeometry(230, 10, 80, 30); - ob->setDefault(TRUE); - - QPushButton *cb; - cb = new QPushButton("Cancel", dlg); - cb->setGeometry(330, 10, 80, 30); - dlg->resize(430, 110); - connect(ob, SIGNAL(clicked()), dlg, SLOT(accept())); - connect(cb, SIGNAL(clicked()), dlg, SLOT(reject())); + SendMessageDialog *dlg; + dlg = new SendMessageDialog(this); if (dlg->exec()) { m.msg_type = MSG_NET; m.param.pword[0] = NET_PROPAGATE; m.param.pword[1] = MSG_VLP; m.param.pword[2] = NodeNumber; - m.param.pword[4] = atoi(nodenr->text().toAscii().data()); + m.param.pword[4] = dlg->getNodeNumber(); m.param.pword[6] = VLP_WRITE; - strcpy(m.param.pstr, msg->text().toAscii().data()); + strcpy(m.param.pstr, dlg->getMessage().toAscii().data()); write(net_sock, &m, sizeof(MESSAGE)); } } @@ -579,7 +502,7 @@ void QKernel::MessageToNode() * Additional window is displayed to get ID of interpreter which should be * killed. */ -void QKernel::KillInterpreter() +void QKernel::on_actionKill_triggered() { QDialog *dlg; QLineEdit *nodenr; @@ -840,15 +763,11 @@ void QKernel::WriteMessage(char *msg) * Adds checkbox to menu item. If it is checked additional info messages are * shown. */ -void QKernel::SetMessages() +void QKernel::on_actionInfo_messages_triggered() { - if (toolsMenu != NULL) { - toolsInfoAction->setChecked(!toolsInfoAction->isChecked()); -// toolsInfoAction->toggle(); - info_messages = toolsInfoAction->isChecked(); - fprintf(stderr, "Info is checked? %s\n", toolsInfoAction->isChecked() ? "yes" : "no"); + if (menuTools != NULL) { + info_messages = actionInfo_messages->isChecked(); } -// menuBar()->repaint(); } /** @@ -856,7 +775,7 @@ void QKernel::SetMessages() * Additional window is displayed to set kernel options which are saved in * vlp.cfg file in kernel executable directory. */ -void QKernel::SetOptions() +void QKernel::on_actionOptions_triggered() { QDialog dlg(this, Qt::Dialog); dlg.setWindowTitle("Options"); @@ -995,7 +914,7 @@ void QKernel::SetOptions() * Additional window is displayed to enter password and retype it. If both are * same kernel window is locked. */ -void QKernel::LockConsole() +void QKernel::on_actionLock_Console_triggered() { QDialog d(this, Qt::Dialog); d.setWindowTitle("Lock console"); @@ -1054,7 +973,7 @@ void QKernel::LockConsole() * Additional window is displayed to enter password. If it is correct, kernel * window is unlocked */ -void QKernel::UnlockConsole() +void QKernel::on_actionUnlock_console_triggered() { QDialog d(this, Qt::Dialog); d.setWindowTitle("Enter password"); @@ -1346,7 +1265,7 @@ void QKernel::CloseInstances(InterpEntry *e) /** * Displays information about virtual machine */ -void QKernel::Info() +void QKernel::on_actionInfo_triggered() { MESSAGE m; @@ -1376,7 +1295,9 @@ int main(int argc, char **argv) } QApplication * app = new QApplication(argc, argv); + QKernel kernel; + kernel.show(); kernel.InitMessage(); diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index 168777c..a95a6f9 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -38,6 +38,7 @@ #include #include "comm.h" +#include "ui/main-window.h" #define GPATH "loggr" #define IPATH "logi" @@ -90,44 +91,37 @@ public: /** * Kernel class */ -class QKernel : public QMainWindow { +class QKernel : public QMainWindow, private Ui::MainWindow { Q_OBJECT public: - QTextEdit *desktop; - QMenuBar *bar; - QMenu *programMenu; - QMenu *machineMenu; - QMenu *toolsMenu; char progdir[256]; int NodeNumber; int ConType; - QKernel(); - - virtual void resizeEvent(QResizeEvent *ev); + QKernel(QWidget *parent = 0); void WriteMessage(char* msg); void InitMessage(); public slots: void n_impl(); - void Run_Prog(); - void Edit(); - void Help(); - void SetOptions(); + void on_actionExecute_triggered(); + void on_actionEditor_triggered(); + void on_actionHelp_triggered(); + void on_actionOptions_triggered(); void AddAddress(); void DelAddress(); - void LockConsole(); - void UnlockConsole(); - void MessageToNode(); + void on_actionLock_Console_triggered(); + void on_actionUnlock_console_triggered(); + void on_actionMessage_triggered(); void QuitProc(); void NetMessage(); void IntMessage(int); - void KillInterpreter(); - void Disconnect(); - void SetMessages(); - void Connect(); - void Info(); + void on_actionKill_triggered(); + void on_actionDisconnect_triggered(); + void on_actionInfo_messages_triggered(); + void on_actionConnect_triggered(); + void on_actionInfo_triggered(); protected: virtual void closeEvent (QCloseEvent * e); @@ -154,18 +148,6 @@ private: bool synchro; bool wait_for_info; char LockPasswd[25]; - QAction * toolsEditorAction; - QAction * toolsOptionsAction; - QAction * toolsInfoAction; - QAction * programExecuteAction; - QAction * programKillAction; - QAction * machineMessageAction; - QAction * machineConnectAction; - QAction * machineDisconnectAction; - QAction * machineInfoAction; - QAction * toolsLockAction; - QAction * toolsUnlockAction; - QAction * quitAction; int net_sock; int freeINTid; diff --git a/src/kernel/send-message.h b/src/kernel/send-message.h new file mode 100644 index 0000000..2653a0f --- /dev/null +++ b/src/kernel/send-message.h @@ -0,0 +1,77 @@ +/************************************************************** + + Copyright (C) 2013 Rafał Długołęcki + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + + + + NOTE: This software is using the free software license of + the QT library v.1.30 from Troll Tech AS. + See the file LICENSE.QT. + +************************************************************/ + +#ifndef VLP_SEND_MESSAGE_H +#define VLP_SEND_MESSAGE_H + +#include +#include +#include + +#include "ui/dialogs/send-message.h" + +/** + * Class responsible for displaying dialog for sending messages + */ +class SendMessageDialog : public QDialog, private Ui::sendMessageDialog { +public: + /** + * Constructs a SendMessageDialog with parent 'parent'. + * The widget flags f are passed on to the QWidget constructor. + * + * @param parent parent widget of this dialog + * @param flags QDialog flags of this dialog + */ + SendMessageDialog(QWidget * parent = 0, Qt::WindowFlags flags = 0 ) : + QDialog(parent, flags) + { + setupUi(this); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + } + + /** + * Returns entered in dialog node number + * @return node number from this dialog textfield + */ + int getNodeNumber() + { + return atoi(nodeNumber->text().toAscii().data()); + } + + /** + * Returns entered in dialog message + * @return message from this dialog textarea + */ + QString getMessage() + { + return message->toPlainText(); + } +}; + + +#endif /* VLP_SEND_MESSAGE_H */ -- 2.30.2