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

kstars

telescopewizardprocess.cpp

Go to the documentation of this file.
00001 /*  Telescope wizard
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 #include <qfile.h>
00011 #include <qpixmap.h>
00012 #include <qlabel.h>
00013 #include <qpushbutton.h>
00014 #include <qwidgetstack.h>
00015 #include <qstring.h>
00016 #include <qtimer.h>
00017 #include <qtable.h>
00018 #include <qtextedit.h>
00019 #include <qradiobutton.h>
00020 
00021 #include <klistview.h>
00022 #include <klineedit.h>
00023 #include <kmessagebox.h>
00024 #include <kprogress.h>
00025 
00026 #include "telescopewizardprocess.h"
00027 #include "Options.h"
00028 #include "kstars.h"
00029 #include "kstarsdata.h"
00030 #include "timedialog.h"
00031 #include "ksutils.h"
00032 #include "libkdeedu/extdate/extdatetime.h"
00033 
00034 #include "indimenu.h"
00035 #include "indidriver.h"
00036 #include "indielement.h"
00037 #include "indiproperty.h"
00038 #include "indistd.h"
00039 #include "indidevice.h"
00040 
00041 #define TIMEOUT_THRESHHOLD  20
00042 
00043 telescopeWizardProcess::telescopeWizardProcess( QWidget* parent, const char* name ) : telescopeWizard(parent, name)
00044 {
00045    currentPort  = -1;
00046    timeOutCount = 0;
00047    indiDev = NULL;
00048    progressScan = NULL;
00049    linkRejected = false;
00050 
00051    QString locStr;
00052    QFile sideIMG;
00053 
00054    if (KSUtils::openDataFile(sideIMG, "wizardside.png"))
00055        wizardPix->setPixmap(QPixmap(sideIMG.name()));
00056 
00057    backB->hide();
00058    currentPage = INTRO_P;
00059 
00060    ksw = (KStars *) parent;
00061 
00062    ksw->establishINDI();
00063 
00064    indimenu   = ksw->getINDIMenu();
00065    indidriver = ksw->getINDIDriver();
00066 
00067    INDIMessageBar = Options::indiMessages();
00068    Options::setIndiMessages( false );
00069 
00070   QTime newTime( ksw->data()->lt().time() );
00071   ExtDate newDate( ksw->data()->lt().date() );
00072 
00073   timeOut->setText( QString().sprintf("%02d:%02d:%02d", newTime.hour(), newTime.minute(), newTime.second()));
00074   dateOut->setText( QString().sprintf("%d-%02d-%02d", newDate.year(), newDate.month(), newDate.day()));
00075 
00076   if (ksw->geo()->translatedProvince().isEmpty())
00077     locationOut->setText( QString("%1, %2").arg(ksw->geo()->translatedName()).arg(ksw->geo()->translatedCountry()));
00078   else
00079     locationOut->setText( QString("%1, %2, %3").arg(ksw->geo()->translatedName())
00080                              .arg(ksw->geo()->translatedProvince())
00081                              .arg(ksw->geo()->translatedCountry()));
00082 
00083 
00084    for (unsigned int i=0; i < indidriver->devices.size(); i++)
00085               if (indidriver->devices[i]->deviceType == KSTARS_TELESCOPE)
00086             telescopeCombo->insertItem(indidriver->devices[i]->label);
00087 
00088    if ( !Options::indiTelescopePort().isEmpty())
00089     portList << Options::indiTelescopePort();
00090     
00091     portList << "/dev/ttyS0" <<  "/dev/ttyS1" << "/dev/ttyS2" << "/dev/ttyS3" << "/dev/ttyS4"
00092              << "/dev/ttyUSB0" << "/dev/ttyUSB1" << "/dev/ttyUSB2" << "/dev/ttyUSB3";// << "/dev/ttyUSB4";
00093 
00094    connect(helpB, SIGNAL(clicked()), parent, SLOT(appHelpActivated()));
00095    connect(nextB, SIGNAL(clicked()), this, SLOT(processNext()));
00096    connect(backB, SIGNAL(clicked()), this, SLOT(processBack()));
00097    connect(setTimeB, SIGNAL(clicked()), this, SLOT(newTime()));
00098    connect(setLocationB, SIGNAL(clicked()), this, SLOT(newLocation()));
00099 
00100    newDeviceTimer = new QTimer(this);
00101    QObject::connect( newDeviceTimer, SIGNAL(timeout()), this, SLOT(processPort()) );
00102 
00103 }
00104 
00105 telescopeWizardProcess::~telescopeWizardProcess()
00106 {
00107   if (progressScan)
00108     if (progressScan->wasCancelled())
00109       indidriver->processDeviceStatus(1);
00110 
00111     Options::setIndiMessages( INDIMessageBar );
00112 
00113     Reset();
00114 }
00115 
00116 void telescopeWizardProcess::processNext(void)
00117 {
00118   int linkResult=0;
00119 
00120  switch (currentPage)
00121  {
00122    case INTRO_P:
00123      currentPage++;
00124      backB->show();
00125      wizardContainer->raiseWidget(currentPage);
00126      break;
00127   case MODEL_P:
00128      currentPage++;
00129      wizardContainer->raiseWidget(currentPage);
00130      break;
00131   case TELESCOPE_P:
00132      currentPage++;
00133      wizardContainer->raiseWidget(currentPage);
00134      break;
00135   case LOCAL_P:
00136      currentPage++;
00137      wizardContainer->raiseWidget(currentPage);
00138      break;
00139   case PORT_P:
00140      linkResult = establishLink();
00141      if ( linkResult == 1)
00142      {
00143 progressScan = new KProgressDialog(this, "autoscan", i18n("Autoscan"), i18n("Please wait while KStars scan communication ports for attached telescopes.\nThis process might take few minutes to complete."), true);
00144    progressScan->setAllowCancel(true);
00145    progressScan->setAutoClose(true);
00146    progressScan->setAutoReset(true);
00147    progressScan->progressBar()->setTotalSteps(portList.count());
00148    progressScan->progressBar()->setValue(0);
00149    progressScan->show();
00150     }
00151     else if (linkResult == 2)
00152       KMessageBox::queuedMessageBox(0, KMessageBox::Information, i18n("Please wait while KStars tries to connect to your telescope..."));
00153     else if (linkResult == -1)
00154       KMessageBox::error(0, i18n("Error. Unable to locate telescope drivers."));
00155      break;
00156   default:
00157      break;
00158   }
00159 
00160 }
00161 
00162 void telescopeWizardProcess::processBack(void)
00163 {
00164  // for now, just display the next page, and restart once we reached the end
00165 
00166  switch (currentPage)
00167  {
00168    case INTRO_P:
00169    // we shouldn't be here!
00170    break;
00171      break;
00172   case MODEL_P:
00173      currentPage--;
00174      backB->hide();
00175      wizardContainer->raiseWidget(currentPage);
00176      break;
00177   case TELESCOPE_P:
00178      currentPage--;
00179      wizardContainer->raiseWidget(currentPage);
00180      break;
00181   case LOCAL_P:
00182      currentPage--;
00183      wizardContainer->raiseWidget(currentPage);
00184      break;
00185   case PORT_P:
00186      currentPage--;
00187      wizardContainer->raiseWidget(currentPage);
00188      break;
00189   default:
00190      break;
00191   }
00192 
00193 }
00194 
00195 void telescopeWizardProcess::newTime()
00196 {
00197     TimeDialog timedialog (ksw->data()->lt(), ksw);
00198 
00199     if ( timedialog.exec() == QDialog::Accepted )
00200     {
00201         KStarsDateTime dt( timedialog.selectedDate(), timedialog.selectedTime() );
00202         ksw->data()->changeDateTime( dt );
00203 
00204         timeOut->setText( QString().sprintf("%02d:%02d:%02d", dt.time().hour(), dt.time().minute(), dt.time().second()));
00205         dateOut->setText( QString().sprintf("%d-%02d-%02d", dt.date().year(), dt.date().month(), dt.date().day()));
00206     }
00207 }
00208 
00209 void telescopeWizardProcess::newLocation()
00210 {
00211 
00212    ksw->slotGeoLocator();
00213 
00214    locationOut->setText( QString("%1, %2, %3").arg(ksw->geo()->translatedName())
00215                          .arg(ksw->geo()->translatedProvince())
00216                          .arg(ksw->geo()->translatedCountry()));
00217    timeOut->setText( QString().sprintf("%02d:%02d:%02d", ksw->data()->lt().time().hour(), ksw->data()->lt().time().minute(), ksw->data()->lt().time().second()));
00218 
00219   dateOut->setText( QString().sprintf("%d-%02d-%02d", ksw->data()->lt().date().year(),
00220   ksw->data()->lt().date().month() ,ksw->data()->lt().date().day()));
00221 
00222 
00223 
00224 }
00225 
00226 int telescopeWizardProcess::establishLink()
00227 {
00228 
00229     if (!indidriver || !indimenu)
00230       return (0);
00231       
00232     QListViewItem *driverItem = NULL;
00233     driverItem = indidriver->localListView->findItem(telescopeCombo->currentText(), 0);
00234     if (driverItem == NULL) return -1;
00235 
00236     // If device is already running, we need to shut it down first
00237     if (indidriver->isDeviceRunning(telescopeCombo->currentText()))
00238     {
00239         indidriver->localListView->setSelected(driverItem, true);
00240         indidriver->processDeviceStatus(1);
00241     }
00242        
00243     // Set custome label for device
00244     indimenu->setCustomLabel(telescopeCombo->currentText());
00245     currentDevice = indimenu->currentLabel;
00246     // Select it
00247     indidriver->localListView->setSelected(driverItem, true);
00248     // Make sure we start is locally
00249     indidriver->localR->setChecked(true);
00250     // Run it
00251     indidriver->processDeviceStatus(0);
00252 
00253     if (!indidriver->isDeviceRunning(telescopeCombo->currentText()))
00254      return (3);
00255 
00256     newDeviceTimer->start(1500);
00257     
00258     if (portIn->text().isEmpty())
00259      return (1);
00260         else
00261      return (2);
00262 
00263 }
00264 
00265 void telescopeWizardProcess::processPort()
00266 {
00267      INDI_P * pp;
00268      INDI_E * lp;
00269 
00270      if (!indidriver || !indimenu)
00271        return;
00272      
00273      timeOutCount++;
00274 
00275      if (timeOutCount >= TIMEOUT_THRESHHOLD)
00276      {
00277        indidriver->processDeviceStatus(1);
00278        Reset();
00279        KMessageBox::error(0, i18n("Error: connection timeout. Unable to communicate with an INDI server"));
00280        close();
00281        return;
00282      }
00283 
00284     indiDev = indimenu->findDeviceByLabel(currentDevice);
00285     if (!indiDev) return;
00286 
00287      // port empty, start autoscan
00288      if (portIn->text().isEmpty())
00289      {
00290        newDeviceTimer->stop();
00291        linkRejected = false;
00292        connect(indiDev->stdDev, SIGNAL(linkRejected()), this, SLOT(scanPorts()));
00293        connect(indiDev->stdDev, SIGNAL(linkAccepted()), this, SLOT(linkSuccess()));
00294        scanPorts();
00295        return;
00296      }
00297 
00298      pp = indiDev->findProp("DEVICE_PORT");
00299      if (!pp) return;
00300      lp = pp->findElement("PORT");
00301      if (!lp) return;
00302 
00303      lp->write_w->setText(portIn->text());
00304      
00305      pp = indiDev->findProp("CONNECTION");
00306      if (!pp) return;
00307 
00308      newDeviceTimer->stop();
00309 
00310      Options::setIndiMessages( INDIMessageBar );
00311 
00312      pp->newSwitch(0);
00313 
00314      timeOutCount = 0;
00315 
00316      indimenu->show();
00317 
00318      close();
00319 
00320 }
00321 
00322 void telescopeWizardProcess::scanPorts()
00323 {
00324      INDI_P * pp;
00325      INDI_E *lp;
00326      
00327      if (!indiDev || !indidriver || !indimenu || linkRejected)
00328       return;
00329 
00330      currentPort++;
00331 
00332      progressScan->progressBar()->setValue(currentPort);
00333 
00334      if ( (unsigned) currentPort >= portList.count())
00335      {
00336       KMessageBox::sorry(0, i18n("Sorry. KStars failed to detect any attached telescopes, please check your settings and try again."));
00337       linkRejected = true;
00338       indidriver->processDeviceStatus(1);
00339       Reset();
00340       return;
00341      }
00342 
00343      if (indiDev->msgST_w)
00344         indiDev->msgST_w->clear();
00345 
00346      pp = indiDev->findProp("DEVICE_PORT");
00347      if (!pp) return;
00348      lp = pp->findElement("PORT");
00349      
00350      lp->write_w->setText(portList[currentPort]);
00351      pp->newText();
00352     
00353      pp = indiDev->findProp("CONNECTION");
00354      if (!pp) return;
00355 
00356      pp->newSwitch(0);
00357 
00358 }
00359 
00360 void telescopeWizardProcess::linkSuccess()
00361 {
00362   Reset();
00363 
00364   indimenu->show();
00365 
00366   close();
00367 
00368 }
00369 
00370 void telescopeWizardProcess::Reset()
00371 {
00372 
00373   currentPort = -1;
00374   timeOutCount = 0;
00375 
00376   if (progressScan)
00377     progressScan->close();
00378 
00379   indiDev = NULL;
00380 
00381 }
00382 
00383 #include "telescopewizardprocess.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