Debian Codegraph @

HercConfiguration/TapeProperties.cpp

raw symbols SCIP
1 /*
2 * File: TapeProperties.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 "HerculesStudio.h"
26 #include "TapeProperties.h"
27 #include "ConfigurationEditor.h"
28 #include "Preferences.h"
29
30 #include <QFileDialog>
31 #include <QMessageBox>
32
33 #include <sstream>
34
35 const std::string TapeProperties::types[] = {"3410", "3420", "3422", "3430", "3480", "3490", "3590", "9347", "8809", ""};
36
37 TapeProperties::TapeProperties(ConfigLine & line, QWidget *parent)
38 : GenericDeviceProperties(line, parent)
39 {
40 ui.setupUi(this);
41 //standard(true);//temp
42 initialize(line);
43
44 connect(ui.okButton, SIGNAL(clicked()), this, SLOT(ok()));
45 connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
46 connect(ui.fileButton, SIGNAL(clicked()), this, SLOT(fileBrowse()));
47 }
48
49 TapeProperties::~TapeProperties()
50 {
51
52 }
53
54 void TapeProperties::ok()
55 {
56 if (!deviceNumberValidator(ui.deviceNumber))
57 return;
58 if (ui.filename->text().isEmpty())
59 {
60 QMessageBox * p = new QMessageBox(this);
61 p->setText("Please enter file name");
62 p->exec();
63 ui.filename->setFocus();
64 return;
65 }
66
67 std::stringstream newLineBuff;
68
69 newLineBuff << ui.deviceNumber->text().toStdString()
70 << " " << ui.tapeCombo->currentText().toStdString();
71
72 newLineBuff << " " << ui.filename->text().toStdString();
73
74 if (ui.noAutomountCheckbox->isChecked())
75 newLineBuff << " noautomount";
76 if (ui.awsCheckbox->isChecked())
77 newLineBuff << " awstape";
78 if (ui.readonlycheckbox->isChecked())
79 newLineBuff << " RO";
80 if (ui.deonirqCheckbox->isChecked())
81 newLineBuff << " deonirq=1";
82 if (ui.compressionCombobox->currentIndex() > 0)
83 {
84 newLineBuff << " compress=1";
85 newLineBuff << " method=" << ui.compressionCombobox->currentText().toStdString();
86 newLineBuff << " level=" << ui.compressionLevelSlider->value();
87 }
88 if (ui.chunkSizeSpinbox->value() != 65535)
89 {
90 newLineBuff << " chunksize=" << ui.chunkSizeSpinbox->value();
91 }
92 if (ui.maxsizeNumSpinbox->value() > 0)
93 {
94 newLineBuff << " maxsize" ;
95 switch (ui.maxsizeUnitsSpinbox->currentIndex())
96 {
97 case (1):
98 newLineBuff << "k=";
99 break;
100 case (2):
101 newLineBuff << "m=";
102 break;
103 default:
104 newLineBuff << "=";
105 break;
106 }
107 newLineBuff << ui.maxsizeNumSpinbox->value();
108 }
109 if (ui.eotmarginSpinbox->value() > 0)
110 {
111 newLineBuff << " eotmargin=" << ui.eotmarginSpinbox->value();
112 }
113
114 newLineBuff << "\n";
115 mLine.replaceLine(newLineBuff.str());
116 emit updateLine(true);
117 this->deleteLater();
118 }
119
120 void TapeProperties::cancel()
121 {
122 emit updateLine(false);
123 this->deleteLater();
124 }
125
126 void TapeProperties::standard(bool set)
127 {
128 if (set)
129 {
130 scsi(false);
131 ui.tapeGroupBox->setTitle("Standard Tape");
132 }
133 //ui.filenameLabel->setVisible(set);
134 //ui.filename->setVisible(set);
135 //ui.fileButton->setVisible(set);
136 ui.awsCheckbox->setVisible(set);
137 ui.readonlycheckbox->setVisible(set);
138 ui.deonirqCheckbox->setVisible(set);
139 ui.compressionCombobox->setVisible(set);
140 ui.compressionLevelSlider->setVisible(set);
141 ui.chunkSizeSpinbox->setVisible(set);
142 ui.chunkSizeLabel->setVisible(set);
143 ui.label_slider_1->setVisible(set);
144 ui.label_slider_9->setVisible(set);
145 ui.maxsizeNumSpinbox->setVisible(set);
146 ui.maxsizeUnitsSpinbox->setVisible(set);
147 ui.maxsizeLabel->setVisible(set);
148 ui.eotmarginSpinbox->setVisible(set);
149 ui.eotmarginLabel->setVisible(set);
150 }
151
152 void TapeProperties::scsi(bool set)
153 {
154 if (set)
155 {
156 standard(false);
157 ui.tapeGroupBox->setTitle("SCSI Tape");
158 }
159 ui.noergCheckbox->setVisible(set);
160 ui.blkid32Checkbox->setVisible(set);
161 }
162
163 void TapeProperties::fileBrowse()
164 {
165 std::string s = QFileDialog::getOpenFileName(this,
166 "Browse For Tape Files",
167 Preferences::getInstance().configDir().c_str(),
168 tr("All files(*)")).toStdString();
169 ui.filename->setText(s.c_str());
170
171 }
172
173 void TapeProperties::initialize(ConfigLine & line)
174 {
175 ui.deviceNumber->setText(line.getToken(0).c_str());
176 std::string dev = line.getToken(1);
177 int type=0;
178 while(types[type].length() > 0)
179 {
180 if (dev == types[type])
181 ui.tapeCombo->setCurrentIndex(type);
182 type++;
183 }
184 standard(true);
185 ui.filename->setText(line.getToken(2).c_str());
186
187 for (int i=3; i<line.size(); i++)
188 {
189 QString token = line.getToken(i).c_str();
190 hOutDebug(3,"token=" << token.toStdString());
191 if (token.toLower() == "--no-erg")
192 {
193 ui.noergCheckbox->setChecked(true);
194 }
195 else if (token.toLower() == "--blkid-32")
196 {
197 ui.blkid32Checkbox->setChecked(true);
198 }
199 else if (token.toLower() == "awstape")
200 {
201 ui.awsCheckbox->setChecked(true);
202 }
203 if ( (token.toLower() == "compress=1") ||
204 (token.toLower() == "idrc=1") )
205 {
206 if (ui.compressionCombobox->currentIndex() == 0)
207 ui.compressionCombobox->setCurrentIndex(1);
208 }
209 if (token.toLower().toStdString().substr(0,7) == "method=")
210 {
211 if (token.toLower().toStdString().substr(7,1) == "z")
212 ui.compressionCombobox->setCurrentIndex(1);
213 else
214 ui.compressionCombobox->setCurrentIndex(2);
215 }
216 if (token.toLower().toStdString().substr(0,6) == "level=")
217 {
218 int level = ConfigurationEditor::parseNum(token.toStdString().substr(6,1).c_str());
219 if (level >= 1 && level <=9)
220 ui.compressionLevelSlider->setValue(level);
221 }
222 if (token.toLower().toStdString().substr(0,10) == "chunksize=")
223 {
224 int chunksize = ConfigurationEditor::parseNum(token.toStdString().substr(10).c_str());
225 if (chunksize >= 4096 && chunksize <=65535)
226 ui.chunkSizeSpinbox->setValue(chunksize);
227
228 }
229 if (token.toLower().toStdString().substr(0,8) == "maxsize=")
230 {
231 int maxsize = ConfigurationEditor::parseNum(token.toStdString().substr(8).c_str());
232 ui.maxsizeUnitsSpinbox->setCurrentIndex(0);
233 ui.maxsizeNumSpinbox->setValue(maxsize);
234 }
235 if (token.toLower().toStdString().substr(0,9) == "maxsizek=")
236 {
237 int maxsize = ConfigurationEditor::parseNum(token.toStdString().substr(9).c_str());
238 ui.maxsizeUnitsSpinbox->setCurrentIndex(1);
239 ui.maxsizeNumSpinbox->setValue(maxsize);
240 }
241 if (token.toLower().toStdString().substr(0,9) == "maxsizem=")
242 {
243 int maxsize = ConfigurationEditor::parseNum(token.toStdString().substr(9).c_str());
244 ui.maxsizeUnitsSpinbox->setCurrentIndex(2);
245 ui.maxsizeNumSpinbox->setValue(maxsize);
246 }
247 if (token.toLower().toStdString().substr(0,10) == "eotmargin=")
248 {
249 int eotmargin = ConfigurationEditor::parseNum(token.toStdString().substr(10).c_str());
250 ui.eotmarginSpinbox->setValue(eotmargin);
251 }
252 if ( (token.toLower() == "readonly=1") ||
253 (token.toLower() == "ro") ||
254 (token.toLower() == "noring") )
255 {
256 ui.readonlycheckbox->setChecked(true);
257 }
258 if (token.toLower() == "deonirq=1")
259 {
260 ui.deonirqCheckbox->setChecked(true);
261 }
262 if (token.toLower() == "noautomount")
263 {
264 ui.noAutomountCheckbox->setChecked(true);
265 }
266 }
267 }