src/hbplugins/devicedialogs/deviceprogressdialogplugin/hbdeviceprogressdialogwidget.cpp
changeset 2 06ff229162e9
parent 0 16d8024aca5e
child 23 e6ad4ef83b23
child 34 ed14f46c0e55
--- a/src/hbplugins/devicedialogs/deviceprogressdialogplugin/hbdeviceprogressdialogwidget.cpp	Mon May 03 12:48:33 2010 +0300
+++ b/src/hbplugins/devicedialogs/deviceprogressdialogplugin/hbdeviceprogressdialogwidget.cpp	Fri May 14 16:09:54 2010 +0300
@@ -31,6 +31,8 @@
 #include "hbdeviceprogressdialogwidget_p.h"
 #include "hbdeviceprogressdialogpluginerrors_p.h"
 
+static const char actionTextTag[] = "t:";
+
 // Constructor
 HbDeviceProgressDialogWidget::HbDeviceProgressDialogWidget(HbProgressDialog::ProgressDialogType progressDialogType,
     const QVariantMap &parameters) : HbProgressDialog(progressDialogType)
@@ -39,14 +41,14 @@
     mLastError = NoError;
     mProgressDialogType = progressDialogType;
     mShowEventReceived = false;
-    mPrimaryAction = 0;
+    mAction = 0;
     resetProperties();
     constructDialog(parameters);
-    if (!mPrimaryAction) {
+    if (!mAction) {
         // If HbProgressDialog default button is used, connect into its triggered signal.
-        HbAction *action = primaryAction();
-        if (action) {
-            connect(action, SIGNAL(triggered()), SLOT(primaryActionTriggered()));
+        QAction *act = action(Cancel);
+        if (act) {
+            connect(act, SIGNAL(triggered()), SLOT(cancelTriggered()));
         }
     }
     setBackgroundFaded(true);
@@ -56,7 +58,7 @@
 // Destructor
 HbDeviceProgressDialogWidget::~HbDeviceProgressDialogWidget()
 {
-    delete mPrimaryAction;
+    delete mAction;
 }
 
 // Set parameters
@@ -200,53 +202,66 @@
         setIcon(HbIcon(mIconName));
     }
     TRACE_EXIT
-    return;
 }
 
-QString HbDeviceProgressDialogWidget::primaryActionText() const
+QString HbDeviceProgressDialogWidget::cancelAction() const
 {
-    HbAction *action = primaryAction();
-    return action ? action->text() : QString();
+    TRACE_ENTRY
+    QAction *act = action(Cancel);
+	QString actionData;
+    if (act) {
+        actionData.append(actionTextTag);
+        actionData.append(act->text());
+    }
+    TRACE_EXIT
+    return actionData;
 }
 
-void HbDeviceProgressDialogWidget::setPrimaryActionText(QString &actionText)
+void HbDeviceProgressDialogWidget::setCancelAction(QString &actionData)
 {
     TRACE_ENTRY
-    HbAction *action = primaryAction();
-    if (action) {
-        action->setText(actionText);
-    } else {
-        if (!mPrimaryAction) {
-            mPrimaryAction = new HbAction(actionText);
-            connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(primaryActionTriggered()));
+    parseActionData(actionData); // parse data to get action text
+    if (!actionData.isNull()) {
+        // Setting action
+        QAction *act = action(Cancel);
+        if (act) {
+            act->setText(actionData);
         } else {
-            mPrimaryAction->setText(actionText);
+            if (!mAction) {
+                mAction = new HbAction(actionData, 0);
+                connect(mAction, SIGNAL(triggered()), this, SLOT(cancelTriggered()));
+            } else {
+                mAction->setText(actionData);
+            }
+            addAction(mAction);
         }
-        setPrimaryAction(mPrimaryAction);
+    } else { // Remove action
+        // If there is a message box's default action, disconnect from it.
+        QAction *act = action(Cancel);
+        if (act && mAction == 0) {
+            act->disconnect(SIGNAL(triggered()), this, SLOT(cancelTriggered()));
+        }
+        if (act) {
+            removeAction(act);
+        }
     }
     TRACE_EXIT
 }
 
-bool HbDeviceProgressDialogWidget::primaryActionNull() const
+QAction *HbDeviceProgressDialogWidget::action(ActionIndex index) const
 {
-    return primaryAction() == 0;
+    QList<QAction*> actionList = actions();
+    return actionList.count() > index ? actionList[index] : 0;
 }
 
-void HbDeviceProgressDialogWidget::setPrimaryActionNull(bool isNull)
+void HbDeviceProgressDialogWidget::parseActionData(QString &data)
 {
-    TRACE_ENTRY
-    if (isNull) {
-        // If there is a message box's default action, disconnect from it.
-        HbAction *action = primaryAction();
-        if (action && mPrimaryAction == 0) {
-            action->disconnect(SIGNAL(triggered()), this, SLOT(primaryActionTriggered()));
-        }
-        setPrimaryAction(0);
+    const QString textTag(actionTextTag);
+    if (data.startsWith(textTag)) {
+        data.remove(0, textTag.length());
     } else {
-        QString text = mPrimaryAction ? mPrimaryAction->text() : QString();
-        setPrimaryActionText(text);
+        data.clear();
     }
-    TRACE_EXIT
 }
 
 QString HbDeviceProgressDialogWidget::animationDefinition() const
@@ -277,11 +292,11 @@
 }
 
 // Primary action triggered
-void HbDeviceProgressDialogWidget::primaryActionTriggered()
+void HbDeviceProgressDialogWidget::cancelTriggered()
 {
     TRACE_ENTRY
     QVariantMap data;
-    data.insert("act", "p");
+    data.insert("act", "c");
     emit deviceDialogData(data);
     TRACE_EXIT
 }