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);
126 PHBox->addLayout(PVBox);
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();
166 void INDI_P::buildSwitchGUI()
168 auto svp =
static_cast<ISwitchVectorProperty*
>(dataProp.getSwitch());
175 if (guiType == PG_BUTTONS)
177 if (svp->r == ISR_1OFMANY)
178 groupB->setExclusive(
true);
180 groupB->setExclusive(
false);
182 else if (guiType == PG_RADIO)
183 groupB->setExclusive(
false);
188 for (
int i = 0; i < svp->nsp; i++)
190 auto lp =
new INDI_E(
this, dataProp);
191 lp->buildSwitch(groupB, svp->sp + i);
192 elementList.append(lp);
197 PHBox->addItem(horSpacer);
200 void 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);
211 elementList.append(lp);
216 PHBox->addItem(horSpacer);
222 if (name ==
"TIME_UTC")
223 setupSetButton(
i18n(
"Time"));
225 setupSetButton(
i18n(
"Set"));
228 void 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);
239 elementList.append(lp);
244 PHBox->addItem(horSpacer);
249 setupSetButton(
i18n(
"Set"));
252 void 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);
263 elementList.append(ep);
268 PHBox->addItem(horSpacer);
271 void 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);
282 elementList.append(lp);
287 PHBox->addItem(horSpacer);
291 enableBLOBC->setChecked(
true);
292 enableBLOBC->setToolTip(
i18n(
"Enable binary data transfer from this property to KStars and vice-versa."));
294 PHBox->addWidget(enableBLOBC);
296 connect(enableBLOBC, SIGNAL(stateChanged(
int)),
this, SLOT(setBLOBOption(
int)));
298 if (dataProp.getPermission() != IP_RO)
299 setupSetButton(
i18n(
"Upload"));
302 void 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());
327 void INDI_P::resetSwitch()
329 auto svp = dataProp.getSwitch();
334 if (menuC !=
nullptr)
336 menuC->setCurrentIndex(svp->findOnSwitchIndex());
340 void 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);
358 void 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);
390 void INDI_P::sendSwitch()
392 auto svp = dataProp.getSwitch();
397 svp->setState(IPS_BUSY);
399 for (
auto &el : elementList)
405 pg->getDevice()->getClientManager()->sendNewProperty(svp);
408 void 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);
449 void 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);
487 menuC->addItems(menuOptions);
488 menuC->setCurrentIndex(onItem);
492 PHBox->addWidget(menuC);
493 PHBox->addItem(horSpacer);
500 setB->setMinimumWidth(MIN_SET_WIDTH *
KStars::Instance()->devicePixelRatio());
501 setB->setMaximumWidth(MAX_SET_WIDTH *
KStars::Instance()->devicePixelRatio());
503 connect(setB, SIGNAL(clicked()),
this, SLOT(processSetButton()));
505 PHBox->addWidget(setB);
508 void INDI_P::addWidget(
QWidget *w)
515 PVBox->addLayout(layout);
518 void INDI_P::updateMenuGUI()
520 auto svp = dataProp.getSwitch();
525 int currentIndex = svp->findOnSwitchIndex();
526 menuC->setCurrentIndex(currentIndex);
529 void INDI_P::processSetButton()
531 switch (dataProp.getType())
535 if (dataProp.isNameMatch(
"TIME_UTC"))
555 void 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)
620 bool INDI_P::isRegistered()
const
622 return (dataProp && dataProp.getRegistered());