kstarsactions.cpp 53.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
#include "tools/adddeepskyobject.h"
84

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

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

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

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

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

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

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

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

Chris Howells's avatar
adding  
Chris Howells committed
135 136 137 138 139
//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() {
140
    KToggleAction *a = (KToggleAction*)sender();
141
    KConfigDialog *kcd = KConfigDialog::exists( "settings" );
142 143 144

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

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

    // 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
234 235
}

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

241
    if ( a == actionCollection()->action( "show_control_panel" ) )
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
    {
       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();
       }
260
       else
261
           ekosManager()->hide();
262
    }
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
    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();
           }
       }
    }

291 292 293
#endif
}

Chris Howells's avatar
adding  
Chris Howells committed
294 295 296
/** Major Dialog Window Actions **/

void KStars::slotCalculator() {
297 298 299
    if( ! m_AstroCalc )
        m_AstroCalc = new AstroCalc (this);
    m_AstroCalc->show();
300
}
301

302
void KStars::slotWizard() {
303 304
    QPointer<KSWizard> wizard = new KSWizard(this);
    if ( wizard->exec() == QDialog::Accepted ) {
305 306
        Options::setRunStartupWizard( false );  //don't run on startup next time

307
        data()->setLocation( *(wizard->geo()) );
308 309 310

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

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

        // reset next dst change time
317
        data()->setNextDSTChange( data()->geo()->tzrule()->nextDSTChange() );
318 319 320 321 322 323 324 325 326

        // 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.
327
        if ( ! Options::isTracking() && Options::useAltAz() ) {
328
            map()->focus()->HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
329 330 331 332 333 334
        }

        // recalculate new times and objects
        data()->setSnapNextFocus();
        updateTime();
    }
335
    delete wizard;
336 337
}

Jason Harris's avatar
Jason Harris committed
338
void KStars::slotDownload() {
339 340
    QPointer<KNS3::DownloadDialog> dlg( new KNS3::DownloadDialog( this ) );
    dlg->exec();
Frederik Gladhorn's avatar
Frederik Gladhorn committed
341 342

    // Get the list of all the installed entries.
343 344
    KNS3::Entry::List installed_entries;
    KNS3::Entry::List changed_entries;
345
    if (dlg) {
346 347
        installed_entries = dlg->installedEntries();
        changed_entries = dlg->changedEntries();
348 349 350
    }

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

352 353 354 355 356 357 358
    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
359
                // To start displaying the custom catalog, add it to SkyMapComposite
360 361 362

                QString catalogName = data()->catalogdb()->GetCatalogName(name);
                Options::setShowCatalogNames(Options::showCatalogNames() << catalogName);
Frederik Gladhorn's avatar
Frederik Gladhorn committed
363 364
                Options::setCatalogFile(Options::catalogFile() << name);
                Options::setShowCatalog(Options::showCatalog() << 1);
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387

            }
        }

        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);
388 389 390
            }
        }
    }
391
}
Jason Harris's avatar
Jason Harris committed
392

393
void KStars::slotAVT() {
394 395
    if ( ! m_AltVsTime ) m_AltVsTime = new AltVsTime(this);
    m_AltVsTime->show();
396 397
}

398
void KStars::slotWUT() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
399 400
    if ( ! m_WUTDialog ) m_WUTDialog = new WUTDialog(this);
    m_WUTDialog->show();
401
}
402

