kstarsactions.cpp 51.8 KB
Newer Older
Chris Howells's avatar
adding  
Chris Howells committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/***************************************************************************
                          kstarsactions.cpp  -  K Desktop Planetarium
                             -------------------
    begin                : Mon Feb 25 2002
    copyright            : (C) 2002 by Jason Harris
    email                : jharris@30doradus.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
17 18

//needed in slotRunScript() for chmod() syscall (remote script downloaded to temp file)
Patrick Spendrin's avatar
Patrick Spendrin committed
19 20 21 22 23

#ifdef _WIN32
#include <windows.h>
#undef interface
#endif
24 25
#include <sys/stat.h>

26 27 28
#include <QCheckBox>
#include <QDir>
#include <QTextStream>
29
#include <QDialog>
30
#include <QDockWidget>
31
#include <QPointer>
32
#include <QInputDialog>
33 34
#include <QQuickWindow>
#include <QQuickView>
35
#include <QDebug>
Jasem Mutlaq's avatar
Jasem Mutlaq committed
36 37 38 39 40 41 42
#include <QAction>
#include <QFileDialog>
#include <QMenu>
#include <QStatusBar>
#include <QProcess>
#include <QIcon>
#include <QTemporaryFile>
43
#include <QStandardPaths>
Jasem Mutlaq's avatar
Jasem Mutlaq committed
44

Jasem Mutlaq's avatar
Jasem Mutlaq committed
45 46 47 48
#include <KActionCollection>
#include <KActionMenu>
#include <KToggleAction>
#include <KMessageBox>
49 50
#include <KTipDialog>
#include <KConfigDialog>
Jasem Mutlaq's avatar
Jasem Mutlaq committed
51

Jasem Mutlaq's avatar
Jasem Mutlaq committed
52
#include <kns3/downloaddialog.h>
Chris Howells's avatar
adding  
Chris Howells committed
53

54 55 56
#include "options/opscatalog.h"
#include "options/opsguides.h"
#include "options/opssolarsystem.h"
57
#include "options/opssatellites.h"
58
#include "options/opssupernovae.h"
59 60
#include "options/opscolors.h"
#include "options/opsadvanced.h"
61

62
#include "Options.h"
Chris Howells's avatar
adding  
Chris Howells committed
63
#include "kstars.h"
64
#include "kstarsdata.h"
65
#include "kstarsdatetime.h"
66
#include "skymap.h"
67 68
#include "skyobjects/skyobject.h"
#include "skyobjects/ksplanetbase.h"
69
#include "simclock.h"
70 71 72 73 74
#include "dialogs/timedialog.h"
#include "dialogs/locationdialog.h"
#include "dialogs/finddialog.h"
#include "dialogs/focusdialog.h"
#include "dialogs/fovdialog.h"
75
#include "dialogs/exportimagedialog.h"
76
#include "printing/printingwizard.h"
77
#include "kswizard.h"
78 79 80
#include "tools/astrocalc.h"
#include "tools/altvstime.h"
#include "tools/wutdialog.h"
81
#include "tools/observinglist.h"
82
#include "tools/eyepiecefield.h"
83

84
#ifdef HAVE_KF5WIT
Jasem Mutlaq's avatar
Jasem Mutlaq committed
85 86 87
#include "tools/whatsinteresting/wiview.h"
#include "tools/whatsinteresting/wilpsettings.h"
#include "tools/whatsinteresting/wiequipsettings.h"
88
#endif
89

90
#include "tools/skycalendar.h"
91 92 93
#include "tools/scriptbuilder.h"
#include "tools/planetviewer.h"
#include "tools/jmoontool.h"
94 95
//FIXME Port to KF5
//#include "tools/moonphasetool.h"
96
#include "tools/flagmanager.h"
97
#include "tools/horizonmanager.h"
98
#include "oal/execute.h"
Henry de Valence's avatar
Purge.  
Henry de Valence committed
99
#include "projections/projector.h"
100
#include "imageexporter.h"
101 102

#include <config-kstars.h>
103
#include <KSharedConfig>
104

Jasem Mutlaq's avatar
Jasem Mutlaq committed
105
#ifdef HAVE_INDI
106 107
#include "indi/telescopewizardprocess.h"
#include "indi/opsindi.h"
Jasem Mutlaq's avatar
Jasem Mutlaq committed
108 109
#include "indi/drivermanager.h"
#include "indi/guimanager.h"
110 111
#endif

112
#include "skycomponents/catalogcomponent.h"
113
#include "skycomponents/skymapcomposite.h"
114 115
#include "skycomponents/solarsystemcomposite.h"
#include "skycomponents/cometscomponent.h"
116
#include "skycomponents/asteroidscomponent.h"
117
#include "skycomponents/supernovaecomponent.h"
118
#include "skycomponents/satellitescomponent.h"
119

Jasem Mutlaq's avatar
Jasem Mutlaq committed
120
#ifdef HAVE_CFITSIO
121
#include "fitsviewer/fitsviewer.h"
Jasem Mutlaq's avatar
Jasem Mutlaq committed
122
#ifdef HAVE_INDI
123 124
#include "ekos/ekosmanager.h"
#include "ekos/opsekos.h"
125
#endif
126 127
#endif

128
#ifdef HAVE_XPLANET
129
#include "xplanet/opsxplanet.h"
130 131
#endif

132
// #include "libkdeedu/kdeeduui/kdeeduglossary.h"
133

Chris Howells's avatar
adding  
Chris Howells committed
134 135 136 137 138
//This file contains function definitions for Actions declared in kstars.h

/** ViewToolBar Action.  All of the viewToolBar buttons are connected to this slot. **/

