| 1 | /* |
| 2 | * File: DasdIsup.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 "DasdIsup.h" |
| 26 | #include "UtilityExecutor.h" |
| 27 | #include "UtilityRunner.h" |
| 28 | #include "StringTokenizer.h" |
| 29 | #include "Preferences.h" |
| 30 | |
| 31 | #include <QFileDialog> |
| 32 | #include <QMessageBox> |
| 33 | |
| 34 | #include <csignal> |
| 35 | |
| 36 | DasdIsup::DasdIsup(QWidget *parent) |
| 37 | : GenericUtility("dasdisup",parent) |
| 38 | { |
| 39 | ui.setupUi(this); |
| 40 | ui.progressBar->setVisible(false); |
| 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(browseSfClicked())); |
| 46 | } |
| 47 | |
| 48 | DasdIsup::~DasdIsup() |
| 49 | { |
| 50 | |
| 51 | } |
| 52 | |
| 53 | void DasdIsup::exitClicked() |
| 54 | { |
| 55 | deleteLater(); |
| 56 | } |
| 57 | |
| 58 | void DasdIsup::runClicked() |
| 59 | { |
| 60 | if ((mExecutor != NULL) && (mExecutor->getQProcess()->state() == QProcess::Running)) |
| 61 | { |
| 62 | mExecutor->terminate(); |
| 63 | QMessageBox::warning(this, "dasdisup", |
| 64 | "dasdisup operation was aborted at user's request", |
| 65 | QMessageBox::Ok, |
| 66 | QMessageBox::NoButton); |
| 67 | mExecutor = NULL; |
| 68 | ui.runButton->setText("Run"); |
| 69 | return; |
| 70 | } |
| 71 | if (ui.filename->text().isEmpty()) |
| 72 | { |
| 73 | QMessageBox::warning(this, "dasdisup", "Please specify ckd file to process", |
| 74 | QMessageBox::Ok, QMessageBox::NoButton); |
| 75 | } |
| 76 | std::vector<std::string> parameters; |
| 77 | |
| 78 | parameters.push_back(ui.filename->text().toStdString()); |
| 79 | |
| 80 | if (!ui.shadowFile->text().isEmpty()) |
| 81 | { |
| 82 | parameters.push_back(ui.shadowFile->text().toStdString()); |
| 83 | } |
| 84 | parameters.push_back("EXTERNALGUI"); |
| 85 | std::string command = "dasdisup"; |
| 86 | |
| 87 | ui.progressBar->setVisible(true); |
| 88 | execute(command, Preferences::getInstance().hercDir(), parameters); |
| 89 | |
| 90 | connect(mRunner, SIGNAL(valueChanged(int)), this, SLOT(runnerValueChanged(int))); |
| 91 | connect(mRunner, SIGNAL(maximumChanged(int)), this, SLOT(runnerMaximumChanged(int))); |
| 92 | connect(mRunner, SIGNAL(error(QByteArray)), this, SLOT(runnerError(QByteArray))); |
| 93 | ui.runButton->setText("Stop"); |
| 94 | } |
| 95 | |
| 96 | void DasdIsup::browseFileClicked() |
| 97 | { |
| 98 | QString s = QFileDialog::getOpenFileName(this,"Browse for disk to update",ui.filename->text()); |
| 99 | ui.filename->setText(s); |
| 100 | } |
| 101 | |
| 102 | void DasdIsup::browseSfClicked() |
| 103 | { |
| 104 | QString s = QFileDialog::getOpenFileName(this,"Browse for shadow file",ui.shadowFile->text()); |
| 105 | ui.shadowFile->setText(s); |
| 106 | } |
| 107 | |
| 108 | void DasdIsup::runnerMaximumChanged(int maximum) |
| 109 | { |
| 110 | ui.progressBar->setMaximum(maximum); |
| 111 | hOutDebug(2,"dasdisup maximum is " << maximum); |
| 112 | } |
| 113 | |
| 114 | void DasdIsup::runnerValueChanged(int value) |
| 115 | { |
| 116 | if (value > 0) |
| 117 | ui.progressBar->setValue(value); |
| 118 | else if (value < 0) |
| 119 | { |
| 120 | ui.progressBar->setValue(ui.progressBar->maximum()); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | void DasdIsup::finishedSlot() |
| 125 | { |
| 126 | QMessageBox::information(this, "dasdisup", "Disk update successfully completed!", |
| 127 | QMessageBox::Ok, |
| 128 | QMessageBox::NoButton); |
| 129 | deleteLater(); |
| 130 | } |