• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

indiproperty.cpp

Go to the documentation of this file.
00001 /*  INDI Property
00002     Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
00003 
00004     This application is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008     
00009    
00010  */
00011  
00012  #include "indiproperty.h"
00013  #include "indigroup.h"
00014  #include "indidevice.h"
00015  #include "devicemanager.h"
00016  #include "indimenu.h"
00017  #include "indistd.h"
00018  #include "indi/indicom.h"
00019  #include "Options.h"
00020  #include "kstars.h"
00021  #include "timedialog.h"
00022  #include "skymap.h"
00023 
00024  #include "indi/base64.h"
00025  #include "indi/indicom.h"
00026  
00027  #include <kpopupmenu.h>
00028  #include <klineedit.h>
00029  #include <kled.h>
00030  #include <klocale.h>
00031  #include <kcombobox.h>
00032  #include <kpushbutton.h>
00033  #include <knuminput.h> 
00034  #include <kdebug.h>
00035  #include <kmessagebox.h>
00036  
00037  #include <qbuttongroup.h> 
00038  #include <qcheckbox.h>
00039  #include <qlabel.h>
00040  #include <qlayout.h>
00041  #include <qtimer.h>
00042  #include <qfile.h>
00043  #include <qdatastream.h>
00044  #include <qtooltip.h>
00045 
00046  #include <unistd.h>
00047  #include <stdlib.h>
00048  
00049 /*******************************************************************
00050 ** INDI Property: contains widgets, labels, and their status
00051 *******************************************************************/
00052 INDI_P::INDI_P(INDI_G *parentGroup, QString inName)
00053 {
00054   name = inName;
00055 
00056   pg = parentGroup;
00057   
00058   el.setAutoDelete(true);
00059   
00060   stdID       = -1;
00061   
00062   indistd     = new INDIStdProperty(this, pg->dp->parent->ksw, pg->dp->stdDev);
00063   
00064   PHBox           = new QHBoxLayout(0, 0, KDialogBase::spacingHint());
00065   PVBox           = new QVBoxLayout(0, 0, KDialogBase::spacingHint());
00066   light           = NULL;
00067   label_w         = NULL;
00068   set_w           = NULL;
00069   assosiatedPopup = NULL;
00070   groupB          = NULL;
00071 }
00072 
00073 /* INDI property desstructor, makes sure everything is "gone" right */
00074 INDI_P::~INDI_P()
00075 {
00076       pg->propertyLayout->removeItem(PHBox);
00077       el.clear();
00078       delete (light);
00079       delete (label_w);
00080       delete (set_w);
00081       delete (PHBox);
00082       delete (indistd);
00083       delete (groupB);
00084 }
00085 
00086 bool INDI_P::isOn(QString component)
00087 {
00088 
00089   INDI_E *lp;
00090 
00091   lp = findElement(component);
00092 
00093   if (!lp)
00094    return false;
00095 
00096   if (lp->check_w && lp->check_w->isChecked())
00097      return true;
00098   if (lp->push_w && lp->push_w->isDown())
00099       return true;
00100 
00101   return false;
00102 }
00103 
00104 INDI_E * INDI_P::findElement(QString elementName)
00105 {
00106   INDI_E *element = NULL;
00107   
00108   for (element = el.first(); element != NULL; element = el.next())
00109      if (element->name == elementName || element->label == elementName)
00110         break;
00111 
00112   return element;
00113 }
00114 
00115 void INDI_P::drawLt(PState lstate)
00116 {
00117 
00118   
00119         /* set state light */
00120     switch (lstate)
00121     {
00122       case PS_IDLE:
00123       light->setColor(Qt::gray);
00124       break;
00125 
00126       case PS_OK:
00127       light->setColor(Qt::green);
00128       emit okState();
00129       disconnect( this, SIGNAL(okState()), 0, 0 );
00130       break;
00131 
00132       case PS_BUSY:
00133       light->setColor(Qt::yellow);
00134       break;
00135 
00136       case PS_ALERT:
00137       light->setColor(Qt::red);
00138       break;
00139 
00140       default:
00141       break;
00142 
00143     }
00144     
00145 }
00146 
00147 void INDI_P::newText()
00148 {
00149   INDI_E * lp;
00150   
00151   for (lp = el.first(); lp != NULL; lp = el.next())
00152   {
00153       /* If PG_SCALE */
00154       if (lp->spin_w)
00155        lp->targetValue = lp->spin_w->value();
00156       /* PG_NUMERIC or PG_TEXT */
00157       else
00158       {
00159         switch (perm)
00160     {
00161       case PP_RW:
00162       if (lp->write_w->text().isEmpty())
00163        lp->text = lp->read_w->text();
00164       else
00165        lp->text = lp->write_w->text();
00166       break;
00167       
00168       case PP_RO:
00169         break;
00170       
00171       case PP_WO:
00172        lp->text = lp->write_w->text();
00173       break;
00174     }
00175     
00176     if (guitype == PG_NUMERIC)
00177     {
00178            f_scansexa(lp->text.ascii(), &(lp->targetValue));
00179        if ((lp->targetValue > lp->max || lp->targetValue < lp->min))
00180        {
00181          KMessageBox::error(0, i18n("Invalid range for element %1. Valid range is from %2 to %3").arg(lp->label).arg(lp->min).arg(lp->max));
00182          return;
00183        }
00184         }
00185      }
00186   }
00187 
00188   state = PS_BUSY;
00189 
00190   drawLt(state);
00191   
00192   /* perform any std functions */
00193   indistd->newText();
00194 
00195   if (guitype == PG_TEXT)
00196     pg->dp->parentMgr->sendNewText(this);
00197   else if (guitype == PG_NUMERIC)
00198     pg->dp->parentMgr->sendNewNumber(this);
00199 
00200 }
00201 
00202 void INDI_P::convertSwitch(int id)
00203 {
00204  
00205  INDI_E *lp;
00206  QString mLabel;
00207  int switchIndex=0;
00208  
00209  if (assosiatedPopup == NULL)
00210   return;
00211 
00212   mLabel = assosiatedPopup->text(id).replace("&", "");
00213 
00214   //kdDebug() << "Name: " << name << " ID: " << id << endl;
00215  /* Special case is CCD_EXPOSE_DURATION, not a switch */
00216  if (stdID == CCD_EXPOSE_DURATION && mLabel.find(label) != -1)
00217  {
00218    newText();
00219    return;
00220  }
00221 
00222  /* Another special case, center telescope */
00223  if (mLabel.find("Crosshair") != -1)
00224  {
00225         if (!indistd->stdDev->dp->isOn()) return;
00226     if (indistd->stdDev->telescopeSkyObject == NULL) return;
00227     indistd->ksw->map()->setClickedObject(indistd->stdDev->telescopeSkyObject);
00228     indistd->ksw->map()->setClickedPoint(indistd->stdDev->telescopeSkyObject);
00229     indistd->ksw->map()->slotCenter();
00230     return;
00231  }
00232    
00233  lp = findElement(mLabel);
00234  
00235  if (!lp)
00236    return;
00237    
00238  for (uint i=0; i < el.count(); i++)
00239  {
00240    if (el.at(i)->label == mLabel)
00241    {
00242      switchIndex = i;
00243      break;
00244    }
00245  }
00246 
00247  if (indistd->convertSwitch(switchIndex, lp))
00248    return;
00249  else if (lp->state == PS_OFF)
00250          newSwitch(switchIndex);     
00251 }
00252 
00253 
00254 void INDI_P::newSwitch(int id)
00255 {
00256 
00257   QFont buttonFont;
00258   INDI_E *lp;
00259 
00260   lp = el.at(id);
00261 
00262   switch (guitype)
00263   {
00264     case PG_MENU:
00265     if (lp->state == PS_ON)
00266             return;
00267 
00268     for (unsigned int i=0; i < el.count(); i++)
00269       el.at(i)->state = PS_OFF;
00270       
00271     lp->state = PS_ON;
00272         break;
00273  
00274    case PG_BUTTONS:
00275       for (unsigned int i=0; i < el.count(); i++)
00276       {
00277           if (i == (unsigned int) id) continue;
00278       
00279           el.at(i)->push_w->setDown(false);
00280           buttonFont = el.at(i)->push_w->font();
00281       buttonFont.setBold(FALSE);
00282       el.at(i)->push_w->setFont(buttonFont);
00283           el.at(i)->state = PS_OFF;
00284        }
00285 
00286         lp->push_w->setDown(true);
00287     buttonFont = lp->push_w->font();
00288     buttonFont.setBold(TRUE);
00289     lp->push_w->setFont(buttonFont);
00290     lp->state = PS_ON;
00291 
00292        break;
00293        
00294    case PG_RADIO:
00295     lp->state = lp->state == PS_ON ? PS_OFF : PS_ON;
00296     lp->check_w->setChecked(lp->state == PS_ON);
00297    break;
00298    
00299    default:
00300     break;
00301 
00302   }
00303 
00304   state = PS_BUSY;
00305 
00306   drawLt(state);
00307   
00308   if (indistd->newSwitch(id, lp))
00309    return;
00310 
00311   pg->dp->parentMgr->sendNewSwitch (this, id);
00312 
00313 
00314 }
00315 
00316 /* Display file dialog to select and upload a file to the client
00317    Loop through blobs and send each accordingly
00318  */
00319 void INDI_P::newBlob()
00320 {
00321  QFile fp;
00322  QString filename;
00323  QString format;
00324  QDataStream binaryStream;
00325  int data64_size=0, pos=0;
00326  char *data_file;
00327  unsigned char *data, *data64;
00328  bool sending (false);
00329  bool valid (true);
00330  
00331   for (unsigned int i=0; i < el.count(); i++)
00332   {
00333      filename = el.at(i)->write_w->text();
00334      if (filename.isEmpty())
00335      {
00336         valid = false;
00337         continue; 
00338      }
00339      
00340       fp.setName(filename);
00341 
00342       if ( (pos = filename.findRev(".")) != -1)
00343         format = filename.mid (pos, filename.length());
00344 
00345       if (!fp.open(IO_ReadOnly))
00346       {
00347           KMessageBox::error(0, i18n("Cannot open file %1 for reading").arg(filename));
00348           valid = false;
00349           continue;
00350      }
00351      
00352      binaryStream.setDevice(&fp);
00353 
00354      data_file = new char[fp.size()];
00355      if (data_file == NULL)
00356      {
00357     KMessageBox::error(0, i18n("Not enough memory to load %1").arg(filename));
00358     fp.close();
00359         valid = false;
00360         continue;
00361      }
00362 
00363      binaryStream.readRawBytes(data_file, fp.size());
00364      data = (unsigned char *) data_file;
00365 
00366      data64 = new unsigned char[4*fp.size()/3+4];
00367      if (data64 == NULL)
00368      {
00369     KMessageBox::error(0, i18n("Not enough memory to convert file %1 to base64").arg(filename));
00370         fp.close();
00371         valid = false;
00372         continue;
00373      }
00374 
00375      data64_size = to64frombits (data64, data, fp.size());
00376 
00377      delete (data);
00378 
00379     if (sending == false)
00380     {
00381         sending = true;
00382     pg->dp->parentMgr->startBlob (pg->dp->name, name, QString(timestamp()));
00383     }
00384 
00385     pg->dp->parentMgr->sendOneBlob(el.at(i)->name, data64_size, format, data64);
00386 
00387     fp.close();
00388     delete (data64);
00389 
00390   }
00391 
00392   /* Nothing been made, no changes */
00393   if (!sending && !valid)
00394     return;
00395   else if (sending)
00396     pg->dp->parentMgr->finishBlob();
00397 
00398   if (valid) 
00399     state = PS_BUSY;
00400   else
00401     state = PS_ALERT;
00402 
00403   drawLt(state);
00404 
00405 }
00406 
00407 /* build widgets for property pp using info in root.
00408  */
00409 void INDI_P::addGUI (XMLEle *root)
00410 {
00411     XMLAtt *prompt;
00412     char errmsg[512];
00413 
00414     /* add to GUI group */
00415     light = new KLed (pg->propertyContainer);
00416     light->setMaximumSize(16,16);
00417     light->setLook(KLed::Sunken);
00418     //light->setShape(KLed::Rectangular);
00419     drawLt(state);
00420     
00421     /* #1 First widegt is the LED status indicator */
00422     PHBox->addWidget(light);
00423         
00424     /* #2 add label for prompt */
00425     prompt = findAtt(root, "label", errmsg);
00426     
00427     if (!prompt)
00428         label = name;
00429     else
00430         label = valuXMLAtt(prompt);
00431     
00432     // use property name if label is empty
00433     if (label.isEmpty())
00434     {
00435        label = name;
00436        label_w = new QLabel(label, pg->propertyContainer);
00437     }
00438     else
00439        label_w = new QLabel(label, pg->propertyContainer);
00440      
00441        label_w->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)5, 0, 0, label_w->sizePolicy().hasHeightForWidth() ) );
00442        label_w->setFrameShape( QLabel::GroupBoxPanel );
00443        label_w->setMinimumWidth(PROPERTY_LABEL_WIDTH);
00444        label_w->setMaximumWidth(PROPERTY_LABEL_WIDTH);
00445        label_w->setTextFormat( QLabel::RichText );
00446        label_w->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter | QLabel::AlignHCenter) );
00447        
00448        PHBox->addWidget(label_w);
00449      
00450          light->show();
00451      label_w->show();
00452      
00453      /* #3 Add the Vertical layout thay may contain several elements */
00454      PHBox->addLayout(PVBox);
00455 }
00456 
00457 int INDI_P::buildTextGUI(XMLEle *root, char errmsg[])
00458 {
00459         INDI_E *lp;
00460     XMLEle *text;
00461     XMLAtt *ap;
00462         QString textName, textLabel;
00463     errmsg=errmsg;
00464     
00465         for (text = nextXMLEle (root, 1); text != NULL; text = nextXMLEle (root, 0))
00466     {
00467         if (strcmp (tagXMLEle(text), "defText"))
00468         continue;
00469 
00470         ap = findXMLAtt(text, "name");
00471         if (!ap)
00472         {
00473             kdDebug() << "Error: unable to find attribute 'name' for property " << name << endl;
00474             return (-1);
00475         }
00476 
00477         textName = valuXMLAtt(ap);
00478             textName.truncate(MAXINDINAME);
00479 
00480         ap = findXMLAtt(text, "label");
00481 
00482         if (!ap)
00483         {
00484           kdDebug() << "Error: unable to find attribute 'label' for property " << name << endl;
00485           return (-1);
00486         }
00487 
00488         textLabel = valuXMLAtt(ap);
00489             
00490 
00491         if (textLabel.isEmpty())
00492           textLabel = textName;
00493 
00494           textLabel.truncate(MAXINDINAME);
00495          
00496              lp = new INDI_E(this, textName, textLabel);
00497 
00498          lp->buildTextGUI(QString(pcdataXMLEle(text)));
00499          
00500          el.append(lp);
00501          
00502      }
00503     
00504     if (perm == PP_RO)
00505       return 0;
00506     
00507      // INDI STD, but we use our own controls
00508      if (name == "TIME")
00509      {
00510             setupSetButton("Time");
00511             QObject::connect(set_w, SIGNAL(clicked()), indistd, SLOT(newTime()));
00512      }
00513      else
00514      {
00515         setupSetButton("Set");
00516             QObject::connect(set_w, SIGNAL(clicked()), this, SLOT(newText()));
00517          }
00518      
00519      return 0;
00520      
00521 }
00522 
00523 int INDI_P::buildNumberGUI  (XMLEle *root, char errmsg[])
00524 {
00525     char format[32];
00526     double min=0, max=0, step=0;
00527     XMLEle *number;
00528     XMLAtt *ap;
00529     INDI_E *lp;
00530     QString numberName, numberLabel;
00531     errmsg=errmsg;
00532     
00533     for (number = nextXMLEle (root, 1); number != NULL; number = nextXMLEle (root, 0))
00534     {
00535         if (strcmp (tagXMLEle(number), "defNumber"))
00536         continue;
00537 
00538         ap = findXMLAtt(number, "name");
00539         if (!ap)
00540         {
00541             kdDebug() << "Error: unable to find attribute 'name' for property " << name << endl;
00542             return (-1);
00543         }
00544 
00545         numberName = valuXMLAtt(ap);
00546             numberName.truncate(MAXINDINAME);
00547 
00548         ap = findXMLAtt(number, "label");
00549 
00550         if (!ap)
00551         {
00552           kdDebug() << "Error: unable to find attribute 'label' for property " << name << endl;
00553           return (-1);
00554         }
00555 
00556         numberLabel = valuXMLAtt(ap);
00557         
00558         if (numberLabel.isEmpty())
00559           numberLabel = numberName;
00560 
00561            numberLabel.truncate(MAXINDINAME);
00562         
00563         lp = new INDI_E(this, numberName, numberLabel);
00564 
00565         ap = findXMLAtt (number, "min");
00566         if (ap)
00567         min = atof(valuXMLAtt(ap));
00568         ap = findXMLAtt (number, "max");
00569         if (ap)
00570         max = atof(valuXMLAtt(ap));
00571         ap = findXMLAtt (number, "step");
00572         if (ap)
00573         step = atof(valuXMLAtt(ap));
00574         ap = findXMLAtt (number, "format");
00575         if (ap)
00576         strcpy(format,valuXMLAtt(ap));
00577 
00578         lp->initNumberValues(min, max, step, format);
00579 
00580         lp->buildNumberGUI(atof(pcdataXMLEle(number)));
00581 
00582         el.append(lp);
00583 
00584      }
00585      
00586     if (perm == PP_RO)
00587       return 0;
00588       
00589         if (name == "CCD_EXPOSE_DURATION")
00590               setupSetButton("Start");
00591         else
00592           setupSetButton("Set");
00593           
00594     QObject::connect(set_w, SIGNAL(clicked()), this, SLOT(newText()));
00595            
00596     return (0);
00597 }
00598 
00599 
00600 void INDI_P::setupSetButton(QString caption)
00601 {
00602     set_w = new QPushButton(caption, pg->propertyContainer);
00603     set_w->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, set_w->sizePolicy().hasHeightForWidth() ) );
00604     set_w->setMinimumWidth( MIN_SET_WIDTH );
00605     set_w->setMaximumWidth( MAX_SET_WIDTH );
00606 
00607     PHBox->addWidget(set_w);
00608 }
00609 
00610 int INDI_P::buildMenuGUI(XMLEle *root, char errmsg[])
00611 {
00612     XMLEle *sep = NULL;
00613     XMLAtt *ap;
00614     INDI_E *lp;
00615     QString switchName, switchLabel;
00616     QStringList menuOptions;
00617     int i=0, onItem=-1;
00618 
00619     guitype = PG_MENU;
00620 
00621         // build pulldown menu first
00622     // create each switch.
00623     // N.B. can only be one in On state.
00624     for (sep = nextXMLEle (root, 1), i=0; sep != NULL; sep = nextXMLEle (root, 0), i++)
00625     {
00626         /* look for switch tage */
00627         if (strcmp (tagXMLEle(sep), "defSwitch"))
00628                    continue;
00629 
00630             /* find name  */
00631         ap = findAtt (sep, "name", errmsg);
00632         if (!ap)
00633         return (-1);
00634 
00635         switchName = valuXMLAtt(ap);
00636             switchName.truncate(MAXINDINAME);
00637         
00638         /* find label */
00639         ap = findAtt (sep, "label", errmsg);
00640          if (!ap)
00641         return (-1);
00642 
00643         switchLabel = valuXMLAtt(ap);
00644 
00645         if (switchLabel.isEmpty())
00646           switchLabel = switchName;
00647 
00648             switchLabel.truncate(MAXINDINAME);
00649 
00650             lp = new INDI_E(this, switchName, switchLabel);
00651 
00652         if (pg->dp->crackSwitchState (pcdataXMLEle(sep), &(lp->state)) < 0)
00653         {
00654         snprintf (errmsg, ERRMSG_SIZE, "INDI: <%.64s> unknown state %.64s for %.64s %.64s %.64s",
00655                 tagXMLEle(root), valuXMLAtt(ap), name.ascii(), lp->name.ascii(), name.ascii());
00656         return (-1);
00657         }
00658 
00659              menuOptions.append(switchLabel);
00660         
00661         if (lp->state == PS_ON)
00662         {
00663         if (onItem != -1)
00664         {
00665             snprintf (errmsg, ERRMSG_SIZE, "INDI: <%.64s> %.64s %.64s has multiple On switches",
00666                     tagXMLEle(root), name.ascii(), lp->name.ascii());
00667             return (-1);
00668         }
00669         
00670         onItem = i;
00671         }
00672             
00673         el.append(lp);
00674     }
00675 
00676     om_w = new KComboBox(pg->propertyContainer);
00677     om_w->insertStringList(menuOptions);
00678     om_w->setCurrentItem(onItem);
00679     
00680     HorSpacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00681     
00682     PHBox->addWidget(om_w);
00683     PHBox->addItem(HorSpacer);
00684 
00685     QObject::connect(om_w, SIGNAL(activated(int)), this, SLOT(newSwitch(int)));
00686 
00687         return (0);
00688 }
00689 
00690 int INDI_P::buildSwitchesGUI(XMLEle *root, char errmsg[])
00691 {
00692         XMLEle *sep;
00693     XMLAtt *ap;
00694     INDI_E *lp;
00695     KPushButton *button(NULL);
00696     QCheckBox   *checkbox;
00697     QFont buttonFont;
00698     QString switchName, switchLabel;
00699     int j;
00700 
00701     groupB = new QButtonGroup(0);
00702         groupB->setFrameShape(QFrame::NoFrame);
00703     if (guitype == PG_BUTTONS)
00704       groupB->setExclusive(true);
00705       
00706     QObject::connect(groupB, SIGNAL(clicked(int)), this, SLOT(newSwitch(int)));
00707 
00708        for (sep = nextXMLEle (root, 1), j=-1; sep != NULL; sep = nextXMLEle (root, 0))
00709        {
00710         /* look for switch tage */
00711         if (strcmp (tagXMLEle(sep), "defSwitch"))
00712                    continue;
00713             
00714         /* find name  */
00715         ap = findAtt (sep, "name", errmsg);
00716         if (!ap)
00717         return (-1);
00718 
00719         switchName = valuXMLAtt(ap);
00720             switchName.truncate(MAXINDINAME);
00721 
00722         /* find label */
00723         ap = findAtt (sep, "label", errmsg);
00724          if (!ap)
00725             return (-1);
00726 
00727         switchLabel = valuXMLAtt(ap);
00728         
00729         if (switchLabel.isEmpty())
00730           switchLabel = switchName;
00731 
00732             switchLabel.truncate(MAXINDINAME);
00733         
00734             lp = new INDI_E(this, switchName, switchLabel);
00735 
00736         if (pg->dp->crackSwitchState (pcdataXMLEle(sep), &(lp->state)) < 0)
00737         {
00738         snprintf (errmsg, ERRMSG_SIZE, "INDI: <%.64s> unknown state %.64s for %.64s %.64s %.64s",
00739                 tagXMLEle(root), valuXMLAtt(ap), name.ascii(), name.ascii(), lp->name.ascii());
00740         return (-1);
00741         }
00742 
00743         j++;
00744 
00745         /* build toggle */
00746         switch (guitype)
00747         {
00748           case PG_BUTTONS:
00749            button = new KPushButton(switchLabel, pg->propertyContainer);
00750 
00751            groupB->insert(button, j);
00752 
00753            if (lp->state == PS_ON)
00754            {
00755                button->setDown(true);
00756            buttonFont = button->font();
00757            buttonFont.setBold(TRUE);
00758            button->setFont(buttonFont);
00759            }
00760 
00761            lp->push_w = button;
00762 
00763            PHBox->addWidget(button);
00764                    
00765            button->show();
00766 
00767           break;
00768 
00769           case PG_RADIO:
00770           checkbox = new QCheckBox(switchLabel, pg->propertyContainer);
00771           groupB->insert(checkbox, j);
00772 
00773           if (lp->state == PS_ON)
00774             checkbox->setChecked(true);
00775 
00776           lp->check_w = checkbox;
00777           
00778           PHBox->addWidget(checkbox);
00779           
00780               checkbox->show();
00781 
00782           break;
00783 
00784           default:
00785           break;
00786 
00787         }
00788 
00789         el.append(lp);
00790     }
00791 
00792         if (j < 0)
00793      return (-1);
00794      
00795         HorSpacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00796     
00797     PHBox->addItem(HorSpacer);
00798 
00799         return (0);
00800 }
00801 
00802 int INDI_P::buildLightsGUI(XMLEle *root, char errmsg[])
00803 {
00804         XMLEle *lep;
00805     XMLAtt *ap;
00806     INDI_E *lp;
00807     QString sname, slabel;
00808     
00809     for (lep = nextXMLEle (root, 1); lep != NULL; lep = nextXMLEle (root, 0))
00810         {
00811         if (strcmp (tagXMLEle(lep), "defLight"))
00812         continue;
00813 
00814         /* find name  */
00815         ap = findAtt (lep, "name", errmsg);
00816         if (!ap) return (-1);
00817     
00818         sname = valuXMLAtt(ap);
00819             sname.truncate(MAXINDINAME);
00820 
00821         /* find label */
00822         ap = findAtt (lep, "label", errmsg);
00823          if (!ap) return (-1);
00824 
00825         slabel = valuXMLAtt(ap);
00826         if (slabel.isEmpty())
00827           slabel = sname;
00828 
00829             slabel.truncate(MAXINDINAME);
00830        
00831        lp = new INDI_E(this, sname, slabel);
00832 
00833        if (pg->dp->crackLightState (pcdataXMLEle(lep), &lp->state) < 0)
00834         {
00835         snprintf (errmsg, ERRMSG_SIZE, "INDI: <%.64s> unknown state %.64s for %.64s %.64s %.64s",
00836                 tagXMLEle(root), valuXMLAtt(ap), pg->dp->name.ascii(), name.ascii(), sname.ascii());
00837         return (-1);
00838        }
00839        
00840        lp->buildLightGUI();
00841            el.append(lp);
00842     }
00843     
00844     HorSpacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00845     
00846     PHBox->addItem(HorSpacer);
00847 
00848     return (0);
00849 }
00850 
00851 /* Build BLOB GUI
00852  * Return 0 if okay, -1 if error */
00853 int INDI_P::buildBLOBGUI(XMLEle *root, char errmsg[])
00854 {
00855   INDI_E *lp;
00856   XMLEle *blob;
00857   XMLAtt *ap;
00858   QString blobName, blobLabel ;
00859   errmsg=errmsg;
00860     
00861   for (blob = nextXMLEle (root, 1); blob != NULL; blob = nextXMLEle (root, 0))
00862   {
00863     if (strcmp (tagXMLEle(blob), "defBLOB"))
00864       continue;
00865 
00866     ap = findXMLAtt(blob, "name");
00867     if (!ap)
00868     {
00869       kdDebug() << "Error: unable to find attribute 'name' for property " << name << endl;
00870       return (-1);
00871     }
00872 
00873     blobName = valuXMLAtt(ap);
00874     blobName.truncate(MAXINDINAME);
00875 
00876     ap = findXMLAtt(blob, "label");
00877 
00878     if (!ap)
00879     {
00880       kdDebug() << "Error: unable to find attribute 'label' for property " << name << endl;
00881       return (-1);
00882     }
00883 
00884     blobLabel = valuXMLAtt(ap);
00885 
00886     if (blobLabel.isEmpty())
00887       blobLabel = blobName;
00888 
00889     blobLabel.truncate(MAXINDINAME);
00890 
00891     lp = new INDI_E(this, blobName, blobLabel);
00892 
00893     lp->buildBLOBGUI();
00894          
00895     el.append(lp);
00896          
00897   }
00898     
00899   if (perm == PP_RO)
00900     return 0;
00901     
00902    setupSetButton(i18n("Upload"));
00903    QObject::connect(set_w, SIGNAL(clicked()), this, SLOT(newBlob()));
00904 
00905   return 0;
00906      
00907 }
00908 
00909 void INDI_P::activateSwitch(QString name)
00910 {
00911   int iCounter = 0;
00912   INDI_E *element;
00913   
00914   for (element = el.first(); element != NULL; element = el.next())
00915   {
00916      if (element->name == name && element->push_w)
00917        newSwitch(iCounter);
00918      
00919      iCounter++;
00920   }
00921   
00922 }
00923 
00924 
00925 
00926 #include "indiproperty.moc"

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal