camerauis/cameraxui/cxui/src/cxuivideoprecaptureview.cpp
changeset 41 67457b2ffb33
parent 40 2922f70fca82
child 42 feebad15db8c
equal deleted inserted replaced
40:2922f70fca82 41:67457b2ffb33
    29 #include <hbmenu.h>
    29 #include <hbmenu.h>
    30 #include <hbdialog.h>
    30 #include <hbdialog.h>
    31 #include <hbnotificationdialog.h>
    31 #include <hbnotificationdialog.h>
    32 #include <hbfeedbacksettings.h>
    32 #include <hbfeedbacksettings.h>
    33 #include <hbfeedbacknamespace.h>
    33 #include <hbfeedbacknamespace.h>
       
    34 #include <hbactivitymanager.h>
    34 
    35 
    35 #include "cxuivideoprecaptureview.h"
    36 #include "cxuivideoprecaptureview.h"
    36 #include "cxeengine.h"
    37 #include "cxeengine.h"
    37 #include "cxeviewfindercontrol.h"
    38 #include "cxeviewfindercontrol.h"
    38 #include "cxevideocapturecontrol.h"
    39 #include "cxevideocapturecontrol.h"
    94     CX_DEBUG_EXIT_FUNCTION();
    95     CX_DEBUG_EXIT_FUNCTION();
    95 }
    96 }
    96 
    97 
    97 void CxuiVideoPrecaptureView::construct(HbMainWindow *mainwindow, CxeEngine *engine,
    98 void CxuiVideoPrecaptureView::construct(HbMainWindow *mainwindow, CxeEngine *engine,
    98                                         CxuiDocumentLoader *documentLoader,
    99                                         CxuiDocumentLoader *documentLoader,
    99                                         CxuiCaptureKeyHandler *keyHandler)
   100                                         CxuiCaptureKeyHandler *keyHandler,
   100 {
   101                                         HbActivityManager *activityManager)
   101     CX_DEBUG_ENTER_FUNCTION();
   102 {
   102 
   103     CX_DEBUG_ENTER_FUNCTION();
   103     CxuiPrecaptureView::construct(mainwindow, engine, documentLoader, keyHandler);
   104 
       
   105     CxuiPrecaptureView::construct(mainwindow, engine, documentLoader, keyHandler, activityManager);
   104     mCaptureKeyHandler = keyHandler;
   106     mCaptureKeyHandler = keyHandler;
   105 
   107 
   106     mVideoCaptureControl = &(engine->videoCaptureControl());
   108     mVideoCaptureControl = &(engine->videoCaptureControl());
   107 
   109 
   108     connect(&mElapsedTimer, SIGNAL(timeout()), this, SLOT(updateTimeLabels()));
   110     connect(&mElapsedTimer, SIGNAL(timeout()), this, SLOT(updateTimeLabels()));
   109     connect(mVideoCaptureControl, SIGNAL(snapshotReady(CxeError::Id, const QPixmap&, const QString&)),
   111     connect(mVideoCaptureControl, SIGNAL(snapshotReady(CxeError::Id, const QImage&, const QString&)),
   110             this, SLOT(handleSnapshot(CxeError::Id)));
   112             this, SLOT(handleSnapshot(CxeError::Id)));
   111     connect(mVideoCaptureControl, SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id)),
   113     connect(mVideoCaptureControl, SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id)),
   112             this, SLOT(handleVideoStateChanged(CxeVideoCaptureControl::State,CxeError::Id)));
   114             this, SLOT(handleVideoStateChanged(CxeVideoCaptureControl::State,CxeError::Id)));
   113     connect(&(mEngine->settings()), SIGNAL(sceneChanged(CxeScene&)),
   115     connect(&(mEngine->settings()), SIGNAL(sceneChanged(CxeScene&)),
   114             this, SLOT(handleSceneChanged(CxeScene&)));
   116             this, SLOT(handleSceneChanged(CxeScene&)));
   272     }
   274     }
   273 
   275 
   274     // Initialize the video time counters.
   276     // Initialize the video time counters.
   275     updateTimeLabels();
   277     updateTimeLabels();
   276 
   278 
   277 
   279     // View is ready. Needed for startup performance automated testing.
       
   280     emit viewReady();
       
   281 
       
   282     CX_DEBUG_EXIT_FUNCTION();
       
   283 }
       
   284 
       
   285 /*!
       
   286  * Restore view state from activity.
       
   287  */
       
   288 void CxuiVideoPrecaptureView::restoreActivity(const QString &activityId, const QVariant &data)
       
   289 {
       
   290     Q_UNUSED(activityId);
       
   291     Q_UNUSED(data);
       
   292 
       
   293     CX_DEBUG_ENTER_FUNCTION();
       
   294     // no need to restore any state
       
   295     CX_DEBUG_EXIT_FUNCTION();
       
   296 }
       
   297 
       
   298 /*!
       
   299  * Save view state to activity.
       
   300  */
       
   301 void CxuiVideoPrecaptureView::saveActivity()
       
   302 {
       
   303     CX_DEBUG_ENTER_FUNCTION();
       
   304     QVariantMap data;
       
   305     QVariantHash params;
       
   306     //@todo: add pre-capture icon as screenshot
       
   307     mActivityManager->removeActivity(CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY);
       
   308     mActivityManager->addActivity(CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY, data, params);
       
   309     CX_DEBUG_EXIT_FUNCTION();
       
   310 }
       
   311 
       
   312 /*!
       
   313  * Clear activity from activity manager.
       
   314  */
       
   315 void CxuiVideoPrecaptureView::clearActivity()
       
   316 {
       
   317     CX_DEBUG_ENTER_FUNCTION();
       
   318     mActivityManager->removeActivity(CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY);
   278     CX_DEBUG_EXIT_FUNCTION();
   319     CX_DEBUG_EXIT_FUNCTION();
   279 }
   320 }
   280 
   321 
   281 /*!
   322 /*!
   282 * Initialize settings grid.
   323 * Initialize settings grid.
   300         action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::WHITE_BALANCE);
   341         action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::WHITE_BALANCE);
   301         action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE);
   342         action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE);
   302 
   343 
   303         connect(mCaptureKeyHandler, SIGNAL(autofocusKeyPressed()), mSettingsGrid, SLOT(close()));
   344         connect(mCaptureKeyHandler, SIGNAL(autofocusKeyPressed()), mSettingsGrid, SLOT(close()));
   304     }
   345     }
       
   346 }
       
   347 
       
   348 /**
       
   349 * Get if postcapture view should be shown or not.
       
   350 * Postcapture view may be shown for a predefined time or
       
   351 * until user dismisses it, or it may be completely disabled.
       
   352 */
       
   353 bool CxuiVideoPrecaptureView::isPostcaptureOn() const
       
   354 {
       
   355     CX_DEBUG_ENTER_FUNCTION();
       
   356     if (CxuiServiceProvider::isCameraEmbedded()) {
       
   357         // always show post capture in embedded mode
       
   358         CX_DEBUG_EXIT_FUNCTION();
       
   359         return true;
       
   360     }
       
   361 
       
   362     // Read the value from settings. Ignoring reading error.
       
   363     // On error (missing settings) default to "postcapture on".
       
   364     int showPostcapture(-1);
       
   365     if(mEngine) {
       
   366         mEngine->settings().get(CxeSettingIds::VIDEO_SHOWCAPTURED, showPostcapture);
       
   367     }
       
   368 
       
   369     CX_DEBUG_EXIT_FUNCTION();
       
   370     return showPostcapture != 0; // 0 == no postcapture
       
   371 }
       
   372 
       
   373 /*!
       
   374 * Update the scene mode icon.
       
   375 * @param sceneId The new scene id.
       
   376 */
       
   377 void CxuiVideoPrecaptureView::updateSceneIcon(const QString& sceneId)
       
   378 {
       
   379     CX_DEBUG_ENTER_FUNCTION();
       
   380 
       
   381     if (mEngine->mode() == Cxe::VideoMode) {
       
   382         CX_DEBUG(("CxuiPrecaptureView - scene: %s", sceneId.toAscii().constData()));
       
   383 
       
   384         // No need to update icon, if widgets are not even loaded yet.
       
   385         // We'll update the icon once the widgets are loaded.
       
   386         if (mWidgetsLoaded) {
       
   387             QString iconObjectName = VIDEO_PRE_CAPTURE_SCENE_MODE_ACTION;
       
   388             QString icon = getSettingItemIcon(CxeSettingIds::VIDEO_SCENE, sceneId);
       
   389 
       
   390             CX_DEBUG(("CxuiVideoPrecaptureView - icon: %s", icon.toAscii().constData()));
       
   391 
       
   392             if (mDocumentLoader) {
       
   393                 QObject *obj = mDocumentLoader->findObject(iconObjectName);
       
   394                 CX_DEBUG_ASSERT(obj);
       
   395                 qobject_cast<HbAction *>(obj)->setIcon(HbIcon(icon));
       
   396             }
       
   397         } else {
       
   398             CX_DEBUG(("CxuiVideoPrecaptureView - widgets not loaded yet, ignored!"));
       
   399         }
       
   400     }
       
   401     CX_DEBUG_EXIT_FUNCTION();
       
   402 }
       
   403 
       
   404 /*!
       
   405     Update the quality indicator
       
   406 */
       
   407 void CxuiVideoPrecaptureView::updateQualityIcon()
       
   408 {
       
   409     CX_DEBUG_ENTER_FUNCTION();
       
   410 
       
   411     if (mQualityIcon && mEngine) {
       
   412         QString icon = "";
       
   413         int currentValue = -1;
       
   414 
       
   415         mEngine->settings().get(CxeSettingIds::VIDEO_QUALITY, currentValue);
       
   416         icon = getSettingItemIcon(CxeSettingIds::VIDEO_QUALITY, currentValue);
       
   417 
       
   418         mQualityIcon->setIcon(HbIcon(icon));
       
   419     }
       
   420 
       
   421     CX_DEBUG_EXIT_FUNCTION();
   305 }
   422 }
   306 
   423 
   307 void CxuiVideoPrecaptureView::handleSnapshot(CxeError::Id /*error*/)
   424 void CxuiVideoPrecaptureView::handleSnapshot(CxeError::Id /*error*/)
   308 {
   425 {
   309     CX_DEBUG_ENTER_FUNCTION();
   426     CX_DEBUG_ENTER_FUNCTION();
   320 
   437 
   321     if (time) {
   438     if (time) {
   322         mMenu = takeMenu();
   439         mMenu = takeMenu();
   323         mVideoCaptureControl->record();
   440         mVideoCaptureControl->record();
   324     } else {
   441     } else {
   325         launchDiskFullNotification();
   442         emit errorEncountered(CxeError::DiskFull);
   326     }
   443     }
   327 
   444 
   328     CX_DEBUG_EXIT_FUNCTION();
   445     CX_DEBUG_EXIT_FUNCTION();
   329 }
   446 }
   330 
   447 
   369         show = (mEngine->isEngineReady()
   486         show = (mEngine->isEngineReady()
   370              || state == CxeVideoCaptureControl::Recording
   487              || state == CxeVideoCaptureControl::Recording
   371              || state == CxeVideoCaptureControl::Paused);
   488              || state == CxeVideoCaptureControl::Paused);
   372     }
   489     }
   373     return show;
   490     return show;
       
   491 }
       
   492 
       
   493 /*!
       
   494  * Play feedback when touching view outside of any widget?
       
   495  * If video is paused feedback is off.  Otherwise on.
       
   496  */
       
   497 bool CxuiVideoPrecaptureView::isFeedbackEnabled() const
       
   498 {
       
   499     CxeVideoCaptureControl::State state(mEngine->videoCaptureControl().state());
       
   500     if (state == CxeVideoCaptureControl::Paused) {
       
   501         return false;
       
   502     } else {
       
   503         return true;
       
   504     }
   374 }
   505 }
   375 
   506 
   376 // CxuiPrecaptureView::showToolbar()
   507 // CxuiPrecaptureView::showToolbar()
   377 // Shows toolbar. Calls the base class implementation if not recording
   508 // Shows toolbar. Calls the base class implementation if not recording
   378 // since toolbar is not shown during recording
   509 // since toolbar is not shown during recording
   568             record();
   699             record();
   569         }
   700         }
   570         break;
   701         break;
   571     case CxeVideoCaptureControl::Recording:
   702     case CxeVideoCaptureControl::Recording:
   572         hideControls();
   703         hideControls();
       
   704         emit stopStandbyTimer();
   573         if (mDocumentLoader){
   705         if (mDocumentLoader){
   574             mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_RECORDING);
   706             mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_RECORDING);
   575         }
   707         }
   576         mElapsedTimer.start(CXUI_ELAPSED_TIME_TIMEOUT);
   708         mElapsedTimer.start(CXUI_ELAPSED_TIME_TIMEOUT);
   577         disableFeedback();
   709         disableFeedback();
   602         //if (mRecordingAnimation && mRecordingIcon) {
   734         //if (mRecordingAnimation && mRecordingIcon) {
   603         //    mRecordingAnimation->stop();
   735         //    mRecordingAnimation->stop();
   604         //}
   736         //}
   605 
   737 
   606         enableFeedback();
   738         enableFeedback();
   607 
   739         emit startStandbyTimer();
   608         mElapsedTimer.stop();
   740         mElapsedTimer.stop();
   609         hideControls();
   741         hideControls();
   610 
   742 
   611         if (mMenu) {
   743         if (mMenu) {
   612             setMenu(mMenu);
   744             setMenu(mMenu);
   662     if (!error) {
   794     if (!error) {
   663         mEngine->initMode(Cxe::VideoMode);
   795         mEngine->initMode(Cxe::VideoMode);
   664         disconnect(mVideoCaptureControl, SIGNAL(videoComposed(CxeError::Id, const QString&)),
   796         disconnect(mVideoCaptureControl, SIGNAL(videoComposed(CxeError::Id, const QString&)),
   665                    this, SLOT(prepareNewVideo(CxeError::Id)));
   797                    this, SLOT(prepareNewVideo(CxeError::Id)));
   666     } else {
   798     } else {
   667         emit reportError(error);
   799         emit errorEncountered(error);
   668     }
   800     }
   669 
   801 
   670 }
       
   671 
       
   672 /**
       
   673 * Toggle video light on / off.
       
   674 */
       
   675 void CxuiVideoPrecaptureView::toggleLight()
       
   676 {
       
   677     launchNotSupportedNotification();
       
   678 }
   802 }
   679 
   803 
   680 void CxuiVideoPrecaptureView::handleQuitClicked()
   804 void CxuiVideoPrecaptureView::handleQuitClicked()
   681 {
   805 {
   682     CX_DEBUG_ENTER_FUNCTION();
   806     CX_DEBUG_ENTER_FUNCTION();
   693 
   817 
   694     QCoreApplication::exit();
   818     QCoreApplication::exit();
   695 
   819 
   696     CX_DEBUG_EXIT_FUNCTION();
   820     CX_DEBUG_EXIT_FUNCTION();
   697 }
   821 }
   698 
       
   699 void CxuiVideoPrecaptureView::handleFocusLost()
       
   700 {
       
   701     CX_DEBUG_IN_FUNCTION();
       
   702     // Release camera. Stopping possibly ongoing recording is handled by engine.
       
   703     releaseCamera();
       
   704 }
       
   705 
       
   706 void CxuiVideoPrecaptureView::handleBatteryEmpty()
       
   707 {
       
   708     CX_DEBUG_ENTER_FUNCTION();
       
   709 
       
   710     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   711     if (state == CxeVideoCaptureControl::Recording){
       
   712         stop(); // delete recording icon
       
   713     }
       
   714     CX_DEBUG_EXIT_FUNCTION();
       
   715 }
       
   716 
       
   717 
   822 
   718 void CxuiVideoPrecaptureView::launchVideoScenePopup()
   823 void CxuiVideoPrecaptureView::launchVideoScenePopup()
   719 {
   824 {
   720     CX_DEBUG_ENTER_FUNCTION();
   825     CX_DEBUG_ENTER_FUNCTION();
   721     hideControls();
   826     hideControls();
   820     }
   925     }
   821     return CxuiPrecaptureView::eventFilter(object, event);
   926     return CxuiPrecaptureView::eventFilter(object, event);
   822 }
   927 }
   823 
   928 
   824 //end of file
   929 //end of file
       
   930