StelApp.cpp   StelApp.cpp 
skipping to change at line 42 skipping to change at line 42
#include "GridLinesMgr.hpp" #include "GridLinesMgr.hpp"
#include "MilkyWay.hpp" #include "MilkyWay.hpp"
#include "MeteorMgr.hpp" #include "MeteorMgr.hpp"
#include "LabelMgr.hpp" #include "LabelMgr.hpp"
#include "ScreenImageMgr.hpp" #include "ScreenImageMgr.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelLocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "StelDownloadMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelFontMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelScriptMgr.hpp" #include "StelScriptMgr.hpp"
#include "StelMainScriptAPIProxy.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "StelSkyImageMgr.hpp" #include "StelSkyLayerMgr.hpp"
#include "StelAudioMgr.hpp" #include "StelAudioMgr.hpp"
#include "StelMainWindow.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelMainGraphicsView.hpp"
#include "StelGuiBase.hpp"
#include "StelPainter.hpp"
#include <iostream> #include <iostream>
#include <QStringList> #include <QStringList>
#include <QString> #include <QString>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QRegExp> #include <QRegExp>
#include <QTextStream> #include <QTextStream>
#include <QMouseEvent> #include <QMouseEvent>
#include <QDebug> #include <QDebug>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QSysInfo> #include <QSysInfo>
#include <QNetworkProxy>
#ifdef WIN32 #include <QMessageBox>
#include <windows.h> #include <QNetworkDiskCache>
#endif #include <QNetworkReply>
// Initialize static variables // Initialize static variables
StelApp* StelApp::singleton = NULL; StelApp* StelApp::singleton = NULL;
QTime* StelApp::qtime = NULL; QTime* StelApp::qtime = NULL;
QFile StelApp::logFile;
QString StelApp::log; void StelApp::initStatic()
{
StelApp::qtime = new QTime();
StelApp::qtime->start();
}
/************************************************************************* /*************************************************************************
Create and initialize the main Stellarium application. Create and initialize the main Stellarium application.
*************************************************************************/ *************************************************************************/
StelApp::StelApp(int argc, char** argv, QObject* parent) StelApp::StelApp(QObject* parent)
: QObject(parent), core(NULL), fps(0), maxfps(10000.f), frame(0), : QObject(parent), core(NULL), stelGui(NULL), fps(0),
timefr(0.), timeBase(0.), flagNightVision(false), frame(0), timefr(0.), timeBase(0.), flagNightVision(false),
configFile("config.ini"), startupScript("startup.ssc"), confSettings(NULL), initialized(false), saveProjW(-1), saveProjH(-
confSettings(NULL), initialized(false), saveProjW(-1), 1), drawState(0)
saveProjH(-1)
{ {
// Stat variables // Stat variables
nbDownloadedFiles=0; nbDownloadedFiles=0;
totalDownloadedSize=0; totalDownloadedSize=0;
nbUsedCache=0; nbUsedCache=0;
totalUsedCacheSize=0; totalUsedCacheSize=0;
// Used for getting system date formatting
setlocale(LC_TIME, "");
// We need scanf()/printf() and friends to always work in the C loca
le,
// otherwise configuration/INI file parsing will be erroneous.
setlocale(LC_NUMERIC, "C");
setObjectName("StelApp"); setObjectName("StelApp");
skyCultureMgr=NULL; skyCultureMgr=NULL;
localeMgr=NULL; localeMgr=NULL;
fontManager=NULL;
stelObjectMgr=NULL; stelObjectMgr=NULL;
textureMgr=NULL; textureMgr=NULL;
moduleMgr=NULL; moduleMgr=NULL;
loadingBar=NULL; loadingBar=NULL;
networkAccessManager=NULL; networkAccessManager=NULL;
// Can't create 2 StelApp instances // Can't create 2 StelApp instances
Q_ASSERT(!singleton); Q_ASSERT(!singleton);
singleton = this; singleton = this;
argList = new QStringList;
for(int i=0; i<argc; i++)
*argList << argv[i];
// Echo debug output to log file
stelFileMgr = new StelFileMgr();
logFile.setFileName(stelFileMgr->getUserDir()+"/log.txt");
QDir userDirTmp(stelFileMgr->getUserDir());
if (!userDirTmp.exists())
{
// Try to create it
StelFileMgr::mkDir(stelFileMgr->getUserDir());
}
if (logFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODev
ice::Text | QIODevice::Unbuffered))
qInstallMsgHandler(StelApp::debugLogHandler);
StelApp::qtime = new QTime();
StelApp::qtime->start();
// Print system info to log file
setupLog();
// Parse for first set of CLI arguments - stuff we want to process b
efore other
// output, such as --help and --version, and if we want to set the c
onfigFile value.
parseCLIArgsPreConfig();
// Load language codes
try
{
StelTranslator::init(stelFileMgr->findFile("data/iso639-1.ut
f8"));
}
catch (std::runtime_error& e)
{
qDebug() << "ERROR while loading translations: " << e.what()
<< endl;
}
// OK, print the console splash and get on with loading the program
QString versionLine = QString("This is %1 - http://www.stellarium.or
g").arg(StelApp::getApplicationName());
QString copyrightLine = QString("Copyright (C) 2000-2009 Fabien Cher
eau et al");
int maxLength = qMax(versionLine.size(), copyrightLine.size());
qDebug() << qPrintable(QString(" %1").arg(QString().fill('-', maxLen
gth+2)));
qDebug() << qPrintable(QString("[ %1 ]").arg(versionLine.leftJustifi
ed(maxLength, ' ')));
qDebug() << qPrintable(QString("[ %1 ]").arg(copyrightLine.leftJusti
fied(maxLength, ' ')));
qDebug() << qPrintable(QString(" %1").arg(QString().fill('-', maxLen
gth+2)));
if (logFile.isOpen())
qDebug() << "Writing log file to:" << logFile.fileName();
else
qDebug() << "Unable to open log file:" << logFile.fileName()
<< ".";
QStringList p=stelFileMgr->getSearchPaths();
qDebug() << "File search paths:";
int n=0;
foreach (QString i, p)
{
qDebug() << " " << n << ". " << i;
++n;
}
qDebug() << "Config file is: " << configFile;
// implement "restore default settings" feature.
bool restoreDefaults = false;
if (stelFileMgr->exists(configFile))
{
QSettings* tmpSettings = new QSettings(configFile, StelIniFo
rmat);
restoreDefaults = tmpSettings->value("main/restore_defaults"
, false).toBool();
delete tmpSettings;
}
if (restoreDefaults)
{
QFile(configFile).remove();
qDebug() << "DELETING old config.ini";
}
if (!stelFileMgr->exists(configFile))
{
qDebug() << "config file " << configFile << " does not exist
- copying the default file.";
copyDefaultConfigFile();
}
// Load the configuration file
confSettings = new QSettings(getConfigFilePath(), StelIniFormat, thi
s);
// Main section
QString version = confSettings->value("main/version").toString();
if (version.isEmpty())
{
qWarning() << "Found an invalid config file. Overwrite with
default.";
delete confSettings;
QFile::remove(getConfigFilePath());
copyDefaultConfigFile();
confSettings = new QSettings(getConfigFilePath(), StelIniFor
mat);
// get the new version value from the updated config file
version = confSettings->value("main/version").toString();
}
if (version!=QString(PACKAGE_VERSION))
{
QTextStream istr(&version);
char tmp;
int v1 =0;
int v2 =0;
istr >> v1 >> tmp >> v2;
// Config versions less than 0.6.0 are not supported, otherw
ise we will try to use it
if(v1==0 && v2<6)
{
// The config file is too old to try an importation
qDebug() << "The current config file is from a versi
on too old for parameters to be imported ("
<< (version.isEmpty() ? "<0.6.0" : version)
<< ").\n"
<< "It will be replaced by the default conf
ig file.";
delete confSettings;
QFile::remove(getConfigFilePath());
copyDefaultConfigFile();
confSettings = new QSettings(getConfigFilePath(), St
elIniFormat);
}
else
{
qDebug() << "Attempting to use an existing older con
fig file.";
}
}
parseCLIArgsPostConfig();
moduleMgr = new StelModuleMgr(); moduleMgr = new StelModuleMgr();
maxfps = confSettings->value("video/maximum_fps",10000.).toDouble();
minfps = confSettings->value("video/minimum_fps",10000.).toDouble();
// Init a default StelStyle, before loading modules, it will be over rided // Init a default StelStyle, before loading modules, it will be over rided
currentStelStyle = NULL; currentStelStyle = NULL;
setColorScheme("color"); setColorScheme("color");
} }
/************************************************************************* /*************************************************************************
Deinitialize and destroy the main Stellarium application. Deinitialize and destroy the main Stellarium application.
*************************************************************************/ *************************************************************************/
StelApp::~StelApp() StelApp::~StelApp()
{ {
#if QT_VERSION >= 0x040500
qDebug() << qPrintable(QString("Downloaded %1 files (%2 kbytes) in a session of %3 sec (average of %4 kB/s + %5 files from cache (%6 kB)).").ar g(nbDownloadedFiles).arg(totalDownloadedSize/1024).arg(getTotalRunTime()).a rg((double)(totalDownloadedSize/1024)/getTotalRunTime()).arg(nbUsedCache).a rg(totalUsedCacheSize/1024)); qDebug() << qPrintable(QString("Downloaded %1 files (%2 kbytes) in a session of %3 sec (average of %4 kB/s + %5 files from cache (%6 kB)).").ar g(nbDownloadedFiles).arg(totalDownloadedSize/1024).arg(getTotalRunTime()).a rg((double)(totalDownloadedSize/1024)/getTotalRunTime()).arg(nbUsedCache).a rg(totalUsedCacheSize/1024));
#endif
if (scriptMgr->scriptIsRunning())
scriptMgr->stopScript();
stelObjectMgr->unSelect(); stelObjectMgr->unSelect();
moduleMgr->unloadModule("StelSkyImageMgr", false); // We need to de lete it afterward moduleMgr->unloadModule("StelSkyLayerMgr", false); // We need to de lete it afterward
moduleMgr->unloadModule("StelObjectMgr", false);// We need to delete it afterward moduleMgr->unloadModule("StelObjectMgr", false);// We need to delete it afterward
StelModuleMgr* tmp = moduleMgr; StelModuleMgr* tmp = moduleMgr;
moduleMgr = new StelModuleMgr(); // Create a secondary instance to a void crashes at other deinit moduleMgr = new StelModuleMgr(); // Create a secondary instance to a void crashes at other deinit
delete tmp; tmp=NULL; delete tmp; tmp=NULL;
delete loadingBar; loadingBar=NULL;
delete core; core=NULL; delete core; core=NULL;
delete skyCultureMgr; skyCultureMgr=NULL; delete skyCultureMgr; skyCultureMgr=NULL;
delete localeMgr; localeMgr=NULL; delete localeMgr; localeMgr=NULL;
delete fontManager; fontManager=NULL;
delete audioMgr; audioMgr=NULL; delete audioMgr; audioMgr=NULL;
delete stelObjectMgr; stelObjectMgr=NULL; // Delete the module by ha nd afterward delete stelObjectMgr; stelObjectMgr=NULL; // Delete the module by ha nd afterward
delete stelFileMgr; stelFileMgr=NULL;
delete textureMgr; textureMgr=NULL; delete textureMgr; textureMgr=NULL;
delete planetLocationMgr; planetLocationMgr=NULL; delete planetLocationMgr; planetLocationMgr=NULL;
delete moduleMgr; moduleMgr=NULL; // Delete the secondary instance delete moduleMgr; moduleMgr=NULL; // Delete the secondary instance
delete argList; argList=NULL;
delete currentStelStyle; delete currentStelStyle;
logFile.close();
Q_ASSERT(singleton); Q_ASSERT(singleton);
singleton = NULL; singleton = NULL;
} }
#if QT_VERSION >= 0x040500 void StelApp::init(QSettings* conf)
#include <QNetworkDiskCache>
#include <QDesktopServices>
#endif
/*************************************************************************
Return the full name of stellarium, i.e. "stellarium 0.9.0"
*************************************************************************/
QString StelApp::getApplicationName()
{ {
#ifdef SVN_REVISION confSettings = conf;
return QString("Stellarium")+" "+PACKAGE_VERSION+" (SVN r"+SVN_REVIS
ION+")";
#else
return QString("Stellarium")+" "+PACKAGE_VERSION;
#endif
}
/************************************************************************* core = new StelCore();
Return the version of stellarium, i.e. "0.9.0" if (saveProjW!=-1 && saveProjH!=-1)
*************************************************************************/ core->windowHasBeenResized(0, 0, saveProjW, saveProjH);
QString StelApp::getApplicationVersion()
{
#ifdef SVN_REVISION
return QString(PACKAGE_VERSION)+" (SVN r"+SVN_REVISION+")";
#else
return QString(PACKAGE_VERSION);
#endif
}
void StelApp::debugLogHandler(QtMsgType type, const char* msg) // Avoid using GL Shaders by default since it causes so many problem
{ s with broken drivers.
fprintf(stderr, "%s\n", msg); useGLShaders = confSettings->value("main/use_glshaders", false).toBo
StelApp::writeLog(QString(msg)); ol();
} useGLShaders = useGLShaders && QGLShaderProgram::hasOpenGLShaderProg
rams();
useGLShaders = useGLShaders && (QGLFormat::openGLVersionFlags().test
Flag(QGLFormat::OpenGL_Version_2_0) || QGLFormat::openGLVersionFlags().test
Flag(QGLFormat::OpenGL_ES_Version_2_0));
void StelApp::writeLog(QString msg) StelPainter::initSystemGLInfo();
{
msg += "\n"; // Initialize AFTER creation of openGL context
logFile.write(qPrintable(msg), msg.size()); textureMgr = new StelTextureMgr();
log += msg; textureMgr->init();
}
#ifdef SVN_REVISION
loadingBar = new StelLoadingBar(12., "logo24bits.png", QString("SVN
r%1").arg(SVN_REVISION), 25, 320, 101);
#else
loadingBar = new StelLoadingBar(12., "logo24bits.png", PACKAGE_VERSI
ON, 45, 320, 121);
#endif // SVN_RELEASE
loadingBar->SetMessage("Initialize");
loadingBar->Draw(0);
void StelApp::init()
{
networkAccessManager = new QNetworkAccessManager(this); networkAccessManager = new QNetworkAccessManager(this);
#if QT_VERSION >= 0x040500
// Activate http cache if Qt version >= 4.5 // Activate http cache if Qt version >= 4.5
QNetworkDiskCache* cache = new QNetworkDiskCache(networkAccessManage r); QNetworkDiskCache* cache = new QNetworkDiskCache(networkAccessManage r);
QString cachePath = QDesktopServices::storageLocation(QDesktopServic QString cachePath = StelFileMgr::getCacheDir();
es::CacheLocation);
if (cachePath.isEmpty())
{
cachePath = StelApp::getInstance().getFileMgr().getUserDir()
+"/cache";
}
qDebug() << "Cache directory is: " << cachePath; qDebug() << "Cache directory is: " << cachePath;
cache->setCacheDirectory(cachePath); cache->setCacheDirectory(cachePath);
networkAccessManager->setCache(cache); networkAccessManager->setCache(cache);
#endif
connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), this , SLOT(reportFileDownloadFinished(QNetworkReply*))); connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), this , SLOT(reportFileDownloadFinished(QNetworkReply*)));
// Stel Object Data Base manager // Stel Object Data Base manager
stelObjectMgr = new StelObjectMgr(); stelObjectMgr = new StelObjectMgr();
stelObjectMgr->init(); stelObjectMgr->init();
getModuleMgr().registerModule(stelObjectMgr); getModuleMgr().registerModule(stelObjectMgr);
core = new StelCore();
if (saveProjW!=-1 && saveProjH!=-1)
core->windowHasBeenResized(saveProjW, saveProjH);
textureMgr = new StelTextureMgr();
localeMgr = new StelLocaleMgr(); localeMgr = new StelLocaleMgr();
fontManager = new StelFontMgr();
skyCultureMgr = new StelSkyCultureMgr(); skyCultureMgr = new StelSkyCultureMgr();
planetLocationMgr = new StelLocationMgr(); planetLocationMgr = new StelLocationMgr();
// Initialize AFTER creation of openGL context
textureMgr->init();
#ifdef SVN_REVISION
loadingBar = new StelLoadingBar(12., "logo24bits.png", QString("SVN
r%1").arg(SVN_REVISION), 25, 320, 101);
#else
loadingBar = new StelLoadingBar(12., "logo24bits.png", PACKAGE_VERSI
ON, 45, 320, 121);
#endif // SVN_RELEASE
downloadMgr = new StelDownloadMgr();
localeMgr->init(); localeMgr->init();
skyCultureMgr->init(); skyCultureMgr->init();
// Init the solar system first // Init the solar system first
SolarSystem* ssystem = new SolarSystem(); SolarSystem* ssystem = new SolarSystem();
ssystem->init(); ssystem->init();
getModuleMgr().registerModule(ssystem); getModuleMgr().registerModule(ssystem);
// Load hipparcos stars & names // Load hipparcos stars & names
StarMgr* hip_stars = new StarMgr(); StarMgr* hip_stars = new StarMgr();
skipping to change at line 399 skipping to change at line 218
NebulaMgr* nebulas = new NebulaMgr(); NebulaMgr* nebulas = new NebulaMgr();
nebulas->init(); nebulas->init();
getModuleMgr().registerModule(nebulas); getModuleMgr().registerModule(nebulas);
// Init milky way // Init milky way
MilkyWay* milky_way = new MilkyWay(); MilkyWay* milky_way = new MilkyWay();
milky_way->init(); milky_way->init();
getModuleMgr().registerModule(milky_way); getModuleMgr().registerModule(milky_way);
// Init sky image manager // Init sky image manager
skyImageMgr = new StelSkyImageMgr(); skyImageMgr = new StelSkyLayerMgr();
skyImageMgr->init(); skyImageMgr->init();
getModuleMgr().registerModule(skyImageMgr); getModuleMgr().registerModule(skyImageMgr);
// Init audio manager // Init audio manager
audioMgr = new StelAudioMgr(); audioMgr = new StelAudioMgr();
// Telescope manager // Telescope manager
TelescopeMgr* telescope_mgr = new TelescopeMgr(); TelescopeMgr* telescope_mgr = new TelescopeMgr();
telescope_mgr->init(); telescope_mgr->init();
getModuleMgr().registerModule(telescope_mgr); getModuleMgr().registerModule(telescope_mgr);
skipping to change at line 440 skipping to change at line 259
// User labels // User labels
LabelMgr* skyLabels = new LabelMgr(); LabelMgr* skyLabels = new LabelMgr();
skyLabels->init(); skyLabels->init();
getModuleMgr().registerModule(skyLabels); getModuleMgr().registerModule(skyLabels);
// Scripting images // Scripting images
ScreenImageMgr* scriptImages = new ScreenImageMgr(); ScreenImageMgr* scriptImages = new ScreenImageMgr();
scriptImages->init(); scriptImages->init();
getModuleMgr().registerModule(scriptImages); getModuleMgr().registerModule(scriptImages);
// ugly fix by Johannes: call skyCultureMgr->init twice so that // ugly fix by Johannes: call skyCultureMgr->init twice so that
// star names are loaded again // star names are loaded again
skyCultureMgr->init(); skyCultureMgr->init();
// Initialisation of the color scheme // Initialisation of the color scheme
flagNightVision=true; // fool caching flagNightVision=true; // fool caching
setVisionModeNight(false); setVisionModeNight(false);
setVisionModeNight(confSettings->value("viewing/flag_night").toBool( )); setVisionModeNight(confSettings->value("viewing/flag_night").toBool( ));
// Generate dependency Lists for all modules // Proxy Initialisation
moduleMgr->generateCallingLists(); QString proxyName = confSettings->value("proxy/host_name").toString(
);
QString proxyUser = confSettings->value("proxy/user").toString();
QString proxyPassword = confSettings->value("proxy/password").toStri
ng();
QVariant proxyPort = confSettings->value("proxy/port");
if (proxyName!="" && !proxyPort.isNull()){
QNetworkProxy proxy(QNetworkProxy::HttpProxy);
proxy.setHostName(proxyName);
proxy.setPort(proxyPort.toUInt());
if(proxyUser!="" && proxyPassword!="") {
proxy.setUser(proxyUser);
proxy.setPassword(proxyPassword);
}
QNetworkProxy::setApplicationProxy(proxy);
}
updateI18n(); updateI18n();
scriptMgr = new StelScriptMgr(this);
initialized = true; initialized = true;
delete loadingBar;
loadingBar=NULL;
} }
// Load and initialize external modules (plugins) // Load and initialize external modules (plugins)
void StelApp::initPlugIns() void StelApp::initPlugIns()
{ {
// Load dynamically all the modules found in the modules/ directorie s // Load dynamically all the modules found in the modules/ directorie s
// which are configured to be loaded at startup // which are configured to be loaded at startup
foreach (StelModuleMgr::PluginDescriptor i, moduleMgr->getPluginsLis t()) foreach (StelModuleMgr::PluginDescriptor i, moduleMgr->getPluginsLis t())
{ {
if (i.loadAtStartup==false) if (i.loadAtStartup==false)
continue; continue;
StelModule* m = moduleMgr->loadPlugin(i.key); StelModule* m = moduleMgr->loadPlugin(i.info.id);
if (m!=NULL) if (m!=NULL)
{ {
moduleMgr->registerModule(m, true); moduleMgr->registerModule(m, true);
m->init(); m->init();
} }
} }
} }
void StelApp::setupLog()
{
// write timestamp
StelApp::writeLog(QString("%1").arg(QDateTime::currentDateTime().toS
tring(Qt::ISODate)));
// write command line arguments
QString args;
foreach(QString arg, *argList)
args += QString("%1 ").arg(arg);
StelApp::writeLog(args);
// write OS version
#ifdef Q_WS_WIN
switch(QSysInfo::WindowsVersion)
{
case QSysInfo::WV_95:
StelApp::writeLog("Windows 95");
break;
case QSysInfo::WV_98:
StelApp::writeLog("Windows 98");
break;
case QSysInfo::WV_Me:
StelApp::writeLog("Windows Me");
break;
case QSysInfo::WV_NT:
StelApp::writeLog("Windows NT");
break;
case QSysInfo::WV_2000:
StelApp::writeLog("Windows 2000");
break;
case QSysInfo::WV_XP:
StelApp::writeLog("Windows XP");
break;
case QSysInfo::WV_2003:
StelApp::writeLog("Windows Server 2003");
break;
case QSysInfo::WV_VISTA:
StelApp::writeLog("Windows Vista");
break;
default:
StelApp::writeLog("Unsupported Windows version");
break;
}
// somebody writing something useful for Macs would be great here
#elif defined Q_WS_MAC
switch(QSysInfo::MacintoshVersion)
{
case QSysInfo::MV_10_3:
StelApp::writeLog("Mac OS X 10.3");
break;
case QSysInfo::MV_10_4:
StelApp::writeLog("Mac OS X 10.4");
break;
case QSysInfo::MV_10_5:
StelApp::writeLog("Mac OS X 10.5");
break;
default:
StelApp::writeLog("Unsupported Mac version");
break;
}
#elif defined Q_OS_LINUX
QFile procVersion("/proc/version");
if(!procVersion.open(QIODevice::ReadOnly | QIODevice::Text))
StelApp::writeLog("Unknown Linux version");
else
{
QString version = procVersion.readAll();
if(version.right(1) == "\n")
version.chop(1);
StelApp::writeLog(version);
procVersion.close();
}
#else
StelApp::writeLog("Unsupported operating system");
#endif
// write GCC version
#ifndef __GNUC__
StelApp::writeLog("Non-GCC compiler");
#else
StelApp::writeLog(QString("Compiled with GCC %1.%2.%3").arg(__GNUC__
).arg(__GNUC_MINOR__).arg(__GNUC_PATCHLEVEL__));
#endif
// write Qt version
StelApp::writeLog(QString("Qt runtime version: %1").arg(qVersion()))
;
StelApp::writeLog(QString("Qt compilation version: %1").arg(QT_VERSI
ON_STR));
// write addressing mode
#ifdef __LP64__
StelApp::writeLog("Addressing mode: 64-bit");
#else
StelApp::writeLog("Addressing mode: 32-bit");
#endif
// write memory and CPU info
#ifdef Q_OS_LINUX
QFile infoFile("/proc/meminfo");
if(!infoFile.open(QIODevice::ReadOnly | QIODevice::Text))
StelApp::writeLog("Could not get memory info.");
else
{
while(!infoFile.peek(1).isEmpty())
{
QString line = infoFile.readLine();
line.chop(1);
if(line.startsWith("Mem") || line.startsWith("SwapTo
tal"))
StelApp::writeLog(line);
}
infoFile.close();
}
infoFile.setFileName("/proc/cpuinfo");
if(!infoFile.open(QIODevice::ReadOnly | QIODevice::Text))
StelApp::writeLog("Could not get CPU info.");
else
{
while(!infoFile.peek(1).isEmpty())
{
QString line = infoFile.readLine();
line.chop(1);
if(line.startsWith("model name") || line.startsWith(
"cpu MHz"))
StelApp::writeLog(line);
}
infoFile.close();
}
QProcess lspci;
lspci.start("lspci -v", QIODevice::ReadOnly);
lspci.waitForFinished(100);
QString pciData(lspci.readAll());
QStringList pciLines = pciData.split('\n', QString::SkipEmptyParts);
for(int i = 0; i < pciLines.size(); i++)
{
if(pciLines.at(i).contains("VGA compatible controller"))
{
StelApp::writeLog(pciLines.at(i));
i++;
while(i < pciLines.size() && pciLines.at(i).startsWi
th('\t'))
{
if(pciLines.at(i).contains("Kernel driver in
use"))
StelApp::writeLog(pciLines.at(i).tri
mmed());
else if(pciLines.at(i).contains("Kernel modu
les"))
StelApp::writeLog(pciLines.at(i).tri
mmed());
i++;
}
}
}
// Aargh Windows API
#elif defined Q_WS_WIN
// Hopefully doesn't throw a linker error on earlier systems. Not li
ke
// I'm gonna test it or anything.
if(QSysInfo::WindowsVersion >= QSysInfo::WV_2000)
{
#ifdef __LP64__
MEMORYSTATUSEX statex;
GlobalMemoryStatusEx(&statex);
StelApp::writeLog(QString("Total physical memory: %1 MB (unr
eliable)").arg(statex.ullTotalPhys/(1024<<10)));
StelApp::writeLog(QString("Total virtual memory: %1 MB (unre
liable)").arg(statex.ullTotalVirtual/(1024<<10)));
StelApp::writeLog(QString("Physical memory in use: %1%").arg
(statex.dwMemoryLoad));
#else
MEMORYSTATUS statex;
GlobalMemoryStatus(&statex);
StelApp::writeLog(QString("Total memory: %1 MB (unreliable)"
).arg(statex.dwTotalPhys/(1024<<10)));
StelApp::writeLog(QString("Total virtual memory: %1 MB (unre
liable)").arg(statex.dwTotalVirtual/(1024<<10)));
StelApp::writeLog(QString("Physical memory in use: %1%").arg
(statex.dwMemoryLoad));
#endif
}
else
StelApp::writeLog("Windows version too old to get memory inf
o.");
HKEY hKey = NULL;
DWORD dwType = REG_DWORD;
DWORD numVal = 0;
DWORD dwSize = sizeof(numVal);
// iterate over the processors listed in the registry
QString procKey = "Hardware\\Description\\System\\CentralProcessor";
LONG lRet = ERROR_SUCCESS;
int i;
for(i = 0; lRet == ERROR_SUCCESS; i++)
{
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT(qPrintable(QString("%1\\%2").arg(pr
ocKey).arg(i))),
0, KEY_QUERY_VALUE, &hKey);
if(lRet == ERROR_SUCCESS)
{
if(RegQueryValueEx(hKey, "~MHz", NULL, &dwType, (LPB
YTE)&numVal, &dwSize) == ERROR_SUCCESS)
StelApp::writeLog(QString("Processor speed:
%1 MHz").arg(numVal));
else
StelApp::writeLog("Could not get processor s
peed.");
}
// can you believe this trash?
dwType = REG_SZ;
char nameStr[512];
DWORD nameSize = sizeof(nameStr);
if(lRet == ERROR_SUCCESS)
{
if(RegQueryValueEx(hKey, "ProcessorNameString", NULL
, &dwType, (LPBYTE)&nameStr, &nameSize) == ERROR_SUCCESS)
StelApp::writeLog(QString("Processor name: %
1").arg(nameStr));
else
StelApp::writeLog("Could not get processor n
ame.");
}
RegCloseKey(hKey);
}
if(i == 0)
StelApp::writeLog("Could not get processor info.");
#elif defined Q_WS_MAC
StelApp::writeLog("You look like a Mac user. How would you like to w
rite some system info code here? That would help a lot.");
#endif
}
void StelApp::parseCLIArgsPreConfig(void)
{
if (argsGetOption(argList, "-v", "--version"))
{
qDebug() << qPrintable(getApplicationName());
exit(0);
}
if (argsGetOption(argList, "-h", "--help"))
{
// Get the basename of binary
QString binName = argList->at(0);
binName.remove(QRegExp("^.*[/\\\\]"));
qDebug() << "Usage:\n"
<< " "
<< qPrintable(binName) << " [options]\n\n"
<< "Options:\n"
<< "--version (or -v) : Print program name and ve
rsion and exit.\n"
<< "--help (or -h) : This cruft.\n"
<< "--config-file (or -c) : Use an alternative name f
or the config file\n"
<< "--user-dir (or -u) : Use an alternative user d
ata directory\n"
<< "--full-screen (or -f) : With argument \"yes\" or
\"no\" over-rides\n"
<< " the full screen setting i
n the config file\n"
<< "--screenshot-dir : Specify directory to save
screenshots\n"
<< "--startup-script : Specify name of startup s
cript\n"
<< "--home-planet : Specify observer planet (
English name)\n"
<< "--altitude : Specify observer altitude
in meters\n"
<< "--longitude : Specify longitude, e.g. +
53d58\\'16.65\\\"\n"
<< "--latitude : Specify latitude, e.g. -1
d4\\'27.48\\\"\n"
<< "--list-landscapes : Print a list of value lan
dscape IDs\n"
<< "--landscape : Start using landscape who
se ID (dir name)\n"
<< " is passed as parameter to
option\n"
<< "--sky-date : Specify sky date in forma
t yyyymmdd\n"
<< "--sky-time : Specify sky time in forma
t hh:mm:ss\n"
<< "--fov : Specify the field of view
(degrees)\n"
<< "--projection-type : Specify projection type,
e.g. stereographic\n"
<< "--restore-defaults : Delete existing config.in
i and use defaults\n";
exit(0);
}
if (argsGetOption(argList, "", "--list-landscapes"))
{
QSet<QString> landscapeIds = stelFileMgr->listContents("land
scapes", StelFileMgr::Directory);
for(QSet<QString>::iterator i=landscapeIds.begin(); i!=lands
capeIds.end(); ++i)
{
try
{
// finding the file will throw an exception
if it is not found
// in that case we won't output the landscap
e ID as it canont work
stelFileMgr->findFile("landscapes/" + *i + "
/landscape.ini");
qDebug() << qPrintable(*i);
}
catch (std::runtime_error& e){}
}
exit(0);
}
try
{
QString newUserDir;
newUserDir = argsGetOptionWithArg<QString>(argList, "-u", "-
-user-dir", "");
if (newUserDir!="" && !newUserDir.isEmpty())
stelFileMgr->setUserDir(newUserDir);
}
catch (std::runtime_error& e)
{
qCritical() << "ERROR: while processing --user-dir option: "
<< e.what();
exit(1);
}
// If the chosen user directory does not exist we will create it
if (!StelFileMgr::exists(stelFileMgr->getUserDir()))
{
if (!StelFileMgr::mkDir(stelFileMgr->getUserDir()))
{
qCritical() << "ERROR - cannot create non-existent u
ser directory" << stelFileMgr->getUserDir();
exit(1);
}
}
bool restoreDefaultConfigFile = false;
if (argsGetOption(argList, "", "--restore-defaults"))
restoreDefaultConfigFile=true;
try
{
setConfigFile(argsGetOptionWithArg<QString>(argList, "-c", "
--config-file", "config.ini"), restoreDefaultConfigFile);
}
catch (std::runtime_error& e)
{
qWarning() << "WARNING: while looking for --config-file opti
on: " << e.what() << ". Using \"config.ini\"";
setConfigFile("config.ini", restoreDefaultConfigFile);
}
startupScript = argsGetOptionWithArg<QString>(argList, "", "--startu
p-script", "startup.ssc");
}
void StelApp::parseCLIArgsPostConfig()
{
// Over-ride config file options with command line options
// We should catch exceptions from argsGetOptionWithArg...
int fullScreen, altitude;
float fov;
QString landscapeId, homePlanet, longitude, latitude, skyDate, skyTi
me, projectionType, screenshotDir;
try
{
fullScreen = argsGetYesNoOption(argList, "-f", "--full-scree
n", -1);
landscapeId = argsGetOptionWithArg<QString>(argList, "", "--
landscape", "");
homePlanet = argsGetOptionWithArg<QString>(argList, "", "--h
ome-planet", "");
altitude = argsGetOptionWithArg<int>(argList, "", "--altitud
e", -1);
longitude = argsGetOptionWithArg<QString>(argList, "", "--lo
ngitude", "");
latitude = argsGetOptionWithArg<QString>(argList, "", "--lat
itude", "");
skyDate = argsGetOptionWithArg<QString>(argList, "", "--sky-
date", "");
skyTime = argsGetOptionWithArg<QString>(argList, "", "--sky-
time", "");
fov = argsGetOptionWithArg<float>(argList, "", "--fov", -1.0
);
projectionType = argsGetOptionWithArg<QString>(argList, "",
"--projection-type", "");
screenshotDir = argsGetOptionWithArg<QString>(argList, "", "
--screenshot-dir", "");
}
catch (std::runtime_error& e)
{
qCritical() << "ERROR while checking command line options: "
<< e.what();
exit(0);
}
// Will be -1 if option is not found, in which case we don't change
anything.
if (fullScreen == 1) confSettings->setValue("video/fullscreen", true
);
else if (fullScreen == 0) confSettings->setValue("video/fullscreen",
false);
if (landscapeId != "") confSettings->setValue("init_location/landsca
pe_name", landscapeId);
if (homePlanet != "") confSettings->setValue("init_location/home_pla
net", homePlanet);
if (altitude != -1) confSettings->setValue("init_location/altitude",
altitude);
QRegExp longLatRx("[\\-+]?\\d+d\\d+\\'\\d+(\\.\\d+)?\"");
if (longitude != "")
{
if (longLatRx.exactMatch(longitude))
confSettings->setValue("init_location/longitude", lo
ngitude);
else
qWarning() << "WARNING: --longitude argument has unr
ecognised format";
}
if (latitude != "")
{
if (longLatRx.exactMatch(latitude))
confSettings->setValue("init_location/latitude", lat
itude);
else
qWarning() << "WARNING: --latitude argument has unre
cognised format";
}
if (skyDate != "" || skyTime != "")
{
// Get the Julian date for the start of the current day
// and the extra necessary for the time of day as separate
// components. Then if the --sky-date and/or --sky-time fla
gs
// are set we over-ride the component, and finally add them
to
// get the full julian date and set that.
// First, lets determine the Julian day number and the part
for the time of day
QDateTime now = QDateTime::currentDateTime();
double skyDatePart = now.date().toJulianDay();
double skyTimePart = StelUtils::qTimeToJDFraction(now.time()
);
// Over-ride the skyDatePart if the user specified the date
using --sky-date
if (skyDate != "")
{
// validate the argument format, we will tolerate yy
yy-mm-dd by removing all -'s
QRegExp dateRx("\\d{8}");
if (dateRx.exactMatch(skyDate.remove("-")))
skyDatePart = QDate::fromString(skyDate, "yy
yyMMdd").toJulianDay();
else
qWarning() << "WARNING: --sky-date argument
has unrecognised format (I want yyyymmdd)";
}
if (skyTime != "")
{
QRegExp timeRx("\\d{1,2}:\\d{2}:\\d{2}");
if (timeRx.exactMatch(skyTime))
skyTimePart = StelUtils::qTimeToJDFraction(Q
Time::fromString(skyTime, "hh:mm:ss"));
else
qWarning() << "WARNING: --sky-time argument
has unrecognised format (I want hh:mm:ss)";
}
confSettings->setValue("navigation/startup_time_mode", "pres
et");
confSettings->setValue("navigation/preset_sky_time", skyDate
Part + skyTimePart);
}
if (fov > 0.0) confSettings->setValue("navigation/init_fov", fov);
if (projectionType != "") confSettings->setValue("projection/type",
projectionType);
if (screenshotDir!="")
{
try
{
QString newShotDir = argsGetOptionWithArg<QString>(a
rgList, "", "--screenshot-dir", "");
if (!newShotDir.isEmpty() && newShotDir!="")
stelFileMgr->setScreenshotDir(newShotDir);
}
catch (std::runtime_error& e)
{
qWarning() << "WARNING: problem while setting screen
shot directory for --screenshot-dir option: " << e.what();
}
}
else
{
QString confScreenshotDir = confSettings->value("main/screen
shot_dir", "").toString();
if (confScreenshotDir!="")
{
try
{
stelFileMgr->setScreenshotDir(confScreenshot
Dir);
}
catch (std::runtime_error& e)
{
qWarning() << "WARNING: problem while settin
g screenshot from config file setting: " << e.what();
}
}
}
}
void StelApp::update(double deltaTime) void StelApp::update(double deltaTime)
{ {
if (!initialized) if (!initialized)
return; return;
++frame; ++frame;
timefr+=deltaTime; timefr+=deltaTime;
if (timefr-timeBase > 1.) if (timefr-timeBase > 1.)
{ {
// Calc the FPS rate every seconds // Calc the FPS rate every seconds
fps=(double)frame/(timefr-timeBase); fps=(double)frame/(timefr-timeBase);
frame = 0; frame = 0;
timeBase+=1.; timeBase+=1.;
} }
skipping to change at line 948 skipping to change at line 339
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionU pdate)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionU pdate))
{ {
i->update(deltaTime); i->update(deltaTime);
} }
stelObjectMgr->update(deltaTime); stelObjectMgr->update(deltaTime);
} }
//! Main drawing function called at each frame //! Iterate through the drawing sequence.
void StelApp::draw() bool StelApp::drawPartial()
{ {
if (!initialized) if (drawState == 0)
return;
core->preDraw();
// Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionD
raw))
{ {
i->draw(core); if (!initialized)
return false;
core->preDraw();
drawState = 1;
return true;
}
const QList<StelModule*> modules = moduleMgr->getCallOrders(StelModu
le::ActionDraw);
int index = drawState - 1;
if (index < modules.size())
{
if (modules[index]->drawPartial(core))
return true;
drawState++;
return true;
} }
core->postDraw(); core->postDraw();
drawState = 0;
return false;
}
//! Main drawing function called at each frame
void StelApp::draw()
{
Q_ASSERT(drawState == 0);
while (drawPartial()) {}
Q_ASSERT(drawState == 0);
} }
/************************************************************************* /*************************************************************************
Call this when the size of the GL window has changed Call this when the size of the GL window has changed
*************************************************************************/ *************************************************************************/
void StelApp::glWindowHasBeenResized(int w, int h) void StelApp::glWindowHasBeenResized(float x, float y, float w, float h)
{ {
if (core) if (core)
core->windowHasBeenResized(w, h); core->windowHasBeenResized(x, y, w, h);
else else
{ {
saveProjW = w; saveProjW = w;
saveProjH = h; saveProjH = h;
} }
// Send the event to every StelModule
foreach (StelModule* iter, moduleMgr->getAllModules())
{
iter->glWindowHasBeenResized(w, h);
}
} }
// Handle mouse clics // Handle mouse clics
void StelApp::handleClick(QMouseEvent* event) void StelApp::handleClick(QMouseEvent* event)
{ {
event->setAccepted(false); event->setAccepted(false);
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseClicks)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseClicks))
{ {
i->handleMouseClicks(event); i->handleMouseClicks(event);
skipping to change at line 1034 skipping to change at line 437
event->setAccepted(false); event->setAccepted(false);
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleKeys)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleKeys))
{ {
i->handleKeys(event); i->handleKeys(event);
if (event->isAccepted()) if (event->isAccepted())
return; return;
} }
} }
void StelApp::setConfigFile(const QString& configName, bool restoreDefaults
)
{
try
{
configFile = stelFileMgr->findFile(configName, StelFileMgr::
Flags(StelFileMgr::Writable|StelFileMgr::File));
if (restoreDefaults == true)
{
QString backupFile(configFile.left(configFile.length
()-3) + QString("old"));
if (QFileInfo(backupFile).exists())
QFile(backupFile).remove();
QFile(configFile).rename(backupFile);
qDebug() << "setting defaults - old config is backed
up in " << backupFile;
}
return;
}
catch (std::runtime_error& e)
{
//qDebug() << "DEBUG StelApp::setConfigFile could not locate
writable config file " << configName;
}
try
{
configFile = stelFileMgr->findFile(configName, StelFileMgr::
File);
return;
}
catch (std::runtime_error& e)
{
//qDebug() << "DEBUG StelApp::setConfigFile could not find r
ead only config file " << configName;
}
try
{
configFile = stelFileMgr->findFile(configName, StelFileMgr::
New);
//qDebug() << "DEBUG StelApp::setConfigFile found NEW file p
ath: " << configFile;
return;
}
catch (std::runtime_error& e)
{
qCritical() << "ERROR StelApp::setConfigFile could not find
or create configuration file " << configName;
exit(1);
}
}
void StelApp::copyDefaultConfigFile()
{
QString defaultConfigFilePath;
try
{
defaultConfigFilePath = stelFileMgr->findFile("data/default_
config.ini");
}
catch (std::runtime_error& e)
{
qCritical() << "ERROR StelApp::copyDefaultConfigFile failed
to locate data/default_config.ini. Please check your installation.";
exit(1);
}
QFile::copy(defaultConfigFilePath, configFile);
if (!stelFileMgr->exists(configFile))
{
qCritical() << "ERROR StelApp::copyDefaultConfigFile failed
to copy file " << defaultConfigFilePath
<< " to " << configFile << ". You could try to copy
it by hand.";
exit(1);
}
}
// Set the colorscheme for all the modules // Set the colorscheme for all the modules
void StelApp::setColorScheme(const QString& section) void StelApp::setColorScheme(const QString& section)
{ {
if (!currentStelStyle) if (!currentStelStyle)
currentStelStyle = new StelStyle; currentStelStyle = new StelStyle;
currentStelStyle->confSectionName = section; currentStelStyle->confSectionName = section;
QString qtStyleFileName; QString qtStyleFileName;
QString htmlStyleFileName; QString htmlStyleFileName;
skipping to change at line 1124 skipping to change at line 460
qtStyleFileName = "data/gui/nightStyle.css"; qtStyleFileName = "data/gui/nightStyle.css";
htmlStyleFileName = "data/gui/nightHtml.css"; htmlStyleFileName = "data/gui/nightHtml.css";
} }
else if (section=="color") else if (section=="color")
{ {
qtStyleFileName = "data/gui/normalStyle.css"; qtStyleFileName = "data/gui/normalStyle.css";
htmlStyleFileName = "data/gui/normalHtml.css"; htmlStyleFileName = "data/gui/normalHtml.css";
} }
// Load Qt style sheet // Load Qt style sheet
StelFileMgr& fileMan(StelApp::getInstance().getFileMgr());
QString styleFilePath; QString styleFilePath;
try try
{ {
styleFilePath = fileMan.findFile(qtStyleFileName); styleFilePath = StelFileMgr::findFile(qtStyleFileName);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "WARNING: can't find Qt style sheet:" << qtSty leFileName; qWarning() << "WARNING: can't find Qt style sheet:" << qtSty leFileName;
} }
QFile styleFile(styleFilePath); QFile styleFile(styleFilePath);
styleFile.open(QIODevice::ReadOnly); styleFile.open(QIODevice::ReadOnly);
currentStelStyle->qtStyleSheet = styleFile.readAll(); currentStelStyle->qtStyleSheet = styleFile.readAll();
// Load HTML style sheet // Load HTML style sheet
try try
{ {
styleFilePath = fileMan.findFile(htmlStyleFileName); styleFilePath = StelFileMgr::findFile(htmlStyleFileName);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "WARNING: can't find css:" << htmlStyleFileNam e; qWarning() << "WARNING: can't find css:" << htmlStyleFileNam e;
} }
QFile htmlStyleFile(styleFilePath); QFile htmlStyleFile(styleFilePath);
htmlStyleFile.open(QIODevice::ReadOnly); htmlStyleFile.open(QIODevice::ReadOnly);
currentStelStyle->htmlStyleSheet = htmlStyleFile.readAll(); currentStelStyle->htmlStyleSheet = htmlStyleFile.readAll();
// Send the event to every StelModule // Send the event to every StelModule
skipping to change at line 1171 skipping to change at line 506
if (flagNightVision!=b) if (flagNightVision!=b)
{ {
flagNightVision=b; flagNightVision=b;
setColorScheme(b ? "night_color" : "color"); setColorScheme(b ? "night_color" : "color");
} }
} }
// Update translations and font for sky everywhere in the program // Update translations and font for sky everywhere in the program
void StelApp::updateI18n() void StelApp::updateI18n()
{ {
StelMainWindow::getInstance().initTitleI18n();
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* iter, moduleMgr->getAllModules()) foreach (StelModule* iter, moduleMgr->getAllModules())
{ {
iter->updateI18n(); iter->updateI18n();
} }
if (getGui())
getGui()->updateI18n();
} }
// Update and reload sky culture informations everywhere in the program // Update and reload sky culture informations everywhere in the program
void StelApp::updateSkyCulture() void StelApp::updateSkyCulture()
{ {
QString skyCultureDir = getSkyCultureMgr().getCurrentSkyCultureID(); QString skyCultureDir = getSkyCultureMgr().getCurrentSkyCultureID();
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* iter, moduleMgr->getAllModules()) foreach (StelModule* iter, moduleMgr->getAllModules())
{ {
iter->updateSkyCulture(skyCultureDir); iter->updateSkyCulture(skyCultureDir);
} }
} }
bool StelApp::argsGetOption(QStringList* args, QString shortOpt, QString lo
ngOpt)
{
bool result=false;
// Don't see anything after a -- as an option
int lastOptIdx = args->indexOf("--");
if (lastOptIdx == -1)
lastOptIdx = args->size();
for(int i=0; i<lastOptIdx; i++)
{
if ((shortOpt!="" && args->at(i) == shortOpt) || args->at(i)
== longOpt)
{
result = true;
i=args->size();
}
}
return result;
}
template<class T>
T StelApp::argsGetOptionWithArg(QStringList* args, QString shortOpt, QStrin
g longOpt, T defaultValue)
{
// Don't see anything after a -- as an option
int lastOptIdx = args->indexOf("--");
if (lastOptIdx == -1)
lastOptIdx = args->size();
for(int i=0; i<lastOptIdx; i++)
{
bool match(false);
QString argStr("");
// form -n=arg
if ((shortOpt!="" && args->at(i).left(shortOpt.length()+1)==
shortOpt+"="))
{
match=true;
argStr=args->at(i).right(args->at(i).length() - shor
tOpt.length() - 1);
}
// form --number=arg
else if (args->at(i).left(longOpt.length()+1)==longOpt+"=")
{
match=true;
argStr=args->at(i).right(args->at(i).length() - long
Opt.length() - 1);
}
// forms -n arg and --number arg
else if ((shortOpt!="" && args->at(i)==shortOpt) || args->at
(i)==longOpt)
{
if (i+1>=lastOptIdx)
{
throw (std::runtime_error(qPrintable("optarg
_missing ("+longOpt+")")));
}
else
{
match=true;
argStr=args->at(i+1);
i++; // skip option argument in next iterat
ion
}
}
if (match)
{
T retVal;
QTextStream converter(qPrintable(argStr));
converter >> retVal;
if (converter.status() != QTextStream::Ok)
throw (std::runtime_error(qPrintable("optarg
_type ("+longOpt+")")));
else
return retVal;
}
}
return defaultValue;
}
int StelApp::argsGetYesNoOption(QStringList* args, QString shortOpt, QStrin
g longOpt, int defaultValue)
{
QString strArg = argsGetOptionWithArg<QString>(args, shortOpt, longO
pt, "");
if (strArg == "")
{
return defaultValue;
}
if (strArg.compare("yes", Qt::CaseInsensitive)==0
|| strArg.compare("y", Qt::CaseInsensitive)==0
|| strArg.compare("true", Qt::CaseInsensitive)==0
|| strArg.compare("t", Qt::CaseInsensitive)==0
|| strArg.compare("on", Qt::CaseInsensitive)==0
|| strArg=="1")
{
return 1;
}
else if (strArg.compare("no", Qt::CaseInsensitive)==0
|| strArg.compare("n", Qt::CaseInsensitive)==0
|| strArg.compare("false", Qt::CaseInsensitive)==0
|| strArg.compare("f", Qt::CaseInsensitive)==0
|| strArg.compare("off", Qt::CaseInsensitive)==0
|| strArg=="0")
{
return 0;
}
else
{
throw (std::runtime_error("optarg_type"));
}
}
// Return the time since when stellarium is running in second. // Return the time since when stellarium is running in second.
double StelApp::getTotalRunTime() double StelApp::getTotalRunTime()
{ {
return (double)StelApp::qtime->elapsed()/1000; return (double)(StelApp::qtime->elapsed())/1000.;
} }
void StelApp::reportFileDownloadFinished(QNetworkReply* reply) void StelApp::reportFileDownloadFinished(QNetworkReply* reply)
{ {
#if QT_VERSION >= 0x040500
bool fromCache = reply->attribute(QNetworkRequest::SourceIsFromCache Attribute).toBool(); bool fromCache = reply->attribute(QNetworkRequest::SourceIsFromCache Attribute).toBool();
#else
bool fromCache = false;
#endif
if (fromCache) if (fromCache)
{ {
++nbUsedCache; ++nbUsedCache;
totalUsedCacheSize+=reply->bytesAvailable(); totalUsedCacheSize+=reply->bytesAvailable();
} }
else else
{ {
++nbDownloadedFiles; ++nbDownloadedFiles;
totalDownloadedSize+=reply->bytesAvailable(); totalDownloadedSize+=reply->bytesAvailable();
} }
} }
void StelApp::makeMainGLContextCurrent()
{
StelMainGraphicsView::getInstance().makeGLContextCurrent();
}
 End of changes. 61 change blocks. 
1034 lines changed or deleted 115 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/