Commit 02b0c74b authored by Jasem Mutlaq's avatar Jasem Mutlaq
Browse files

Bit of refactoring, EkosManager is back to KStars class since it is not data-oriented

parent c649c587
......@@ -29,9 +29,8 @@
#include <QTemporaryFile>
#include <QtSvg/QSvgGenerator>
ImageExporter::ImageExporter( QObject *parent ) : QObject( parent ), m_KStars( KStars::Instance() ), m_includeLegend( false ), m_Size( 0 )
ImageExporter::ImageExporter( QObject *parent ) : QObject( parent ), m_includeLegend( false ), m_Size( 0 )
{
Q_ASSERT( m_KStars );
m_Legend = new Legend;
// set font for legend labels
......@@ -43,7 +42,7 @@ ImageExporter::ImageExporter( QObject *parent ) : QObject( parent ), m_KStars( K
void ImageExporter::exportSvg(const QString &fileName)
{
SkyMap *map = m_KStars->map();
SkyMap *map = SkyMap::Instance();
// export as SVG
QSvgGenerator svgGenerator;
......@@ -54,7 +53,7 @@ void ImageExporter::exportSvg(const QString &fileName)
svgGenerator.setResolution(qMax(map->logicalDpiX(), map->logicalDpiY()));
svgGenerator.setViewBox(QRect(0, 0, map->width(), map->height()));
SkyQPainter painter(m_KStars, &svgGenerator);
SkyQPainter painter(KStars::Instance(), &svgGenerator);
painter.begin();
map->exportSkyImage(&painter);
......@@ -85,7 +84,7 @@ bool ImageExporter::exportRasterGraphics(const QString &fileName)
qWarning() << xi18n("Could not parse image format of %1; assuming PNG.", fileName);
}
SkyMap *map = m_KStars->map();
SkyMap *map = SkyMap::Instance();
int width, height;
if ( m_Size ) {
......@@ -171,7 +170,7 @@ void ImageExporter::addLegend(SkyQPainter *painter)
void ImageExporter::addLegend(QPaintDevice *pd)
{
SkyQPainter painter(m_KStars, pd);
SkyQPainter painter(KStars::Instance(), pd);
painter.begin();
addLegend(&painter);
......
......@@ -102,7 +102,6 @@ private:
void addLegend(SkyQPainter *painter);
void addLegend(QPaintDevice *pd);
KStars *m_KStars;
bool m_includeLegend;
Legend *m_Legend;
QSize *m_Size;
......
......@@ -40,7 +40,7 @@ OpsEkos::~OpsEkos() {}
void OpsEkos::slotApply()
{
EkosManager *ekosManager = KStarsData::Instance()->ekosManager();
EkosManager *ekosManager = KStars::Instance()->ekosManager();
if (ekosManager)
ekosManager->refreshRemoteDrivers();
......
......@@ -1164,7 +1164,7 @@ void CCD::processBLOB(IBLOB* bp)
if ((targetChip->isBatchMode() && targetChip->getCaptureMode() == FITS_NORMAL) || Options::showFITS() == false)
KStars::Instance()->statusBar()->showMessage( xi18n("%1 file saved to %2", QString(fmt).toUpper(), filename ), 0);
if (Options::playFITSAlarm() && KStarsData::Instance()->ekosManager())
if (Options::playFITSAlarm())
KSNotify::play(KSNotify::NOTIFY_FILE_RECEIVED);
if (targetChip->showFITS() == false && targetChip->getCaptureMode() == FITS_NORMAL)
......
......@@ -46,16 +46,17 @@
#ifdef HAVE_INDI
#include "indi/drivermanager.h"
#include "ekos/ekosmanager.h"
#endif
KStars *KStars::pinstance = 0;
KStars::KStars( bool doSplash, bool clockrun, const QString &startdate )
: KXmlGuiWindow(), kstarsData(0), skymap(0), TimeStep(0),
colorActionMenu(0), fovActionMenu(0), findDialog(0),
imgExportDialog(0), imageExporter(0),
m_altVsTime(0), m_WUTDialog(0), m_WIView(0), m_ObsConditions(0), m_wiDock(0), m_skyCalender(0),
m_scriptBuilder(0), m_planetViewer(0), m_JMoonTool(0), m_moonPhaseTool(0), m_flagManager(0), astrocalc(0), m_printingWizard(0),
: KXmlGuiWindow(), colorActionMenu(0), fovActionMenu(0), m_KStarsData(0), m_SkyMap(0), m_TimeStepBox(0),
m_ExportImageDialog(0), m_PrintingWizard(0), m_FindDialog(0),
m_AstroCalc(0), m_AltVsTime(0), m_SkyCalendar(0), m_ScriptBuilder(0),
m_PlanetViewer(0), m_JMoonTool(0), m_MoonPhaseTool(0), m_FlagManager(0),
m_WUTDialog(0), m_WIView(0), m_ObsConditions(0), m_wiDock(0),
DialogIsObsolete(false), StartClockRunning( clockrun ),
StartDateString( startdate )
{
......@@ -63,6 +64,10 @@ KStars::KStars( bool doSplash, bool clockrun, const QString &startdate )
QDBusConnection::sessionBus().registerObject("/KStars", this);
QDBusConnection::sessionBus().registerService("org.kde.kstars");
#ifdef HAVE_INDI
m_EkosManager = NULL;
#endif
// Set pinstance to yourself
pinstance = this;
......@@ -72,10 +77,10 @@ KStars::KStars( bool doSplash, bool clockrun, const QString &startdate )
projectionGroup = new QActionGroup( this );
cschemeGroup = new QActionGroup( this );
kstarsData = KStarsData::Create();
Q_ASSERT( kstarsData );
m_KStarsData = KStarsData::Create();
Q_ASSERT( m_KStarsData );
//Set Geographic Location from Options
kstarsData->setLocationFromOptions();
m_KStarsData->setLocationFromOptions();
//Initialize Time and Date
KStarsDateTime startDate = KStarsDateTime::fromString( StartDateString );
......@@ -92,10 +97,10 @@ KStars::KStars( bool doSplash, bool clockrun, const QString &startdate )
KStarsSplash *splash = 0;
if ( doSplash ) {
splash = new KStarsSplash(0);
connect( kstarsData, SIGNAL( progressText(QString) ), splash, SLOT( setMessage(QString) ));
connect( m_KStarsData, SIGNAL( progressText(QString) ), splash, SLOT( setMessage(QString) ));
splash->show();
} else {
connect( kstarsData, SIGNAL( progressText(QString) ), kstarsData, SLOT( slotConsoleMessage(QString) ) );
connect( m_KStarsData, SIGNAL( progressText(QString) ), m_KStarsData, SLOT( slotConsoleMessage(QString) ) );
}
//set up Dark color scheme for application windows
......@@ -110,7 +115,7 @@ KStars::KStars( bool doSplash, bool clockrun, const QString &startdate )
OriginalPalette = QApplication::palette();
//Initialize data. When initialization is complete, it will run dataInitFinished()
if( !kstarsData->initialize() )
if( !m_KStarsData->initialize() )
return;
delete splash;
datainitFinished();
......@@ -136,9 +141,10 @@ KStars::~KStars()
#ifdef HAVE_INDI
DriverManager::Instance()->clearServers();
delete m_EkosManager;
#endif
delete kstarsData;
delete m_KStarsData;
pinstance = 0;
QSqlDatabase::removeDatabase("userdb");
......@@ -146,11 +152,11 @@ KStars::~KStars()
}
void KStars::clearCachedFindDialog() {
if ( findDialog ) { // dialog is cached
if ( m_FindDialog ) { // dialog is cached
/** Delete findDialog only if it is not opened */
if ( findDialog->isHidden() ) {
delete findDialog;
findDialog = 0;
if ( m_FindDialog->isHidden() ) {
delete m_FindDialog;
m_FindDialog = 0;
DialogIsObsolete = false;
}
else
......@@ -194,7 +200,7 @@ void KStars::applyConfig( bool doApplyFocus ) {
statusBar()->setVisible( Options::showStatusBar() );
//color scheme
kstarsData->colorScheme()->loadFromConfig();
m_KStarsData->colorScheme()->loadFromConfig();
QApplication::setPalette( Options::darkAppColors() ? DarkPalette : OriginalPalette );
//Set toolbar options from config file
......@@ -224,8 +230,8 @@ void KStars::applyConfig( bool doApplyFocus ) {
}
void KStars::showImgExportDialog() {
if(imgExportDialog)
imgExportDialog->show();
if(m_ExportImageDialog)
m_ExportImageDialog->show();
}
void KStars::syncFOVActions() {
......@@ -355,3 +361,15 @@ void KStars::updateTime( const bool automaticDSTchange ) {
QTimer::singleShot( 0, Data->clock(), SLOT( manualTick() ) );
}
}
#ifdef HAVE_INDI
EkosManager *KStars::ekosManager()
{
if (!m_EkosManager)
m_EkosManager = new EkosManager();
return m_EkosManager;
}
#endif
......@@ -56,6 +56,7 @@ class ObserverAdd;
class Execute;
class ExportImageDialog;
class PrintingWizard;
class EkosManager;
class OpsCatalog;
class OpsGuides;
......@@ -118,14 +119,18 @@ public:
virtual ~KStars();
/** @return pointer to KStarsData object which contains application data. */
inline KStarsData* data() const { return kstarsData; }
inline KStarsData* data() const { return m_KStarsData; }
/** @return pointer to SkyMap object which is the sky display widget. */
inline SkyMap* map() const { return skymap; }
inline SkyMap* map() const { return m_SkyMap; }
inline FlagManager* flagManager() const { return m_flagManager; }
inline FlagManager* flagManager() const { return m_FlagManager; }
inline PrintingWizard* printingWizard() const { return m_printingWizard; }
inline PrintingWizard* printingWizard() const { return m_PrintingWizard; }
#ifdef HAVE_INDI
EkosManager *ekosManager();
#endif
/** Add an item to the color-scheme action manu
* @param name The name to use in the menu
......@@ -597,35 +602,44 @@ private:
/** Build the KStars main window */
void buildGUI();
KStarsData *kstarsData;
SkyMap *skymap;
KActionMenu *colorActionMenu, *fovActionMenu;
TimeStepBox *TimeStep;
KStarsData *m_KStarsData;
SkyMap *m_SkyMap;
KActionMenu *colorActionMenu, *fovActionMenu;
// Widgets
TimeStepBox *m_TimeStepBox;
FindDialog *findDialog;
ExportImageDialog *imgExportDialog;
ImageExporter *imageExporter;
// Dialogs & Tools
//FIXME: move to KStarsData
// File Menu
ExportImageDialog *m_ExportImageDialog;
PrintingWizard *m_PrintingWizard;
// Pointing Menu
FindDialog *m_FindDialog;
AltVsTime *m_altVsTime;
// Tool Menu
AstroCalc *m_AstroCalc;
AltVsTime *m_AltVsTime;
SkyCalendar *m_SkyCalendar;
ScriptBuilder *m_ScriptBuilder;
PlanetViewer *m_PlanetViewer;
JMoonTool *m_JMoonTool;
MoonPhaseTool *m_MoonPhaseTool;
FlagManager *m_FlagManager;
#ifdef HAVE_INDI
EkosManager *m_EkosManager;
#endif
// FIXME Port to QML2
WUTDialog *m_WUTDialog;
WIView *m_WIView;
WILPSettings *m_WISettings;
WIEquipSettings *m_WIEquipmentSettings;
ObsConditions *m_ObsConditions;
QDockWidget *m_wiDock;
SkyCalendar *m_skyCalender;
ScriptBuilder *m_scriptBuilder;
PlanetViewer *m_planetViewer;
JMoonTool *m_JMoonTool;
MoonPhaseTool *m_moonPhaseTool;
FlagManager *m_flagManager;
AstroCalc *astrocalc;
PrintingWizard *m_printingWizard;
QActionGroup *projectionGroup, *cschemeGroup;
......
......@@ -223,9 +223,9 @@ void KStars::slotViewToolBar() {
/** Major Dialog Window Actions **/
void KStars::slotCalculator() {
if( ! astrocalc )
astrocalc = new AstroCalc (this);
astrocalc->show();
if( ! m_AstroCalc )
m_AstroCalc = new AstroCalc (this);
m_AstroCalc->show();
}
void KStars::slotWizard() {
......@@ -320,8 +320,8 @@ void KStars::slotDownload() {
}
void KStars::slotAVT() {
if ( ! m_altVsTime ) m_altVsTime = new AltVsTime(this);
m_altVsTime->show();
if ( ! m_AltVsTime ) m_AltVsTime = new AltVsTime(this);
m_AltVsTime->show();
}
void KStars::slotWUT() {
......@@ -404,8 +404,8 @@ void KStars::slotShowWIView(int status)
}
void KStars::slotCalendar() {
if ( ! m_skyCalender ) m_skyCalender = new SkyCalendar(this);
m_skyCalender->show();
if ( ! m_SkyCalendar ) m_SkyCalendar = new SkyCalendar(this);
m_SkyCalendar->show();
}
void KStars::slotGlossary(){
......@@ -419,13 +419,13 @@ void KStars::slotGlossary(){
}
void KStars::slotScriptBuilder() {
if ( ! m_scriptBuilder ) m_scriptBuilder = new ScriptBuilder(this);
m_scriptBuilder->show();
if ( ! m_ScriptBuilder ) m_ScriptBuilder = new ScriptBuilder(this);
m_ScriptBuilder->show();
}
void KStars::slotSolarSystem() {
if ( ! m_planetViewer ) m_planetViewer = new PlanetViewer(this);
m_planetViewer->show();
if ( ! m_PlanetViewer ) m_PlanetViewer = new PlanetViewer(this);
m_PlanetViewer->show();
}
void KStars::slotJMoonTool() {
......@@ -440,8 +440,8 @@ void KStars::slotMoonPhaseTool() {
}
void KStars::slotFlagManager() {
if ( ! m_flagManager ) m_flagManager = new FlagManager(this);
m_flagManager->show();
if ( ! m_FlagManager ) m_FlagManager = new FlagManager(this);
m_FlagManager->show();
}
void KStars::slotTelescopeWizard()
......@@ -495,7 +495,7 @@ void KStars::slotEkos()
return;
}
EkosManager *m_ekosManager = KStarsData::Instance()->ekosManager();
EkosManager *m_ekosManager = KStars::Instance()->ekosManager();
m_ekosManager->show();
m_ekosManager->raise();
......@@ -595,7 +595,7 @@ void KStars::slotApplyConfigChanges() {
// If the focus object was a constellation and the sky culture has changed, remove the focus object
if( map()->focusObject() && map()->focusObject()->type() == SkyObject::CONSTELLATION ) {
if( kstarsData->skyComposite()->currentCulture() != kstarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) || kstarsData->skyComposite()->isLocalCNames() != Options::useLocalConstellNames() ) {
if( m_KStarsData->skyComposite()->currentCulture() != m_KStarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) || m_KStarsData->skyComposite()->isLocalCNames() != Options::useLocalConstellNames() ) {
map()->setClickedObject( NULL );
map()->setFocusObject( NULL );
}
......@@ -605,9 +605,9 @@ void KStars::slotApplyConfigChanges() {
data()->setFullTimeUpdate();
map()->forceUpdate();
kstarsData->skyComposite()->setCurrentCulture( kstarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) );
kstarsData->skyComposite()->reloadCLines();
kstarsData->skyComposite()->reloadCNames();
m_KStarsData->skyComposite()->setCurrentCulture( m_KStarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) );
m_KStarsData->skyComposite()->reloadCLines();
m_KStarsData->skyComposite()->reloadCNames();
}
void KStars::slotApplyWIConfigChanges() {
......@@ -665,13 +665,13 @@ void KStars::slotSetTimeToNow() {
void KStars::slotFind() {
clearCachedFindDialog();
if ( !findDialog ) { // create new dialog if no dialog is existing
findDialog = new FindDialog( this );
if ( !m_FindDialog ) { // create new dialog if no dialog is existing
m_FindDialog = new FindDialog( this );
}
if ( !findDialog ) qWarning() << xi18n( "KStars::slotFind() - Not enough memory for dialog" ) ;
if ( !m_FindDialog ) qWarning() << xi18n( "KStars::slotFind() - Not enough memory for dialog" ) ;
SkyObject *targetObject;
if ( findDialog->exec() == QDialog::Accepted && ( targetObject = findDialog->selectedObject() ) ) {
if ( m_FindDialog->exec() == QDialog::Accepted && ( targetObject = m_FindDialog->selectedObject() ) ) {
map()->setClickedObject( targetObject );
map()->setClickedPoint( map()->clickedObject() );
map()->slotCenter();
......@@ -731,17 +731,17 @@ void KStars::slotExportImage() {
// 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.
if ( !imageExporter )
imageExporter = new ImageExporter( this );
//if ( !m_ImageExporter )
//m_ImageExporter = new ImageExporter( this );
if ( !imgExportDialog ) {
imgExportDialog = new ExportImageDialog( fileURL.url(), QSize( map()->width(), map()->height() ), imageExporter );
if ( !m_ExportImageDialog ) {
m_ExportImageDialog = new ExportImageDialog( fileURL.url(), QSize( map()->width(), map()->height() ), KStarsData::Instance()->imageExporter() );
} else {
imgExportDialog->setOutputUrl( fileURL.url() );
imgExportDialog->setOutputSize( QSize ( map()->width(), map()->height() ) );
m_ExportImageDialog->setOutputUrl( fileURL.url() );
m_ExportImageDialog->setOutputSize( QSize ( map()->width(), map()->height() ) );
}
imgExportDialog->show();
m_ExportImageDialog->show();
}
void KStars::slotRunScript() {
......@@ -910,12 +910,12 @@ void KStars::slotPrint() {
}
void KStars::slotPrintingWizard() {
if(m_printingWizard) {
delete m_printingWizard;
if(m_PrintingWizard) {
delete m_PrintingWizard;
}
m_printingWizard = new PrintingWizard(this);
m_printingWizard->show();
m_PrintingWizard = new PrintingWizard(this);
m_PrintingWizard->show();
}
void KStars::slotToggleTimer() {
......@@ -1124,7 +1124,7 @@ void KStars::slotMapProjection() {
//DEBUG
qDebug() << xi18n( "Projection system: %1", Options::projection() );
skymap->forceUpdate();
m_SkyMap->forceUpdate();
}
//Settings Menu:
......@@ -1165,7 +1165,7 @@ void KStars::slotFOVEdit() {
}
void KStars::slotObsList() {
kstarsData->observingList()->show();
m_KStarsData->observingList()->show();
}
void KStars::slotEquipmentWriter() {
......@@ -1265,7 +1265,7 @@ void KStars::slotAboutToQuit()
{
// Delete skymap. This required to run destructors and save
// current state in the option.
delete skymap;
delete m_SkyMap;
//Store Window geometry in Options object
Options::setWindowWidth( width() );
......@@ -1278,7 +1278,7 @@ void KStars::slotAboutToQuit()
writeConfig();
if( !Options::obsListSaveImage() ) {
foreach ( const QString& file, kstarsData->observingList()->imageList() )
foreach ( const QString& file, m_KStarsData->observingList()->imageList() )
QFile::remove( QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + file ) ;
}
}
......
......@@ -40,14 +40,11 @@
#include "oal/execute.h"
#include "simclock.h"
#include "timezonerule.h"
#include "imageexporter.h"
#include <config-kstars.h>
#include "dialogs/detaildialog.h"
#ifdef HAVE_INDI
#include "ekos/ekosmanager.h"
#endif
namespace {
// Report fatal error during data loading to user
......@@ -103,35 +100,29 @@ KStarsData::KStarsData() :
m_Geo(dms(0), dms(0)),
m_ksuserdb(),
m_catalogdb(),
m_observingList(0),
m_execute(0),
m_ObservingList(0),
m_Execute(0),
m_ImageExporter(0),
temporaryTrail( false ),
//locale( new KLocale( "kstars" ) ),
m_preUpdateID(0), m_updateID(0),
m_preUpdateNumID(0), m_updateNumID(0),
m_preUpdateNum( J2000 ), m_updateNum( J2000 )
{
m_logObject = new OAL::Log;
m_LogObject = new OAL::Log;
// at startup times run forward
setTimeDirection( 0.0 );
#ifdef HAVE_INDI
m_ekosManager = NULL;
#endif
}
KStarsData::~KStarsData() {
Q_ASSERT( pinstance );
//delete locale;
delete m_logObject;
delete m_execute;
delete m_observingList;
#ifdef HAVE_INDI
delete m_ekosManager;
#endif
delete m_LogObject;
delete m_Execute;
delete m_ObservingList;
delete m_ImageExporter;
qDeleteAll( geoList );
qDeleteAll( ADVtreeList );
......@@ -184,10 +175,7 @@ bool KStarsData::initialize() {
}
//Initialize Observing List
m_observingList = new ObservingList();
#ifdef HAVE_INDI
m_ekosManager = new EkosManager();
#endif
m_ObservingList = new ObservingList();
readUserLog();
......@@ -1040,10 +1028,18 @@ void KStarsData::syncFOV()
}
Execute* KStarsData::executeSession() {
if( !m_execute )
m_execute = new Execute();
if( !m_Execute )
m_Execute = new Execute();
return m_Execute;
}
ImageExporter * KStarsData::imageExporter()
{
if (!m_ImageExporter)
m_ImageExporter = new ImageExporter(KStars::Instance());
return m_execute;
return m_ImageExporter;
}
......@@ -49,7 +49,6 @@ class SkyMap;
class SkyMapComposite;
class SkyObject;
class FOV;
class EkosManager;
class TimeZoneRule;
struct ADVTreeData;
......@@ -210,15 +209,14 @@ public:
inline const QList<FOV*> getAvailableFOVs() const { return availFOVs; }
/** Return log object */
OAL::Log *logObject() { return m_logObject; }
OAL::Log *logObject() { return m_LogObject; }
/** Return ADV Tree */
QList<ADVTreeData*> avdTree() { return ADVtreeList; }
inline ObservingList* observingList() const { return m_observingList; }
#ifdef HAVE_INDI
inline EkosManager *ekosManager() const { return m_ekosManager; }
#endif
inline ObservingList* observingList() const { return m_ObservingList; }
ImageExporter * imageExporter();
Execute* executeSession();
......@@ -340,12 +338,11 @@ private:
KSUserDB m_ksuserdb;
CatalogDB m_catalogdb;
ColorScheme CScheme;
OAL::Log *m_logObject;
ObservingList *m_observingList;
#ifdef HAVE_INDI
EkosManager *m_ekosManager;
#endif
Execute *m_execute;
OAL::Log *m_LogObject;
ObservingList *m_ObservingList;
Execute *m_Execute;
ImageExporter *m_ImageExporter;
//EquipmentWriter *m_equipmentWriter;
bool TimeRunsForward, temporaryTrail;
......