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

kstars

kstarsactions.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           kstarsactions.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : Mon Feb 25 2002
00005     copyright            : (C) 2002 by Jason Harris
00006     email                : jharris@30doradus.org
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 //needed in slotRunScript() for chmod() syscall (remote script downloaded to temp file)
00019 #include <sys/stat.h>
00020 
00021 #include <kdebug.h>
00022 #include <kaction.h>
00023 #include <kactionclasses.h>
00024 #include <klineedit.h>
00025 #include <kshortcut.h>
00026 #include <kiconloader.h>
00027 #include <kio/netaccess.h>
00028 #include <kmessagebox.h>
00029 #include <ktempfile.h>
00030 #include <ktip.h>
00031 #include <kstandarddirs.h>
00032 #include <kconfigdialog.h>
00033 #include <kfiledialog.h>
00034 #include <kinputdialog.h>
00035 #include <kpopupmenu.h>
00036 #include <kstatusbar.h>
00037 #include <kprocess.h>
00038 #include <qcheckbox.h>
00039 #include <qdir.h>
00040 #include <kdeversion.h>
00041 //FIXME GLSOSSARY (uncomment these when content is added)
00042 //#include <libkdeedu/kdeeduui/kdeeduglossary.h>
00043 
00044 #include "opscatalog.h"
00045 #include "opsguides.h"
00046 #include "opssolarsystem.h"
00047 #include "opscolors.h"
00048 #include "opsadvanced.h"
00049 
00050 #include "Options.h"
00051 #include "kstars.h"
00052 #include "kstarsdata.h"
00053 #include "kstarsdatetime.h"
00054 #include "skymap.h"
00055 #include "skyobject.h"
00056 #include "skyobjectname.h"
00057 #include "ksplanetbase.h"
00058 #include "ksasteroid.h"
00059 #include "kscomet.h"
00060 #include "ksmoon.h"
00061 #include "simclock.h"
00062 #include "infoboxes.h"
00063 #include "toggleaction.h"
00064 #include "timedialog.h"
00065 #include "locationdialog.h"
00066 #include "finddialog.h"
00067 #include "focusdialog.h"
00068 #include "fovdialog.h"
00069 #include "kswizard.h"
00070 #include "tools/lcgenerator.h"
00071 #include "tools/astrocalc.h"
00072 #include "tools/altvstime.h"
00073 #include "tools/wutdialog.h"
00074 #include "tools/scriptbuilder.h"
00075 #include "tools/planetviewer.h"
00076 #include "tools/jmoontool.h"
00077 #include "devmanager.h"
00078 #include "indimenu.h"
00079 #include "indidriver.h"
00080 #include "indifitsconf.h"
00081 #include "telescopewizardprocess.h"
00082 #include "telescopeprop.h"
00083 #include "fitsviewer.h"
00084 
00085 #if ( KDE_IS_VERSION( 3, 2, 90 ) )
00086 #include "ksnewstuff.h"
00087 #endif  // KDE >= 3.2.90
00088 #include "imagesequence.h"
00089 
00090 //This file contains function definitions for Actions declared in kstars.h
00091 
00094 void KStars::slotViewToolBar() {
00095 
00096     if ( sender()->name() == QString( "show_stars" ) ) {
00097         Options::setShowStars( !Options::showStars() );
00098     } else if ( sender()->name() == QString( "show_deepsky" ) ) {
00099         Options::setShowDeepSky( ! Options::showDeepSky() );
00100     } else if ( sender()->name() == QString( "show_planets" ) ) {
00101         Options::setShowPlanets( ! Options::showPlanets() );
00102     } else if ( sender()->name() == QString( "show_clines" ) ) {
00103         Options::setShowCLines( !Options::showCLines() );
00104     } else if ( sender()->name() == QString( "show_cnames" ) ) {
00105         Options::setShowCNames( !Options::showCNames() );
00106     } else if ( sender()->name() == QString( "show_cbounds" ) ) {
00107         Options::setShowCBounds( !Options::showCBounds() );
00108     } else if ( sender()->name() == QString( "show_mw" ) ) {
00109         Options::setShowMilkyWay( !Options::showMilkyWay() );
00110     } else if ( sender()->name() == QString( "show_grid" ) ) {
00111         Options::setShowGrid( !Options::showGrid() );
00112     } else if ( sender()->name() == QString( "show_horizon" ) ) {
00113         Options::setShowGround( !Options::showGround() );
00114     }
00115 
00116     // update time for all objects because they might be not initialized
00117     // it's needed when using horizontal coordinates
00118     data()->setFullTimeUpdate();
00119     updateTime();
00120 
00121     map()->forceUpdate();
00122 }
00123 
00126 void KStars::slotCalculator() {
00127     AstroCalc astrocalc (this);
00128     astrocalc.exec();
00129 }
00130 
00131 void KStars::slotWizard() {
00132     KSWizard wizard(this);
00133     if ( wizard.exec() == QDialog::Accepted ) {
00134         Options::setRunStartupWizard( false );  //don't run on startup next time
00135 
00136         data()->setLocation( wizard.geo() );
00137 
00138         // reset infoboxes
00139         infoBoxes()->geoChanged( geo() );
00140 
00141         // adjust local time to keep UT the same.
00142         // create new LT without DST offset
00143         KStarsDateTime ltime = geo()->UTtoLT( data()->ut() );
00144 
00145         // reset timezonerule to compute next dst change
00146         geo()->tzrule()->reset_with_ltime( ltime, geo()->TZ0(), data()->isTimeRunningForward() );
00147 
00148         // reset next dst change time
00149         data()->setNextDSTChange( geo()->tzrule()->nextDSTChange() );
00150 
00151         // reset local sideral time
00152         data()->syncLST();
00153 
00154         // Make sure Numbers, Moon, planets, and sky objects are updated immediately
00155         data()->setFullTimeUpdate();
00156 
00157         // If the sky is in Horizontal mode and not tracking, reset focus such that
00158         // Alt/Az remain constant.
00159         if ( data()->useDefaultOptions ) {
00160             SkyPoint newPoint;
00161             newPoint.setAz( Options::focusRA() );
00162             newPoint.setAlt( Options::focusDec() + 0.0001 );
00163             newPoint.HorizontalToEquatorial( LST(), geo()->lat() );
00164             map()->setDestination( &newPoint );
00165         } else if ( ! Options::isTracking() && Options::useAltAz() ) {
00166             map()->focus()->HorizontalToEquatorial( LST(), geo()->lat() );
00167         }
00168 
00169         // recalculate new times and objects
00170         data()->setSnapNextFocus();
00171         updateTime();
00172     }
00173 }
00174 
00175 void KStars::slotDownload() {
00176 #if ( KDE_IS_VERSION( 3, 2, 90 ) )
00177     if (!kns) kns = new KSNewStuff( this );
00178     kns->download();
00179 #endif //KDE >= 3.2.90
00180 }
00181 
00182 void KStars::slotLCGenerator() {
00183     if (AAVSODialog == NULL)
00184         AAVSODialog = new LCGenerator(this);
00185 
00186     AAVSODialog->show();
00187 }
00188 
00189 void KStars::slotAVT() {
00190     AltVsTime * avt = new AltVsTime(this);
00191     avt->show();
00192 }
00193 
00194 void KStars::slotWUT() {
00195     WUTDialog dialog(this);
00196     dialog.exec();
00197 }
00198 
00199 //FIXME GLOSSARY
00200 // void KStars::slotGlossary(){
00201 //  GlossaryDialog *dlg = new GlossaryDialog( true, this, "glossary" );
00202 //  QString glossaryfile =data()->stdDirs->findResource( "data", "kstars/glossary.xml" );
00203 //  KURL u = glossaryfile;
00204 //  Glossary *g = Glossary::readFromXML( u );
00205 //  g->setName( i18n( "Knowledge" ) );
00206 //  dlg->addGlossary( g );
00207 //  dlg->show();
00208 // }
00209 
00210 void KStars::slotScriptBuilder() {
00211     ScriptBuilder sb(this);
00212     sb.exec();
00213 }
00214 
00215 void KStars::slotSolarSystem() {
00216     PlanetViewer pv(this);
00217     pv.exec();
00218 }
00219 
00220 void KStars::slotJMoonTool() {
00221     JMoonTool jmt(this);
00222     jmt.exec();
00223 }
00224 
00225 void KStars::slotImageSequence()
00226 {
00227   if (indiseq == NULL)
00228     indiseq = new imagesequence(this);
00229 
00230   if (indiseq->updateStatus())
00231     indiseq->show();
00232 }
00233 
00234 void KStars::slotTelescopeWizard()
00235 {
00236   telescopeWizardProcess twiz(this);
00237   twiz.exec();
00238 }
00239 
00240 void KStars::slotTelescopeProperties()
00241 {
00242   telescopeProp scopeProp(this);
00243   scopeProp.exec();
00244 }
00245 
00246 void KStars::slotINDIPanel() {
00247 
00248    if (indimenu == NULL)
00249      indimenu = new INDIMenu(this);
00250 
00251    indimenu->updateStatus();
00252 }
00253 
00254 void KStars::slotINDIDriver() {
00255     if (indidriver == NULL)
00256         indidriver = new INDIDriver(this);
00257     indidriver->show();
00258 }
00259 
00260 void KStars::slotINDIConf() {
00261 
00262    INDIFITSConf indioptions(this);
00263 
00264     indioptions.loadOptions();
00265    /*QStringList filterList;
00266  
00267    
00268    indiconf.timeCheck->setChecked( Options::indiAutoTime() );
00269    indiconf.GeoCheck->setChecked( Options::indiAutoGeo() );
00270    indiconf.crosshairCheck->setChecked( Options::indiCrosshairs() );
00271    indiconf.messagesCheck->setChecked ( Options::indiMessages() );
00272    indiconf.fitsAutoDisplayCheck->setChecked( Options::indiFITSDisplay() );
00273    indiconf.telPort_IN->setText ( Options::indiTelescopePort());
00274    indiconf.vidPort_IN->setText ( Options::indiVideoPort());
00275 
00276    if (Options::fitsSaveDirectory().isEmpty())
00277    {
00278      indiconf.fitsDIR_IN->setText (QDir:: homeDirPath());
00279      Options::setFitsSaveDirectory( indiconf.fitsDIR_IN->text());
00280    }
00281    else
00282    indiconf.fitsDIR_IN->setText ( Options::fitsSaveDirectory());
00283 
00284    if (Options::filterAlias().empty())
00285    {
00286         filterList << "0" << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8"
00287                    << "9";
00288         indiconf.filterCombo->insertStringList(filterList);
00289    }*/
00290 
00291    if (indioptions.exec() == QDialog::Accepted)
00292    {
00293      /*Options::setIndiAutoTime( indiconf.timeCheck->isChecked() );
00294      Options::setIndiAutoGeo( indiconf.GeoCheck->isChecked() );
00295      Options::setIndiCrosshairs( indiconf.crosshairCheck->isChecked() );
00296      Options::setIndiMessages( indiconf.messagesCheck->isChecked() );
00297      Options::setIndiFITSDisplay (indiconf.fitsAutoDisplayCheck->isChecked());
00298      Options::setIndiTelescopePort ( indiconf.telPort_IN->text());
00299      Options::setIndiVideoPort( indiconf.vidPort_IN->text());
00300      Options::setFitsSaveDirectory( indiconf.fitsDIR_IN->text());*/
00301      indioptions.saveOptions();
00302 
00303      map()->forceUpdateNow();
00304    }
00305 }
00306 
00307 void KStars::slotGeoLocator() {
00308     LocationDialog locationdialog (this);
00309     if ( locationdialog.exec() == QDialog::Accepted ) {
00310         GeoLocation *newLocation = locationdialog.selectedCity();
00311         if ( newLocation ) {
00312             // set new location in options
00313             data()->setLocation( *newLocation );
00314 
00315             // reset infoboxes
00316             infoBoxes()->geoChanged( newLocation );
00317 
00318             // adjust local time to keep UT the same.
00319             // create new LT without DST offset
00320             KStarsDateTime ltime = newLocation->UTtoLT( data()->ut() );
00321 
00322             // reset timezonerule to compute next dst change
00323             newLocation->tzrule()->reset_with_ltime( ltime, newLocation->TZ0(), data()->isTimeRunningForward() );
00324 
00325             // reset next dst change time
00326             data()->setNextDSTChange( newLocation->tzrule()->nextDSTChange() );
00327 
00328             // reset local sideral time
00329             data()->syncLST();
00330 
00331             // Make sure Numbers, Moon, planets, and sky objects are updated immediately
00332             data()->setFullTimeUpdate();
00333 
00334             // If the sky is in Horizontal mode and not tracking, reset focus such that
00335             // Alt/Az remain constant.
00336             if ( ! Options::isTracking() && Options::useAltAz() ) {
00337                 map()->focus()->HorizontalToEquatorial( LST(), geo()->lat() );
00338             }
00339 
00340             // recalculate new times and objects
00341             data()->setSnapNextFocus();
00342             updateTime();
00343         }
00344     }
00345 }
00346 
00347 void KStars::slotViewOps() {
00348     KStandardDirs stdDirs;
00349 
00350     //An instance of your dialog could be already created and could be cached,
00351     //in which case you want to display the cached dialog instead of creating
00352     //another one
00353     if ( KConfigDialog::showDialog( "settings" ) ) return;
00354 
00355     //KConfigDialog didn't find an instance of this dialog, so lets create it :
00356     KConfigDialog* dialog = new KConfigDialog( this, "settings",
00357                          Options::self() );
00358 
00359     connect( dialog, SIGNAL( applyClicked() ), this, SLOT( slotApplySettings() ) );
00360     connect( dialog, SIGNAL( okClicked() ), this, SLOT( slotApplySettings() ) );
00361 
00362     OpsCatalog *opcatalog    = new OpsCatalog( this, "catalogs" );
00363     OpsGuides  *opguides     = new OpsGuides( this, "guides" );
00364     OpsSolarSystem *opsolsys = new OpsSolarSystem( this, "solarsystem" );
00365     OpsColors  *opcolors     = new OpsColors( this, "colors" );
00366     OpsAdvanced *opadvanced  = new OpsAdvanced( this, "advanced" );
00367 
00368     dialog->addPage(opcatalog, i18n("Catalogs"), "kstars_catalog");
00369     dialog->addPage(opsolsys, i18n("Solar System"), "kstars_solarsystem");
00370     dialog->addPage(opguides, i18n("Guides"), "kstars_guides");
00371     dialog->addPage(opcolors, i18n("Colors"), "kstars_colors");
00372     dialog->addPage(opadvanced, i18n("Advanced"), "kstars_advanced");
00373 
00374     dialog->show();
00375 }
00376 
00377 void KStars::slotApplyConfigChanges() {
00378     Options::writeConfig();
00379     applyConfig();
00380     data()->setFullTimeUpdate();
00381     map()->forceUpdate();
00382 }
00383 
00384 void KStars::slotSetTime() {
00385     TimeDialog timedialog ( data()->lt(), this );
00386 
00387     if ( timedialog.exec() == QDialog::Accepted ) {
00388         data()->changeDateTime( geo()->LTtoUT( timedialog.selectedDateTime() ) );
00389 
00390         if ( Options::useAltAz() ) {
00391             map()->focus()->HorizontalToEquatorial( LST(), geo()->lat() );
00392         }
00393 
00394         //If focusObject has a Planet Trail, clear it and start anew.
00395         if ( map()->focusObject() && map()->focusObject()->isSolarSystem() &&
00396              ((KSPlanetBase*)map()->focusObject())->hasTrail() ) {
00397           ((KSPlanetBase*)map()->focusObject())->clearTrail();
00398           ((KSPlanetBase*)map()->focusObject())->addToTrail();
00399         }
00400     }
00401 }
00402 
00403 void KStars::slotFind() {
00404     clearCachedFindDialog();
00405     if ( !findDialog ) {      // create new dialog if no dialog is existing
00406         findDialog = new FindDialog( this );
00407     }
00408 
00409     if ( !findDialog ) kdWarning() << i18n( "KStars::slotFind() - Not enough memory for dialog" ) << endl;
00410 
00411     if ( findDialog->exec() == QDialog::Accepted && findDialog->currentItem() ) {
00412         map()->setClickedObject( findDialog->currentItem()->objName()->skyObject() );
00413         map()->setClickedPoint( map()->clickedObject() );
00414         map()->slotCenter();
00415     }
00416 
00417     // check if data has changed while dialog was open
00418     if ( DialogIsObsolete ) clearCachedFindDialog();
00419 }
00420 
00423 //File
00424 void KStars::newWindow() {
00425     new KStars(true);
00426 }
00427 
00428 void KStars::closeWindow() {
00429     // since QT 3.1 close() just emits lastWindowClosed if the window is not hidden
00430     show();
00431     close();
00432 }
00433 
00434 void KStars::slotOpenFITS()
00435 {
00436 
00437   KURL fileURL = KFileDialog::getOpenURL( QDir::homeDirPath(), "*.fits *.fit *.fts|Flexible Image Transport System");
00438 
00439   if (fileURL.isEmpty())
00440     return;
00441 
00442   FITSViewer * fv = new FITSViewer(&fileURL, this);
00443   fv->show();
00444 
00445 }
00446 
00447 void KStars::slotExportImage() {
00448     KURL fileURL = KFileDialog::getSaveURL( QDir::homeDirPath(), "image/png image/jpeg image/gif image/x-portable-pixmap image/x-bmp" );
00449 
00450     //Warn user if file exists!
00451     if (QFile::exists(fileURL.path()))
00452     {
00453         int r=KMessageBox::warningContinueCancel(static_cast<QWidget *>(parent()),
00454                                 i18n( "A file named \"%1\" already exists. "
00455                                         "Overwrite it?" ).arg(fileURL.fileName()),
00456                                 i18n( "Overwrite File?" ),
00457                                 i18n( "&Overwrite" ) );
00458         
00459         if(r==KMessageBox::Cancel) return;
00460     }
00461     
00462     exportImage( fileURL.url(), map()->width(), map()->height() );
00463 }
00464 
00465 void KStars::slotRunScript() {
00466     KURL fileURL = KFileDialog::getOpenURL( QDir::homeDirPath(), "*.kstars|KStars Scripts (*.kstars)" );
00467     QFile f;
00468     QString fname;
00469 
00470     if ( fileURL.isValid() ) {
00471         if ( ! fileURL.isLocalFile() ) {
00472             //Warn the user about executing remote code.
00473             QString message = i18n( "Warning:  You are about to execute a remote shell script on your machine. " );
00474             message += i18n( "If you absolutely trust the source of this script, press Continue to execute the script; " );
00475             message += i18n( "to save the file without executing it, press Save; " );
00476             message += i18n( "to cancel the download, press Cancel. " );
00477 
00478             int result = KMessageBox::warningYesNoCancel( 0, message, i18n( "Really Execute Remote Script?" ),
00479                     KStdGuiItem::cont(), KStdGuiItem::save() );
00480 
00481             if ( result == KMessageBox::Cancel ) return;
00482             if ( result == KMessageBox::No ) { //save file
00483                 KURL saveURL = KFileDialog::getSaveURL( QDir::homeDirPath(), "*.kstars|KStars Scripts (*.kstars)" );
00484                 KTempFile tmpfile;
00485                 tmpfile.setAutoDelete(true);
00486 
00487                 while ( ! saveURL.isValid() ) {
00488                     message = i18n( "Save location is invalid. Try another location?" );
00489                     if ( KMessageBox::warningYesNo( 0, message, i18n( "Invalid Save Location" ), i18n("Try Another"), i18n("Do Not Try") ) == KMessageBox::No ) return;
00490                     saveURL = KFileDialog::getSaveURL( QDir::homeDirPath(), "*.kstars|KStars Scripts (*.kstars)" );
00491                 }
00492 
00493                 if ( saveURL.isLocalFile() ) {
00494                     fname = saveURL.path();
00495                 } else {
00496                     fname = tmpfile.name();
00497                 }
00498 
00499                 if( KIO::NetAccess::download( fileURL, fname, this ) ) {
00500                     chmod( fname.ascii(), S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH ); //make it executable
00501 
00502                     if ( tmpfile.name() == fname ) { //upload to remote location
00503                         if ( ! KIO::NetAccess::upload( tmpfile.name(), fileURL, this ) ) {
00504                             QString message = i18n( "Could not upload image to remote location: %1" ).arg( fileURL.prettyURL() );
00505                             KMessageBox::sorry( 0, message, i18n( "Could not upload file" ) );
00506                         }
00507                     }
00508                 } else {
00509                     KMessageBox::sorry( 0, i18n( "Could not download the file." ), i18n( "Download Error" ) );
00510                 }
00511 
00512                 return;
00513             }
00514         }
00515 
00516         //Damn the torpedos and full speed ahead, we're executing the script!
00517         KTempFile tmpfile;
00518         tmpfile.setAutoDelete(true);
00519 
00520         if ( ! fileURL.isLocalFile() ) {
00521             fname = tmpfile.name();
00522             if( KIO::NetAccess::download( fileURL, fname, this ) ) {
00523                 chmod( fname.ascii(), S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH );
00524                 f.setName( fname );
00525             }
00526         } else {
00527             f.setName( fileURL.path() );
00528         }
00529 
00530         if ( !f.open( IO_ReadOnly) ) {
00531             QString message = i18n( "Could not open file %1" ).arg( f.name() );
00532             KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00533             return;
00534         }
00535 
00536         // Before we run the script, make sure that it's safe.  Each line must either begin with "#"
00537         // or begin with "dcop $KSTARS".  Otherwise, the line must be equal to one of the following:
00538         // "KSTARS=`dcopfind -a 'kstars*'`";  "MAIN=KStarsInterface";  or "CLOCK=clock#1"
00539         QTextStream istream(&f);
00540         QString line;
00541         bool fileOK( true );
00542 
00543         while (  ! istream.eof() ) {
00544             line = istream.readLine();
00545             if ( line.left(1) != "#" && line.left(12) != "dcop $KSTARS"
00546                     && line.stripWhiteSpace() != "KSTARS=`dcopfind -a 'kstars*'`"
00547                     && line.stripWhiteSpace() != "MAIN=KStarsInterface"
00548                     && line.stripWhiteSpace() != "CLOCK=clock#1" ) {
00549                 fileOK = false;
00550                 break;
00551             }
00552         }
00553 
00554         if ( ! fileOK ) {
00555             int answer;
00556             answer = KMessageBox::warningContinueCancel( 0, i18n( "The selected script contains unrecognized elements,"
00557                 "indicating that it was not created using the KStars script builder. "
00558                 "This script may not function properly, and it may even contain malicious code. "
00559                 "Would you like to execute it anyway?" ),
00560                     i18n( "Script Validation Failed" ), i18n("Run Nevertheless"), "daExecuteScript" );
00561             if ( answer == KMessageBox::Cancel ) return;
00562         }
00563 
00564         //FIXME STRINGS FREEZE
00565         //Add statusbar message that script is running
00566         //ks->statusBar()->changeItem( i18n( "Running script: %1" ).arg( fileURL.fileName() ), 0 );
00567 
00568         KProcess p;
00569         p << f.name();
00570         p.start( KProcess::DontCare );
00571 
00572         while ( p.isRunning() ) kapp->processEvents( 50 ); //otherwise tempfile may get deleted before script completes.
00573     }
00574 }
00575 
00576 void KStars::slotPrint() {
00577     bool switchColors(false);
00578 
00579     //Suggest Chart color scheme
00580     if ( data()->colorScheme()->colorNamed( "SkyColor" ) != "#FFFFFF" ) {
00581         QString message = i18n( "You can save printer ink by using the \"Star Chart\" "
00582                 "color scheme, which uses a white background. Would you like to "
00583                 "temporarily switch to the Star Chart color scheme for printing?" );
00584 
00585         int answer;
00586         answer = KMessageBox::questionYesNoCancel( 0, message, i18n( "Switch to Star Chart Colors?" ),
00587             i18n("Switch Color Scheme"), i18n("Do Not Switch"), "askAgainPrintColors" );
00588 
00589         if ( answer == KMessageBox::Cancel ) return;
00590         if ( answer == KMessageBox::Yes ) switchColors = true;
00591     }
00592 
00593     printImage( true, switchColors );
00594 }
00595 
00596 //Set Time to CPU clock
00597 void KStars::slotSetTimeToNow() {
00598     data()->changeDateTime( geo()->LTtoUT( KStarsDateTime::currentDateTime() ) );
00599 
00600     if ( Options::useAltAz() ) {
00601         map()->focus()->HorizontalToEquatorial( LST(), geo()->lat() );
00602     }
00603 
00604     //If focusObject has a Planet Trail, clear it and start anew.
00605     if ( map()->focusObject() && map()->focusObject()->isSolarSystem() &&
00606          ((KSPlanetBase*)map()->focusObject())->hasTrail() ) {
00607       ((KSPlanetBase*)map()->focusObject())->clearTrail();
00608       ((KSPlanetBase*)map()->focusObject())->addToTrail();
00609     }
00610 }
00611 
00612 void KStars::slotToggleTimer() {
00613     if ( data()->clock()->isActive() ) {
00614         data()->clock()->stop();
00615         updateTime();
00616     } else {
00617         if ( fabs( data()->clock()->scale() ) > Options::slewTimeScale() )
00618             data()->clock()->setManualMode( true );
00619         data()->clock()->start();
00620         if ( data()->clock()->isManualMode() ) map()->forceUpdate();
00621     }
00622 }
00623 
00624 //Focus
00625 void KStars::slotPointFocus() {
00626     QString sentFrom( sender()->name() );
00627 
00628     if ( sentFrom == "zenith" )
00629         map()->invokeKey( KKey( "Z" ).keyCodeQt() );
00630     else if ( sentFrom == "north" )
00631         map()->invokeKey( KKey( "N" ).keyCodeQt() );
00632     else if ( sentFrom == "east" )
00633         map()->invokeKey( KKey( "E" ).keyCodeQt() );
00634     else if ( sentFrom == "south" )
00635         map()->invokeKey( KKey( "S" ).keyCodeQt() );
00636     else if ( sentFrom == "west" )
00637         map()->invokeKey( KKey( "W" ).keyCodeQt() );
00638 }
00639 
00640 void KStars::slotTrack() {
00641     if ( Options::isTracking() ) {
00642         Options::setIsTracking( false );
00643         actionCollection()->action("track_object")->setText( i18n( "Engage &Tracking" ) );
00644         actionCollection()->action("track_object")->setIconSet( BarIcon( "decrypted" ) );
00645         if ( map()->focusObject() && map()->focusObject()->isSolarSystem() && data()->temporaryTrail ) {
00646             ((KSPlanetBase*)map()->focusObject())->clearTrail();
00647             data()->temporaryTrail = false;
00648         }
00649 
00650         map()->setClickedObject( NULL );
00651         map()->setFocusObject( NULL );//no longer tracking focusObject
00652         map()->setFocusPoint( NULL );
00653     } else {
00654         map()->setClickedPoint( map()->focus() );
00655         map()->setClickedObject( NULL );
00656         map()->setFocusObject( NULL );//no longer tracking focusObject
00657         map()->setFocusPoint( map()->clickedPoint() );
00658         Options::setIsTracking( true );
00659         actionCollection()->action("track_object")->setText( i18n( "Stop &Tracking" ) );
00660         actionCollection()->action("track_object")->setIconSet( BarIcon( "encrypted" ) );
00661     }
00662 
00663     map()->forceUpdate();
00664 }
00665 
00666 void KStars::slotManualFocus() {
00667     FocusDialog focusDialog( this ); // = new FocusDialog( this );
00668     if ( Options::useAltAz() ) focusDialog.activateAzAltPage();
00669 
00670     if ( focusDialog.exec() == QDialog::Accepted ) {
00671         //If the requested position is very near the pole, we need to point first
00672         //to an intermediate location just below the pole in order to get the longitudinal
00673         //position (RA/Az) right.
00674         double realAlt( focusDialog.point()->alt()->Degrees() );
00675         double realDec( focusDialog.point()->dec()->Degrees() );
00676         if ( Options::useAltAz() && realAlt > 89.0 ) {
00677             focusDialog.point()->setAlt( 89.0 );
00678         }
00679         if ( ! Options::useAltAz() && realDec > 89.0 ) {
00680             focusDialog.point()->setDec( 89.0 );
00681         }
00682 
00683         //Do we need to convert Az/Alt to RA/Dec?
00684         if ( focusDialog.usedAltAz() )
00685             focusDialog.point()->HorizontalToEquatorial( LST(), geo()->lat() );
00686 
00687         //Do we need to convert RA/Dec to Alt/Az?
00688         if ( ! focusDialog.usedAltAz() )
00689             focusDialog.point()->EquatorialToHorizontal( LST(), geo()->lat() );
00690 
00691         map()->setClickedPoint( focusDialog.point() );
00692         if ( Options::isTracking() ) slotTrack();
00693 
00694         map()->slotCenter();
00695 
00696         //The slew takes some time to complete, and this often causes the final focus point to be slightly
00697         //offset from the user's requested coordinates (because EquatorialToHorizontal() is called
00698         //throughout the process, which depends on the sidereal time).  So we now "polish" the final
00699         //position by resetting the final focus to the focusDialog point.
00700         //
00701         //Also, if the requested position was within 1 degree of the coordinate pole, this will
00702         //automatically correct the final pointing from the intermediate offset position to the final position
00703         if ( Options::useAltAz() ) {
00704             data()->setSnapNextFocus();
00705             map()->setDestinationAltAz( focusDialog.point()->alt()->Degrees(), focusDialog.point()->az()->Degrees() );
00706         } else {
00707             data()->setSnapNextFocus();
00708             map()->setDestination( focusDialog.point()->ra()->Hours(), focusDialog.point()->dec()->Degrees() );
00709         }
00710 
00711         //Now, if the requested point was near a pole, we need to reset the Alt/Dec of the focus.
00712         if ( Options::useAltAz() && realAlt > 89.0 ) map()->focus()->setAlt( realAlt );
00713         if ( ! Options::useAltAz() && realDec > 89.0 ) map()->focus()->setDec( realAlt );
00714 
00715         //Don't track if we set Alt/Az coordinates.  This way, Alt/Az remain constant.
00716         if ( focusDialog.usedAltAz() ) map()->stopTracking();
00717     }
00718 }
00719 
00720 //View Menu
00721 void KStars::slotZoomIn() {
00722     actionCollection()->action("zoom_out")->setEnabled (true);
00723     if ( Options::zoomFactor() < MAXZOOM )
00724         Options::setZoomFactor( Options::zoomFactor()*DZOOM );
00725 
00726     if ( Options::zoomFactor() >= MAXZOOM ) {
00727         Options::setZoomFactor( MAXZOOM );
00728         actionCollection()->action("zoom_in")->setEnabled (false);
00729     }
00730 
00731     map()->forceUpdate();
00732 }
00733 
00734 void KStars::slotZoomOut() {
00735     actionCollection()->action("zoom_in")->setEnabled (true);
00736     if ( Options::zoomFactor() > MINZOOM )
00737         Options::setZoomFactor( Options::zoomFactor()/DZOOM );
00738 
00739     if ( Options::zoomFactor() <= MINZOOM ) {
00740         Options::setZoomFactor( MINZOOM );
00741         actionCollection()->action("zoom_out")->setEnabled (false);
00742     }
00743 
00744     map()->forceUpdate();
00745 }
00746 
00747 void KStars::slotDefaultZoom() {
00748     Options::setZoomFactor( DEFAULTZOOM );
00749     map()->forceUpdate();
00750 
00751     if ( Options::zoomFactor() > MINZOOM )
00752         actionCollection()->action("zoom_out")->setEnabled (true);
00753     if ( Options::zoomFactor() < MAXZOOM )
00754         actionCollection()->action("zoom_in")->setEnabled (true);
00755 }
00756 
00757 void KStars::slotSetZoom() {
00758     bool ok( false );
00759     double currentAngle = map()->width() / ( Options::zoomFactor() * dms::DegToRad );
00760     double angSize = currentAngle;
00761     double minAngle = map()->width() / ( MAXZOOM * dms::DegToRad );
00762     double maxAngle = map()->width() / ( MINZOOM * dms::DegToRad );
00763 
00764     angSize = KInputDialog::getDouble( i18n( "The user should enter an angle for the field-of-view of the display",
00765             "Enter Desired Field-of-View Angle" ), i18n( "Enter a field-of-view angle in degrees: " ),
00766             currentAngle, minAngle, maxAngle, 0.1, 1, &ok );
00767 
00768     if ( ok ) {
00769         Options::setZoomFactor( map()->width() / ( angSize * dms::DegToRad ) );
00770 
00771         if ( Options::zoomFactor() <= MINZOOM ) {
00772             Options::setZoomFactor( MINZOOM );
00773             actionCollection()->action("zoom_out")->setEnabled( false );
00774         } else {
00775             actionCollection()->action("zoom_out")->setEnabled( true );
00776         }
00777 
00778         if ( Options::zoomFactor() >= MAXZOOM ) {
00779             Options::setZoomFactor( MAXZOOM );
00780             actionCollection()->action("zoom_in")->setEnabled( false );
00781         } else {
00782             actionCollection()->action("zoom_in")->setEnabled( true );
00783         }
00784 
00785         map()->forceUpdate();
00786     }
00787 }
00788 
00789 void KStars::slotCoordSys() {
00790     if ( Options::useAltAz() ) {
00791         Options::setUseAltAz( false );
00792         if ( Options::useRefraction() ) {
00793             if ( map()->focusObject() ) //simply update focus to focusObject's position
00794                 map()->setFocus( map()->focusObject() );
00795             else { //need to recompute focus for unrefracted position
00796                 map()->setFocusAltAz( map()->refract( map()->focus()->alt(), false ).Degrees(), 
00797                         map()->focus()->az()->Degrees() );
00798                 map()->focus()->HorizontalToEquatorial( data()->lst(), geo()->lat() );
00799             }
00800         }
00801         actCoordSys->turnOn();
00802     } else {
00803         Options::setUseAltAz( true );
00804         if ( Options::useRefraction() ) {
00805             map()->setFocusAltAz( map()->refract( map()->focus()->alt(), true ).Degrees(), 
00806                     map()->focus()->az()->Degrees() );
00807         }
00808         actCoordSys->turnOff();
00809     }
00810     map()->forceUpdate();
00811 }
00812 
00813 //Settings Menu:
00814 void KStars::slotColorScheme() {
00815     //use mid(3) to exclude the leading "cs_" prefix from the action name
00816     QString filename = QString( sender()->name() ).mid(3) + ".colors";
00817     loadColorScheme( filename );
00818 }
00819 
00820 void KStars::slotTargetSymbol() {
00821     QString symbolName( sender()->name() );
00822     FOV f( symbolName ); //read data from fov.dat
00823 
00824     Options::setFOVName( f.name() );
00825     Options::setFOVSize( f.size() );
00826     Options::setFOVShape( f.shape() );
00827     Options::setFOVColor( f.color() );
00828     data()->fovSymbol.setName( Options::fOVName() );
00829     data()->fovSymbol.setSize( Options::fOVSize() );
00830     data()->fovSymbol.setShape( Options::fOVShape() );
00831     data()->fovSymbol.setColor( Options::fOVColor().name() );
00832 
00833 //Careful!!  If the user selects a small FOV (like HST), this basically crashes kstars :(
00834 //  //set ZoomLevel to match the FOV symbol
00835 //  zoom( (double)(map()->width()) * 60.0 / ( 2.0 * dms::DegToRad * data()->fovSymbol.size() ) );
00836 
00837     map()->forceUpdate();
00838 }
00839 
00840 void KStars::slotFOVEdit() {
00841     FOVDialog fovdlg( this );
00842     if ( fovdlg.exec() == QDialog::Accepted ) {
00843         //replace existing fov.dat with data from the FOVDialog
00844         QFile f;
00845         f.setName( locateLocal( "appdata", "fov.dat" ) );
00846 
00847         //rebuild fov.dat if FOVList is empty
00848         if ( fovdlg.FOVList.isEmpty() ) {
00849             f.remove();
00850             initFOV();
00851         } else {
00852             if ( ! f.open( IO_WriteOnly ) ) {
00853                 kdDebug() << i18n( "Could not open fov.dat for writing." ) << endl;
00854             } else {
00855                 QTextStream ostream(&f);
00856 
00857                 for ( FOV *fov = fovdlg.FOVList.first(); fov; fov = fovdlg.FOVList.next() )
00858                     ostream << fov->name() << ":" << fov->size()
00859                             << ":" << QString("%1").arg( fov->shape() ) << ":" << fov->color() << endl;
00860 
00861                 f.close();
00862             }
00863         }
00864 
00865         //repopulate FOV menu  with items from new fov.dat
00866         fovActionMenu->popupMenu()->clear();
00867 
00868         if ( f.open( IO_ReadOnly ) ) {
00869             QTextStream stream( &f );
00870             while ( !stream.eof() ) {
00871                 QString line = stream.readLine();
00872                 QStringList fields = QStringList::split( ":", line );
00873 
00874                 if ( fields.count() == 4 ) {
00875                     QString nm = fields[0].stripWhiteSpace();
00876                     KToggleAction *kta = new KToggleAction( nm, 0, this, SLOT( slotTargetSymbol() ),
00877                             actionCollection(), nm.utf8() );
00878                     kta->setExclusiveGroup( "fovsymbol" );
00879                     fovActionMenu->insert( kta );
00880                 }
00881             }
00882         } else {
00883             kdDebug() << i18n( "Could not open file: %1" ).arg( f.name() ) << endl;
00884         }
00885 
00886         fovActionMenu->popupMenu()->insertSeparator();
00887         fovActionMenu->insert( new KAction( i18n( "Edit FOV Symbols..." ), 0, this,
00888                 SLOT( slotFOVEdit() ), actionCollection(), "edit_fov" ) );
00889 
00890         //set FOV to whatever was highlighted in FOV dialog
00891         if ( fovdlg.FOVList.count() > 0 ) {
00892             Options::setFOVName( fovdlg.FOVList.at( fovdlg.currentItem() )->name() );
00893             data()->fovSymbol.setName( Options::fOVName() );
00894             data()->fovSymbol.setSize( Options::fOVSize() );
00895             data()->fovSymbol.setShape( Options::fOVShape() );
00896             data()->fovSymbol.setColor( Options::fOVColor().name() );
00897         }
00898 
00899 //Careful!!  If the user selects a small FOV (like HST), this basically crashes kstars :(
00900 //      //set ZoomLevel to match the FOV symbol
00901 //      zoom( (double)(map()->width()) * 60.0 / ( 2.0 * dms::DegToRad * data()->fovSymbol.size() ) );
00902     }
00903 }
00904 
00905 void KStars::slotObsList() {
00906   obsList->show();
00907 }
00908 
00909 //Help Menu
00910 void KStars::slotTipOfDay() {
00911     KTipDialog::showTip("kstars/tips", true);
00912 }
00913 
00914 // Toggle to and from full screen mode
00915 void KStars::slotFullScreen()
00916 {
00917   if ( topLevelWidget()->isFullScreen() ) {
00918     topLevelWidget()->showNormal();
00919     }
00920   else {
00921     topLevelWidget()->showFullScreen();
00922     }
00923 }
00924 
00925 void KStars::slotClearAllTrails() {
00926     //Exclude object with temporary trail
00927     SkyObject *exOb( NULL );
00928     if ( map()->focusObject() && map()->focusObject()->isSolarSystem() && data()->temporaryTrail ) {
00929         exOb = map()->focusObject();
00930     }
00931     
00932     //Major bodies
00933     if ( !( exOb && exOb->name() == "Moon" ) )    data()->Moon->clearTrail();
00934     if ( !( exOb && exOb->name() == "Sun" ) )     data()->PCat->findByName("Sun")->clearTrail();
00935     if ( !( exOb && exOb->name() == "Mercury" ) ) data()->PCat->findByName("Mercury")->clearTrail();
00936     if ( !( exOb && exOb->name() == "Venus" ) )   data()->PCat->findByName("Venus")->clearTrail();
00937     if ( !( exOb && exOb->name() == "Mars" ) )    data()->PCat->findByName("Mars")->clearTrail();
00938     if ( !( exOb && exOb->name() == "Jupiter" ) ) data()->PCat->findByName("Jupiter")->clearTrail();
00939     if ( !( exOb && exOb->name() == "Saturn" ) )  data()->PCat->findByName("Saturn")->clearTrail();
00940     if ( !( exOb && exOb->name() == "Uranus" ) )  data()->PCat->findByName("Uranus")->clearTrail();
00941     if ( !( exOb && exOb->name() == "Neptune" ) ) data()->PCat->findByName("Neptune")->clearTrail();
00942     if ( !( exOb && exOb->name() == "Pluto" ) )   data()->PCat->findByName("Pluto")->clearTrail();
00943     
00944     //Asteroids
00945     for ( KSAsteroid *ast = data()->asteroidList.first(); ast; ast = data()->asteroidList.next() ) 
00946         if ( !( exOb && exOb->name() == ast->name() ) ) ast->clearTrail();
00947 
00948     //Comets
00949     for ( KSComet *com = data()->cometList.first(); com; com = data()->cometList.next() ) 
00950         if ( !( exOb && exOb->name() == com->name() ) ) com->clearTrail();
00951 
00952     map()->forceUpdate();
00953 }
00954 
00955 //toggle display of GUI Items on/off
00956 void KStars::slotShowGUIItem( bool show ) {
00957 //Toolbars
00958     if ( sender()->name() == QString( "show_mainToolBar" ) ) {
00959         Options::setShowMainToolBar( show );
00960         if ( show ) toolBar( "mainToolBar" )->show();
00961         else toolBar( "mainToolBar" )->hide();
00962     }
00963     if ( sender()->name() == QString( "show_viewToolBar" ) ) {
00964         Options::setShowViewToolBar( show );
00965         if ( show ) toolBar( "viewToolBar" )->show();
00966         else toolBar( "viewToolBar" )->hide();
00967     }
00968 
00969     if ( sender()->name() == QString( "show_statusBar" ) ) {
00970         Options::setShowStatusBar( show );
00971         if ( show ) statusBar()->show();
00972         else  statusBar()->hide();
00973     }
00974 
00975     if ( sender()->name() == QString( "show_sbAzAlt" ) ) {
00976         Options::setShowAltAzField( show );
00977         if ( show ) {
00978             //To preserve the order (AzAlt before RADec), we have to remove
00979             //the RADec field and then add both back.
00980             if ( Options::showRADecField() ) statusBar()->removeItem( 2 );
00981 
00982             QString s = "000d 00m 00s,   +00d 00\' 00\""; //only need this to set the width
00983             statusBar()->insertFixedItem( s, 1, true );
00984             statusBar()->setItemAlignment( 1, AlignRight | AlignVCenter );
00985             statusBar()->changeItem( "", 1 );
00986 
00987             if ( Options::showRADecField() ) {
00988                 statusBar()->insertFixedItem( s, 2, true );
00989                 statusBar()->setItemAlignment( 2, AlignRight | AlignVCenter );
00990                 statusBar()->changeItem( "", 2 );
00991             }
00992         } else {
00993             statusBar()->removeItem( 1 );
00994         }
00995     }
00996 
00997     if ( sender()->name() == QString( "show_sbRADec" ) ) {
00998         Options::setShowRADecField( show );
00999         if ( show ) {
01000             QString s = "000d 00m 00s,   +00d 00\' 00\""; //only need this to set the width
01001             statusBar()->insertFixedItem( s, 2, true );
01002             statusBar()->setItemAlignment( 2, AlignRight | AlignVCenter );
01003             statusBar()->changeItem( "", 2 );
01004         } else {
01005             statusBar()->removeItem( 2 );
01006         }
01007     }
01008 
01009 //InfoBoxes: we only change options here; these are also connected to slots in
01010 //InfoBoxes that actually toggle the display.
01011     if ( sender()->name() == QString( "show_boxes" ) )
01012         Options::setShowInfoBoxes( show );
01013     if ( sender()->name() == QString( "show_time_box" ) )
01014         Options::setShowTimeBox( show );
01015     if ( sender()->name() == QString( "show_location_box" ) )
01016         Options::setShowGeoBox( show );
01017     if ( sender()->name() == QString( "show_focus_box" ) )
01018         Options::setShowFocusBox( show );
01019 }
01020 
01021 void KStars::addColorMenuItem( QString name, QString actionName ) {
01022     colorActionMenu->insert( new KAction( name, 0,
01023             this, SLOT( slotColorScheme() ), actionCollection(), actionName.local8Bit() ) );
01024 }
01025 
01026 void KStars::removeColorMenuItem( QString actionName ) {
01027     kdDebug() << "removing " << actionName << endl;
01028     colorActionMenu->remove( actionCollection()->action( actionName.local8Bit() ) );
01029 }
01030 
01031 void KStars::establishINDI()
01032 {
01033     if (indimenu == NULL)
01034       indimenu = new INDIMenu(this);
01035 
01036     if (indidriver == NULL)
01037       indidriver = new INDIDriver(this);
01038 }
01039 

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