Debian Codegraph @

HercConfiguration/ConsoleProperties.cpp

raw symbols SCIP
1 /*
2 * File: ConsoleProperties.cpp
3 *
4 * Author: Jacob Dekel
5 * Created on: Aug 7, 2009
6 *
7 * Copyright (c) 2009-2013 Jacob Dekel
8 * $Id$
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25 #include "ConsoleProperties.h"
26 #include "HerculesStudio.h"
27
28 #include <sstream>
29 #include <iostream>
30
31 ConsoleProperties::ConsoleProperties(ConfigLine & line, QWidget *parent)
32 : GenericDeviceProperties(line, parent), mLine(line)
33 {
34 ui.setupUi(this);
35 if (!mLine.isNew())
36 {
37 hOutDebug(5, "not new" << mLine.getLine());
38 ui.deviceNumber->setText(mLine.getToken(0).c_str());
39
40 if (mLine.getToken(1) == "1052")
41 ui.deviceCombo->setCurrentIndex(0);
42 else if (mLine.getToken(1) == "3215")
43 ui.deviceCombo->setCurrentIndex(1);
44 else if (mLine.getLowercaseToken(1) == "1052-c")
45 ui.deviceCombo->setCurrentIndex(2);
46 else ui.deviceCombo->setCurrentIndex(3);
47
48 if (ui.deviceCombo->currentIndex() >= 2)
49 // integrated
50 {
51 setIntegrated(true);
52
53 if (mLine.size() > 2)
54 {
55 ui.commandPrefix->setText(mLine.getToken(2).c_str());
56 }
57 }
58 else // not integrated
59 {
60 setIntegrated(false);
61 int index=2;
62 if (mLine.getToken(index) == "noprompt")
63 {
64 ui.noPromptCheckBox->setChecked(true);
65 index++;
66 }
67
68 if (mLine.size() > index)
69 {
70 if (mLine.getToken(index).length() > 0 && mLine.getToken(index)[0] != '*')
71 ui.terminalGroup->setText(mLine.getToken(index).c_str());
72 ui.ipAddress->setText(mLine.getToken(index+1).c_str());
73 ui.subnetMask->setText(mLine.getToken(index+2).c_str());
74 }
75 }
76 }
77 else
78 {
79 setIntegrated(false);
80 }
81 connect(ui.OKButton, SIGNAL(clicked()), this, SLOT(ok()));
82 connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
83 connect(ui.deviceCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(deviceTypeChanged(int)) );
84 }
85
86 ConsoleProperties::~ConsoleProperties()
87 {
88
89 }
90
91 void ConsoleProperties::ok()
92 {
93 if (!deviceNumberValidator(ui.deviceNumber))
94 return;
95 if ( (ui.deviceCombo->currentIndex() < 2) && !validateIp(ui.ipAddress,false, false))
96 return;
97 if (!validateIp(ui.subnetMask,true, false))
98 return;
99 std::stringstream newLineBuff;
100 if (ui.deviceCombo->currentIndex() >= 2)
101 {
102 newLineBuff << ui.deviceNumber->text().toStdString() << " "
103 << ui.deviceCombo->currentText().toStdString() << " "
104 << ui.commandPrefix->text().toStdString() + "\n";
105 }
106 else
107 {
108 newLineBuff << ui.deviceNumber->text().toStdString()
109 << " " << ui.deviceCombo->currentText().toStdString();
110
111 // noprompt
112 if (ui.noPromptCheckBox->isChecked())
113 newLineBuff << " noprompt" ;
114
115 // terminal group
116 if (ui.terminalGroup->text().length() > 0)
117 newLineBuff << " " << ui.terminalGroup->text().toStdString();
118 else
119 newLineBuff << " *";
120
121 // ip address
122 newLineBuff << " " << ui.ipAddress->text().toStdString();
123
124 // subnet mask
125 if (ui.subnetMask->text() != "...")
126 newLineBuff << " " << ui.subnetMask->text().toStdString();
127
128 newLineBuff << "\n";
129
130 }
131 hOutDebug(5, newLineBuff.str());
132 mLine.replaceLine(newLineBuff.str());
133 emit updateLine(true);
134 this->deleteLater();
135 }
136
137 void ConsoleProperties::cancel()
138 {
139 emit updateLine(false);
140 deleteLater();
141 }
142
143 void ConsoleProperties::setIntegrated(bool integrated)
144 {
145 ui.commandPrefix->setVisible(integrated);
146 ui.noPromptCheckBox->setEnabled(!integrated);
147 ui.label_terminal->setText( integrated ? "Command Prefix" : "Terminal Group");
148 ui.terminalGroup->setVisible(!integrated);
149 ui.ipAddress->setEnabled(!integrated);
150 ui.subnetMask->setEnabled(!integrated);
151
152 }
153
154 void ConsoleProperties::deviceTypeChanged(int index)
155 {
156 if (index >= 2)
157 setIntegrated(true);
158 else
159 setIntegrated(false);
160 }