Jasem Mutlaq's avatar
Jasem Mutlaq committed
403
//FIXME Port to QML2
404
//#if 0
405 406
void KStars::slotWISettings()
{
407
#ifdef HAVE_KF5WIT
Jasem Mutlaq's avatar
Jasem Mutlaq committed
408
    if (m_WIView && !m_wiDock->isVisible())
409 410 411 412 413
    {
        slotShowWIView(1);
        return;
    }

414 415
    if (KConfigDialog::showDialog("wisettings"))
    {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
416
        m_WIEquipmentSettings->populateScopeListWidget();
417 418
        return;
    }
419 420 421

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

422
    connect(dialog, SIGNAL(settingsChanged(const QString &)), this, SLOT(slotApplyWIConfigChanges()));
423 424
    connect(dialog, SIGNAL(finished(int)), this, SLOT(slotShowWIView(int)));

Jasem Mutlaq's avatar
Jasem Mutlaq committed
425
    m_WISettings = new WILPSettings(this);
426
    m_WIEquipmentSettings = new WIEquipSettings();
427 428
    dialog->addPage(m_WISettings, i18n("Light Pollution Settings"));
    dialog->addPage(m_WIEquipmentSettings, i18n("Equipment Settings - Equipment Type and Parameters"));
429
    dialog->show();
430
#endif
431 432 433 434
}

void KStars::slotShowWIView(int status)
{
435
#ifdef HAVE_KF5WIT
436

437 438
    if (status == 0) return;          //Cancelled

439
    int bortle = Options::bortleClass();
Jasem Mutlaq's avatar
Jasem Mutlaq committed
440
    m_WIEquipmentSettings->setAperture();
441 442 443 444 445 446

    /* 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.
     */
447
    ObsConditions::Equipment equip = ObsConditions::None;
448

449 450 451 452 453 454 455 456
    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;
457

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

460
    //Update observing conditions for What's Interesting
Jasem Mutlaq's avatar
Jasem Mutlaq committed
461 462
    if (!m_ObsConditions)
        m_ObsConditions = new ObsConditions(bortle, aperture, equip, telType);
463
    else
Jasem Mutlaq's avatar
Jasem Mutlaq committed
464
        m_ObsConditions->setObsConditions(bortle, aperture, equip, telType);
465

Jasem Mutlaq's avatar
Jasem Mutlaq committed
466
    if (!m_WIView)
467
    {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
468 469 470 471 472 473 474 475 476
        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);
477 478
    }
    else
479
    {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
480 481
        m_WIView->updateModels(m_ObsConditions);
        m_wiDock->setVisible(true);
482
    }
483

484 485
#endif
}
486

487
void KStars::slotCalendar() {
488 489
    if ( ! m_SkyCalendar ) m_SkyCalendar = new SkyCalendar(this);
    m_SkyCalendar->show();
490 491
}

492
void KStars::slotGlossary(){
493 494
    // 	GlossaryDialog *dlg = new GlossaryDialog( this, true );
    // 	QString glossaryfile =data()->stdDirs->findResource( "data", "kstars/glossary.xml" );
Jasem Mutlaq's avatar
Jasem Mutlaq committed
495
    // 	QUrl u = glossaryfile;
496
    // 	Glossary *g = new Glossary( u );
497
    // 	g->setName( i18n( "Knowledge" ) );
498 499
    // 	dlg->addGlossary( g );
    // 	dlg->show();
500 501
}

502
void KStars::slotScriptBuilder() {
503 504
    if ( ! m_ScriptBuilder ) m_ScriptBuilder = new ScriptBuilder(this);
    m_ScriptBuilder->show();
505
}
506

507
void KStars::slotSolarSystem() {
508 509
    if ( ! m_PlanetViewer ) m_PlanetViewer = new PlanetViewer(this);
    m_PlanetViewer->show();
510 511
}

512
void KStars::slotJMoonTool() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
513 514
    if ( ! m_JMoonTool ) m_JMoonTool = new JMoonTool(this);
    m_JMoonTool->show();
515 516
}

517
void KStars::slotMoonPhaseTool() {
518 519 520
    //FIXME Port to KF5
    //if( ! mpt ) mpt = new MoonPhaseTool( this );
    //mpt->show();
521 522
}

523
void KStars::slotFlagManager() {
524 525
    if ( ! m_FlagManager ) m_FlagManager = new FlagManager(this);
    m_FlagManager->show();
526 527
}

528 529
void KStars::slotTelescopeWizard()
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
530
#ifdef HAVE_INDI
531
    #ifndef Q_OS_WIN
