| 1 | /* |
| 2 | * File: HetGet.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 "HetGet.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 | HetGet::HetGet(QWidget *parent) |
| 37 | : GenericUtility("hetget",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.browseInFile, SIGNAL(clicked()), this, SLOT(browseInFileClicked())); |
| 44 | connect(ui.browseOutDir, SIGNAL(clicked()), this, SLOT(browseOutDirClicked())); |
| 45 | connect(ui.browseOutFile, SIGNAL(clicked()), this, SLOT(browseOutFileClicked())); |
| 46 | connect(ui.asciiCheckBox, SIGNAL(stateChanged(int)), this, SLOT(asciiChanged())); |
| 47 | connect(ui.stripCheckBox, SIGNAL(stateChanged(int)), this, SLOT(stripChanged())); |
| 48 | connect(ui.unblockCheckBox, SIGNAL(stateChanged(int)), this, SLOT(unblockChanged())); |
| 49 | |
| 50 | ui.outdir->setText(Preferences::getInstance().logsDir().c_str()); |
| 51 | ui.outdir->setBackgroundRole(QPalette::Window); |
| 52 | ui.outdir->setToolTip("Use the button on the right to select directory"); |
| 53 | } |
| 54 | |
| 55 | HetGet::~HetGet() |
| 56 | { |
| 57 | |
| 58 | } |
| 59 | |
| 60 | void HetGet::runClicked() |
| 61 | { |
| 62 | if (!runOrStopClicked()) |
| 63 | { |
| 64 | ui.runButton->setText("Run"); |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | if (ui.infile->text().isEmpty()) |
| 69 | { |
| 70 | QMessageBox::warning(this, "hetget", "Please specify input tape file to process", |
| 71 | QMessageBox::Ok, QMessageBox::NoButton); |
| 72 | return; |
| 73 | } |
| 74 | else |
| 75 | { |
| 76 | if (!QFile::exists(ui.infile->text())) |
| 77 | { |
| 78 | QMessageBox::warning(this, "hetget", "Input tape file does not exist", |
| 79 | QMessageBox::Ok, QMessageBox::NoButton); |
| 80 | ui.infile->setFocus(Qt::OtherFocusReason); |
| 81 | return; |
| 82 | |
| 83 | } |
| 84 | } |
| 85 | if (ui.outfile->text().isEmpty()) |
| 86 | { |
| 87 | QMessageBox::warning(this, "hetget", "Please specify output tape file", |
| 88 | QMessageBox::Ok, QMessageBox::NoButton); |
| 89 | return; |
| 90 | } |
| 91 | std::vector<std::string> parameters; |
| 92 | if (ui.nlCheckBox->isChecked()) parameters.push_back("-n"); |
| 93 | if (ui.asciiCheckBox->isChecked()) parameters.push_back("-a"); |
| 94 | if (ui.unblockCheckBox->isChecked()) parameters.push_back("-u"); |
| 95 | if (ui.stripCheckBox->isChecked()) parameters.push_back("-s"); |
| 96 | parameters.push_back(ui.infile->text().toStdString()); |
| 97 | QString outfile = ui.outdir->text(); |
| 98 | if (outfile.size() > 0) |
| 99 | outfile += "/"; |
| 100 | outfile += ui.outfile->text(); |
| 101 | parameters.push_back(outfile.toStdString()); |
| 102 | parameters.push_back(QString::number(ui.inputBlocksSpinBox->value()).toStdString()); |
| 103 | |
| 104 | std::string command = "hetget"; |
| 105 | |
| 106 | execute(command, Preferences::getInstance().hercDir(), parameters); |
| 107 | ui.runButton->setText("Stop"); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | void HetGet::exitClicked() |
| 112 | { |
| 113 | deleteLater(); |
| 114 | } |
| 115 | |
| 116 | void HetGet::browseInFileClicked() |
| 117 | { |
| 118 | QString s = QFileDialog::getOpenFileName(this,"Browse for tape to process",ui.infile->text()); |
| 119 | if (s.size() > 0) |
| 120 | { |
| 121 | ui.infile->setText(s); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | void HetGet::browseOutDirClicked() |
| 126 | { |
| 127 | QString s = QFileDialog::getExistingDirectory(this,"Browse for target output directory",ui.outdir->text()); |
| 128 | if (s.size() > 0) ui.outdir->setText(s); |
| 129 | } |
| 130 | |
| 131 | void HetGet::browseOutFileClicked() |
| 132 | { |
| 133 | QString s = QFileDialog::getOpenFileName(this,"Browse for target output file",ui.outdir->text()); |
| 134 | if (s.size() > 0) |
| 135 | { |
| 136 | QFileInfo fi(s); |
| 137 | ui.outdir->setText(fi.absolutePath()); |
| 138 | ui.outfile->setText(fi.fileName()); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | void HetGet::asciiChanged() |
| 143 | { |
| 144 | if (ui.asciiCheckBox->isChecked()) |
| 145 | ui.unblockCheckBox->setChecked(true); |
| 146 | } |
| 147 | |
| 148 | void HetGet::stripChanged() |
| 149 | { |
| 150 | if (ui.stripCheckBox->isChecked()) |
| 151 | ui.asciiCheckBox->setChecked(true); |
| 152 | } |
| 153 | |
| 154 | void HetGet::unblockChanged() |
| 155 | { |
| 156 | if (!ui.unblockCheckBox->isChecked()) |
| 157 | ui.asciiCheckBox->setChecked(false); |
| 158 | } |
| 159 | |
| 160 | void HetGet::finishedSlot() |
| 161 | { |
| 162 | deleteLater(); |
| 163 | } |
| 164 |