camerauis/cameraxui/cxui/src/main.cpp
changeset 58 ddba9caa7f32
parent 52 7e18d488ac5f
child 61 fc3ff57d09ad
equal deleted inserted replaced
55:0da2a5b56583 58:ddba9caa7f32
    20 // needed for localization
    20 // needed for localization
    21 #include <QLocale>
    21 #include <QLocale>
    22 #include <HbTranslator>
    22 #include <HbTranslator>
    23 #include <hbmainwindow.h>
    23 #include <hbmainwindow.h>
    24 #include <xqserviceutil.h>
    24 #include <xqserviceutil.h>
       
    25 #include <afactivation.h>
    25 
    26 
    26 #ifdef Q_OS_SYMBIAN
    27 #ifdef Q_OS_SYMBIAN
    27 #include <coemain.h>
    28 #include <coemain.h>
    28 #include <eikenv.h>
    29 #include <eikenv.h>
       
    30 #include <XQSettingsManager>
    29 #endif // Q_OS_SYMBIAN
    31 #endif // Q_OS_SYMBIAN
    30 
    32 
    31 #include "cxeengine.h"
    33 #include "cxeengine.h"
    32 #include "cxecameradevicecontrol.h"
    34 #include "cxecameradevicecontrol.h"
    33 #include "cxuiapplication.h"
    35 #include "cxuiapplication.h"
    34 #include "cxuiviewmanager.h"
    36 #include "cxuiviewmanager.h"
    35 #include "cxuiapplicationstate.h"
    37 #include "cxuiapplicationstate.h"
    36 #include "cxuienums.h"
    38 #include "cxuienums.h"
    37 #include "cxutils.h"
    39 #include "cxutils.h"
    38 #include "cxuiserviceprovider.h"
    40 #include "cxuiserviceprovider.h"
       
    41 #include "cxuidisplaypropertyhandler.h"
    39 
    42 
    40 #ifdef Q_OS_SYMBIAN
    43 #ifdef Q_OS_SYMBIAN
    41 #include "OstTraceDefinitions.h"
    44 #include "OstTraceDefinitions.h"
    42 #ifdef OST_TRACE_COMPILER_IN_USE
    45 #ifdef OST_TRACE_COMPILER_IN_USE
    43 #include "mainTraces.h"
    46 #include "mainTraces.h"
    48 
    51 
    49 // CONSTANTS
    52 // CONSTANTS
    50 const QString TRANSLATIONS_PATH = "/resource/qt/translations/";
    53 const QString TRANSLATIONS_PATH = "/resource/qt/translations/";
    51 const QString TRANSLATIONS_FILE = "camera";
    54 const QString TRANSLATIONS_FILE = "camera";
    52 
    55 
       
    56 const long int RUNTIME_FEATURES_CENREP_UID = 0x20027018;
       
    57 const unsigned long int USE_RASTER_GRAPHICS_SYSTEM_KEY = 0x07;
       
    58 
    53 int main(int argc, char *argv[])
    59 int main(int argc, char *argv[])
    54 {
    60 {
    55     CX_DEBUG(("CxUI: entering main()"));
    61     CX_DEBUG(("CxUI: entering main()"));
    56     OstTrace0( camerax_performance, _MAIN, "msg: e_CX_STARTUP 1" );
    62     OstTrace0( camerax_performance, _MAIN, "msg: e_CX_STARTUP 1" );
    57 
    63 
    58     Q_INIT_RESOURCE(cxui);
    64     Q_INIT_RESOURCE(cxui);
    59 
    65 
    60     // Use software rendering / raster graphics system to save graphics memory
    66 #ifdef Q_OS_SYMBIAN
    61     CX_DEBUG(("CxUI: Take raster graphics system into use"));
    67     XQSettingsManager settingManager;
    62     QApplication::setGraphicsSystem("raster");
    68     XQCentralRepositorySettingsKey useRasterGraphicsSystemKey(
       
    69             RUNTIME_FEATURES_CENREP_UID, USE_RASTER_GRAPHICS_SYSTEM_KEY);
       
    70     QVariant useRasterGraphicsSystemValue =
       
    71             settingManager.readItemValue(useRasterGraphicsSystemKey,
       
    72                                          XQSettingsManager::TypeInt);
       
    73 
       
    74     if (useRasterGraphicsSystemValue.isNull()
       
    75         || useRasterGraphicsSystemValue.toInt()) {
       
    76         // Either there was an error reading the value or the value was
       
    77         // non-zero. Raster graphics system should be forced
       
    78         CX_DEBUG(("CxUI: Take raster graphics system into use"));
       
    79         QApplication::setGraphicsSystem("raster");
       
    80     }
       
    81 #endif
    63 
    82 
    64     OstTrace0( camerax_performance, DUP1__MAIN, "msg: e_CX_HBAPP_CREATION 1" );
    83     OstTrace0( camerax_performance, DUP1__MAIN, "msg: e_CX_HBAPP_CREATION 1" );
    65     CxuiApplication app(argc, argv);
    84     CxuiApplication app(argc, argv);
    66     OstTrace0( camerax_performance, DUP2__MAIN, "msg: e_CX_HBAPP_CREATION 0" );
    85     OstTrace0( camerax_performance, DUP2__MAIN, "msg: e_CX_HBAPP_CREATION 0" );
    67 
    86 
    70     // ui construction.
    89     // ui construction.
    71     OstTrace0( camerax_performance, DUP7__MAIN, "msg: e_CX_CREATE_ENGINE 1" );
    90     OstTrace0( camerax_performance, DUP7__MAIN, "msg: e_CX_CREATE_ENGINE 1" );
    72     CxeEngine *engine = CxeEngine::createEngine();
    91     CxeEngine *engine = CxeEngine::createEngine();
    73     OstTrace0( camerax_performance, DUP8__MAIN, "msg: e_CX_CREATE_ENGINE 0" );
    92     OstTrace0( camerax_performance, DUP8__MAIN, "msg: e_CX_CREATE_ENGINE 0" );
    74 
    93 
    75     if (app.activateReason() == Hb::ActivationReasonService ||
    94     AfActivation activation;
       
    95     if (activation.reason() == Hb::ActivationReasonService ||
    76         // @todo: There's a bug in orbit and we never get Hb::ActivationReasonService as
    96         // @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
    97         // activation reason. Use XQServiceUtil to determine if starting service as
    78         // a workaround for now
    98         // a workaround for now
    79         XQServiceUtil::isService()) {
    99         XQServiceUtil::isService()) {
    80         CX_DEBUG(("CxUI: Camera started as service"));
   100         CX_DEBUG(("CxUI: Camera started as service"));
    81         // Embedded mode.  Engine is inited to correct mode
   101         // Embedded mode.  Engine is inited to correct mode
    82         // by service provider when request arrives
   102         // by service provider when request arrives
    83         CX_DEBUG(("CxUI: creating serviceprovider"));
   103         CX_DEBUG(("CxUI: creating serviceprovider"));
    84         CxuiServiceProvider::create(engine);
   104         CxuiServiceProvider::create(engine);
    85         CX_DEBUG(("CxUI: done"));
   105         CX_DEBUG(("CxUI: done"));
    86     } else if (app.activateReason() == Hb::ActivationReasonActivity) {
   106     } else if (activation.reason() == Hb::ActivationReasonActivity) {
    87         CX_DEBUG(("CxUI: Camera started as activity"));
   107         CX_DEBUG(("CxUI: Camera started as activity"));
    88         Cxe::CameraMode mode = Cxe::ImageMode;
   108         Cxe::CameraMode mode = Cxe::ImageMode;
    89         QString activityId = app.activateId();
   109         QString activityId = activation.name();
    90         if (activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY ||
   110         if (activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY ||
    91             activityId == CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY) {
   111             activityId == CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY) {
    92             mode = Cxe::VideoMode;
   112             mode = Cxe::VideoMode;
    93         }
   113         }
    94 
   114 
   117     OstTrace0( camerax_performance, DUP4__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 0" );
   137     OstTrace0( camerax_performance, DUP4__MAIN, "msg: e_CX_LOAD_TRANSLATIONS 0" );
   118     CX_DEBUG(("CxUI: ..translations loaded"));
   138     CX_DEBUG(("CxUI: ..translations loaded"));
   119 
   139 
   120     // Create main window
   140     // Create main window
   121     OstTrace0( camerax_performance, DUP5__MAIN, "msg: e_CX_MAINWINDOW_CREATION 1" );
   141     OstTrace0( camerax_performance, DUP5__MAIN, "msg: e_CX_MAINWINDOW_CREATION 1" );
   122     HbMainWindow mainWindow(0, Hb::WindowFlagTransparent | Hb::WindowFlagNoBackground);
   142     HbMainWindow *mainWindow = new HbMainWindow(0, Hb::WindowFlagTransparent | Hb::WindowFlagNoBackground);
   123     mainWindow.setAttribute(Qt::WA_NoBackground);
   143     mainWindow->setAttribute(Qt::WA_NoBackground);
   124     OstTrace0( camerax_performance, DUP6__MAIN, "msg: e_CX_MAINWINDOW_CREATION 0" );
   144     OstTrace0( camerax_performance, DUP6__MAIN, "msg: e_CX_MAINWINDOW_CREATION 0" );
   125 
   145 
   126     // Set main window to landscape and full screen
   146     // Set main window to landscape and full screen
   127     OstTrace0( camerax_performance, DUP13__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 1" );
   147     OstTrace0( camerax_performance, DUP13__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 1" );
   128     mainWindow.setOrientation(Qt::Horizontal);
   148     mainWindow->setOrientation(Qt::Horizontal);
   129     OstTrace0( camerax_performance, DUP14__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 0" );
   149     OstTrace0( camerax_performance, DUP14__MAIN, "msg: e_CX_MAINWINDOW_SETORIENTATION 0" );
   130     OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" );
   150     OstTrace0( camerax_performance, DUP15__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 1" );
   131 
   151 
   132 #ifdef Q_OS_SYMBIAN
   152 #ifdef Q_OS_SYMBIAN
   133     mainWindow.showFullScreen();
   153     mainWindow->showFullScreen();
   134 #else
   154 #else
   135     /*
   155     /*
   136      * todo : check if this is an Orbit bug or if there's a better solution
   156      * todo : check if this is an Orbit bug or if there's a better solution
   137     */
   157     */
   138     mainWindow.resize(640, 360);
   158     mainWindow->resize(640, 360);
   139     mainWindow.setOrientation(Qt::Vertical, false);
   159     mainWindow->setOrientation(Qt::Vertical, false);
   140     mainWindow.show();
   160     mainWindow->show();
   141     mainWindow.setOrientation(Qt::Horizontal, false);
   161     mainWindow->setOrientation(Qt::Horizontal, false);
   142 #endif //Q_OS_SYMBIAN
   162 #endif //Q_OS_SYMBIAN
   143     OstTrace0( camerax_performance, DUP16__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 0" );
   163     OstTrace0( camerax_performance, DUP16__MAIN, "msg: e_CX_MAINWINDOW_FULLSCREEN 0" );
   144 
   164 
   145     // Create view manager
   165     // Create view manager
   146     OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" );
   166     OstTrace0( camerax_performance, DUP11__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 1" );
   147     CxuiViewManager *viewManager = new CxuiViewManager(app, mainWindow, *engine);
   167     CxuiViewManager *viewManager = new CxuiViewManager(app, *mainWindow, *engine);
   148     OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" );
   168     OstTrace0( camerax_performance, DUP12__MAIN, "msg: e_CX_CREATE_VIEW_MANAGER 0" );
   149 
   169 
   150     // Give main window id to engine for setting up viewfinder window behind it
   170     // Give main window id to engine for setting up viewfinder window behind it
   151     OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_PREPAREWINDOW 1" );
   171     OstTrace0( camerax_performance, DUP17__MAIN, "msg: e_CX_PREPAREWINDOW 1" );
   152     engine->viewfinderControl().setWindow(mainWindow.effectiveWinId());
   172     engine->viewfinderControl().setWindow(mainWindow->effectiveWinId());
   153     OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_PREPAREWINDOW 0" );
   173     OstTrace0( camerax_performance, DUP18__MAIN, "msg: e_CX_PREPAREWINDOW 0" );
       
   174 
       
   175     // connect display handler to vf state changes
       
   176     CxuiDisplayPropertyHandler displayHandler;
       
   177     QObject::connect(&engine->viewfinderControl(), SIGNAL(stateChanged(CxeViewfinderControl::State, CxeError::Id)),
       
   178                      &displayHandler, SLOT(handleVfStateChanged(CxeViewfinderControl::State, CxeError::Id)));
   154 
   179 
   155     int returnValue = app.exec();
   180     int returnValue = app.exec();
   156 
   181 
   157     delete viewManager;
   182     delete viewManager;
       
   183 	viewManager = NULL;
   158     CxuiServiceProvider::destroy(); // delete service provider instance
   184     CxuiServiceProvider::destroy(); // delete service provider instance
       
   185     engine->cameraDeviceControl().release();
       
   186     delete mainWindow;
       
   187 	mainWindow = NULL;
   159     delete engine;
   188     delete engine;
       
   189 	engine = NULL;
   160 
   190 
   161     return returnValue;
   191     return returnValue;
   162 }
   192 }