camerauis/cameraxui/cxui/src/main.cpp
changeset 48 42ba2d16bf40
parent 37 64817133cd1d
child 56 01e205c615b9
--- a/camerauis/cameraxui/cxui/src/main.cpp	Tue Jul 06 14:04:02 2010 +0300
+++ b/camerauis/cameraxui/cxui/src/main.cpp	Wed Aug 18 09:37:18 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -15,27 +15,34 @@
 *
 */
 
-#include <coemain.h>
-#include <eikenv.h>
 #include <QApplication>
 #include <QGraphicsProxyWidget>
 // needed for localization
+#include <QLocale>
 #include <HbTranslator>
-#include <QLocale>
 #include <hbmainwindow.h>
+#include <xqserviceutil.h>
+
+#ifdef Q_OS_SYMBIAN
+#include <coemain.h>
+#include <eikenv.h>
+#endif // Q_OS_SYMBIAN
 
 #include "cxeengine.h"
 #include "cxecameradevicecontrol.h"
 #include "cxuiapplication.h"
 #include "cxuiviewmanager.h"
 #include "cxuiapplicationstate.h"
+#include "cxuienums.h"
 #include "cxutils.h"
 #include "cxuiserviceprovider.h"
 
+#ifdef Q_OS_SYMBIAN
 #include "OstTraceDefinitions.h"
 #ifdef OST_TRACE_COMPILER_IN_USE
 #include "mainTraces.h"
-#endif
+#endif // OST_TRACE_COMPILER_IN_USE
+#endif // Q_OS_SYMBIAN
 
 using namespace Cxe;
 
@@ -63,80 +70,101 @@
     // Reserve and power on can then proceed in parallel with
     // ui construction.
     OstTrace0( camerax_performance, DUP7__MAIN, "msg: e_CX_CREATE_ENGINE 1" );
-    CxeEngine *eng = CxeEngine::createEngine();
+    CxeEngine *engine = CxeEngine::createEngine();
     OstTrace0( camerax_performance, DUP8__MAIN, "msg: e_CX_CREATE_ENGINE 0" );
 
-    if (app.activateReason() == Hb::ActivationReasonService) {
+    if (app.activateReason() == Hb::ActivationReasonService ||
+        // @todo: There's a bug in orbit and we never get Hb::ActivationReasonService as
+        // activation reason. Use XQServiceUtil to determine if starting service as
+        // a workaround for now
+        XQServiceUtil::isService()) {
+        CX_DEBUG(("CxUI: Camera started as service"));
         // Embedded mode.  Engine is inited to correct mode
         // by service provider when request arrives
         CX_DEBUG(("CxUI: creating serviceprovider"));
-        CxuiServiceProvider::create(eng);
+        CxuiServiceProvider::create(engine);
         CX_DEBUG(("CxUI: done"));
-    } else {
-        // Normal mode. Init engine now.
-        OstTrace0( camerax_performance, DUP9__MAIN, "msg: e_CX_INIT_ENGINE 1" );
-		 //! @todo temporarily commented as part of a hack to change the startup sequence
-         // to avoid GOOM issues
-        //eng->initMode(Cxe::ImageMode);
-        OstTrace0( camerax_performance, DUP10__MAIN, "msg: e_CX_INIT_ENGINE 0" );
-    }
+    } else if (app.activateReason() == Hb::ActivationReasonActivity) {
+        CX_DEBUG(("CxUI: Camera started as activity"));
+        Cxe::CameraMode mode = Cxe::ImageMode;
+        QString activityId = app.activateId();
+        if (activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY ||
+            activityId == CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY) {
+            mode = Cxe::VideoMode;
+        }
+
+        if (activityId == CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY ||
+            activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY) {
+            // init engine only if going to pre-capture
+            engine->initMode(mode);
+        } else {
+            // in post-capture don't init but set the correct mode to engine
+            // so init can be done later
+            engine->setMode(mode);
+        }
+	} else {
+        CX_DEBUG(("CxUI: Camera started as normal app"));
+	    // normal start
+	    engine->initMode(engine->mode());
+	}
+
+#ifdef Q_OS_SYMBIAN
+    //!@todo: Yield run time to system to get enough resources released to start camera.
+    CX_DEBUG(("CxUI: yield control for resource freeing.."));
+    User::After(2*1000*1000); // 2s
+    CX_DEBUG(("CxUI: waiting done.."));
+#endif // Q_OS_SYMBIAN
 
     // Load language specific application localization file, e.g. "camera_en.qm"
