camerauis/cameraxui/cxui/src/cxuierrormanager.cpp
changeset 21 fa6d9f75d6a6
parent 19 d9aefe59d544
child 36 b12f3922a74f
child 43 0e652f8f1fbd
equal deleted inserted replaced
19:d9aefe59d544 21:fa6d9f75d6a6
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <hbdialog.h>
       
    19 #include <hblabel.h>
       
    20 #include <hbpushbutton.h>
       
    21 #include <QCoreApplication>
    18 #include <QCoreApplication>
       
    19 #include <HbDialog>
       
    20 #include <HbMessageBox>
       
    21 #include <HbLabel>
       
    22 #include <HbPushButton>
    22 
    23 
    23 #include "cxutils.h"
    24 #include "cxutils.h"
    24 #include "cxeerror.h"
    25 #include "cxeerror.h"
    25 #include "cxeengine.h"
    26 #include "cxeengine.h"
    26 #include "cxuienums.h"
    27 #include "cxuienums.h"
    27 #include "cxuierrormanager.h"
    28 #include "cxuierrormanager.h"
    28 #include "cxuidocumentloader.h"
    29 #include "cxuidocumentloader.h"
    29 #include "cxecameradevicecontrol.h"
    30 #include "cxecameradevicecontrol.h"
    30 
    31 
    31 
    32 
    32 /*
    33 /*!
    33 * CxuiErrorManager::CxuiErrorManager
    34 * Constructor
    34 */
    35 */
    35 CxuiErrorManager::CxuiErrorManager(CxuiCaptureKeyHandler &keyHandler,CxuiDocumentLoader *documentLoader) :
    36 CxuiErrorManager::CxuiErrorManager(CxuiCaptureKeyHandler &keyHandler,CxuiDocumentLoader *documentLoader) :
    36     mKeyHandler(keyHandler),
    37     mKeyHandler(keyHandler),
    37     mDocumentLoader(documentLoader),
    38     mDocumentLoader(documentLoader),
    38     mErrorMsgPopup(NULL),
    39     mErrorMsgPopup(NULL),
    40 {
    41 {
    41     CX_DEBUG_ENTER_FUNCTION();
    42     CX_DEBUG_ENTER_FUNCTION();
    42     CX_DEBUG_EXIT_FUNCTION();
    43     CX_DEBUG_EXIT_FUNCTION();
    43 }
    44 }
    44 
    45 
    45 // ---------------------------------------------------------------------------
    46 /*!
    46 // CxuiViewManager::~CxuiViewManager
    47 * Destructor
    47 //
    48 */
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CxuiErrorManager::~CxuiErrorManager()
    49 CxuiErrorManager::~CxuiErrorManager()
    51 {
    50 {
    52     CX_DEBUG_ENTER_FUNCTION();
    51     CX_DEBUG_ENTER_FUNCTION();
    53     CX_DEBUG_EXIT_FUNCTION();
    52     CX_DEBUG_EXIT_FUNCTION();
    54 }
    53 }
    55 
    54 
    56 
    55 
    57 // ---------------------------------------------------------------------------
    56 /*!
    58 // CxuiErrorManager::reportError
    57 * Analyze the error code and act accordingly.
    59 //
    58 * @param error Error code.
    60 // ---------------------------------------------------------------------------
    59 */
    61 //
       
    62 void CxuiErrorManager::analyze(CxeError::Id error)
    60 void CxuiErrorManager::analyze(CxeError::Id error)
    63 {
    61 {
    64     CX_DEBUG_ENTER_FUNCTION();
    62     CX_DEBUG_ENTER_FUNCTION();
    65 
    63 
    66     mErrorMsgPopup = NULL;
    64     mErrorMsgPopup = NULL;
    67     mErrorSeverity = CxuiErrorManager::None;
    65     mErrorSeverity = CxuiErrorManager::None;
    68 
    66 
    69     // start evaluating the error.
    67     if (error != CxeError::None) {
    70     QString errorMsgTxt = getErrorDetails(error);
    68         // start evaluating the error.
    71 
    69         QString errorMsgTxt = getErrorDetails(error);
    72     if(mErrorSeverity != CxuiErrorManager::None) {
    70 
    73         // show the error note to the user.
    71         if(mErrorSeverity != CxuiErrorManager::None) {
    74         launchPopup(errorMsgTxt);
    72             // show the error note to the user.
    75     } else {
    73             launchPopup(errorMsgTxt);
    76         // ignore
    74         } else {
    77     }
    75             // ignore
    78 
    76         }
    79     CX_DEBUG_EXIT_FUNCTION();
    77     }
    80 }
    78 
    81 
    79     CX_DEBUG_EXIT_FUNCTION();
    82 
    80 }
    83 // ---------------------------------------------------------------------------
    81 
    84 // CxuiErrorManager::aboutToClosePopup
    82 
    85 //
    83 /*!
    86 // ---------------------------------------------------------------------------
    84 * Slot that gets called when error note is closed.
    87 //
    85 */
    88 void CxuiErrorManager::aboutToClosePopup()
    86 void CxuiErrorManager::aboutToClosePopup()
    89 {
    87 {
    90     CX_DEBUG_ENTER_FUNCTION();
    88     CX_DEBUG_ENTER_FUNCTION();
    91     // handle any use-cases when the error can be recovered
    89     // handle any use-cases when the error can be recovered
    92     emit errorRecovered();
    90     emit errorRecovered();
    93     CX_DEBUG_EXIT_FUNCTION();
    91     CX_DEBUG_EXIT_FUNCTION();
    94 }
    92 }
    95 
    93 
    96 
    94 
    97 
    95 /*!
    98 // ---------------------------------------------------------------------------
    96 * Helper method for closing the application.
    99 // CxuiErrorManager::closeApp
    97 */
   100 //
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CxuiErrorManager::closeApp()
    98 void CxuiErrorManager::closeApp()
   104 {
    99 {
   105     CX_DEBUG_ENTER_FUNCTION();
   100     CX_DEBUG_ENTER_FUNCTION();
   106     QCoreApplication::quit();
   101     QCoreApplication::quit();
   107     CX_DEBUG_EXIT_FUNCTION();
   102     CX_DEBUG_EXIT_FUNCTION();
   108 }
   103 }
   109 
   104 
   110 
   105 
   111 
   106 
   112 // ---------------------------------------------------------------------------
   107 /*!
   113 // CxuiErrorManager::getErrorDetails
   108 * Helper method to get the error message to use for showing note to user,
   114 // evaluates error for error severity and error note
   109 * and set the severity level, based on given error code.
   115 // ---------------------------------------------------------------------------
   110 * @param error Error code to be analyzed.
       
   111 */
   116 QString CxuiErrorManager::getErrorDetails(CxeError::Id error)
   112 QString CxuiErrorManager::getErrorDetails(CxeError::Id error)
   117 {
   113 {
   118     CX_DEBUG_ENTER_FUNCTION();
   114     CX_DEBUG_ENTER_FUNCTION();
   119     QString msg("No Error");
   115     QString msg("No Error");
   120     switch(error) {
   116     switch(error) {
   127             break;
   123             break;
   128         case CxeError::InUse:
   124         case CxeError::InUse:
   129             mErrorSeverity = CxuiErrorManager::Severe;
   125             mErrorSeverity = CxuiErrorManager::Severe;
   130             msg = hbTrId("txt_cam_info_camera_already_in_use");
   126             msg = hbTrId("txt_cam_info_camera_already_in_use");
   131             break;
   127             break;
       
   128         case CxeError::DiskFull:
       
   129             mErrorSeverity = CxuiErrorManager::Warning;
       
   130             msg = hbTrId("txt_cam_info_memory_full");
   132         default:
   131         default:
   133             break;
   132             break;
   134     }
   133     }
   135     CX_DEBUG_EXIT_FUNCTION();
   134     CX_DEBUG_EXIT_FUNCTION();
   136 
   135 
   137     return msg;
   136     return msg;
   138 }
   137 }
   139 
   138 
   140 
   139 /*!
   141 // ---------------------------------------------------------------------------
   140 *
   142 // CxuiErrorManager::launchPopup
   141 */
   143 // ---------------------------------------------------------------------------
       
   144 void CxuiErrorManager::launchPopup(QString& errorMsgTxt)
   142 void CxuiErrorManager::launchPopup(QString& errorMsgTxt)
   145 {
   143 {
   146     CX_DEBUG_ENTER_FUNCTION();
   144     CX_DEBUG_ENTER_FUNCTION();
   147 
   145 
       
   146     switch (mErrorSeverity) {
       
   147     case CxuiErrorManager::Warning:
       
   148         showLowSeverityNote(errorMsgTxt);
       
   149         break;
       
   150     case CxuiErrorManager::Severe:
       
   151     case CxuiErrorManager::Critical:
       
   152         showHighSeverityNote(errorMsgTxt);
       
   153         break;
       
   154     default:
       
   155         break;
       
   156     }
       
   157 
       
   158     CX_DEBUG_EXIT_FUNCTION();
       
   159 }
       
   160 
       
   161 /*!
       
   162 * Show error note for high severity error.
       
   163 */
       
   164 void CxuiErrorManager::showHighSeverityNote(QString& errorMsgTxt)
       
   165 {
   148     // we always prepare the popup for the new message and hence we load the
   166     // we always prepare the popup for the new message and hence we load the
   149     // popup everytime from document loader
   167     // popup everytime from document loader
   150 
   168 
   151     CX_ASSERT_ALWAYS(mDocumentLoader);
   169     CX_ASSERT_ALWAYS(mDocumentLoader);
   152     bool ok = false;
   170     bool ok = false;
   154     // Use document loader to create popup
   172     // Use document loader to create popup
   155     mDocumentLoader->load(CxUiLayout::ERROR_POPUP_XML, &ok);
   173     mDocumentLoader->load(CxUiLayout::ERROR_POPUP_XML, &ok);
   156     CX_DEBUG(("mErrorMsgPopup load ok=%d", ok));
   174     CX_DEBUG(("mErrorMsgPopup load ok=%d", ok));
   157 
   175 
   158     mErrorMsgPopup = qobject_cast<HbDialog*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_POPUP));
   176     mErrorMsgPopup = qobject_cast<HbDialog*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_POPUP));
   159 
       
   160     CX_ASSERT_ALWAYS(mErrorMsgPopup);
   177     CX_ASSERT_ALWAYS(mErrorMsgPopup);
       
   178 
       
   179     // HbDialog's default background item is replaced with black rectangle
       
   180     QGraphicsRectItem *backgroundItem = new QGraphicsRectItem();
       
   181     QBrush blackBrush = QBrush(Qt::black);
       
   182     backgroundItem->setBrush(blackBrush);
       
   183     QGraphicsItem *origBgItem = mErrorMsgPopup->backgroundItem();
       
   184     backgroundItem->setRect(origBgItem->boundingRect());
       
   185     mErrorMsgPopup->setBackgroundItem(backgroundItem);
   161 
   186 
   162     mErrorMsgPopup->setTimeout(HbDialog::NoTimeout);
   187     mErrorMsgPopup->setTimeout(HbDialog::NoTimeout);
   163     mErrorMsgPopup->setBackgroundFaded(false);
   188     mErrorMsgPopup->setBackgroundFaded(false);
   164 
   189 
   165     // color of standby text is set in the code. It cannot be done in docml
   190     // color of standby text is set in the code. It cannot be done in docml
   180 
   205 
   181     mErrorMsgPopup->show();
   206     mErrorMsgPopup->show();
   182 
   207 
   183     CX_DEBUG_EXIT_FUNCTION();
   208     CX_DEBUG_EXIT_FUNCTION();
   184 }
   209 }
       
   210 
       
   211 /*!
       
   212 * Show error note for low severity error.
       
   213 */
       
   214 void CxuiErrorManager::showLowSeverityNote(QString& errorMsgTxt)
       
   215 {
       
   216     CX_DEBUG_ENTER_FUNCTION();
       
   217     HbMessageBox::warning(errorMsgTxt);
       
   218     CX_DEBUG_EXIT_FUNCTION();
       
   219 }