FreeCAD

Форк
0
/
DlgRunExternal.cpp 
134 строки · 4.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
#include <QFileDialog>
26
#endif
27

28
#include "DlgRunExternal.h"
29
#include "ui_DlgRunExternal.h"
30
#include "FileDialog.h"
31

32

33
using namespace Gui::Dialog;
34

35
/* TRANSLATOR Gui::Dialog::DlgRunExternal */
36

37
/**
38
 *  Constructs a DlgRunExternal which is a child of 'parent', with the
39
 *  name 'name' and widget flags set to 'f'
40
 *
41
 *  The dialog will by default be modeless, unless you set 'modal' to
42
 *  true to construct a modal dialog.
43
 */
44
DlgRunExternal::DlgRunExternal(QWidget* parent, Qt::WindowFlags fl)
45
    : QDialog(parent, fl)
46
    , process(this)
47
    , advancedHidden(true)
48
    , ui(new Ui_DlgRunExternal)
49
{
50
    // clang-format off
51
    ui->setupUi(this);
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);
59
    // clang-format on
60

61
    ui->gridLayout->setSizeConstraint(QLayout::SetFixedSize);
62
    ui->extensionWidget->hide();
63
}
64

65
/**
66
 *  Destroys the object and frees any allocated resources
67
 */
68
DlgRunExternal::~DlgRunExternal() = default;
69

70
void DlgRunExternal::addArgument(const QString& arg)
71
{
72
    arguments.append(arg);
73
}
74

75
int DlgRunExternal::runProcess()
76
{
77
    QFileInfo ifo(ProcName);
78

79
    ui->programName->setText(ifo.baseName());
80
    ui->programPath->setText(ProcName);
81
    process.start(ProcName, arguments);
82

83
    ui->buttonAccept->setEnabled(false);
84
    ui->buttonDiscard->setEnabled(false);
85
    return exec();
86
}
87

88
void DlgRunExternal::reject()
89
{
90
    QDialog::reject();
91
}
92

93
void DlgRunExternal::accept()
94
{
95
    QDialog::accept();
96
}
97

98
void DlgRunExternal::abort()
99
{
100
    process.terminate();
101
    DlgRunExternal::reject();
102
}
103

104
void DlgRunExternal::advanced()
105
{
106
    if (advancedHidden) {
107
        ui->extensionWidget->show();
108
        advancedHidden = false;
109
    }
110
    else {
111
        ui->extensionWidget->hide();
112
        advancedHidden = true;
113
    }
114
}
115

116
void DlgRunExternal::finished(int exitCode, QProcess::ExitStatus exitStatus)
117
{
118
    Q_UNUSED(exitCode);
119
    Q_UNUSED(exitStatus);
120
    ui->buttonAccept->setEnabled(true);
121
    ui->buttonDiscard->setEnabled(true);
122
    ui->buttonAbort->setEnabled(false);
123
}
124

125
void DlgRunExternal::onChooseProgramClicked()
126
{
127
    QString fn;
128
    fn = QFileDialog::getOpenFileName(this, tr("Select a file"), ui->programPath->text());
129
    if (!fn.isEmpty()) {
130
        ui->programPath->setText(fn);
131
    }
132
}
133

134
#include "moc_DlgRunExternal.cpp"
135

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.