main.cpp   main.cpp 
skipping to change at line 20 skipping to change at line 20
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* 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 <QtGui/QApplication> #include <config.h>
#include <QtGui/QMessageBox>
#include <QTranslator>
#include "StelMainGraphicsView.hpp"
#include "StelMainWindow.hpp" #include "StelMainWindow.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelLogger.hpp"
#include "StelFileMgr.hpp"
#include "CLIProcessor.hpp"
#include "StelIniParser.hpp"
#include <QDebug> #include <QDebug>
#include <QApplication>
#include <QMessageBox>
#include <QTranslator>
#include <QGLFormat> #include <QGLFormat>
#include <QPlastiqueStyle> #include <QPlastiqueStyle>
#ifdef MACOSX #include <QFileInfo>
#include "StelMacosxDirs.hpp" #include <QtPlugin>
Q_IMPORT_PLUGIN(StelGui)
#ifdef USE_STATIC_PLUGIN_VIRGO
Q_IMPORT_PLUGIN(VirGO)
#endif
#ifdef USE_STATIC_PLUGIN_SVMT
Q_IMPORT_PLUGIN(SVMT)
#endif
#ifdef USE_STATIC_PLUGIN_HELLOSTELMODULE
Q_IMPORT_PLUGIN(HelloStelModule)
#endif
#ifdef USE_STATIC_PLUGIN_ANGLEMEASURE
Q_IMPORT_PLUGIN(AngleMeasure)
#endif
#ifdef USE_STATIC_PLUGIN_COMPASSMARKS
Q_IMPORT_PLUGIN(CompassMarks)
#endif
#ifdef USE_STATIC_PLUGIN_SATELLITES
Q_IMPORT_PLUGIN(Satellites)
#endif
#ifdef USE_STATIC_PLUGIN_TEXTUSERINTERFACE
Q_IMPORT_PLUGIN(TextUserInterface)
#endif
#ifdef USE_STATIC_PLUGIN_LOGBOOK
Q_IMPORT_PLUGIN(LogBook)
#endif
#ifdef USE_STATIC_PLUGIN_OCULARS
Q_IMPORT_PLUGIN(Oculars)
#endif
#ifdef USE_STATIC_PLUGIN_TELESCOPECONTROL
Q_IMPORT_PLUGIN(TelescopeControl)
#endif #endif
//! @class GettextStelTranslator //! @class GettextStelTranslator
//! Provides i18n support through gettext. //! Provides i18n support through gettext.
class GettextStelTranslator : public QTranslator class GettextStelTranslator : public QTranslator
{ {
public: public:
virtual bool isEmpty() const { return false; } virtual bool isEmpty() const { return false; }
virtual QString translate(const char* context, const char* sourceTex t, const char* comment=0) const virtual QString translate(const char* context, const char* sourceTex t, const char* comment=0) const
{ {
return q_(sourceText); return q_(sourceText);
} }
}; };
//! Copies the default configuration file.
//! This function copies the default_config.ini file to config.ini (or othe
r
//! name specified on the command line located in the user data directory.
void copyDefaultConfigFile(const QString& newPath)
{
QString defaultConfigFilePath;
try
{
defaultConfigFilePath = StelFileMgr::findFile("data/default_
config.ini");
}
catch (std::runtime_error& e)
{
qFatal("ERROR copyDefaultConfigFile failed to locate data/de
fault_config.ini. Please check your installation.");
}
QFile::copy(defaultConfigFilePath, newPath);
if (!StelFileMgr::exists(newPath))
{
qFatal("ERROR copyDefaultConfigFile failed to copy file %s
to %s. You could try to copy it by hand.",
qPrintable(defaultConfigFilePath), qPrintable(newPat
h));
}
}
// Main stellarium procedure // Main stellarium procedure
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
QCoreApplication::setApplicationName("stellarium"); QCoreApplication::setApplicationName("stellarium");
QCoreApplication::setApplicationVersion(StelApp::getApplicationVersi on()); QCoreApplication::setApplicationVersion(StelUtils::getApplicationVer sion());
QCoreApplication::setOrganizationDomain("stellarium.org"); QCoreApplication::setOrganizationDomain("stellarium.org");
QCoreApplication::setOrganizationName("stellarium"); QCoreApplication::setOrganizationName("stellarium");
//QApplication::setDesktopSettingsAware(false); #ifndef USE_OPENGL_ES2
QApplication::setStyle(new QPlastiqueStyle()); QApplication::setStyle(new QPlastiqueStyle());
#endif
// 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");
// Handle command line options for alternative Qt graphics system ty
pes.
// DEFAULT_GRAPHICS_SYSTEM is defined per platform in the main CMake
Lists.txt file.
// Avoid overriding if the user already specified the mode on the CL
I.
bool doSetDefaultGraphicsSystem=true;
for (int i = 1; i < argc; ++i)
{
//QApplication accepts -graphicssystem only if
//its value is a separate argument (the next value in argv)
if (QString(argv[i]) == "-graphicssystem")
{
doSetDefaultGraphicsSystem = false;
}
}
// If the user didn't set the graphics-system on the command line, u
se the one provided at compile time.
if (doSetDefaultGraphicsSystem)
{
qDebug() << "Using default graphics system specified at buil
d time: " << DEFAULT_GRAPHICS_SYSTEM;
QApplication::setGraphicsSystem(DEFAULT_GRAPHICS_SYSTEM);
}
// With Qt 4.5, force the usage of the raster backend // The QApplication MUST be created before the StelFileMgr is initia
char** argv2 = (char**)malloc(sizeof(char*)*(argc+2)); lized.
memcpy(argv2, argv, argc*sizeof(char*)); QApplication app(argc, argv);
char cmd1[] = "-graphicssystem";
char cmd2[] = "raster";
argv2[argc]=cmd1;
argv2[argc+1]=cmd2;
int argc2 = argc+2;
QApplication app(argc2, argv2);
#ifdef MACOSX // Init the file manager
StelMacosxDirs::addApplicationPluginDirectory(); StelFileMgr::init();
// Start logging.
StelLogger::init(StelFileMgr::getUserDir()+"/log.txt");
// Log command line arguments
QString argStr;
QStringList argList;
for (int i=0; i<argc; ++i)
{
argList << argv[i];
argStr += QString("%1 ").arg(argv[i]);
}
StelLogger::writeLog(argStr);
// Parse for first set of CLI arguments - stuff we want to process b
efore other
// output, such as --help and --version
CLIProcessor::parseCLIArgsPreConfig(argList);
// OK we start the full program.
// Print the console splash and get on with loading the program
QString versionLine = QString("This is %1 - http://www.stellarium.or
g").arg(StelUtils::getApplicationName());
QString copyrightLine = QString("Copyright (C) 2000-2010 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)));
qDebug() << "Writing log file to:" << StelLogger::getLogFileName();
qDebug() << "File search paths:";
int n=0;
foreach (QString i, StelFileMgr::getSearchPaths())
{
qDebug() << " " << n << ". " << i;
++n;
}
// Now manage the loading of the proper config file
QString configName;
try
{
configName = CLIProcessor::argsGetOptionWithArg(argList, "-c
", "--config-file", "config.ini").toString();
}
catch (std::runtime_error& e)
{
qWarning() << "WARNING: while looking for --config-file opti
on: " << e.what() << ". Using \"config.ini\"";
configName = "config.ini";
}
QString configFileFullPath;
try
{
configFileFullPath = StelFileMgr::findFile(configName, StelF
ileMgr::Flags(StelFileMgr::Writable|StelFileMgr::File));
}
catch (std::runtime_error& e)
{
try
{
configFileFullPath = StelFileMgr::findFile(configNam
e, StelFileMgr::New);
}
catch (std::runtime_error& e)
{
qFatal("Could not create configuration file %s.", qP
rintable(configName));
}
}
QSettings* confSettings = NULL;
if (StelFileMgr::exists(configFileFullPath))
{
// Implement "restore default settings" feature.
bool restoreDefaultConfigFile = false;
if (CLIProcessor::argsGetOption(argList, "", "--restore-defa
ults"))
{
restoreDefaultConfigFile=true;
}
else
{
confSettings = new QSettings(configFileFullPath, Ste
lIniFormat, NULL);
restoreDefaultConfigFile = confSettings->value("main
/restore_defaults", false).toBool();
}
if (!restoreDefaultConfigFile)
{
QString version = confSettings->value("main/version"
, "0.0.0").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 s
upported, otherwise 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 version too old for parameters to be imported ("
<< (version.isEmpty
() ? "<0.6.0" : version) << ").\n"
<< "It will be repl
aced by the default config file.";
restoreDefaultConfigFile = true;
}
else
{
qDebug() << "Attempting to use an ex
isting older config file.";
}
}
}
if (restoreDefaultConfigFile)
{
if (confSettings)
delete confSettings;
QString backupFile(configFileFullPath.left(configFil
eFullPath.length()-3) + QString("old"));
if (QFileInfo(backupFile).exists())
QFile(backupFile).remove();
QFile(configFileFullPath).rename(backupFile);
copyDefaultConfigFile(configFileFullPath);
confSettings = new QSettings(configFileFullPath, Ste
lIniFormat);
qWarning() << "Resetting defaults config file. Previ
ous config file was backed up in " << backupFile;
}
}
else
{
qDebug() << "Config file " << configFileFullPath << " does n
ot exist. Copying the default file.";
copyDefaultConfigFile(configFileFullPath);
confSettings = new QSettings(configFileFullPath, StelIniForm
at);
}
Q_ASSERT(confSettings);
qDebug() << "Config file is: " << configFileFullPath;
// Override config file values from CLI.
CLIProcessor::parseCLIArgsPostConfig(argList, confSettings);
if (confSettings->value("main/use_qpaintenginegl2", true).toBool())
{
// The default is to let Qt choose which paint engine fits t
he best between OpenGL and OpenGL2.
// However it causes troubles on some older hardware, so add
an option.
}
else
{
// The user explicitely request to use the older paint engin
e.
QGL::setPreferredPaintEngine(QPaintEngine::OpenGL);
}
#ifdef Q_OS_MAC
// On Leopard (10.5) + ppc architecture, text display is buggy if Op
enGL2 Qt paint engine is used.
if ((QSysInfo::MacintoshVersion == QSysInfo::MV_LEOPARD) && (QSysInf
o::ByteOrder == QSysInfo::BigEndian))
QGL::setPreferredPaintEngine(QPaintEngine::OpenGL);
#endif #endif
// Initialize translator feature
try
{
StelTranslator::init(StelFileMgr::findFile("data/iso639-1.ut
f8"));
}
catch (std::runtime_error& e)
{
qWarning() << "ERROR while loading translations: " << e.what
() << endl;
}
// Use our gettext translator for Qt translations as well
GettextStelTranslator trans; GettextStelTranslator trans;
app.installTranslator(&trans); app.installTranslator(&trans);
if (!QGLFormat::hasOpenGL()) if (!QGLFormat::hasOpenGL())
{ {
QMessageBox::warning(0, "Stellarium", q_("This system does n ot support OpenGL.")); QMessageBox::warning(0, "Stellarium", q_("This system does n ot support OpenGL."));
} }
StelMainWindow* mainWin = new StelMainWindow(NULL); StelMainWindow mainWin;
StelMainGraphicsView* view = new StelMainGraphicsView(NULL, argc, ar mainWin.init(confSettings);
gv);
mainWin->setCentralWidget(view);
mainWin->init();
app.exec(); app.exec();
view->deinitGL(); mainWin.deinit();
delete view;
delete mainWin; delete confSettings;
free(argv2); StelLogger::deinit();
return 0; return 0;
} }
 End of changes. 14 change blocks. 
28 lines changed or deleted 316 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/