camerauis/cameraxui/cxui/src/cxuipostcaptureview.cpp
changeset 46 c826656d6714
parent 42 feebad15db8c
child 58 ddba9caa7f32
equal deleted inserted replaced
42:feebad15db8c 46:c826656d6714
    29 #include <hbtoolbar.h>
    29 #include <hbtoolbar.h>
    30 #include <hbaction.h>
    30 #include <hbaction.h>
    31 #include <hbmessagebox.h>
    31 #include <hbmessagebox.h>
    32 #include <hbactivitymanager.h>
    32 #include <hbactivitymanager.h>
    33 
    33 
       
    34 #include <xqaiwdecl.h>
    34 #include <shareui.h>
    35 #include <shareui.h>
    35 #include <thumbnailmanager_qt.h>
    36 #include <thumbnailmanager_qt.h>
    36 
    37 
    37 #include "cxeviewfindercontrol.h"
    38 #include "cxeviewfindercontrol.h"
    38 #include "cxuienums.h"
    39 #include "cxuienums.h"
   215     stopTimers();
   216     stopTimers();
   216     releaseCamera();
   217     releaseCamera();
   217 
   218 
   218     QString videoFile(getCurrentFilename());
   219     QString videoFile(getCurrentFilename());
   219 
   220 
   220     XQAiwRequest *videoRequest = mAppManager.create(
   221     XQAiwRequest *videoRequest = mAppManager.create(XQI_VIDEO_PLAY, XQOP_VIDEO_PLAY, true);
   221         "com.nokia.symbian.IVideoView","playMedia(QString)", true);
       
   222 
   222 
   223     if (videoRequest) {
   223     if (videoRequest) {
   224         QVariantList fileList;
   224         QVariantList fileList;
   225         fileList.append(QVariant(videoFile));
   225         fileList.append(QVariant(videoFile));
   226         videoRequest->setArguments(fileList);
   226         videoRequest->setArguments(fileList);
   228         CX_DEBUG(("CxuiPostcaptureView: sending request"));
   228         CX_DEBUG(("CxuiPostcaptureView: sending request"));
   229         QVariant result;
   229         QVariant result;
   230         bool res = videoRequest->send(result);
   230         bool res = videoRequest->send(result);
   231         if (res) {
   231         if (res) {
   232             CX_DEBUG(("CxuiPostcaptureView: request sent, received \"%s\"",
   232             CX_DEBUG(("CxuiPostcaptureView: request sent, received \"%s\"",
   233                       result.toString().toAscii().constData()));
   233                       qPrintable(result.toString())));
   234         } else {
   234         } else {
   235             CX_DEBUG(("CxuiPostcaptureView: request sending failed, error=%d",
   235             CX_DEBUG(("CxuiPostcaptureView: request sending failed, error=%d",
   236                       videoRequest->lastError()));
   236                       videoRequest->lastError()));
   237         }
   237         }
   238         delete videoRequest;
   238         delete videoRequest;
   276     hideControls();
   276     hideControls();
   277     mDeleteNoteOpen = false;
   277     mDeleteNoteOpen = false;
   278 
   278 
   279     // Check that user confirmed delete
   279     // Check that user confirmed delete
   280     if (action == HbMessageBox::Yes) {
   280     if (action == HbMessageBox::Yes) {
   281         QString filename = getCurrentFilename();
   281         QFileInfo fileInfo(getCurrentFilename());
   282         QFileInfo fileInfo(filename);
       
   283         if (fileInfo.exists()) {
   282         if (fileInfo.exists()) {
   284             //! @todo
   283             //! @todo
   285             // We can retry deletion if file deletion does'nt succeed,
   284             // We can retry deletion if file deletion does'nt succeed,
   286             // but this is left out for the time being since the user
   285             // but this is left out for the time being since the user
   287             // can't delete it so early that it's not saved yet or
   286             // can't delete it so early that it's not saved yet or
   405 * Paint method.
   404 * Paint method.
   406 * Used for performance tracing purposes.
   405 * Used for performance tracing purposes.
   407 */
   406 */
   408 void CxuiPostcaptureView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
   407 void CxuiPostcaptureView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
   409 {
   408 {
   410     OstTrace0(camerax_performance, CXUIPOSTCAPTUREVIEW_SNAPSHOT_DRAW, "msg: e_CX_SHOT_TO_SNAPSHOT 0");
   409     // Performance trace for checking shot to snapshot time.
       
   410     // Guard that we actually have the snapshot set before outputting the trace.
       
   411     if (mImageLabel && !mImageLabel->icon().isNull()) {
       
   412         OstTrace0(camerax_performance, CXUIPOSTCAPTUREVIEW_SNAPSHOT_DRAW, "msg: e_CX_SHOT_TO_SNAPSHOT 0");
       
   413     }
       
   414 
   411     QGraphicsWidget::paint(painter, option, widget);
   415     QGraphicsWidget::paint(painter, option, widget);
   412 }
   416 }
   413 
   417 
   414 /*!
   418 /*!
   415  * Restore view state from activity.
   419  * Restore view state from activity.
   422     CX_DEBUG_ENTER_FUNCTION();
   426     CX_DEBUG_ENTER_FUNCTION();
   423 
   427 
   424     // get filename. if filename is not found (toString() returns empty string)
   428     // get filename. if filename is not found (toString() returns empty string)
   425     // we will go back to pre-capture in updateSnapshotImage()
   429     // we will go back to pre-capture in updateSnapshotImage()
   426     mFilename = data.toMap()[FILENAME_KEY].toString();
   430     mFilename = data.toMap()[FILENAME_KEY].toString();
   427     CX_DEBUG(("Got filename %s from activity", mFilename.toAscii().data()));
   431     CX_DEBUG(("Got filename [%s] from activity", qPrintable(mFilename)));
   428 
   432 
   429     CX_DEBUG_EXIT_FUNCTION();
   433     CX_DEBUG_EXIT_FUNCTION();
   430 }
   434 }
   431 
   435 
   432 /*!
   436 /*!
   437     CX_DEBUG_ENTER_FUNCTION();
   441     CX_DEBUG_ENTER_FUNCTION();
   438     QVariantMap data;
   442     QVariantMap data;
   439     QVariantHash params;
   443     QVariantHash params;
   440 
   444 
   441     QString filename = getCurrentFilename();
   445     QString filename = getCurrentFilename();
   442     CX_DEBUG(("Saving filename %s", filename.toAscii().data()));
   446     CX_DEBUG(("Saving filename [%s]", qPrintable(filename)));
   443     data.insert(FILENAME_KEY, filename);
   447     data.insert(FILENAME_KEY, filename);
   444 
   448 
   445     QImage img(mMainWindow->rect().size(), QImage::Format_ARGB32_Premultiplied);
   449     QImage img(mMainWindow->rect().size(), QImage::Format_ARGB32_Premultiplied);
   446     QPainter p(&img);
   450     QPainter p(&img);
   447     mMainWindow->render(&p, mMainWindow->rect(), mMainWindow->rect());
   451     mMainWindow->render(&p, mMainWindow->rect(), mMainWindow->rect());
   481     QGraphicsWidget::showEvent(event);
   485     QGraphicsWidget::showEvent(event);
   482 
   486 
   483     if (event->type() == QEvent::Show) {
   487     if (event->type() == QEvent::Show) {
   484         QCoreApplication::instance()->installEventFilter(this);
   488         QCoreApplication::instance()->installEventFilter(this);
   485 
   489 
       
   490         // Update snapshot for current file.
       
   491         // If the current file does not exist anymore, return to pre-capture view.
   486         updateSnapshotImage();
   492         updateSnapshotImage();
   487         showControls();
   493 
   488         startTimers();
   494         // If the image / video has been deleted, control returned to pre-capture view.
       
   495         // No point to start timers or show controls then.
       
   496         if (mMainWindow->currentView() == this) {
       
   497             showControls();
       
   498             startTimers();
       
   499         }
       
   500 
   489         event->accept();
   501         event->accept();
   490     }
   502     }
   491 
   503 
   492     CX_DEBUG_EXIT_FUNCTION();
   504     CX_DEBUG_EXIT_FUNCTION();
   493 }
   505 }
   571  */
   583  */
   572 void CxuiPostcaptureView::updateSnapshotImage()
   584 void CxuiPostcaptureView::updateSnapshotImage()
   573 {
   585 {
   574     CX_DEBUG_ENTER_FUNCTION();
   586     CX_DEBUG_ENTER_FUNCTION();
   575 
   587 
   576     if (!mFilename.isNull()) {
   588     if (isFileDeleted()) {
   577         CX_DEBUG(("CxuiPostcaptureView::updateSnapshot restoring activity"));
   589         // File deleted, go to pre-capture view.
       
   590         CX_DEBUG(("File has been deleted, going back to pre-capture"));
       
   591         goToPrecaptureView();
       
   592 
       
   593     } else if (!mFilename.isNull()) {
   578         // filename set, we are restoring activity
   594         // filename set, we are restoring activity
   579         if (QFile::exists(mFilename)) {
   595         if (!mThumbnailManager) {
   580             CX_DEBUG(("Filename ok, requesting thumbnail from TNM"));
   596             mThumbnailManager = new ThumbnailManager();
   581             if (!mThumbnailManager) {
   597             connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)),
   582                 mThumbnailManager = new ThumbnailManager();
   598                     this, SLOT(handleThumbnailReady(QPixmap)));
   583                 connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)),
   599             mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
   584                                                 this, SLOT(handleThumbnailReady(QPixmap, void*, int, int)));
       
   585                 mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
       
   586             }
       
   587             mThumbnailManager->getThumbnail(mFilename);
       
   588             CX_DEBUG(("Thumbnail requested"));
       
   589 
       
   590         } else {
       
   591             // file deleted
       
   592             CX_DEBUG(("File %s has been deleted, going back to pre-capture", mFilename.toAscii().data()));
       
   593             goToPrecaptureView();
       
   594         }
   600         }
       
   601         mThumbnailManager->getThumbnail(mFilename);
       
   602         CX_DEBUG(("Thumbnail requested"));
       
   603 
   595     } else {
   604     } else {
       
   605         // Normal use of post-capture view
   596         QPixmap snapshot;
   606         QPixmap snapshot;
   597         if (mEngine->mode() == ImageMode) {
   607         if (mEngine->mode() == ImageMode) {
   598             if( mEngine->stillCaptureControl().imageCount() > 0 ) {
   608 
       
   609             if (mEngine->stillCaptureControl().imageCount() > 0) {
   599                 snapshot = mEngine->stillCaptureControl()[0].snapshot();
   610                 snapshot = mEngine->stillCaptureControl()[0].snapshot();
   600             }
   611             }
   601         } else {
   612         } else {
   602             snapshot = mEngine->videoCaptureControl().snapshot();
   613             snapshot = mEngine->videoCaptureControl().snapshot();
   603         }
   614         }
   604         if (mImageLabel) {
   615 
   605                 mImageLabel->setIcon(HbIcon(QIcon(snapshot)));
   616         // Update the snapshot image
   606             } else {
   617         handleThumbnailReady(snapshot);
   607                 // do nothing
   618     }
       
   619 
       
   620     CX_DEBUG_EXIT_FUNCTION();
       
   621 }
       
   622 
       
   623 /*!
       
   624 * Check if the file we show this post-capture view for is deleted.
       
   625 * This can happen e.g. if we send camera to background and delete
       
   626 * the file in other application. When used as activity, we may also
       
   627 * get the name of already deleted file as activity parameter.
       
   628 * @return True if the current file is deleted, false if not.
       
   629 */
       
   630 bool CxuiPostcaptureView::isFileDeleted()
       
   631 {
       
   632     CX_DEBUG_ENTER_FUNCTION();
       
   633 
       
   634     bool deleted(false);
       
   635 
       
   636     // Check how we entered this view.
       
   637     if (mFilename.isNull()) {
       
   638         CX_DEBUG(("Checking engine filename"));
       
   639         // Normally entered post-capture view.
       
   640         if (mEngine->mode() == ImageMode) {
       
   641             // Check that the image have been saved already.
       
   642             // If not, it cannot have been deleted in that case.
       
   643             CxeStillImage &image(mEngine->stillCaptureControl()[0]);
       
   644             CX_DEBUG(("Image filename [%s]", qPrintable(image.filename())));
       
   645             CX_DEBUG(("Image file saved: %d exists: %d", image.saved(), QFile::exists(image.filename())));
       
   646             deleted = image.saved() && !QFile::exists(image.filename());
       
   647         } else {
       
   648             // Check that video has been stopped fully.
       
   649             // If it's still stopping, QFile may not work.
       
   650             CX_DEBUG(("Video filename [%s]", qPrintable(mEngine->videoCaptureControl().filename())));
       
   651             deleted = mEngine->videoCaptureControl().state() != CxeVideoCaptureControl::Stopping
       
   652                    && !QFile::exists(mEngine->videoCaptureControl().filename());
   608         }
   653         }
   609     }
   654     } else {
   610 
   655         // Started as activity, check the filename given when restoring activity.
   611     CX_DEBUG_EXIT_FUNCTION();
   656         CX_DEBUG(("Checking filename saved in activity"));
       
   657         deleted = !QFile::exists(mFilename);
       
   658     }
       
   659 
       
   660     CX_DEBUG_EXIT_FUNCTION();
       
   661     return deleted;
   612 }
   662 }
   613 
   663 
   614 /* !
   664 /* !
   615  * gets the filename of the current file
   665  * gets the filename of the current file
   616  */
   666  */
   617 QString CxuiPostcaptureView::getCurrentFilename()
   667 QString CxuiPostcaptureView::getCurrentFilename()
   618 {
   668 {
   619     CX_DEBUG_ENTER_FUNCTION();
   669     CX_DEBUG_ENTER_FUNCTION();
       
   670     QString filename;
   620 
   671 
   621     if (!mFilename.isNull()) {
   672     if (!mFilename.isNull()) {
   622         // post-capture started by activity, engine doesn't contain correct
   673         // post-capture started by activity, engine doesn't contain correct
   623         // filename anymore so use the stored one
   674         // filename anymore so use the stored one
   624         CX_DEBUG(("Using filename saved in activity"));
   675         CX_DEBUG(("Using filename saved in activity"));
   625         CX_DEBUG_EXIT_FUNCTION();
   676         filename = mFilename;
   626         return mFilename;
       
   627     }
       
   628 
       
   629     CX_DEBUG(("Getting filename from engine"));
       
   630     QString filename;
       
   631 
       
   632     if (mEngine->mode() == Cxe::VideoMode) {
       
   633         filename = mEngine->videoCaptureControl().filename();
       
   634     } else {
   677     } else {
   635         //!@todo Currently only gets index 0 from the still capture control.
   678         CX_DEBUG(("Getting filename from engine"));
   636         CxeStillCaptureControl& stillCaptureControl = mEngine->stillCaptureControl();
   679         if (mEngine->mode() == Cxe::VideoMode) {
   637         if (stillCaptureControl.imageCount()) {
   680             filename = mEngine->videoCaptureControl().filename();
   638             filename = stillCaptureControl[0].filename();
   681         } else {
       
   682             //!@todo Currently only gets index 0 from the still capture control.
       
   683             CxeStillCaptureControl& stillCaptureControl = mEngine->stillCaptureControl();
       
   684             if (stillCaptureControl.imageCount() > 0) {
       
   685                 filename = stillCaptureControl[0].filename();
       
   686             }
   639         }
   687         }
   640     }
   688     }
   641     CX_DEBUG((filename.toAscii()));
   689 
   642 
   690     CX_DEBUG(("Got filename [%s]", qPrintable(filename)));
   643     CX_DEBUG_EXIT_FUNCTION();
   691     CX_DEBUG_EXIT_FUNCTION();
   644 
   692 
   645     return filename;
   693     return filename;
   646 }
   694 }
   647 
   695 
   667     CX_DEBUG_ENTER_FUNCTION();
   715     CX_DEBUG_ENTER_FUNCTION();
   668 
   716 
   669     // Common functionality first.
   717     // Common functionality first.
   670     CxuiView::exitStandby();
   718     CxuiView::exitStandby();
   671 
   719 
   672     //!@note We should not start timers until we receive the ShowEvent
   720     // Update snapshot and check the current file is not deleted.
   673     showControls();
   721     updateSnapshotImage();
       
   722 
       
   723     if (mMainWindow->currentView() == this) {
       
   724         showControls();
       
   725     }
   674 
   726 
   675     CX_DEBUG_EXIT_FUNCTION();
   727     CX_DEBUG_EXIT_FUNCTION();
   676 }
   728 }
   677 
   729 
   678 /*!
   730 /*!
   693 
   745 
   694 /*!
   746 /*!
   695  * Handle thumbnail received from ThumbnailManager.
   747  * Handle thumbnail received from ThumbnailManager.
   696  *
   748  *
   697  * @param thumbnail Thumbnail as QPixmap
   749  * @param thumbnail Thumbnail as QPixmap
   698  * @param clientData Not used
   750  */
   699  * @param id Thumbnail manager request id
   751 void CxuiPostcaptureView::handleThumbnailReady(QPixmap thumbnail)
   700  * @param errorCode Error code
   752 {
   701  */
   753     CX_DEBUG_ENTER_FUNCTION();
   702 void CxuiPostcaptureView::handleThumbnailReady(QPixmap thumbnail, void *clientData, int id, int errorCode)
       
   703 {
       
   704     CX_DEBUG_ENTER_FUNCTION();
       
   705 
       
   706     Q_UNUSED(clientData);
       
   707     Q_UNUSED(id);
       
   708 
   754 
   709     if (thumbnail.isNull()) {
   755     if (thumbnail.isNull()) {
   710         CX_DEBUG(("Received null thumbnail from TNM, going to pre-capture. Error=%d", errorCode));
   756         CX_DEBUG(("[WARNING] Received null thumbnail from TNM, going to pre-capture."));
   711         // null thumbnail, go to precapture
   757         // null thumbnail, go to precapture
   712         goToPrecaptureView();
   758         goToPrecaptureView();
   713     } else if (mImageLabel) {
   759     } else if (mImageLabel) {
   714         mImageLabel->setIcon(HbIcon(QIcon(thumbnail)));
   760         mImageLabel->setIcon(HbIcon(QIcon(thumbnail)));
   715     }
   761     }
   755     } else {
   801     } else {
   756         settingId = CxeSettingIds::VIDEO_SHOWCAPTURED;
   802         settingId = CxeSettingIds::VIDEO_SHOWCAPTURED;
   757     }
   803     }
   758 
   804 
   759     if (!CxuiServiceProvider::isCameraEmbedded()) {
   805     if (!CxuiServiceProvider::isCameraEmbedded()) {
   760         CxeError::Id err = mEngine->settings().get(settingId, postCaptureTimeout);
   806         postCaptureTimeout = mEngine->settings().get<int>(settingId, 0);
   761 
   807 
   762         if (postCaptureTimeout > 0 && err == CxeError::None) {
   808         if (postCaptureTimeout > 0) {
   763             mPostcaptureTimer.start(postCaptureTimeout);
   809             mPostcaptureTimer.start(postCaptureTimeout);
   764         } else {
   810         } else {
   765             // do nothing
   811             // do nothing
   766         }
   812         }
   767     }
   813     }