Debian Codegraph @

HercUtilities/DasdInit.cpp

raw symbols SCIP
1 /*
2 * File: DasdInit.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 "DasdInit.h"
26 #include "UtilityExecutor.h"
27 #include "UtilityRunner.h"
28 #include "DasdTab.h"
29 #include "LineEditWithFocus.h"
30 #include "StringTokenizer.h"
31 #include "Preferences.h"
32 #include "ConfigurationEditor.h"
33 #include "SystemUtils.h"
34
35 #include <QMessageBox>
36 #include <QProcess>
37 #include <QFileDialog>
38
39 #include <string>
40 #include <sstream>
41 #include <cerrno>
42 #include <sys/types.h>
43 #include <csignal>
44
45 DasdInit::DasdInit(QWidget *parent)
46 : GenericUtility("dasdinit", parent)
47 {
48 ui.setupUi(this);
49 ui.volser->setValidator(new VolserValidator(this));
50 QLineEdit *old = ui.filename;
51 LineEditWithFocus * myLineEdit = new LineEditWithFocus(ui.groupBox);
52 ui.filename = myLineEdit;
53 ui.filename->setObjectName(old->objectName());
54 ui.filename->setGeometry(old->geometry());
55 delete old;
56
57 ui.path->setText(Preferences::getInstance().configDir().c_str());
58
59 ui.progressBar->setVisible(false);
60 ui.sizeSpinBox->setEnabled(false);
61 ui.linuxCheckBox->setEnabled(false);
62 setSizeValue();
63
64 connect(ui.rawCheckBox, SIGNAL(stateChanged(int)), this, SLOT(rawSlot(int)));
65 connect(ui.runButton, SIGNAL(clicked()), this, SLOT(runClicked()));
66 connect(ui.exitButton, SIGNAL(clicked()), this, SLOT(exitClicked()));
67 connect(ui.sizeCheckBox, SIGNAL(clicked()), this, SLOT(sizeClicked()));
68 connect(ui.deviceTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(newDevType()));
69 connect(ui.browseButton, SIGNAL(clicked()), this, SLOT(browseClicked()));
70 connect(myLineEdit, SIGNAL(FocusGained()), this, SLOT(filenameFocus()));
71 }
72
73 DasdInit::~DasdInit()
74 {
75
76 }
77
78 void DasdInit::rawSlot(int)
79 {
80 if (ui.rawCheckBox->isChecked())
81 {
82 ui.volser->setEnabled(false);
83 ui.volser->clear();
84 }
85 else
86 {
87 ui.volser->setEnabled(!ui.rawCheckBox->isChecked());
88 }
89
90 }
91
92 void DasdInit::sizeClicked()
93 {
94 if (ui.sizeCheckBox->isChecked())
95 {
96 ui.sizeSpinBox->setEnabled(true);
97 setSizeValue();
98 }
99 else
100 {
101 ui.sizeSpinBox->setEnabled(false);
102 setSizeValue();
103 }
104 }
105
106 void DasdInit::setSizeValue()
107 {
108 int size = DasdTab::getInstance().getCkdSize(ui.deviceTypeComboBox->currentText().toStdString());
109 if (size == 0)
110 {
111 size = DasdTab::getInstance().getFbaSize(ui.deviceTypeComboBox->currentText().toStdString());
112 ui.altCheckBox->setEnabled(false);
113 ui.altCheckBox->setChecked(false);
114 }
115 else
116 {
117 if (ui.sizeCheckBox->isChecked())
118 {
119 ui.altCheckBox->setEnabled(false);
120 ui.altCheckBox->setChecked(false);
121 }
122 else
123 {
124 ui.altCheckBox->setEnabled(true);
125 }
126
127 }
128 ui.sizeSpinBox->setValue( size );
129 ui.progressBar->setMaximum(size);
130 }
131
132 void DasdInit::filenameFocus()
133 {
134 hOutDebug(2,"dasdinit focus");
135 if (ui.filename->text().length() == 0)
136 {
137 QString s = "dasd.";
138 s += ui.deviceTypeComboBox->currentText();
139 if (DasdTab::getInstance().getCkdSize(ui.deviceTypeComboBox->currentText().toStdString()) > 0)
140 s += ".ckd";
141 else
142 s += ".fba";
143 ui.filename->setText(s);
144 }
145 }
146
147 void DasdInit::exitClicked()
148 {
149 deleteLater();
150 }
151
152 void DasdInit::runClicked()
153 {
154 if (!runOrStopClicked())
155 {
156 ui.runButton->setText("Run");
157 return;
158 }
159
160 if (ui.filename->text().isEmpty() && !ui.rawCheckBox->isChecked())
161 {
162 QMessageBox::warning(this, "dasdinit",
163 "missing output file name",
164 QMessageBox::Ok,
165 QMessageBox::NoButton);
166 return;
167 }
168
169 if (ui.volser->text().isEmpty() && !ui.rawCheckBox->isChecked())
170 {
171 QMessageBox::warning(this, "dasdinit",
172 "missing volume serial number",
173 QMessageBox::Ok,
174 QMessageBox::NoButton);
175 return;
176 }
177
178 mEnded = false;
179 std::vector<std::string> parameters;
180
181 switch (ui.compressionComboBox->currentIndex())
182 {
183 case 1:
184 parameters.push_back("-z");
185 break;
186 case 2:
187 parameters.push_back("-bz2");
188 break;
189 case 3:
190 parameters.push_back("-0");
191 break;
192 default:
193 break;
194 }
195 if (ui.lfsCheckBox->isChecked())
196 parameters.push_back("-lfs");
197 if (ui.altCheckBox->isChecked())
198 parameters.push_back("-a");
199 if (ui.rawCheckBox->isChecked())
200 parameters.push_back("-r");
201 if (ui.linuxCheckBox->isChecked())
202 parameters.push_back("-linux");
203 std::string fullPath;
204 if (ui.path->text().length() > 0)
205 {
206 fullPath = ui.path->text().toStdString();
207 fullPath += "/";
208 }
209
210 fullPath += ui.filename->text().toStdString();
211 parameters.push_back(fullPath);
212 parameters.push_back(ui.deviceTypeComboBox->currentText().toStdString());
213 if (!ui.rawCheckBox->isChecked())
214 parameters.push_back(ui.volser->text().toStdString());
215 if (ui.sizeCheckBox->isChecked())
216 parameters.push_back(ui.sizeSpinBox->text().toStdString());
217 std::string command = "dasdinit";
218 std::string path = Preferences::getInstance().hercDir();
219
220 ui.progressBar->setVisible(true);
221 execute(command, path, parameters);
222 connect(mRunner, SIGNAL(valueChanged(int)), this, SLOT(runnerValueChanged(int)));
223 connect(mRunner, SIGNAL(maximumChanged(int)), this, SLOT(runnerMaximumChanged(int)));
224 connect(mErrorRunner, SIGNAL(valueChanged(int)), this, SLOT(runnerValueChanged(int)));
225 connect(mErrorRunner, SIGNAL(maximumChanged(int)), this, SLOT(runnerMaximumChanged(int)));
226 ui.runButton->setText("Stop");
227 }
228
229 void DasdInit::newDevType()
230 {
231 if (ui.deviceTypeComboBox->currentText().toStdString().compare(0,4,"3390") == 0)
232 ui.linuxCheckBox->setEnabled(true);
233 else
234 {
235 ui.linuxCheckBox->setEnabled(false);
236 ui.linuxCheckBox->setChecked(false);
237 }
238 setSizeValue();
239 }
240
241 void DasdInit::browseClicked()
242 {
243 QString s = QFileDialog::getExistingDirectory(this,"Browse for dasd path",ui.path->text());
244 ui.path->setText(s);
245 }
246
247 void DasdInit::runnerMaximumChanged(int maximum)
248 {
249 ui.progressBar->setMaximum(maximum);
250 }
251
252 void DasdInit::runnerValueChanged(int value)
253 {
254 if (value > 0)
255 ui.progressBar->setValue(value);
256 else
257 ui.progressBar->setValue(ui.progressBar->maximum());
258 }
259
260 void DasdInit::initialize()
261 {
262
263 }
264
265 DasdInit::VolserValidator::VolserValidator(QObject * parent )
266 : QValidator(parent)
267 {
268
269 }
270
271 QValidator::State DasdInit::VolserValidator::validate(QString & input, int & ) const
272 {
273 if (input.length() > 6)
274 return Invalid;
275 input = input.toUpper();
276 return Acceptable;
277 }
278
279 void DasdInit::finishedSlot()
280 {
281 if (mExecutor == NULL)
282 {
283 ui.progressBar->setValue(ui.progressBar->maximum());
284 if (mRc == 0)
285 QMessageBox::information(this, "dasdinit", "Disk creation successfully completed!",
286 QMessageBox::Ok,
287 QMessageBox::NoButton);
288 }
289 deleteLater();
290 }