void KStars::slotViewToolBar() {
139
    KToggleAction *a = (KToggleAction*)sender();
140
    KConfigDialog *kcd = KConfigDialog::exists( "settings" );
141 142 143

    if ( a == actionCollection()->action( "show_stars" ) ) {
        Options::setShowStars( a->isChecked() );
144 145 146
        if ( kcd ) {
            opcatalog->kcfg_ShowStars->setChecked( a->isChecked() );
        }
147 148
    } else if ( a == actionCollection()->action( "show_deepsky" ) ) {
        Options::setShowDeepSky( a->isChecked() );
149 150 151
        if ( kcd ) {
            opcatalog->kcfg_ShowDeepSky->setChecked( a->isChecked() );
        }
152 153
    } else if ( a == actionCollection()->action( "show_planets" ) ) {
        Options::setShowSolarSystem( a->isChecked() );
154 155 156
        if ( kcd ) {
            opsolsys->kcfg_ShowSolarSystem->setChecked( a->isChecked() );
        }
157 158
    } else if ( a == actionCollection()->action( "show_clines" ) ) {
        Options::setShowCLines( a->isChecked() );
159 160 161
        if ( kcd ) {
            opguides->kcfg_ShowCLines->setChecked( a->isChecked() );
        }
162 163
    } else if ( a == actionCollection()->action( "show_cnames" ) ) {
        Options::setShowCNames( a->isChecked() );
164 165 166
        if ( kcd ) {
            opguides->kcfg_ShowCNames->setChecked( a->isChecked() );
        }
167 168
    } else if ( a == actionCollection()->action( "show_cbounds" ) ) {
        Options::setShowCBounds( a->isChecked() );
169 170 171
        if ( kcd ) {
            opguides->kcfg_ShowCBounds->setChecked( a->isChecked() );
        }
172 173 174 175 176
    } else if ( a == actionCollection()->action( "show_constellationart" ) ) {
        Options::setShowConstellationArt( a->isChecked() );
        if ( kcd ) {
            opguides->kcfg_ShowConstellationArt->setChecked( a->isChecked() );
        }
177 178
    } else if ( a == actionCollection()->action( "show_mw" ) ) {
        Options::setShowMilkyWay( a->isChecked() );
179 180 181
        if ( kcd ) {
            opguides->kcfg_ShowMilkyWay->setChecked( a->isChecked() );
        }
182
    } else if ( a == actionCollection()->action( "show_equatorial_grid" ) ) {
183 184 185 186
        // if autoSelectGrid is selected and the user clicked the
        // show_equatorial_grid button, he probably wants us to disable
        // the autoSelectGrid and display the equatorial grid.
        Options::setAutoSelectGrid(false);
187
        Options::setShowEquatorialGrid( a->isChecked() );
188
        if ( kcd ) {
189
            opguides->kcfg_ShowEquatorialGrid->setChecked( a->isChecked() );
190
            opguides->kcfg_AutoSelectGrid->setChecked(false);
191
        }
192
    } else if ( a == actionCollection()->action( "show_horizontal_grid" ) ) {
193
        Options::setAutoSelectGrid(false);
194 195 196
        Options::setShowHorizontalGrid( a->isChecked() );
        if ( kcd ) {
            opguides->kcfg_ShowHorizontalGrid->setChecked( a->isChecked() );
197
            opguides->kcfg_AutoSelectGrid->setChecked(false);
198
        }
199 200
    } else if ( a == actionCollection()->action( "show_horizon" ) ) {
        Options::setShowGround( a->isChecked() );
201
        if( !a->isChecked() && Options::useRefraction() ) {
202 203
           QString caption = i18n( "Refraction effects disabled" );
           QString message = i18n( "When the horizon is switched off, refraction effects are temporarily disabled." );
204

205 206
           KMessageBox::information( this, message, caption, "dag_refract_hide_ground" );
        }
207 208 209
        if ( kcd ) {
            opguides->kcfg_ShowGround->setChecked( a->isChecked() );
        }
210 211 212 213 214
    } else if ( a == actionCollection()->action( "show_flags" ) ) {
        Options::setShowFlags( a->isChecked() );
        if ( kcd ) {
            opguides->kcfg_ShowFlags->setChecked( a->isChecked() );
        }
215 216 217 218 219
    } else if ( a == actionCollection()->action( "show_satellites" ) ) {
        Options::setShowSatellites( a->isChecked() );
        if ( kcd ) {
            opssatellites->kcfg_ShowSatellites->setChecked( a->isChecked() );
        }
220 221
    } else if ( a == actionCollection()->action( "show_supernovae" ) ) {
        Options::setShowSupernovae( a->isChecked() );
222 223 224
        if ( kcd ) {
            opssupernovae->kcfg_ShowSupernovae->setChecked ( a->isChecked() ) ;
        }
225 226 227 228 229 230 231 232
    }

    // update time for all objects because they might be not initialized
    // it's needed when using horizontal coordinates
    data()->setFullTimeUpdate();
    updateTime();

    map()->forceUpdate();
Chris Howells's avatar
adding  
Chris Howells committed
233 234
}

