moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / kstarsdcop.cpp
blob7e929ed37333c3d14e79c37d9b4683dba2c9440d
1 /***************************************************************************
2 kstarsdcop.cpp - description
3 -------------------
4 begin : Son Apr 7 2002
5 copyright : (C) 2002 by Thomas Kabelmann
6 email : tk78@gmx.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 //KStars DCOP functions
20 #include <qdir.h>
21 #include <qlistview.h>
22 #include <qradiobutton.h>
24 #include <kio/netaccess.h>
25 #include <kmessagebox.h>
26 #include <kprinter.h>
27 #include <kshortcut.h>
28 #include <ktempfile.h>
29 #include <kurl.h>
30 #include <klistview.h>
31 #include <kpushbutton.h>
32 #include <klineedit.h>
33 #include <knuminput.h>
35 #include "kstars.h"
36 #include "kstarsdata.h"
37 #include "skymap.h"
38 #include "skyobject.h"
39 #include "infoboxes.h"
40 #include "simclock.h"
41 #include "Options.h"
43 // INDI includes
44 #include "indidriver.h"
45 #include "indimenu.h"
46 #include "indielement.h"
47 #include "indidevice.h"
48 #include "indiproperty.h"
49 #include "devicemanager.h"
51 void KStars::setRaDec( double ra, double dec ) {
52 map()->setDestination( new SkyPoint( ra, dec ) );
55 void KStars::setAltAz( double alt, double az ) {
56 map()->setDestinationAltAz(alt,az);
59 void KStars::lookTowards ( const QString direction ) {
60 QString dir = direction.lower();
61 if (dir == "zenith" || dir=="z") map()->invokeKey( KKey( "Z" ).keyCodeQt() );
62 else if (dir == "north" || dir=="n") map()->invokeKey( KKey( "N" ).keyCodeQt() );
63 else if (dir == "east" || dir=="e") map()->invokeKey( KKey( "E" ).keyCodeQt() );
64 else if (dir == "south" || dir=="s") map()->invokeKey( KKey( "S" ).keyCodeQt() );
65 else if (dir == "west" || dir=="w") map()->invokeKey( KKey( "W" ).keyCodeQt() );
66 else if (dir == "northeast" || dir=="ne") {
67 map()->stopTracking();
68 map()->clickedPoint()->setAlt( 15.0 ); map()->clickedPoint()->setAz( 45.0 );
69 map()->clickedPoint()->HorizontalToEquatorial( LST(), geo()->lat() );
70 map()->slotCenter();
71 } else if (dir == "southeast" || dir=="se") {
72 map()->stopTracking();
73 map()->clickedPoint()->setAlt( 15.0 ); map()->clickedPoint()->setAz( 135.0 );
74 map()->clickedPoint()->HorizontalToEquatorial( LST(), geo()->lat() );
75 map()->slotCenter();
76 } else if (dir == "southwest" || dir=="sw") {
77 map()->stopTracking();
78 map()->clickedPoint()->setAlt( 15.0 ); map()->clickedPoint()->setAz( 225.0 );
79 map()->clickedPoint()->HorizontalToEquatorial( LST(), geo()->lat() );
80 map()->slotCenter();
81 } else if (dir == "northwest" || dir=="nw") {
82 map()->stopTracking();
83 map()->clickedPoint()->setAlt( 15.0 ); map()->clickedPoint()->setAz( 315.0 );
84 map()->clickedPoint()->HorizontalToEquatorial( LST(), geo()->lat() );
85 map()->slotCenter();
86 } else {
87 SkyObject *target = data()->objectNamed( direction );
88 if ( target != NULL ) {
89 map()->setClickedObject( target );
90 map()->setClickedPoint( target );
91 map()->slotCenter();
96 void KStars::zoom( double z ) {
97 if ( z > MAXZOOM ) z = MAXZOOM;
98 if ( z < MINZOOM ) z = MINZOOM;
99 Options::setZoomFactor( z );
100 map()->forceUpdate();
103 void KStars::setLocalTime(int yr, int mth, int day, int hr, int min, int sec) {
104 data()->changeDateTime( KStarsDateTime( ExtDate(yr, mth, day), QTime(hr,min,sec) ) );
107 void KStars::waitFor( double t ) {
108 kapp->dcopClient()->suspend();
109 QTimer::singleShot( int( 1000.*t ), this, SLOT( resumeDCOP() ) );
112 void KStars::waitForKey( const QString k ) {
113 data()->resumeKey = KKey( k );
114 if ( ! data()->resumeKey.isNull() ) {
115 kapp->dcopClient()->suspend();
116 } else {
117 kdDebug() << i18n( "Error [DCOP waitForKey()]: Invalid key requested." ) << endl;
121 void KStars::setTracking( bool track ) {
122 if ( track != Options::isTracking() ) slotTrack();
125 void KStars::popupMessage( int /*x*/, int /*y*/, QString /*message*/ ){
126 //Show a small popup window at (x,y) with a text message
129 void KStars::drawLine( int /*x1*/, int /*y1*/, int /*x2*/, int /*y2*/, int /*speed*/ ) {
130 //Draw a line on the skymap display
133 void KStars::setGeoLocation( QString city, QString province, QString country ) {
134 //Set the geographic location
135 bool cityFound( false );
137 for (GeoLocation *loc = data()->geoList.first(); loc; loc = data()->geoList.next()) {
138 if ( loc->translatedName() == city &&
139 ( province.isEmpty() || loc->translatedProvince() == province ) &&
140 loc->translatedCountry() == country ) {
142 cityFound = true;
144 data()->setLocation( *loc );
146 //notify on-screen GeoBox
147 infoBoxes()->geoChanged( loc );
149 //configure time zone rule
150 KStarsDateTime ltime = loc->UTtoLT( data()->ut() );
151 loc->tzrule()->reset_with_ltime( ltime, loc->TZ0(), data()->isTimeRunningForward() );
152 data()->setNextDSTChange( loc->tzrule()->nextDSTChange() );
154 //reset LST
155 data()->syncLST();
157 //make sure planets, etc. are updated immediately
158 data()->setFullTimeUpdate();
160 // If the sky is in Horizontal mode and not tracking, reset focus such that
161 // Alt/Az remain constant.
162 if ( ! Options::isTracking() && Options::useAltAz() ) {
163 map()->focus()->HorizontalToEquatorial( LST(), geo()->lat() );
166 // recalculate new times and objects
167 data()->setSnapNextFocus();
168 updateTime();
170 //no need to keep looking, we're done.
171 break;
175 if ( !cityFound ) {
176 if ( province.isEmpty() )
177 kdDebug() << i18n( "Error [DCOP setGeoLocation]: city " ) << city << ", "
178 << country << i18n( " not found in database." ) << endl;
179 else
180 kdDebug() << i18n( "Error [DCOP setGeoLocation]: city " ) << city << ", "
181 << province << ", " << country << i18n( " not found in database." ) << endl;
185 void KStars::changeViewOption( const QString op, const QString val ) {
186 bool bOk(false), nOk(false), dOk(false);
188 //parse bool value
189 bool bVal(false);
190 if ( val.lower() == "true" ) { bOk = true; bVal = true; }
191 if ( val.lower() == "false" ) { bOk = true; bVal = false; }
192 if ( val == "1" ) { bOk = true; bVal = true; }
193 if ( val == "0" ) { bOk = true; bVal = false; }
195 //parse int value
196 int nVal = val.toInt( &nOk );
198 //parse double value
199 double dVal = val.toDouble( &dOk );
201 //[GUI]
202 if ( op == "ShowInfoBoxes" && bOk ) Options::setShowInfoBoxes( bVal );
203 if ( op == "ShowTimeBox" && bOk ) Options::setShowTimeBox( bVal );
204 if ( op == "ShowGeoBox" && bOk ) Options::setShowGeoBox( bVal );
205 if ( op == "ShowFocusBox" && bOk ) Options::setShowFocusBox( bVal );
206 if ( op == "ShadeTimeBox" && bOk ) Options::setShadeTimeBox( bVal );
207 if ( op == "ShadeGeoBox" && bOk ) Options::setShadeGeoBox( bVal );
208 if ( op == "ShadeFocusBox" && bOk ) Options::setShadeFocusBox( bVal );
209 if ( op == "ShowMainToolBar" && bOk ) Options::setShowMainToolBar( bVal );
210 if ( op == "ShowViewToolBar" && bOk ) Options::setShowViewToolBar( bVal );
212 //[View]
213 if ( op == "FOVName" ) Options::setFOVName( val );
214 if ( op == "FOVSize" && dOk ) Options::setFOVSize( (float)dVal );
215 if ( op == "FOVShape" && nOk ) Options::setFOVShape( nVal );
216 if ( op == "FOVColor" ) Options::setFOVColor( val );
217 if ( op == "ShowStars" && bOk ) Options::setShowStars( bVal );
218 if ( op == "ShowMessier" && bOk ) Options::setShowMessier( bVal );
219 if ( op == "ShowMessierImages" && bOk ) Options::setShowMessierImages( bVal );
220 if ( op == "ShowNGC" && bOk ) Options::setShowNGC( bVal );
221 if ( op == "ShowIC" && bOk ) Options::setShowIC( bVal );
222 if ( op == "ShowCLines" && bOk ) Options::setShowCLines( bVal );
223 if ( op == "ShowCBounds" && bOk ) Options::setShowCBounds( bVal );
224 if ( op == "ShowCNames" && bOk ) Options::setShowCNames( bVal );
225 if ( op == "ShowMilkyWay" && bOk ) Options::setShowMilkyWay( bVal );
226 if ( op == "ShowGrid" && bOk ) Options::setShowGrid( bVal );
227 if ( op == "ShowEquator" && bOk ) Options::setShowEquator( bVal );
228 if ( op == "ShowEcliptic" && bOk ) Options::setShowEcliptic( bVal );
229 if ( op == "ShowHorizon" && bOk ) Options::setShowHorizon( bVal );
230 if ( op == "ShowGround" && bOk ) Options::setShowGround( bVal );
231 if ( op == "ShowSun" && bOk ) Options::setShowSun( bVal );
232 if ( op == "ShowMoon" && bOk ) Options::setShowMoon( bVal );
233 if ( op == "ShowMercury" && bOk ) Options::setShowMercury( bVal );
234 if ( op == "ShowVenus" && bOk ) Options::setShowVenus( bVal );
235 if ( op == "ShowMars" && bOk ) Options::setShowMars( bVal );
236 if ( op == "ShowJupiter" && bOk ) Options::setShowJupiter( bVal );
237 if ( op == "ShowSaturn" && bOk ) Options::setShowSaturn( bVal );
238 if ( op == "ShowUranus" && bOk ) Options::setShowUranus( bVal );
239 if ( op == "ShowNeptune" && bOk ) Options::setShowNeptune( bVal );
240 if ( op == "ShowPluto" && bOk ) Options::setShowPluto( bVal );
241 if ( op == "ShowAsteroids" && bOk ) Options::setShowAsteroids( bVal );
242 if ( op == "ShowComets" && bOk ) Options::setShowComets( bVal );
243 if ( op == "ShowPlanets" && bOk ) Options::setShowPlanets( bVal );
244 if ( op == "ShowDeepSky" && bOk ) Options::setShowDeepSky( bVal );
245 if ( op == "ShowStarNames" && bOk ) Options::setShowStarNames( bVal );
246 if ( op == "ShowStarMagnitudes" && bOk ) Options::setShowStarMagnitudes( bVal );
247 if ( op == "ShowAsteroidNames" && bOk ) Options::setShowAsteroidNames( bVal );
248 if ( op == "ShowCometNames" && bOk ) Options::setShowCometNames( bVal );
249 if ( op == "ShowPlanetNames" && bOk ) Options::setShowPlanetNames( bVal );
250 if ( op == "ShowPlanetImages" && bOk ) Options::setShowPlanetImages( bVal );
251 if ( op == "HideOnSlew" && bOk ) Options::setHideOnSlew( bVal );
252 if ( op == "HideStars" && bOk ) Options::setHideStars( bVal );
253 if ( op == "HidePlanets" && bOk ) Options::setHidePlanets( bVal );
254 if ( op == "HideMessier" && bOk ) Options::setHideMessier( bVal );
255 if ( op == "HideNGC" && bOk ) Options::setHideNGC( bVal );
256 if ( op == "HideIC" && bOk ) Options::setHideIC( bVal );
257 if ( op == "HideMilkyWay" && bOk ) Options::setHideMilkyWay( bVal );
258 if ( op == "HideCNames" && bOk ) Options::setHideCNames( bVal );
259 if ( op == "HideCLines" && bOk ) Options::setHideCLines( bVal );
260 if ( op == "HideCBounds" && bOk ) Options::setHideCBounds( bVal );
261 if ( op == "HideGrid" && bOk ) Options::setHideGrid( bVal );
263 if ( op == "UseAltAz" && bOk ) Options::setUseAltAz( bVal );
264 if ( op == "UseRefraction" && bOk ) Options::setUseRefraction( bVal );
265 if ( op == "UseAutoLabel" && bOk ) Options::setUseAutoLabel( bVal );
266 if ( op == "UseHoverLabel" && bOk ) Options::setUseHoverLabel( bVal );
267 if ( op == "UseAutoTrail" && bOk ) Options::setUseAutoTrail( bVal );
268 if ( op == "UseAnimatedSlewing" && bOk ) Options::setUseAnimatedSlewing( bVal );
269 if ( op == "FadePlanetTrails" && bOk ) Options::setFadePlanetTrails( bVal );
270 if ( op == "SlewTimeScale" && dOk ) Options::setSlewTimeScale( dVal );
271 if ( op == "ZoomFactor" && dOk ) Options::setZoomFactor( dVal );
272 if ( op == "MagLimitDrawStar" && dOk ) Options::setMagLimitDrawStar( dVal );
273 if ( op == "MagLimitDrawDeepSky" && dOk ) Options::setMagLimitDrawDeepSky( dVal );
274 if ( op == "MagLimitDrawStarZoomOut" && dOk ) Options::setMagLimitDrawStarZoomOut( dVal );
275 if ( op == "MagLimitDrawDeepSkyZoomOut" && dOk ) Options::setMagLimitDrawDeepSkyZoomOut( dVal );
276 if ( op == "MagLimitDrawStarInfo" && dOk ) Options::setMagLimitDrawStarInfo( dVal );
277 if ( op == "MagLimitHideStar" && dOk ) Options::setMagLimitHideStar( dVal );
278 if ( op == "MagLimitAsteroid" && dOk ) Options::setMagLimitAsteroid( dVal );
279 if ( op == "MagLimitAsteroidName" && dOk ) Options::setMagLimitAsteroidName( dVal );
280 if ( op == "MaxRadCometName" && dOk ) Options::setMaxRadCometName( dVal );
282 //these three are a "radio group"
283 if ( op == "UseLatinConstellationNames" && bOk ) {
284 Options::setUseLatinConstellNames( true );
285 Options::setUseLocalConstellNames( false );
286 Options::setUseAbbrevConstellNames( false );
288 if ( op == "UseLocalConstellationNames" && bOk ) {
289 Options::setUseLatinConstellNames( false );
290 Options::setUseLocalConstellNames( true );
291 Options::setUseAbbrevConstellNames( false );
293 if ( op == "UseAbbrevConstellationNames" && bOk ) {
294 Options::setUseLatinConstellNames( false );
295 Options::setUseLocalConstellNames( false );
296 Options::setUseAbbrevConstellNames( true );
299 map()->forceUpdate();
302 void KStars::setColor( const QString name, const QString value ) {
303 ColorScheme *cs = data()->colorScheme();
304 if ( cs->hasColorNamed( name ) ) {
305 cs->setColor( name, value );
306 map()->forceUpdate();
310 void KStars::loadColorScheme( const QString _name ) {
311 QString name( _name );
312 QString filename = name.lower().stripWhiteSpace();
313 bool ok( false );
315 //Parse default names which don't follow the regular file-naming scheme
316 if ( name == i18n("use default color scheme", "Default Colors") ) filename = "default.colors";
317 if ( name == i18n("use 'star chart' color scheme", "Star Chart") ) filename = "chart.colors";
318 if ( name == i18n("use 'night vision' color scheme", "Night Vision") ) filename = "night.colors";
320 //Try the filename if it ends with ".colors"
321 if ( filename.endsWith( ".colors" ) )
322 ok = data()->colorScheme()->load( filename );
324 //If that didn't work, try assuming that 'name' is the color scheme name
325 //convert it to a filename exactly as ColorScheme::save() does
326 if ( ! ok ) {
327 if ( !filename.isEmpty() ) {
328 for( unsigned int i=0; i<filename.length(); ++i)
329 if ( filename.at(i)==' ' ) filename.replace( i, 1, "-" );
331 filename = filename.append( ".colors" );
332 ok = data()->colorScheme()->load( filename );
335 if ( ! ok ) kdDebug() << i18n( "Unable to load color scheme named %1. Also tried %2." ).arg( name ).arg( filename );
338 if ( ok ) {
339 map()->setStarColorMode( data()->colorScheme()->starColorMode() );
340 map()->setStarColorIntensity( data()->colorScheme()->starColorIntensity() );
342 //set the application colors for the Night Vision scheme
343 if ( Options::darkAppColors() == false && filename == "night.colors" ) {
344 Options::setDarkAppColors( true );
345 OriginalPalette = QApplication::palette();
346 QApplication::setPalette( DarkPalette, true );
349 if ( Options::darkAppColors() && filename != "night.colors" ) {
350 Options::setDarkAppColors( false );
351 QApplication::setPalette( OriginalPalette, true );
354 map()->forceUpdate();
358 void KStars::exportImage( const QString url, int w, int h ) {
359 //If the filename string contains no "/" separators, assume the
360 //user wanted to place a file in their home directory.
361 KURL fileURL;
362 if ( ! url.contains( "/" ) ) fileURL = QDir::homeDirPath() + "/" + url;
363 else fileURL = url;
365 KTempFile tmpfile;
366 QString fname;
367 tmpfile.setAutoDelete(true);
369 QPixmap skyimage( map()->width(), map()->height() );
370 QPixmap outimage( w, h );
371 outimage.fill();
373 if ( fileURL.isValid() ) {
374 if ( fileURL.isLocalFile() ) {
375 fname = fileURL.path();
376 } else {
377 fname = tmpfile.name();
380 //Determine desired image format from filename extension
381 QString ext = fname.mid( fname.findRev(".")+1 );
382 const char* format = "PNG";
383 if ( ext.lower() == "png" ) { format = "PNG"; }
384 else if ( ext.lower() == "jpg" || ext.lower() == "jpeg" ) { format = "JPG"; }
385 else if ( ext.lower() == "gif" ) { format = "GIF"; }
386 else if ( ext.lower() == "pnm" ) { format = "PNM"; }
387 else if ( ext.lower() == "bmp" ) { format = "BMP"; }
388 else { kdWarning() << i18n( "Could not parse image format of %1; assuming PNG." ).arg( fname ) << endl; }
390 map()->exportSkyImage( &skyimage );
391 kapp->processEvents(10000);
393 //skyImage is the size of the sky map. The requested image size is w x h.
394 //If w x h is smaller than the skymap, then we simply crop the image.
395 //If w x h is larger than the skymap, pad the skymap image with a white border.
396 if ( w == map()->width() && h == map()->height() ) {
397 outimage = skyimage;
398 } else {
399 int dx(0), dy(0), sx(0), sy(0);
400 int sw(map()->width()), sh(map()->height());
401 if ( w > map()->width() ) {
402 dx = (w - map()->width())/2;
403 } else {
404 sx = (map()->width() - w)/2;
405 sw = w;
407 if ( h > map()->height() ) {
408 dy = (h - map()->height())/2;
409 } else {
410 sy = (map()->height() - h)/2;
411 sh = h;
414 bitBlt( &outimage, dx, dy, &skyimage, sx, sy, sw, sh );
417 if ( ! outimage.save( fname, format ) ) kdDebug() << i18n( "Error: Unable to save image: %1 " ).arg( fname ) << endl;
418 else kdDebug() << i18n( "Image saved to file: %1" ).arg( fname ) << endl;
420 if ( tmpfile.name() == fname ) { //attempt to upload image to remote location
421 if ( ! KIO::NetAccess::upload( tmpfile.name(), fileURL, this ) ) {
422 QString message = i18n( "Could not upload image to remote location: %1" ).arg( fileURL.prettyURL() );
423 KMessageBox::sorry( 0, message, i18n( "Could not upload file" ) );
429 void KStars::printImage( bool usePrintDialog, bool useChartColors ) {
430 KPrinter printer( true, QPrinter::HighResolution );
431 printer.setFullPage( false );
433 //Set up the printer (either with the Print Dialog,
434 //or using the default settings)
435 bool ok( false );
436 if ( usePrintDialog )
437 ok = printer.setup( this, i18n("Print Sky") );
438 else
439 ok = printer.autoConfigure();
441 if( ok ) {
442 kapp->setOverrideCursor( waitCursor );
444 //Save current colorscheme and switch to Star Chart colors
445 //(if requested)
446 ColorScheme cs;
447 if ( useChartColors ) {
448 cs.copy( * data()->colorScheme() );
449 loadColorScheme( "chart.colors" );
452 map()->setMapGeometry();
453 map()->exportSkyImage( &printer );
455 //Restore old color scheme if necessary
456 //(if printing was aborted, the colorscheme is still restored)
457 if ( useChartColors ) {
458 data()->colorScheme()->copy( cs );
460 // restore colormode and colorintensity in skymap
461 map()->setStarColorMode( cs.starColorMode() );
462 map()->setStarColorIntensity( cs.starColorIntensity() );
463 map()->forceUpdate();
466 kapp->restoreOverrideCursor();
470 void KStars::startINDI (QString deviceName, bool useLocal)
473 establishINDI();
475 if (!indidriver || !indimenu)
477 kdDebug() << "establishINDI() failed." << endl;
478 return;
481 QListViewItem *driverItem = NULL;
482 driverItem = indidriver->localListView->findItem(deviceName, 0);
483 if (driverItem == NULL)
485 kdDebug() << "Device " << deviceName << " not found!" << endl;
486 return;
489 // If device is already running, we need to shut it down first
490 if (indidriver->isDeviceRunning(deviceName))
492 indidriver->localListView->setSelected(driverItem, true);
493 indidriver->processDeviceStatus(1);
496 // Set custome label for device
497 indimenu->setCustomLabel(deviceName);
498 // Select it
499 indidriver->localListView->setSelected(driverItem, true);
501 // Start it either locally or as series
502 if (useLocal)
503 indidriver->localR->setChecked(true);
504 else
505 indidriver->serverR->setChecked(true);
507 // Run it
508 indidriver->processDeviceStatus(0);
512 void KStars::shutdownINDI (QString deviceName)
514 if (!indidriver || !indimenu)
516 kdDebug() << "establishINDI() failed." << endl;
517 return;
520 QListViewItem *driverItem = NULL;
521 driverItem = indidriver->localListView->findItem(deviceName, 0);
522 if (driverItem == NULL)
524 kdDebug() << "Device " << deviceName << " not found!" << endl;
525 return;
528 indidriver->processDeviceStatus(1);
533 void KStars::switchINDI(QString deviceName, bool turnOn)
535 INDI_D *dev;
536 INDI_P *prop;
538 if (!indidriver || !indimenu)
540 kdDebug() << "switchINDI: establishINDI() failed." << endl;
541 return;
544 dev = indimenu->findDevice(deviceName);
545 if (!dev)
546 dev = indimenu->findDeviceByLabel(deviceName);
547 if (!dev)
549 kdDebug() << "Device " << deviceName << " not found!" << endl;
550 return;
553 if (turnOn && dev->isOn() || (!turnOn && !dev->isOn()))
554 return;
556 prop = dev->findProp("CONNECTION");
557 if (!prop) return;
559 if (turnOn)
560 prop->newSwitch(0);
561 else
562 prop->newSwitch(1);
567 void KStars::setINDIPort(QString deviceName, QString port)
569 INDI_D *dev;
570 INDI_P *prop;
571 INDI_E *el;
573 if (!indidriver || !indimenu)
575 kdDebug() << "setINDIPort: establishINDI() failed." << endl;
576 return;
579 dev = indimenu->findDevice(deviceName);
580 if (!dev)
581 dev = indimenu->findDeviceByLabel(deviceName);
582 if (!dev)
584 kdDebug() << "Device " << deviceName << " not found!" << endl;
585 return;
588 prop = dev->findProp("DEVICE_PORT");
589 if (!prop) return;
591 el = prop->findElement("PORT");
593 if (!el->write_w)
594 return;
596 el->write_w->setText(port);
598 prop->newText();
603 void KStars::setINDITargetCoord(QString deviceName, double RA, double DEC)
605 INDI_D *dev;
606 INDI_P *prop;
607 INDI_E *el;
609 if (!indidriver || !indimenu)
611 kdDebug() << "setINDITarget: establishINDI() failed." << endl;
612 return;
615 dev = indimenu->findDevice(deviceName);
616 if (!dev)
617 dev = indimenu->findDeviceByLabel(deviceName);
618 if (!dev)
620 kdDebug() << "Device " << deviceName << " not found!" << endl;
621 return;
624 prop = dev->findProp("EQUATORIAL_EOD_COORD");
625 if (!prop) return;
627 el = prop->findElement("RA");
628 if (!el) return;
629 if (!el->write_w) return;
631 el->write_w->setText(QString("%1").arg(RA));
633 el = prop->findElement("DEC");
634 if (!el) return;
635 if (!el->write_w) return;
637 el->write_w->setText(QString("%1").arg(DEC));
639 prop->newText();
644 void KStars::setINDITargetName(QString deviceName, QString objectName)
646 INDI_D *dev;
647 INDI_P *prop;
648 INDI_E *el;
650 if (!indidriver || !indimenu)
652 kdDebug() << "setINDITarget: establishINDI() failed." << endl;
653 return;
656 SkyObject *target = data()->objectNamed( objectName );
657 if (!target) return;
659 dev = indimenu->findDevice(deviceName);
660 if (!dev)
661 dev = indimenu->findDeviceByLabel(deviceName);
662 if (!dev)
664 kdDebug() << "Device " << deviceName << " not found!" << endl;
665 return;
668 prop = dev->findProp("EQUATORIAL_EOD_COORD");
669 if (!prop) return;
671 el = prop->findElement("RA");
672 if (!el) return;
673 if (!el->write_w) return;
675 el->write_w->setText(QString("%1").arg(target->ra()->Hours()));
677 el = prop->findElement("DEC");
678 if (!el) return;
679 if (!el->write_w) return;
681 el->write_w->setText(QString("%1").arg(target->dec()->Degrees()));
683 prop->newText();
688 void KStars::setINDIAction(QString deviceName, QString action)
690 INDI_D *dev;
691 INDI_E *el;
693 if (!indidriver || !indimenu)
695 kdDebug() << "setINDIAction: establishINDI() failed." << endl;
696 return;
699 dev = indimenu->findDevice(deviceName);
700 if (!dev)
701 dev = indimenu->findDeviceByLabel(deviceName);
702 if (!dev)
704 kdDebug() << "Device " << deviceName << " not found!" << endl;
705 return;
708 el = dev->findElem(action);
709 if (!el) return;
711 el->pp->activateSwitch(action);
716 void KStars::waitForINDIAction(QString deviceName, QString action)
719 INDI_D *dev;
720 INDI_P *prop;
721 INDI_E *el;
723 if (!indidriver || !indimenu)
725 kdDebug() << "waitForINDIAction: establishINDI() failed." << endl;
726 return;
729 dev = indimenu->findDevice(deviceName);
730 if (!dev)
731 dev = indimenu->findDeviceByLabel(deviceName);
732 if (!dev)
734 kdDebug() << "Device " << deviceName << " not found!" << endl;
735 return;
738 prop = dev->findProp(action);
740 if (prop == NULL)
742 el = dev->findElem(action);
743 if (!el) return;
745 QObject::connect(el->pp, SIGNAL(okState()), this, SLOT(resumeDCOP(void )));
747 else
748 QObject::connect(prop, SIGNAL(okState()), this, SLOT(resumeDCOP(void )));
750 kapp->dcopClient()->suspend();
755 void KStars::setINDIFocusSpeed(QString deviceName, QString action)
757 if (!indidriver || !indimenu)
759 kdDebug() << "setINDIFocusSpeed: establishINDI() failed." << endl;
760 return;
763 setINDIAction(deviceName, action);
768 void KStars::startINDIFocus(QString deviceName, int focusDir)
770 if (!indidriver || !indimenu)
772 kdDebug() << "setINDIFocusSpeed: establishINDI() failed!" << endl;
773 return;
776 if (focusDir == 0)
777 setINDIAction(deviceName, "FOCUS_IN");
778 else if (focusDir == 1)
779 setINDIAction(deviceName, "FOCUS_OUT");
784 void KStars::setINDIGeoLocation(QString deviceName, double longitude, double latitude)
787 INDI_D *dev;
788 INDI_P *prop;
789 INDI_E *el;
791 if (!indidriver || !indimenu)
793 kdDebug() << "setINDIGeoLocation: establishINDI() failed." << endl;
794 return;
797 dev = indimenu->findDevice(deviceName);
798 if (!dev)
799 dev = indimenu->findDeviceByLabel(deviceName);
800 if (!dev)
802 kdDebug() << "Device " << deviceName << " not found!" << endl;
803 return;
806 prop = dev->findProp("GEOGRAPHICAL_COORD");
807 if (!prop) return;
809 el = prop->findElement("LONG");
810 if (!el) return;
811 if (!el->write_w) return;
813 el->write_w->setText(QString("%1").arg(longitude));
815 el = prop->findElement("LAT");
816 if (!el) return;
817 if (!el->write_w) return;
819 el->write_w->setText(QString("%1").arg(latitude));
821 prop->newText();
826 void KStars::setINDIFocusTimeout(QString deviceName, int timeout)
828 INDI_D *dev;
829 INDI_P *prop;
830 INDI_E *el;
832 if (!indidriver || !indimenu)
834 kdDebug() << "startINDIFocus: establishINDI() failed." << endl;
835 return;
838 dev = indimenu->findDevice(deviceName);
839 if (!dev)
840 dev = indimenu->findDeviceByLabel(deviceName);
841 if (!dev)
843 kdDebug() << "Device " << deviceName << " not found!" << endl;
844 return;
847 prop = dev->findProp("FOCUS_TIMEOUT");
848 if (!prop)
849 return;
851 el = prop->findElement("TIMEOUT");
852 if (!el) return;
854 if (el->write_w)
855 el->write_w->setText(QString("%1").arg(timeout));
856 else if (el->spin_w)
857 el->spin_w->setValue(timeout);
859 prop->newText();
864 void KStars::startINDIExposure(QString deviceName, int timeout)
866 INDI_D *dev;
867 INDI_P *prop;
868 INDI_E *el;
870 if (!indidriver || !indimenu)
872 kdDebug() << "startINDIExposure: establishINDI() failed." << endl;
873 return;
876 dev = indimenu->findDevice(deviceName);
877 if (!dev)
878 dev = indimenu->findDeviceByLabel(deviceName);
879 if (!dev)
881 kdDebug() << "Device " << deviceName << " not found!" << endl;
882 return;
885 prop = dev->findProp("EXPOSE_DURATION");
886 if (!prop) return;
888 el = prop->findElement("EXPOSE_S");
889 if (!el) return;
891 if (el->write_w)
892 el->write_w->setText(QString("%1").arg(timeout));
893 else if (el->spin_w)
894 el->spin_w->setValue(timeout);
897 prop->newText();
901 void KStars::setINDIFilterNum(QString deviceName, int filter_num)
903 INDI_D *dev;
904 INDI_P *prop;
905 INDI_E *el;
907 if (!indidriver || !indimenu)
909 kdDebug() << "setINDIFilterNum: establishINDI() failed." << endl;
910 return;
913 dev = indimenu->findDevice(deviceName);
914 if (!dev)
915 dev = indimenu->findDeviceByLabel(deviceName);
916 if (!dev)
918 kdDebug() << "Device " << deviceName << " not found!" << endl;
919 return;
922 prop = dev->findProp("FILTER_CONF");
923 if (!prop) return;
925 el = prop->findElement("FILTER_NUM");
926 if (!el) return;
928 if (el->write_w)
929 el->write_w->setText(QString("%1").arg(filter_num));
930 else if (el->spin_w)
931 el->spin_w->setValue(filter_num);
933 prop->newText();
937 void KStars::setINDIUTC(QString deviceName, QString UTCDateTime)
939 INDI_D *dev;
940 INDI_P *prop;
941 INDI_E *el;
943 if (!indidriver || !indimenu)
945 kdDebug() << "startINDIUTC: establishINDI() failed." << endl;
946 return;
949 dev = indimenu->findDevice(deviceName);
950 if (!dev)
951 dev = indimenu->findDeviceByLabel(deviceName);
952 if (!dev)
954 kdDebug() << "Device " << deviceName << " not found!" << endl;
955 return;
958 prop = dev->findProp("TIME");
959 if (!prop) return;
961 el = prop->findElement("UTC");
962 if (!el) return;
963 if (!el->write_w) return;
965 el->write_w->setText(UTCDateTime);
967 prop->newText();
971 void KStars::setINDIScopeAction(QString deviceName, QString action)
973 setINDIAction(deviceName, action);
976 void KStars::setINDIFrameType(QString deviceName, QString type)
978 setINDIAction(deviceName, type);
981 void KStars::setINDICCDTemp(QString deviceName, int temp)
983 INDI_D *dev;
984 INDI_P *prop;
985 INDI_E *el;
987 if (!indidriver || !indimenu)
989 kdDebug() << "setINDICCDTemp: establishINDI() failed." << endl;
990 return;
993 dev = indimenu->findDevice(deviceName);
994 if (!dev)
995 dev = indimenu->findDeviceByLabel(deviceName);
996 if (!dev)
998 kdDebug() << "Device " << deviceName << " not found!" << endl;
999 return;
1002 prop = dev->findProp("CCD_TEMPERATURE");
1003 if (!prop) return;
1005 el = prop->findElement("TEMPERATURE");
1006 if (!el) return;
1008 if (el->write_w)
1009 el->write_w->setText(QString("%1").arg(temp));
1010 else if (el->spin_w)
1011 el->spin_w->setValue(temp);
1014 prop->newText();