Kstars

opsindi.cpp
1 /*
2  SPDX-FileCopyrightText: 2003 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "opsindi.h"
8 
9 #include "ksnotification.h"
10 #include "kstars.h"
11 #include "Options.h"
12 
13 #include <KConfigDialog>
14 
15 #include <QCheckBox>
16 #include <QComboBox>
17 #include <QDesktopServices>
18 #include <QFileDialog>
19 #include <QPushButton>
20 #include <QStringList>
21 
22 OpsINDI::OpsINDI() : QFrame(KStars::Instance())
23 {
24  setupUi(this);
25 
26  //Get a pointer to the KConfigDialog
27  m_ConfigDialog = KConfigDialog::exists("settings");
28 
29  selectFITSDirB->setIcon(
30  QIcon::fromTheme("document-open-folder"));
31  selectFITSDirB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
32  selectDriversDirB->setIcon(
33  QIcon::fromTheme("document-open-folder"));
34  selectDriversDirB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
35  selectINDIHubB->setIcon(
36  QIcon::fromTheme("document-open"));
37  selectINDIHubB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
38 
39 #ifdef Q_OS_OSX
40  connect(kcfg_indiServerIsInternal, SIGNAL(clicked()), this, SLOT(toggleINDIInternal()));
41  kcfg_indiServerIsInternal->setToolTip(i18n("Internal or external INDI server?"));
42  connect(kcfg_indiDriversAreInternal, SIGNAL(clicked()), this, SLOT(toggleDriversInternal()));
43  kcfg_indiDriversAreInternal->setToolTip(i18n("Internal or external INDI drivers?"));
44 
45  if (Options::indiServerIsInternal())
46  kcfg_indiServer->setEnabled(false);
47  if (Options::indiDriversAreInternal())
48  kcfg_indiDriversDir->setEnabled(false);
49 
50 #else
51  kcfg_indiServerIsInternal->setVisible(false);
52  kcfg_indiDriversAreInternal->setVisible(false);
53 #endif
54 
55  connect(selectFITSDirB, SIGNAL(clicked()), this, SLOT(saveFITSDirectory()));
56  connect(selectDriversDirB, SIGNAL(clicked()), this, SLOT(saveDriversDirectory()));
57  connect(showLogsB, SIGNAL(clicked()), this, SLOT(slotShowLogFiles()));
58  connect(kcfg_indiServer, SIGNAL(editingFinished()), this, SLOT(verifyINDIServer()));
59  connect(selectINDIHubB, &QPushButton::clicked, this, &OpsINDI::saveINDIHubAgent);
60 
61 #ifdef Q_OS_WIN
62  kcfg_indiServer->setEnabled(false);
63 #endif
64 }
65 
66 void OpsINDI::toggleINDIInternal()
67 {
68  kcfg_indiServer->setEnabled(!kcfg_indiServerIsInternal->isChecked());
69  if (kcfg_indiServerIsInternal->isChecked())
70  kcfg_indiServer->setText("*Internal INDI Server*");
71  else
72  kcfg_indiServer->setText(KSUtils::getDefaultPath("indiServer"));
73 }
74 
75 void OpsINDI::toggleDriversInternal()
76 {
77  kcfg_indiDriversDir->setEnabled(!kcfg_indiDriversAreInternal->isChecked());
78  if (kcfg_indiDriversAreInternal->isChecked())
79  kcfg_indiDriversDir->setText("*Internal INDI Drivers*");
80  else
81  kcfg_indiDriversDir->setText(KSUtils::getDefaultPath("indiDriversDir"));
82 
83  KSNotification::info(i18n("You need to restart KStars for this change to take effect."));
84 }
85 
86 void OpsINDI::saveFITSDirectory()
87 {
88  QString dir =
89  QFileDialog::getExistingDirectory(KStars::Instance(), i18nc("@title:window", "FITS Default Directory"), kcfg_fitsDir->text());
90 
91  if (!dir.isEmpty())
92  kcfg_fitsDir->setText(dir);
93 }
94 
95 void OpsINDI::saveDriversDirectory()
96 {
97  QString dir = QFileDialog::getExistingDirectory(KStars::Instance(), i18nc("@title:window", "INDI Drivers Directory"),
98  kcfg_indiDriversDir->text());
99 
100  if (!dir.isEmpty())
101  {
102  kcfg_indiDriversDir->setText(dir);
103  KSNotification::info(i18n("You need to restart KStars for this change to take effect."));
104  }
105 }
106 
107 void OpsINDI::saveINDIHubAgent()
108 {
109  QUrl url = QFileDialog::getOpenFileUrl(this, i18nc("@title:window", "Select INDIHub Agent"), QUrl(), "indihub-agent");
110  if (url.isEmpty())
111  return;
112 
113  kcfg_INDIHubAgent->setText(url.toLocalFile());
114 }
115 
116 void OpsINDI::slotShowLogFiles()
117 {
118  QUrl path = QUrl::fromLocalFile(QDir::homePath() + "/.indi/logs");
119 
121 }
122 
123 void OpsINDI::verifyINDIServer()
124 {
125  // Do not verify internal
126  if (kcfg_indiServerIsInternal->isChecked())
127  return;
128 
129  QFileInfo indiserver(kcfg_indiServer->text());
130 
131  if (indiserver.exists() && indiserver.isFile() && indiserver.baseName() == "indiserver")
132  return;
133 
134  KSNotification::error(i18n("%1 is not a valid INDI server binary.", kcfg_indiServer->text()));
135 }
QUrl getOpenFileUrl(QWidget *parent, const QString &caption, const QUrl &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options, const QStringList &supportedSchemes)
void clicked(bool checked)
QIcon fromTheme(const QString &name)
bool openUrl(const QUrl &url)
QString homePath()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
static KStars * Instance()
Definition: kstars.h:125
QString i18n(const char *text, const TYPE &arg...)
bool isEmpty() const const
bool isEmpty() const const
QUrl fromLocalFile(const QString &localFile)
QString toLocalFile() const const
static KConfigDialog * exists(const QString &name)
This is the main window for KStars. In addition to the GUI elements, the class contains the program c...
Definition: kstars.h:92
void setupUi(QWidget *widget)
KIOFILEWIDGETS_EXPORT QString dir(const QString &fileClass)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options)
WA_LayoutUsesWidgetRect
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 16 2022 04:00:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.