1
/***************************************************************************
2
* Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
28
#include "DlgRunExternal.h"
29
#include "ui_DlgRunExternal.h"
30
#include "FileDialog.h"
33
using namespace Gui::Dialog;
35
/* TRANSLATOR Gui::Dialog::DlgRunExternal */
38
* Constructs a DlgRunExternal which is a child of 'parent', with the
39
* name 'name' and widget flags set to 'f'
41
* The dialog will by default be modeless, unless you set 'modal' to
42
* true to construct a modal dialog.
44
DlgRunExternal::DlgRunExternal(QWidget* parent, Qt::WindowFlags fl)
47
, advancedHidden(true)
48
, ui(new Ui_DlgRunExternal)
52
connect(ui->chooseProgram, &QPushButton::clicked, this, &DlgRunExternal::onChooseProgramClicked);
53
connect(&process, qOverload<int, QProcess::ExitStatus>(&QProcess::finished),
54
this, qOverload<int, QProcess::ExitStatus>(&DlgRunExternal::finished));
55
connect(ui->buttonAccept, &QPushButton::clicked, this, &DlgRunExternal::accept);
56
connect(ui->buttonDiscard, &QPushButton::clicked, this, &DlgRunExternal::reject);
57
connect(ui->buttonAbort, &QPushButton::clicked, this, &DlgRunExternal::abort);
58
connect(ui->buttonAdvanced, &QPushButton::clicked, this, &DlgRunExternal::advanced);
61
ui->gridLayout->setSizeConstraint(QLayout::SetFixedSize);
62
ui->extensionWidget->hide();
66
* Destroys the object and frees any allocated resources
68
DlgRunExternal::~DlgRunExternal() = default;
70
void DlgRunExternal::addArgument(const QString& arg)
72
arguments.append(arg);
75
int DlgRunExternal::runProcess()
77
QFileInfo ifo(ProcName);
79
ui->programName->setText(ifo.baseName());
80
ui->programPath->setText(ProcName);
81
process.start(ProcName, arguments);
83
ui->buttonAccept->setEnabled(false);
84
ui->buttonDiscard->setEnabled(false);
88
void DlgRunExternal::reject()
93
void DlgRunExternal::accept()
98
void DlgRunExternal::abort()
101
DlgRunExternal::reject();
104
void DlgRunExternal::advanced()
106
if (advancedHidden) {
107
ui->extensionWidget->show();
108
advancedHidden = false;
111
ui->extensionWidget->hide();
112
advancedHidden = true;
116
void DlgRunExternal::finished(int exitCode, QProcess::ExitStatus exitStatus)
119
Q_UNUSED(exitStatus);
120
ui->buttonAccept->setEnabled(true);
121
ui->buttonDiscard->setEnabled(true);
122
ui->buttonAbort->setEnabled(false);
125
void DlgRunExternal::onChooseProgramClicked()
128
fn = QFileDialog::getOpenFileName(this, tr("Select a file"), ui->programPath->text());
130
ui->programPath->setText(fn);
134
#include "moc_DlgRunExternal.cpp"