29 #include <hbdevicedialogtrace_p.h> |
29 #include <hbdevicedialogtrace_p.h> |
30 #include <hbiconanimationmanager.h> |
30 #include <hbiconanimationmanager.h> |
31 #include "hbdeviceprogressdialogwidget_p.h" |
31 #include "hbdeviceprogressdialogwidget_p.h" |
32 #include "hbdeviceprogressdialogpluginerrors_p.h" |
32 #include "hbdeviceprogressdialogpluginerrors_p.h" |
33 |
33 |
|
34 static const char actionTextTag[] = "t:"; |
|
35 |
34 // Constructor |
36 // Constructor |
35 HbDeviceProgressDialogWidget::HbDeviceProgressDialogWidget(HbProgressDialog::ProgressDialogType progressDialogType, |
37 HbDeviceProgressDialogWidget::HbDeviceProgressDialogWidget(HbProgressDialog::ProgressDialogType progressDialogType, |
36 const QVariantMap ¶meters) : HbProgressDialog(progressDialogType) |
38 const QVariantMap ¶meters) : HbProgressDialog(progressDialogType) |
37 { |
39 { |
38 TRACE_ENTRY |
40 TRACE_ENTRY |
39 mLastError = NoError; |
41 mLastError = NoError; |
40 mProgressDialogType = progressDialogType; |
42 mProgressDialogType = progressDialogType; |
41 mShowEventReceived = false; |
43 mShowEventReceived = false; |
42 mPrimaryAction = 0; |
44 mAction = 0; |
43 resetProperties(); |
45 resetProperties(); |
44 constructDialog(parameters); |
46 constructDialog(parameters); |
45 if (!mPrimaryAction) { |
47 if (!mAction) { |
46 // If HbProgressDialog default button is used, connect into its triggered signal. |
48 // If HbProgressDialog default button is used, connect into its triggered signal. |
47 HbAction *action = primaryAction(); |
49 QAction *act = action(Cancel); |
48 if (action) { |
50 if (act) { |
49 connect(action, SIGNAL(triggered()), SLOT(primaryActionTriggered())); |
51 connect(act, SIGNAL(triggered()), SLOT(cancelTriggered())); |
50 } |
52 } |
51 } |
53 } |
52 setBackgroundFaded(true); |
54 setBackgroundFaded(true); |
53 TRACE_EXIT |
55 TRACE_EXIT |
54 } |
56 } |
55 |
57 |
56 // Destructor |
58 // Destructor |
57 HbDeviceProgressDialogWidget::~HbDeviceProgressDialogWidget() |
59 HbDeviceProgressDialogWidget::~HbDeviceProgressDialogWidget() |
58 { |
60 { |
59 delete mPrimaryAction; |
61 delete mAction; |
60 } |
62 } |
61 |
63 |
62 // Set parameters |
64 // Set parameters |
63 bool HbDeviceProgressDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters) |
65 bool HbDeviceProgressDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters) |
64 { |
66 { |
198 if (mIconName != iconName) { |
200 if (mIconName != iconName) { |
199 mIconName = iconName; |
201 mIconName = iconName; |
200 setIcon(HbIcon(mIconName)); |
202 setIcon(HbIcon(mIconName)); |
201 } |
203 } |
202 TRACE_EXIT |
204 TRACE_EXIT |
203 return; |
205 } |
204 } |
206 |
205 |
207 QString HbDeviceProgressDialogWidget::cancelAction() const |
206 QString HbDeviceProgressDialogWidget::primaryActionText() const |
208 { |
207 { |
209 TRACE_ENTRY |
208 HbAction *action = primaryAction(); |
210 QAction *act = action(Cancel); |
209 return action ? action->text() : QString(); |
211 QString actionData; |
210 } |
212 if (act) { |
211 |
213 actionData.append(actionTextTag); |
212 void HbDeviceProgressDialogWidget::setPrimaryActionText(QString &actionText) |
214 actionData.append(act->text()); |
213 { |
215 } |
214 TRACE_ENTRY |
216 TRACE_EXIT |
215 HbAction *action = primaryAction(); |
217 return actionData; |
216 if (action) { |
218 } |
217 action->setText(actionText); |
219 |
|
220 void HbDeviceProgressDialogWidget::setCancelAction(QString &actionData) |
|
221 { |
|
222 TRACE_ENTRY |
|
223 parseActionData(actionData); // parse data to get action text |
|
224 if (!actionData.isNull()) { |
|
225 // Setting action |
|
226 QAction *act = action(Cancel); |
|
227 if (act) { |
|
228 act->setText(actionData); |
|
229 } else { |
|
230 if (!mAction) { |
|
231 mAction = new HbAction(actionData, 0); |
|
232 connect(mAction, SIGNAL(triggered()), this, SLOT(cancelTriggered())); |
|
233 } else { |
|
234 mAction->setText(actionData); |
|
235 } |
|
236 addAction(mAction); |
|
237 } |
|
238 } else { // Remove action |
|
239 // If there is a message box's default action, disconnect from it. |
|
240 QAction *act = action(Cancel); |
|
241 if (act && mAction == 0) { |
|
242 act->disconnect(SIGNAL(triggered()), this, SLOT(cancelTriggered())); |
|
243 } |
|
244 if (act) { |
|
245 removeAction(act); |
|
246 } |
|
247 } |
|
248 TRACE_EXIT |
|
249 } |
|
250 |
|
251 QAction *HbDeviceProgressDialogWidget::action(ActionIndex index) const |
|
252 { |
|
253 QList<QAction*> actionList = actions(); |
|
254 return actionList.count() > index ? actionList[index] : 0; |
|
255 } |
|
256 |
|
257 void HbDeviceProgressDialogWidget::parseActionData(QString &data) |
|
258 { |
|
259 const QString textTag(actionTextTag); |
|
260 if (data.startsWith(textTag)) { |
|
261 data.remove(0, textTag.length()); |
218 } else { |
262 } else { |
219 if (!mPrimaryAction) { |
263 data.clear(); |
220 mPrimaryAction = new HbAction(actionText); |
264 } |
221 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(primaryActionTriggered())); |
|
222 } else { |
|
223 mPrimaryAction->setText(actionText); |
|
224 } |
|
225 setPrimaryAction(mPrimaryAction); |
|
226 } |
|
227 TRACE_EXIT |
|
228 } |
|
229 |
|
230 bool HbDeviceProgressDialogWidget::primaryActionNull() const |
|
231 { |
|
232 return primaryAction() == 0; |
|
233 } |
|
234 |
|
235 void HbDeviceProgressDialogWidget::setPrimaryActionNull(bool isNull) |
|
236 { |
|
237 TRACE_ENTRY |
|
238 if (isNull) { |
|
239 // If there is a message box's default action, disconnect from it. |
|
240 HbAction *action = primaryAction(); |
|
241 if (action && mPrimaryAction == 0) { |
|
242 action->disconnect(SIGNAL(triggered()), this, SLOT(primaryActionTriggered())); |
|
243 } |
|
244 setPrimaryAction(0); |
|
245 } else { |
|
246 QString text = mPrimaryAction ? mPrimaryAction->text() : QString(); |
|
247 setPrimaryActionText(text); |
|
248 } |
|
249 TRACE_EXIT |
|
250 } |
265 } |
251 |
266 |
252 QString HbDeviceProgressDialogWidget::animationDefinition() const |
267 QString HbDeviceProgressDialogWidget::animationDefinition() const |
253 { |
268 { |
254 return mAnimationDefinition; |
269 return mAnimationDefinition; |
275 HbProgressDialog::showEvent(event); |
290 HbProgressDialog::showEvent(event); |
276 mShowEventReceived = true; |
291 mShowEventReceived = true; |
277 } |
292 } |
278 |
293 |
279 // Primary action triggered |
294 // Primary action triggered |
280 void HbDeviceProgressDialogWidget::primaryActionTriggered() |
295 void HbDeviceProgressDialogWidget::cancelTriggered() |
281 { |
296 { |
282 TRACE_ENTRY |
297 TRACE_ENTRY |
283 QVariantMap data; |
298 QVariantMap data; |
284 data.insert("act", "p"); |
299 data.insert("act", "c"); |
285 emit deviceDialogData(data); |
300 emit deviceDialogData(data); |
286 TRACE_EXIT |
301 TRACE_EXIT |
287 } |
302 } |