+    // Translations need to be loaded before any widgets are created.
     CX_DEBUG(("CxUI: Load translations.."));
     OstTrace0( camerax_performance, DUP3__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 1" );
-    HbTranslator* trans = new HbTranslator(TRANSLATIONS_PATH, TRANSLATIONS_FILE);
+    HbTranslator translator(TRANSLATIONS_PATH, TRANSLATIONS_FILE);
     // Load language specific common localization file
-    trans->loadCommon();
+    translator.loadCommon();
     OstTrace0( camerax_performance, DUP4__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 0" );
     CX_DEBUG(("CxUI: ..translations loaded"));
 
+    // Create main window
     OstTrace0( camerax_performance, DUP5__MAIN, "msg: e_CX_MAINWINDOW_CREATION 1" );
-    HbMainWindow *mainWindow = new HbMainWindow(0, Hb::WindowFlagTransparent |
-                                                   Hb::WindowFlagNoBackground);
-    mainWindow->setAttribute(Qt::WA_NoBackground);
+    HbMainWindow mainWindow(0, Hb::WindowFlagTransparent | Hb::WindowFlagNoBackground);
+    mainWindow.setAttribute(Qt::WA_NoBackground);
     OstTrace0( camerax_performance, DUP6__MAIN, "msg: e_CX_MAINWINDOW_CREATION 0" );
 
-    OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" );
-    CxuiViewManager *viewManager = new CxuiViewManager(app, *mainWindow, *eng);
-    OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" );
-
+    // Set main window to landscape and full screen
     OstTrace0( camerax_performance, DUP13__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 1" );
-    mainWindow->setOrientation(Qt::Horizontal);
+    mainWindow.setOrientation(Qt::Horizontal);
     OstTrace0( camerax_performance, DUP14__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 0" );
+    OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" );
 
-    OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" );
-    mainWindow->showFullScreen();
+#ifdef Q_OS_SYMBIAN
+    mainWindow.showFullScreen();
+#else
+    /*
+     * todo : check if this is an Orbit bug or if there's a better solution
+    */
+    mainWindow.resize(640, 360);
+    mainWindow.setOrientation(Qt::Vertical, false);
+    mainWindow.show();
+    mainWindow.setOrientation(Qt::Horizontal, false);
+#endif //Q_OS_SYMBIAN
     OstTrace0( camerax_performance, DUP16__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 0" );
 
-    OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_PREPAREWINDOW 1" );
-    eng->viewfinderControl().setWindow(mainWindow->effectiveWinId());
-    OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_PREPAREWINDOW 0" );
+    // Create view manager
+    OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" );
+    CxuiViewManager *viewManager = new CxuiViewManager(app, mainWindow, *engine);
+    OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" );
 
-    //! @todo initMode call added here as a temporary hack to change the startup sequence
-	// in order to avoid GOOM issues.
-	if (app.activateReason() != Hb::ActivationReasonService
-	 && viewManager->applicationState().currentState() == CxuiApplicationState::Normal) {
-    	User::After(2000000);
-    	if (app.activateReason() == Hb::ActivationReasonActivity) {
-    	    // when started by activity, let viewmanager init
-    	    // to correct mode
-    	    viewManager->initEngine();
-    	} else {
-    	    // normal start
-    	    eng->initMode(eng->mode());
-    	}
-    }
+    // Give main window id to engine for setting up viewfinder window behind it
+    OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_PREPAREWINDOW 1" );
+    engine->viewfinderControl().setWindow(mainWindow.effectiveWinId());
+    OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_PREPAREWINDOW 0" );
 
     int returnValue = app.exec();
 
     delete viewManager;
-
-    // delete service provider instance
-    CxuiServiceProvider::destroy();
-
-    delete mainWindow;
-    delete trans;
-    delete eng;
+    CxuiServiceProvider::destroy(); // delete service provider instance
+    delete engine;
 
     return returnValue;
 }