| 1 | /* |
| 2 | * File: Dasdconv.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 "Dasdconv.h" |
| 26 | #include "HerculesStudio.h" |
| 27 | #include "UtilityExecutor.h" |
| 28 | #include "UtilityRunner.h" |
| 29 | #include "Preferences.h" |
| 30 | |
| 31 | #include <QFileDialog> |
| 32 | #include <QMessageBox> |
| 33 | |
| 34 | #include <csignal> |
| 35 | |
| 36 | |
| 37 | Dasdconv::Dasdconv(QWidget *parent) |
| 38 | : GenericUtility("dasdconv",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.browseOutButton, SIGNAL(clicked()), this, SLOT(browseOutClicked())); |
| 46 | |
| 47 | } |
| 48 | |
| 49 | Dasdconv::~Dasdconv() |
| 50 | { |
| 51 | |
| 52 | } |
| 53 | |
| 54 | void Dasdconv::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, "dasdconv", "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, "dasdconv", "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, "dasdconv", "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, "dasdconv", "Please specify output directory", |
| 83 | QMessageBox::Ok, QMessageBox::NoButton); |
| 84 | return; |
| 85 | } |
| 86 | if (!QFile::exists(ui.path->text())) |
| 87 | { |
| 88 | QMessageBox::warning(this, "dasdconv", "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, "dasdconv", "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 | |
| 106 | parameters.push_back(ui.infile->text().toStdString()); |
| 107 | |
| 108 | std::string fullPath; |
| 109 | if (ui.path->text().length() > 0) |
| 110 | { |
| 111 | fullPath = ui.path->text().toStdString(); |
| 112 | fullPath += "/"; |
| 113 | } |
| 114 | fullPath += ui.filename->text().toStdString(); |
| 115 | |
| 116 | parameters.push_back(fullPath); |
| 117 | std::string command = "dasdconv"; |
| 118 | |
| 119 | execute(command, Preferences::getInstance().hercDir(), parameters); |
| 120 | |
| 121 | connect(mRunner, SIGNAL(valueChanged(int)), this, SLOT(runnerValueChanged(int))); |
| 122 | connect(mRunner, SIGNAL(maximumChanged(int)), this, SLOT(runnerMaximumChanged(int))); |
| 123 | connect(mRunner, SIGNAL(error(QByteArray)), this, SLOT(runnerError(QByteArray))); |
| 124 | connect(mErrorRunner, SIGNAL(valueChanged(int)), this, SLOT(runnerValueChanged(int))); |
| 125 | connect(mErrorRunner, SIGNAL(maximumChanged(int)), this, SLOT(runnerMaximumChanged(int))); |
| 126 | ui.runButton->setText("Stop"); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | void Dasdconv::exitClicked() |
| 131 | { |
| 132 | deleteLater(); |
| 133 | } |
| 134 | |
| 135 | void Dasdconv::browseFileClicked() |
| 136 | { |
| 137 | QString s = QFileDialog::getOpenFileName(this,"Browse for input disk",ui.filename->text()); |
| 138 | ui.infile->setText(s); |
| 139 | if (ui.path->text().isEmpty()) |
| 140 | { |
| 141 | QDir d("/"); |
| 142 | std::string path = d.absoluteFilePath(s).toStdString(); |
| 143 | int lastSlash = s.toStdString().find_last_of('/'); |
| 144 | ui.path->setText(path.substr(0,lastSlash).c_str()); |
| 145 | } |
| 146 | |
| 147 | } |
| 148 | void Dasdconv::browseOutClicked() |
| 149 | { |
| 150 | QString s = QFileDialog::getExistingDirectory(this,"Browse for output file path",ui.path->text()); |
| 151 | ui.path->setText(s); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | void Dasdconv::runnerMaximumChanged(int maximum) |
| 156 | { |
| 157 | ui.progressBar->setMaximum(maximum); |
| 158 | } |
| 159 | |
| 160 | void Dasdconv::runnerValueChanged(int value) |
| 161 | { |
| 162 | hOutDebug(5, "dasdconv got value changed " << value); |
| 163 | if (value > 0) |
| 164 | ui.progressBar->setValue(value); |
| 165 | else |
| 166 | { |
| 167 | ui.progressBar->setValue(ui.progressBar->maximum()); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void Dasdconv::finishedSlot() |
| 172 | { |
| 173 | deleteLater(); |
| 174 | } |