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

kstars

telescopeprop.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           telescopeprop.cpp  -  description
00003                              -------------------
00004     begin                : Wed June 8th 2005
00005     copyright            : (C) 2005 by Jasem Mutlaq
00006     email                : mutlaqja@ikarustech.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #include <kpushbutton.h>
00020 #include <klistbox.h>
00021 #include <kcombobox.h>
00022 #include <klineedit.h>
00023 #include <kmessagebox.h>
00024 
00025 #include <vector>
00026 
00027 #include "telescopeprop.h"
00028 #include "kstars.h"
00029 #include "indimenu.h"
00030 #include "indidriver.h"
00031 
00032 telescopeProp::telescopeProp(QWidget* parent, const char* name, bool modal, WFlags fl)
00033 : scopeProp(parent,name, modal,fl)
00034 {
00035 
00036   ksw = (KStars *) parent;
00037   
00038   ksw->establishINDI();
00039   indi_driver = ksw->getINDIDriver();
00040   newScopePending = false;
00041 
00042   connect (newB, SIGNAL(clicked()), this, SLOT(newScope()));
00043   connect (saveB, SIGNAL(clicked()), this, SLOT(saveScope()));
00044   connect (removeB, SIGNAL(clicked()), this, SLOT(removeScope()));
00045   connect (telescopeListBox, SIGNAL(highlighted(int)),this, SLOT(updateScopeDetails(int)));
00046   connect(closeB, SIGNAL(clicked()), this, SLOT(close()));
00047 
00048   // Fill the combo box with drivers
00049   driverCombo->insertStringList(indi_driver->driversList);
00050 
00051   // Fill the list box with telescopes
00052   for (unsigned int i=0; i < indi_driver->devices.size(); i++)
00053   {
00054     if (indi_driver->devices[i]->deviceType == KSTARS_TELESCOPE)
00055         telescopeListBox->insertItem(indi_driver->devices[i]->label);
00056   }
00057 
00058   telescopeListBox->setCurrentItem(0);
00059   updateScopeDetails(0);
00060      
00061 
00062 }
00063 
00064 telescopeProp::~telescopeProp()
00065 {
00066 }
00067 
00068 void telescopeProp::newScope()
00069 {
00070 
00071   driverCombo->clearEdit();
00072   labelEdit->clear();
00073   focalEdit->clear();
00074   versionEdit->clear();
00075   apertureEdit->clear();
00076 
00077   driverCombo->setFocus();
00078   telescopeListBox->clearFocus();
00079   telescopeListBox->clearSelection();
00080 
00081   newScopePending = true;
00082 
00083 }
00084 
00085 void telescopeProp::saveScope()
00086 {
00087   IDevice *dev (NULL);
00088   double focal_length(-1), aperture(-1);
00089   int finalIndex = -1;
00090 
00091   if (labelEdit->text().isEmpty())
00092     {
00093        KMessageBox::error(NULL, i18n("Telescope label is missing."));
00094        return;
00095     }
00096 
00097     if (driverCombo->currentText().isEmpty())
00098     {
00099       KMessageBox::error(NULL, i18n("Telescope driver is missing."));
00100       return;
00101     }
00102 
00103    if (versionEdit->text().isEmpty())
00104    {
00105      KMessageBox::error(NULL, i18n("Telescope driver version is missing."));
00106      return;
00107    }
00108 
00109    if (telescopeListBox->currentItem() != -1)
00110     finalIndex = findDeviceIndex(telescopeListBox->currentItem());
00111 
00112   // Add new scope
00113   if (newScopePending)
00114   {
00115 
00116     dev = new IDevice(labelEdit->text(), driverCombo->currentText(), versionEdit->text());
00117 
00118     dev->deviceType = KSTARS_TELESCOPE;
00119 
00120     focal_length = focalEdit->text().toDouble();
00121     aperture = apertureEdit->text().toDouble();
00122 
00123     if (focal_length > 0)
00124      dev->focal_length = focal_length;
00125     if (aperture > 0)
00126      dev->aperture = aperture;
00127 
00128     indi_driver->devices.push_back(dev);
00129 
00130     telescopeListBox->insertItem(labelEdit->text());
00131 
00132     telescopeListBox->setCurrentItem(telescopeListBox->count() - 1);
00133 
00134   }
00135   else
00136   {
00137     if (finalIndex == -1) return;
00138     indi_driver->devices[finalIndex]->label  = labelEdit->text();
00139     indi_driver->devices[finalIndex]->version = versionEdit->text();
00140     indi_driver->devices[finalIndex]->driver = driverCombo->currentText();
00141     
00142     
00143     focal_length = focalEdit->text().toDouble();
00144     aperture = apertureEdit->text().toDouble();
00145 
00146     if (focal_length > 0)
00147      indi_driver->devices[finalIndex]->focal_length = focal_length;
00148     if (aperture > 0)
00149      indi_driver->devices[finalIndex]->aperture = aperture;
00150   }
00151 
00152   indi_driver->saveDevicesToDisk();
00153 
00154   newScopePending = false;
00155 
00156   driverCombo->clearFocus();
00157   labelEdit->clearFocus();
00158   focalEdit->clearFocus();
00159   apertureEdit->clearFocus();
00160 
00161   KMessageBox::information(NULL, i18n("You need to restart KStars for changes to take effect."));
00162 
00163 }
00164 
00165 int telescopeProp::findDeviceIndex(int listIndex)
00166 {
00167   int finalIndex = -1;
00168 
00169   for (unsigned int i=0; i < indi_driver->devices.size(); i++)
00170   {
00171     if (indi_driver->devices[i]->label == telescopeListBox->text(listIndex))
00172     {
00173     finalIndex = i;
00174         break;
00175     }
00176    }
00177 
00178  return finalIndex;
00179 
00180 }
00181 
00182 void telescopeProp::updateScopeDetails(int index)
00183 {
00184 
00185   int finalIndex = -1;
00186   newScopePending = false;
00187   bool foundFlag(false);
00188  
00189   focalEdit->clear();
00190   apertureEdit->clear();
00191 
00192 
00193    finalIndex = findDeviceIndex(index);
00194    if (finalIndex == -1)
00195    {
00196       kdDebug() << "final index is invalid. internal error." << endl;
00197       return;
00198    }
00199 
00200   for (int i=0; i < driverCombo->count(); i++)
00201     if (indi_driver->devices[finalIndex]->driver == driverCombo->text(i))
00202      {
00203        driverCombo->setCurrentItem(i);
00204        foundFlag = true;
00205        break;
00206      }
00207 
00208   if (foundFlag == false)
00209     driverCombo->setCurrentText(indi_driver->devices[finalIndex]->driver);
00210 
00211   labelEdit->setText(indi_driver->devices[finalIndex]->label);
00212 
00213   versionEdit->setText(indi_driver->devices[finalIndex]->version);
00214 
00215   if (indi_driver->devices[finalIndex]->focal_length != -1)
00216     focalEdit->setText(QString("%1").arg(indi_driver->devices[finalIndex]->focal_length));
00217 
00218   if (indi_driver->devices[finalIndex]->aperture != -1)
00219         apertureEdit->setText(QString("%1").arg(indi_driver->devices[finalIndex]->aperture));
00220 
00221 }
00222 
00223 void telescopeProp::removeScope()
00224 {
00225 
00226   int index, finalIndex;
00227 
00228   index = telescopeListBox->currentItem();
00229   finalIndex = findDeviceIndex(index);
00230 
00231   if (KMessageBox::warningContinueCancel( 0, i18n("Are you sure you want to remove %1?").arg(indi_driver->devices[finalIndex]->label), i18n("Delete Confirmation"),KStdGuiItem::del())!=KMessageBox::Continue)
00232            return;
00233 
00234   telescopeListBox->removeItem(index);
00235 
00236   delete (indi_driver->devices[finalIndex]);
00237   indi_driver->devices.erase(indi_driver->devices.begin() + finalIndex);
00238   
00239   indi_driver->saveDevicesToDisk();
00240 
00241 }
00242 
00243 
00244 #include "telescopeprop.moc"
00245 

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