Debian Codegraph @

HercConfiguration/DasdProperties.cpp

raw symbols SCIP
1 /*
2 * File: DasdProperties.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 "DasdProperties.h"
26 #include "Preferences.h"
27
28 #include <QFileDialog>
29 #include <QMessageBox>
30
31 #include <sstream>
32
33 std::string DasdProperties::ckd[] = {"2305", "2311", "2314", "3330", "3340", "3350",
34 "3375", "3380", "3390", "9345", ""};
35
36 std::string DasdProperties::fba[] = {"3310", "3370", "9332", "9335", "9336", "0671", ""};
37
38 DasdProperties::DasdProperties(ConfigLine& configLine, QWidget *parent)
39 : GenericDeviceProperties(configLine, parent)
40 {
41 ui.setupUi(this);
42
43 connect(ui.okButton, SIGNAL(clicked()), this, SLOT(ok()));
44 connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
45 connect(ui.typeCombo, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(typeChanged(const QString &)));
46 connect(ui.localRadioButton,SIGNAL(toggled(bool)), this, SLOT(localInetChanged()));
47 connect(ui.browseButton, SIGNAL(clicked()), this, SLOT(browseClicked()));
48 connect(ui.browseShadowButton, SIGNAL(clicked()), this, SLOT(browseShadowClicked()));
49
50 initialize(configLine);
51 }
52
53 DasdProperties::~DasdProperties()
54 {
55
56 }
57
58 void DasdProperties::ok()
59 {
60 if (!deviceNumberValidator(ui.deviceNumber))
61 return;
62 std::stringstream newLineBuff;
63
64 newLineBuff << ui.deviceNumber->text().toStdString() << " "
65 << ui.typeCombo->currentText().toStdString();
66
67 if (ui.localRadioButton->isChecked())
68 {
69 if (ui.filename->text().isEmpty())
70 {
71 QMessageBox * p = new QMessageBox(this);
72 p->setText("Please enter file name");
73 p->exec();
74 ui.filename->setFocus();
75 return;
76 }
77 newLineBuff << " " << ui.filename->text().toStdString();
78 }
79 else
80 {
81 if (!validateIp(ui.remotehost, false, false))
82 return;
83 newLineBuff << " " << ui.remotehost->text().toStdString() << ":" << ui.portSpinBox->value() << ":" << ui.devnoSpinBox->value();
84 }
85
86 if (ui.nosynchioCheckBox->isChecked())
87 newLineBuff << " nosyncio";
88 if (!ui.shadow->text().isEmpty())
89 newLineBuff << " sf=" << ui.shadow->text().toStdString();
90
91 if (!isFba(ui.typeCombo->currentText().toStdString()))
92 {
93 if (ui.cuComboBox->currentIndex()>0)
94 newLineBuff << " cu=" << ui.cuComboBox->currentText().toStdString();
95 if (!ui.standardRadioButton->isChecked())
96 {
97 newLineBuff << (ui.ReadonlyRadioButton->isChecked() ? " readonly" : " fakewrite");
98 }
99 }
100 else
101 {
102 //TODO
103 }
104
105 newLineBuff << "\n";
106 mLine.replaceLine(newLineBuff.str());
107 emit updateLine(true);
108 this->deleteLater();
109 }
110
111 void DasdProperties::cancel()
112 {
113 emit updateLine(false);
114 this->deleteLater();
115 }
116
117 void DasdProperties::browseClicked()
118 {
119 std::string s = QFileDialog::getOpenFileName(this,
120 "Locate DASD File",
121 Preferences::getInstance().configDir().c_str(),
122 tr("All files(*)")).toUtf8().data();
123 ui.filename->setText(s.c_str());
124 }
125
126 void DasdProperties::browseShadowClicked()
127 {
128 std::string s = QFileDialog::getOpenFileName(this,
129 "Locate Shadow DASD File",
130 Preferences::getInstance().configDir().c_str(),
131 tr("All files(*)")).toUtf8().data();
132 ui.shadow->setText(s.c_str());
133 }
134
135 void DasdProperties::typeChanged(const QString& newValue)
136 {
137 if (isFba(newValue.toStdString()))
138 setFba(true);
139 else
140 setCkd(true);
141 }
142
143
144 void DasdProperties::localInetChanged()
145 {
146 if (ui.localRadioButton->isChecked())
147 {
148 setLocal(true);
149 }
150 else
151 setInet(true);
152 }
153
154 void DasdProperties::setLocal(bool set)
155 {
156 if (set)
157 setInet(!set);
158 ui.filenameLabel->setVisible(set);
159 ui.filename->setVisible(set);
160 ui.browseButton->setVisible(set);
161 ui.shadowLabel->setVisible(set);
162 ui.shadow->setVisible(set);
163 ui.browseShadowButton->setVisible(set);
164 }
165
166 void DasdProperties::setInet(bool set)
167 {
168 if (set)
169 setLocal(!set);
170 ui.remotehostLabel->setVisible(set);
171 ui.remotehost->setVisible(set);
172 ui.portLabel->setVisible(set);
173 ui.portSpinBox->setVisible(set);
174 ui.devnoLabel->setVisible(set);
175 ui.devnoSpinBox->setVisible(set);
176 }
177
178 bool DasdProperties::isFba(const std::string& dev)
179 {
180 int i=0;
181 while (fba[i] != "")
182 {
183 if (dev == fba[i])
184 return true;
185 i++;
186 }
187 return false;
188 }
189
190 void DasdProperties::setFba(bool set)
191 {
192 if (set) setCkd(false);
193 }
194
195 void DasdProperties::setCkd(bool set)
196 {
197 if (set) setFba(false);
198 ui.ioModeGroupbox->setVisible(set);
199 ui.cuComboBox->setVisible(set);
200 ui.cuLabel->setVisible(set);
201 }
202
203 bool DasdProperties::isInet(const std::string& fileName, stringArray & vec)
204 {
205 int count;
206 size_t ppos= -1;
207 size_t pos = -2;
208 for (count = 0; count < 3 && pos != std::string::npos; count++)
209 {
210 pos = fileName.find(':',ppos+1);
211 if (pos != std::string::npos)
212 {
213 std::string s = fileName.substr(ppos+1,pos-ppos-1);
214 vec[count] = s;
215 ppos = pos;
216 }
217 else if (count ==2)
218 vec[2] = fileName.substr(ppos+1);
219
220 }
221 return count==3;
222 }
223
224 void DasdProperties::initialize(ConfigLine& line)
225 {
226 ui.deviceNumber->setText(line.getToken(0).c_str());
227 int origType = ui.typeCombo->currentIndex();
228 for (int i=0; i<ui.typeCombo->maxCount(); i++)
229 {
230 ui.typeCombo->setCurrentIndex(i);
231 if (ui.typeCombo->currentText().toStdString() == line.getToken(1))
232 break;
233 else
234 ui.typeCombo->setCurrentIndex(-1);
235 }
236 if (ui.typeCombo->currentIndex() == -1)
237 ui.typeCombo->setCurrentIndex(origType);
238 std::string vec[3];
239 if (isInet(line.getToken(2), vec))
240 {
241 ui.remotehost->setText(vec[0].c_str());
242 ui.portSpinBox->setValue(atoi(vec[1].c_str()));
243 ui.devnoSpinBox->setValue(atoi(vec[2].c_str()));
244 ui.inetRadioButton->setChecked(true);
245 }
246 else
247 {
248 std::string token = line.getToken(2);
249 ui.filename->setText(token.c_str());
250 }
251 for (int i=2; i<line.size(); i++)
252 {
253 if (line.getToken(i).substr(0,3) == "sf=")
254 {
255 ui.shadow->setText(line.getToken(i).substr(3).c_str());
256 }
257 else if (line.getToken(i) == "nosyncio" || line.getToken(i) == "syio")
258 {
259 ui.nosynchioCheckBox->setChecked(true);
260 }
261 else if (line.getToken(i) == "nosyncio" || line.getToken(i) == "syio")
262 {
263 ui.nosynchioCheckBox->setChecked(true);
264 }
265 else if (line.getToken(i) == "readonly" || line.getToken(i) == "rdonly"|| line.getToken(i) == "ro")
266 {
267 ui.ReadonlyRadioButton->setChecked(true);
268 }
269 else if (line.getToken(i) == "fakewrite" || line.getToken(i) == "fakewrt"|| line.getToken(i) == "fw")
270 {
271 ui.fakeWritesRadioButton->setChecked(true);
272 }
273 else if (line.getToken(i).substr(0,3) == "cu=")
274 {
275 std::string cu = line.getToken(i).substr(3);
276 for (int ii=0; ii<ui.cuComboBox->maxCount(); ii++)
277 {
278 ui.cuComboBox->setCurrentIndex(ii);
279 if (ui.cuComboBox->currentText().toStdString() == cu)
280 break;
281 else
282 ui.cuComboBox->setCurrentIndex(-1);
283 }
284 }
285 }
286
287 localInetChanged();
288 typeChanged(ui.typeCombo->currentText());
289
290 }