camerauis/cameraxui/cxui/src/main.cpp
branchRCL_3
changeset 54 bac7acad7cb3
parent 53 61bc0f252b2b
child 57 2c87b2808fd7
equal deleted inserted replaced
53:61bc0f252b2b 54:bac7acad7cb3
     1 /*
       
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QApplication>
       
    19 #include <QGraphicsProxyWidget>
       
    20 // needed for localization
       
    21 #include <QLocale>
       
    22 #include <HbTranslator>
       
    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
       
    30 
       
    31 #include "cxeengine.h"
       
    32 #include "cxecameradevicecontrol.h"
       
    33 #include "cxuiapplication.h"
       
    34 #include "cxuiviewmanager.h"
       
    35 #include "cxuiapplicationstate.h"
       
    36 #include "cxuienums.h"
       
    37 #include "cxutils.h"
       
    38 #include "cxuiserviceprovider.h"
       
    39 
       
    40 #ifdef Q_OS_SYMBIAN
       
    41 #include "OstTraceDefinitions.h"
       
    42 #ifdef OST_TRACE_COMPILER_IN_USE
       
    43 #include "mainTraces.h"
       
    44 #endif // OST_TRACE_COMPILER_IN_USE
       
    45 #endif // Q_OS_SYMBIAN
       
    46 
       
    47 using namespace Cxe;
       
    48 
       
    49 // CONSTANTS
       
    50 const QString TRANSLATIONS_PATH = "/resource/qt/translations/";
       
    51 const QString TRANSLATIONS_FILE = "camera";
       
    52 
       
    53 int main(int argc, char *argv[])
       
    54 {
       
    55     CX_DEBUG(("CxUI: entering main()"));
       
    56     OstTrace0( camerax_performance, _MAIN, "msg: e_CX_STARTUP 1" );
       
    57 
       
    58     Q_INIT_RESOURCE(cxui);
       
    59 
       
    60     // Use software rendering / raster graphics system to save graphics memory
       
    61     CX_DEBUG(("CxUI: Take raster graphics system into use"));
       
    62     QApplication::setGraphicsSystem("raster");
       
    63 
       
    64     OstTrace0( camerax_performance, DUP1__MAIN, "msg: e_CX_HBAPP_CREATION 1" );
       
    65     CxuiApplication app(argc, argv);
       
    66     OstTrace0( camerax_performance, DUP2__MAIN, "msg: e_CX_HBAPP_CREATION 0" );
       
    67 
       
    68     // Creating and initializing engine as early as possible.
       
    69     // Reserve and power on can then proceed in parallel with
       
    70     // ui construction.
       
    71     OstTrace0( camerax_performance, DUP7__MAIN, "msg: e_CX_CREATE_ENGINE 1" );
       
    72     CxeEngine *engine = CxeEngine::createEngine();
       
    73     OstTrace0( camerax_performance, DUP8__MAIN, "msg: e_CX_CREATE_ENGINE 0" );
       
    74 
       
    75     if (app.activateReason() == Hb::ActivationReasonService ||
       
    76         // @todo: There's a bug in orbit and we never get Hb::ActivationReasonService as
       
    77         // activation reason. Use XQServiceUtil to determine if starting service as
       
    78         // a workaround for now
       
    79         XQServiceUtil::isService()) {
       
    80         CX_DEBUG(("CxUI: Camera started as service"));
       
    81         // Embedded mode.  Engine is inited to correct mode
       
    82         // by service provider when request arrives
       
    83         CX_DEBUG(("CxUI: creating serviceprovider"));
       
    84         CxuiServiceProvider::create(engine);
       
    85         CX_DEBUG(("CxUI: done"));
       
    86     } else if (app.activateReason() == Hb::ActivationReasonActivity) {
       
    87         CX_DEBUG(("CxUI: Camera started as activity"));
       
    88         Cxe::CameraMode mode = Cxe::ImageMode;
       
    89         QString activityId = app.activateId();
       
    90         if (activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY ||
       
    91             activityId == CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY) {
       
    92             mode = Cxe::VideoMode;
       
    93         }
       
    94 
       
    95         if (activityId == CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY ||
       
    96             activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY) {
       
    97             // init engine only if going to pre-capture
       
    98             engine->initMode(mode);
       
    99         } else {
       
   100             // in post-capture don't init but set the correct mode to engine
       
   101             // so init can be done later
       
   102             engine->setMode(mode);
       
   103         }
       
   104     } else {
       
   105         CX_DEBUG(("CxUI: Camera started as normal app"));
       
   106         // normal start
       
   107         engine->initMode(engine->mode());
       
   108     }
       
   109 
       
   110     // Load language specific application localization file, e.g. "camera_en.qm"
       
   111     // Translations need to be loaded before any widgets are created.
       
   112     CX_DEBUG(("CxUI: Load translations.."));
       
   113     OstTrace0( camerax_performance, DUP3__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 1" );
       
   114     HbTranslator translator(TRANSLATIONS_PATH, TRANSLATIONS_FILE);
       
   115     // Load language specific common localization file
       
   116     translator.loadCommon();
       
   117     OstTrace0( camerax_performance, DUP4__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 0" );
       
   118     CX_DEBUG(("CxUI: ..translations loaded"));
       
   119 
       
   120     // Create main window
       
   121     OstTrace0( camerax_performance, DUP5__MAIN, "msg: e_CX_MAINWINDOW_CREATION 1" );
       
   122     HbMainWindow mainWindow(0, Hb::WindowFlagTransparent | Hb::WindowFlagNoBackground);
       
   123     mainWindow.setAttribute(Qt::WA_NoBackground);
       
   124     OstTrace0( camerax_performance, DUP6__MAIN, "msg: e_CX_MAINWINDOW_CREATION 0" );
       
   125 
       
   126     // Set main window to landscape and full screen
       
   127     OstTrace0( camerax_performance, DUP13__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 1" );
       
   128     mainWindow.setOrientation(Qt::Horizontal);
       
   129     OstTrace0( camerax_performance, DUP14__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 0" );
       
   130     OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" );
       
   131 
       
   132 #ifdef Q_OS_SYMBIAN
       
   133     mainWindow.showFullScreen();
       
   134 #else
       
   135     /*
       
   136      * todo : check if this is an Orbit bug or if there's a better solution
       
   137     */
       
   138     mainWindow.resize(640, 360);
       
   139     mainWindow.setOrientation(Qt::Vertical, false);
       
   140     mainWindow.show();
       
   141     mainWindow.setOrientation(Qt::Horizontal, false);
       
   142 #endif //Q_OS_SYMBIAN
       
   143     OstTrace0( camerax_performance, DUP16__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 0" );
       
   144 
       
   145     // Create view manager
       
   146     OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" );
       
   147     CxuiViewManager *viewManager = new CxuiViewManager(app, mainWindow, *engine);
       
   148     OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" );
       
   149 
       
   150     // Give main window id to engine for setting up viewfinder window behind it
       
   151     OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_PREPAREWINDOW 1" );
       
   152     engine->viewfinderControl().setWindow(mainWindow.effectiveWinId());
       
   153     OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_PREPAREWINDOW 0" );
       
   154 
       
   155     int returnValue = app.exec();
       
   156 
       
   157     delete viewManager;
       
   158     CxuiServiceProvider::destroy(); // delete service provider instance
       
   159     delete engine;
       
   160 
       
   161     return returnValue;
       
   162 }