Debian Codegraph @

src/gui/settingsDialog/uploader/ScriptUploaderSettings.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "ScriptUploaderSettings.h"
21
22 ScriptUploaderSettings::ScriptUploaderSettings(const QSharedPointer<IConfig> &config, const QSharedPointer<IFileDialogService> &fileDialogService) :
23 mConfig(config),
24 mLayout(new QGridLayout(this)),
25 mCopyOutputToClipboardCheckbox(new QCheckBox(this)),
26 mStopOnStdErrCheckbox(new QCheckBox(this)),
27 mCopyOutputFilterLabel(new QLabel(this)),
28 mScriptPathLabel(new QLabel(this)),
29 mCopyOutputFilterLineEdit(new QLineEdit(this)),
30 mUploadScriptPathLineEdit(new QLineEdit(this)),
31 mBrowseButton(new QPushButton(this)),
32 mFileDialogService(fileDialogService)
33 {
34 initGui();
35 loadConfig();
36 }
37
38 ScriptUploaderSettings::~ScriptUploaderSettings()
39 {
40 delete mCopyOutputToClipboardCheckbox;
41 delete mStopOnStdErrCheckbox;
42 delete mCopyOutputFilterLabel;
43 delete mScriptPathLabel;
44 delete mCopyOutputFilterLineEdit;
45 delete mUploadScriptPathLineEdit;
46 delete mBrowseButton;
47 }
48
49 void ScriptUploaderSettings::saveSettings()
50 {
51 mConfig->setUploadScriptStopOnStdErr(mStopOnStdErrCheckbox->isChecked());
52 mConfig->setUploadScriptCopyOutputToClipboard(mCopyOutputToClipboardCheckbox->isChecked());
53 mConfig->setUploadScriptCopyOutputFilter(mCopyOutputFilterLineEdit->text());
54 mConfig->setUploadScriptPath(mUploadScriptPathLineEdit->text());
55 }
56
57 void ScriptUploaderSettings::initGui()
58 {
59 mStopOnStdErrCheckbox->setText(tr("Stop when upload script writes to StdErr"));
60 mStopOnStdErrCheckbox->setToolTip(tr("Marks the upload as failed when script writes to StdErr.\n"
61 "Without this setting errors in the script will be unnoticed."));
62
63 mCopyOutputToClipboardCheckbox->setText(tr("Copy script output to clipboard"));
64 connect(mCopyOutputToClipboardCheckbox, &QCheckBox::stateChanged, this, &ScriptUploaderSettings::copyToClipboardChanged);
65
66 mCopyOutputFilterLabel->setText(tr("Filter:"));
67 mCopyOutputFilterLabel->setToolTip(tr("RegEx Expression. Only copy to clipboard what matches the RegEx Expression.\n"
68 "When omitted, everything is copied."));
69
70 mCopyOutputFilterLineEdit->setToolTip(mCopyOutputFilterLabel->toolTip());
71
72 mScriptPathLabel->setText(tr("Script:"));
73 mScriptPathLabel->setToolTip(tr("Path to script that will be called for uploading. During upload the script will be called\n"
74 "with the path to a temporary png file as a single argument."));
75
76 mUploadScriptPathLineEdit->setToolTip(mScriptPathLabel->toolTip());
77
78 mBrowseButton->setText(tr("Browse"));
79 connect(mBrowseButton, &QPushButton::clicked, this, &ScriptUploaderSettings::ShowScriptSelectionDialog);
80
81 mLayout->setAlignment(Qt::AlignTop);
82 mLayout->setColumnMinimumWidth(0, 10);
83 mLayout->addWidget(mStopOnStdErrCheckbox, 0, 0, 1, 3);
84 mLayout->addWidget(mCopyOutputToClipboardCheckbox, 1, 0, 1, 3);
85 mLayout->addWidget(mCopyOutputFilterLabel, 2, 1, 1, 1);
86 mLayout->addWidget(mCopyOutputFilterLineEdit, 2, 2, 1, 1);
87 mLayout->addWidget(mScriptPathLabel, 3, 0, 1, 1);
88 mLayout->addWidget(mUploadScriptPathLineEdit, 3, 1, 1, 2);
89 mLayout->addWidget(mBrowseButton, 3, 3, 1, 1);
90
91 setTitle(tr("Script Uploader"));
92 setLayout(mLayout);
93 }
94
95 void ScriptUploaderSettings::loadConfig()
96 {
97 mStopOnStdErrCheckbox->setChecked(mConfig->uploadScriptStopOnStdErr());
98 mCopyOutputToClipboardCheckbox->setChecked(mConfig->uploadScriptCopyOutputToClipboard());
99 mCopyOutputFilterLineEdit->setText(mConfig->uploadScriptCopyOutputFilter());
100 mUploadScriptPathLineEdit->setText(mConfig->uploadScriptPath());
101
102 copyToClipboardChanged();
103 }
104
105 void ScriptUploaderSettings::ShowScriptSelectionDialog()
106 {
107 auto path = mFileDialogService->getOpenFileName(this, tr("Select Upload Script"), mConfig->uploadScriptPath());
108 if(PathHelper::isPathValid(path)) {
109 mUploadScriptPathLineEdit->setText(path);
110 }
111 }
112
113 void ScriptUploaderSettings::copyToClipboardChanged()
114 {
115 auto enabled = mCopyOutputToClipboardCheckbox->isChecked();
116 mCopyOutputFilterLabel->setEnabled(enabled);
117 mCopyOutputFilterLineEdit->setEnabled(enabled);
118 }