16#include <QButtonGroup>
17#include <QSocketNotifier>
29#include <KLocalizedString>
35#include "skyobjects/skyobject.h"
36#include "dialogs/timedialog.h"
37#include "geolocation.h"
39#include "indiproperty.h"
40#include "indidevice.h"
42#include "indielement.h"
44#include <indi_debug.h>
46const char *libindi_strings_context =
"string from libindi, used in the config dialog";
53 m_BaseDevice = baseDevice;
54 m_ClientManager = in_cm;
56 m_Name = m_BaseDevice.getDeviceName();
65 msgST_w->setReadOnly(
true);
68 deviceVBox->addWidget(groupContainer);
69 deviceVBox->addWidget(msgST_w);
70 deviceVBox->setStretchFactor(0, 2);
75bool INDI_D::buildProperty(INDI::Property prop)
80 QString groupName(prop.getGroupName());
82 if (prop.getDeviceName() != m_Name)
85 INDI_G *pg = getGroup(groupName);
89 pg =
new INDI_G(
this, groupName);
90 groupsList.append(pg);
91 groupContainer->addTab(pg,
i18nc(libindi_strings_context, groupName.toUtf8()));
94 return pg->addProperty(prop);
98bool INDI_D::removeProperty(INDI::Property prop)
103 QString groupName(prop->getGroupName());
105 if (strcmp(prop->getDeviceName(), m_BaseDevice->getDeviceName()))
114 INDI_G *pg = getGroup(groupName);
119 bool removeResult = pg->removeProperty(prop->getName());
121 if (pg->size() == 0 && removeResult)
124 groupContainer->removeTab(groupsList.indexOf(pg));
125 groupsList.removeOne(pg);
133bool INDI_D::removeProperty(INDI::Property prop)
135 if (prop.getDeviceName() != m_Name)
138 for (
auto &oneGroup : groupsList)
140 for (
auto &oneProperty : oneGroup->getProperties())
142 if (prop.getName() == oneProperty->getName())
144 bool rc = oneGroup->removeProperty(prop.getName());
145 if (oneGroup->size() == 0)
147 int index = groupsList.indexOf(oneGroup);
148 groupContainer->removeTab(index);
149 delete groupsList.takeAt(index);
159bool INDI_D::updateProperty(INDI::Property prop)
161 switch (prop.getType())
164 return updateSwitchGUI(prop);
166 return updateNumberGUI(prop);
168 return updateTextGUI(prop);
170 return updateLightGUI(prop);
172 return updateBLOBGUI(prop);
178bool INDI_D::updateSwitchGUI(INDI::Property prop)
180 INDI_P *guiProp =
nullptr;
182 if (m_Name != prop.getDeviceName())
185 for (
const auto &pg : groupsList)
187 if ((guiProp = pg->getProperty(prop.getName())) !=
nullptr)
191 if (guiProp ==
nullptr || guiProp->isRegistered() ==
false)
194 guiProp->updateStateLED();
196 if (guiProp->getGUIType() == PG_MENU)
197 guiProp->updateMenuGUI();
200 for (
const auto &lp : guiProp->getElements())
207bool INDI_D::updateTextGUI(INDI::Property prop)
209 INDI_P *guiProp =
nullptr;
211 if (m_Name != prop.getDeviceName())
214 for (
const auto &pg : groupsList)
216 auto p = pg->getProperty(prop.getName());
224 if (guiProp ==
nullptr)
227 guiProp->updateStateLED();
229 for (
const auto &lp : guiProp->getElements())
235bool INDI_D::updateNumberGUI(INDI::Property prop)
237 INDI_P *guiProp =
nullptr;
239 if (m_Name != prop.getDeviceName())
242 for (
const auto &pg : groupsList)
244 auto p = pg->getProperty(prop.getName());
252 if (guiProp ==
nullptr)
255 guiProp->updateStateLED();
257 for (
const auto &lp : guiProp->getElements())
263bool INDI_D::updateLightGUI(INDI::Property prop)
265 INDI_P *guiProp =
nullptr;
267 if (m_Name != prop.getDeviceName())
270 for (
const auto &pg : groupsList)
272 auto p = pg->getProperty(prop.getName());
280 if (guiProp ==
nullptr)
283 guiProp->updateStateLED();
285 for (
const auto &lp : guiProp->getElements())
291bool INDI_D::updateBLOBGUI(INDI::Property prop)
293 INDI_P *guiProp =
nullptr;
295 if (m_Name != prop.getDeviceName())
298 for (
const auto &pg : groupsList)
300 auto p = pg->getProperty(prop.getName());
308 if (guiProp ==
nullptr)
311 guiProp->updateStateLED();
316void INDI_D::updateMessageLog(INDI::BaseDevice idv,
int messageID)
318 if (idv.getDeviceName() != m_BaseDevice.getDeviceName())
322 QString formatted = message;
325 if (message.
mid(21, 2) ==
"[E")
326 formatted = QString(
"<span style='color:red'>%1</span>").
arg(message);
327 else if (message.
mid(21, 2) ==
"[W")
328 formatted = QString(
"<span style='color:orange'>%1</span>").
arg(message);
329 else if (message.
mid(21, 2) !=
"[I")
332 qCDebug(KSTARS_INDI) << idv.getDeviceName() <<
":" << message.
mid(21);
336 if (Options::showINDIMessages())
339 msgST_w->ensureCursorVisible();
340 msgST_w->insertHtml(
i18nc(
"Message shown in INDI control panel",
"%1", formatted));
341 msgST_w->insertPlainText(
"\n");
342 QTextCursor c = msgST_w->textCursor();
344 msgST_w->setTextCursor(c);
346 qCInfo(KSTARS_INDI) << idv.getDeviceName() <<
": " << message.
mid(21);
357 for (
const auto &pg : groupsList)
359 if (pg->getName() == groupName)
366void INDI_D::clearMessageLog()
ClientManager manages connection to INDI server, creation of devices, and receiving/sending propertie...
INDI_G represents a collection of INDI properties that share a common group.
static KStars * Instance()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QStatusBar * statusBar() const const
void showMessage(const QString &message, int timeout)
QString arg(Args &&... args) const const
QString fromStdString(const std::string &str)
QString mid(qsizetype position, qsizetype n) const const
bool movePosition(MoveOperation operation, MoveMode mode, int n)