vlp-27 Added move OptionsDialog to the QtDesigner generated one.
authorRafał Długołęcki <kontakt@dlugolecki.net.pl>
Tue, 29 Oct 2013 23:45:09 +0000 (00:45 +0100)
committerRafał Długołęcki <kontakt@dlugolecki.net.pl>
Tue, 29 Oct 2013 23:45:09 +0000 (00:45 +0100)
Makefile.am
data/kernel/dialogs/options.ui
src/kernel/kernel.cpp
src/kernel/kernel.h
src/kernel/options.h [new file with mode: 0644]

index 1dd212bb2e7acf7345c94f50db75436e4dceeb5b..efc6331eeb911145aeaa9f0ce7cde88019e0fdef 100644 (file)
@@ -62,7 +62,10 @@ 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/options.moc.cpp
 bin_logker_CPPFLAGS = $(bin_logker_CFLAGS)
 bin_logker_LDADD = $(bin_logker_LIBS)
 bin_logkerdir = src/kernel src/kernel/ui src/kernel/ui/dialogs
@@ -93,9 +96,12 @@ src/kernel/ui/dialogs/send-message.h: data/kernel/dialogs/send-message.ui
 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
+
+src/kernel/options.moc.cpp:
+       moc-qt4 src/kernel/options.h -o src/kernel/options.moc.cpp
        
 clean-logker-extra:
-       rm -f src/kernel/*.moc
+       rm -f src/kernel/*.moc.cpp
        rm -f bin/logker
        
 bin_logint_SOURCES = \
index bf757582ad94595c1940ffc8ce688e8422b8f8b1..1753920f730935509efd5b7c8a1f3742b68e052c 100644 (file)
@@ -24,7 +24,7 @@
       </widget>
      </item>
      <item>
-      <widget class="QLineEdit" name="homeDirectory"/>
+      <widget class="QLineEdit" name="programsDirectory"/>
      </item>
     </layout>
    </item>
@@ -44,7 +44,7 @@
    <item>
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
-      <string>Virtual Processor properties</string>
+      <string>Virtual Processor properties (activated after restart)</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_7">
       <item>
@@ -61,7 +61,7 @@
              </widget>
             </item>
             <item>
-             <widget class="QLineEdit" name="lineEdit_2"/>
+             <widget class="QLineEdit" name="nodeNumber"/>
             </item>
            </layout>
           </item>
@@ -71,7 +71,7 @@
              <set>Qt::ImhExclusiveInputMask</set>
             </property>
             <property name="title">
-             <string>GroupBox</string>
+             <string>Connection type</string>
             </property>
             <layout class="QVBoxLayout" name="verticalLayout_6">
              <item>
                <property name="text">
                 <string>Explicit</string>
                </property>
+               <property name="checked">
+                <bool>true</bool>
+               </property>
               </widget>
              </item>
              <item>
               <widget class="QRadioButton" name="registration">
+               <property name="enabled">
+                <bool>false</bool>
+               </property>
                <property name="text">
                 <string>Registration</string>
                </property>
            </widget>
           </item>
           <item>
-           <widget class="QListView" name="listView"/>
+           <widget class="QListWidget" name="connections"/>
           </item>
          </layout>
         </item>
index 8321476ff915e4c37d017939894065d160f132e9..0ac3ba7f21806a3a9198d38ceecc30f2b7ec47c0 100644 (file)
@@ -66,6 +66,7 @@
 #include "kernel.h"
 #include "send-message.h"
 #include "kill-interpreter.h"
+#include "options.h"
 
 /* File resides in top directory (where are Makefiles)*/
 #include "../../config.h"
@@ -431,50 +432,6 @@ void QKernel::QuitProc()
        QApplication::instance()->quit();
 }
 
