camerauis/cameraxui/cxui/src/cxuierrormanager.cpp
changeset 19 d9aefe59d544
child 21 fa6d9f75d6a6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbdialog.h>
       
    19 #include <hblabel.h>
       
    20 #include <hbpushbutton.h>
       
    21 #include <QCoreApplication>
       
    22 
       
    23 #include "cxutils.h"
       
    24 #include "cxeerror.h"
       
    25 #include "cxeengine.h"
       
    26 #include "cxuienums.h"
       
    27 #include "cxuierrormanager.h"
       
    28 #include "cxuidocumentloader.h"
       
    29 #include "cxecameradevicecontrol.h"
       
    30 
       
    31 
       
    32 /*
       
    33 * CxuiErrorManager::CxuiErrorManager
       
    34 */
       
    35 CxuiErrorManager::CxuiErrorManager(CxuiCaptureKeyHandler &keyHandler,CxuiDocumentLoader *documentLoader) :
       
    36     mKeyHandler(keyHandler),
       
    37     mDocumentLoader(documentLoader),
       
    38     mErrorMsgPopup(NULL),
       
    39     mErrorSeverity(CxuiErrorManager::None)
       
    40 {
       
    41     CX_DEBUG_ENTER_FUNCTION();
       
    42     CX_DEBUG_EXIT_FUNCTION();
       
    43 }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CxuiViewManager::~CxuiViewManager
       
    47 //
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CxuiErrorManager::~CxuiErrorManager()
       
    51 {
       
    52     CX_DEBUG_ENTER_FUNCTION();
       
    53     CX_DEBUG_EXIT_FUNCTION();
       
    54 }
       
    55 
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CxuiErrorManager::reportError
       
    59 //
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CxuiErrorManager::analyze(CxeError::Id error)
       
    63 {
       
    64     CX_DEBUG_ENTER_FUNCTION();
       
    65 
       
    66     mErrorMsgPopup = NULL;
       
    67     mErrorSeverity = CxuiErrorManager::None;
       
    68 
       
    69     // start evaluating the error.
       
    70     QString errorMsgTxt = getErrorDetails(error);
       
    71 
       
    72     if(mErrorSeverity != CxuiErrorManager::None) {
       
    73         // show the error note to the user.
       
    74         launchPopup(errorMsgTxt);
       
    75     } else {
       
    76         // ignore
       
    77     }
       
    78 
       
    79     CX_DEBUG_EXIT_FUNCTION();
       
    80 }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CxuiErrorManager::aboutToClosePopup
       
    85 //
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CxuiErrorManager::aboutToClosePopup()
       
    89 {
       
    90     CX_DEBUG_ENTER_FUNCTION();
       
    91     // handle any use-cases when the error can be recovered
       
    92     emit errorRecovered();
       
    93     CX_DEBUG_EXIT_FUNCTION();
       
    94 }
       
    95 
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CxuiErrorManager::closeApp
       
   100 //
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CxuiErrorManager::closeApp()
       
   104 {
       
   105     CX_DEBUG_ENTER_FUNCTION();
       
   106     QCoreApplication::quit();
       
   107     CX_DEBUG_EXIT_FUNCTION();
       
   108 }
       
   109 
       
   110 
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CxuiErrorManager::getErrorDetails
       
   114 // evaluates error for error severity and error note
       
   115 // ---------------------------------------------------------------------------
       
   116 QString CxuiErrorManager::getErrorDetails(CxeError::Id error)
       
   117 {
       
   118     CX_DEBUG_ENTER_FUNCTION();
       
   119     QString msg("No Error");
       
   120     switch(error) {
       
   121         case CxeError::Died:
       
   122         case CxeError::InitializationFailed:
       
   123         case CxeError::HwNotAvailable:
       
   124         case CxeError::NotReady:
       
   125             mErrorSeverity = CxuiErrorManager::Severe;
       
   126             msg = hbTrId("txt_cam_info_error");
       
   127             break;
       
   128         case CxeError::InUse:
       
   129             mErrorSeverity = CxuiErrorManager::Severe;
       
   130             msg = hbTrId("txt_cam_info_camera_already_in_use");
       
   131             break;
       
   132         default:
       
   133             break;
       
   134     }
       
   135     CX_DEBUG_EXIT_FUNCTION();
       
   136 
       
   137     return msg;
       
   138 }
       
   139 
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CxuiErrorManager::launchPopup
       
   143 // ---------------------------------------------------------------------------
       
   144 void CxuiErrorManager::launchPopup(QString& errorMsgTxt)
       
   145 {
       
   146     CX_DEBUG_ENTER_FUNCTION();
       
   147 
       
   148     // we always prepare the popup for the new message and hence we load the
       
   149     // popup everytime from document loader
       
   150 
       
   151     CX_ASSERT_ALWAYS(mDocumentLoader);
       
   152     bool ok = false;
       
   153 
       
   154     // Use document loader to create popup
       
   155     mDocumentLoader->load(CxUiLayout::ERROR_POPUP_XML, &ok);
       
   156     CX_DEBUG(("mErrorMsgPopup load ok=%d", ok));
       
   157 
       
   158     mErrorMsgPopup = qobject_cast<HbDialog*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_POPUP));
       
   159 
       
   160     CX_ASSERT_ALWAYS(mErrorMsgPopup);
       
   161 
       
   162     mErrorMsgPopup->setTimeout(HbDialog::NoTimeout);
       
   163     mErrorMsgPopup->setBackgroundFaded(false);
       
   164 
       
   165     // color of standby text is set in the code. It cannot be done in docml
       
   166     HbLabel* label = qobject_cast<HbLabel*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_TEXT_WIDGET));
       
   167     label->setTextColor(Qt::white);
       
   168     label->setPlainText(errorMsgTxt);
       
   169 
       
   170     HbPushButton *exitButton = qobject_cast<HbPushButton*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_BUTTON_WIDGET));
       
   171 
       
   172     if(mErrorSeverity == CxuiErrorManager::Severe) {
       
   173         // inform ui about error recovery
       
   174         emit aboutToRecoverError();
       
   175         QObject::connect(mErrorMsgPopup, SIGNAL(aboutToClose()), this, SLOT(closeApp()));
       
   176         exitButton->show();
       
   177     } else {
       
   178         // TODO handle other severity cases here.
       
   179     }
       
   180 
       
   181     mErrorMsgPopup->show();
       
   182 
       
   183     CX_DEBUG_EXIT_FUNCTION();
       
   184 }