235 236 237 238 239 240 241
void KStars::slotINDIToolBar()
{
#ifdef HAVE_INDI
    KToggleAction *a = (KToggleAction*)sender();

    if ( a == actionCollection()->action( "show_device_manager" ) )
    {
242 243 244 245 246 247 248
        if (a->isChecked())
        {
            DriverManager::Instance()->raise();
            DriverManager::Instance()->activateWindow();
            DriverManager::Instance()->showNormal();
        }
        else
249
           DriverManager::Instance()->hide();
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
    }    
    else if ( a == actionCollection()->action( "show_control_panel" ) )
    {
       if (a->isChecked())
       {
           GUIManager::Instance()->raise();
           GUIManager::Instance()->activateWindow();
           GUIManager::Instance()->showNormal();
       }
       else
           GUIManager::Instance()->hide();
    }
    else if ( a == actionCollection()->action( "show_ekos" ) )
    {
       if (a->isChecked())
       {
           ekosManager()->raise();
           ekosManager()->activateWindow();
           ekosManager()->showNormal();
       }
270
       else
271
           ekosManager()->hide();
272
    }
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
    else if ( a == actionCollection()->action( "show_fits_viewer" ) )
    {
       QList<FITSViewer *> viewers = findChildren<FITSViewer *>();

       if (viewers.isEmpty())
       {
           a->setEnabled(false);
           return;
       }

       if (a->isChecked())
       {
           foreach(FITSViewer *view, viewers)
           {
               view->raise();
               view->activateWindow();
               view->showNormal();
           }
       }
       else
       {
           foreach(FITSViewer *view, viewers)
           {
               view->hide();
           }
       }
    }

301 302 303
#endif
}

Chris Howells's avatar
adding  
Chris Howells committed
304 305 306
/** Major Dialog Window Actions **/

void KStars::slotCalculator() {
307 308 309
    if( ! m_AstroCalc )
        m_AstroCalc = new AstroCalc (this);
    m_AstroCalc->show();
310
}
311

312
void KStars::slotWizard() {
313 314
    QPointer<KSWizard> wizard = new KSWizard(this);
    if ( wizard->exec() == QDialog::Accepted ) {
315 316
        Options::setRunStartupWizard( false );  //don't run on startup next time

317
        data()->setLocation( *(wizard->geo()) );
318 319 320

        // adjust local time to keep UT the same.
        // create new LT without DST offset
321
        KStarsDateTime ltime = data()->geo()->UTtoLT( data()->ut() );
322 323

        // reset timezonerule to compute next dst change
324
        data()->geo()->tzrule()->reset_with_ltime( ltime, data()->geo()->TZ0(), data()->isTimeRunningForward() );
325 326

        // reset next dst change time
327
        data()->setNextDSTChange( data()->geo()->tzrule()->nextDSTChange() );
328 329 330 331 332 333 334 335 336

        // reset local sideral time
        data()->syncLST();

        // Make sure Numbers, Moon, planets, and sky objects are updated immediately
        data()->setFullTimeUpdate();

        // If the sky is in Horizontal mode and not tracking, reset focus such that
        // Alt/Az remain constant.
337
        if ( ! Options::isTracking() && Options::useAltAz() ) {
338
            map()->focus()->HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
339 340 341 342 343 344
        }

        // recalculate new times and objects
        data()->setSnapNextFocus();
        updateTime();
    }
345
    delete wizard;
346 347
}

