Debian Codegraph @

HercUtilities/HetInit.cpp

raw symbols SCIP
1 /*
2 * File: HetInit.cpp
3 *
4 * Author: Jacob Dekel
5 * Created on: Sep 3, 2010
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 "HetInit.h"
26 #include "HerculesStudio.h"
27 #include "UtilityRunner.h"
28 #include "Preferences.h"
29
30 #include <QFileDialog>
31 #include <QMessageBox>
32
33 #include <csignal>
34
35
36 HetInit::HetInit(QWidget *parent)
37 : GenericUtility("hetinit",parent)
38 {
39 ui.setupUi(this);
40
41 connect(ui.runButton, SIGNAL(clicked()), this, SLOT(runClicked()));
42 connect(ui.exitButton, SIGNAL(clicked()), this, SLOT(exitClicked()));
43 connect(ui.browseFileButton, SIGNAL(clicked()), this, SLOT(browseFileClicked()));
44 connect(ui.browseDirButton, SIGNAL(clicked()), this, SLOT(browseDirClicked()));
45
46 mVolser = new VolserSpinBox(ui.groupBox);
47 mVolser->setObjectName(QString::fromUtf8("spinBox"));
48 mVolser->setGeometry(QRect(20, 40, 91, 22));
49
50 ui.directory->setText(Preferences::getInstance().logsDir().c_str());
51 ui.directory->setBackgroundRole(QPalette::Window);
52 ui.directory->setToolTip("Use the button on the right to select directory");
53 }
54
55 HetInit::~HetInit()
56 {
57
58 }
59
60 void HetInit::runClicked()
61 {
62 if (!runOrStopClicked())
63 {
64 ui.runButton->setText("Run");
65 return;
66 }
67
68 if (ui.filename->text().isEmpty())
69 {
70 QMessageBox::warning(this, "hetinit", "Please specify tape file to create",
71 QMessageBox::Ok, QMessageBox::NoButton);
72 return;
73 }
74 std::vector<std::string> parameters;
75
76 if (ui.compressionCheckbox->isChecked())
77 parameters.push_back("-d");
78 if (ui.nlCheckbox->isChecked())
79 parameters.push_back("-n");
80 else
81 {
82 parameters.push_back("-i");
83 if (!ui.owner->text().isEmpty()) parameters.push_back(ui.owner->text().toStdString());
84 }
85
86 std::string filename = ui.directory->text().toStdString();
87 if (filename.size() > 0)
88 filename += "/";
89 filename += ui.filename->text().toStdString();
90 parameters.push_back(filename);
91 parameters.push_back(mVolser->text().toStdString());
92
93 std::string command = "hetinit";
94
95 execute(command, Preferences::getInstance().hercDir(), parameters);
96 ui.runButton->setText("Stop");
97 }
98
99
100 void HetInit::exitClicked()
101 {
102 deleteLater();
103 }
104
105 void HetInit::browseFileClicked()
106 {
107 QString s = QFileDialog::getOpenFileName(this,"Browse for disk to update",ui.filename->text());
108 if (s.size() > 0)
109 {
110 QFileInfo fi(s);
111 ui.directory->setText(fi.absolutePath());
112 ui.filename->setText(fi.fileName());
113 }
114 }
115
116 void HetInit::browseDirClicked()
117 {
118 QString s = QFileDialog::getExistingDirectory(this,"Browse for disk to update",ui.directory->text());
119 if (s.size() > 0) ui.directory->setText(s);
120 }
121
122 void HetInit::finishedSlot()
123 {
124 deleteLater();
125 }
126
127 //////////////// VolserSpinBox //////////////////////////////
128
129 VolserSpinBox::VolserSpinBox(QWidget * parent) : QAbstractSpinBox(parent)
130 {
131 connect(this, SIGNAL(editingFinished()), this, SLOT(verify()));
132 setText("000000");
133 verify();
134 }
135
136 VolserSpinBox::~VolserSpinBox()
137 {
138
139 }
140
141 QFlags<QAbstractSpinBox::StepEnabledFlag> VolserSpinBox::stepEnabled () const
142 {
143 return mStepFlag ;
144 }
145
146 QString VolserSpinBox::text() const
147 {
148 return lineEdit()->text();
149 }
150
151 void VolserSpinBox::setText(QString text)
152 {
153 lineEdit()->setText(text);
154 }
155
156 void VolserSpinBox::stepBy ( int steps )
157 {
158 if (verify()) // standard numbering
159 {
160 int value = text().toUInt() + steps;
161 if (value > 999999) return;
162 if (value < 0) return;
163 QString result = QString::number(value);
164 if (result.size() < 6)
165 result = QString("000000").left(6-result.size()) + result;
166 setText(result);
167 verify();
168 }
169 }
170
171 bool VolserSpinBox::verify()
172 {
173 bool verified = true;
174 QString str = text();
175 if (str.size() == 6)
176 {
177 char num[6];
178 strncpy(num,text().toUtf8().data(),6);
179 for (int i=0; i<6; i++)
180 {
181 if (!isdigit(num[i]))
182 {
183 verified = false;
184 }
185 }
186 }
187 else
188 {
189 verified = false;
190 }
191
192 if (verified)
193 {
194 mStepFlag = QAbstractSpinBox::StepUpEnabled | QAbstractSpinBox::StepDownEnabled;
195 if (str == "000000") mStepFlag &= ~QAbstractSpinBox::StepDownEnabled;
196 if (str == "999999") mStepFlag &= ~QAbstractSpinBox::StepUpEnabled;
197 }
198 else
199 {
200 mStepFlag = QAbstractSpinBox::StepNone;
201 }
202 return verified;
203 }