camerauis/cameraxui/cxui/src/cxuipostcaptureview.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
child 45 24fd82631616
--- a/camerauis/cameraxui/cxui/src/cxuipostcaptureview.cpp	Thu May 13 21:30:19 2010 +0300
+++ b/camerauis/cameraxui/cxui/src/cxuipostcaptureview.cpp	Thu Jul 15 01:55:05 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -17,7 +17,6 @@
 #include <QDebug>
 #include <QPixmap>
 #include <QTimer>
-#include <QGraphicsSceneEvent>
 #include <QFileInfo>
 #include <QApplication>
 #include <QGraphicsRectItem>
@@ -30,9 +29,10 @@
 #include <hbtoolbar.h>
 #include <hbaction.h>
 #include <hbmessagebox.h>
-#include <hbnotificationdialog.h>
+#include <hbactivitymanager.h>
 
 #include <shareui.h>
+#include <thumbnailmanager_qt.h>
 
 #include "cxeviewfindercontrol.h"
 #include "cxuienums.h"
@@ -40,7 +40,6 @@
 #include "cxeengine.h"
 #include "cxecameradevicecontrol.h"
 #include "cxestillcapturecontrol.h"
-#include "cxeviewfindercontrol.h"
 #include "cxevideocapturecontrol.h"
 #include "cxestillimage.h"
 #include "cxutils.h"
@@ -50,75 +49,74 @@
 #include "cxenamespace.h"
 #include "cxuiserviceprovider.h"
 
+#ifdef Q_OS_SYMBIAN
 #include "OstTraceDefinitions.h"
 #ifdef OST_TRACE_COMPILER_IN_USE
 #include "cxuipostcaptureviewTraces.h"
 #endif
+#endif //Q_OS_SYMBIAN
 
 
 using namespace CxUiLayout;
 using namespace Cxe;
 
-// CONSTANTS
-const int CXUI_HIDE_CONTROLS_TIMEOUT = 6000; // 6 seconds
-const QString PhotosAppExe = "photos.exe";
-const QString VideosAppExe = "videoplayer.exe";
 
-//!@todo Temporarily disabled.
-//const int CXUI_STOP_VIEWFINDER_TIMEOUT = 5000; // 5 seconds
-//const int CXUI_RELEASE_CAMERA_TIMEOUT = 10000; // 10 seconds
+namespace {
+    const QString FILENAME_KEY = "filename";
+    const int CXUI_STOP_VIEWFINDER_TIMEOUT = 5000; //  5 seconds
+    const int CXUI_RELEASE_CAMERA_TIMEOUT = 60000; // 60 seconds
+}
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::CxuiPostcaptureView
-//
-// ---------------------------------------------------------------------------
-//
+
+/*!
+* Constructor.
+*/
 CxuiPostcaptureView::CxuiPostcaptureView(QGraphicsItem *parent) :
-    HbView(parent),
-    mMainWindow(NULL),
-    mEngine(NULL),
+    CxuiView(parent),
     mStillToolbar(NULL),
     mVideoToolbar(NULL),
     mEmbeddedToolbar(NULL),
     mBackgroundItem(NULL),
     mImageLabel(NULL),
-    mHideControlsTimeout(this),
+    mShareUi(NULL),
     mStopViewfinderTimer(this),
     mReleaseCameraTimer(this),
     mPostcaptureTimer(this),