Jason Harris's avatar
Jason Harris committed
348
void KStars::slotDownload() {
349 350
    QPointer<KNS3::DownloadDialog> dlg( new KNS3::DownloadDialog( this ) );
    dlg->exec();
Frederik Gladhorn's avatar
Frederik Gladhorn committed
351 352

    // Get the list of all the installed entries.
353 354
    KNS3::Entry::List installed_entries;
    KNS3::Entry::List changed_entries;
355
    if (dlg) {
356 357
        installed_entries = dlg->installedEntries();
        changed_entries = dlg->changedEntries();
358 359 360
    }

    delete dlg;
Frederik Gladhorn's avatar
Frederik Gladhorn committed
361

362 363 364 365 366 367 368
    foreach (const KNS3::Entry &entry, installed_entries)
    {
        foreach (const QString &name, entry.installedFiles())
        {
            if ( name.endsWith( QLatin1String( ".cat" ) ) )
            {
                data()->catalogdb()->AddCatalogContents(name);
Frederik Gladhorn's avatar
Frederik Gladhorn committed
369
                // To start displaying the custom catalog, add it to SkyMapComposite
370 371 372

                QString catalogName = data()->catalogdb()->GetCatalogName(name);
                Options::setShowCatalogNames(Options::showCatalogNames() << catalogName);
Frederik Gladhorn's avatar
Frederik Gladhorn committed
373 374
                Options::setCatalogFile(Options::catalogFile() << name);
                Options::setShowCatalog(Options::showCatalog() << 1);
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397

            }
        }

        KStars::Instance()->data()->skyComposite()->reloadDeepSky();
        // update time for all objects because they might be not initialized
        // it's needed when using horizontal coordinates
        KStars::Instance()->data()->setFullTimeUpdate();
        KStars::Instance()->updateTime();
        KStars::Instance()->map()->forceUpdate();
    }

    foreach (const KNS3::Entry &entry, changed_entries)
    {
        foreach (const QString &name, entry.uninstalledFiles())
        {
            if ( name.endsWith( QLatin1String( ".cat" ) ) )
            {
                data()->catalogdb()->RemoveCatalog(name);
                // To start displaying the custom catalog, add it to SkyMapComposite
                QStringList catFile = Options::catalogFile();
                catFile.removeOne(name);
                Options::setCatalogFile(catFile);
398 399 400
            }
        }
    }
401
}
Jason Harris's avatar
Jason Harris committed
402

403
void KStars::slotAVT() {
404 405
    if ( ! m_AltVsTime ) m_AltVsTime = new AltVsTime(this);
    m_AltVsTime->show();
406 407
}

408
void KStars::slotWUT() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
409 410
    if ( ! m_WUTDialog ) m_WUTDialog = new WUTDialog(this);
    m_WUTDialog->show();
411
}
412

Jasem Mutlaq's avatar
Jasem Mutlaq committed
413
//FIXME Port to QML2
414
//#if 0
415 416
void KStars::slotWISettings()
{
417
#ifdef HAVE_KF5WIT
Jasem Mutlaq's avatar
Jasem Mutlaq committed
418
    if (m_WIView && !m_wiDock->isVisible())
419 420 421 422 423
    {
        slotShowWIView(1);
        return;
    }

424 425
    if (KConfigDialog::showDialog("wisettings"))
    {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
426
        m_WIEquipmentSettings->populateScopeListWidget();
427 428
        return;
    }
429 430 431

    KConfigDialog* dialog = new KConfigDialog(this, "wisettings", Options::self());

432
    connect(dialog, SIGNAL(settingsChanged(const QString &)), this, SLOT(slotApplyWIConfigChanges()));
433 434
    connect(dialog, SIGNAL(finished(int)), this, SLOT(slotShowWIView(int)));

Jasem Mutlaq's avatar
Jasem Mutlaq committed
435
    m_WISettings = new WILPSettings(this);
436
    m_WIEquipmentSettings = new WIEquipSettings();
437 438
    dialog->addPage(m_WISettings, i18n("Light Pollution Settings"));
    dialog->addPage(m_WIEquipmentSettings, i18n("Equipment Settings - Equipment Type and Parameters"));
439
    dialog->show();
440
#endif
441 442 443 444
}

