camerauis/cameraxui/cxui/src/cxuierrormanager.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
equal deleted inserted replaced
28:3075d9b614e6 43:0e652f8f1fbd
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QCoreApplication>
    18 #include <QCoreApplication>
       
    19 #include <HbAction>
    19 #include <HbDialog>
    20 #include <HbDialog>
    20 #include <HbMessageBox>
    21 #include <HbMessageBox>
    21 #include <HbLabel>
    22 #include <HbLabel>
    22 #include <HbPushButton>
    23 #include <HbPushButton>
    23 
    24 
    31 
    32 
    32 
    33 
    33 /*!
    34 /*!
    34 * Constructor
    35 * Constructor
    35 */
    36 */
    36 CxuiErrorManager::CxuiErrorManager(CxuiCaptureKeyHandler &keyHandler,CxuiDocumentLoader *documentLoader) :
    37 CxuiErrorManager::CxuiErrorManager(CxuiDocumentLoader *documentLoader) :
    37     mKeyHandler(keyHandler),
       
    38     mDocumentLoader(documentLoader),
    38     mDocumentLoader(documentLoader),
    39     mErrorMsgPopup(NULL),
    39     mErrorMsgPopup(NULL),
       
    40     mErrorId(CxeError::None),
    40     mErrorSeverity(CxuiErrorManager::None)
    41     mErrorSeverity(CxuiErrorManager::None)
    41 {
    42 {
    42     CX_DEBUG_ENTER_FUNCTION();
    43     CX_DEBUG_ENTER_FUNCTION();
    43     CX_DEBUG_EXIT_FUNCTION();
    44     CX_DEBUG_EXIT_FUNCTION();
    44 }
    45 }
    52     CX_DEBUG_EXIT_FUNCTION();
    53     CX_DEBUG_EXIT_FUNCTION();
    53 }
    54 }
    54 
    55 
    55 
    56 
    56 /*!
    57 /*!
    57 * Analyze the error code and act accordingly.
    58 * Check the error code and show either error popup, warning popup or do nothing,
    58 * @param error Error code.
    59 * if "no error" code is given.
    59 */
    60 * @param error Error id. If CxeError::None, no action is taken. Otherwise
    60 void CxuiErrorManager::analyze(CxeError::Id error)
    61 * either warning or error popup is shown based on the severity of error.
    61 {
    62 *
    62     CX_DEBUG_ENTER_FUNCTION();
    63 */
    63 
    64 void CxuiErrorManager::check(CxeError::Id error)
    64     mErrorMsgPopup = NULL;
    65 {
       
    66     CX_DEBUG_ENTER_FUNCTION();
    65     mErrorSeverity = CxuiErrorManager::None;
    67     mErrorSeverity = CxuiErrorManager::None;
    66 
    68 
    67     if (error != CxeError::None) {
    69     if (error != CxeError::None) {
       
    70         mErrorId = error;
       
    71 
    68         // start evaluating the error.
    72         // start evaluating the error.
    69         QString errorMsgTxt = getErrorDetails(error);
    73         QString errorText;
    70 
    74         QString buttonText;
    71         if(mErrorSeverity != CxuiErrorManager::None) {
    75         getErrorDetails(errorText, buttonText);
       
    76 
       
    77         if (mErrorSeverity != CxuiErrorManager::None) {
       
    78             // Clear the old error if one for some reason exists.
       
    79             clear();
       
    80 
    72             // show the error note to the user.
    81             // show the error note to the user.
    73             launchPopup(errorMsgTxt);
    82             launchPopup(errorText, buttonText);
    74         } else {
    83         } else {
    75             // ignore
    84             // ignore
    76         }
    85         }
    77     }
    86     }
    78 
    87 
    79     CX_DEBUG_EXIT_FUNCTION();
    88     CX_DEBUG_EXIT_FUNCTION();
    80 }
    89 }
    81 
    90 
       
    91 /*!
       
    92 * Close the open error popup.
       
    93 */
       
    94 void CxuiErrorManager::clear()
       
    95 {
       
    96     CX_DEBUG_ENTER_FUNCTION();
       
    97     if (mErrorMsgPopup) {
       
    98         mErrorMsgPopup->close();
       
    99         mErrorMsgPopup = NULL;
       
   100     }
       
   101     CX_DEBUG_EXIT_FUNCTION();
       
   102 }
    82 
   103 
    83 /*!
   104 /*!
    84 * Slot that gets called when error note is closed.
   105 * Slot that gets called when error note is closed.
    85 */
   106 */
    86 void CxuiErrorManager::aboutToClosePopup()
   107 void CxuiErrorManager::popupClosed(HbAction *action)
    87 {
   108 {
    88     CX_DEBUG_ENTER_FUNCTION();
   109     Q_UNUSED(action)
       
   110 
       
   111     CX_DEBUG_ENTER_FUNCTION();
       
   112     // Dialog or action instance cannot be used anymore.
       
   113     mErrorMsgPopup = NULL;
       
   114 
    89     // handle any use-cases when the error can be recovered
   115     // handle any use-cases when the error can be recovered
    90     emit errorRecovered();
   116     emit errorPopupClosed();
    91     CX_DEBUG_EXIT_FUNCTION();
   117     CX_DEBUG_EXIT_FUNCTION();
    92 }
   118 }
    93 
   119 
    94 
   120 
    95 /*!
   121 /*!
   107 /*!
   133 /*!
   108 * Helper method to get the error message to use for showing note to user,
   134 * Helper method to get the error message to use for showing note to user,
   109 * and set the severity level, based on given error code.
   135 * and set the severity level, based on given error code.
   110 * @param error Error code to be analyzed.
   136 * @param error Error code to be analyzed.
   111 */
   137 */
   112 QString CxuiErrorManager::getErrorDetails(CxeError::Id error)
   138 void CxuiErrorManager::getErrorDetails(QString &errorText, QString &buttonText)
   113 {
   139 {
   114     CX_DEBUG_ENTER_FUNCTION();
   140     CX_DEBUG_ENTER_FUNCTION();
   115     QString msg("No Error");
   141     switch (mErrorId) {
   116     switch(error) {
   142         case CxeError::MemoryNotAccessible:
       
   143             mErrorSeverity = CxuiErrorManager::Error;
       
   144             errorText = hbTrId("txt_cam_info_error_usb_disconnected");
       
   145             buttonText = hbTrId("txt_cam_info_error_usb_disconnected_button");
       
   146             break;
       
   147         case CxeError::InUse:
       
   148             mErrorSeverity = CxuiErrorManager::Error;
       
   149             errorText = hbTrId("txt_cam_info_camera_already_in_use");
       
   150             buttonText = hbTrId("txt_common_button_close");
       
   151             break;
       
   152         case CxeError::DiskFull:
       
   153             mErrorSeverity = CxuiErrorManager::Warning;
       
   154             errorText = hbTrId("txt_cam_info_memory_full");
       
   155             break;
       
   156         case CxeError::OutOfMemory:
       
   157             mErrorSeverity = CxuiErrorManager::Error;
       
   158             errorText = hbTrId("txt_cam_info_error_ram_full");
       
   159             buttonText = hbTrId("txt_common_ok");
       
   160             break;
   117         case CxeError::Died:
   161         case CxeError::Died:
   118         case CxeError::InitializationFailed:
   162         case CxeError::InitializationFailed:
   119         case CxeError::HwNotAvailable:
   163         case CxeError::HwNotAvailable:
   120         case CxeError::NotReady:
   164         case CxeError::NotReady:
   121             mErrorSeverity = CxuiErrorManager::Severe;
       
   122             msg = hbTrId("txt_cam_info_error");
       
   123             break;
       
   124         case CxeError::InUse:
       
   125             mErrorSeverity = CxuiErrorManager::Severe;
       
   126             msg = hbTrId("txt_cam_info_camera_already_in_use");
       
   127             break;
       
   128         case CxeError::DiskFull:
       
   129             mErrorSeverity = CxuiErrorManager::Warning;
       
   130             msg = hbTrId("txt_cam_info_memory_full");
       
   131         default:
   165         default:
   132             break;
   166             mErrorSeverity = CxuiErrorManager::Error;
   133     }
   167             errorText = hbTrId("txt_cam_info_error");
   134     CX_DEBUG_EXIT_FUNCTION();
   168             buttonText = hbTrId("txt_common_button_close");
   135 
   169             break;
   136     return msg;
   170     }
   137 }
   171     CX_DEBUG_EXIT_FUNCTION();
   138 
   172 }
   139 /*!
   173 
   140 *
   174 /*!
   141 */
   175 * Show warning or error popup.
   142 void CxuiErrorManager::launchPopup(QString& errorMsgTxt)
   176 * @param errorText Message to be shown in the popup.
       
   177 * @param buttonText Button text to be shown in the action button of the popup. Not used on warning popup.
       
   178 */
       
   179 void CxuiErrorManager::launchPopup(const QString &errorText, const QString &buttonText)
   143 {
   180 {
   144     CX_DEBUG_ENTER_FUNCTION();
   181     CX_DEBUG_ENTER_FUNCTION();
   145 
   182 
   146     switch (mErrorSeverity) {
   183     switch (mErrorSeverity) {
       
   184     case CxuiErrorManager::None:
       
   185         break;
   147     case CxuiErrorManager::Warning:
   186     case CxuiErrorManager::Warning:
   148         showLowSeverityNote(errorMsgTxt);
   187         showWarningPopup(errorText);
   149         break;
       
   150     case CxuiErrorManager::Severe:
       
   151     case CxuiErrorManager::Critical:
       
   152         showHighSeverityNote(errorMsgTxt);
       
   153         break;
   188         break;
   154     default:
   189     default:
       
   190         showErrorPopup(errorText, buttonText);
   155         break;
   191         break;
   156     }
   192     }
   157 
   193 
   158     CX_DEBUG_EXIT_FUNCTION();
   194     mErrorSeverity = CxuiErrorManager::None;
   159 }
   195 
   160 
   196     CX_DEBUG_EXIT_FUNCTION();
   161 /*!
   197 }
   162 * Show error note for high severity error.
   198 
   163 */
   199 /*!
   164 void CxuiErrorManager::showHighSeverityNote(QString& errorMsgTxt)
   200 * Show error note for severe error.
       
   201 */
       
   202 void CxuiErrorManager::showErrorPopup(const QString &errorText, const QString &buttonText)
   165 {
   203 {
   166     // we always prepare the popup for the new message and hence we load the
   204     // we always prepare the popup for the new message and hence we load the
   167     // popup everytime from document loader
   205     // popup everytime from document loader
   168 
   206 
   169     CX_ASSERT_ALWAYS(mDocumentLoader);
   207     CX_ASSERT_ALWAYS(mDocumentLoader);
   173     mDocumentLoader->load(CxUiLayout::ERROR_POPUP_XML, &ok);
   211     mDocumentLoader->load(CxUiLayout::ERROR_POPUP_XML, &ok);
   174     CX_DEBUG(("mErrorMsgPopup load ok=%d", ok));
   212     CX_DEBUG(("mErrorMsgPopup load ok=%d", ok));
   175 
   213 
   176     mErrorMsgPopup = qobject_cast<HbDialog*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_POPUP));
   214     mErrorMsgPopup = qobject_cast<HbDialog*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_POPUP));
   177     CX_ASSERT_ALWAYS(mErrorMsgPopup);
   215     CX_ASSERT_ALWAYS(mErrorMsgPopup);
       
   216     mErrorMsgPopup->setAttribute(Qt::WA_DeleteOnClose, true);
       
   217     mErrorMsgPopup->setTimeout(HbDialog::NoTimeout);
   178 
   218 
   179     // HbDialog's default background item is replaced with black rectangle
   219     // HbDialog's default background item is replaced with black rectangle
   180     QGraphicsRectItem *backgroundItem = new QGraphicsRectItem();
   220     QGraphicsRectItem *backgroundItem = new QGraphicsRectItem();
   181     QBrush blackBrush = QBrush(Qt::black);
   221     QBrush blackBrush = QBrush(Qt::black);
   182     backgroundItem->setBrush(blackBrush);
   222     backgroundItem->setBrush(blackBrush);
   183     QGraphicsItem *origBgItem = mErrorMsgPopup->backgroundItem();
   223     QGraphicsItem *origBgItem = mErrorMsgPopup->backgroundItem();
   184     backgroundItem->setRect(origBgItem->boundingRect());
   224     backgroundItem->setRect(origBgItem->boundingRect());
   185     mErrorMsgPopup->setBackgroundItem(backgroundItem);
   225     mErrorMsgPopup->setBackgroundItem(backgroundItem);
   186 
   226 
   187     mErrorMsgPopup->setTimeout(HbDialog::NoTimeout);
       
   188     mErrorMsgPopup->setBackgroundFaded(false);
       
   189 
   227 
   190     // color of standby text is set in the code. It cannot be done in docml
   228     // color of standby text is set in the code. It cannot be done in docml
   191     HbLabel* label = qobject_cast<HbLabel*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_TEXT_WIDGET));
   229     HbLabel* label = qobject_cast<HbLabel*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_TEXT_WIDGET));
   192     label->setTextColor(Qt::white);
   230     label->setTextColor(Qt::white);
   193     label->setPlainText(errorMsgTxt);
   231     label->setPlainText(errorText);
   194 
   232 
   195     HbPushButton *exitButton = qobject_cast<HbPushButton*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_BUTTON_WIDGET));
   233     HbPushButton *exitButton = qobject_cast<HbPushButton*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_BUTTON_WIDGET));
   196 
   234     if (!buttonText.isEmpty()) {
   197     if(mErrorSeverity == CxuiErrorManager::Severe) {
       
   198         // inform ui about error recovery
   235         // inform ui about error recovery
   199         emit aboutToRecoverError();
   236         exitButton->setText(buttonText);
   200         QObject::connect(mErrorMsgPopup, SIGNAL(aboutToClose()), this, SLOT(closeApp()));
   237         connect(exitButton, SIGNAL(released()), this, SLOT(closeApp()));
   201         exitButton->show();
   238         exitButton->show();
   202     } else {
   239     }
   203         // TODO handle other severity cases here.
   240 
   204     }
   241     emit errorPopupShown();
   205 
   242     mErrorMsgPopup->open(this, SLOT(popupClosed(HbAction*)));
   206     mErrorMsgPopup->show();
   243 
   207 
   244     CX_DEBUG_EXIT_FUNCTION();
   208     CX_DEBUG_EXIT_FUNCTION();
   245 }
   209 }
   246 
   210 
   247 /*!
   211 /*!
   248 * Show warning note for low severity error.
   212 * Show error note for low severity error.
   249 */
   213 */
   250 void CxuiErrorManager::showWarningPopup(const QString &errorText)
   214 void CxuiErrorManager::showLowSeverityNote(QString& errorMsgTxt)
   251 {
   215 {
   252     CX_DEBUG_ENTER_FUNCTION();
   216     CX_DEBUG_ENTER_FUNCTION();
   253     HbMessageBox::warning(errorText);
   217     HbMessageBox::warning(errorMsgTxt);
   254     CX_DEBUG_EXIT_FUNCTION();
   218     CX_DEBUG_EXIT_FUNCTION();
   255 }
   219 }