StelApp.cpp   StelApp.cpp 
skipping to change at line 25 skipping to change at line 25
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "LoadingBar.hpp" #include "StelLoadingBar.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "TelescopeMgr.hpp" #include "TelescopeMgr.hpp"
#include "ConstellationMgr.hpp" #include "ConstellationMgr.hpp"
#include "NebulaMgr.hpp" #include "NebulaMgr.hpp"
#include "LandscapeMgr.hpp" #include "LandscapeMgr.hpp"
#include "GridLinesMgr.hpp" #include "GridLinesMgr.hpp"
#include "MilkyWay.hpp" #include "MilkyWay.hpp"
#include "MeteorMgr.hpp" #include "MeteorMgr.hpp"
#include "LabelMgr.hpp"
#include "ScreenImageMgr.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "Projector.hpp" #include "StelProjector.hpp"
#include "LocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "StelDownloadMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelFontMgr.hpp" #include "StelFontMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "MovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
//#include "QtScriptMgr.hpp" #include "StelScriptMgr.hpp"
#include "QtJsonParser.hpp" #include "StelJsonParser.hpp"
#include "SkyBackground.hpp" #include "StelSkyImageMgr.hpp"
#include "StelAudioMgr.hpp"
#include "StelStyle.hpp" #include "StelStyle.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>
#ifdef WIN32
#include <windows.h>
#endif
// 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;
/************************************************************************* /*************************************************************************
Create and initialize the main Stellarium application. Create and initialize the main Stellarium application.
*************************************************************************/ *************************************************************************/
StelApp::StelApp(int argc, char** argv, QObject* parent) : QObject(parent), StelApp::StelApp(int argc, char** argv, QObject* parent)
core(NULL), fps(0), maxfps(10000.f), frame(0), timefr(0.), : QObject(parent), core(NULL), fps(0), maxfps(10000.f), frame(0),
timeBase(0.), flagNightVision(false), configFile("config.ini"), conf timefr(0.), timeBase(0.), flagNightVision(false),
Settings(NULL), configFile("config.ini"), startupScript("startup.ssc"),
initialized(false), saveProjW(-1), saveProjH(-1) confSettings(NULL), initialized(false), saveProjW(-1),
{ saveProjH(-1)
{
// Stat variables
nbDownloadedFiles=0;
totalDownloadedSize=0;
nbUsedCache=0;
totalUsedCacheSize=0;
// Used for getting system date formatting // Used for getting system date formatting
setlocale(LC_TIME, ""); setlocale(LC_TIME, "");
// We need scanf()/printf() and friends to always work in the C loca le, // We need scanf()/printf() and friends to always work in the C loca le,
// otherwise configuration/INI file parsing will be erroneous. // otherwise configuration/INI file parsing will be erroneous.
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
setObjectName("StelApp"); setObjectName("StelApp");
skyCultureMgr=NULL; skyCultureMgr=NULL;
localeMgr=NULL; localeMgr=NULL;
fontManager=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
assert(!singleton); Q_ASSERT(!singleton);
singleton = this; singleton = this;
argList = new QStringList; argList = new QStringList;
for(int i=0; i<argc; i++) for(int i=0; i<argc; i++)
*argList << argv[i]; *argList << argv[i];
// Echo debug output to log file
stelFileMgr = new StelFileMgr(); 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 = new QTime();
StelApp::qtime->start(); 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 // 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. // output, such as --help and --version, and if we want to set the c onfigFile value.
parseCLIArgsPreConfig(); parseCLIArgsPreConfig();
// Load language codes // Load language codes
try try
{ {
Translator::init(stelFileMgr->findFile("data/iso639-1.utf8") ); StelTranslator::init(stelFileMgr->findFile("data/iso639-1.ut f8"));
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "ERROR while loading translations: " << e.what() << endl; qDebug() << "ERROR while loading translations: " << e.what() << endl;
} }
// OK, print the console splash and get on with loading the program // OK, print the console splash and get on with loading the program
std::cout << " ----------------------------------------------------- QString versionLine = QString("This is %1 - http://www.stellarium.or
--" << std::endl; g").arg(StelApp::getApplicationName());
std::cout << "[ This is " << qPrintable(StelApp::getApplicationName( QString copyrightLine = QString("Copyright (C) 2000-2009 Fabien Cher
)) << " - http://www.stellarium.org ]" << std::endl; eau et al");
std::cout << "[ Copyright (C) 2000-2008 Fabien Chereau et al int maxLength = qMax(versionLine.size(), copyrightLine.size());
]" << std::endl; qDebug() << qPrintable(QString(" %1").arg(QString().fill('-', maxLen
std::cout << " ----------------------------------------------------- gth+2)));
--" << std::endl; 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(); QStringList p=stelFileMgr->getSearchPaths();
qDebug() << "File search paths:"; qDebug() << "File search paths:";
int n=0; int n=0;
foreach (QString i, p) foreach (QString i, p)
{ {
qDebug() << " " << n << ". " << i; qDebug() << " " << n << ". " << i;
++n; ++n;
} }
qDebug() << "Config file is: " << configFile; 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)) if (!stelFileMgr->exists(configFile))
{ {
qDebug() << "config file " << configFile << " does not exist - copying the default file."; qDebug() << "config file " << configFile << " does not exist - copying the default file.";
copyDefaultConfigFile(); copyDefaultConfigFile();
} }
// Load the configuration file // Load the configuration file
confSettings = new QSettings(getConfigFilePath(), StelIniFormat, thi s); confSettings = new QSettings(getConfigFilePath(), StelIniFormat, thi s);
// Main section // Main section
skipping to change at line 202 skipping to change at line 256
// 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));
#endif
if (scriptMgr->scriptIsRunning())
scriptMgr->stopScript();
stelObjectMgr->unSelect();
moduleMgr->unloadModule("StelSkyImageMgr", false); // We need to de
lete it afterward
moduleMgr->unloadModule("StelObjectMgr", false);// We need to delete
it afterward
StelModuleMgr* tmp = moduleMgr;
moduleMgr = new StelModuleMgr(); // Create a secondary instance to a
void crashes at other deinit
delete tmp; tmp=NULL;
delete loadingBar; loadingBar=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 fontManager; fontManager=NULL;
delete stelObjectMgr; stelObjectMgr=NULL; delete skyImageMgr; skyImageMgr=NULL; // Delete the module by hand a
fterward
delete audioMgr; audioMgr=NULL;
delete stelObjectMgr; stelObjectMgr=NULL; // Delete the module by ha
nd afterward
delete stelFileMgr; stelFileMgr=NULL; delete stelFileMgr; stelFileMgr=NULL;
delete moduleMgr; moduleMgr=NULL; // Also delete all modules
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 argList; argList=NULL; delete argList; argList=NULL;
delete currentStelStyle; delete currentStelStyle;
assert(singleton); logFile.close();
Q_ASSERT(singleton);
singleton = NULL; singleton = NULL;
} }
#if QT_VERSION >= 0x040500
#include <QNetworkDiskCache>
#include <QDesktopServices>
#endif
/************************************************************************* /*************************************************************************
Return the full name of stellarium, i.e. "stellarium 0.9.0" Return the full name of stellarium, i.e. "stellarium 0.9.0"
*************************************************************************/ *************************************************************************/
QString StelApp::getApplicationName() QString StelApp::getApplicationName()
{ {
#ifdef SVN_REVISION
return QString("Stellarium")+" "+PACKAGE_VERSION+" (SVN r"+SVN_REVIS
ION+")";
#else
return QString("Stellarium")+" "+PACKAGE_VERSION; return QString("Stellarium")+" "+PACKAGE_VERSION;
#endif
}
void StelApp::debugLogHandler(QtMsgType type, const char* msg)
{
fprintf(stderr, "%s\n", msg);
StelApp::writeLog(QString(msg));
}
void StelApp::writeLog(QString msg)
{
msg += "\n";
logFile.write(qPrintable(msg), msg.size());
log += msg;
} }
void StelApp::init() void StelApp::init()
{ {
networkAccessManager = new QNetworkAccessManager(this); networkAccessManager = new QNetworkAccessManager(this);
// #if QT_VERSION >= 0x040500
// // Activate http cache if Qt version >= 4.5
// QNetworkDiskCache* cache = new QNetworkDiskCache(networkAccessManage
r);
// QString cachePath = QDesktopServices::storageLocation(QDesktopServic
es::CacheLocation);
// if (cachePath.isEmpty())
// {
// cachePath = StelApp::getInstance().getFileMgr().getUserDir()
+"/cache";
// }
// qDebug() << "Cache directory is: " << cachePath;
// cache->setCacheDirectory(cachePath);
// networkAccessManager->setCache(cache);
// #endif
connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), this
, SLOT(reportFileDownloadFinished(QNetworkReply*)));
core = new StelCore(); core = new StelCore();
if (saveProjW!=-1 && saveProjH!=-1) if (saveProjW!=-1 && saveProjH!=-1)
core->getProjection()->windowHasBeenResized(saveProjW, saveP rojH); core->windowHasBeenResized(saveProjW, saveProjH);
textureMgr = new StelTextureMgr(); textureMgr = new StelTextureMgr();
localeMgr = new StelLocaleMgr(); localeMgr = new StelLocaleMgr();
fontManager = new StelFontMgr(); fontManager = new StelFontMgr();
skyCultureMgr = new StelSkyCultureMgr(); skyCultureMgr = new StelSkyCultureMgr();
planetLocationMgr = new LocationMgr(); planetLocationMgr = new StelLocationMgr();
timeMultiplier = 1;
// Initialize AFTER creation of openGL context // Initialize AFTER creation of openGL context
textureMgr->init(); textureMgr->init();
loadingBar = new LoadingBar(core->getProjection(), 12., "logo24bitsb #ifdef SVN_REVISION
eta.png", loadingBar = new StelLoadingBar(12., "logo24bits.png", QString("SVN
core->getProjection()->getViewportWidth(), core->getPr r%1").arg(SVN_REVISION), 25, 320, 101);
ojection()->getViewportHeight(), #else
PACKAGE_VERSION, 45, 320, 121); loadingBar = new StelLoadingBar(12., "logo24bits.png", PACKAGE_VERSI
ON, 45, 320, 121);
#endif // SVN_RELEASE
downloadMgr = new StelDownloadMgr();
// 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);
localeMgr->init(); localeMgr->init();
skyCultureMgr->init(); skyCultureMgr->init();
// Init the solar system first // Init the solar system first
skipping to change at line 279 skipping to change at line 386
// Init nebulas // Init nebulas
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 background // Init sky image manager
SkyBackground* skyBackground = new SkyBackground(); skyImageMgr = new StelSkyImageMgr();
skyBackground->init(); skyImageMgr->init();
getModuleMgr().registerModule(skyBackground); getModuleMgr().registerModule(skyImageMgr);
// Init audio manager
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);
// Constellations // Constellations
ConstellationMgr* asterisms = new ConstellationMgr(hip_stars); ConstellationMgr* asterisms = new ConstellationMgr(hip_stars);
asterisms->init(); asterisms->init();
getModuleMgr().registerModule(asterisms); getModuleMgr().registerModule(asterisms);
skipping to change at line 308 skipping to change at line 418
GridLinesMgr* gridLines = new GridLinesMgr(); GridLinesMgr* gridLines = new GridLinesMgr();
gridLines->init(); gridLines->init();
getModuleMgr().registerModule(gridLines); getModuleMgr().registerModule(gridLines);
// Meteors // Meteors
MeteorMgr* meteors = new MeteorMgr(10, 60); MeteorMgr* meteors = new MeteorMgr(10, 60);
meteors->init(); meteors->init();
getModuleMgr().registerModule(meteors); getModuleMgr().registerModule(meteors);
// User labels
LabelMgr* skyLabels = new LabelMgr();
skyLabels->init();
getModuleMgr().registerModule(skyLabels);
// Scripting images
ScreenImageMgr* scriptImages = new ScreenImageMgr();
scriptImages->init();
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 // Generate dependency Lists for all modules
moduleMgr->generateCallingLists(); moduleMgr->generateCallingLists();
updateI18n(); updateI18n();
//QtScriptMgr scriptMgr; scriptMgr = new StelScriptMgr(this);
//scriptMgr.test();
initialized = true; initialized = true;
} }
// 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())
{ {
skipping to change at line 345 skipping to change at line 464
continue; continue;
StelModule* m = moduleMgr->loadPlugin(i.key); StelModule* m = moduleMgr->loadPlugin(i.key);
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) void StelApp::parseCLIArgsPreConfig(void)
{ {
if (argsGetOption(argList, "-v", "--version")) if (argsGetOption(argList, "-v", "--version"))
{ {
std::cout << qPrintable(getApplicationName()) << std::endl; qDebug() << qPrintable(getApplicationName());
exit(0); exit(0);
} }
if (argsGetOption(argList, "-h", "--help")) if (argsGetOption(argList, "-h", "--help"))
{ {
// Get the basename of binary // Get the basename of binary
QString binName = argList->at(0); QString binName = argList->at(0);
binName.remove(QRegExp("^.*[/\\\\]")); binName.remove(QRegExp("^.*[/\\\\]"));
std::cout << "Usage:" << std::endl qDebug() << "Usage:\n"
<< " " << " "
<< qPrintable(binName) << " [options]" << std::endl << << qPrintable(binName) << " [options]\n\n"
std::endl << "Options:\n"
<< "Options:" << std::endl << "--version (or -v) : Print program name and ve
<< "--version (or -v) : Print program name and ve rsion and exit.\n"
rsion and exit." << std::endl << "--help (or -h) : This cruft.\n"
<< "--help (or -h) : This cruft." << std::endl << "--config-file (or -c) : Use an alternative name f
<< "--config-file (or -c) : Use an alternative name f or the config file\n"
or the config file" << std::endl << "--user-dir (or -u) : Use an alternative user d
<< "--user-dir (or -u) : Use an alternative user d ata directory\n"
ata directory" << std::endl << "--full-screen (or -f) : With argument \"yes\" or
<< "--full-screen (or -f) : With argument \"yes\" or \"no\" over-rides\n"
\"no\" over-rides" << std::endl << " the full screen setting i
<< " the full screen setting i n the config file\n"
n the config file" << std::endl << "--screenshot-dir : Specify directory to save
<< "--screenshot-dir : Specify directory to save screenshots\n"
screenshots" << std::endl << "--startup-script : Specify name of startup s
<< "--home-planet : Specify observer planet ( cript\n"
English name)" << std::endl << "--home-planet : Specify observer planet (
<< "--altitude : Specify observer altitude English name)\n"
in meters" << std::endl << "--altitude : Specify observer altitude
<< "--longitude : Specify longitude, e.g. + in meters\n"
53d58\\'16.65\\\"" << std::endl << "--longitude : Specify longitude, e.g. +
<< "--latitude : Specify latitude, e.g. -1 53d58\\'16.65\\\"\n"
d4\\'27.48\\\"" << std::endl << "--latitude : Specify latitude, e.g. -1
<< "--list-landscapes : Print a list of value lan d4\\'27.48\\\"\n"
dscape IDs" << std::endl << "--list-landscapes : Print a list of value lan
<< "--landscape : Start using landscape who dscape IDs\n"
se ID (dir name)" << std::endl << "--landscape : Start using landscape who
<< " is passed as parameter to se ID (dir name)\n"
option" << std::endl << " is passed as parameter to
<< "--sky-date : Specify sky date in forma option\n"
t yyyymmdd" << std::endl << "--sky-date : Specify sky date in forma
<< "--sky-time : Specify sky time in forma t yyyymmdd\n"
t hh:mm:ss" << std::endl << "--sky-time : Specify sky time in forma
<< "--fov : Specify the field of view t hh:mm:ss\n"
(degrees)" << std::endl << "--fov : Specify the field of view
<< "--projection-type : Specify projection type, (degrees)\n"
e.g. stereographic" << std::endl << "--projection-type : Specify projection type,
<< "--restore-defaults : Delete existing config.in e.g. stereographic\n"
i and use defaults" << std::endl; << "--restore-defaults : Delete existing config.in
i and use defaults\n";
exit(0); exit(0);
} }
if (argsGetOption(argList, "", "--list-landscapes")) if (argsGetOption(argList, "", "--list-landscapes"))
{ {
QSet<QString> landscapeIds = stelFileMgr->listContents("land scapes", StelFileMgr::Directory); QSet<QString> landscapeIds = stelFileMgr->listContents("land scapes", StelFileMgr::Directory);
for(QSet<QString>::iterator i=landscapeIds.begin(); i!=lands capeIds.end(); ++i) for(QSet<QString>::iterator i=landscapeIds.begin(); i!=lands capeIds.end(); ++i)
{ {
try try
{ {
// finding the file will throw an exception if it is not found // 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 // in that case we won't output the landscap e ID as it canont work
stelFileMgr->findFile("landscapes/" + *i + " /landscape.ini"); stelFileMgr->findFile("landscapes/" + *i + " /landscape.ini");
std::cout << qPrintable(*i) << std::endl; qDebug() << qPrintable(*i);
} }
catch (std::runtime_error& e){} catch (std::runtime_error& e){}
} }
exit(0); exit(0);
} }
try try
{ {
QString newUserDir; QString newUserDir;
newUserDir = argsGetOptionWithArg<QString>(argList, "-u", "- -user-dir", ""); newUserDir = argsGetOptionWithArg<QString>(argList, "-u", "- -user-dir", "");
skipping to change at line 439 skipping to change at line 779
try try
{ {
setConfigFile(argsGetOptionWithArg<QString>(argList, "-c", " --config-file", "config.ini"), restoreDefaultConfigFile); setConfigFile(argsGetOptionWithArg<QString>(argList, "-c", " --config-file", "config.ini"), restoreDefaultConfigFile);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "WARNING: while looking for --config-file opti on: " << e.what() << ". Using \"config.ini\""; qWarning() << "WARNING: while looking for --config-file opti on: " << e.what() << ". Using \"config.ini\"";
setConfigFile("config.ini", restoreDefaultConfigFile); setConfigFile("config.ini", restoreDefaultConfigFile);
} }
try startupScript = argsGetOptionWithArg<QString>(argList, "", "--startu
{ p-script", "startup.ssc");
QString newShotDir = argsGetOptionWithArg<QString>(argList,
"", "--screenshot-dir", "");
if (!newShotDir.isEmpty() && newShotDir!="")
stelFileMgr->setScreenshotDir(newShotDir);
}
catch (std::runtime_error& e)
{
qWarning() << "WARNING: problem while setting screenshot dir
ectory for --screenshot-dir option: " << e.what();
}
} }
void StelApp::parseCLIArgsPostConfig() void StelApp::parseCLIArgsPostConfig()
{ {
// Over-ride config file options with command line options // Over-ride config file options with command line options
// We should catch exceptions from argsGetOptionWithArg... // We should catch exceptions from argsGetOptionWithArg...
int fullScreen, altitude; int fullScreen, altitude;
float fov; float fov;
QString landscapeId, homePlanet, longitude, latitude, skyDate, skyTi me, projectionType; QString landscapeId, homePlanet, longitude, latitude, skyDate, skyTi me, projectionType, screenshotDir;
try try
{ {
fullScreen = argsGetYesNoOption(argList, "-f", "--full-scree n", -1); fullScreen = argsGetYesNoOption(argList, "-f", "--full-scree n", -1);
landscapeId = argsGetOptionWithArg<QString>(argList, "", "-- landscape", ""); landscapeId = argsGetOptionWithArg<QString>(argList, "", "-- landscape", "");
homePlanet = argsGetOptionWithArg<QString>(argList, "", "--h ome-planet", ""); homePlanet = argsGetOptionWithArg<QString>(argList, "", "--h ome-planet", "");
altitude = argsGetOptionWithArg<int>(argList, "", "--altitud e", -1); altitude = argsGetOptionWithArg<int>(argList, "", "--altitud e", -1);
longitude = argsGetOptionWithArg<QString>(argList, "", "--lo ngitude", ""); longitude = argsGetOptionWithArg<QString>(argList, "", "--lo ngitude", "");
latitude = argsGetOptionWithArg<QString>(argList, "", "--lat itude", ""); latitude = argsGetOptionWithArg<QString>(argList, "", "--lat itude", "");
skyDate = argsGetOptionWithArg<QString>(argList, "", "--sky- date", ""); skyDate = argsGetOptionWithArg<QString>(argList, "", "--sky- date", "");
skyTime = argsGetOptionWithArg<QString>(argList, "", "--sky- time", ""); skyTime = argsGetOptionWithArg<QString>(argList, "", "--sky- time", "");
fov = argsGetOptionWithArg<float>(argList, "", "--fov", -1.0 ); fov = argsGetOptionWithArg<float>(argList, "", "--fov", -1.0 );
projectionType = argsGetOptionWithArg<QString>(argList, "", "--projection-type", ""); projectionType = argsGetOptionWithArg<QString>(argList, "", "--projection-type", "");
screenshotDir = argsGetOptionWithArg<QString>(argList, "", " --screenshot-dir", "");
} }
catch (std::exception& e) catch (std::runtime_error& e)
{ {
qCritical() << "ERROR while checking command line options: " << e.what(); qCritical() << "ERROR while checking command line options: " << e.what();
exit(0); exit(0);
} }
// Will be -1 if option is not found, in which case we don't change anything. // Will be -1 if option is not found, in which case we don't change anything.
if (fullScreen == 1) confSettings->setValue("video/fullscreen", true ); if (fullScreen == 1) confSettings->setValue("video/fullscreen", true );
else if (fullScreen == 0) confSettings->setValue("video/fullscreen", false); else if (fullScreen == 0) confSettings->setValue("video/fullscreen", false);
if (landscapeId != "") confSettings->setValue("init_location/landsca pe_name", landscapeId); if (landscapeId != "") confSettings->setValue("init_location/landsca pe_name", landscapeId);
skipping to change at line 519 skipping to change at line 850
// and the extra necessary for the time of day as separate // and the extra necessary for the time of day as separate
// components. Then if the --sky-date and/or --sky-time fla gs // components. Then if the --sky-date and/or --sky-time fla gs
// are set we over-ride the component, and finally add them to // are set we over-ride the component, and finally add them to
// get the full julian date and set that. // get the full julian date and set that.
// First, lets determine the Julian day number and the part for the time of day // First, lets determine the Julian day number and the part for the time of day
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
double skyDatePart = now.date().toJulianDay(); double skyDatePart = now.date().toJulianDay();
double skyTimePart = StelUtils::qTimeToJDFraction(now.time() ); double skyTimePart = StelUtils::qTimeToJDFraction(now.time() );
// Over-ride the sktDatePart if the user specified the date using --sky-date // Over-ride the skyDatePart if the user specified the date using --sky-date
if (skyDate != "") if (skyDate != "")
{ {
// validate the argument format, we will tolerate yy yy-mm-dd by removing all -'s // validate the argument format, we will tolerate yy yy-mm-dd by removing all -'s
QRegExp dateRx("\\d{8}"); QRegExp dateRx("\\d{8}");
if (dateRx.exactMatch(skyDate.remove("-"))) if (dateRx.exactMatch(skyDate.remove("-")))
skyDatePart = QDate::fromString(skyDate, "yy yyMMdd").toJulianDay(); skyDatePart = QDate::fromString(skyDate, "yy yyMMdd").toJulianDay();
else else
qWarning() << "WARNING: --sky-date argument has unrecognised format (I want yyyymmdd)"; qWarning() << "WARNING: --sky-date argument has unrecognised format (I want yyyymmdd)";
} }
skipping to change at line 546 skipping to change at line 877
qWarning() << "WARNING: --sky-time argument has unrecognised format (I want hh:mm:ss)"; qWarning() << "WARNING: --sky-time argument has unrecognised format (I want hh:mm:ss)";
} }
confSettings->setValue("navigation/startup_time_mode", "pres et"); confSettings->setValue("navigation/startup_time_mode", "pres et");
confSettings->setValue("navigation/preset_sky_time", skyDate Part + skyTimePart); confSettings->setValue("navigation/preset_sky_time", skyDate Part + skyTimePart);
} }
if (fov > 0.0) confSettings->setValue("navigation/init_fov", fov); if (fov > 0.0) confSettings->setValue("navigation/init_fov", fov);
if (projectionType != "") confSettings->setValue("projection/type", projectionType); 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.;
} }
// change time rate if needed to fast forward scripts
deltaTime *= timeMultiplier;
core->update(deltaTime); core->update(deltaTime);
moduleMgr->update(); moduleMgr->update();
// 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);
} }
skipping to change at line 602 skipping to change at line 959
core->postDraw(); core->postDraw();
} }
/************************************************************************* /*************************************************************************
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(int w, int h)
{ {
if (core) if (core)
core->getProjection()->windowHasBeenResized(w, h); core->windowHasBeenResized(w, h);
else else
{ {
saveProjW = w; saveProjW = w;
saveProjH = h; saveProjH = h;
} }
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* iter, moduleMgr->getAllModules()) foreach (StelModule* iter, moduleMgr->getAllModules())
{ {
iter->glWindowHasBeenResized(w, h); 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 angleMouseClicks)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseClicks))
{ {
i->handleMouseClicks(event); i->handleMouseClicks(event);
if (event->isAccepted()) if (event->isAccepted())
return; return;
} }
} }
// Handle mouse wheel. // Handle mouse wheel.
void StelApp::handleWheel(QWheelEvent* event) void StelApp::handleWheel(QWheelEvent* 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 angleMouseClicks)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseClicks))
{ {
i->handleMouseWheel(event); i->handleMouseWheel(event);
if (event->isAccepted()) if (event->isAccepted())
return; return;
} }
} }
// Handle mouse move // Handle mouse move
void StelApp::handleMove(int x, int y, Qt::MouseButtons b) void StelApp::handleMove(int x, int y, Qt::MouseButtons b)
{ {
skipping to change at line 931 skipping to change at line 1288
{ {
throw (std::runtime_error("optarg_type")); 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)
{
#if QT_VERSION >= 0x040500
bool fromCache = reply->attribute(QNetworkRequest::SourceIsFromCache
Attribute).toBool();
#else
bool fromCache = false;
#endif
if (fromCache)
{
++nbUsedCache;
totalUsedCacheSize+=reply->bytesAvailable();
}
else
{
++nbDownloadedFiles;
totalDownloadedSize+=reply->bytesAvailable();
}
}
 End of changes. 46 change blocks. 
106 lines changed or deleted 513 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/