void KStars::slotShowWIView(int status)
{
445
#ifdef HAVE_KF5WIT
446

447 448
    if (status == 0) return;          //Cancelled

449
    int bortle = Options::bortleClass();
Jasem Mutlaq's avatar
Jasem Mutlaq committed
450
    m_WIEquipmentSettings->setAperture();
451 452 453 454 455 456

    /* NOTE This part of the code dealing with equipment type is presently not required
     * as WI does not differentiate between Telescope and Binoculars. It only needs the
     * aperture of the equipment whichever available. However this is kept as a part of
     * the code as support to be utilised in the future.
     */
457
    ObsConditions::Equipment equip = ObsConditions::None;
458

459 460 461 462 463 464 465 466
    if (Options::telescopeCheck() && Options::binocularsCheck())
        equip = ObsConditions::Both;
    else if (Options::telescopeCheck())
        equip = ObsConditions::Telescope;
    else if (Options::binocularsCheck())
        equip = ObsConditions::Binoculars;

    ObsConditions::TelescopeType telType = (equip == ObsConditions::Telescope) ? m_WIEquipmentSettings->getTelType() : ObsConditions::Invalid;
467

Jasem Mutlaq's avatar
Jasem Mutlaq committed
468
    int aperture = m_WIEquipmentSettings->getAperture();
469

470
    //Update observing conditions for What's Interesting
Jasem Mutlaq's avatar
Jasem Mutlaq committed
471 472
    if (!m_ObsConditions)
        m_ObsConditions = new ObsConditions(bortle, aperture, equip, telType);
473
    else
Jasem Mutlaq's avatar
Jasem Mutlaq committed
474
        m_ObsConditions->setObsConditions(bortle, aperture, equip, telType);
475

Jasem Mutlaq's avatar
Jasem Mutlaq committed
476
    if (!m_WIView)
477
    {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
478 479 480 481 482 483 484 485 486
        m_WIView = new WIView(0, m_ObsConditions);
        m_wiDock = new QDockWidget(this);
        m_wiDock->setObjectName("What's Interesting");
        m_wiDock->setAllowedAreas(Qt::RightDockWidgetArea);
        QWidget *container = QWidget::createWindowContainer(m_WIView->getWIBaseView());
        m_wiDock->setWidget(container);
        m_wiDock->setMinimumWidth(container->width());
        addDockWidget(Qt::RightDockWidgetArea, m_wiDock);
        m_wiDock->setVisible(true);
487 488
    }
    else
489
    {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
490 491
        m_WIView->updateModels(m_ObsConditions);
        m_wiDock->setVisible(true);
492
    }
493

494 495
#endif
}
496

497
void KStars::slotCalendar() {
498 499
    if ( ! m_SkyCalendar ) m_SkyCalendar = new SkyCalendar(this);
    m_SkyCalendar->show();
500 501
}

502
void KStars::slotGlossary(){
503 504
    // 	GlossaryDialog *dlg = new GlossaryDialog( this, true );
    // 	QString glossaryfile =data()->stdDirs->findResource( "data", "kstars/glossary.xml" );
Jasem Mutlaq's avatar
Jasem Mutlaq committed
505
    // 	QUrl u = glossaryfile;
506
    // 	Glossary *g = new Glossary( u );
507
    // 	g->setName( i18n( "Knowledge" ) );
508 509
    // 	dlg->addGlossary( g );
    // 	dlg->show();
510 511
}

512
void KStars::slotScriptBuilder() {
513 514
    if ( ! m_ScriptBuilder ) m_ScriptBuilder = new ScriptBuilder(this);
    m_ScriptBuilder->show();
515
}
516

517
void KStars::slotSolarSystem() {
518 519
    if ( ! m_PlanetViewer ) m_PlanetViewer = new PlanetViewer(this);
    m_PlanetViewer->show();
520 521
}

522
void KStars::slotJMoonTool() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
523 524
    if ( ! m_JMoonTool ) m_JMoonTool = new JMoonTool(this);
    m_JMoonTool->show();
525 526
}

527
void KStars::slotMoonPhaseTool() {
528 529 530
    //FIXME Port to KF5
    //if( ! mpt ) mpt = new MoonPhaseTool( this );
    //mpt->show();
531 532
}

533
void KStars::slotFlagManager() {
534 535
    if ( ! m_FlagManager ) m_FlagManager = new FlagManager(this);
    m_FlagManager->show();
536 537
}

538 539
void KStars::slotTelescopeWizard()
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
540
#ifdef HAVE_INDI
Jasem Mutlaq's avatar
Jasem Mutlaq committed
541
    if (QStandardPaths::findExecutable("indiserver").isEmpty())
542
    {
543
        KMessageBox::error(NULL, i18n("Unable to find INDI server. Please make sure the package that provides the 'indiserver' binary is installed."));
544 545 546
        return;
    }

547 548 549
    QPointer<telescopeWizardProcess> twiz = new telescopeWizardProcess(this);
    twiz->exec();
    delete twiz;
550
#endif
551 552
}

