1 /* |
|
2 * Copyright (c) 2009-2010 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 <QCoreApplication> |
|
19 #include <HbAction> |
|
20 #include <HbDialog> |
|
21 #include <HbMessageBox> |
|
22 #include <HbLabel> |
|
23 #include <HbPushButton> |
|
24 |
|
25 #include "cxutils.h" |
|
26 #include "cxeerror.h" |
|
27 #include "cxeengine.h" |
|
28 #include "cxuienums.h" |
|
29 #include "cxuierrormanager.h" |
|
30 #include "cxuidocumentloader.h" |
|
31 #include "cxecameradevicecontrol.h" |
|
32 |
|
33 |
|
34 /*! |
|
35 * Constructor |
|
36 */ |
|
37 CxuiErrorManager::CxuiErrorManager(CxuiDocumentLoader *documentLoader) : |
|
38 mDocumentLoader(documentLoader), |
|
39 mErrorMsgPopup(NULL), |
|
40 mErrorId(CxeError::None), |
|
41 mErrorSeverity(CxuiErrorManager::None) |
|
42 { |
|
43 CX_DEBUG_ENTER_FUNCTION(); |
|
44 CX_DEBUG_EXIT_FUNCTION(); |
|
45 } |
|
46 |
|
47 /*! |
|
48 * Destructor |
|
49 */ |
|
50 CxuiErrorManager::~CxuiErrorManager() |
|
51 { |
|
52 CX_DEBUG_ENTER_FUNCTION(); |
|
53 CX_DEBUG_EXIT_FUNCTION(); |
|
54 } |
|
55 |
|
56 |
|
57 /*! |
|
58 * Check the error code and show either error popup, warning popup or do nothing, |
|
59 * if "no error" code is given. |
|
60 * @param error Error id. If CxeError::None, no action is taken. Otherwise |
|
61 * either warning or error popup is shown based on the severity of error. |
|
62 * |
|
63 */ |
|
64 void CxuiErrorManager::check(CxeError::Id error) |
|
65 { |
|
66 CX_DEBUG_ENTER_FUNCTION(); |
|
67 mErrorSeverity = CxuiErrorManager::None; |
|
68 |
|
69 if (error != CxeError::None) { |
|
70 mErrorId = error; |
|
71 |
|
72 // start evaluating the error. |
|
73 QString errorText; |
|
74 QString buttonText; |
|
75 getErrorDetails(errorText, buttonText); |
|
76 |
|
77 if (mErrorSeverity != CxuiErrorManager::None) { |
|
78 // Clear the old error if one for some reason exists. |
|
79 clear(); |
|
80 |
|
81 // show the error note to the user. |
|
82 launchPopup(errorText, buttonText); |
|
83 } else { |
|
84 // ignore |
|
85 } |
|
86 } |
|
87 |
|
88 CX_DEBUG_EXIT_FUNCTION(); |
|
89 } |
|
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 } |
|
103 |
|
104 /*! |
|
105 * Slot that gets called when error note is closed. |
|
106 */ |
|
107 void CxuiErrorManager::popupClosed(HbAction *action) |
|
108 { |
|
109 Q_UNUSED(action) |
|
110 |
|
111 CX_DEBUG_ENTER_FUNCTION(); |
|
112 // Dialog or action instance cannot be used anymore. |
|
113 mErrorMsgPopup = NULL; |
|
114 |
|
115 // handle any use-cases when the error can be recovered |
|
116 emit errorPopupClosed(); |
|
117 CX_DEBUG_EXIT_FUNCTION(); |
|
118 } |
|
119 |
|
120 |
|
121 /*! |
|
122 * Helper method for closing the application. |
|
123 */ |
|
124 void CxuiErrorManager::closeApp() |
|
125 { |
|
126 CX_DEBUG_ENTER_FUNCTION(); |
|
127 QCoreApplication::quit(); |
|
128 CX_DEBUG_EXIT_FUNCTION(); |
|
129 } |
|
130 |
|
131 |
|
132 |
|
133 /*! |
|
134 * Helper method to get the error message to use for showing note to user, |
|
135 * and set the severity level, based on given error code. |
|
136 * @param error Error code to be analyzed. |
|
137 */ |
|
138 void CxuiErrorManager::getErrorDetails(QString &errorText, QString &buttonText) |
|
139 { |
|
140 CX_DEBUG_ENTER_FUNCTION(); |
|
141 switch (mErrorId) { |
|
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_button_ok"); |
|
160 break; |
|
161 case CxeError::Died: |
|
162 case CxeError::InitializationFailed: |
|
163 case CxeError::HwNotAvailable: |
|
164 case CxeError::NotReady: |
|
165 default: |
|
166 mErrorSeverity = CxuiErrorManager::Error; |
|
167 errorText = hbTrId("txt_cam_info_error"); |
|
168 buttonText = hbTrId("txt_common_button_close"); |
|
169 break; |
|
170 } |
|
171 CX_DEBUG_EXIT_FUNCTION(); |
|
172 } |
|
173 |
|
174 /*! |
|
175 * Show warning or error popup. |
|
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) |
|
180 { |
|
181 CX_DEBUG_ENTER_FUNCTION(); |
|
182 |
|
183 switch (mErrorSeverity) { |
|
184 case CxuiErrorManager::None: |
|
185 break; |
|
186 case CxuiErrorManager::Warning: |
|
187 showWarningPopup(errorText); |
|
188 break; |
|
189 default: |
|
190 showErrorPopup(errorText, buttonText); |
|
191 break; |
|
192 } |
|
193 |
|
194 mErrorSeverity = CxuiErrorManager::None; |
|
195 |
|
196 CX_DEBUG_EXIT_FUNCTION(); |
|
197 } |
|
198 |
|
199 /*! |
|
200 * Show error note for severe error. |
|
201 */ |
|
202 void CxuiErrorManager::showErrorPopup(const QString &errorText, const QString &buttonText) |
|
203 { |
|
204 // we always prepare the popup for the new message and hence we load the |
|
205 // popup everytime from document loader |
|
206 |
|
207 CX_ASSERT_ALWAYS(mDocumentLoader); |
|
208 bool ok = false; |
|
209 |
|
210 // Use document loader to create popup |
|
211 mDocumentLoader->load(CxUiLayout::ERROR_POPUP_XML, &ok); |
|
212 CX_DEBUG(("mErrorMsgPopup load ok=%d", ok)); |
|
213 |
|
214 mErrorMsgPopup = qobject_cast<HbDialog*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_POPUP)); |
|
215 CX_ASSERT_ALWAYS(mErrorMsgPopup); |
|
216 mErrorMsgPopup->setAttribute(Qt::WA_DeleteOnClose, true); |
|
217 mErrorMsgPopup->setTimeout(HbDialog::NoTimeout); |
|
218 |
|
219 // HbDialog's default background item is replaced with black rectangle |
|
220 QGraphicsRectItem *backgroundItem = new QGraphicsRectItem(); |
|
221 QBrush blackBrush = QBrush(Qt::black); |
|
222 backgroundItem->setBrush(blackBrush); |
|
223 QGraphicsItem *origBgItem = mErrorMsgPopup->backgroundItem(); |
|
224 backgroundItem->setRect(origBgItem->boundingRect()); |
|
225 mErrorMsgPopup->setBackgroundItem(backgroundItem); |
|
226 |
|
227 |
|
228 // color of standby text is set in the code. It cannot be done in docml |
|
229 HbLabel* label = qobject_cast<HbLabel*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_TEXT_WIDGET)); |
|
230 label->setTextColor(Qt::white); |
|
231 label->setPlainText(errorText); |
|
232 |
|
233 HbPushButton *exitButton = qobject_cast<HbPushButton*>(mDocumentLoader->findWidget(CxUiLayout::ERROR_BUTTON_WIDGET)); |
|
234 if (!buttonText.isEmpty()) { |
|
235 // inform ui about error recovery |
|
236 exitButton->setText(buttonText); |
|
237 connect(exitButton, SIGNAL(released()), this, SLOT(closeApp())); |
|
238 exitButton->show(); |
|
239 } |
|
240 |
|
241 emit errorPopupShown(); |
|
242 mErrorMsgPopup->open(this, SLOT(popupClosed(HbAction*))); |
|
243 |
|
244 CX_DEBUG_EXIT_FUNCTION(); |
|
245 } |
|
246 |
|
247 /*! |
|
248 * Show warning note for low severity error. |
|
249 */ |
|
250 void CxuiErrorManager::showWarningPopup(const QString &errorText) |
|
251 { |
|
252 CX_DEBUG_ENTER_FUNCTION(); |
|
253 HbMessageBox::warning(errorText); |
|
254 CX_DEBUG_EXIT_FUNCTION(); |
|
255 } |
|