File:  [Local Repository] / imach / imach-gui / dialog.cpp
Revision 1.1: download - view: text, annotated - select for diffs
Tue Feb 27 23:00:08 2018 UTC (6 years, 4 months ago) by brouard
Branches: MAIN
CVS tags: HEAD
Summary: imach gui

    1: // dialog.cpp
    2: 
    3: #include "dialog.h"
    4: #include "ui_dialog.h"
    5: #include <QDebug>
    6: #include <QString>
    7: #include <QProcess>
    8: #include <QScrollBar>
    9: #include <QMessageBox>
   10: #include <QFileInfo>
   11: #include <QFileDialog>
   12: 
   13: #include <QTextStream>
   14: #include <QFile>
   15: #include <QDesktopServices>
   16: #include <QUrl>
   17: 
   18: Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)
   19: {
   20:     ui->setupUi(this);
   21: 
   22:     // Play button for output - initially disabled
   23:     //ui->playOutputButton->setEnabled(false);
   24:     ui->openGnuplotButton->setEnabled(false);
   25: 
   26:     // Create three processes
   27:     // 1.imachexec, 2.input play 3.output play
   28:     mImachexecProcess = new QProcess(this);
   29:     mGnuplotProcess = new QProcess(this);
   30:     //mOutputPlayProcess = new QProcess(this);
   31: 
   32:     connect(mImachexecProcess, SIGNAL(started()), this, SLOT(processStarted()));
   33: 
   34:     connect(mImachexecProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
   35:     connect(mImachexecProcess, SIGNAL(finished(int)), this, SLOT(imachexecFinished()));
   36: }
   37: 
   38: Dialog::~Dialog()
   39: {
   40:     delete ui;
   41: }
   42: 
   43: void Dialog::processStarted()
   44: {
   45:     qDebug() << "processStarted()";
   46: }
   47: 
   48: // imach start
   49: void Dialog::on_startButton_clicked()
   50: {
   51:     QString program = "imach";
   52: 
   53:     QStringList arguments;
   54: 
   55:     QString input = ui->fromLineEdit->text();
   56:     if(input.isEmpty()) {
   57:         qDebug() << "No input";
   58:         QMessageBox::information(this,
   59:                      tr("imach"),tr("Input file not specified"));
   60:         return;
   61:     }
   62:     QString output = input;
   63: //    QString output = ui->toLineEdit->text();
   64: //    if(output.isEmpty()) {
   65: //        qDebug() << "No output";
   66: //        QMessageBox::information(this,
   67: //                     tr("imach"),tr("Output file not specified"));
   68: //        return;
   69: //    }
   70: 
   71: //    QString fileName = ui->toLineEdit->text();
   72: //    qDebug() << "output file check " << fileName;
   73: //    qDebug() << "QFile::exists(fileName) = " << QFile::exists(fileName);
   74: //    if (QFile::exists(fileName)) {
   75: //         if (QMessageBox::question(this, tr("imach"),
   76: //                    tr("There already exists a file called %1 in "
   77: //                    "the current directory. Overwrite?").arg(fileName),
   78: //                    QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
   79: //             == QMessageBox::No)
   80: //             return;
   81: //         QFile::remove(fileName);
   82: //         while(QFile::exists(fileName)) {
   83: //             qDebug() << "output file still there";
   84: //         }
   85: //     }
   86: 
   87: //    arguments << input << output;
   88:       arguments << input << " q";
   89: 
   90:     qDebug() << arguments;
   91: 
   92:     mImachexecProcess->setProcessChannelMode(QProcess::MergedChannels);
   93:     mImachexecProcess->start(program, arguments);
   94: }
   95: 
   96: void Dialog::readyReadStandardOutput()
   97: {
   98:     mOutputString.append(mImachexecProcess->readAllStandardOutput());
   99:     ui->textEdit->setText(mOutputString);
  100: 
  101:     // put the slider at the bottom
  102:     ui->textEdit->verticalScrollBar()
  103:             ->setSliderPosition(
  104:                 ui->textEdit->verticalScrollBar()->maximum());
  105: }
  106: 
  107: void Dialog::imachexecFinished()
  108: {
  109:     // Set the imachexec status by checking output gnuplot file's existence
  110:     //QString fileName = ui->toLineEdit->text();
  111:     QString fichnom = ui->fromLineEdit->text();
  112:     QFileInfo fileInfor(fichnom);
  113:     QString NomComplet = fileInfor.completeBaseName();
  114:     //QString NomSuffix = fileInfor.suffix();
  115:     //QString NomCheminsansEx = fileInfor.canonicalPath()+NomComplet;
  116:     QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp";
  117:     //QFileInfo fileInfoGp(NomCompGp);
  118: 
  119:     //if (QFile::exists(fileName)) {
  120:     if (QFile::exists(NomCompGp)) {
  121:         ui->imachStatusLabel
  122:                 ->setText("IMaCh Status: Successful!");
  123:         //ui->playOutputButton->setEnabled(true);
  124:         ui->openGnuplotButton->setEnabled(true);
  125:     }
  126:     else {
  127:         ui->imachStatusLabel
  128:                 ->setText("IMaCh Status: Failed!");
  129:     }
  130: }
  131: 
  132: // Browse... button clicked - this is for input file
  133: void Dialog::on_fileOpenButton_clicked()
  134: {
  135:     QString fileName =
  136:         QFileDialog::getOpenFileName(
  137:                 this,
  138:                 tr("Open File"),
  139:                 "/tmp/test",
  140:                 tr("imach parameter files (*.imach *.txt *.log *.gp)"));
  141:     QFileInfo fileInfor(fileName);
  142:     if (!fileName.isEmpty()) {
  143:         ui->fromLineEdit->setText(fileName);
  144:     }
  145: 
  146: }
  147: 
  148: void Dialog::on_openLogButton_clicked()
  149: {
  150:     QString fichnom = ui->fromLineEdit->text();
  151:     QFileInfo fileInfor(fichnom);
  152:     QString NomComplet = fileInfor.completeBaseName();
  153:     QString NomCompLog = fileInfor.canonicalPath()+"/"+NomComplet+".log";
  154:     //QFileInfo fileInfolog(NomCompLog);
  155:     QDesktopServices::openUrl(QUrl("file://"+NomCompLog,QUrl::TolerantMode));
  156: }
  157: 
  158: void Dialog::on_launchbrowButton_clicked()
  159: {
  160:     QString fichnom = ui->fromLineEdit->text();
  161:     QFileInfo fileInfor(fichnom);
  162:     QString NomComplet = fileInfor.completeBaseName();
  163:     QString NomCompLaunch = fileInfor.canonicalPath()+"/"+NomComplet+".htm";
  164:     //QFileInfo fileInfolog(NomCompLaunch;
  165:     QDesktopServices::openUrl(QUrl("file://"+NomCompLaunch,QUrl::TolerantMode));
  166: }
  167: 
  168: void Dialog::on_openGnuplotButton_clicked()
  169: {
  170:  //   QString program = "ffplay";
  171:  //   QStringList arguments;
  172:     QString fichnom = ui->fromLineEdit->text();
  173:     QFileInfo fileInfor(fichnom);
  174:     QString NomComplet = fileInfor.completeBaseName();
  175:     //QString NomSuffix = fileInfor.suffix();
  176:     //QString NomCheminsansEx = fileInfor.canonicalPath()+NomComplet;
  177:     QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp";
  178:     QFileInfo fileInfoGp(NomCompGp);
  179:     //QString input = NomCheminsansEx;
  180:     //   arguments << input;
  181:  //   mInputPlayProcess->start(program, arguments);
  182:   //  QFile file(NomCompLog);
  183:   //  if(!file.open(QIODevice::ReadOnly))
  184:   //      QMessageBox::information(0,"info",file.errorString());
  185: 
  186:     QDesktopServices::openUrl(QUrl("file://"+NomCompGp,QUrl::TolerantMode));
  187: //o    QTextStream in(&file);
  188: //o    ui->playInputButton->setText(in.readAll());
  189: }
  190: 
  191: 
  192: void Dialog::on_runGnuplotButton_clicked()
  193: {
  194:     QString program = "gnuplot";
  195:     QStringList arguments;
  196:     QString fichnom = ui->fromLineEdit->text();
  197:     QFileInfo fileInfor(fichnom);
  198:     QString NomComplet = fileInfor.completeBaseName();
  199:     QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp";
  200:     //QFileInfo fileInfoGp(NomCompGp);
  201:     //QString input = NomCheminsansEx;
  202:     arguments << NomCompGp;
  203:     mGnuplotProcess->start(program, arguments);
  204:   //  QFile file(NomCompLog);
  205:   //  if(!file.open(QIODevice::ReadOnly))
  206:   //      QMessageBox::information(0,"info",file.errorString());
  207: 
  208:     //QDesktopServices::openUrl(QUrl("file://"+NomCompGp,QUrl::TolerantMode));
  209: //o    QTextStream in(&file);
  210: //o    ui->playInputButton->setText(in.readAll());
  211: }
  212: 
  213: //void Dialog::on_playOutputButton_clicked()
  214: //{
  215: //    QString program = "ffplay";
  216: //    QStringList arguments;
  217: //    QString output = ui->toLineEdit->text();
  218: //    arguments << output;
  219: //    mInputPlayProcess->start(program, arguments);
  220: //}
  221: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>