553
void KStars::slotINDIPanel()
554
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
555
#ifdef HAVE_INDI
Jasem Mutlaq's avatar
Jasem Mutlaq committed
556
    if (QStandardPaths::findExecutable("indiserver").isEmpty())
557
    {
558
        KMessageBox::error(NULL, i18n("Unable to find INDI server. Please make sure the package that provides the 'indiserver' binary is installed."));
559 560
        return;
    }
Jasem Mutlaq's avatar
Jasem Mutlaq committed
561
    GUIManager::Instance()->updateStatus();
562
#endif
563 564
}

565
void KStars::slotINDIDriver()
566
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
567
#ifdef HAVE_INDI
Jasem Mutlaq's avatar
Jasem Mutlaq committed
568
    if (QStandardPaths::findExecutable("indiserver").isEmpty())
569
    {
570
        KMessageBox::error(NULL, i18n("Unable to find INDI server. Please make sure the package that provides the 'indiserver' binary is installed."));
571 572 573
        return;
    }

574 575 576 577
    DriverManager::Instance()->raise();
    DriverManager::Instance()->activateWindow();
    DriverManager::Instance()->showNormal();

578
#endif
579 580
}

581 582
void KStars::slotEkos()
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
583 584
#ifdef HAVE_CFITSIO
#ifdef HAVE_INDI
585

Jasem Mutlaq's avatar
Jasem Mutlaq committed
586
    if (QStandardPaths::findExecutable("indiserver").isEmpty())
587
    {
588
        KMessageBox::error(NULL, i18n("Unable to find INDI server. Please make sure the package that provides the 'indiserver' binary is installed."));
589 590 591
        return;
    }

592 593 594
    ekosManager()->raise();
    ekosManager()->activateWindow();
    ekosManager()->showNormal();
595 596

#endif
597
#endif
598 599
}

Chris Howells's avatar
adding  
Chris Howells committed
600
void KStars::slotGeoLocator() {
601 602 603
    QPointer<LocationDialog> locationdialog = new LocationDialog(this);
    if ( locationdialog->exec() == QDialog::Accepted ) {
        GeoLocation *newLocation = locationdialog->selectedCity();
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
        if ( newLocation ) {
            // set new location in options
            data()->setLocation( *newLocation );

            // adjust local time to keep UT the same.
            // create new LT without DST offset
            KStarsDateTime ltime = newLocation->UTtoLT( data()->ut() );

            // reset timezonerule to compute next dst change
            newLocation->tzrule()->reset_with_ltime( ltime, newLocation->TZ0(), data()->isTimeRunningForward() );

            // reset next dst change time
            data()->setNextDSTChange( newLocation->tzrule()->nextDSTChange() );

            // reset local sideral time
            data()->syncLST();

            // Make sure Numbers, Moon, planets, and sky objects are updated immediately
            data()->setFullTimeUpdate();

            // If the sky is in Horizontal mode and not tracking, reset focus such that
            // Alt/Az remain constant.
            if ( ! Options::isTracking() && Options::useAltAz() ) {
627
                map()->focus()->HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
628 629 630 631 632 633 634
            }

            // recalculate new times and objects
            data()->setSnapNextFocus();
            updateTime();
        }
    }
635
    delete locationdialog;
Chris Howells's avatar
adding  
Chris Howells committed
636 637 638
}

void KStars::slotViewOps() {
639 640 641 642 643 644 645 646 647 648 649
    //An instance of your dialog could be already created and could be cached,
    //in which case you want to display the cached dialog instead of creating
    //another one
    if ( KConfigDialog::showDialog( "settings" ) ) return;

    //KConfigDialog didn't find an instance of this dialog, so lets create it :
    KConfigDialog* dialog = new KConfigDialog( this, "settings",
                            Options::self() );

    connect( dialog, SIGNAL( settingsChanged( const QString &) ), this, SLOT( slotApplyConfigChanges() ) );

650 651 652 653 654 655 656
    opcatalog    = new OpsCatalog();
    opguides     = new OpsGuides();
    opsolsys     = new OpsSolarSystem();
    opssatellites= new OpsSatellites();
    opssupernovae= new OpsSupernovae();
    opcolors     = new OpsColors();
    opadvanced   = new OpsAdvanced();
657

658 659 660 661 662 663
    dialog->addPage(opcatalog, i18n("Catalogs"), "kstars_catalog");
    dialog->addPage(opsolsys, i18n("Solar System"), "kstars_solarsystem");
    dialog->addPage(opssatellites, i18n("Satellites"), "kstars_satellites");
    dialog->addPage(opssupernovae, i18n("Supernovae"), "kstars_supernovae");
    dialog->addPage(opguides, i18n("Guides"), "kstars_guides");
    dialog->addPage(opcolors, i18n("Colors"), "kstars_colors");
664

Jasem Mutlaq's avatar
Jasem Mutlaq committed
665
    #ifdef HAVE_INDI
666
    opsindi = new OpsINDI();
667
    dialog->addPage(opsindi, i18n("INDI"), "kstars_indi");
668

Jasem Mutlaq's avatar
Jasem Mutlaq committed
669
    #ifdef HAVE_CFITSIO
670
    opsekos = new OpsEkos();
671
    KPageWidgetItem *ekosOption = dialog->addPage(opsekos, i18n("Ekos"), "kstars_ekos");
672 673
    if (m_EkosManager)
        m_EkosManager->setOptionsWidget(ekosOption);
674 675
    #endif

676 677
    #endif

678 679
#ifdef HAVE_XPLANET
    opsxplanet = new OpsXplanet( this );
680
    dialog->addPage(opsxplanet, i18n("Xplanet"), "kstars_xplanet");
681 682
#endif

683
    dialog->addPage(opadvanced, i18n("Advanced"), "kstars_advanced");
684

685
    dialog->show();
686 687
}

