~ubuntu-branches/ubuntu/trusty/stellarium/trusty

« back to all changes in this revision

Viewing changes to src/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2010-07-31 15:44:02 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100731154402-511dojtyt5ycuizd
Tags: 0.10.5-1
* New upstream release (Closes: #586804)
* Remove 01_fix_pow10_function_check.diff, now applied upstream
* Remove 02_remove_unknown_locale_code.diff, no more needed
* Rendering of `old_style' landscapes fixed by upstream (Closes: #581657)
* Update debian/control:
  - Bump Standards-Version from 3.8.4 to 3.9.0
  - Add libqt4-sql-sqlite to Depends (Closes: #582726)
* Update debian/copyright:
  - Fix FSF address

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
18
 */
19
19
 
20
 
#include <config.h>
21
20
#include "StelMainWindow.hpp"
22
21
#include "StelTranslator.hpp"
23
22
#include "StelLogger.hpp"
32
31
#include <QGLFormat>
33
32
#include <QPlastiqueStyle>
34
33
#include <QFileInfo>
35
 
#include <QtPlugin>
36
 
 
37
 
Q_IMPORT_PLUGIN(StelGui)
38
 
 
39
 
#ifdef USE_STATIC_PLUGIN_VIRGO
40
 
Q_IMPORT_PLUGIN(VirGO)
41
 
#endif
42
 
 
43
 
#ifdef USE_STATIC_PLUGIN_SVMT
44
 
Q_IMPORT_PLUGIN(SVMT)
45
 
#endif
46
 
 
47
 
#ifdef USE_STATIC_PLUGIN_HELLOSTELMODULE
48
 
Q_IMPORT_PLUGIN(HelloStelModule)
49
 
#endif
50
 
 
51
 
#ifdef USE_STATIC_PLUGIN_ANGLEMEASURE
52
 
Q_IMPORT_PLUGIN(AngleMeasure)
53
 
#endif
54
 
 
55
 
#ifdef USE_STATIC_PLUGIN_COMPASSMARKS
56
 
Q_IMPORT_PLUGIN(CompassMarks)
57
 
#endif
58
 
 
59
 
#ifdef USE_STATIC_PLUGIN_SATELLITES
60
 
Q_IMPORT_PLUGIN(Satellites)
61
 
#endif
62
 
 
63
 
#ifdef USE_STATIC_PLUGIN_TEXTUSERINTERFACE
64
 
Q_IMPORT_PLUGIN(TextUserInterface)
65
 
#endif
66
 
 
67
 
#ifdef USE_STATIC_PLUGIN_LOGBOOK
68
 
Q_IMPORT_PLUGIN(LogBook)
69
 
#endif
70
 
 
71
 
#ifdef USE_STATIC_PLUGIN_OCULARS
72
 
Q_IMPORT_PLUGIN(Oculars)
73
 
#endif
74
 
 
75
 
#ifdef USE_STATIC_PLUGIN_TELESCOPECONTROL
76
 
Q_IMPORT_PLUGIN(TelescopeControl)
77
 
#endif
 
34
#include <QFontDatabase>
 
35
#ifdef Q_OS_WIN
 
36
#include <windows.h>
 
37
#endif //Q_OS_WIN
78
38
 
79
39
//! @class GettextStelTranslator
80
40
//! Provides i18n support through gettext.
85
45
 
86
46
        virtual QString translate(const char* context, const char* sourceText, const char* comment=0) const
87
47
        {
 
48
                Q_UNUSED(context);
 
49
                Q_UNUSED(comment);
88
50
                return q_(sourceText);
89
51
        }
90
52
};
116
78
// Main stellarium procedure
117
79
int main(int argc, char **argv)
118
80
{
 
81
#ifdef Q_OS_WIN
 
82
        // Fix for the speeding system clock bug on systems that use ACPI
 
83
        // See http://support.microsoft.com/kb/821893
 
84
        UINT timerGrain = 1;
 
85
        if (timeBeginPeriod(timerGrain) == TIMERR_NOCANDO)
 
86
        {
 
87
                // If this is too fine a grain, try the lowest value used by a timer
 
88
                timerGrain = 5;
 
89
                if (timeBeginPeriod(timerGrain) == TIMERR_NOCANDO)
 
90
                        timerGrain = 0;
 
91
        }
 
92
#endif
 
93
 
119
94
        QCoreApplication::setApplicationName("stellarium");
120
95
        QCoreApplication::setApplicationVersion(StelUtils::getApplicationVersion());
121
96
        QCoreApplication::setOrganizationDomain("stellarium.org");
122
97
        QCoreApplication::setOrganizationName("stellarium");
123
98
 
124
 
#ifndef USE_OPENGL_ES2
 
99
#ifndef BUILD_FOR_MAEMO
125
100
        QApplication::setStyle(new QPlastiqueStyle());
126
101
#endif
127
102
 
128
 
        // Used for getting system date formatting
129
 
        setlocale(LC_TIME, "");
130
 
        // We need scanf()/printf() and friends to always work in the C locale,
131
 
        // otherwise configuration/INI file parsing will be erroneous.
132
 
        setlocale(LC_NUMERIC, "C");
133
 
 
134
103
        // Handle command line options for alternative Qt graphics system types.
135
104
        // DEFAULT_GRAPHICS_SYSTEM is defined per platform in the main CMakeLists.txt file.
136
105
        // Avoid overriding if the user already specified the mode on the CLI.
154
123
        // The QApplication MUST be created before the StelFileMgr is initialized.
155
124
        QApplication app(argc, argv);
156
125
 
 
126
        // QApplication sets current locale, but
 
127
        // we need scanf()/printf() and friends to always work in the C locale,
 
128
        // otherwise configuration/INI file parsing will be erroneous.
 
129
        setlocale(LC_NUMERIC, "C");
 
130
 
157
131
        // Init the file manager
158
132
        StelFileMgr::init();
159
133
 
160
 
        // Start logging.
161
 
        StelLogger::init(StelFileMgr::getUserDir()+"/log.txt");
162
 
 
163
134
        // Log command line arguments
164
135
        QString argStr;
165
136
        QStringList argList;
168
139
                argList << argv[i];
169
140
                argStr += QString("%1 ").arg(argv[i]);
170
141
        }
171
 
        StelLogger::writeLog(argStr);
172
 
 
173
142
        // Parse for first set of CLI arguments - stuff we want to process before other
174
143
        // output, such as --help and --version
175
144
        CLIProcessor::parseCLIArgsPreConfig(argList);
176
145
 
 
146
        // Start logging.
 
147
        StelLogger::init(StelFileMgr::getUserDir()+"/log.txt");
 
148
        StelLogger::writeLog(argStr);
 
149
 
177
150
        // OK we start the full program.
178
151
        // Print the console splash and get on with loading the program
179
152
        QString versionLine = QString("This is %1 - http://www.stellarium.org").arg(StelUtils::getApplicationName());
286
259
        // Override config file values from CLI.
287
260
        CLIProcessor::parseCLIArgsPostConfig(argList, confSettings);
288
261
 
289
 
        if (confSettings->value("main/use_qpaintenginegl2", true).toBool())
 
262
        bool safeMode = false;
 
263
        if (confSettings->value("main/use_qpaintenginegl2", true).toBool() && !qApp->property("onetime_safe_mode").isValid())
290
264
        {
291
265
                // The default is to let Qt choose which paint engine fits the best between OpenGL and OpenGL2.
292
266
                // However it causes troubles on some older hardware, so add an option.
295
269
        {
296
270
                // The user explicitely request to use the older paint engine.
297
271
                QGL::setPreferredPaintEngine(QPaintEngine::OpenGL);
 
272
                safeMode = true;
298
273
        }
299
274
 
300
275
#ifdef Q_OS_MAC
303
278
                QGL::setPreferredPaintEngine(QPaintEngine::OpenGL);
304
279
#endif
305
280
 
 
281
// On maemo we'll use the standard OS font
 
282
#ifndef BUILD_FOR_MAEMO
 
283
        // Add the DejaVu font that we use everywhere in the program
 
284
        try
 
285
        {
 
286
                const QString& fName = StelFileMgr::findFile("data/DejaVuSans.ttf");
 
287
                if (!fName.isEmpty())
 
288
                        QFontDatabase::addApplicationFont(fName);
 
289
        }
 
290
        catch (std::runtime_error& e)
 
291
        {
 
292
                // Removed this warning practically allowing to package the program without the font file.
 
293
                // This is useful for distribution having already a package for DejaVu font.
 
294
                // qWarning() << "ERROR while loading font DejaVuSans : " << e.what();
 
295
        }
 
296
 
 
297
        // Set the default application font and font size.
 
298
        // Note that style sheet will possibly override this setting.
 
299
#ifdef Q_OS_WIN
 
300
        // On windows use Verdana font, to avoid unresolved bug with OpenGL1 Qt paint engine.
 
301
        // See Launchpad question #111823 for more info
 
302
        QFont tmpFont(safeMode ? "Verdana" : "DejaVu Sans");
 
303
        
 
304
        // Activate verdana by defaut for all win32 builds to see if it improves things.
 
305
        // -> this seems to bring crippled arabic fonts with OpenGL2 paint engine..
 
306
        // QFont tmpFont("Verdana");
 
307
#else
 
308
#ifdef Q_OS_MAC
 
309
        QFont tmpFont("Verdana");
 
310
#else
 
311
        QFont tmpFont("DejaVu Sans");
 
312
#endif
 
313
#endif
 
314
        tmpFont.setPixelSize(13);
 
315
        QApplication::setFont(tmpFont);
 
316
#endif
 
317
 
306
318
        // Initialize translator feature
307
319
        try
308
320
        {
328
340
 
329
341
        delete confSettings;
330
342
        StelLogger::deinit();
 
343
 
 
344
        #ifdef Q_OS_WIN
 
345
        if(timerGrain)
 
346
                timeEndPeriod(timerGrain);
 
347
        #endif //Q_OS_WIN
 
348
 
331
349
        return 0;
332
350
}
333
351