-/**
- * Adds IP address to the configuration.
- * Additional window is displayed to add address to the list
- */
-void QKernel::AddAddress()
-{
-       QDialog d(this, Qt::Dialog);
-       QLabel lab("IP Address:", &d);
-       QLineEdit ed("", &d);
-       QPushButton ob("", &d);
-       QPushButton cb("", &d);
-
-       if (connections) {
-               ob.setGeometry(30, 60, 80, 30);
-               ob.setText("Ok");
-               ob.setDefault(TRUE);
-               lab.setGeometry(10, 10, 60, 30);
-               lab.setText("Address");
-               ed.setGeometry(70, 10, 140, 30);
-               cb.setGeometry(130, 60, 80, 30);
-               cb.setText("Cancel");
-               d.resize(240, 100);
-               connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
-               connect(&cb, SIGNAL(clicked()), &d, SLOT(reject())); 
-               if (d.exec())
-                       if (strcmp(ed.text().toAscii().data(), "") != 0) {
-                               connections->addItem(ed.text());
-                       }
-       }
-}
-
-/**
- * Deletes current address from available connections.
- */
-void QKernel::DelAddress()
-{
-       if (connections) {
-               if (connections->currentRow() != -1) {
-                       /* TODO: Checki if this work correctly after porting */
-                       connections->removeItemWidget(connections->currentItem());
-               }
-       }
-}
-
 /**
  * Sends message to node.
  * Additional window is displayed to set Node Number of node where send message,
@@ -759,92 +716,20 @@ void QKernel::on_actionInfo_messages_triggered()
  */
 void QKernel::on_actionOptions_triggered()
 {
-       QDialog dlg(this, Qt::Dialog);
-       dlg.setWindowTitle("Options");
+       OptionsDialog * dlg = new OptionsDialog(this, Qt::Dialog);
        ConnectEntry *e;
+       QListWidget *connections;
        unsigned int i;
 
-       QLineEdit* progs;
-       progs = new QLineEdit(progdir, &dlg);
-       progs->setGeometry(150, 20, 180, 30);
-
-       QLabel* tmpQLabel;
-       tmpQLabel = new QLabel("Programs directory", &dlg);
-       tmpQLabel->setGeometry(30, 20, 120, 30);
-
-       QFrame* tmpQFrame;
-       tmpQFrame = new QFrame(&dlg);
-       tmpQFrame->setGeometry(10, 60, 380, 30);
-       tmpQFrame->setFrameStyle(52);
+       dlg->setDefaultNodeNumber(NodeNumber);
+       dlg->setDefaultProgramsDirectory(progdir);
 
-       tmpQLabel = new QLabel("Virtual Processor properties (activated after "
-                                               "restarting VLP):", &dlg);
-       tmpQLabel->setGeometry(10, 80, 340, 30);
-
-       QLineEdit *nn;
-       char nns[256];
-       sprintf(nns, "%d", NodeNumber);
-       nn = new QLineEdit(nns, &dlg);
-       nn->setGeometry(110, 110, 40, 30);
-
-       tmpQLabel = new QLabel("Node number:", &dlg);
-       tmpQLabel->setGeometry(20, 110, 90, 30);
-
-       QRadioButton *exp, *reg;
-       exp = new QRadioButton("Explicit", &dlg);
-       exp->setGeometry(30, 170, 100, 30);
-       exp->setChecked(TRUE);
-
-       reg = new QRadioButton("Registration", &dlg);
-       reg->setGeometry(30, 200, 100, 30);
-       reg->setEnabled(FALSE);
-
-       connections = new QListWidget(&dlg);
-       connections->setGeometry(170, 140, 130, 100);
-
-       for (int i = 0; i < ConnectList.size(); i++) {
+       for (i = 0; i < ConnectList.size(); i++) {
                e = ConnectList.at(i);
-               connections->addItem(e->addr);
+               dlg->addConnection(e);
        }
 
-       tmpQLabel = new QLabel("Connection list:", &dlg);
-       tmpQLabel->setGeometry(170, 110, 100, 30);
-
-       QPushButton *addbtn;
-       QPushButton *delbtn;
-       QPushButton *okbtn;
-       QPushButton *cancelbtn;
-       addbtn = new QPushButton("Add", &dlg);
-       addbtn->setGeometry(310, 150, 60, 30);
-       connect(addbtn, SIGNAL(clicked()), this, SLOT(AddAddress()));
-
-       delbtn = new QPushButton("Del", &dlg);
-       delbtn->setGeometry(310, 200, 60, 30);
-       connect(delbtn, SIGNAL(clicked()), this, SLOT(DelAddress()));
-
-       okbtn = new QPushButton("Ok", &dlg);
-       okbtn->setGeometry(80, 260, 100, 30);
-       okbtn->setDefault(TRUE);
-       connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       cancelbtn = new QPushButton("Cancel", &dlg);
-       cancelbtn->setGeometry(210, 260, 100, 30);
-       connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
-
-       QGroupBox* group;
-       group = new QGroupBox("Connection type", &dlg);
-       group->setGeometry(20, 150, 120, 90);
-       group->setAlignment(Qt::AlignLeft);
-       group->lower();
-
-       QVBoxLayout *vbox = new QVBoxLayout();
-       vbox->addWidget(exp);
-       vbox->addWidget(reg);
-       vbox->addStretch(1);
-       group->setLayout(vbox);
-
-       dlg.resize(400, 310);
-       if (dlg.exec()) {
+       if (dlg->exec()) {
                config_t cfg;
                config_setting_t *root;
                config_setting_t *setting;
@@ -854,12 +739,12 @@ void QKernel::on_actionOptions_triggered()
 
                setting = config_setting_add(root, "progdir",
                                                        CONFIG_TYPE_STRING);
-               config_setting_set_string(setting, progs->text().toAscii().data());
-               strcpy(progdir, progs->text().toAscii().data());
+               strcpy(progdir, dlg->getProgramsDirectory().toAscii().data());
+               config_setting_set_string(setting, progdir);
 
                setting = config_setting_add(root, "node_number",
                                                        CONFIG_TYPE_INT);
-               config_setting_set_int(setting, atoi(nn->text().toAscii().data()));
+               config_setting_set_int(setting, dlg->getNodeNumber());
 
                setting = config_setting_add(root, "homedir",
                                                        CONFIG_TYPE_STRING);
@@ -867,12 +752,15 @@ void QKernel::on_actionOptions_triggered()
 
                setting = config_setting_add(root, "type",
                                                        CONFIG_TYPE_STRING);
-               if (exp->isChecked()) {
+               if (strcmp(dlg->getConnectionType().toLower().toAscii().data(),
+                                                       "explicit") == 0) {
                        config_setting_set_string(setting, "explicit");
 
                        config_setting_t *hosts = NULL;
                        hosts = config_setting_add(root, "host",
                                                        CONFIG_TYPE_ARRAY);
+                       
+                       connections = dlg->getConnectionList();
                        for(i = 0; i < connections->count(); i++) {
                                setting = config_setting_add(hosts, NULL,
                                                        CONFIG_TYPE_STRING);
index a95a6f98b99e1436a6d9b85e36658dd5c64eda0b..6d71fc036d96153d28a285e400ad163394608e55 100644 (file)
@@ -96,6 +96,10 @@ class QKernel : public QMainWindow, private Ui::MainWindow {
 public:
        char progdir[256];
        int NodeNumber;
+       /**
+        * Connection type (explicit = 1/registration = 2)
+        * @attention It looks that it is not used 
+        */
        int ConType;
 
        QKernel(QWidget *parent = 0);
@@ -109,8 +113,6 @@ public slots:
        void on_actionEditor_triggered();
        void on_actionHelp_triggered();
        void on_actionOptions_triggered();
-       void AddAddress();
-       void DelAddress();
        void on_actionLock_Console_triggered();
        void on_actionUnlock_console_triggered();
        void on_actionMessage_triggered();
@@ -129,7 +131,6 @@ protected:
 private:
        QList<InterpEntry*> Interpreters;
        QList<ConnectEntry*> ConnectList;
-       QListWidget *connections;
        
        /**
         * number of working interpreters
diff --git a/src/kernel/options.h b/src/kernel/options.h
new file mode 100644 (file)
index 0000000..7dd1f89
--- /dev/null
@@ -0,0 +1,171 @@
+/**************************************************************
+
+  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_OPTIONS_DIALOG_H
+#define VLP_OPTIONS_DIALOG_H
+
+#include <QtGui/QDialog>
+#include <QtCore/QString>
+#include <stdlib.h>
+
+#include "ui/dialogs/options.h"
+#include "kernel.h"
+
+/**
+ * Class responsible for displaying dialog with VLP configuration
+ */
+class OptionsDialog : public QDialog, private Ui::optionsDialog {
+       Q_OBJECT
+public:
+       /**
+        * Constructs an OptionsDialog 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
+        */
+       OptionsDialog(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());
+       }
+       
+       /**
+        * Sets default node number
+        * @param number node number which will be set in textfield
+        */
+       void setDefaultNodeNumber(int number)
+       {
+               QString str = QString::number(number);
+               nodeNumber->setText(str);
+       }
+       
+       /**
+        * Returns entered in dialog message
+        * @return message from this dialog textarea
+        */
+       QString getConnectionType()
+       {
+               /* QtDesigner 4.5 does not have QButtonGroup. This is temporary
+                * code to check correct setting
+                */
+               return explicit_2->isChecked() ?
+                       explicit_2->text() : registration->text();
+       }
+
+       /**
+        * Returns entire widget QListView containing connections list.
+        * Use it for get entered by user connections
+        * @return QListView pointer containing list of connections
+        */
+       QListWidget * getConnectionList()
+       {
+               return connections;
+       }
+
+       /**
+        * Returns entered in dialog Programs Directory
+        * @return programs directory
+        */
+       QString getProgramsDirectory()
+       {
+               return programsDirectory->text();
+       }
+       
+       /**
+        * Sets default node number
+        * @param directory programs direcotry which will be set in textfield
+        */
+       void setDefaultProgramsDirectory(QString directory)
+       {
+               programsDirectory->setText(directory);
+       }
+
+       /**
+        * Adds given ConnectEntry data to the dialog QListView
+        * @param entry ConnectEntry to add to list of connections
+        */
+       void addConnection(ConnectEntry *entry) {
+               connections->addItem(entry->addr);
+       }
+
+private slots:
+       /**
+        * Adds IP address to the configuration.
+        * Additional window is displayed to add address to the list
+        */
+       void on_addConnection_clicked()
+       {
+               QDialog dialog(this, Qt::Dialog);
+               QLabel lab("IP Address:", &dialog);
+               QLineEdit ed("", &dialog);
+               QPushButton ok("Ok", &dialog);
+               QPushButton cancel("Cancel", &dialog);
+
+               ok.setGeometry(30, 60, 80, 30);
+               ok.setDefault(TRUE);
+               lab.setGeometry(10, 10, 60, 30);
+               ed.setGeometry(70, 10, 140, 30);
+               cancel.setGeometry(130, 60, 80, 30);
+               dialog.resize(240, 100);
+
+               connect(&ok, SIGNAL(clicked()), &dialog, SLOT(accept()));
+               connect(&cancel, SIGNAL(clicked()), &dialog, SLOT(reject()));
+
+               if (dialog.exec()) {
+                       if (strcmp(ed.text().toAscii().data(), "") != 0) {
+                               connections->addItem(ed.text());
+                       }
+               }
+       
+       }
+
+       /**
+        * Deletes current address from available connections.
+        */
+       void on_deleteConnection_clicked()
+       {
+               int row = connections->currentRow();
+               if (row != -1) {
+                       delete connections->item(row);
+               }
+       }
+};
+
+
+#endif /* VLP_OPTIONS_DIALOG_H */