Jason Harris's avatar
Jason Harris committed
688
void KStars::slotApplyConfigChanges() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
689
    Options::self()->save();
690 691

    // If the focus object was a constellation and the sky culture has changed, remove the focus object
692
    if( map()->focusObject() && map()->focusObject()->type() == SkyObject::CONSTELLATION ) {
693
        if( m_KStarsData->skyComposite()->currentCulture() != m_KStarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) || m_KStarsData->skyComposite()->isLocalCNames() != Options::useLocalConstellNames() ) {
694 695 696
            map()->setClickedObject( NULL );
            map()->setFocusObject( NULL );
        }
697 698
    }

699 700 701
    applyConfig();
    data()->setFullTimeUpdate();
    map()->forceUpdate();
702

703 704 705
    m_KStarsData->skyComposite()->setCurrentCulture(  m_KStarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) );
    m_KStarsData->skyComposite()->reloadCLines();
    m_KStarsData->skyComposite()->reloadCNames();
706
    m_KStarsData->skyComposite()->reloadConstellationArt();
Chris Howells's avatar
adding  
Chris Howells committed
707 708
}

709
void KStars::slotApplyWIConfigChanges() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
710
    Options::self()->save();
711 712 713
    applyConfig();
}

Chris Howells's avatar
adding  
Chris Howells committed
714
void KStars::slotSetTime() {
715
    QPointer<TimeDialog> timedialog = new TimeDialog( data()->lt(), data()->geo(), this );
716

717
    if ( timedialog->exec() == QDialog::Accepted ) {
718
        data()->changeDateTime( data()->geo()->LTtoUT( timedialog->selectedDateTime() ) );
719 720 721

        if ( Options::useAltAz() ) {
            if ( map()->focusObject() ) {
722
                map()->focusObject()->EquatorialToHorizontal( data()->lst(), data()->geo()->lat() );
723 724
                map()->setFocus( map()->focusObject() );
            } else
725
                map()->focus()->HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
726 727 728 729 730
        }

        map()->forceUpdateNow();

        //If focusObject has a Planet Trail, clear it and start anew.
731 732 733 734
        KSPlanetBase* planet = dynamic_cast<KSPlanetBase*>( map()->focusObject() );
        if( planet && planet->hasTrail() ) {
            planet->clearTrail();
            planet->addToTrail();
735 736
        }
    }
737
    delete timedialog;
Chris Howells's avatar
adding  
Chris Howells committed
738 739
}

740 741
//Set Time to CPU clock
void KStars::slotSetTimeToNow() {
742
    data()->changeDateTime( KStarsDateTime::currentDateTimeUtc() );
743 744 745

    if ( Options::useAltAz() ) {
        if ( map()->focusObject() ) {
746
            map()->focusObject()->EquatorialToHorizontal( data()->lst(), data()->geo()->lat() );
747 748
            map()->setFocus( map()->focusObject() );
        } else
749
            map()->focus()->HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
750 751 752 753 754
    }

    map()->forceUpdateNow();

    //If focusObject has a Planet Trail, clear it and start anew.
755 756 757 758
    KSPlanetBase* planet = dynamic_cast<KSPlanetBase*>( map()->focusObject() );
    if( planet && planet->hasTrail() ) {
        planet->clearTrail();
        planet->addToTrail();
759
    }
760 761
}

