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