vlp-27 Added move OptionsDialog to the QtDesigner generated one.
[vlp.git] / src / kernel / options.h
1 /**************************************************************
2
3   Copyright (C) 2013  Rafał Długołęcki
4
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation; either version 2
8  of the License, or (at your option) any later version.
9
10  This program is distributed in the hope that it will be useful, 
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  GNU General Public License for more details.
14
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19
20
21
22  NOTE: This software is using the free software license of 
23        the QT library v.1.30 from Troll Tech AS.
24        See the file LICENSE.QT.
25
26 ************************************************************/
27
28 #ifndef VLP_OPTIONS_DIALOG_H
29 #define VLP_OPTIONS_DIALOG_H
30
31 #include <QtGui/QDialog>
32 #include <QtCore/QString>
33 #include <stdlib.h>
34
35 #include "ui/dialogs/options.h"
36 #include "kernel.h"
37
38 /**
39  * Class responsible for displaying dialog with VLP configuration
40  */
41 class OptionsDialog : public QDialog, private Ui::optionsDialog {
42         Q_OBJECT
43 public:
44         /**
45          * Constructs an OptionsDialog with parent 'parent'.
46          * The widget flags f are passed on to the QWidget constructor.
47          *
48          * @param parent parent widget of this dialog
49          * @param flags QDialog flags of this dialog
50          */
51         OptionsDialog(QWidget * parent = 0, Qt::WindowFlags flags = 0) :
52                 QDialog(parent, flags)
53         {
54                 setupUi(this);
55                 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
56                 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
57         }
58         
59         /**
60          * Returns entered in dialog node number
61          * @return node number from this dialog textfield
62          */
63         int getNodeNumber()
64         {
65                 return atoi(nodeNumber->text().toAscii().data());
66         }
67         
68         /**
69          * Sets default node number
70          * @param number node number which will be set in textfield
71          */
72         void setDefaultNodeNumber(int number)
73         {
74                 QString str = QString::number(number);
75                 nodeNumber->setText(str);
76         }
77         
78         /**
79          * Returns entered in dialog message
80          * @return message from this dialog textarea
81          */
82         QString getConnectionType()
83         {
84                 /* QtDesigner 4.5 does not have QButtonGroup. This is temporary
85                  * code to check correct setting
86                  */
87                 return explicit_2->isChecked() ?
88                         explicit_2->text() : registration->text();
89         }
90
91         /**
92          * Returns entire widget QListView containing connections list.
93          * Use it for get entered by user connections
94          * @return QListView pointer containing list of connections
95          */
96         QListWidget * getConnectionList()
97         {
98                 return connections;
99         }
100
101         /**
102          * Returns entered in dialog Programs Directory
103          * @return programs directory
104          */
105         QString getProgramsDirectory()
106         {
107                 return programsDirectory->text();
108         }
109         
110         /**
111          * Sets default node number
112          * @param directory programs direcotry which will be set in textfield
113          */
114         void setDefaultProgramsDirectory(QString directory)
115         {
116                 programsDirectory->setText(directory);
117         }
118
119         /**
120          * Adds given ConnectEntry data to the dialog QListView
121          * @param entry ConnectEntry to add to list of connections
122          */
123         void addConnection(ConnectEntry *entry) {
124                 connections->addItem(entry->addr);
125         }
126
127 private slots:
128         /**
129          * Adds IP address to the configuration.
130          * Additional window is displayed to add address to the list
131          */
132         void on_addConnection_clicked()
133         {
134                 QDialog dialog(this, Qt::Dialog);
135                 QLabel lab("IP Address:", &dialog);
136                 QLineEdit ed("", &dialog);
137                 QPushButton ok("Ok", &dialog);
138                 QPushButton cancel("Cancel", &dialog);
139
140                 ok.setGeometry(30, 60, 80, 30);
141                 ok.setDefault(TRUE);
142                 lab.setGeometry(10, 10, 60, 30);
143                 ed.setGeometry(70, 10, 140, 30);
144                 cancel.setGeometry(130, 60, 80, 30);
145                 dialog.resize(240, 100);
146
147                 connect(&ok, SIGNAL(clicked()), &dialog, SLOT(accept()));
148                 connect(&cancel, SIGNAL(clicked()), &dialog, SLOT(reject()));
149
150                 if (dialog.exec()) {
151                         if (strcmp(ed.text().toAscii().data(), "") != 0) {
152                                 connections->addItem(ed.text());
153                         }
154                 }
155         
156         }
157
158         /**
159          * Deletes current address from available connections.
160          */
161         void on_deleteConnection_clicked()
162         {
163                 int row = connections->currentRow();
164                 if (row != -1) {
165                         delete connections->item(row);
166                 }
167         }
168 };
169
170
171 #endif /* VLP_OPTIONS_DIALOG_H */