Fix forward navigation control on Linux.
[dorian] / main.cpp
1 #include <QtGui/QApplication>
2
3 #include "mainwindow.h"
4 #include "trace.h"
5 #include "settings.h"
6 #include "library.h"
7 #include "settings.h"
8 #include "bookdb.h"
9 #include "search.h"
10 #include "platform.h"
11 #include "splash.h"
12
13 #ifdef Q_OS_SYMBIAN
14 #   include "mediakeysobserver.h"
15 #endif
16
17 static const char *DORIAN_VERSION =
18 #include "pkg/version.txt"
19 ;
20
21 static const QtMsgType DORIAN_DEFAULT_TRACE_LEVEL =
22 #ifdef Q_OS_SYMBIAN
23         QtDebugMsg
24 #else
25         QtWarningMsg
26 #endif
27         ;
28
29 int main(int argc, char *argv[])
30 {
31     int ret;
32
33     // Set up application
34     QApplication app(argc, argv);
35     app.setApplicationName("Dorian");
36     app.setApplicationVersion(DORIAN_VERSION);
37     app.setOrganizationDomain("pipacs.com");
38     app.setOrganizationName("Pipacs");
39
40     // Initialize tracing
41     Settings *settings = Settings::instance();
42     Trace::level = (QtMsgType)settings->
43         value("tracelevel", (int)DORIAN_DEFAULT_TRACE_LEVEL).toInt();
44     Trace::setFileName(settings->value("tracefilename").toString());
45     qInstallMsgHandler(Trace::messageHandler);
46
47     // Show splash screen
48     Splash splash;
49     splash.show();
50     app.processEvents();
51
52     // Initialize main window
53     MainWindow *mainWindow = new MainWindow();
54     mainWindow->initialize();
55
56     // Hide splash screen
57     splash.finish(mainWindow);
58
59     // Apply settings (orientation, style etc.)
60     settings->apply();
61
62     // Run event loop, re-start application if event loop exit code was 1000
63     ret = app.exec();
64     if (ret == 1000) {
65         Platform::instance()->restart(argv);
66     }
67
68     // Release singletons
69     delete mainWindow;
70     Library::close();
71     BookDb::close();
72     Settings::close();
73     Search::close();
74     Platform::close();
75 #ifdef Q_OS_SYMBIAN
76     MediaKeysObserver::close();
77 #endif
78
79     return ret;
80 }