StelApp.cpp   StelApp.cpp 
skipping to change at line 27 skipping to change at line 27
* 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 "StelLoadingBar.hpp" #include "StelLoadingBar.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.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 "LabelMgr.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 "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelMovementMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelScriptMgr.hpp"
#include "StelMainScriptAPIProxy.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "StelSkyLayerMgr.hpp" #include "StelSkyLayerMgr.hpp"
#include "StelAudioMgr.hpp" #include "StelAudioMgr.hpp"
#include "StelStyle.hpp"
#include "StelMainGraphicsView.hpp"
#include "StelGuiBase.hpp" #include "StelGuiBase.hpp"
#include "StelPainter.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 <QTextStream> #include <QTextStream>
#include <QMouseEvent> #include <QMouseEvent>
#include <QDebug> #include <QDebug>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QSysInfo> #include <QSysInfo>
#include <QNetworkProxy> #include <QNetworkProxy>
#include <QMessageBox> #include <QMessageBox>
#include <QNetworkDiskCache> #include <QNetworkDiskCache>
#include <QNetworkReply> #include <QNetworkReply>
#include <cstdlib>
// Initialize static variables // Initialize static variables
StelApp* StelApp::singleton = NULL; StelApp* StelApp::singleton = NULL;
QTime* StelApp::qtime = NULL; QTime* StelApp::qtime = NULL;
void StelApp::initStatic() void StelApp::initStatic()
{ {
StelApp::qtime = new QTime(); StelApp::qtime = new QTime();
StelApp::qtime->start(); StelApp::qtime->start();
} }
void StelApp::deinitStatic()
{
delete StelApp::qtime;
StelApp::qtime = NULL;
}
/************************************************************************* /*************************************************************************
Create and initialize the main Stellarium application. Create and initialize the main Stellarium application.
*************************************************************************/ *************************************************************************/
StelApp::StelApp(QObject* parent) StelApp::StelApp(QObject* parent)
: QObject(parent), core(NULL), stelGui(NULL), fps(0), : QObject(parent), core(NULL), stelGui(NULL), fps(0),
frame(0), timefr(0.), timeBase(0.), flagNightVision(false), frame(0), timefr(0.), timeBase(0.), flagNightVision(false),
confSettings(NULL), initialized(false), saveProjW(-1), saveProjH(- 1), drawState(0) confSettings(NULL), initialized(false), saveProjW(-1), saveProjH(- 1), drawState(0)
{ {
// Stat variables // Stat variables
nbDownloadedFiles=0; nbDownloadedFiles=0;
skipping to change at line 105 skipping to change at line 103
nbUsedCache=0; nbUsedCache=0;
totalUsedCacheSize=0; totalUsedCacheSize=0;
setObjectName("StelApp"); setObjectName("StelApp");
skyCultureMgr=NULL; skyCultureMgr=NULL;
localeMgr=NULL; localeMgr=NULL;
stelObjectMgr=NULL; stelObjectMgr=NULL;
textureMgr=NULL; textureMgr=NULL;
moduleMgr=NULL; moduleMgr=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;
moduleMgr = new StelModuleMgr(); moduleMgr = new StelModuleMgr();
// Init a default StelStyle, before loading modules, it will be over
rided
currentStelStyle = NULL;
setColorScheme("color");
} }
/************************************************************************* /*************************************************************************
Deinitialize and destroy the main Stellarium application. Deinitialize and destroy the main Stellarium application.
*************************************************************************/ *************************************************************************/
StelApp::~StelApp() StelApp::~StelApp()
{ {
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));
stelObjectMgr->unSelect(); stelObjectMgr->unSelect();
moduleMgr->unloadModule("StelSkyLayerMgr", 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 skyImageMgr; skyImageMgr=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 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 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 currentStelStyle;
Q_ASSERT(singleton); Q_ASSERT(singleton);
singleton = NULL; singleton = NULL;
} }
void StelApp::setupHttpProxy()
{
QString proxyHost = confSettings->value("proxy/host_name").toString(
);
QString proxyPort = confSettings->value("proxy/port").toString();
QString proxyUser = confSettings->value("proxy/user").toString();
QString proxyPass = confSettings->value("proxy/password").toString()
;
// If proxy settings not found in config, use environment variable
// if it is defined. (Config file over-rides environment).
if (proxyHost.isEmpty() && proxyUser.isEmpty() && proxyPass.isEmpty(
) && proxyPort.isEmpty())
{
char *httpProxyEnv;
httpProxyEnv = std::getenv("http_proxy");
if (!httpProxyEnv)
{
httpProxyEnv = std::getenv("HTTP_PROXY");
}
if (httpProxyEnv)
{
QString proxyString = QString(httpProxyEnv);
if (!proxyString.isEmpty())
{
// Regular expressions with multiple optiona
l sub-expressions are so unreadable --MNG
QRegExp pre("^http://((([^:]+):([^@]+))@)?([
^:]+)(:(\\d+))?");
if (pre.exactMatch(proxyString))
{
proxyUser = pre.capturedTexts().at(3
);
proxyPass = pre.capturedTexts().at(4
);
proxyHost = pre.capturedTexts().at(5
);
proxyPort = pre.capturedTexts().at(7
);
}
else
{
qDebug() << "indecipherable environm
ent variable http_proxy:" << proxyString;
return;
}
}
}
}
if (!proxyHost.isEmpty())
{
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName(proxyHost);
if (!proxyPort.isEmpty())
proxy.setPort(proxyPort.toUShort());
if (!proxyUser.isEmpty())
proxy.setUser(proxyUser);
if (!proxyPass.isEmpty())
proxy.setPassword(proxyPass);
QString ppDisp = proxyPass;
ppDisp.replace(QRegExp("."), "x");
qDebug() << "Using HTTP proxy:" << proxyUser << ppDisp << pr
oxyHost << proxyPort;
QNetworkProxy::setApplicationProxy(proxy);
}
}
void StelApp::init(QSettings* conf) void StelApp::init(QSettings* conf)
{ {
confSettings = conf; confSettings = conf;
core = new StelCore(); core = new StelCore();
if (saveProjW!=-1 && saveProjH!=-1) if (saveProjW!=-1 && saveProjH!=-1)
core->windowHasBeenResized(0, 0, saveProjW, saveProjH); core->windowHasBeenResized(0, 0, saveProjW, saveProjH);
#ifndef USE_OPENGL_ES2
// Avoid using GL Shaders by default since it causes so many problem s with broken drivers. // Avoid using GL Shaders by default since it causes so many problem s with broken drivers.
useGLShaders = confSettings->value("main/use_glshaders", false).toBo ol(); useGLShaders = confSettings->value("main/use_glshaders", false).toBo ol();
useGLShaders = useGLShaders && QGLShaderProgram::hasOpenGLShaderProg useGLShaders = useGLShaders && QGLShaderProgram::hasOpenGLShaderProg
rams(); rams() && !qApp->property("onetime_safe_mode").isValid();
useGLShaders = useGLShaders && (QGLFormat::openGLVersionFlags().test
Flag(QGLFormat::OpenGL_Version_2_0) || QGLFormat::openGLVersionFlags().test
Flag(QGLFormat::OpenGL_ES_Version_2_0));
StelPainter::initSystemGLInfo(); // We use OpenGL 2.1 features in our shaders
useGLShaders = useGLShaders && (QGLFormat::openGLVersionFlags().test
Flag(QGLFormat::OpenGL_Version_2_1) || QGLFormat::openGLVersionFlags().test
Flag(QGLFormat::OpenGL_ES_Version_2_0));
#else
useGLShaders = true;
#endif
// Initialize AFTER creation of openGL context // Initialize AFTER creation of openGL context
textureMgr = new StelTextureMgr(); textureMgr = new StelTextureMgr();
textureMgr->init(); textureMgr->init();
#ifdef SVN_REVISION #ifdef BUILD_FOR_MAEMO
loadingBar = new StelLoadingBar(12., "logo24bits.png", QString("SVN StelLoadingBar loadingBar("textures/logo24bits.png", "", 25, 320, 10
r%1").arg(SVN_REVISION), 25, 320, 101); 1, 800, 400);
#else #else
loadingBar = new StelLoadingBar(12., "logo24bits.png", PACKAGE_VERSI #ifdef SVN_REVISION
ON, 45, 320, 121); StelLoadingBar loadingBar("textures/logo24bits.png", QString("SVN r%
#endif // SVN_RELEASE 1").arg(SVN_REVISION), 25, 320, 101);
loadingBar->SetMessage("Initialize"); #else
loadingBar->Draw(0); StelLoadingBar loadingBar("textures/logo24bits.png", PACKAGE_VERSION
, 45, 320, 121);
#endif
#endif
loadingBar.draw();
networkAccessManager = new QNetworkAccessManager(this); networkAccessManager = new QNetworkAccessManager(this);
// 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 = StelFileMgr::getCacheDir(); QString cachePath = StelFileMgr::getCacheDir();
qDebug() << "Cache directory is: " << cachePath; qDebug() << "Cache directory is: " << cachePath;
cache->setCacheDirectory(cachePath); cache->setCacheDirectory(cachePath);
networkAccessManager->setCache(cache); networkAccessManager->setCache(cache);
connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), this , SLOT(reportFileDownloadFinished(QNetworkReply*))); connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), this , SLOT(reportFileDownloadFinished(QNetworkReply*)));
skipping to change at line 193 skipping to change at line 254
// 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 = new StelLocaleMgr(); localeMgr = new StelLocaleMgr();
skyCultureMgr = new StelSkyCultureMgr(); skyCultureMgr = new StelSkyCultureMgr();
planetLocationMgr = new StelLocationMgr(); planetLocationMgr = new StelLocationMgr();
localeMgr->init(); localeMgr->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();
hip_stars->init(); hip_stars->init();
getModuleMgr().registerModule(hip_stars); getModuleMgr().registerModule(hip_stars);
skipping to change at line 225 skipping to change at line 285
getModuleMgr().registerModule(milky_way); getModuleMgr().registerModule(milky_way);
// Init sky image manager // Init sky image manager
skyImageMgr = new StelSkyLayerMgr(); 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
TelescopeMgr* telescope_mgr = new TelescopeMgr();
telescope_mgr->init();
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);
// Landscape, atmosphere & cardinal points section // Landscape, atmosphere & cardinal points section
LandscapeMgr* landscape = new LandscapeMgr(); LandscapeMgr* landscape = new LandscapeMgr();
landscape->init(); landscape->init();
getModuleMgr().registerModule(landscape); getModuleMgr().registerModule(landscape);
skipping to change at line 254 skipping to change at line 309
// 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 // User labels
LabelMgr* skyLabels = new LabelMgr(); LabelMgr* skyLabels = new LabelMgr();
skyLabels->init(); skyLabels->init();
getModuleMgr().registerModule(skyLabels); getModuleMgr().registerModule(skyLabels);
// Scripting images
ScreenImageMgr* scriptImages = new ScreenImageMgr();
scriptImages->init();
getModuleMgr().registerModule(scriptImages);
// ugly fix by Johannes: call skyCultureMgr->init twice so that
// star names are loaded again
skyCultureMgr->init(); skyCultureMgr->init();
// Initialisation of the color scheme // Initialisation of the color scheme
flagNightVision=true; // fool caching bool tmp = confSettings->value("viewing/flag_night").toBool();
setVisionModeNight(false); flagNightVision=!tmp; // fool caching
setVisionModeNight(confSettings->value("viewing/flag_night").toBool( setVisionModeNight(tmp);
));
// Proxy Initialisation // Proxy Initialisation
QString proxyName = confSettings->value("proxy/host_name").toString( setupHttpProxy();
);
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();
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)
skipping to change at line 440 skipping to change at line 470
{ {
i->handleKeys(event); i->handleKeys(event);
if (event->isAccepted()) if (event->isAccepted())
return; return;
} }
} }
// 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 (getGui())
currentStelStyle = new StelStyle; getGui()->setStelStyle(section);
currentStelStyle->confSectionName = section;
QString qtStyleFileName;
QString htmlStyleFileName;
if (section=="night_color")
{
qtStyleFileName = "data/gui/nightStyle.css";
htmlStyleFileName = "data/gui/nightHtml.css";
}
else if (section=="color")
{
qtStyleFileName = "data/gui/normalStyle.css";
htmlStyleFileName = "data/gui/normalHtml.css";
}
// Load Qt style sheet
QString styleFilePath;
try
{
styleFilePath = StelFileMgr::findFile(qtStyleFileName);
}
catch (std::runtime_error& e)
{
qWarning() << "WARNING: can't find Qt style sheet:" << qtSty
leFileName;
}
QFile styleFile(styleFilePath);
styleFile.open(QIODevice::ReadOnly);
currentStelStyle->qtStyleSheet = styleFile.readAll();
// Load HTML style sheet
try
{
styleFilePath = StelFileMgr::findFile(htmlStyleFileName);
}
catch (std::runtime_error& e)
{
qWarning() << "WARNING: can't find css:" << htmlStyleFileNam
e;
}
QFile htmlStyleFile(styleFilePath);
htmlStyleFile.open(QIODevice::ReadOnly);
currentStelStyle->htmlStyleSheet = htmlStyleFile.readAll();
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* iter, moduleMgr->getAllModules()) foreach (StelModule* iter, moduleMgr->getAllModules())
{ {
iter->setStelStyle(*currentStelStyle); iter->setStelStyle(section);
} }
} }
//! Set flag for activating night vision mode //! Set flag for activating night vision mode
void StelApp::setVisionModeNight(bool b) void StelApp::setVisionModeNight(bool b)
{ {
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()
{ {
#ifdef ENABLE_NLS
// 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()) if (getGui())
getGui()->updateI18n(); getGui()->updateI18n();
#endif
} }
// 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);
skipping to change at line 546 skipping to change at line 534
{ {
++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. 29 change blocks. 
117 lines changed or deleted 111 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/