Jasem Mutlaq's avatar
Jasem Mutlaq committed
532
    if (QStandardPaths::findExecutable("indiserver").isEmpty())
533
    {
534
        KMessageBox::error(NULL, i18n("Unable to find INDI server. Please make sure the package that provides the 'indiserver' binary is installed."));
535 536
        return;
    }
537
    #endif
538

539 540 541
    QPointer<telescopeWizardProcess> twiz = new telescopeWizardProcess(this);
    twiz->exec();
    delete twiz;
542
#endif
543 544
}

545
void KStars::slotINDIPanel()
546
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
547
#ifdef HAVE_INDI
548
    #ifndef Q_OS_WIN
Jasem Mutlaq's avatar
Jasem Mutlaq committed
549
    if (QStandardPaths::findExecutable("indiserver").isEmpty())
550
    {
551
        KMessageBox::error(NULL, i18n("Unable to find INDI server. Please make sure the package that provides the 'indiserver' binary is installed."));
552 553
        return;
    }
554
    #endif
Jasem Mutlaq's avatar
Jasem Mutlaq committed
555
    GUIManager::Instance()->updateStatus();
556
#endif
557 558
}

559
void KStars::slotINDIDriver()
560
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
561
#ifdef HAVE_INDI
562
    #ifndef Q_OS_WIN
Jasem Mutlaq's avatar
Jasem Mutlaq committed
563
    if (QStandardPaths::findExecutable("indiserver").isEmpty())
564
    {
565
        KMessageBox::error(NULL, i18n("Unable to find INDI server. Please make sure the package that provides the 'indiserver' binary is installed."));
566 567
        return;
    }
568
    #endif
569

570 571 572 573
    DriverManager::Instance()->raise();
    DriverManager::Instance()->activateWindow();
    DriverManager::Instance()->showNormal();

574
#endif
575 576
}

577 578
void KStars::slotEkos()
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
579 580
#ifdef HAVE_CFITSIO
#ifdef HAVE_INDI
581

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

590 591 592
    ekosManager()->raise();
    ekosManager()->activateWindow();
    ekosManager()->showNormal();
593 594

#endif
595
#endif
596 597
}

