| 1 | /* |
| 2 | * File: DasdLoad.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 "DasdLoad.h" |
| 26 | #include "HerculesStudio.h" |
| 27 | #include "UtilityRunner.h" |
| 28 | #include "Preferences.h" |
| 29 | #include "StringTokenizer.h" |
| 30 | |
| 31 | |
| 32 | #include <QMessageBox> |
| 33 | #include <QFileDialog> |
| 34 | #include <QFileInfo> |
| 35 | |
| 36 | #include <csignal> |
| 37 | |
| 38 | DasdLoad::DasdLoad(QWidget *parent) |
| 39 | : GenericUtility("dasdload", parent) |
| 40 | { |
| 41 | ui.setupUi(this); |
| 42 | |
| 43 | connect(ui.runButton, SIGNAL(clicked()), this, SLOT(runClicked())); |
| 44 | connect(ui.exitButton, SIGNAL(clicked()), this, SLOT(exitClicked())); |
| 45 | connect(ui.browseCtlButton, SIGNAL(clicked()), this, SLOT(browseCtlClicked())); |
| 46 | connect(ui.browseOutButton, SIGNAL(clicked()), this, SLOT(browseOutClicked())); |
| 47 | } |
| 48 | |
| 49 | DasdLoad::~DasdLoad() |
| 50 | { |
| 51 | |
| 52 | } |
| 53 | |
| 54 | void DasdLoad::exitClicked() |
| 55 | { |
| 56 | deleteLater(); |
| 57 | } |
| 58 | |
| 59 | void DasdLoad::runClicked() |
| 60 | { |
| 61 | if (!runOrStopClicked()) |
| 62 | { |
| 63 | ui.runButton->setText("Run"); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | std::vector<std::string> parameters; |
| 68 | |
| 69 | if (ui.filename->text().isEmpty()) |
| 70 | { |
| 71 | QMessageBox::warning(this, "dasdload", "Please specify dasd file to create", |
| 72 | QMessageBox::Ok, QMessageBox::NoButton); |
| 73 | return; |
| 74 | } |
| 75 | if (ui.path->text().isEmpty()) |
| 76 | { |
| 77 | QMessageBox::warning(this, "dasdload", "Please specify path for dasd file to create", |
| 78 | QMessageBox::Ok, QMessageBox::NoButton); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | switch (ui.compressionComboBox->currentIndex()) |
| 83 | { |
| 84 | case 1: |
| 85 | parameters.push_back("-z"); |
| 86 | break; |
| 87 | case 2: |
| 88 | parameters.push_back("-bz2"); |
| 89 | break; |
| 90 | case 3: |
| 91 | parameters.push_back("-0"); |
| 92 | break; |
| 93 | default: |
| 94 | break; |
| 95 | } |
| 96 | if (ui.lfsCheckBox->isChecked()) |
| 97 | parameters.push_back("-lfs"); |
| 98 | if (ui.altCheckBox->isChecked()) |
| 99 | parameters.push_back("-a"); |
| 100 | parameters.push_back(ui.control->text().toStdString()); |
| 101 | std::string fullPath; |
| 102 | if (ui.path->text().length() > 0) |
| 103 | { |
| 104 | fullPath = ui.path->text().toStdString(); |
| 105 | fullPath += "/"; |
| 106 | } |
| 107 | fullPath += ui.filename->text().toStdString(); |
| 108 | parameters.push_back(fullPath); |
| 109 | std::string command = "dasdload"; |
| 110 | std::string path = ""; |
| 111 | QFileInfo fi(ui.control->text()); |
| 112 | hOutDebug(2, "dir: " << fi.absolutePath().toStdString()); |
| 113 | |
| 114 | execute(command, Preferences::getInstance().hercDir(), parameters, fi.absolutePath()); |
| 115 | |
| 116 | ui.progressBar->setVisible(true); |
| 117 | connect(mErrorRunner, SIGNAL(valueChanged(int)), this, SLOT(runnerValueChanged(int))); |
| 118 | connect(mErrorRunner, SIGNAL(maximumChanged(int)), this, SLOT(runnerMaximumChanged(int))); |
| 119 | ui.runButton->setText("Stop"); |
| 120 | } |
| 121 | |
| 122 | void DasdLoad::browseCtlClicked() |
| 123 | { |
| 124 | QString s = QFileDialog::getOpenFileName(this,"Browse for input file path",ui.path->text()); |
| 125 | ui.control->setText(s); |
| 126 | } |
| 127 | |
| 128 | void DasdLoad::browseOutClicked() |
| 129 | { |
| 130 | QString s = QFileDialog::getExistingDirectory(this,"Browse for output file path",ui.path->text()); |
| 131 | ui.path->setText(s); |
| 132 | } |
| 133 | |
| 134 | void DasdLoad::runnerMaximumChanged(int maximum) |
| 135 | { |
| 136 | ui.progressBar->setMaximum(maximum); |
| 137 | } |
| 138 | |
| 139 | void DasdLoad::runnerValueChanged(int value) |
| 140 | { |
| 141 | if (value > 0) |
| 142 | ui.progressBar->setValue(value); |
| 143 | else |
| 144 | ui.progressBar->setValue(ui.progressBar->maximum()); |
| 145 | } |
| 146 | |
| 147 | void DasdLoad::finishedSlot() |
| 148 | { |
| 149 | if (mStarted && mFinished && mFinishedOK) |
| 150 | { |
| 151 | QMessageBox::information(this, "dasdload", "Dasdload operation successfully completed!", |
| 152 | QMessageBox::Ok, |
| 153 | QMessageBox::NoButton); |
| 154 | deleteLater(); |
| 155 | } |
| 156 | else emit error(); |
| 157 | } |
| 158 | |
| 159 |