7 #include "indiproperty.h"
9 #include "clientmanager.h"
10 #include "indidevice.h"
11 #include "indielement.h"
12 #include "indigroup.h"
16 #include "dialogs/timedialog.h"
19 #include <indiproperty.h>
22 #include <KSqueezedTextLabel>
24 #include <QAbstractButton>
25 #include <QButtonGroup>
28 #include <QHBoxLayout>
29 #include <QPushButton>
30 #include <QVBoxLayout>
32 extern const char *libindi_strings_context;
37 INDI_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");
51 void INDI_P::updateStateLED()
54 switch (dataProp.getState())
76 void INDI_P::initGUI()
80 if (label ==
"(I18N_EMPTY_MESSAGE)")
81 label = dataProp.getLabel();
84 ledStatus =
new KLed(
this);
85 ledStatus->setMaximumSize(16, 16);
86 ledStatus->setLook(KLed::Sunken);
101 if (label ==
"(I18N_EMPTY_MESSAGE)")
112 labelW->setMargin(2);
113 labelW->setFixedWidth(PROPERTY_LABEL_WIDTH *
KStars::Instance()->devicePixelRatio());
116 labelW->setWordWrap(
true);
125 PHBox->addLayout(PVBox);
127 switch (dataProp.getType())
130 if (dataProp.getSwitch()->getRule() == ISR_NOFMANY)
132 else if (dataProp.getSwitch()->count() > 4)
135 guiType = PG_BUTTONS;
137 if (guiType == PG_MENU)
164 void INDI_P::buildSwitchGUI()
166 auto svp =
static_cast<ISwitchVectorProperty*
>(dataProp.getSwitch());
173 if (guiType == PG_BUTTONS)
175 if (svp->r == ISR_1OFMANY)
176 groupB->setExclusive(
true);
178 groupB->setExclusive(
false);
180 else if (guiType == PG_RADIO)
181 groupB->setExclusive(
false);
186 for (
int i = 0; i < svp->nsp; i++)
188 auto lp =
new INDI_E(
this, dataProp);
189 lp->buildSwitch(groupB, svp->sp + i);
190 elementList.append(lp);
195 PHBox->addItem(horSpacer);
198 void INDI_P::buildTextGUI()
200 auto tvp =
static_cast<ITextVectorProperty*
>(dataProp.getText());
205 for (
int i = 0; i < tvp->ntp; i++)
207 auto lp =
new INDI_E(
this, dataProp);
208 lp->buildText(tvp->tp + i);
209 elementList.append(lp);
214 PHBox->addItem(horSpacer);
220 if (name ==
"TIME_UTC")
221 setupSetButton(
i18n(
"Time"));
223 setupSetButton(
i18n(
"Set"));
226 void INDI_P::buildNumberGUI()
228 auto nvp =
static_cast<INumberVectorProperty*
>(dataProp.getNumber());
233 for (
int i = 0; i < nvp->nnp; i++)
235 auto lp =
new INDI_E(
this, dataProp);
236 lp->buildNumber(nvp->np + i);
237 elementList.append(lp);
242 PHBox->addItem(horSpacer);
247 setupSetButton(
i18n(
"Set"));
250 void INDI_P::buildLightGUI()
252 auto lvp =
static_cast<ILightVectorProperty*
>(dataProp.getLight());
257 for (
int i = 0; i < lvp->nlp; i++)
259 auto ep =
new INDI_E(
this, dataProp);
260 ep->buildLight(lvp->lp + i);
261 elementList.append(ep);
266 PHBox->addItem(horSpacer);
269 void INDI_P::buildBLOBGUI()
271 auto bvp =
static_cast<IBLOBVectorProperty*
>(dataProp.getBLOB());
276 for (
int i = 0; i < bvp->nbp; i++)
278 auto lp =
new INDI_E(
this, dataProp);
279 lp->buildBLOB(bvp->bp + i);
280 elementList.append(lp);
285 PHBox->addItem(horSpacer);
289 enableBLOBC->setChecked(
true);
290 enableBLOBC->setToolTip(
i18n(
"Enable binary data transfer from this property to KStars and vice-versa."));
292 PHBox->addWidget(enableBLOBC);
294 connect(enableBLOBC, SIGNAL(stateChanged(
int)),
this, SLOT(setBLOBOption(
int)));
296 if (dataProp.getPermission() != IP_RO)
297 setupSetButton(
i18n(
"Upload"));
300 void INDI_P::setBLOBOption(
int state)
302 pg->getDevice()->getClientManager()->setBLOBEnabled(state ==
Qt::Checked, dataProp.getDeviceName(), dataProp.getName());
307 auto svp = dataProp.getSwitch();
315 for (
auto &el : elementList)
317 if (el->getLabel() == buttonText)
319 newSwitch(el->getName());
325 void INDI_P::resetSwitch()
327 auto svp = dataProp.getSwitch();
332 if (menuC !=
nullptr)
334 menuC->setCurrentIndex(svp->findOnSwitchIndex());
338 void INDI_P::newSwitch(
int index)
340 auto svp = dataProp.getSwitch();
345 if (index >= svp->count() || index < 0)
348 auto sp = svp->at(index);
351 sp->setState(ISS_ON);
356 void INDI_P::newSwitch(
const QString &name)
358 auto svp = dataProp.getSwitch();
368 if (svp->getRule() == ISR_1OFMANY)
371 sp->setState(ISS_ON);
375 if (svp->getRule() == ISR_ATMOST1)
377 ISState prev_state = sp->getState();
379 sp->setState(prev_state);
382 sp->setState(sp->getState() == ISS_ON ? ISS_OFF : ISS_ON);
388 void INDI_P::sendSwitch()
390 auto svp = dataProp.getSwitch();
395 svp->setState(IPS_BUSY);
397 for (
auto &el : elementList)
403 pg->getDevice()->getClientManager()->sendNewSwitch(svp);
406 void INDI_P::sendText()
408 switch (dataProp.getType())
412 auto tvp = dataProp.getText();
416 tvp->setState(IPS_BUSY);
418 for (
auto &el : elementList)
421 pg->getDevice()->getClientManager()->sendNewText(tvp);
428 auto nvp = dataProp.getNumber();
432 nvp->setState(IPS_BUSY);
434 for (
auto &el : elementList)
437 pg->getDevice()->getClientManager()->sendNewNumber(nvp);
447 void INDI_P::buildMenuGUI()
452 auto svp = dataProp.getSwitch();
459 if (svp->getPermission() == IP_RO)
460 connect(menuC, SIGNAL(activated(
int)),
this, SLOT(resetSwitch()));
462 connect(menuC, SIGNAL(activated(
int)),
this, SLOT(newSwitch(
int)));
464 for (
int i = 0; i < svp->nsp; i++)
466 auto tp = svp->at(i);
468 if (tp->getState() == ISS_ON)
471 auto lp =
new INDI_E(
this, dataProp);
473 lp->buildMenuItem(tp);
475 oneOption =
i18nc(libindi_strings_context, lp->getLabel().toUtf8());
477 if (oneOption ==
"(I18N_EMPTY_MESSAGE)")
478 oneOption = lp->getLabel().
toUtf8();
480 menuOptions.
append(oneOption);
482 elementList.append(lp);
485 menuC->addItems(menuOptions);
486 menuC->setCurrentIndex(onItem);
490 PHBox->addWidget(menuC);
491 PHBox->addItem(horSpacer);
498 setB->setMinimumWidth(MIN_SET_WIDTH *
KStars::Instance()->devicePixelRatio());
499 setB->setMaximumWidth(MAX_SET_WIDTH *
KStars::Instance()->devicePixelRatio());
501 connect(setB, SIGNAL(clicked()),
this, SLOT(processSetButton()));
503 PHBox->addWidget(setB);
506 void INDI_P::addWidget(
QWidget *w)
513 PVBox->addLayout(layout);
516 void INDI_P::updateMenuGUI()
518 auto svp = dataProp.getSwitch();
523 int currentIndex = svp->findOnSwitchIndex();
524 menuC->setCurrentIndex(currentIndex);
527 void INDI_P::processSetButton()
529 switch (dataProp.getType())
533 if (dataProp.isNameMatch(
"TIME_UTC"))
553 void INDI_P::sendBlob()
557 auto bvp = dataProp.getBLOB();
562 bvp->setState(IPS_BUSY);
564 pg->getDevice()->getClientManager()->startBlob(bvp->getDeviceName(), bvp->getName(), timestamp());
566 for (
int i = 0; i < elementList.count(); i++)
568 INDI::WidgetView<IBLOB> *bp = bvp->at(i);
569 #if (INDI_VERSION_MINOR >= 4 && INDI_VERSION_RELEASE >= 2)
570 pg->getDevice()->getClientManager()->sendOneBlob(bp);
572 pg->getDevice()->getClientManager()->sendOneBlob(bp->getName(), bp->getSize(), bp->getFormat(),
573 const_cast<void *
>(bp->getBlob()));
602 pg->getDevice()->getClientManager()->finishBlob();
609 INDI_E *timeEle = getElement(
"UTC");
610 INDI_E *offsetEle = getElement(
"OFFSET");
611 if (!timeEle || !offsetEle)
622 timeEle->setText(
QString(
"%1-%2-%3T%4:%5:%6")
640 for (
auto *ep : elementList)
642 if (ep->getName() == elementName)
649 bool INDI_P::isRegistered()
const
651 return (dataProp && dataProp.getRegistered());