1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "runconfigpane.h" |
6 | #include "environmentwidget.h" |
7 | |
8 | #include "services/project/projectservice.h" |
9 | |
10 | #include <QVBoxLayout> |
11 | #include <QLabel> |
12 | #include <QLineEdit> |
13 | #include <QPushButton> |
14 | #include <QFileDialog> |
15 | #include <QFormLayout> |
16 | #include <QTextBrowser> |
17 | |
18 | using namespace dpfservice; |
19 | |
20 | class RunConfigPanePrivate |
21 | { |
22 | friend class RunConfigPane; |
23 | |
24 | QLineEdit *cmdArgsLineEdit{nullptr}; |
25 | QLineEdit *workingDirLineEdit{nullptr}; |
26 | QLineEdit *excutableLabel{nullptr}; |
27 | |
28 | EnvironmentWidget *environmentWidget{nullptr}; |
29 | QString currentTargetName; |
30 | config::RunParam *runParam{nullptr}; |
31 | }; |
32 | |
33 | RunConfigPane::RunConfigPane(QWidget *parent) |
34 | : QWidget(parent) |
35 | , d (new RunConfigPanePrivate()) |
36 | { |
37 | setupUi(); |
38 | } |
39 | |
40 | RunConfigPane::~RunConfigPane() |
41 | { |
42 | |
43 | } |
44 | |
45 | void RunConfigPane::setupUi() |
46 | { |
47 | QVBoxLayout *vLayout = new QVBoxLayout(this); |
48 | |
49 | QFrame *mainFrame = new QFrame(this); |
50 | mainFrame->setObjectName("mainframe" ); |
51 | QFormLayout *formLayout = new QFormLayout(mainFrame); |
52 | |
53 | // excutable label ui. |
54 | d->excutableLabel = new QLineEdit(mainFrame); |
55 | d->excutableLabel->setText(tr("Here is the executable path" )); |
56 | d->excutableLabel->setReadOnly(true); |
57 | formLayout->addRow(tr("Executable path:" ), d->excutableLabel); |
58 | |
59 | // command line ui. |
60 | d->cmdArgsLineEdit = new QLineEdit(mainFrame); |
61 | connect(d->cmdArgsLineEdit, &QLineEdit::textChanged, [this](){ |
62 | if (d->runParam) |
63 | d->runParam->arguments = d->cmdArgsLineEdit->text().trimmed(); |
64 | }); |
65 | formLayout->addRow(tr("Command line arguments:" ), d->cmdArgsLineEdit); |
66 | |
67 | // working directory ui. |
68 | QHBoxLayout *browLayout = new QHBoxLayout(mainFrame); |
69 | auto browseBtn = new QPushButton(mainFrame); |
70 | browseBtn->setText(tr("Browse..." )); |
71 | d->workingDirLineEdit = new QLineEdit(mainFrame); |
72 | d->workingDirLineEdit->setReadOnly(true); |
73 | connect(d->workingDirLineEdit, &QLineEdit::textChanged, [this](){ |
74 | if (d->runParam) |
75 | d->runParam->workDirectory = d->workingDirLineEdit->text().trimmed(); |
76 | }); |
77 | browLayout->addWidget(d->workingDirLineEdit); |
78 | browLayout->addWidget(browseBtn); |
79 | formLayout->addRow(tr("Working directory:" ), browLayout); |
80 | connect(browseBtn, &QPushButton::clicked, [this](){ |
81 | QString outputDirectory = QFileDialog::getExistingDirectory(this, tr("Working directory" ), d->workingDirLineEdit->text()); |
82 | if (!outputDirectory.isEmpty()) { |
83 | d->workingDirLineEdit->setText(outputDirectory.toUtf8()); |
84 | } |
85 | }); |
86 | |
87 | mainFrame->setLayout(formLayout); |
88 | |
89 | d->environmentWidget = new EnvironmentWidget(this); |
90 | vLayout->addWidget(mainFrame); |
91 | vLayout->addWidget(d->environmentWidget); |
92 | |
93 | vLayout->setMargin(0); |
94 | } |
95 | |
96 | void RunConfigPane::bindValues(config::RunParam *runParam) |
97 | { |
98 | d->runParam = runParam; |
99 | d->environmentWidget->bindValues(&runParam->env); |
100 | d->cmdArgsLineEdit->setText(runParam->arguments); |
101 | d->workingDirLineEdit->setText(runParam->workDirectory); |
102 | d->currentTargetName = runParam->targetName; |
103 | d->excutableLabel->setText(runParam->targetPath); |
104 | } |
105 | |
106 | |