Kstars

scriptsmanager.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include <QFileDialog>
8 #include <QFileInfo>
9 
10 #include "scriptsmanager.h"
11 #include "ui_scriptsmanager.h"
12 #include "auxiliary/ksnotification.h"
13 
14 #include "scriptsmanager.h"
15 #include "ui_scriptsmanager.h"
16 
17 namespace Ekos
18 {
19 ScriptsManager::ScriptsManager(QWidget *parent) :
20  QDialog(parent),
21  ui(new Ui::ScriptsManager)
22 {
23  ui->setupUi(this);
24 
25  connect(ui->preJobB, &QPushButton::clicked, this, &ScriptsManager::handleSelectScripts);
26  connect(ui->postJobB, &QPushButton::clicked, this, &ScriptsManager::handleSelectScripts);
27  connect(ui->preCaptureB, &QPushButton::clicked, this, &ScriptsManager::handleSelectScripts);
28  connect(ui->postCaptureB, &QPushButton::clicked, this, &ScriptsManager::handleSelectScripts);
29 
30  connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
31  connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
32 }
33 
34 void ScriptsManager::handleSelectScripts()
35 {
36  QPushButton *button = qobject_cast<QPushButton*>(sender());
37  if (!button)
38  return;
39 
40  QString title;
41  if (button == ui->preJobB)
42  title = i18nc("@title:window", "Pre Job Script");
43  else if (button == ui->postJobB)
44  title = i18nc("@title:window", "Post Job Script");
45  else if (button == ui->postCaptureB)
46  title = i18nc("@title:window", "Post Capture Script");
47  else if (button == ui->preCaptureB)
48  title = i18nc("@title:window", "Pre Capture Script");
49 
50  QUrl url = QFileDialog::getOpenFileUrl(this, title);
51  if (!url.isValid())
52  return;
53 
54  QString localFile = url.toLocalFile();
55  QFileInfo info(localFile);
56 
57  if (info.permission(QFileDevice::ExeOwner) == false)
58  {
59  KSNotification::error(i18n("File %1 is not executable.", localFile));
60  return;
61  }
62 
63  if (button == ui->preJobB)
64  ui->preJobScript->setText(localFile);
65  else if (button == ui->postJobB)
66  ui->postJobScript->setText(localFile);
67  else if (button == ui->postCaptureB)
68  ui->postCaptureScript->setText(localFile);
69  else if (button == ui->preCaptureB)
70  ui->preCaptureScript->setText(localFile);
71 
72  connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
73  connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
74 }
75 
76 void ScriptsManager::setScripts(const QMap<ScriptTypes, QString> &scripts)
77 {
78  if (scripts.contains(SCRIPT_PRE_JOB))
79  ui->preJobScript->setText(scripts[SCRIPT_PRE_JOB]);
80 
81  if (scripts.contains(SCRIPT_POST_JOB))
82  ui->postJobScript->setText(scripts[SCRIPT_POST_JOB]);
83 
84  if (scripts.contains(SCRIPT_PRE_CAPTURE))
85  ui->preCaptureScript->setText(scripts[SCRIPT_PRE_CAPTURE]);
86 
87  if (scripts.contains(SCRIPT_POST_CAPTURE))
88  ui->postCaptureScript->setText(scripts[SCRIPT_POST_CAPTURE]);
89 }
90 
91 QMap<ScriptTypes, QString> ScriptsManager::getScripts()
92 {
94 
95  scripts[SCRIPT_PRE_JOB] = ui->preJobScript->text();
96  scripts[SCRIPT_POST_JOB] = ui->postJobScript->text();
97  scripts[SCRIPT_PRE_CAPTURE] = ui->preCaptureScript->text();
98  scripts[SCRIPT_POST_CAPTURE] = ui->postCaptureScript->text();
99 
100  return scripts;
101 }
102 
103 ScriptsManager::~ScriptsManager()
104 {
105  delete ui;
106 }
107 
108 }
QUrl getOpenFileUrl(QWidget *parent, const QString &caption, const QUrl &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options, const QStringList &supportedSchemes)
@ SCRIPT_POST_JOB
Script to run after a sequence job is completed.
Definition: ekos.h:174
bool contains(const Key &key) const const
virtual void reject()
Ekos is an advanced Astrophotography tool for Linux. It is based on a modular extensible framework to...
Definition: align.cpp:70
void clicked(bool checked)
bool isValid() const const
@ SCRIPT_PRE_CAPTURE
Script to run before a sequence capture is started.
Definition: ekos.h:172
QString i18n(const char *text, const TYPE &arg...)
virtual void accept()
QString toLocalFile() const const
void setupUi(QWidget *widget)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
@ SCRIPT_PRE_JOB
Script to run before a sequence job is started.
Definition: ekos.h:171
@ SCRIPT_POST_CAPTURE
Script to run after a sequence capture is completed.
Definition: ekos.h:173
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 04:01:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.