Chris Howells's avatar
adding  
Chris Howells committed
598
void KStars::slotGeoLocator() {
599 600 601
    QPointer<LocationDialog> locationdialog = new LocationDialog(this);
    if ( locationdialog->exec() == QDialog::Accepted ) {
        GeoLocation *newLocation = locationdialog->selectedCity();
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
        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() ) {
625
                map()->focus()->HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
626 627 628 629 630 631 632
            }

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

void KStars::slotViewOps() {
637 638 639 640 641 642 643 644
    //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() );
645
    #ifdef Q_OS_OSX
646
        dialog->setWindowFlags(Qt::Tool| Qt::WindowStaysOnTopHint);
647
    #endif
648 649 650

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

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

659 660 661
    KPageWidgetItem *page;
    
    page = dialog->addPage(opcatalog, i18n("Catalogs"), "kstars_catalog");
662
    page->setIcon(QIcon::fromTheme("kstars_catalog", QIcon(":/icons/breeze/default/kstars_catalog.svg")));
663 664
                         
    page = dialog->addPage(opsolsys, i18n("Solar System"), "kstars_solarsystem");
665
    page->setIcon(QIcon::fromTheme("kstars_solarsystem", QIcon(":/icons/breeze/default/kstars_solarsystem.svg")));
666 667
    
    page = dialog->addPage(opssatellites, i18n("Satellites"), "kstars_satellites");
668
    page->setIcon(QIcon::fromTheme("kstars_satellites", QIcon(":/icons/breeze/default/kstars_satellites.svg")));
669 670
    
    page = dialog->addPage(opssupernovae, i18n("Supernovae"), "kstars_supernovae");
671
    page->setIcon(QIcon::fromTheme("kstars_supernovae", QIcon(":/icons/breeze/default/kstars_supernovae.svg")));
672 673
    
    page = dialog->addPage(opguides, i18n("Guides"), "kstars_guides");
674
    page->setIcon(QIcon::fromTheme("kstars_guides", QIcon(":/icons/breeze/default/kstars_guides.svg")));
675 676
    
    page = dialog->addPage(opcolors, i18n("Colors"), "kstars_colors");
677
    page->setIcon(QIcon::fromTheme("kstars_colors", QIcon(":/icons/breeze/default/kstars_colors.svg")));
678

Jasem Mutlaq's avatar
Jasem Mutlaq committed
679
    #ifdef HAVE_INDI
680
    opsindi = new OpsINDI();
681
    page= dialog->addPage(opsindi, i18n("INDI"), "kstars_indi");
682
    page->setIcon(QIcon::fromTheme("kstars_indi", QIcon(":/icons/breeze/default/kstars_indi.svg")));
683

Jasem Mutlaq's avatar
Jasem Mutlaq committed
684
    #ifdef HAVE_CFITSIO
685
    opsekos = new OpsEkos();
686
    KPageWidgetItem *ekosOption = dialog->addPage(opsekos, i18n("Ekos"), "kstars_ekos");
687
    ekosOption->setIcon(QIcon::fromTheme("kstars_ekos", QIcon(":/icons/breeze/default/kstars_ekos.svg")));
688 689
    if (m_EkosManager)
        m_EkosManager->setOptionsWidget(ekosOption);
690 691
    #endif

692 693
    #endif

694 695
#ifdef HAVE_XPLANET
    opsxplanet = new OpsXplanet( this );
696
    page = dialog->addPage(opsxplanet, i18n("Xplanet"), "kstars_xplanet");
697
    page->setIcon(QIcon::fromTheme("kstars_xplanet", QIcon(":/icons/breeze/default/kstars_xplanet.svg")));
698 699
#endif

700
    page=dialog->addPage(opadvanced, i18n("Advanced"), "kstars_advanced");
701
    page->setIcon(QIcon::fromTheme("kstars_advanced", QIcon(":/icons/breeze/default/kstars_advanced.svg")));
702

703
    dialog->show();
704 705
}

Jason Harris's avatar
Jason Harris committed
706
void KStars::slotApplyConfigChanges() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
707
    Options::self()->save();
708 709

    // If the focus object was a constellation and the sky culture has changed, remove the focus object
710
    if( map()->focusObject() && map()->focusObject()->type() == SkyObject::CONSTELLATION ) {
711
        if( m_KStarsData->skyComposite()->currentCulture() != m_KStarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) || m_KStarsData->skyComposite()->isLocalCNames() != Options::useLocalConstellNames() ) {
712 713 714
            map()->setClickedObject( NULL );
            map()->setFocusObject( NULL );
        }
715 716
    }

717 718 719
    applyConfig();
    data()->setFullTimeUpdate();
    map()->forceUpdate();
720

721 722 723
    m_KStarsData->skyComposite()->setCurrentCulture(  m_KStarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) );
    m_KStarsData->skyComposite()->reloadCLines();
    m_KStarsData->skyComposite()->reloadCNames();
724
    m_KStarsData->skyComposite()->reloadConstellationArt();
Chris Howells's avatar
adding  
Chris Howells committed
725 726
}

727
void KStars::slotApplyWIConfigChanges() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
728
    Options::self()->save();
729 730 731
    applyConfig();
}

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

735
    if ( timedialog->exec() == QDialog::Accepted ) {
736
        data()->changeDateTime( data()->geo()->LTtoUT( timedialog->selectedDateTime() ) );
737 738 739

        if ( Options::useAltAz() ) {
            if ( map()->focusObject() ) {
740
                map()->focusObject()->EquatorialToHorizontal( data()->lst(), data()->geo()->lat() );
741 742
                map()->setFocus( map()->focusObject() );
            } else
743
                map()->focus()->HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
744 745 746 747 748
        }

        map()->forceUpdateNow();

        //If focusObject has a Planet Trail, clear it and start anew.
749 750 751 752
        KSPlanetBase* planet = dynamic_cast<KSPlanetBase*>( map()->focusObject() );
        if( planet && planet->hasTrail() ) {
            planet->clearTrail();
            planet->addToTrail();
753 754
        }
    }
