camerauis/cameraxui/cxui/src/main.cpp
changeset 48 42ba2d16bf40
parent 37 64817133cd1d
child 56 01e205c615b9
equal deleted inserted replaced
37:64817133cd1d 48:42ba2d16bf40
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    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
       
    21 #include <QLocale>
    23 #include <HbTranslator>
    22 #include <HbTranslator>
    24 #include <QLocale>
       
    25 #include <hbmainwindow.h>
    23 #include <hbmainwindow.h>
       
    24 #include <xqserviceutil.h>
       
    25 
       
    26 #ifdef Q_OS_SYMBIAN
       
    27 #include <coemain.h>
       
    28 #include <eikenv.h>
       
    29 #endif // Q_OS_SYMBIAN
    26 
    30 
    27 #include "cxeengine.h"
    31 #include "cxeengine.h"
    28 #include "cxecameradevicecontrol.h"
    32 #include "cxecameradevicecontrol.h"
    29 #include "cxuiapplication.h"
    33 #include "cxuiapplication.h"
    30 #include "cxuiviewmanager.h"
    34 #include "cxuiviewmanager.h"
    31 #include "cxuiapplicationstate.h"
    35 #include "cxuiapplicationstate.h"
       
    36 #include "cxuienums.h"
    32 #include "cxutils.h"
    37 #include "cxutils.h"
    33 #include "cxuiserviceprovider.h"
    38 #include "cxuiserviceprovider.h"
    34 
    39 
       
    40 #ifdef Q_OS_SYMBIAN
    35 #include "OstTraceDefinitions.h"
    41 #include "OstTraceDefinitions.h"
    36 #ifdef OST_TRACE_COMPILER_IN_USE
    42 #ifdef OST_TRACE_COMPILER_IN_USE
    37 #include "mainTraces.h"
    43 #include "mainTraces.h"
    38 #endif
    44 #endif // OST_TRACE_COMPILER_IN_USE
       
    45 #endif // Q_OS_SYMBIAN
    39 
    46 
    40 using namespace Cxe;
    47 using namespace Cxe;
    41 
    48 
    42 // CONSTANTS
    49 // CONSTANTS
    43 const QString TRANSLATIONS_PATH = "/resource/qt/translations/";
    50 const QString TRANSLATIONS_PATH = "/resource/qt/translations/";
    61 
    68 
    62     // Creating and initializing engine as early as possible.
    69     // Creating and initializing engine as early as possible.
    63     // Reserve and power on can then proceed in parallel with
    70     // Reserve and power on can then proceed in parallel with
    64     // ui construction.
    71     // ui construction.
    65     OstTrace0( camerax_performance, DUP7__MAIN, "msg: e_CX_CREATE_ENGINE 1" );
    72     OstTrace0( camerax_performance, DUP7__MAIN, "msg: e_CX_CREATE_ENGINE 1" );
    66     CxeEngine *eng = CxeEngine::createEngine();
    73     CxeEngine *engine = CxeEngine::createEngine();
    67     OstTrace0( camerax_performance, DUP8__MAIN, "msg: e_CX_CREATE_ENGINE 0" );
    74     OstTrace0( camerax_performance, DUP8__MAIN, "msg: e_CX_CREATE_ENGINE 0" );
    68 
    75 
    69     if (app.activateReason() == Hb::ActivationReasonService) {
    76     if (app.activateReason() == Hb::ActivationReasonService ||
       
    77         // @todo: There's a bug in orbit and we never get Hb::ActivationReasonService as
       
    78         // activation reason. Use XQServiceUtil to determine if starting service as
       
    79         // a workaround for now
       
    80         XQServiceUtil::isService()) {
       
    81         CX_DEBUG(("CxUI: Camera started as service"));
    70         // Embedded mode.  Engine is inited to correct mode
    82         // Embedded mode.  Engine is inited to correct mode
    71         // by service provider when request arrives
    83         // by service provider when request arrives
    72         CX_DEBUG(("CxUI: creating serviceprovider"));
    84         CX_DEBUG(("CxUI: creating serviceprovider"));
    73         CxuiServiceProvider::create(eng);
    85         CxuiServiceProvider::create(engine);
    74         CX_DEBUG(("CxUI: done"));
    86         CX_DEBUG(("CxUI: done"));
    75     } else {
    87     } else if (app.activateReason() == Hb::ActivationReasonActivity) {
    76         // Normal mode. Init engine now.
    88         CX_DEBUG(("CxUI: Camera started as activity"));
    77         OstTrace0( camerax_performance, DUP9__MAIN, "msg: e_CX_INIT_ENGINE 1" );
    89         Cxe::CameraMode mode = Cxe::ImageMode;
    78 		 //! @todo temporarily commented as part of a hack to change the startup sequence
    90         QString activityId = app.activateId();
    79          // to avoid GOOM issues
    91         if (activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY ||
    80         //eng->initMode(Cxe::ImageMode);
    92             activityId == CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY) {
    81         OstTrace0( camerax_performance, DUP10__MAIN, "msg: e_CX_INIT_ENGINE 0" );
    93             mode = Cxe::VideoMode;
    82     }
    94         }
       
    95 
       
    96         if (activityId == CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY ||
       
    97             activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY) {
       
    98             // init engine only if going to pre-capture
       
    99             engine->initMode(mode);
       
   100         } else {
       
   101             // in post-capture don't init but set the correct mode to engine
       
   102             // so init can be done later
       
   103             engine->setMode(mode);
       
   104         }
       
   105 	} else {
       
   106         CX_DEBUG(("CxUI: Camera started as normal app"));
       
   107 	    // normal start
       
   108 	    engine->initMode(engine->mode());
       
   109 	}
       
   110 
       
   111 #ifdef Q_OS_SYMBIAN
       
   112     //!@todo: Yield run time to system to get enough resources released to start camera.
       
   113     CX_DEBUG(("CxUI: yield control for resource freeing.."));
       
   114     User::After(2*1000*1000); // 2s
       
   115     CX_DEBUG(("CxUI: waiting done.."));
       
   116 #endif // Q_OS_SYMBIAN
    83 
   117 
    84     // Load language specific application localization file, e.g. "camera_en.qm"
   118     // Load language specific application localization file, e.g. "camera_en.qm"
       
   119     // Translations need to be loaded before any widgets are created.
    85     CX_DEBUG(("CxUI: Load translations.."));
   120     CX_DEBUG(("CxUI: Load translations.."));
    86     OstTrace0( camerax_performance, DUP3__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 1" );
   121     OstTrace0( camerax_performance, DUP3__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 1" );
    87     HbTranslator* trans = new HbTranslator(TRANSLATIONS_PATH, TRANSLATIONS_FILE);
   122     HbTranslator translator(TRANSLATIONS_PATH, TRANSLATIONS_FILE);
    88     // Load language specific common localization file
   123     // Load language specific common localization file
    89     trans->loadCommon();
   124     translator.loadCommon();
    90     OstTrace0( camerax_performance, DUP4__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 0" );
   125     OstTrace0( camerax_performance, DUP4__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 0" );
    91     CX_DEBUG(("CxUI: ..translations loaded"));
   126     CX_DEBUG(("CxUI: ..translations loaded"));
    92 
   127 
       
   128     // Create main window
    93     OstTrace0( camerax_performance, DUP5__MAIN, "msg: e_CX_MAINWINDOW_CREATION 1" );
   129     OstTrace0( camerax_performance, DUP5__MAIN, "msg: e_CX_MAINWINDOW_CREATION 1" );
    94     HbMainWindow *mainWindow = new HbMainWindow(0, Hb::WindowFlagTransparent |
   130     HbMainWindow mainWindow(0, Hb::WindowFlagTransparent | Hb::WindowFlagNoBackground);
    95                                                    Hb::WindowFlagNoBackground);
   131     mainWindow.setAttribute(Qt::WA_NoBackground);
    96     mainWindow->setAttribute(Qt::WA_NoBackground);
       
    97     OstTrace0( camerax_performance, DUP6__MAIN, "msg: e_CX_MAINWINDOW_CREATION 0" );
   132     OstTrace0( camerax_performance, DUP6__MAIN, "msg: e_CX_MAINWINDOW_CREATION 0" );
    98 
   133 
       
   134     // Set main window to landscape and full screen
       
   135     OstTrace0( camerax_performance, DUP13__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 1" );
       
   136     mainWindow.setOrientation(Qt::Horizontal);
       
   137     OstTrace0( camerax_performance, DUP14__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 0" );
       
   138     OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" );
       
   139 
       
   140 #ifdef Q_OS_SYMBIAN
       
   141     mainWindow.showFullScreen();
       
   142 #else
       
   143     /*
       
   144      * todo : check if this is an Orbit bug or if there's a better solution
       
   145     */
       
   146     mainWindow.resize(640, 360);
       
   147     mainWindow.setOrientation(Qt::Vertical, false);
       
   148     mainWindow.show();
       
   149     mainWindow.setOrientation(Qt::Horizontal, false);
       
   150 #endif //Q_OS_SYMBIAN
       
   151     OstTrace0( camerax_performance, DUP16__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 0" );
       
   152 
       
   153     // Create view manager
    99     OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" );
   154     OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" );
   100     CxuiViewManager *viewManager = new CxuiViewManager(app, *mainWindow, *eng);
   155     CxuiViewManager *viewManager = new CxuiViewManager(app, mainWindow, *engine);
   101     OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" );
   156     OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" );
   102 
   157 
   103     OstTrace0( camerax_performance, DUP13__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 1" );
   158     // Give main window id to engine for setting up viewfinder window behind it
   104     mainWindow->setOrientation(Qt::Horizontal);
       
   105     OstTrace0( camerax_performance, DUP14__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 0" );
       
   106 
       
   107     OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" );
       
   108     mainWindow->showFullScreen();
       
   109     OstTrace0( camerax_performance, DUP16__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 0" );
       
   110 
       
   111     OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_PREPAREWINDOW 1" );
   159     OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_PREPAREWINDOW 1" );
   112     eng->viewfinderControl().setWindow(mainWindow->effectiveWinId());
   160     engine->viewfinderControl().setWindow(mainWindow.effectiveWinId());
   113     OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_PREPAREWINDOW 0" );
   161     OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_PREPAREWINDOW 0" );
   114 
       
   115     //! @todo initMode call added here as a temporary hack to change the startup sequence
       
   116 	// in order to avoid GOOM issues.
       
   117 	if (app.activateReason() != Hb::ActivationReasonService
       
   118 	 && viewManager->applicationState().currentState() == CxuiApplicationState::Normal) {
       
   119     	User::After(2000000);
       
   120     	if (app.activateReason() == Hb::ActivationReasonActivity) {
       
   121     	    // when started by activity, let viewmanager init
       
   122     	    // to correct mode
       
   123     	    viewManager->initEngine();
       
   124     	} else {
       
   125     	    // normal start
       
   126     	    eng->initMode(eng->mode());
       
   127     	}
       
   128     }
       
   129 
   162 
   130     int returnValue = app.exec();
   163     int returnValue = app.exec();
   131 
   164 
   132     delete viewManager;
   165     delete viewManager;
   133 
   166     CxuiServiceProvider::destroy(); // delete service provider instance
   134     // delete service provider instance
   167     delete engine;
   135     CxuiServiceProvider::destroy();
       
   136 
       
   137     delete mainWindow;
       
   138     delete trans;
       
   139     delete eng;
       
   140 
   168 
   141     return returnValue;
   169     return returnValue;
   142 }
   170 }