// dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
#include <QDebug>
#include <QString>
#include <QProcess>
#include <QScrollBar>
#include <QMessageBox>
#include <QFileInfo>
#include <QFileDialog>
#include <QTextStream>
#include <QFile>
#include <QDesktopServices>
#include <QUrl>
Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)
{
ui->setupUi(this);
// Play button for output - initially disabled
//ui->playOutputButton->setEnabled(false);
ui->openGnuplotButton->setEnabled(false);
// Create three processes
// 1.imachexec, 2.input play 3.output play
mImachexecProcess = new QProcess(this);
mGnuplotProcess = new QProcess(this);
//mOutputPlayProcess = new QProcess(this);
connect(mImachexecProcess, SIGNAL(started()), this, SLOT(processStarted()));
connect(mImachexecProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
connect(mImachexecProcess, SIGNAL(finished(int)), this, SLOT(imachexecFinished()));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::processStarted()
{
qDebug() << "processStarted()";
}
// imach start
void Dialog::on_startButton_clicked()
{
QString program = "imach";
QStringList arguments;
QString input = ui->fromLineEdit->text();
if(input.isEmpty()) {
qDebug() << "No input";
QMessageBox::information(this,
tr("imach"),tr("Input file not specified"));
return;
}
QString output = input;
// QString output = ui->toLineEdit->text();
// if(output.isEmpty()) {
// qDebug() << "No output";
// QMessageBox::information(this,
// tr("imach"),tr("Output file not specified"));
// return;
// }
// QString fileName = ui->toLineEdit->text();
// qDebug() << "output file check " << fileName;
// qDebug() << "QFile::exists(fileName) = " << QFile::exists(fileName);
// if (QFile::exists(fileName)) {
// if (QMessageBox::question(this, tr("imach"),
// tr("There already exists a file called %1 in "
// "the current directory. Overwrite?").arg(fileName),
// QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
// == QMessageBox::No)
// return;
// QFile::remove(fileName);
// while(QFile::exists(fileName)) {
// qDebug() << "output file still there";
// }
// }
// arguments << input << output;
arguments << input << " q";
qDebug() << arguments;
mImachexecProcess->setProcessChannelMode(QProcess::MergedChannels);
mImachexecProcess->start(program, arguments);
}
void Dialog::readyReadStandardOutput()
{
mOutputString.append(mImachexecProcess->readAllStandardOutput());
ui->textEdit->setText(mOutputString);
// put the slider at the bottom
ui->textEdit->verticalScrollBar()
->setSliderPosition(
ui->textEdit->verticalScrollBar()->maximum());
}
void Dialog::imachexecFinished()
{
// Set the imachexec status by checking output gnuplot file's existence
//QString fileName = ui->toLineEdit->text();
QString fichnom = ui->fromLineEdit->text();
QFileInfo fileInfor(fichnom);
QString NomComplet = fileInfor.completeBaseName();
//QString NomSuffix = fileInfor.suffix();
//QString NomCheminsansEx = fileInfor.canonicalPath()+NomComplet;
QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp";
//QFileInfo fileInfoGp(NomCompGp);
//if (QFile::exists(fileName)) {
if (QFile::exists(NomCompGp)) {
ui->imachStatusLabel
->setText("IMaCh Status: Successful!");
//ui->playOutputButton->setEnabled(true);
ui->openGnuplotButton->setEnabled(true);
}
else {
ui->imachStatusLabel
->setText("IMaCh Status: Failed!");
}
}
// Browse... button clicked - this is for input file
void Dialog::on_fileOpenButton_clicked()
{
QString fileName =
QFileDialog::getOpenFileName(
this,
tr("Open File"),
"/tmp/test",
tr("imach parameter files (*.imach *.txt *.log *.gp)"));
QFileInfo fileInfor(fileName);
if (!fileName.isEmpty()) {
ui->fromLineEdit->setText(fileName);
}
}
void Dialog::on_openLogButton_clicked()
{
QString fichnom = ui->fromLineEdit->text();
QFileInfo fileInfor(fichnom);
QString NomComplet = fileInfor.completeBaseName();
QString NomCompLog = fileInfor.canonicalPath()+"/"+NomComplet+".log";
//QFileInfo fileInfolog(NomCompLog);
QDesktopServices::openUrl(QUrl("file://"+NomCompLog,QUrl::TolerantMode));
}
void Dialog::on_launchbrowButton_clicked()
{
QString fichnom = ui->fromLineEdit->text();
QFileInfo fileInfor(fichnom);
QString NomComplet = fileInfor.completeBaseName();
QString NomCompLaunch = fileInfor.canonicalPath()+"/"+NomComplet+".htm";
//QFileInfo fileInfolog(NomCompLaunch;
QDesktopServices::openUrl(QUrl("file://"+NomCompLaunch,QUrl::TolerantMode));
}
void Dialog::on_openGnuplotButton_clicked()
{
// QString program = "ffplay";
// QStringList arguments;
QString fichnom = ui->fromLineEdit->text();
QFileInfo fileInfor(fichnom);
QString NomComplet = fileInfor.completeBaseName();
//QString NomSuffix = fileInfor.suffix();
//QString NomCheminsansEx = fileInfor.canonicalPath()+NomComplet;
QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp";
QFileInfo fileInfoGp(NomCompGp);
//QString input = NomCheminsansEx;
// arguments << input;
// mInputPlayProcess->start(program, arguments);
// QFile file(NomCompLog);
// if(!file.open(QIODevice::ReadOnly))
// QMessageBox::information(0,"info",file.errorString());
QDesktopServices::openUrl(QUrl("file://"+NomCompGp,QUrl::TolerantMode));
//o QTextStream in(&file);
//o ui->playInputButton->setText(in.readAll());
}
void Dialog::on_runGnuplotButton_clicked()
{
QString program = "gnuplot";
QStringList arguments;
QString fichnom = ui->fromLineEdit->text();
QFileInfo fileInfor(fichnom);
QString NomComplet = fileInfor.completeBaseName();
QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp";
//QFileInfo fileInfoGp(NomCompGp);
//QString input = NomCheminsansEx;
arguments << NomCompGp;
mGnuplotProcess->start(program, arguments);
// QFile file(NomCompLog);
// if(!file.open(QIODevice::ReadOnly))
// QMessageBox::information(0,"info",file.errorString());
//QDesktopServices::openUrl(QUrl("file://"+NomCompGp,QUrl::TolerantMode));
//o QTextStream in(&file);
//o ui->playInputButton->setText(in.readAll());
}
//void Dialog::on_playOutputButton_clicked()
//{
// QString program = "ffplay";
// QStringList arguments;
// QString output = ui->toLineEdit->text();
// arguments << output;
// mInputPlayProcess->start(program, arguments);
//}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>