Kstars

main.cpp
1/*
2 SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "ksnumbers.h"
8#include "kspaths.h"
9#include "kstars_debug.h"
10#include "kstarsdata.h"
11#include "ksnotification.h"
12#include "kstarsdatetime.h"
13#include "catalogsdb.h"
14#if defined(KSTARS_LITE)
15#include "kstarslite.h"
16#endif
17#include "ksutils.h"
18#include "Options.h"
19#include "simclock.h"
20#include "version.h"
21#if !defined(KSTARS_LITE)
22#include "kstars.h"
23#include "skymap.h"
24#endif
25
26#if !defined(KSTARS_LITE)
27#include <KAboutData>
28#include <KCrash>
29#endif
30#include <KLocalizedString>
31
32#include <QApplication>
33#if !defined(KSTARS_LITE)
34#include <QCommandLineParser>
35#include <QCommandLineOption>
36#endif
37#include <QDebug>
38#include <QPixmap>
39#include <QScreen>
40#include <QtGlobal>
41#include <QTranslator>
42
43#if defined(Q_OS_LINUX) || defined(Q_OS_OSX)
44#include <signal.h>
45#endif
46
47#ifndef KSTARS_LITE
48static const char description[] = I18N_NOOP("Desktop Planetarium");
49static const char notice[] = I18N_NOOP(
50 "Some images in KStars are for non-commercial use only. See README.images.");
51#endif
52
53#if defined(Q_OS_ANDROID)
54// __attribute__ is needed because clang-based linking removes the main() symbol from the shared library on Android
56#endif
57int main(int argc, char *argv[])
58{
59#if defined(Q_OS_LINUX) || defined(Q_OS_OSX)
60 // Ignore SIGPIPE
61 signal(SIGPIPE, SIG_IGN);
62#endif
63
65
67
68#ifdef Q_OS_OSX
69 //Note, this function will return true on OS X if the data directories are good to go. If not, quit with error code 1!
70 if (!KSUtils::setupMacKStarsIfNeeded())
71 {
72 KSNotification::sorry(i18n("Sorry, without a KStars Data Directory, KStars "
73 "cannot operate. Exiting program now."));
74 return 1;
75 }
76#endif
77 Options::setKStarsFirstRun(false);
78 app.setApplicationVersion(KSTARS_VERSION);
79 /**
80 * enable high dpi support
81 */
82 app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
83
85#if defined(KSTARS_LITE)
86#if defined(__ANDROID__)
88 "kstars", "/data/data/org.kde.kstars.lite/qt-reserved-files/share/kstars/locale");
89#else
90 KLocalizedString::addDomainLocaleDir("kstars", "locale");
91#endif
92#endif
93
94#ifndef KSTARS_LITE
95
96 // Create writable data dir if it does not exist
98 writableDir.mkdir(KSPaths::writableLocation(QStandardPaths::GenericDataLocation));
99 writableDir.mkdir(KSPaths::writableLocation(QStandardPaths::TempLocation));
100
104 KAboutData aboutData(
105 "kstars", i18n("KStars"), versionString, i18n(description), KAboutLicense::GPL,
106 "2001-" + QString::number(QDate::currentDate().year()) +
107 i18n(" (c), The KStars Team\n\nThe Gaussian Process Guider Algorithm: (c) "
108 "2014-2017 Max Planck Society"),
109 i18nc("Build number followed by copyright notice", "Build: %1\n\n%2\n\n%3",
112 "Pre-release beta snapshot. Do not use in production." :
113 "Stable release.",
114 i18n(notice)),
115 "https://edu.kde.org/kstars");
116 aboutData.addAuthor(i18n("Jason Harris"), i18n("Original Author"),
117 "jharris@30doradus.org", "http://www.30doradus.org");
118 aboutData.addAuthor(i18n("Jasem Mutlaq"), i18n("Current Maintainer"),
119 "mutlaqja@ikarustech.com", "https://www.indilib.org");
120
121 // Active developers
122 aboutData.addAuthor(i18n("Akarsh Simha"), QString(), "akarsh@kde.org",
123 "http://www.ph.utexas.edu/~asimha");
124 aboutData.addAuthor(i18n("Robert Lancaster"),
125 i18n("FITSViewer & Ekos Improvements. KStars OSX Port"),
126 "rlancaste@gmail.com");
127 aboutData.addAuthor(i18n("Eric Dejouhanet"), QString(), "eric.dejouhanet@gmail.com",
128 i18n("Ekos Scheduler Improvements"));
129 aboutData.addAuthor(i18n("Wolfgang Reissenberger"), QString(),
130 "sterne-jaeger@t-online.de",
131 i18n("Ekos Scheduler & Observatory Improvements"));
132 aboutData.addAuthor(i18n("Hy Murveit"), QString(), "murveit@gmail.com",
133 i18n("FITS, Focus, Guide Improvements"));
134 aboutData.addAuthor(i18n("John Evans"), QString(), "john.e.evans.email@gmail.com",
135 i18n("Focus algorithms"));
136
137 // Inactive developers
138 aboutData.addAuthor(i18n("Csaba Kertesz"), QString(), "csaba.kertesz@gmail.com", "");
139 aboutData.addAuthor("Valentin Boettcher", QString(), "hiro@protagon.space",
140 i18n("Binary Asteroid List, DSO Database & Catalogs"));
141 aboutData.addAuthor(i18n("Artem Fedoskin"), i18n("KStars Lite"),
142 "afedoskin3@gmail.com");
143 aboutData.addAuthor(i18n("James Bowlin"), QString(), "bowlin@mindspring.com");
144 aboutData.addAuthor(i18n("Pablo de Vicente"), QString(), "pvicentea@wanadoo.es");
145 aboutData.addAuthor(i18n("Thomas Kabelmann"), QString(), "tk78@gmx.de");
146 aboutData.addAuthor(i18n("Heiko Evermann"), QString(), "heiko@evermann.de",
147 "https://www.evermann.de");
148 aboutData.addAuthor(i18n("Carsten Niehaus"), QString(), "cniehaus@gmx.de");
149 aboutData.addAuthor(i18n("Mark Hollomon"), QString(), "mhh@mindspring.com");
150 aboutData.addAuthor(i18n("Alexey Khudyakov"), QString(), "alexey.skladnoy@gmail.com");
151 aboutData.addAuthor(i18n("M&eacute;d&eacute;ric Boquien"), QString(),
152 "mboquien@free.fr");
153 aboutData.addAuthor(i18n("J&eacute;r&ocirc;me Sonrier"), QString(),
154 "jsid@emor3j.fr.eu.org");
155 aboutData.addAuthor(i18n("Prakash Mohan"), QString(), "prakash.mohan@kdemail.net");
156 aboutData.addAuthor(i18n("Victor Cărbune"), QString(), "victor.carbune@kdemail.net");
157 aboutData.addAuthor(i18n("Henry de Valence"), QString(), "hdevalence@gmail.com");
158 aboutData.addAuthor(i18n("Samikshan Bairagya"), QString(),
159 "samikshan.bairagya@kdemail.net");
160 aboutData.addAuthor(i18n("Rafał Kułaga"), QString(), "rl.kulaga@gmail.com");
161 aboutData.addAuthor(i18n("Rishab Arora"), QString(), "ra.rishab@gmail.com");
162
163 // Contributors
164 aboutData.addCredit(
165 i18n("Valery Kharitonov"),
166 i18n("Converted labels containing technical terms to links to documentation"));
167 aboutData.addCredit(i18n("Ana-Maria Constantin"),
168 i18n("Technical documentation on Astronomy and KStars"));
169 aboutData.addCredit(i18n("Andrew Stepanenko"),
170 i18n("Guiding code based on lin_guider"));
171 aboutData.addCredit(i18n("Nuno Pinheiro"), i18n("Artwork"));
172 aboutData.addCredit(
173 i18n("Utkarsh Simha"),
174 i18n("Improvements to observation plan execution, star hopper etc."));
175 aboutData.addCredit(i18n("Daniel Holler"),
176 i18n("Extensive testing and suggestions for Ekos/INDI."));
177 aboutData.addCredit(
178 i18n("Stephane Lucas"),
179 i18n("Extensive testing and suggestions for Ekos Scheduler. KStars OSX Port"));
180 aboutData.addCredit(i18n("Yuri Fabirovsky"),
181 i18n("Splash screen for both regular KStars and KStars Lite."));
182 aboutData.addCredit(i18n("Jamie Smith"), i18n("KStars OSX Port."));
183 aboutData.addCredit(i18n("Patrick Molenaar"), i18n("Bahtinov Focus Assistant."));
184 aboutData.addCredit(i18n("Philipp Auersperg-Castell"), i18n("Supernovae daily updates"));
185 aboutData.addCredit(i18n("Tony Schriber"), i18n("Rotator Dialog improvements"));
186 aboutData.addCredit(i18n("Joseph McGee"), i18n("Sub-exposure calculator based on Dr Robin Glover's work"));
187
189
190 QCommandLineParser parser;
191 aboutData.setupCommandLine(&parser);
193
194 //parser.addHelpOption(INSERT_DESCRIPTION_HERE);
195 parser.addOption(QCommandLineOption("dump", i18n("Dump sky image to file."), "file"));
196 parser.addOption(QCommandLineOption("script", i18n("Script to execute."), "file"));
197 parser.addOption(QCommandLineOption("width", i18n("Width of sky image."), "value"));
198 parser.addOption(QCommandLineOption("height", i18n("Height of sky image."), "value"));
199 parser.addOption(QCommandLineOption("date", i18n("Date and time."), "string"));
200 parser.addOption(QCommandLineOption("paused", i18n("Start with clock paused.")));
201
202 // urls to open
203 parser.addPositionalArgument(QStringLiteral("urls"), i18n("FITS file(s) to open."),
204 QStringLiteral("[urls...]"));
205
206 parser.process(app);
207 aboutData.processCommandLine(&parser);
208
209 if (parser.isSet("dump"))
210 {
211 qCDebug(KSTARS) << "Dumping sky image";
212
213 //parse filename and image format
214 const char *format = "PNG";
215 QString fname = parser.value("dump");
216 QString ext = fname.mid(fname.lastIndexOf(".") + 1);
217 if (ext.toLower() == "png")
218 {
219 format = "PNG";
220 }
221 else if (ext.toLower() == "jpg" || ext.toLower() == "jpeg")
222 {
223 format = "JPG";
224 }
225 else if (ext.toLower() == "gif")
226 {
227 format = "GIF";
228 }
229 else if (ext.toLower() == "pnm")
230 {
231 format = "PNM";
232 }
233 else if (ext.toLower() == "bmp")
234 {
235 format = "BMP";
236 }
237 else
238 {
239 qCWarning(KSTARS) << i18n("Could not parse image format of %1; assuming PNG.",
240 fname);
241 }
242
243 //parse width and height
244 bool ok(false);
245 int w(0), h(0);
246 w = parser.value("width").toInt(&ok);
247 if (ok)
248 h = parser.value("height").toInt(&ok);
249 if (!ok)
250 {
251 qCWarning(KSTARS) << "Unable to parse arguments Width: "
252 << parser.value("width")
253 << " Height: " << parser.value("height");
254 return 1;
255 }
256
257 KStarsData *dat = KStarsData::Create();
258 QObject::connect(dat, SIGNAL(progressText(QString)), dat,
259 SLOT(slotConsoleMessage(QString)));
260 dat->initialize();
261
262 //Set Geographic Location
263 dat->setLocationFromOptions();
264
265 //Set color scheme
266 dat->colorScheme()->loadFromConfig();
267
268 //set clock now that we have a location:
269 //Check to see if user provided a date/time string. If not, use current CPU time
270 QString datestring = parser.value("date");
271 KStarsDateTime kdt;
272 if (!datestring.isEmpty())
273 {
274 if (datestring.contains("-")) //assume ISODate format
275 {
276 if (datestring.contains(":")) //also includes time
277 {
278 //kdt = QDateTime::fromString( datestring, QDateTime::ISODate );
280 }
281 else //string probably contains date only
282 {
283 //kdt.setDate( QDate::fromString( datestring, Qt::ISODate ) );
285 kdt.setTime(QTime(0, 0, 0));
286 }
287 }
288 else //assume Text format for date string
289 {
290 kdt = dat->geo()->LTtoUT(
292 }
293
294 if (!kdt.isValid())
295 {
296 qCWarning(KSTARS) << i18n(
297 "Supplied date string is invalid: %1. Using CPU date/time instead.",
298 datestring);
299
301 }
302 }
303 else
304 {
306 }
307 dat->clock()->setUTC(kdt);
308
309 SkyMap *map = SkyMap::Create();
310 map->resize(w, h);
311 QPixmap sky(w, h);
312
313 dat->setFullTimeUpdate();
314 dat->updateTime(dat->geo(), map != nullptr);
315
316 SkyPoint dest(Options::focusRA(), Options::focusDec());
317 map->setDestination(dest);
318 map->destination()->EquatorialToHorizontal(dat->lst(), dat->geo()->lat());
319 map->setFocus(map->destination());
320 map->focus()->EquatorialToHorizontal(dat->lst(), dat->geo()->lat());
321
322 //Execute the specified script
323 QString scriptfile = parser.value("script");
324 if (!scriptfile.isEmpty())
325 {
326 if (dat->executeScript(scriptfile, map))
327 {
328 std::cout << i18n("Script executed.").toUtf8().data() << std::endl;
329 }
330 else
331 {
332 qCWarning(KSTARS) << i18n("Could not execute script.");
333 }
334 }
335
336 qApp->processEvents();
337 map->setupProjector();
338 map->exportSkyImage(&sky);
339 qApp->processEvents();
340
341 if (!sky.save(fname, format))
342 qCWarning(KSTARS) << "Unable to save image: " << fname;
343 else
344 qCDebug(KSTARS) << "Saved to file: %1" << fname;
345
346 delete map;
347 //delete dat;
348 return 0;
349 }
350
351 //Try to parse the given date string
352 QString datestring = parser.value("date");
353
354 if (!datestring.isEmpty() && !KStarsDateTime::fromString(datestring).isValid())
355 {
356 qWarning() << i18n("Using CPU date/time instead.");
357 datestring.clear();
358 }
359
360#endif
361
362 // Create writable data dir if it does not exist
363 QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).mkpath(".");
364 QDir(KSPaths::writableLocation(QStandardPaths::AppConfigLocation)).mkpath(".");
365 QDir(KSPaths::writableLocation(QStandardPaths::CacheLocation)).mkpath(".");
366 QDir(KSPaths::writableLocation(QStandardPaths::TempLocation)).mkpath(qAppName());
367
368#ifndef KSTARS_LITE
369 KStars::createInstance(true, !parser.isSet("paused"), datestring);
370
371 // no session.. just start up normally
372 const QStringList urls = parser.positionalArguments();
373
374 // take arguments
375 if (!urls.isEmpty())
376 {
377 foreach (const QString &url, urls)
378 {
380
381 KStars::Instance()->openFITS(u);
382 }
383 }
384 QObject::connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()));
385
386 app.exec();
387#else
389
390 app.exec();
391#endif
392 return 0;
393}
KAboutData & addAuthor(const QString &name, const QString &task, const QString &emailAddress, const QString &webAddress, const QString &kdeStoreUsername)
KAboutData & addCredit(const QString &name, const QString &task, const QString &emailAddress, const QString &webAddress, const QString &kdeStoreUsername)
QString shortDescription() const
static void setApplicationData(const KAboutData &aboutData)
void processCommandLine(QCommandLineParser *parser)
bool setupCommandLine(QCommandLineParser *parser)
static void addDomainLocaleDir(const QByteArray &domain, const QString &path)
static void setApplicationDomain(const QByteArray &domain)
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
static KStarsDateTime fromString(const QString &s)
void setDate(const QDate &d)
Assign the Date according to a QDate object.
static KStarsDateTime currentDateTimeUtc()
void setTime(const QTime &t)
Assign the Time according to a QTime object.
static KStarsLite * createInstance(bool doSplash, bool clockrunning=true, const QString &startDateString=QString())
Create an instance of this class.
static KStars * Instance()
Definition kstars.h:123
static KStars * createInstance(bool doSplash, bool clockrunning=true, const QString &startDateString=QString())
Create an instance of this class.
Definition kstars.cpp:239
This is the canvas on which the sky is painted.
Definition skymap.h:54
The sky coordinates of a point in the sky.
Definition skypoint.h:45
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
KCOREADDONS_EXPORT QString versionString()
KCRASH_EXPORT void initialize()
QAction * quit(const QObject *recvr, const char *slot, QObject *parent)
char * data()
bool addOption(const QCommandLineOption &option)
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
bool isSet(const QCommandLineOption &option) const const
QStringList positionalArguments() const const
void process(const QCoreApplication &app)
void setApplicationDescription(const QString &description)
QString value(const QCommandLineOption &option) const const
void setAttribute(Qt::ApplicationAttribute attribute, bool on)
QDate currentDate()
QDate fromString(QStringView string, QStringView format, QCalendar cal)
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
bool isValid() const const
QString currentPath()
bool mkpath(const QString &dirPath) const const
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)
int toInt(bool *ok, int base) const const
QByteArray toUtf8() const const
AA_EnableHighDpiScaling
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QUrl fromUserInput(const QString &userInput, const QString &workingDirectory, UserInputResolutionOptions options)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.