DlgRunExternal.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QFileDialog>
00027 # include <QMessageBox>
00028 #endif
00029 
00030 #include "Application.h"
00031 #include "MainWindow.h"
00032 #include "DlgRunExternal.h"
00033 #include "FileDialog.h"
00034 
00035 #include "ui_DlgRunExternal.h"
00036 
00037 
00038 using namespace Gui::Dialog;
00039 
00040 /* TRANSLATOR Gui::Dialog::DlgRunExternal */
00041 
00049 DlgRunExternal::DlgRunExternal( QWidget* parent, Qt::WFlags fl )
00050     : QDialog(parent, fl),process(this),advancedHidden(true)
00051 {
00052     ui = new Ui_DlgRunExternal();
00053     ui->setupUi(this);
00054     connect(&process,SIGNAL(finished(int, QProcess::ExitStatus)),
00055             this,SLOT(finished(int, QProcess::ExitStatus)));
00056     connect(ui->buttonAccept,SIGNAL(clicked()),this,SLOT(accept()));
00057     connect(ui->buttonDiscard,SIGNAL(clicked()),this,SLOT(reject()));
00058     connect(ui->buttonAbort,SIGNAL(clicked()),this,SLOT(abort()));
00059     connect(ui->buttonAdvanced,SIGNAL(clicked()),this,SLOT(advanced()));
00060 
00061     ui->gridLayout->setSizeConstraint(QLayout::SetFixedSize);
00062     ui->extensionWidget->hide();
00063 }
00064 
00068 DlgRunExternal::~DlgRunExternal()
00069 {
00070     // no need to delete child widgets, Qt does it all for us
00071     delete ui;
00072 }
00073 
00074 int DlgRunExternal::Do(void)
00075 {
00076     QFileInfo ifo (ProcName);
00077 
00078     ui->programName->setText(ifo.baseName());
00079     ui->programPath->setText(ProcName);
00080     process.start(ProcName,arguments);
00081 
00082     ui->buttonAccept->setEnabled(false);
00083     ui->buttonDiscard->setEnabled(false);
00084     return exec();
00085 }
00086 
00087 void DlgRunExternal::reject (void)
00088 {
00089     QDialog::reject();
00090 }
00091 
00092 void DlgRunExternal::accept (void)
00093 {
00094     QDialog::accept();
00095 }
00096 
00097 void DlgRunExternal::abort (void)
00098 {
00099     process.terminate();
00100     DlgRunExternal::reject();
00101 }
00102 
00103 void DlgRunExternal::advanced (void)
00104 {
00105     if (advancedHidden){
00106         ui->extensionWidget->show();
00107         advancedHidden = false;
00108     }
00109     else {
00110         ui->extensionWidget->hide();
00111         advancedHidden = true;
00112     }
00113 }
00114 
00115 void DlgRunExternal::finished (int exitCode, QProcess::ExitStatus exitStatus)
00116 {
00117     ui->buttonAccept->setEnabled(true);
00118     ui->buttonDiscard->setEnabled(true);
00119     ui->buttonAbort->setEnabled(false);
00120 }
00121 
00122 void DlgRunExternal::on_chooseProgram_clicked()
00123 {
00124     QString fn;
00125     fn = QFileDialog::getOpenFileName(this, tr("Select a file"), ui->programPath->text());
00126     if (!fn.isEmpty()) {
00127         ui->programPath->setText(fn);
00128     }
00129 }
00130 
00131 #include "moc_DlgRunExternal.cpp"
00132 

Generated on Wed Nov 23 19:00:07 2011 for FreeCAD by  doxygen 1.6.1