#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"
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,
*/
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;
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);
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);
--- /dev/null
+/**************************************************************
+
+ 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 */