7#include "indiproperty.h"
9#include "clientmanager.h"
10#include "indidevice.h"
11#include "indielement.h"
16#include "dialogs/timedialog.h"
19#include <indiproperty.h>
22#include <KSqueezedTextLabel>
24#include <QAbstractButton>
25#include <QButtonGroup>
32extern const char *libindi_strings_context;
37INDI_P::INDI_P(
INDI_G *ipg, INDI::Property prop) :
QWidget(ipg), pg(ipg), dataProp(prop)
42 PHBox->setObjectName(
"Property Horizontal Layout");
43 PHBox->setContentsMargins(0, 0, 0, 0);
46 PVBox->setObjectName(
"Property Vertical Layout");
51void INDI_P::updateStateLED()
54 switch (dataProp.getState())
80 if (label ==
"(I18N_EMPTY_MESSAGE)")
81 label = dataProp.getLabel();
84 ledStatus =
new KLed(
this);
86 ledStatus->
setLook(KLed::Sunken);
101 if (label ==
"(I18N_EMPTY_MESSAGE)")
128 switch (dataProp.getType())
131 if (dataProp.getSwitch()->getRule() == ISR_NOFMANY)
133 else if (dataProp.getSwitch()->count() > 4)
136 guiType = PG_BUTTONS;
138 if (guiType == PG_MENU)
163 labelWidget->
raise();
166void INDI_P::buildSwitchGUI()
168 auto svp =
static_cast<ISwitchVectorProperty*
>(dataProp.getSwitch());
175 if (guiType == PG_BUTTONS)
177 if (svp->r == ISR_1OFMANY)
182 else if (guiType == PG_RADIO)
188 for (
int i = 0; i < svp->nsp; i++)
190 auto lp =
new INDI_E(
this, dataProp);
191 lp->buildSwitch(groupB, svp->sp + i);
200void INDI_P::buildTextGUI()
202 auto tvp =
static_cast<ITextVectorProperty*
>(dataProp.getText());
207 for (
int i = 0; i < tvp->ntp; i++)
209 auto lp =
new INDI_E(
this, dataProp);
210 lp->buildText(tvp->tp + i);
222 if (name ==
"TIME_UTC")
228void INDI_P::buildNumberGUI()
230 auto nvp =
static_cast<INumberVectorProperty*
>(dataProp.getNumber());
235 for (
int i = 0; i < nvp->nnp; i++)
237 auto lp =
new INDI_E(
this, dataProp);
238 lp->buildNumber(nvp->np + i);
252void INDI_P::buildLightGUI()
254 auto lvp =
static_cast<ILightVectorProperty*
>(dataProp.getLight());
259 for (
int i = 0; i < lvp->nlp; i++)
261 auto ep =
new INDI_E(
this, dataProp);
262 ep->buildLight(lvp->lp + i);
271void INDI_P::buildBLOBGUI()
273 auto bvp =
static_cast<IBLOBVectorProperty*
>(dataProp.getBLOB());
278 for (
int i = 0; i < bvp->nbp; i++)
280 auto lp =
new INDI_E(
this, dataProp);
281 lp->buildBLOB(bvp->bp + i);
292 enableBLOBC->
setToolTip(
i18n(
"Enable binary data transfer from this property to KStars and vice-versa."));
296 connect(enableBLOBC, SIGNAL(stateChanged(
int)),
this, SLOT(setBLOBOption(
int)));
298 if (dataProp.getPermission() != IP_RO)
302void INDI_P::setBLOBOption(
int state)
304 pg->getDevice()->getClientManager()->setBLOBEnabled(state ==
Qt::Checked, dataProp.getDeviceName(), dataProp.getName());
309 auto svp = dataProp.getSwitch();
317 for (
auto &el : elementList)
319 if (el->getLabel() == buttonText)
321 newSwitch(el->getName());
327void INDI_P::resetSwitch()
329 auto svp = dataProp.getSwitch();
334 if (menuC !=
nullptr)
340void INDI_P::newSwitch(
int index)
342 auto svp = dataProp.getSwitch();
347 if (index >= svp->count() || index < 0)
350 auto sp = svp->at(index);
353 sp->setState(ISS_ON);
358void INDI_P::newSwitch(
const QString &name)
360 auto svp = dataProp.getSwitch();
370 if (svp->getRule() == ISR_1OFMANY)
373 sp->setState(ISS_ON);
377 if (svp->getRule() == ISR_ATMOST1)
379 ISState prev_state = sp->getState();
381 sp->setState(prev_state);
384 sp->setState(sp->getState() == ISS_ON ? ISS_OFF : ISS_ON);
390void INDI_P::sendSwitch()
392 auto svp = dataProp.getSwitch();
397 svp->setState(IPS_BUSY);
399 for (
auto &el : elementList)
405 pg->getDevice()->getClientManager()->sendNewProperty(svp);
408void INDI_P::sendText()
410 switch (dataProp.getType())
414 auto tvp = dataProp.getText();
418 tvp->setState(IPS_BUSY);
420 for (
auto &el : elementList)
423 pg->getDevice()->getClientManager()->sendNewProperty(tvp);
430 auto nvp = dataProp.getNumber();
434 nvp->setState(IPS_BUSY);
436 for (
auto &el : elementList)
439 pg->getDevice()->getClientManager()->sendNewProperty(nvp);
449void INDI_P::buildMenuGUI()
454 auto svp = dataProp.getSwitch();
461 if (svp->getPermission() == IP_RO)
462 connect(menuC, SIGNAL(activated(
int)),
this, SLOT(resetSwitch()));
464 connect(menuC, SIGNAL(activated(
int)),
this, SLOT(newSwitch(
int)));
466 for (
int i = 0; i < svp->nsp; i++)
468 auto tp = svp->at(i);
470 if (tp->getState() == ISS_ON)
473 auto lp =
new INDI_E(
this, dataProp);
475 lp->buildMenuItem(tp);
477 oneOption =
i18nc(libindi_strings_context, lp->getLabel().toUtf8());
479 if (oneOption ==
"(I18N_EMPTY_MESSAGE)")
480 oneOption = lp->getLabel().
toUtf8();
482 menuOptions.
append(oneOption);
484 elementList.append(lp);
503 connect(setB, SIGNAL(clicked()),
this, SLOT(processSetButton()));
508void INDI_P::addWidget(
QWidget *w)
518void INDI_P::updateMenuGUI()
520 auto svp = dataProp.getSwitch();
525 int currentIndex = svp->findOnSwitchIndex();
529void INDI_P::processSetButton()
531 switch (dataProp.getType())
535 if (dataProp.isNameMatch(
"TIME_UTC"))
555void INDI_P::sendBlob()
557 auto bvp = dataProp.getBLOB();
562 bvp->setState(IPS_BUSY);
564 pg->getDevice()->getClientManager()->startBlob(bvp->getDeviceName(), bvp->getName(),
567 for (
int i = 0; i < elementList.count(); i++)
569 auto bp = bvp->at(i);
570 pg->getDevice()->getClientManager()->sendOneBlob(bp);
573 pg->getDevice()->getClientManager()->finishBlob();
580 INDI_E *timeEle = getElement(
"UTC");
581 INDI_E *offsetEle = getElement(
"OFFSET");
582 if (!timeEle || !offsetEle)
593 timeEle->setText(
QString(
"%1-%2-%3T%4:%5:%6")
611 for (
auto *ep : elementList)
613 if (ep->getName() == elementName)
620bool INDI_P::isRegistered()
const
622 return (dataProp && dataProp.getRegistered());
INDI_E represents an INDI GUI element (Number, Text, Switch, Light, or BLOB) within an INDI property.
INDI_G represents a collection of INDI properties that share a common group.
void newTime()
newTime Display dialog to set UTC date and time to the driver.
void setupSetButton(const QString &caption)
Setup the 'set' button in the property.
void setColor(const QColor &color)
virtual void setAlignment(Qt::Alignment)
void setMargin(int margin)
static KStars * Instance()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString name(StandardAction id)
QString label(StandardShortcut id)
virtual void addItem(QLayoutItem *item) override
void addLayout(QLayout *layout, int stretch)
const char * constData() const const
void addItems(const QStringList &texts)
void setCurrentIndex(int index)
QDateTime currentDateTimeUtc()
QString toString(QStringView format, QCalendar cal) const const
void setFrameShadow(Shadow)
void setFrameShape(Shape)
QIcon fromTheme(const QString &name)
void setTextFormat(Qt::TextFormat)
void setWordWrap(bool on)
void setContentsMargins(const QMargins &margins)
void append(QList< T > &&value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
qreal devicePixelRatio() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QByteArray toLatin1() const const
QByteArray toUtf8() const const