2 Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
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.
13 #include <qpushbutton.h>
14 #include <qwidgetstack.h>
18 #include <qtextedit.h>
19 #include <qradiobutton.h>
21 #include <klistview.h>
22 #include <klineedit.h>
23 #include <kmessagebox.h>
24 #include <kprogress.h>
26 #include "telescopewizardprocess.h"
29 #include "kstarsdata.h"
30 #include "timedialog.h"
32 #include "libkdeedu/extdate/extdatetime.h"
35 #include "indidriver.h"
36 #include "indielement.h"
37 #include "indiproperty.h"
39 #include "indidevice.h"
41 #define TIMEOUT_THRESHHOLD 20
43 telescopeWizardProcess::telescopeWizardProcess( QWidget
* parent
, const char* name
) : telescopeWizard(parent
, name
)
54 if (KSUtils::openDataFile(sideIMG
, "wizardside.png"))
55 wizardPix
->setPixmap(QPixmap(sideIMG
.name()));
58 currentPage
= INTRO_P
;
60 ksw
= (KStars
*) parent
;
64 indimenu
= ksw
->getINDIMenu();
65 indidriver
= ksw
->getINDIDriver();
67 INDIMessageBar
= Options::indiMessages();
68 Options::setIndiMessages( false );
70 QTime
newTime( ksw
->data()->lt().time() );
71 ExtDate
newDate( ksw
->data()->lt().date() );
73 timeOut
->setText( QString().sprintf("%02d:%02d:%02d", newTime
.hour(), newTime
.minute(), newTime
.second()));
74 dateOut
->setText( QString().sprintf("%d-%02d-%02d", newDate
.year(), newDate
.month(), newDate
.day()));
76 if (ksw
->geo()->translatedProvince().isEmpty())
77 locationOut
->setText( QString("%1, %2").arg(ksw
->geo()->translatedName()).arg(ksw
->geo()->translatedCountry()));
79 locationOut
->setText( QString("%1, %2, %3").arg(ksw
->geo()->translatedName())
80 .arg(ksw
->geo()->translatedProvince())
81 .arg(ksw
->geo()->translatedCountry()));
84 for (unsigned int i
=0; i
< indidriver
->devices
.size(); i
++)
85 if (indidriver
->devices
[i
]->deviceType
== KSTARS_TELESCOPE
)
86 telescopeCombo
->insertItem(indidriver
->devices
[i
]->label
);
88 if ( !Options::indiTelescopePort().isEmpty())
89 portList
<< Options::indiTelescopePort();
91 portList
<< "/dev/ttyS0" << "/dev/ttyS1" << "/dev/ttyS2" << "/dev/ttyS3" << "/dev/ttyS4"
92 << "/dev/ttyUSB0" << "/dev/ttyUSB1" << "/dev/ttyUSB2" << "/dev/ttyUSB3";// << "/dev/ttyUSB4";
94 connect(helpB
, SIGNAL(clicked()), parent
, SLOT(appHelpActivated()));
95 connect(nextB
, SIGNAL(clicked()), this, SLOT(processNext()));
96 connect(backB
, SIGNAL(clicked()), this, SLOT(processBack()));
97 connect(setTimeB
, SIGNAL(clicked()), this, SLOT(newTime()));
98 connect(setLocationB
, SIGNAL(clicked()), this, SLOT(newLocation()));
100 newDeviceTimer
= new QTimer(this);
101 QObject::connect( newDeviceTimer
, SIGNAL(timeout()), this, SLOT(processPort()) );
105 telescopeWizardProcess::~telescopeWizardProcess()
108 if (progressScan
->wasCancelled())
109 indidriver
->processDeviceStatus(1);
111 Options::setIndiMessages( INDIMessageBar
);
116 void telescopeWizardProcess::processNext(void)
125 wizardContainer
->raiseWidget(currentPage
);
129 wizardContainer
->raiseWidget(currentPage
);
133 wizardContainer
->raiseWidget(currentPage
);
137 wizardContainer
->raiseWidget(currentPage
);
140 linkResult
= establishLink();
141 if ( linkResult
== 1)
143 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);
144 progressScan
->setAllowCancel(true);
145 progressScan
->setAutoClose(true);
146 progressScan
->setAutoReset(true);
147 progressScan
->progressBar()->setTotalSteps(portList
.count());
148 progressScan
->progressBar()->setValue(0);
149 progressScan
->show();
151 else if (linkResult
== 2)
152 KMessageBox::queuedMessageBox(0, KMessageBox::Information
, i18n("Please wait while KStars tries to connect to your telescope..."));
153 else if (linkResult
== -1)
154 KMessageBox::error(0, i18n("Error. Unable to locate telescope drivers."));
162 void telescopeWizardProcess::processBack(void)
164 // for now, just display the next page, and restart once we reached the end
169 // we shouldn't be here!
175 wizardContainer
->raiseWidget(currentPage
);
179 wizardContainer
->raiseWidget(currentPage
);
183 wizardContainer
->raiseWidget(currentPage
);
187 wizardContainer
->raiseWidget(currentPage
);
195 void telescopeWizardProcess::newTime()
197 TimeDialog
timedialog (ksw
->data()->lt(), ksw
);
199 if ( timedialog
.exec() == QDialog::Accepted
)
201 KStarsDateTime
dt( timedialog
.selectedDate(), timedialog
.selectedTime() );
202 ksw
->data()->changeDateTime( dt
);
204 timeOut
->setText( QString().sprintf("%02d:%02d:%02d", dt
.time().hour(), dt
.time().minute(), dt
.time().second()));
205 dateOut
->setText( QString().sprintf("%d-%02d-%02d", dt
.date().year(), dt
.date().month(), dt
.date().day()));
209 void telescopeWizardProcess::newLocation()
212 ksw
->slotGeoLocator();
214 locationOut
->setText( QString("%1, %2, %3").arg(ksw
->geo()->translatedName())
215 .arg(ksw
->geo()->translatedProvince())
216 .arg(ksw
->geo()->translatedCountry()));
217 timeOut
->setText( QString().sprintf("%02d:%02d:%02d", ksw
->data()->lt().time().hour(), ksw
->data()->lt().time().minute(), ksw
->data()->lt().time().second()));
219 dateOut
->setText( QString().sprintf("%d-%02d-%02d", ksw
->data()->lt().date().year(),
220 ksw
->data()->lt().date().month() ,ksw
->data()->lt().date().day()));
226 int telescopeWizardProcess::establishLink()
229 if (!indidriver
|| !indimenu
)
232 QListViewItem
*driverItem
= NULL
;
233 driverItem
= indidriver
->localListView
->findItem(telescopeCombo
->currentText(), 0);
234 if (driverItem
== NULL
) return -1;
236 // If device is already running, we need to shut it down first
237 if (indidriver
->isDeviceRunning(telescopeCombo
->currentText()))
239 indidriver
->localListView
->setSelected(driverItem
, true);
240 indidriver
->processDeviceStatus(1);
243 // Set custome label for device
244 indimenu
->setCustomLabel(telescopeCombo
->currentText());
245 currentDevice
= indimenu
->currentLabel
;
247 indidriver
->localListView
->setSelected(driverItem
, true);
248 // Make sure we start is locally
249 indidriver
->localR
->setChecked(true);
251 indidriver
->processDeviceStatus(0);
253 if (!indidriver
->isDeviceRunning(telescopeCombo
->currentText()))
256 newDeviceTimer
->start(1500);
258 if (portIn
->text().isEmpty())
265 void telescopeWizardProcess::processPort()
270 if (!indidriver
|| !indimenu
)
275 if (timeOutCount
>= TIMEOUT_THRESHHOLD
)
277 indidriver
->processDeviceStatus(1);
279 KMessageBox::error(0, i18n("Error: connection timeout. Unable to communicate with an INDI server"));
284 indiDev
= indimenu
->findDeviceByLabel(currentDevice
);
285 if (!indiDev
) return;
287 // port empty, start autoscan
288 if (portIn
->text().isEmpty())
290 newDeviceTimer
->stop();
291 linkRejected
= false;
292 connect(indiDev
->stdDev
, SIGNAL(linkRejected()), this, SLOT(scanPorts()));
293 connect(indiDev
->stdDev
, SIGNAL(linkAccepted()), this, SLOT(linkSuccess()));
298 pp
= indiDev
->findProp("DEVICE_PORT");
300 lp
= pp
->findElement("PORT");
303 lp
->write_w
->setText(portIn
->text());
305 pp
= indiDev
->findProp("CONNECTION");
308 newDeviceTimer
->stop();
310 Options::setIndiMessages( INDIMessageBar
);
322 void telescopeWizardProcess::scanPorts()
327 if (!indiDev
|| !indidriver
|| !indimenu
|| linkRejected
)
332 progressScan
->progressBar()->setValue(currentPort
);
334 if ( (unsigned) currentPort
>= portList
.count())
336 KMessageBox::sorry(0, i18n("Sorry. KStars failed to detect any attached telescopes, please check your settings and try again."));
338 indidriver
->processDeviceStatus(1);
343 if (indiDev
->msgST_w
)
344 indiDev
->msgST_w
->clear();
346 pp
= indiDev
->findProp("DEVICE_PORT");
348 lp
= pp
->findElement("PORT");
350 lp
->write_w
->setText(portList
[currentPort
]);
353 pp
= indiDev
->findProp("CONNECTION");
360 void telescopeWizardProcess::linkSuccess()
370 void telescopeWizardProcess::Reset()
377 progressScan
->close();
383 #include "telescopewizardprocess.moc"