Kstars

scriptsmanager.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Jasem Mutlaq <mutlaqja@ikarustech.com>
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
17namespace Ekos
18{
19ScriptsManager::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
34void 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
76void ScriptsManager::setScripts(const QMap<ScriptTypes, QString> &scripts)
77{
78 ui->preJobScript->setText(scripts[SCRIPT_PRE_JOB]);
79 ui->postJobScript->setText(scripts[SCRIPT_POST_JOB]);
80 ui->preCaptureScript->setText(scripts[SCRIPT_PRE_CAPTURE]);
81 ui->postCaptureScript->setText(scripts[SCRIPT_POST_CAPTURE]);
82}
83
84QMap<ScriptTypes, QString> ScriptsManager::getScripts()
85{
87
88 scripts[SCRIPT_PRE_JOB] = ui->preJobScript->text();
89 scripts[SCRIPT_POST_JOB] = ui->postJobScript->text();
90 scripts[SCRIPT_PRE_CAPTURE] = ui->preCaptureScript->text();
91 scripts[SCRIPT_POST_CAPTURE] = ui->postCaptureScript->text();
92
93 return scripts;
94}
95
96ScriptsManager::~ScriptsManager()
97{
98 delete ui;
99}
100
101}
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
@ SCRIPT_POST_CAPTURE
Script to run after a sequence capture is completed.
Definition ekos.h:176
@ SCRIPT_POST_JOB
Script to run after a sequence job is completed.
Definition ekos.h:177
@ SCRIPT_PRE_CAPTURE
Script to run before a sequence capture is started.
Definition ekos.h:175
@ SCRIPT_PRE_JOB
Script to run before a sequence job is started.
Definition ekos.h:174
void clicked(bool checked)
virtual void accept()
virtual void reject()
QUrl getOpenFileUrl(QWidget *parent, const QString &caption, const QUrl &dir, const QString &filter, QString *selectedFilter, Options options, const QStringList &supportedSchemes)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isValid() const const
QString toLocalFile() const const
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.