Chris Howells's avatar
adding  
Chris Howells committed
762
void KStars::slotFind() {
763
    clearCachedFindDialog();
764 765
    if ( !m_FindDialog ) {	  // create new dialog if no dialog is existing
        m_FindDialog = new FindDialog( this );
766
    }
Chris Howells's avatar
adding  
Chris Howells committed
767

768
    if ( !m_FindDialog ) qWarning() << i18n( "KStars::slotFind() - Not enough memory for dialog" ) ;
769
    SkyObject *targetObject;
770
    if ( m_FindDialog->exec() == QDialog::Accepted && ( targetObject = m_FindDialog->selectedObject() ) ) {
771
        map()->setClickedObject( targetObject );
772 773 774
        map()->setClickedPoint( map()->clickedObject() );
        map()->slotCenter();
    }
775

776
    // check if data has changed while dialog was open
777 778
    if ( DialogIsObsolete )
        clearCachedFindDialog();
Chris Howells's avatar
adding  
Chris Howells committed
779 780
}

781 782
void KStars::slotOpenFITS()
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
783
#ifdef HAVE_CFITSIO
784

785
    static QUrl path;
786
    QUrl fileURL = QFileDialog::getOpenFileUrl(KStars::Instance(), i18n("Open FITS"), path, "FITS (*.fits *.fit *.fts)");
Jason Harris's avatar
Jason Harris committed
787

788 789
    if (fileURL.isEmpty())
        return;
Jason Harris's avatar
Jason Harris committed
790

791 792 793 794 795 796 797 798
    // Workaround for "/C:/foo/bar" Qt Bug
    // Reported as fixed in Qt 5.6
    // Emerged Qt 5.5 with patch is not working
    #ifdef Q_OS_WIN
    if (fileURL.path().startsWith("/"))
        fileURL.setPath(fileURL.path().right(fileURL.path().count()-1));
    #endif

799 800 801
    // Remember last directory
    path.setUrl(fileURL.path());

802
    FITSViewer * fv = new FITSViewer(this);
803
    // Error opening file
804
    if (fv->addFITS(&fileURL, FITS_NORMAL, FITS_NONE, QString(), false) == -2)
805 806 807
        delete (fv);
    else
       fv->show();
808
#endif
809 810
}

811
void KStars::slotExportImage() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
812
    //TODO Check this
813 814 815
    //For remote files, this returns
    //QFileInfo::absolutePath: QFileInfo::absolutePath: Constructed with empty filename
    //As of 2014-07-19
Jasem Mutlaq's avatar
Jasem Mutlaq committed
816
    //QUrl fileURL = KFileDialog::getSaveUrl( QDir::homePath(), "image/png image/jpeg image/gif image/x-portable-pixmap image/bmp image/svg+xml" );
817
    QUrl fileURL = QFileDialog::getSaveFileUrl(KStars::Instance(), i18n("Export Image"), QUrl(), "Images (*.png *.jpeg *.gif *.bmp *.svg)" );
Jason Harris's avatar
Jason Harris committed
818

819 820 821 822 823
    //User cancelled file selection dialog - abort image export
    if ( fileURL.isEmpty() ) {
        return;
    }

824 825 826
    //Warn user if file exists!
    if (QFile::exists(fileURL.path()))
    {
827
        int r=KMessageBox::warningContinueCancel(parentWidget(),
828 829
                i18n( "A file named \"%1\" already exists. Overwrite it?" , fileURL.fileName()),
                i18n( "Overwrite File?" ),
830
                KStandardGuiItem::overwrite() );
831 832
        if(r == KMessageBox::Cancel)
            return;
833
    }
834

835 836 837
    // execute image export dialog

    // Note: We don't let ExportImageDialog create its own ImageExporter because we want legend settings etc to be remembered between UI use and DBus scripting interface use.
838 839
    //if ( !m_ImageExporter )
        //m_ImageExporter = new ImageExporter( this );
840

841 842
    if ( !m_ExportImageDialog ) {
        m_ExportImageDialog = new ExportImageDialog( fileURL.url(), QSize( map()->width(), map()->height() ), KStarsData::Instance()->imageExporter() );
843
    } else {
844 845
        m_ExportImageDialog->setOutputUrl( fileURL.url() );
        m_ExportImageDialog->setOutputSize( QSize ( map()->width(), map()->height() ) );
846 847
    }

848
    m_ExportImageDialog->show();
849 850
}

851
void KStars::slotRunScript() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
852 853


854
    QUrl fileURL = QFileDialog::getOpenFileUrl(KStars::Instance(), QString(), QUrl(QDir::homePath()), "*.kstars|" + i18nc("Filter by file type: KStars Scripts.", "KStars Scripts (*.kstars)") );
855
    QFile f;
856 857 858 859
    //QString fname;

    if ( fileURL.isValid() )
    {
860

861 862 863 864 865 866 867
        if (fileURL.isLocalFile() == false)
        {
            KMessageBox::sorry(0, i18n("Executing remote scripts is not supported."));
            return;
        }

        /*