camerauis/cameraxui/cxui/src/main.cpp
changeset 19 d9aefe59d544
child 21 fa6d9f75d6a6
child 28 3075d9b614e6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
       
     1 /*
       
     2 * Copyright (c) 2009 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 #include <QApplication>
       
    18 #include <QGraphicsProxyWidget>
       
    19 #include <hbapplication.h>
       
    20 #include <hbmainwindow.h>
       
    21 #include <coemain.h>
       
    22 #include <eikenv.h>
       
    23 
       
    24 #include "cxeengine.h"
       
    25 #include "cxecameradevicecontrol.h"
       
    26 #include "cxuistillprecaptureview.h"
       
    27 #include "cxuivideoprecaptureview.h"
       
    28 #include "cxuicapturekeyhandler.h"
       
    29 #include "cxuiviewmanager.h"
       
    30 #include "cxutils.h"
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "mainTraces.h"
       
    34 #endif
       
    35 
       
    36 // needed for localization
       
    37 #include <QTranslator>
       
    38 #include <QLocale>
       
    39 
       
    40 #include "cxuiserviceprovider.h"
       
    41 #include <xqserviceutil.h>
       
    42 
       
    43 using namespace Cxe;
       
    44 
       
    45 int main(int argc, char *argv[])
       
    46 {
       
    47     CX_DEBUG(("CxUI: entering main()"));
       
    48     OstTrace0( camerax_performance, _MAIN, "msg: e_CX_STARTUP 1" );
       
    49 
       
    50     Q_INIT_RESOURCE(cxui);
       
    51 
       
    52     OstTrace0( camerax_performance, DUP7__MAIN, "msg: e_CX_HBAPP_CREATION 1" );
       
    53     HbApplication app(argc, argv);
       
    54     OstTrace0( camerax_performance, DUP8__MAIN, "msg: e_CX_HBAPP_CREATION 0" );
       
    55 
       
    56     // Load the language specific localization files: application + common
       
    57     QTranslator translator;
       
    58     QString lang = QLocale::system().name();
       
    59     QString path = "z:/resource/qt/translations/";
       
    60 
       
    61     CX_DEBUG(("CxUI: loading translation"));
       
    62     bool ret = false;
       
    63     ret = translator.load(path + "camera_" + lang);
       
    64     CX_DEBUG(("load ok=%d", ret));
       
    65     app.installTranslator( &translator );
       
    66 
       
    67     QTranslator commonTranslator;
       
    68     commonTranslator.load(path + "common_" + lang);
       
    69     app.installTranslator(&commonTranslator);
       
    70 
       
    71     OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_HBMAINWINDOW_CREATION 1" );
       
    72     HbMainWindow mainWindow(0, Hb::WindowFlagTransparent |
       
    73                                Hb::WindowFlagNoBackground);
       
    74     mainWindow.setAttribute(Qt::WA_NoBackground);
       
    75     OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_HBMAINWINDOW_CREATION 0" );
       
    76 
       
    77     // Creating and initializing engine as early as possible.
       
    78     // Reserve and power on can then proceed in parallel with
       
    79     // ui construction.
       
    80     OstTrace0( camerax_performance, DUP1__MAIN, "msg: e_CX_CREATE_ENGINE 1" );
       
    81     CxeEngine *eng = CxeEngine::createEngine();
       
    82     OstTrace0( camerax_performance, DUP2__MAIN, "msg: e_CX_CREATE_ENGINE 0" );
       
    83 
       
    84     if (XQServiceUtil::isService()) {
       
    85         // Embedded mode.  Engine is inited to correct mode
       
    86         // by service provider when request arrives
       
    87         CX_DEBUG(("CxUI: creating serviceprovider"));
       
    88         CxuiServiceProvider::create(eng);
       
    89         CX_DEBUG(("CxUI: done"));
       
    90     } else {
       
    91         // Normal mode. Init engine now.
       
    92         OstTrace0( camerax_performance, DUP5__MAIN, "msg: e_CX_INIT_ENGINE 1" );
       
    93         eng->initMode(Cxe::ImageMode);
       
    94         OstTrace0( camerax_performance, DUP6__MAIN, "msg: e_CX_INIT_ENGINE 0" );
       
    95     }
       
    96 
       
    97     // If the parent of the engine is set to be the
       
    98     // HbApplication, then for some reason the engine won't be deleted
       
    99     // on shutdown (or at least there will be no traces visible of it)
       
   100     //eng->setParent(&app); // HbApplication will now own the engine
       
   101 
       
   102     CxuiCaptureKeyHandler keyHandler(*eng);
       
   103 
       
   104     OstTrace0( camerax_performance, DUP3__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" );
       
   105     CxuiViewManager viewManager(mainWindow, *eng, keyHandler);
       
   106     OstTrace0( camerax_performance, DUP4__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" );
       
   107 
       
   108     // Setting the viewmanager as the parent of the engine fixes the deletion issue
       
   109     eng->setParent(&viewManager);
       
   110 
       
   111     OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_HBMAINWINDOWORIENT 1" );
       
   112     mainWindow.setOrientation(Qt::Horizontal);
       
   113     OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_HBMAINWINDOWORIENT 0" );
       
   114 
       
   115     OstTrace0( camerax_performance, DUP13__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" );
       
   116     mainWindow.showFullScreen();
       
   117     OstTrace0( camerax_performance, DUP14__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 0" );
       
   118 
       
   119     OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_PREPAREWINDOW 1" );
       
   120     viewManager.prepareWindow();
       
   121 
       
   122     OstTrace0( camerax_performance, DUP16__MAIN, "msg: e_CX_PREPAREWINDOW 0" );
       
   123 
       
   124     int returnValue = app.exec();
       
   125 
       
   126     // delete service provider instance
       
   127     CxuiServiceProvider::destroy();
       
   128 
       
   129     return returnValue;
       
   130 }