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