vlp-27 Added move OptionsDialog to the QtDesigner generated one.
[vlp.git] / src / kernel / options.h
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 */