755
    delete timedialog;
Chris Howells's avatar
adding  
Chris Howells committed
756 757
}

758 759
//Set Time to CPU clock
void KStars::slotSetTimeToNow() {
760
    data()->changeDateTime( KStarsDateTime::currentDateTimeUtc() );
761 762 763

    if ( Options::useAltAz() ) {
        if ( map()->focusObject() ) {
764
            map()->focusObject()->EquatorialToHorizontal( data()->lst(), data()->geo()->lat() );
765 766
            map()->setFocus( map()->focusObject() );
        } else
767
            map()->focus()->HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
768 769 770 771 772
    }

    map()->forceUpdateNow();

    //If focusObject has a Planet Trail, clear it and start anew.
773 774 775 776
    KSPlanetBase* planet = dynamic_cast<KSPlanetBase*>( map()->focusObject() );
    if( planet && planet->hasTrail() ) {
        planet->clearTrail();
        planet->addToTrail();
777
    }
778 779
}

Chris Howells's avatar
adding  
Chris Howells committed
780
void KStars::slotFind() {
781
    clearCachedFindDialog();
782 783
    if ( !m_FindDialog ) {	  // create new dialog if no dialog is existing
        m_FindDialog = new FindDialog( this );
784
    }
Chris Howells's avatar
adding  
Chris Howells committed
785

786
    if ( !m_FindDialog ) qWarning() << i18n( "KStars::slotFind() - Not enough memory for dialog" ) ;
787
    SkyObject *targetObject;
788
    if ( m_FindDialog->exec() == QDialog::Accepted && ( targetObject = m_FindDialog->targetObject() ) ) {
789
        map()->setClickedObject( targetObject );
790 791 792
        map()->setClickedPoint( map()->clickedObject() );
        map()->slotCenter();
    }
793

794
    // check if data has changed while dialog was open
795 796
    if ( DialogIsObsolete )
        clearCachedFindDialog();
Chris Howells's avatar
adding  
Chris Howells committed
797 798
}

799 800
void KStars::slotOpenFITS()
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
801
#ifdef HAVE_CFITSIO
802

803
    static QUrl path = QUrl::fromLocalFile(QDir::homePath());
804
    QUrl fileURL = QFileDialog::getOpenFileUrl(KStars::Instance(), i18n("Open FITS"), path, "FITS (*.fits *.fit *.fts)");
Jason Harris's avatar
Jason Harris committed
805

806 807
    if (fileURL.isEmpty())
        return;
Jason Harris's avatar
Jason Harris committed
808

809 810 811 812
    // 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
813 814
    if (fileURL.toLocalFile().startsWith("/"))
        fileURL.setPath(fileURL.toLocalFile().right(fileURL.toLocalFile().count()-1));
815 816
    #endif

817
    // Remember last directory
818
    path.setUrl(fileURL.toLocalFile());
819

820
    FITSViewer * fv = new FITSViewer((Options::independentWindowFITS()) ? NULL : this);
821
    // Error opening file
822
    if (fv->addFITS(&fileURL, FITS_NORMAL, FITS_NONE, QString(), false) == -2)
823 824 825
        delete (fv);
    else
       fv->show();
826
#endif
827 828
}

829
void KStars::slotExportImage() {
Jasem Mutlaq's avatar
Jasem Mutlaq committed
830
    //TODO Check this
831 832 833
    //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
834
    //QUrl fileURL = KFileDialog::getSaveUrl( QDir::homePath(), "image/png image/jpeg image/gif image/x-portable-pixmap image/bmp image/svg+xml" );
835