camerauis/cameraxui/cxui/src/cxuierrormanager.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
--- a/camerauis/cameraxui/cxui/src/cxuierrormanager.cpp	Thu May 13 21:30:19 2010 +0300
+++ b/camerauis/cameraxui/cxui/src/cxuierrormanager.cpp	Thu Jul 15 01:55:05 2010 +0300
@@ -16,6 +16,7 @@
 */
 
 #include <QCoreApplication>
+#include <HbAction>
 #include <HbDialog>
 #include <HbMessageBox>
 #include <HbLabel>
@@ -33,10 +34,10 @@
 /*!
 * Constructor
 */
-CxuiErrorManager::CxuiErrorManager(CxuiCaptureKeyHandler &keyHandler,CxuiDocumentLoader *documentLoader) :
-    mKeyHandler(keyHandler),
+CxuiErrorManager::CxuiErrorManager(CxuiDocumentLoader *documentLoader) :
     mDocumentLoader(documentLoader),
     mErrorMsgPopup(NULL),
+    mErrorId(CxeError::None),
     mErrorSeverity(CxuiErrorManager::None)
 {
     CX_DEBUG_ENTER_FUNCTION();
@@ -54,23 +55,31 @@
 
 
 /*!
-* Analyze the error code and act accordingly.
-* @param error Error code.
+* Check the error code and show either error popup, warning popup or do nothing,
+* if "no error" code is given.
+* @param error Error id. If CxeError::None, no action is taken. Otherwise
+* either warning or error popup is shown based on the severity of error.
+*
 */
-void CxuiErrorManager::analyze(CxeError::Id error)
+void CxuiErrorManager::check(CxeError::Id error)
 {
     CX_DEBUG_ENTER_FUNCTION();
-
-    mErrorMsgPopup = NULL;
     mErrorSeverity = CxuiErrorManager::None;
 
     if (error != CxeError::None) {
+        mErrorId = error;
+
         // start evaluating the error.
-        QString errorMsgTxt = getErrorDetails(error);
+        QString errorText;
+        QString buttonText;
+        getErrorDetails(errorText, buttonText);
 
-        if(mErrorSeverity != CxuiErrorManager::None) {
+        if (mErrorSeverity != CxuiErrorManager::None) {
+            // Clear the old error if one for some reason exists.
+            clear();
+
             // show the error note to the user.
-            launchPopup(errorMsgTxt);
+            launchPopup(errorText, buttonText);
         } else {
             // ignore
         }
@@ -79,15 +88,32 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
+/*!
+* Close the open error popup.
+*/
+void CxuiErrorManager::clear()
+{
+    CX_DEBUG_ENTER_FUNCTION();
+    if (mErrorMsgPopup) {
+        mErrorMsgPopup->close();
+        mErrorMsgPopup = NULL;
+    }
+    CX_DEBUG_EXIT_FUNCTION();
+}
 
 /*!
 * Slot that gets called when error note is closed.
 */
-void CxuiErrorManager::aboutToClosePopup()
+void CxuiErrorManager::popupClosed(HbAction *action)
 {
+    Q_UNUSED(action)
+
     CX_DEBUG_ENTER_FUNCTION();
+    // Dialog or action instance cannot be used anymore.
+    mErrorMsgPopup = NULL;
+
     // handle any use-cases when the error can be recovered
-    emit errorRecovered();
+    emit errorPopupClosed();
     CX_DEBUG_EXIT_FUNCTION();
 }
 
@@ -109,59 +135,71 @@
 * and set the severity level, based on given error code.
 * @param error Error code to be analyzed.
 */
-QString CxuiErrorManager::getErrorDetails(CxeError::Id error)
+void CxuiErrorManager::getErrorDetails(QString &errorText, QString &buttonText)
 {
     CX_DEBUG_ENTER_FUNCTION();
-    QString msg("No Error");
-    switch(error) {
+    switch (mErrorId) {
+        case CxeError::MemoryNotAccessible:
+            mErrorSeverity = CxuiErrorManager::Error;
+            errorText = hbTrId("txt_cam_info_error_usb_disconnected");
+            buttonText = hbTrId("txt_cam_info_error_usb_disconnected_button");
+            break;
+        case CxeError::InUse:
+            mErrorSeverity = CxuiErrorManager::Error;
+            errorText = hbTrId("txt_cam_info_camera_already_in_use");
+            buttonText = hbTrId("txt_common_button_close");
+            break;
+        case CxeError::DiskFull:
+            mErrorSeverity = CxuiErrorManager::Warning;
+            errorText = hbTrId("txt_cam_info_memory_full");
+            break;
+        case CxeError::OutOfMemory:
+            mErrorSeverity = CxuiErrorManager::Error;
+            errorText = hbTrId("txt_cam_info_error_ram_full");
+            buttonText = hbTrId("txt_common_ok");
+            break;
         case CxeError::Died:
         case CxeError::InitializationFailed:
         case CxeError::HwNotAvailable:
         case CxeError::NotReady:
-            mErrorSeverity = CxuiErrorManager::Severe;
-            msg = hbTrId("txt_cam_info_error");
-            break;
-        case CxeError::InUse:
-            mErrorSeverity = CxuiErrorManager::Severe;
-            msg = hbTrId("txt_cam_info_camera_already_in_use");
-            break;
-        case CxeError::DiskFull:
-            mErrorSeverity = CxuiErrorManager::Warning;
-            msg = hbTrId("txt_cam_info_memory_full");
         default:
+            mErrorSeverity = CxuiErrorManager::Error;
+            errorText = hbTrId("txt_cam_info_error");
+            buttonText = hbTrId("txt_common_button_close");
             break;
     }
     CX_DEBUG_EXIT_FUNCTION();
-
-    return msg;
 }
 
 /*!
-*
+* Show warning or error popup.
+* @param errorText Message to be shown in the popup.
+* @param buttonText Button text to be shown in the action button of the popup. Not used on warning popup.
 */
-void CxuiErrorManager::launchPopup(QString& errorMsgTxt)
+void CxuiErrorManager::launchPopup(const QString &errorText, const QString &buttonText)
 {
     CX_DEBUG_ENTER_FUNCTION();
 
     switch (mErrorSeverity) {
-    case CxuiErrorManager::Warning:
-        showLowSeverityNote(errorMsgTxt);
+    case CxuiErrorManager::None:
         break;
-    case CxuiErrorManager::Severe:
-    case CxuiErrorManager::Critical:
-        showHighSeverityNote(errorMsgTxt);
+    case CxuiErrorManager::Warning:
+        showWarningPopup(errorText);
         break;
     default:
+        showErrorPopup(errorText, buttonText);
         break;
     }
 
+    mErrorSeverity = CxuiErrorManager::None;
+
     CX_DEBUG_EXIT_FUNCTION();
 }
 
 /*!
-* Show error note for high severity error.
+* Show error note for severe error.
 */
-void CxuiErrorManager::showHighSeverityNote(QString& errorMsgTxt)
+void CxuiErrorManager::showErrorPopup(const QString &errorText, const QString &buttonText)
 {
     // we always prepare the popup for the new message and hence we load the
     // popup everytime from document loader
@@ -175,6 +213,8 @@
 
     mErrorMsgPopup = qobject_cast<HbDialog*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_POPUP));
     CX_ASSERT_ALWAYS(mErrorMsgPopup);
+    mErrorMsgPopup->setAttribute(Qt::WA_DeleteOnClose, true);
+    mErrorMsgPopup->setTimeout(HbDialog::NoTimeout);
 
     // HbDialog's default background item is replaced with black rectangle
     QGraphicsRectItem *backgroundItem = new QGraphicsRectItem();
@@ -184,36 +224,32 @@
     backgroundItem->setRect(origBgItem->boundingRect());
     mErrorMsgPopup->setBackgroundItem(backgroundItem);
 
-    mErrorMsgPopup->setTimeout(HbDialog::NoTimeout);
-    mErrorMsgPopup->setBackgroundFaded(false);
 
     // color of standby text is set in the code. It cannot be done in docml
     HbLabel* label = qobject_cast<HbLabel*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_TEXT_WIDGET));
     label->setTextColor(Qt::white);
-    label->setPlainText(errorMsgTxt);
+    label->setPlainText(errorText);
 
     HbPushButton *exitButton = qobject_cast<HbPushButton*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_BUTTON_WIDGET));
-
-    if(mErrorSeverity == CxuiErrorManager::Severe) {
+    if (!buttonText.isEmpty()) {
         // inform ui about error recovery
-        emit aboutToRecoverError();
-        QObject::connect(mErrorMsgPopup, SIGNAL(aboutToClose()), this, SLOT(closeApp()));
+        exitButton->setText(buttonText);
+        connect(exitButton, SIGNAL(released()), this, SLOT(closeApp()));
         exitButton->show();
-    } else {
-        // TODO handle other severity cases here.
     }
 
-    mErrorMsgPopup->show();
+    emit errorPopupShown();
+    mErrorMsgPopup->open(this, SLOT(popupClosed(HbAction*)));
 
     CX_DEBUG_EXIT_FUNCTION();
 }
 
 /*!
-* Show error note for low severity error.
+* Show warning note for low severity error.
 */
-void CxuiErrorManager::showLowSeverityNote(QString& errorMsgTxt)
+void CxuiErrorManager::showWarningPopup(const QString &errorText)
 {
     CX_DEBUG_ENTER_FUNCTION();
-    HbMessageBox::warning(errorMsgTxt);
+    HbMessageBox::warning(errorText);
     CX_DEBUG_EXIT_FUNCTION();
 }