Debian Codegraph @

HercUtilities/Dasdcopy.cpp

raw symbols SCIP
1 /*
2 * File: Dasdcopy.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 "Dasdcopy.h"
26 #include "HerculesStudio.h"
27 #include "UtilityExecutor.h"
28 #include "UtilityRunner.h"
29 #include "Preferences.h"
30
31
32 #include <QFileDialog>
33 #include <QMessageBox>
34
35 #include <csignal>
36
37 Dasdcopy::Dasdcopy(QWidget *parent)
38 : GenericUtility("dasdcopy",parent)
39 {
40 ui.setupUi(this);
41
42 connect(ui.runButton, SIGNAL(clicked()), this, SLOT(runClicked()));
43 connect(ui.exitButton, SIGNAL(clicked()), this, SLOT(exitClicked()));
44 connect(ui.browseFileButton, SIGNAL(clicked()), this, SLOT(browseFileClicked()));
45 connect(ui.browseSfButton, SIGNAL(clicked()), this, SLOT(browseShadowClicked()));
46 connect(ui.browseOutButton, SIGNAL(clicked()), this, SLOT(browseOutClicked()));
47 }
48
49 Dasdcopy::~Dasdcopy()
50 {
51
52 }
53
54 void Dasdcopy::runClicked()
55 {
56 if (!runOrStopClicked())
57 {
58 ui.runButton->setText("Run");
59 return;
60 }
61 if (ui.infile->text().isEmpty())
62 {
63 QMessageBox::warning(this, "dasdcopy", "Please specify input file to convert",
64 QMessageBox::Ok, QMessageBox::NoButton);
65 return;
66 }
67 if (!QFile::exists(ui.infile->text()))
68 {
69 QMessageBox::warning(this, "dasdcopy", "Input file does not exist",
70 QMessageBox::Ok, QMessageBox::NoButton);
71 return;
72
73 }
74 if (ui.filename->text().isEmpty())
75 {
76 QMessageBox::warning(this, "dasdcopy", "Please specify ckd file to create",
77 QMessageBox::Ok, QMessageBox::NoButton);
78 return;
79 }
80 if (ui.path->text().isEmpty())
81 {
82 QMessageBox::warning(this, "dasdcopy", "Please specify output directory",
83 QMessageBox::Ok, QMessageBox::NoButton);
84 return;
85 }
86 if (!QFile::exists(ui.path->text()))
87 {
88 QMessageBox::warning(this, "dasdcopy", "Output directory does not exist",
89 QMessageBox::Ok, QMessageBox::NoButton);
90 return;
91 }
92 QFileInfo dirInfo(ui.path->text());
93 if (!dirInfo.isDir())
94 {
95 QMessageBox::warning(this, "dasdcopy", "Output path is not a directory",
96 QMessageBox::Ok, QMessageBox::NoButton);
97 return;
98 }
99 std::vector<std::string> parameters;
100
101 if (ui.replaceCheckbox->isChecked())
102 parameters.push_back("-r");
103 if (ui.lfsCheckbox->isChecked())
104 parameters.push_back("-lfs");
105 switch (ui.compressionComboBox->currentIndex())
106 {
107 case 1:
108 parameters.push_back("-z");
109 break;
110 case 2:
111 parameters.push_back("-bz2");
112 break;
113 default:
114 break;
115 }
116
117
118 parameters.push_back(ui.infile->text().toStdString());
119
120 std::string fullPath;
121 if (ui.path->text().length() > 0)
122 {
123 fullPath = ui.path->text().toStdString();
124 fullPath += "/";
125 }
126 fullPath += ui.filename->text().toStdString();
127
128 parameters.push_back(fullPath);
129 std::string command = "dasdcopy";
130
131 std::string path = Preferences::getInstance().hercDir();
132 execute(command, path, parameters);
133 mFirstEndReceived = false;
134
135 connect(mRunner, SIGNAL(valueChanged(int)), this, SLOT(runnerValueChanged(int)));
136 connect(mRunner, SIGNAL(maximumChanged(int)), this, SLOT(runnerMaximumChanged(int)));
137 connect(mErrorRunner, SIGNAL(valueChanged(int)), this, SLOT(runnerValueChanged(int)));
138 connect(mErrorRunner, SIGNAL(maximumChanged(int)), this, SLOT(runnerMaximumChanged(int)));
139 ui.runButton->setText("Stop");
140 }
141
142 void Dasdcopy::exitClicked()
143 {
144 deleteLater();
145 }
146
147 void Dasdcopy::browseFileClicked()
148 {
149 QString s = QFileDialog::getOpenFileName(this,"Browse for input disk",ui.infile->text());
150 ui.infile->setText(s);
151 if (ui.path->text().isEmpty())
152 {
153 QDir d("/");
154 std::string path = d.absoluteFilePath(s).toStdString();
155 int lastSlash = s.toStdString().find_last_of('/');
156 ui.path->setText(path.substr(0,lastSlash).c_str());
157 }
158
159 }
160
161 void Dasdcopy::browseShadowClicked()
162 {
163 QString s = QFileDialog::getOpenFileName(this,"Browse for input disk",ui.shadowFile->text());
164 ui.shadowFile->setText(s);
165 }
166
167 void Dasdcopy::browseOutClicked()
168 {
169 QString s = QFileDialog::getExistingDirectory(this,"Browse for output file path",ui.path->text());
170 ui.path->setText(s);
171 }
172
173 void Dasdcopy::runnerMaximumChanged(int maximum)
174 {
175 ui.progressBar->setMaximum(maximum);
176 }
177
178 void Dasdcopy::runnerValueChanged(int value)
179 {
180 hOutDebug(3, "dasdcopy got value changed " << value);
181 if (value >= 0)
182 ui.progressBar->setValue(value);
183 else
184 {
185 if (!mFirstEndReceived)
186 {
187 mFirstEndReceived = true;
188 }
189 else if (mExecutor != NULL)
190 {
191 mExecutor = NULL;
192 QMessageBox::warning(this, "dasdcopy", "Disk copy failed",
193 QMessageBox::Ok,
194 QMessageBox::NoButton);
195 }
196 }
197 }
198
199 void Dasdcopy::finishedSlot()
200 {
201 if (mStarted && mFinished && mFinishedOK)
202 {
203 ui.progressBar->setValue(ui.progressBar->maximum());
204 QMessageBox::information(this, "dasdcopy", "Disk was successfully copied",
205 QMessageBox::Ok,
206 QMessageBox::NoButton);
207 }
208 deleteLater();
209 }