• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • indi
telescopewizardprocess.cpp
Go to the documentation of this file.
1 /* Telescope wizard
2  Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
3 
4  This application is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8  */
9 
10 #include "telescopewizardprocess.h"
11 
12 #include <QFile>
13 #include <QPixmap>
14 #include <QTimer>
15 
16 #include <KMessageBox>
17 #include <KProgressDialog>
18 #include <KDateTime>
19 #include <KStatusBar>
20 
21 #include "Options.h"
22 #include "kstars.h"
23 #include "kstarsdata.h"
24 #include "dialogs/timedialog.h"
25 #include "ksutils.h"
26 
27 #include "guimanager.h"
28 #include "indilistener.h"
29 #include "driverinfo.h"
30 #include "drivermanager.h"
31 #include "indielement.h"
32 #include "indiproperty.h"
33 #include "indistd.h"
34 #include "indidevice.h"
35 
36 #define TIMEOUT_THRESHOLD 20
37 
38 telescopeWizardProcess::telescopeWizardProcess( QWidget* parent, const char* /*name*/ ) : QDialog(parent)
39 {
40  currentPort = -1;
41  timeOutCount = 0;
42  progressScan = NULL;
43  linkRejected = false;
44  ui = new Ui::telescopeWizard();
45  ui->setupUi(this);
46 
47  QString locStr;
48  QFile sideIMG;
49 
50  if (KSUtils::openDataFile(sideIMG, "wzscope.png"))
51  ui->wizardPix->setPixmap(QPixmap(sideIMG.fileName()));
52 
53  ui->backB->hide();
54  currentPage = INTRO_P;
55 
56  INDIMessageBar = Options::showINDIMessages();
57  Options::setShowINDIMessages( false );
58 
59  QTime newTime( KStars::Instance()->data()->lt().time() );
60  QDate newDate( KStars::Instance()->data()->lt().date() );
61 
62  ui->timeOut->setText( QString().sprintf("%02d:%02d:%02d", newTime.hour(), newTime.minute(), newTime.second()));
63  ui->dateOut->setText( QString().sprintf("%d-%02d-%02d", newDate.year(), newDate.month(), newDate.day()));
64 
65  // FIXME is there a better way to check if a translated message is empty?
66  //if (KStars::Instance()->data()->geo()->translatedProvince().isEmpty())
67  if (KStars::Instance()->data()->geo()->translatedProvince() == QString("(I18N_EMPTY_MESSAGE)"))
68  ui->locationOut->setText( QString("%1, %2").arg(KStars::Instance()->data()->geo()->translatedName()).arg(KStars::Instance()->data()->geo()->translatedCountry()));
69  else
70  ui->locationOut->setText( QString("%1, %2, %3").arg(KStars::Instance()->data()->geo()->translatedName())
71  .arg(KStars::Instance()->data()->geo()->translatedProvince())
72  .arg(KStars::Instance()->data()->geo()->translatedCountry()));
73 
74 
75  foreach (DriverInfo *dv, DriverManager::Instance()->getDrivers())
76  {
77  if (dv->getType() == KSTARS_TELESCOPE)
78  {
79  ui->telescopeCombo->addItem(dv->getTreeLabel());
80  driversList[dv->getTreeLabel()] = dv;
81  }
82  }
83 
84  portList << "/dev/ttyS0" << "/dev/ttyS1" << "/dev/ttyS2" << "/dev/ttyS3" << "/dev/ttyS4"
85  << "/dev/ttyUSB0" << "/dev/ttyUSB1" << "/dev/ttyUSB2" << "/dev/ttyUSB3";
86 
87  connect(ui->helpB, SIGNAL(clicked()), parent, SLOT(appHelpActivated()));
88  connect(ui->cancelB, SIGNAL(clicked()), this, SLOT(cancelCheck()));
89  connect(ui->nextB, SIGNAL(clicked()), this, SLOT(processNext()));
90  connect(ui->backB, SIGNAL(clicked()), this, SLOT(processBack()));
91  connect(ui->setTimeB, SIGNAL(clicked()), this, SLOT(newTime()));
92  connect(ui->setLocationB, SIGNAL(clicked()), this, SLOT(newLocation()));
93 
94  //newDeviceTimer = new QTimer(this);
95  //QObject::connect( newDeviceTimer, SIGNAL(timeout()), this, SLOT(processPort()) );
96 
97 }
98 
99 telescopeWizardProcess::~telescopeWizardProcess()
100 {
101  Options::setShowINDIMessages( INDIMessageBar );
102  delete ui;
103  //Reset();
104 }
105 
106 //Called when cancel is clicked, gives a warning if past the first couple of steps
107 void telescopeWizardProcess::cancelCheck(void)
108 {
109  switch (currentPage)
110  {
111  case TELESCOPE_P:
112  case LOCAL_P:
113  case PORT_P:
114  if ( KMessageBox::warningYesNo(0, i18n("Are you sure you want to cancel?")) == KMessageBox::Yes )
115  emit reject();
116  break;
117  default:
118  emit reject();
119  break;
120  }
121 }
122 
123 void telescopeWizardProcess::processNext(void)
124 {
125 
126  switch (currentPage)
127  {
128  case INTRO_P:
129  currentPage++;
130  ui->backB->show();
131  ui->wizardContainer->setCurrentIndex(currentPage);
132  break;
133  case MODEL_P:
134  currentPage++;
135  ui->wizardContainer->setCurrentIndex(currentPage);
136  break;
137  case TELESCOPE_P:
138  currentPage++;
139  ui->wizardContainer->setCurrentIndex(currentPage);
140  break;
141  case LOCAL_P:
142  currentPage++;
143  ui->wizardContainer->setCurrentIndex(currentPage);
144  break;
145  case PORT_P:
146  establishLink();
147  break;
148  default:
149  break;
150  }
151 
152 }
153 
154 void telescopeWizardProcess::processBack(void)
155 {
156  // for now, just display the next page, and restart once we reached the end
157 
158  switch (currentPage)
159  {
160  case INTRO_P:
161  // we shouldn't be here!
162  break;
163  break;
164  case MODEL_P:
165  currentPage--;
166  ui->backB->hide();
167  ui->wizardContainer->setCurrentIndex(currentPage);
168  break;
169  case TELESCOPE_P:
170  currentPage--;
171  ui->wizardContainer->setCurrentIndex(currentPage);
172  break;
173  case LOCAL_P:
174  currentPage--;
175  ui->wizardContainer->setCurrentIndex(currentPage);
176  break;
177  case PORT_P:
178  currentPage--;
179  ui->wizardContainer->setCurrentIndex(currentPage);
180  break;
181  default:
182  break;
183  }
184 
185 }
186 
187 void telescopeWizardProcess::newTime()
188 {
189  TimeDialog timedialog (KStars::Instance()->data()->lt(), KStars::Instance()->data()->geo(), KStars::Instance());
190 
191  if ( timedialog.exec() == QDialog::Accepted )
192  {
193  KStarsDateTime dt( timedialog.selectedDate(), timedialog.selectedTime() );
194  KStars::Instance()->data()->changeDateTime( dt );
195 
196  ui->timeOut->setText( QString().sprintf("%02d:%02d:%02d", dt.time().hour(), dt.time().minute(), dt.time().second()));
197  ui->dateOut->setText( QString().sprintf("%d-%02d-%02d", dt.date().year(), dt.date().month(), dt.date().day()));
198  }
199 }
200 
201 void telescopeWizardProcess::newLocation()
202 {
203  KStars::Instance()->slotGeoLocator();
204  GeoLocation* geo = KStars::Instance()->data()->geo();
205  ui->locationOut->setText( QString("%1, %2, %3")
206  .arg( geo->translatedName() )
207  .arg( geo->translatedProvince() )
208  .arg( geo->translatedCountry()) );
209  ui->timeOut->setText( QString().sprintf("%02d:%02d:%02d",
210  KStars::Instance()->data()->lt().time().hour(),
211  KStars::Instance()->data()->lt().time().minute(),
212  KStars::Instance()->data()->lt().time().second()));
213  ui->dateOut->setText( QString().sprintf("%d-%02d-%02d",
214  KStars::Instance()->data()->lt().date().year(),
215  KStars::Instance()->data()->lt().date().month(),
216  KStars::Instance()->data()->lt().date().day()));
217 }
218 
219 void telescopeWizardProcess::establishLink()
220 {
221  managedDevice.clear();
222 
223  DriverInfo *dv = driversList.value(ui->telescopeCombo->currentText());
224 
225  if (dv == NULL)
226  return;
227 
228  managedDevice.append(dv);
229  connect(INDIListener::Instance(), SIGNAL(newDevice(ISD::GDInterface*)), this, SLOT(processTelescope(ISD::GDInterface*)));
230 
231  if (ui->portIn->text().isEmpty())
232  {
233  progressScan = new KProgressDialog(this, i18n("Telescope Wizard"),
234  i18n("Please wait while KStars scan communication ports for "
235  "attached telescopes.\nThis process might take few "
236  "minutes to complete."), Qt::Dialog);
237  progressScan->progressBar()->setValue(0);
238  //kDebug() << "KProgressDialog for automatic search has been initiated";
239 
240  }
241  else
242  {
243  progressScan = new KProgressDialog(this, i18n("Telescope Wizard"), i18n("Please wait while KStars tries to connect to your telescope..."), Qt::Dialog);
244  progressScan->progressBar()->setValue(portList.count());
245  //kDebug() << "KProgressDialog for manual search has been initiated";
246  }
247 
248  progressScan->setAutoClose(true);
249  progressScan->setAutoReset(true);
250  progressScan->progressBar()->setMinimum(0);
251  progressScan->progressBar()->setMaximum(portList.count());
252  progressScan->show();
253 
254  if (dv->getClientState() == false)
255  {
256  if (DriverManager::Instance()->startDevices(managedDevice) == false)
257  {
258  Reset();
259  close();
260  return;
261  }
262  }
263  else
264  processTelescope(INDIListener::Instance()->getDevice(dv->getName()));
265 
266 
267 }
268 
269 void telescopeWizardProcess::processTelescope(ISD::GDInterface *telescope)
270 {
271  if (telescope == NULL)
272  return;
273 
274  scopeDevice = telescope;
275 
276  // port empty, start autoscan
277  if (ui->portIn->text().isEmpty())
278  {
279  //newDeviceTimer->stop();
280  linkRejected = false;
281  connect(scopeDevice, SIGNAL(Connected()), this, SLOT(linkSuccess()), Qt::QueuedConnection);
282  connect(scopeDevice, SIGNAL(Disconnected()), this, SLOT(scanPorts()), Qt::QueuedConnection);
283  scanPorts();
284  }
285  else
286  {
287  QString scopePort = ui->portIn->text();
288 
289  scopeDevice->runCommand(INDI_SET_PORT, &scopePort);
290 
291  scopeDevice->runCommand(INDI_CONNECT);
292 
293  Options::setShowINDIMessages( INDIMessageBar );
294 
295  close();
296 
297  }
298 
299 
300 
301  /*
302  pp = indiDev->findProp("DEVICE_PORT");
303  if (!pp) return;
304  lp = pp->findElement("PORT");
305  if (!lp) return;
306 
307  lp->write_w->setText(ui->portIn->text());
308 
309  pp = indiDev->findProp("CONNECTION");
310  if (!pp) return;
311 
312  //newDeviceTimer->stop();
313  */
314 
315 
316 
317  /*lp = pp->findElement("CONNECT");
318  pp->newSwitch(lp);
319 
320  Reset();
321 
322  indimenu->show();*/
323 
324 
325 
326 }
327 
328 void telescopeWizardProcess::scanPorts()
329 {
330  if (progressScan == NULL)
331  {
332  close();
333  return;
334  }
335 
336  currentPort++;
337 
338  if (progressScan->wasCancelled())
339  {
340  if (linkRejected)
341  return;
342 
343  disconnect(this, SLOT(linkSuccess()));
344  disconnect(this, SLOT(scanPorts()));
345 
346  DriverManager::Instance()->stopDevices(managedDevice);
347  linkRejected = true;
348  Reset();
349  return;
350  }
351 
352  progressScan->progressBar()->setValue(currentPort);
353 
354  //qDebug() << "Current port is " << currentPort << " and port count is " << portList.count() << endl;
355 
356  if ( currentPort >= portList.count())
357  {
358  if (linkRejected)
359  return;
360 
361  disconnect(this, SLOT(scanPorts()));
362  disconnect(this, SLOT(linkSuccess()));
363  linkRejected = true;
364  DriverManager::Instance()->stopDevices(managedDevice);
365  Reset();
366 
367  KMessageBox::sorry(0, i18n("Sorry. KStars failed to detect any attached telescopes, please check your settings and try again."));
368  return;
369  }
370 
371  QString scopePort = portList[currentPort];
372  scopeDevice->runCommand(INDI_SET_PORT, &scopePort);
373 
374  scopeDevice->runCommand(INDI_CONNECT);
375 
376 }
377 
378 void telescopeWizardProcess::linkSuccess()
379 {
380  Reset();
381 
382  KStars::Instance()->statusBar()->changeItem( i18n("Telescope Wizard completed successfully."), 0);
383 
384  close();
385 
386  GUIManager::Instance()->show();
387 
388 }
389 
390 void telescopeWizardProcess::Reset()
391 {
392  currentPort = -1;
393  timeOutCount = 0;
394  linkRejected = false;
395 
396  delete (progressScan);
397  progressScan = NULL;
398 
399 }
400 
401 #include "telescopewizardprocess.moc"
telescopeWizardProcess::currentPage
unsigned int currentPage
Definition: telescopewizardprocess.h:35
indilistener.h
GeoLocation::translatedName
QString translatedName() const
Definition: geolocation.cpp:78
Options::setShowINDIMessages
static void setShowINDIMessages(bool v)
Set Display INDI messages in the statusbar?
Definition: Options.h:533
QDialog
ISD::GDInterface::runCommand
virtual bool runCommand(int command, void *ptr=NULL)=0
telescopeWizardProcess::TELESCOPE_P
Definition: telescopewizardprocess.h:36
INDIListener::Instance
static INDIListener * Instance()
Definition: indilistener.cpp:46
telescopeWizardProcess::~telescopeWizardProcess
~telescopeWizardProcess()
Definition: telescopewizardprocess.cpp:99
timedialog.h
telescopewizardprocess.h
QWidget
telescopeWizardProcess::processNext
void processNext()
Definition: telescopewizardprocess.cpp:123
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
Options::showINDIMessages
static bool showINDIMessages()
Get Display INDI messages in the statusbar?
Definition: Options.h:543
indidevice.h
TimeDialog::selectedDate
QDate selectedDate(void)
Definition: timedialog.cpp:103
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
INDI_SET_PORT
Definition: indicommon.h:72
telescopeWizardProcess::INTRO_P
Definition: telescopewizardprocess.h:36
guimanager.h
telescopeWizardProcess::linkSuccess
void linkSuccess()
Definition: telescopewizardprocess.cpp:378
INDI_CONNECT
Definition: indicommon.h:72
KSUtils::openDataFile
bool openDataFile(QFile &file, const QString &filename)
Attempt to open the data file named filename, using the QFile object "file".
TimeDialog::selectedTime
QTime selectedTime(void)
Definition: timedialog.cpp:99
TimeDialog
A class for adjusting the Time and Date.
Definition: timedialog.h:47
GeoLocation::translatedProvince
QString translatedProvince() const
Definition: geolocation.cpp:88
driverinfo.h
telescopeWizardProcess::MODEL_P
Definition: telescopewizardprocess.h:36
telescopeWizardProcess::LOCAL_P
Definition: telescopewizardprocess.h:36
telescopeWizardProcess::cancelCheck
void cancelCheck()
Definition: telescopewizardprocess.cpp:107
telescopeWizardProcess::PORT_P
Definition: telescopewizardprocess.h:36
KStarsData::changeDateTime
void changeDateTime(const KStarsDateTime &newDate)
change the current simulation date/time to the KStarsDateTime argument.
Definition: kstarsdata.cpp:272
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
telescopeWizardProcess::processTelescope
void processTelescope(ISD::GDInterface *)
Definition: telescopewizardprocess.cpp:269
KStars::slotGeoLocator
void slotGeoLocator()
action slot: open dialog for selecting a new geographic location
Definition: kstarsactions.cpp:461
telescopeWizardProcess::processBack
void processBack()
Definition: telescopewizardprocess.cpp:154
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
telescopeWizardProcess::scanPorts
void scanPorts()
Definition: telescopewizardprocess.cpp:328
DriverInfo::getTreeLabel
const QString & getTreeLabel()
Definition: driverinfo.h:40
DriverInfo
Definition: driverinfo.h:24
telescopeWizardProcess::telescopeWizardProcess
telescopeWizardProcess(QWidget *parent=0, const char *name=0)
Definition: telescopewizardprocess.cpp:38
DriverInfo::getClientState
bool getClientState()
Definition: driverinfo.h:73
Options.h
GUIManager::Instance
static GUIManager * Instance()
Definition: guimanager.cpp:47
DriverInfo::getType
DeviceFamily getType()
Definition: driverinfo.h:52
DriverInfo::getName
const QString & getName()
Definition: driverinfo.h:36
telescopeWizardProcess::newTime
void newTime()
Definition: telescopewizardprocess.cpp:187
indistd.h
KStars::data
KStarsData * data() const
Definition: kstars.h:131
kstarsdata.h
indiproperty.h
KSTARS_TELESCOPE
Definition: indicommon.h:66
ksutils.h
GeoLocation::translatedCountry
QString translatedCountry() const
Definition: geolocation.cpp:92
telescopeWizardProcess::newLocation
void newLocation()
Definition: telescopewizardprocess.cpp:201
kstars.h
ISD::GDInterface
Definition: indistd.h:48
indielement.h
drivermanager.h
DriverManager::Instance
static DriverManager * Instance()
Definition: drivermanager.cpp:91
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal