13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <coemain.h> |
|
19 #include <eikenv.h> |
|
20 #include <QApplication> |
18 #include <QApplication> |
21 #include <QGraphicsProxyWidget> |
19 #include <QGraphicsProxyWidget> |
22 // needed for localization |
20 // needed for localization |
23 #include <QTranslator> |
|
24 #include <QLocale> |
21 #include <QLocale> |
|
22 #include <HbTranslator> |
25 #include <hbmainwindow.h> |
23 #include <hbmainwindow.h> |
26 #include <xqserviceutil.h> |
24 |
|
25 #ifdef Q_OS_SYMBIAN |
|
26 #include <coemain.h> |
|
27 #include <eikenv.h> |
|
28 #endif // Q_OS_SYMBIAN |
27 |
29 |
28 #include "cxeengine.h" |
30 #include "cxeengine.h" |
29 #include "cxecameradevicecontrol.h" |
31 #include "cxecameradevicecontrol.h" |
30 #include "cxuiapplication.h" |
32 #include "cxuiapplication.h" |
31 #include "cxuiviewmanager.h" |
33 #include "cxuiviewmanager.h" |
|
34 #include "cxuiapplicationstate.h" |
|
35 #include "cxuienums.h" |
32 #include "cxutils.h" |
36 #include "cxutils.h" |
33 #include "cxuiserviceprovider.h" |
37 #include "cxuiserviceprovider.h" |
34 |
38 |
|
39 #ifdef Q_OS_SYMBIAN |
35 #include "OstTraceDefinitions.h" |
40 #include "OstTraceDefinitions.h" |
36 #ifdef OST_TRACE_COMPILER_IN_USE |
41 #ifdef OST_TRACE_COMPILER_IN_USE |
37 #include "mainTraces.h" |
42 #include "mainTraces.h" |
38 #endif |
43 #endif // OST_TRACE_COMPILER_IN_USE |
|
44 #endif // Q_OS_SYMBIAN |
39 |
45 |
40 using namespace Cxe; |
46 using namespace Cxe; |
41 |
47 |
42 // CONSTANTS |
48 // CONSTANTS |
43 const QString TRANSLATIONS_PATH = "z:/resource/qt/translations/"; |
49 const QString TRANSLATIONS_PATH = "/resource/qt/translations/"; |
44 const QString TRANSLATIONS_FILE_NAME = "camera_"; |
50 const QString TRANSLATIONS_FILE = "camera"; |
45 const QString COMMON_TRANSLATIONS_FILE_NAME = "common_"; |
|
46 |
51 |
47 int main(int argc, char *argv[]) |
52 int main(int argc, char *argv[]) |
48 { |
53 { |
49 CX_DEBUG(("CxUI: entering main()")); |
54 CX_DEBUG(("CxUI: entering main()")); |
50 OstTrace0( camerax_performance, _MAIN, "msg: e_CX_STARTUP 1" ); |
55 OstTrace0( camerax_performance, _MAIN, "msg: e_CX_STARTUP 1" ); |
51 |
56 |
52 Q_INIT_RESOURCE(cxui); |
57 Q_INIT_RESOURCE(cxui); |
|
58 |
|
59 // Use software rendering / raster graphics system to save GPU memory. |
|
60 CX_DEBUG(("CxUI: Take raster graphics system into use..")); |
|
61 QApplication::setGraphicsSystem("raster"); |
|
62 CX_DEBUG(("CxUI: ..raster graphics system in use")); |
53 |
63 |
54 OstTrace0( camerax_performance, DUP1__MAIN, "msg: e_CX_HBAPP_CREATION 1" ); |
64 OstTrace0( camerax_performance, DUP1__MAIN, "msg: e_CX_HBAPP_CREATION 1" ); |
55 CxuiApplication app(argc, argv); |
65 CxuiApplication app(argc, argv); |
56 OstTrace0( camerax_performance, DUP2__MAIN, "msg: e_CX_HBAPP_CREATION 0" ); |
66 OstTrace0( camerax_performance, DUP2__MAIN, "msg: e_CX_HBAPP_CREATION 0" ); |
57 |
67 |
58 // Creating and initializing engine as early as possible. |
68 // Creating and initializing engine as early as possible. |
59 // Reserve and power on can then proceed in parallel with |
69 // Reserve and power on can then proceed in parallel with |
60 // ui construction. |
70 // ui construction. |
61 OstTrace0( camerax_performance, DUP7__MAIN, "msg: e_CX_CREATE_ENGINE 1" ); |
71 OstTrace0( camerax_performance, DUP7__MAIN, "msg: e_CX_CREATE_ENGINE 1" ); |
62 CxeEngine *eng = CxeEngine::createEngine(); |
72 CxeEngine *engine = CxeEngine::createEngine(); |
63 OstTrace0( camerax_performance, DUP8__MAIN, "msg: e_CX_CREATE_ENGINE 0" ); |
73 OstTrace0( camerax_performance, DUP8__MAIN, "msg: e_CX_CREATE_ENGINE 0" ); |
64 |
74 |
65 if (XQServiceUtil::isService()) { |
75 if (app.activateReason() == Hb::ActivationReasonService) { |
|
76 CX_DEBUG(("CxUI: Camera started as service")); |
66 // Embedded mode. Engine is inited to correct mode |
77 // Embedded mode. Engine is inited to correct mode |
67 // by service provider when request arrives |
78 // by service provider when request arrives |
68 CX_DEBUG(("CxUI: creating serviceprovider")); |
79 CX_DEBUG(("CxUI: creating serviceprovider")); |
69 CxuiServiceProvider::create(eng); |
80 CxuiServiceProvider::create(engine); |
70 CX_DEBUG(("CxUI: done")); |
81 CX_DEBUG(("CxUI: done")); |
71 } else { |
82 } else if (app.activateReason() == Hb::ActivationReasonActivity) { |
72 // Normal mode. Init engine now. |
83 CX_DEBUG(("CxUI: Camera started as activity")); |
73 OstTrace0( camerax_performance, DUP9__MAIN, "msg: e_CX_INIT_ENGINE 1" ); |
84 Cxe::CameraMode mode = Cxe::ImageMode; |
74 //! @todo temporarily commented as part of a hack to change the startup sequence |
85 QString activityId = app.activateId(); |
75 // to avoid GOOM issues |
86 if (activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY || |
76 //eng->initMode(Cxe::ImageMode); |
87 activityId == CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY) { |
77 OstTrace0( camerax_performance, DUP10__MAIN, "msg: e_CX_INIT_ENGINE 0" ); |
88 mode = Cxe::VideoMode; |
78 } |
89 } |
79 |
90 |
80 // Load the language specific localization files: application + common |
91 if (activityId == CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY || |
|
92 activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY) { |
|
93 // init engine only if going to pre-capture |
|
94 engine->initMode(mode); |
|
95 } else { |
|
96 // in post-capture don't init but set the correct mode to engine |
|
97 // so init can be done later |
|
98 engine->setMode(mode); |
|
99 } |
|
100 } else { |
|
101 CX_DEBUG(("CxUI: Camera started as normal app")); |
|
102 // normal start |
|
103 engine->initMode(engine->mode()); |
|
104 } |
|
105 |
|
106 #ifdef Q_OS_SYMBIAN |
|
107 //!@todo: Yield run time to system to get enough resources released to start camera. |
|
108 CX_DEBUG(("CxUI: yield control for resource freeing..")); |
|
109 User::After(2*1000*1000); // 2s |
|
110 CX_DEBUG(("CxUI: waiting done..")); |
|
111 #endif // Q_OS_SYMBIAN |
|
112 |
|
113 // Load language specific application localization file, e.g. "camera_en.qm" |
|
114 // Translations need to be loaded before any widgets are created. |
|
115 CX_DEBUG(("CxUI: Load translations..")); |
81 OstTrace0( camerax_performance, DUP3__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 1" ); |
116 OstTrace0( camerax_performance, DUP3__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 1" ); |
82 QTranslator translator; |
117 HbTranslator translator(TRANSLATIONS_PATH, TRANSLATIONS_FILE); |
83 QString lang = QLocale::system().name(); |
118 // Load language specific common localization file |
|
119 translator.loadCommon(); |
|
120 OstTrace0( camerax_performance, DUP4__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 0" ); |
|
121 CX_DEBUG(("CxUI: ..translations loaded")); |
84 |
122 |
85 CX_DEBUG(("CxUI: loading translation")); |
123 // Create main window |
86 bool ret = false; |
|
87 ret = translator.load(TRANSLATIONS_PATH + TRANSLATIONS_FILE_NAME + lang); |
|
88 CX_DEBUG(("load ok=%d", ret)); |
|
89 app.installTranslator( &translator ); |
|
90 |
|
91 QTranslator commonTranslator; |
|
92 CX_DEBUG(("CxUI: loading common translation")); |
|
93 ret = false; |
|
94 ret = commonTranslator.load(TRANSLATIONS_PATH + COMMON_TRANSLATIONS_FILE_NAME + lang); |
|
95 CX_DEBUG(("load ok=%d", ret)); |
|
96 app.installTranslator(&commonTranslator); |
|
97 OstTrace0( camerax_performance, DUP4__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 0" ); |
|
98 |
|
99 OstTrace0( camerax_performance, DUP5__MAIN, "msg: e_CX_MAINWINDOW_CREATION 1" ); |
124 OstTrace0( camerax_performance, DUP5__MAIN, "msg: e_CX_MAINWINDOW_CREATION 1" ); |
100 HbMainWindow *mainWindow = new HbMainWindow(0, Hb::WindowFlagTransparent | |
125 HbMainWindow mainWindow(0, Hb::WindowFlagTransparent | Hb::WindowFlagNoBackground); |
101 Hb::WindowFlagNoBackground); |
126 mainWindow.setAttribute(Qt::WA_NoBackground); |
102 mainWindow->setAttribute(Qt::WA_NoBackground); |
|
103 OstTrace0( camerax_performance, DUP6__MAIN, "msg: e_CX_MAINWINDOW_CREATION 0" ); |
127 OstTrace0( camerax_performance, DUP6__MAIN, "msg: e_CX_MAINWINDOW_CREATION 0" ); |
104 |
128 |
|
129 // Set main window to landscape and full screen |
|
130 OstTrace0( camerax_performance, DUP13__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 1" ); |
|
131 mainWindow.setOrientation(Qt::Horizontal); |
|
132 OstTrace0( camerax_performance, DUP14__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 0" ); |
|
133 OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" ); |
|
134 |
|
135 #ifdef Q_OS_SYMBIAN |
|
136 mainWindow.showFullScreen(); |
|
137 #else |
|
138 /* |
|
139 * todo : check if this is an Orbit bug or if there's a better solution |
|
140 */ |
|
141 mainWindow.resize(640, 360); |
|
142 mainWindow.setOrientation(Qt::Vertical, false); |
|
143 mainWindow.show(); |
|
144 mainWindow.setOrientation(Qt::Horizontal, false); |
|
145 #endif //Q_OS_SYMBIAN |
|
146 OstTrace0( camerax_performance, DUP16__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 0" ); |
|
147 |
|
148 // Create view manager |
105 OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" ); |
149 OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" ); |
106 CxuiViewManager *viewManager = new CxuiViewManager(app, *mainWindow, *eng); |
150 CxuiViewManager *viewManager = new CxuiViewManager(app, mainWindow, *engine); |
107 OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" ); |
151 OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" ); |
108 |
152 |
109 OstTrace0( camerax_performance, DUP13__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 1" ); |
153 // Give main window id to engine for setting up viewfinder window behind it |
110 mainWindow->setOrientation(Qt::Horizontal); |
154 OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_PREPAREWINDOW 1" ); |
111 OstTrace0( camerax_performance, DUP14__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 0" ); |
155 engine->viewfinderControl().setWindow(mainWindow.effectiveWinId()); |
|
156 OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_PREPAREWINDOW 0" ); |
112 |
157 |
113 OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" ); |
|
114 mainWindow->showFullScreen(); |
|
115 OstTrace0( camerax_performance, DUP16__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 0" ); |
|
116 |
|
117 OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_PREPAREWINDOW 1" ); |
|
118 viewManager->prepareWindow(); |
|
119 OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_PREPAREWINDOW 0" ); |
|
120 //! @todo initMode call added here as a temporary hack to change the startup sequence |
|
121 // in order to avoid GOOM issues |
|
122 User::After(2000000); |
|
123 eng->initMode(Cxe::ImageMode); |
|
124 int returnValue = app.exec(); |
158 int returnValue = app.exec(); |
125 |
159 |
126 // delete service provider instance |
|
127 CxuiServiceProvider::destroy(); |
|
128 |
|
129 delete viewManager; |
160 delete viewManager; |
130 delete mainWindow; |
161 CxuiServiceProvider::destroy(); // delete service provider instance |
131 delete eng; |
162 delete engine; |
132 |
163 |
133 return returnValue; |
164 return returnValue; |
134 } |
165 } |