camerauis/cameraxui/cxui/src/cxuierrormanager.cpp
changeset 37 64817133cd1d
parent 36 b12f3922a74f
child 52 7e18d488ac5f
equal deleted inserted replaced
36:b12f3922a74f 37:64817133cd1d
    32 
    32 
    33 
    33 
    34 /*!
    34 /*!
    35 * Constructor
    35 * Constructor
    36 */
    36 */
    37 CxuiErrorManager::CxuiErrorManager(CxuiCaptureKeyHandler &keyHandler,CxuiDocumentLoader *documentLoader) :
    37 CxuiErrorManager::CxuiErrorManager(CxuiDocumentLoader *documentLoader) :
    38     mKeyHandler(keyHandler),
       
    39     mDocumentLoader(documentLoader),
    38     mDocumentLoader(documentLoader),
    40     mErrorMsgPopup(NULL),
    39     mErrorMsgPopup(NULL),
    41     mErrorId(CxeError::None),
    40     mErrorId(CxeError::None),
    42     mErrorSeverity(CxuiErrorManager::None)
    41     mErrorSeverity(CxuiErrorManager::None)
    43 {
    42 {
    54     CX_DEBUG_EXIT_FUNCTION();
    53     CX_DEBUG_EXIT_FUNCTION();
    55 }
    54 }
    56 
    55 
    57 
    56 
    58 /*!
    57 /*!
    59 * Show error popup based on the error id.
    58 * Check the error code and show either error popup, warning popup or do nothing,
    60 * @param error Error id.
    59 * if "no error" code is given.
    61 */
    60 * @param error Error id. If CxeError::None, no action is taken. Otherwise
    62 void CxuiErrorManager::showPopup(CxeError::Id error)
    61 * either warning or error popup is shown based on the severity of error.
       
    62 *
       
    63 */
       
    64 void CxuiErrorManager::check(CxeError::Id error)
    63 {
    65 {
    64     CX_DEBUG_ENTER_FUNCTION();
    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) {
    68         CxeError::Id oldError = mErrorId;
       
    69         mErrorId = error;
    70         mErrorId = error;
    70 
    71 
    71         // start evaluating the error.
    72         // start evaluating the error.
    72         QString errorText;
    73         QString errorText;
    73         QString buttonText;
    74         QString buttonText;
    74         getErrorDetails(errorText, buttonText);
    75         getErrorDetails(errorText, buttonText);
    75 
    76 
    76         if (mErrorSeverity != CxuiErrorManager::None) {
    77         if (mErrorSeverity != CxuiErrorManager::None) {
    77             // Clear the old error if one for some reason exists.
    78             // Clear the old error if one for some reason exists.
    78             hidePopup(oldError);
    79             clear();
    79 
    80 
    80             // show the error note to the user.
    81             // show the error note to the user.
    81             launchPopup(errorText, buttonText);
    82             launchPopup(errorText, buttonText);
    82         } else {
    83         } else {
    83             // ignore
    84             // ignore
    86 
    87 
    87     CX_DEBUG_EXIT_FUNCTION();
    88     CX_DEBUG_EXIT_FUNCTION();
    88 }
    89 }
    89 
    90 
    90 /*!
    91 /*!
    91 * Close the open error popup, if it is shown for the same error as requested here.
    92 * Close the open error popup.
    92 * @param error Error id, for which we are closing the error dialog.
    93 */
    93 */
    94 void CxuiErrorManager::clear()
    94 void CxuiErrorManager::hidePopup(CxeError::Id error)
    95 {
    95 {
    96     CX_DEBUG_ENTER_FUNCTION();
    96     CX_DEBUG_ENTER_FUNCTION();
    97     if (mErrorMsgPopup) {
    97     if (mErrorId == error) {
    98         mErrorMsgPopup->close();
    98         if (mErrorMsgPopup) {
    99         mErrorMsgPopup = NULL;
    99             mErrorMsgPopup->close();
       
   100             mErrorMsgPopup = NULL;
       
   101         }
       
   102     }
   100     }
   103     CX_DEBUG_EXIT_FUNCTION();
   101     CX_DEBUG_EXIT_FUNCTION();
   104 }
   102 }
   105 
   103 
   106 /*!
   104 /*!
   107 * Slot that gets called when error note is closed.
   105 * Slot that gets called when error note is closed.
   108 */
   106 */
   109 void CxuiErrorManager::popupClosed(HbAction *action)
   107 void CxuiErrorManager::popupClosed(HbAction *action)
   110 {
   108 {
       
   109     Q_UNUSED(action)
       
   110 
   111     CX_DEBUG_ENTER_FUNCTION();
   111     CX_DEBUG_ENTER_FUNCTION();
   112     // Dialog or action instance cannot be used anymore.
   112     // Dialog or action instance cannot be used anymore.
   113     mErrorMsgPopup = NULL;
   113     mErrorMsgPopup = NULL;
   114 
   114 
   115     // handle any use-cases when the error can be recovered
   115     // handle any use-cases when the error can be recovered
   116     emit errorRecovered();
   116     emit errorPopupClosed();
   117     CX_DEBUG_EXIT_FUNCTION();
   117     CX_DEBUG_EXIT_FUNCTION();
   118 }
   118 }
   119 
   119 
   120 
   120 
   121 /*!
   121 /*!
   138 void CxuiErrorManager::getErrorDetails(QString &errorText, QString &buttonText)
   138 void CxuiErrorManager::getErrorDetails(QString &errorText, QString &buttonText)
   139 {
   139 {
   140     CX_DEBUG_ENTER_FUNCTION();
   140     CX_DEBUG_ENTER_FUNCTION();
   141     switch (mErrorId) {
   141     switch (mErrorId) {
   142         case CxeError::MemoryNotAccessible:
   142         case CxeError::MemoryNotAccessible:
   143             mErrorSeverity = CxuiErrorManager::Severe;
   143             mErrorSeverity = CxuiErrorManager::Error;
   144             errorText = hbTrId("txt_cam_info_error_usb_disconnected");
   144             errorText = hbTrId("txt_cam_info_error_usb_disconnected");
   145             buttonText = hbTrId("txt_cam_info_error_usb_disconnected_button");
   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");
   146             break;
   160             break;
   147         case CxeError::Died:
   161         case CxeError::Died:
   148         case CxeError::InitializationFailed:
   162         case CxeError::InitializationFailed:
   149         case CxeError::HwNotAvailable:
   163         case CxeError::HwNotAvailable:
   150         case CxeError::NotReady:
   164         case CxeError::NotReady:
   151             mErrorSeverity = CxuiErrorManager::Severe;
   165         default:
       
   166             mErrorSeverity = CxuiErrorManager::Error;
   152             errorText = hbTrId("txt_cam_info_error");
   167             errorText = hbTrId("txt_cam_info_error");
   153             buttonText = hbTrId("txt_common_button_close");
   168             buttonText = hbTrId("txt_common_button_close");
   154             break;
   169             break;
   155         case CxeError::InUse:
   170     }
   156             mErrorSeverity = CxuiErrorManager::Severe;
   171     CX_DEBUG_EXIT_FUNCTION();
   157             errorText = hbTrId("txt_cam_info_camera_already_in_use");
   172 }
   158             buttonText = hbTrId("txt_common_button_close");
   173 
   159             break;
   174 /*!
   160         case CxeError::DiskFull:
   175 * Show warning or error popup.
   161             mErrorSeverity = CxuiErrorManager::Warning;
   176 * @param errorText Message to be shown in the popup.
   162             errorText = hbTrId("txt_cam_info_memory_full");
   177 * @param buttonText Button text to be shown in the action button of the popup. Not used on warning popup.
   163             break;
       
   164         default:
       
   165             errorText = "No Error";
       
   166             break;
       
   167     }
       
   168     CX_DEBUG_EXIT_FUNCTION();
       
   169 }
       
   170 
       
   171 /*!
       
   172 *
       
   173 */
   178 */
   174 void CxuiErrorManager::launchPopup(const QString &errorText, const QString &buttonText)
   179 void CxuiErrorManager::launchPopup(const QString &errorText, const QString &buttonText)
   175 {
   180 {
   176     CX_DEBUG_ENTER_FUNCTION();
   181     CX_DEBUG_ENTER_FUNCTION();
   177 
   182 
   178     switch (mErrorSeverity) {
   183     switch (mErrorSeverity) {
   179     case CxuiErrorManager::None:
   184     case CxuiErrorManager::None:
   180         break;
   185         break;
   181     case CxuiErrorManager::Warning:
   186     case CxuiErrorManager::Warning:
   182         showLowSeverityNote(errorText);
   187         showWarningPopup(errorText);
   183         break;
   188         break;
   184     default:
   189     default:
   185         showHighSeverityNote(errorText, buttonText);
   190         showErrorPopup(errorText, buttonText);
   186         break;
   191         break;
   187     }
   192     }
   188 
   193 
   189     mErrorSeverity = CxuiErrorManager::None;
   194     mErrorSeverity = CxuiErrorManager::None;
   190 
   195 
   191     CX_DEBUG_EXIT_FUNCTION();
   196     CX_DEBUG_EXIT_FUNCTION();
   192 }
   197 }
   193 
   198 
   194 /*!
   199 /*!
   195 * Show error note for high severity error.
   200 * Show error note for severe error.
   196 */
   201 */
   197 void CxuiErrorManager::showHighSeverityNote(const QString &errorText, const QString &buttonText)
   202 void CxuiErrorManager::showErrorPopup(const QString &errorText, const QString &buttonText)
   198 {
   203 {
   199     // 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
   200     // popup everytime from document loader
   205     // popup everytime from document loader
   201 
   206 
   202     CX_ASSERT_ALWAYS(mDocumentLoader);
   207     CX_ASSERT_ALWAYS(mDocumentLoader);
   229     if (!buttonText.isEmpty()) {
   234     if (!buttonText.isEmpty()) {
   230         // inform ui about error recovery
   235         // inform ui about error recovery
   231         exitButton->setText(buttonText);
   236         exitButton->setText(buttonText);
   232         connect(exitButton, SIGNAL(released()), this, SLOT(closeApp()));
   237         connect(exitButton, SIGNAL(released()), this, SLOT(closeApp()));
   233         exitButton->show();
   238         exitButton->show();
   234     } else {
   239     }
   235         // TODO handle other severity cases here.
   240 
   236     }
   241     emit errorPopupShown();
   237 
       
   238     emit aboutToRecoverError();
       
   239     mErrorMsgPopup->open(this, SLOT(popupClosed(HbAction*)));
   242     mErrorMsgPopup->open(this, SLOT(popupClosed(HbAction*)));
   240 
   243 
   241     CX_DEBUG_EXIT_FUNCTION();
   244     CX_DEBUG_EXIT_FUNCTION();
   242 }
   245 }
   243 
   246 
   244 /*!
   247 /*!
   245 * Show error note for low severity error.
   248 * Show warning note for low severity error.
   246 */
   249 */
   247 void CxuiErrorManager::showLowSeverityNote(const QString &errorText)
   250 void CxuiErrorManager::showWarningPopup(const QString &errorText)
   248 {
   251 {
   249     CX_DEBUG_ENTER_FUNCTION();
   252     CX_DEBUG_ENTER_FUNCTION();
   250     HbMessageBox::warning(errorText);
   253     HbMessageBox::warning(errorText);
   251     CX_DEBUG_EXIT_FUNCTION();
   254     CX_DEBUG_EXIT_FUNCTION();
   252 }
   255 }