-    mTimersStarted(false)
+    mTimersStarted(false),
+    mDeleteNoteOpen(false),
+    mFilename(QString::null),
+    mThumbnailManager(NULL)
 {
     CX_DEBUG_IN_FUNCTION();
 
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::~CxuiPostcaptureView
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+* Destructor.
+*/
 CxuiPostcaptureView::~CxuiPostcaptureView()
 {
     CX_DEBUG_ENTER_FUNCTION();
     QCoreApplication::instance()->removeEventFilter(this);
     stopTimers();
+    delete mThumbnailManager;
+    delete mShareUi;
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::construct
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+* Second phase construction.
+*/
 void CxuiPostcaptureView::construct(HbMainWindow *mainwindow, CxeEngine *engine,
-                                    CxuiDocumentLoader *documentLoader)
+                                    CxuiDocumentLoader *documentLoader,
+                                    CxuiCaptureKeyHandler *keyHandler,
+                                    HbActivityManager *activityManager)
 {
+    Q_UNUSED(keyHandler);
     CX_DEBUG_ENTER_FUNCTION();
 
-    mMainWindow = mainwindow;
-    mEngine = engine;
-    mDocumentLoader = documentLoader;
+    CxuiView::construct(mainwindow, engine, documentLoader, NULL, activityManager);
 
     // set back action to go back to pre-capture
     HbAction *backAction = new HbAction(Hb::BackNaviAction, this);
@@ -134,6 +132,8 @@
     mImageLabel = qobject_cast<HbLabel *>(widget);
     CX_DEBUG_ASSERT(mImageLabel);
 
+    mShareUi = new ShareUi();
+
     // get toolbar pointers from the documentloader
     widget = mDocumentLoader->findWidget(STILL_POST_CAPTURE_TOOLBAR);
     // This resize is a workaround to get toolbar shown correctly.
@@ -177,30 +177,30 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::handleCaptureKeyPressed
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+* Handle pressing capture key.
+*/
 void CxuiPostcaptureView::handleCaptureKeyPressed()
 {
     CX_DEBUG_ENTER_FUNCTION();
 
-    goToPrecaptureView();
+    if (!mDeleteNoteOpen) {
+        goToPrecaptureView();
+    }
 
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::handleAutofocusKeyPressed
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+* Handle pressing auto focus key.
+*/
 void CxuiPostcaptureView::handleAutofocusKeyPressed()
 {
     CX_DEBUG_ENTER_FUNCTION();
 
-    goToPrecaptureView();
+    if (!mDeleteNoteOpen) {
+        goToPrecaptureView();
+    }
 
     CX_DEBUG_EXIT_FUNCTION();
 }
@@ -210,53 +210,74 @@
  */
 void CxuiPostcaptureView::playVideo()
 {
+    CX_DEBUG_ENTER_FUNCTION();
 
-    launchNotSupportedNotification();
-    //! @todo needs an implementation
-    CX_DEBUG_IN_FUNCTION();
+    stopTimers();
+    releaseCamera();
+
+    QString videoFile(getCurrentFilename());
+
+    XQAiwRequest *videoRequest = mAppManager.create(
+        "com.nokia.symbian.IVideoView","playMedia(QString)", true);
+
+    if (videoRequest) {
+        QVariantList fileList;
+        fileList.append(QVariant(videoFile));
+        videoRequest->setArguments(fileList);
+
+        CX_DEBUG(("CxuiPostcaptureView: sending request"));
+        QVariant result;
+        bool res = videoRequest->send(result);
+        if (res) {
+            CX_DEBUG(("CxuiPostcaptureView: request sent, received \"%s\"",
+                      result.toString().toAscii().constData()));
+        } else {
+            CX_DEBUG(("CxuiPostcaptureView: request sending failed, error=%d",
+                      videoRequest->lastError()));
+        }
+        delete videoRequest;
+        videoRequest = NULL;
+    }
+
+    CX_DEBUG_EXIT_FUNCTION();
 
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::showDeleteNote
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+* Show delete query.
+*/
 void CxuiPostcaptureView::showDeleteNote()
 {
     CX_DEBUG_ENTER_FUNCTION();
 
     hideControls();
 
-    if (mEngine->mode() == Cxe::VideoMode) {
-        HbMessageBox::question(hbTrId("txt_cam_other_delete_video_clip"),
-                               this,
-                               SLOT(handleDeleteDialogClosed(HbAction*)));
-    } else {
-        HbMessageBox::question(hbTrId("txt_cam_other_delete_image"),
-                               this,
-                               SLOT(handleDeleteDialogClosed(HbAction*)));
-    }
+    QString text(mEngine->mode() == Cxe::VideoMode
+               ? hbTrId("txt_cam_other_delete_video_clip")
+               : hbTrId("txt_cam_other_delete_image"));
 
+    HbMessageBox::question(text,
+                           this,
+                           SLOT(handleDeleteDialogClosed(int)),
+                           HbMessageBox::Yes | HbMessageBox::No);
+
+    mDeleteNoteOpen = true;
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::handleDeleteDialogClosed
-//
-// ---------------------------------------------------------------------------
-//
-void CxuiPostcaptureView::handleDeleteDialogClosed(HbAction *action)
+/*!
+* Handle closing delete query dialog.
+* @param action HbMessageBox::Yes if user accepted the delete query, HbMessageBox::No if not.
+*/
+void CxuiPostcaptureView::handleDeleteDialogClosed(int action)
 {
     CX_DEBUG_ENTER_FUNCTION();
 
     hideControls();
-
-    HbMessageBox *dlg = qobject_cast<HbMessageBox*>(sender());
+    mDeleteNoteOpen = false;
 
-    // check that it was "primary action" that closed the dialog
-    if (dlg && dlg->actions().at(0) == action) {
-        // User confirmed delete
+    // Check that user confirmed delete
+    if (action == HbMessageBox::Yes) {
         QString filename = getCurrentFilename();
         QFileInfo fileInfo(filename);
         if (fileInfo.exists()) {
@@ -267,7 +288,7 @@
             // is being harvested by MdS etc.
             QDir dir = fileInfo.absolutePath();
             bool ok = dir.remove(fileInfo.fileName());
-            CX_DEBUG(("Delete file [%s], status %d", fileInfo.fileName().toAscii().constData(), ok));
+            CX_DEBUG(("Delete file [%s], status %d", qPrintable(fileInfo.fileName()), ok));
 
             // Go back to precapture view
             goToPrecaptureView();
@@ -287,25 +308,19 @@
 
     stopTimers();
     releaseCamera();
-
+    hideControls();
     QString filename = getCurrentFilename();
-
     QStringList filelist;
     filelist.append(filename);
 
-    ShareUi dialog;
-    dialog.send(filelist, true);
-
-    showControls();
+    mShareUi->send(filelist, true);
 
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::goToPrecaptureView
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+* Go to pre-capture view.
+*/
 void CxuiPostcaptureView::goToPrecaptureView()
 {
     CX_DEBUG_ENTER_FUNCTION();
@@ -317,8 +332,8 @@
         // Re-enabling starting timers the next time we enter post capture view.
         mTimersStarted = false;
 
-        // Make sure engine prepares for new image/video if necessary
-        mEngine->initMode(mEngine->mode());
+        // reset saved filename
+        mFilename = QString::null;
 
         // Switch to pre-capture view
         emit changeToPrecaptureView();
@@ -327,11 +342,9 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::stopViewfinder
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+* Stop viewfinder.
+*/
 void CxuiPostcaptureView::stopViewfinder()
 {
     CX_DEBUG_ENTER_FUNCTION();
@@ -344,32 +357,12 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::releaseCamera
-//
-// ---------------------------------------------------------------------------
-//
-void CxuiPostcaptureView::releaseCamera()
+/*!
+* Hides toolbar.
+*/
+void CxuiPostcaptureView::hideToolbar()
 {
     CX_DEBUG_ENTER_FUNCTION();
-
-    if (mMainWindow->currentView() == this) {
-        mEngine->cameraDeviceControl().release();
-    }
-    mReleaseCameraTimer.stop();
-
-    CX_DEBUG_EXIT_FUNCTION();
-}
-
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::hideControls
-//
-// ---------------------------------------------------------------------------
-//
-void CxuiPostcaptureView::hideControls()
-{
-    CX_DEBUG_ENTER_FUNCTION();
-
     if (mStillToolbar) {
         mStillToolbar->hide();
     }
@@ -379,64 +372,13 @@
     if (mEmbeddedToolbar) {
         mEmbeddedToolbar->hide();
     }
-
-    hideItems(Hb::AllItems);
-
-    mControlsVisible = false;
-
-    // stop hiding control timer
-    mHideControlsTimeout.stop();
-
-
-    // give the keyboard focus back to the view
-    // for the view to receive key events
-    setFocus();
-
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::showControls
-//
-// ---------------------------------------------------------------------------
-//
-void CxuiPostcaptureView::showControls()
-{
-    CX_DEBUG_ENTER_FUNCTION();
-
-    showToolbar();
-
-    showItems(Hb::AllItems);
-
-    mHideControlsTimeout.start(CXUI_HIDE_CONTROLS_TIMEOUT);
-    mControlsVisible = true;
-
-    CX_DEBUG_EXIT_FUNCTION();
-}
-
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::toggleControls
-//
-// ---------------------------------------------------------------------------
-//
-void CxuiPostcaptureView::toggleControls()
-{
-    CX_DEBUG_ENTER_FUNCTION();
-
-    if (mControlsVisible) {
-        hideControls();
-    } else {
-        showControls();
-    }
-
-    CX_DEBUG_EXIT_FUNCTION();
-}
-
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::eventFilter
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+* Handle events.
+* Needed for restarting timers.
+*/
 bool CxuiPostcaptureView::eventFilter(QObject *object, QEvent *event)
 {
     Q_UNUSED(object)
@@ -465,31 +407,73 @@
 */
 void CxuiPostcaptureView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 {
-        OstTrace0(camerax_performance, CXUIPOSTCAPTUREVIEW_SNAPSHOT_DRAW, "msg: e_CX_SHOT_TO_SNAPSHOT 0");
-        QGraphicsWidget::paint(painter, option, widget);
+    OstTrace0(camerax_performance, CXUIPOSTCAPTUREVIEW_SNAPSHOT_DRAW, "msg: e_CX_SHOT_TO_SNAPSHOT 0");
+    QGraphicsWidget::paint(painter, option, widget);
+}
+
+/*!
+ * Restore view state from activity.
+ * @param activityId Activity id
+ * @param data Activity data
+ */
+void CxuiPostcaptureView::restoreActivity(const QString &activityId, const QVariant &data)
+{
+    Q_UNUSED(activityId);
+    CX_DEBUG_ENTER_FUNCTION();
+
+    // get filename. if filename is not found (toString() returns empty string)
+    // we will go back to pre-capture in updateSnapshotImage()
+    mFilename = data.toMap()[FILENAME_KEY].toString();
+    CX_DEBUG(("Got filename %s from activity", mFilename.toAscii().data()));
+
+    CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::mousePressEvent
-//
-// ---------------------------------------------------------------------------
-//
-void CxuiPostcaptureView::mousePressEvent(QGraphicsSceneMouseEvent *event)
+/*!
+ * Save view state to activity.
+ */
+void CxuiPostcaptureView::saveActivity()
 {
-    //! @todo temporary workaround for title bar mouse event handling bug
-    if (event->type() == QEvent::GraphicsSceneMousePress && event->scenePos().y() > 70) {
-        mPostcaptureTimer.stop();
-        toggleControls();
-        event->accept();
+    CX_DEBUG_ENTER_FUNCTION();
+    QVariantMap data;
+    QVariantHash params;
+
+    QString filename = getCurrentFilename();
+    CX_DEBUG(("Saving filename %s", filename.toAscii().data()));
+    data.insert(FILENAME_KEY, filename);
+
+    QImage img(mMainWindow->rect().size(), QImage::Format_ARGB32_Premultiplied);
+    QPainter p(&img);
+    mMainWindow->render(&p, mMainWindow->rect(), mMainWindow->rect());
+
+    QPixmap screenshot = QPixmap::fromImage(img);
+
+    params.insert("screenshot", screenshot);
+    if (mEngine->mode() == Cxe::ImageMode) {
+        mActivityManager->removeActivity(CxuiActivityIds::STILL_POSTCAPTURE_ACTIVITY);
+        mActivityManager->addActivity(CxuiActivityIds::STILL_POSTCAPTURE_ACTIVITY, data, params);
+    } else {
+        mActivityManager->removeActivity(CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY);
+        mActivityManager->addActivity(CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY, data, params);
     }
-
+    CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::showEvent
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+ * Clear activity from activity manager.
+ */
+void CxuiPostcaptureView::clearActivity()
+{
+    CX_DEBUG_ENTER_FUNCTION();
+    mActivityManager->removeActivity(CxuiActivityIds::STILL_POSTCAPTURE_ACTIVITY);
+    mActivityManager->removeActivity(CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY);
+    CX_DEBUG_EXIT_FUNCTION();
+}
+
+/*!
+* Show event for this view.
+* Update snapshot and start timers.
+*/
 void CxuiPostcaptureView::showEvent(QShowEvent *event)
 {
     CX_DEBUG_ENTER_FUNCTION();
@@ -508,11 +492,10 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::hideEvent
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+* Hide event.
+* Release snapshot and stop timers.
+*/
 void CxuiPostcaptureView::hideEvent(QHideEvent *event)
 {
     CX_DEBUG_ENTER_FUNCTION();
@@ -581,41 +564,50 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
-// ---------------------------------------------------------------------------
-// CxuiPostcaptureView::setImage
-//
-// ---------------------------------------------------------------------------
-//
+/*!
+ * Updates snapshot image. In normal case snapshot is retrieved from engine
+ * but if we are restoring camera to post-capture through activity, then
+ * we get snapshot from thumbnail manager.
+ */
 void CxuiPostcaptureView::updateSnapshotImage()
 {
     CX_DEBUG_ENTER_FUNCTION();
 
-    QPixmap snapshot;
+    if (!mFilename.isNull()) {
+        CX_DEBUG(("CxuiPostcaptureView::updateSnapshot restoring activity"));
+        // filename set, we are restoring activity
+        if (QFile::exists(mFilename)) {
+            CX_DEBUG(("Filename ok, requesting thumbnail from TNM"));
+            if (!mThumbnailManager) {
+                mThumbnailManager = new ThumbnailManager();
+                connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)),
+                                                this, SLOT(handleThumbnailReady(QPixmap, void*, int, int)));
+                mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
+            }
+            mThumbnailManager->getThumbnail(mFilename);
+            CX_DEBUG(("Thumbnail requested"));
 
-    if (mEngine->mode() == ImageMode) {
-        if( mEngine->stillCaptureControl().imageCount() > 0 ) {
-            snapshot = mEngine->stillCaptureControl()[0].snapshot();
+        } else {
+            // file deleted
+            CX_DEBUG(("File %s has been deleted, going back to pre-capture", mFilename.toAscii().data()));
+            goToPrecaptureView();
         }
     } else {
-        snapshot = mEngine->videoCaptureControl().snapshot();
+        QPixmap snapshot;
+        if (mEngine->mode() == ImageMode) {
+            if( mEngine->stillCaptureControl().imageCount() > 0 ) {
+                snapshot = mEngine->stillCaptureControl()[0].snapshot();
+            }
+        } else {
+            snapshot = mEngine->videoCaptureControl().snapshot();
+        }
+        if (mImageLabel) {
+                mImageLabel->setIcon(HbIcon(QIcon(snapshot)));
+            } else {
+                // do nothing
+        }
     }
 
-    if (mImageLabel) {
-        mImageLabel->setIcon(HbIcon(QIcon(snapshot)));
-    } else {
-        // do nothing
-    }
-
-    CX_DEBUG_EXIT_FUNCTION();
-}
-
-/*!
-    Launches "Not supported yet" notification.
- */
-void CxuiPostcaptureView::launchNotSupportedNotification()
-{
-    CX_DEBUG_ENTER_FUNCTION();
-    HbNotificationDialog::launchDialog("Notification", "Not supported yet");
     CX_DEBUG_EXIT_FUNCTION();
 }
 
@@ -626,6 +618,15 @@
 {
     CX_DEBUG_ENTER_FUNCTION();
 
+    if (!mFilename.isNull()) {
+        // post-capture started by activity, engine doesn't contain correct
+        // filename anymore so use the stored one
+        CX_DEBUG(("Using filename saved in activity"));
+        CX_DEBUG_EXIT_FUNCTION();
+        return mFilename;
+    }
+
+    CX_DEBUG(("Getting filename from engine"));
     QString filename;
 
     if (mEngine->mode() == Cxe::VideoMode) {
@@ -645,14 +646,6 @@
 }
 
 /*!
-    Launches the Photos applications as a separate process
-*/
-void CxuiPostcaptureView::launchPhotosApp()
-{
-    QProcess::startDetached(PhotosAppExe);
-}
-
-/*!
     Sends current capture to client app and closes camera
 */
 void CxuiPostcaptureView::select()
@@ -667,71 +660,126 @@
 }
 
 /*!
-    Launches the Videos applications as a separate process
+* Handle exiting standby.
 */
-void CxuiPostcaptureView::launchVideosApp()
+void CxuiPostcaptureView::exitStandby()
 {
-    //Releasing cameda device in order to free
-    //graphical memory
-    releaseCamera();
-    QProcess::startDetached(VideosAppExe);
+    CX_DEBUG_ENTER_FUNCTION();
+
+    // Common functionality first.
+    CxuiView::exitStandby();
+
+    //!@note We should not start timers until we receive the ShowEvent
+    showControls();
+
+    CX_DEBUG_EXIT_FUNCTION();
 }
 
 /*!
-    Handle cases when we loose focus
+* Handle entering standby.
 */
-void CxuiPostcaptureView::handleFocusLost()
+void CxuiPostcaptureView::enterStandby()
 {
     CX_DEBUG_ENTER_FUNCTION();
 
-    // we have lost focus
-    releaseCamera();
+    // Common functionality (release camera).
+    CxuiView::enterStandby();
+
     stopTimers();
     hideControls();
 
     CX_DEBUG_EXIT_FUNCTION();
 }
 
+/*!
+ * Handle thumbnail received from ThumbnailManager.
+ *
+ * @param thumbnail Thumbnail as QPixmap
+ * @param clientData Not used
+ * @param id Thumbnail manager request id
+ * @param errorCode Error code
+ */
+void CxuiPostcaptureView::handleThumbnailReady(QPixmap thumbnail, void *clientData, int id, int errorCode)
+{
+    CX_DEBUG_ENTER_FUNCTION();
 
+    Q_UNUSED(clientData);
+    Q_UNUSED(id);
+
+    if (thumbnail.isNull()) {
+        CX_DEBUG(("Received null thumbnail from TNM, going to pre-capture. Error=%d", errorCode));
+        // null thumbnail, go to precapture
+        goToPrecaptureView();
+    } else if (mImageLabel) {
+        mImageLabel->setIcon(HbIcon(QIcon(thumbnail)));
+    }
+
+    CX_DEBUG_EXIT_FUNCTION();
+}
+
+/*!
+    Start the timers
+*/
 void CxuiPostcaptureView::startTimers()
 {
     CX_DEBUG_ENTER_FUNCTION();
 
     // we start timers only once in a given postcapture view session
-    if (!mTimersStarted) {
-        int postCaptureTimeout = 0;
-        QString settingId;
-
-        if (mEngine->mode() == ImageMode) {
-            settingId = CxeSettingIds::STILL_SHOWCAPTURED;
-        } else {
-            settingId = CxeSettingIds::VIDEO_SHOWCAPTURED;
-        }
-
-        if (!CxuiServiceProvider::isCameraEmbedded()) {
-            CxeError::Id err = mEngine->settings().get(settingId, postCaptureTimeout);
-
-            if (postCaptureTimeout > 0 && err == CxeError::None) {
-                mPostcaptureTimer.start(postCaptureTimeout);
-            } else {
-                // do nothing
-            }
-        }
-
-        // start the hide control timer.
-        mHideControlsTimeout.start(CXUI_HIDE_CONTROLS_TIMEOUT);
-
-        //! @todo Temporarily disabling release timer because of
-        // graphics memory problems related to releasing and reserving again.
-        // mReleaseCameraTimer.start(CXUI_RELEASE_CAMERA_TIMEOUT);
-        // mStopViewfinderTimer.start(CXUI_STOP_VIEWFINDER_TIMEOUT);
-
-        // we make sure that timers are started only once in a given postcaptureview session
+    if(!mTimersStarted) {
+        startPostcaptureTimer();
+        startReleaseTimers();
         mTimersStarted = true;
     }
 
-    // show controls when we get back focus
-    showControls();
+    CX_DEBUG_EXIT_FUNCTION();
+}
+
+/*!
+    Start the timer to return to pre-capture view
+*/
+void CxuiPostcaptureView::startPostcaptureTimer()
+{
+    CX_DEBUG_ENTER_FUNCTION();
+
+    if (!mFilename.isNull()) {
+        // restored from activity, don't do post-capture timeout
+        CX_DEBUG_EXIT_FUNCTION();
+        return;
+    }
+
+    int postCaptureTimeout = 0;
+    QString settingId;
+
+    if (mEngine->mode() == ImageMode) {
+        settingId = CxeSettingIds::STILL_SHOWCAPTURED;
+    } else {
+        settingId = CxeSettingIds::VIDEO_SHOWCAPTURED;
+    }
+
+    if (!CxuiServiceProvider::isCameraEmbedded()) {
+        CxeError::Id err = mEngine->settings().get(settingId, postCaptureTimeout);
+
+        if (postCaptureTimeout > 0 && err == CxeError::None) {
+            mPostcaptureTimer.start(postCaptureTimeout);
+        } else {
+            // do nothing
+        }
+    }
+
+    CX_DEBUG_EXIT_FUNCTION();
+}
+
+/*!
+    Start the timers to stop viewfinder and release the camera
+*/
+void CxuiPostcaptureView::startReleaseTimers()
+{
+    CX_DEBUG_ENTER_FUNCTION();
+
+    // Release camera and stop viewfinder if user stays in postcapture long enough.
+    // Battery could otherwise drain fast.
+    mReleaseCameraTimer.start(CXUI_RELEASE_CAMERA_TIMEOUT);
+    mStopViewfinderTimer.start(CXUI_STOP_VIEWFINDER_TIMEOUT);
 
     CX_DEBUG_EXIT_FUNCTION();
 }
@@ -746,7 +794,7 @@
     mPostcaptureTimer.stop();
     mStopViewfinderTimer.stop();
 
-    // Note: mTimersStarted is intentionally not reset here.
+    //!@note mTimersStarted is intentionally not reset here.
     // Once the timers are stopped, they are not to be started again until
     // we come from precapture view again.
     // E.g. returning from background could otherwise restart the timers and