phonesettings/cpphonesettingsplugins/divertplugin/src/cpdivertplugingroup.cpp
changeset 45 6b911d05207e
parent 37 ba76fc04e6c2
child 46 bc5a64e5bc3c
--- a/phonesettings/cpphonesettingsplugins/divertplugin/src/cpdivertplugingroup.cpp	Fri Jun 04 10:19:18 2010 +0100
+++ b/phonesettings/cpphonesettingsplugins/divertplugin/src/cpdivertplugingroup.cpp	Wed Jun 23 18:12:20 2010 +0300
@@ -15,7 +15,6 @@
  *
  */
 
-#include <QEventLoop>
 #include <hbdataformmodel.h>
 #include <hbdataformmodelitem.h>
 #include <hblineedit.h>
@@ -29,20 +28,16 @@
 #include <hblistwidgetitem.h>
 #include <hblabel.h>
 #include <cpitemdatahelper.h>
-#include "cpdivertselectionitem.h"
 #include "cpdivertplugingroup.h"
 #include "cpplugincommon.h"
 #include "cpphonenotes.h"
 #include "cppluginlogging.h"
 #include "cpdivertitemdata.h"
-#include "cpdivertselectioncustomitem.h"
 
 Q_DECLARE_METATYPE(PsCallDivertingCondition)
 Q_DECLARE_METATYPE(PsServiceGroup)
 
 // CONSTANTS 
-const QString KVoiceMail("voiceMail");
-const QString KVideoMail("voiceMail");
 const QString KOtherNumber("otherNumber");
 
 /*!
@@ -65,7 +60,8 @@
        m_activeProgressNoteId(0),
        m_divertToVoiceMailBox(false),
        m_helper(helper),
-       m_divertTimeout(0)
+       m_activateDivertPhase(NonePhase),
+       m_dialog(NULL)
 {
     DPRINT << ": IN";
     
@@ -105,9 +101,6 @@
         SIGNAL(requestDone()),
         this,
         SLOT(divertRequestProcessed()));
-
-    // Create custom item prototype
-    m_helper.addItemPrototype(new CpDivertSelectionItem());
     
     // Listen form item visibility change
     m_helper.connectToForm(
@@ -116,9 +109,7 @@
     // Create grouped setting items
     createVoiceCallItems(this);
     createVideoCallItems(this);
-    
-    m_eventLoop = new QEventLoop(this); 
-    
+        
     DPRINT << ": OUT";
 }
 
@@ -166,8 +157,8 @@
             hbTrId("txt_phone_setlabel_if_not_answered"),
             hbTrId("txt_phone_setlabel_if_not_answered"), true,
             page);
-    m_DataItemVoiceIfNotAnswered->setContentWidgetData(
-            "timeoutText", hbTrId("txt_phone_setlabel_delay"));
+    m_DataItemVoiceIfNotAnswered->setDescription(
+            hbTrId("txt_phone_setlabel_divert_delay_ln_seconds", 0));
 
     m_DataItemVoiceIfOutOfReach = createDivertItem(
             DivertConditionNotReachable,
@@ -192,6 +183,7 @@
 void CpDivertPluginGroup::createVideoCallItems(CpSettingFormItemData *parent)
 {
     DPRINT << ": IN";
+    
     CpSettingFormItemData *page = new CpSettingFormItemData(
             HbDataFormModelItem::GroupPageItem,
             hbTrId("txt_phone_setlabel_service_val_video_divert"));
@@ -218,9 +210,9 @@
             hbTrId("txt_phone_setlabel_if_not_answered"),
             hbTrId("txt_phone_setlabel_if_not_answered"), true,
             page);
-    m_DataItemVideoIfNotAnswered->setContentWidgetData(
-            "timeoutText", hbTrId("txt_phone_setlabel_delay"));
-
+    m_DataItemVideoIfNotAnswered->setDescription(
+            hbTrId("txt_phone_setlabel_divert_delay_ln_seconds", 0));
+    
     m_DataItemVideoIfOutOfReach = createDivertItem(
             DivertConditionNotReachable,
             ServiceGroupData,
@@ -250,13 +242,13 @@
         CpSettingFormItemData *parent)
 {
     DPRINT << ": IN";
-
+    
     CpDivertItemData *item = new CpDivertItemData(
-        static_cast<HbDataFormModelItem::DataItemType>
-            (CpDivertSelectionItem::CpDivertSelectionItemId), 
+        HbDataFormModelItem::CheckBoxItem,
             label,
             m_helper,
             parent);
+    
     QVariant conditionVar;
     conditionVar.setValue(condition);
     item->setProperty("condition", conditionVar);
@@ -265,6 +257,7 @@
     item->setProperty("serviceGroup", serviceGroupVar);
     item->setProperty("queryLabel", queryLabel);
     item->setProperty("needTimeoutInfo", needTimeoutInfo);
+    item->setProperty("divertItem", true);
     item->setEnabled(false);
     
     // Connect signals
@@ -273,6 +266,7 @@
         this, SLOT(changeDivertingStateRequested(CpDivertItemData&)));
     
     parent->appendChild(item);
+    
     DPRINT << ": OUT";
     return item;
 }
@@ -286,18 +280,21 @@
     DPRINT << "item:" << item;
     
     HbDataFormModelItem* modelItem = 
-            qobject_cast<const HbDataFormModel*>(item.model())->itemFromIndex(item);
+        qobject_cast<const HbDataFormModel*>(item.model())->itemFromIndex(item);
+    if (!isDivertSettingsItem(modelItem)) {
+        return;
+    }
     
-    if (!modelItem->contentWidgetData("number").isValid() &&
-        (static_cast<HbDataFormModelItem::DataItemType>
-            (CpDivertSelectionItem::CpDivertSelectionItemId == modelItem->type()))){
+    bool isInitialStatusQueryDoneForItem = 
+        modelItem->contentWidgetData("text").isValid();
+    if (!isInitialStatusQueryDoneForItem) {
         CpDivertItemData *item = static_cast<CpDivertItemData*>(modelItem); 
-        if(qvariant_cast<PsCallDivertingCondition>(item->property("condition")) !=
+        if (qvariant_cast<PsCallDivertingCondition>(item->property("condition")) !=
                 DivertConditionAllConditionalCases) {
             addToDivertingRequestQueue(CheckDivertStatus, *item);
         }
     }
-
+    
     DPRINT << ": OUT";
 }
 
@@ -308,6 +305,7 @@
         DivertRequest request, CpDivertItemData &item)
 {
     DPRINT << ": IN";
+    
     CpDivertRequestQueueItem i;
     i.request = request;
     i.item = &item;
@@ -322,7 +320,6 @@
         }
     }
 
-
     DPRINT << ": OUT";
 }
 
@@ -332,6 +329,7 @@
 void CpDivertPluginGroup::divertRequestProcessed()
 {
     DPRINT << ": IN";
+    
     // Remove previous request and process next one
     if (!m_divertRequestQueue.isEmpty()) {
         m_divertRequestQueue.dequeue();
@@ -353,19 +351,28 @@
         PsServiceGroup serviceGroup,
         PsCallDivertingCondition condition,
         PsCallDivertingStatus status,
-        const QString& number, int timeout)
+        const QString& aNumber, int aTimeout)
 {
     DPRINT << ": IN";
     
-    CpDivertSelectionCustomitem::State itemState = 
-        CpDivertSelectionCustomitem::Disabled;
+    Qt::CheckState itemState = Qt::Unchecked;
     if (status == DivertingStatusActive) {
-        itemState = CpDivertSelectionCustomitem::Enabled;
+        itemState = Qt::Checked;
     } else if (status == DivertingStatusInactive) {
-        itemState = CpDivertSelectionCustomitem::Deactivated;
+        itemState = Qt::PartiallyChecked;
     } else {
-        itemState = CpDivertSelectionCustomitem::Disabled;
+        itemState = Qt::Unchecked;
     }
+
+    QString number = aNumber;
+    int timeout = aTimeout;
+    if (Qt::PartiallyChecked == itemState) {
+        number = QString("");
+        timeout = 0;
+    }
+    
+    QVariant numberValue;
+    numberValue.setValue(number);
     
     switch (condition) {
     case DivertConditionAllConditionalCases:
@@ -381,24 +388,35 @@
     case DivertConditionNoReply:
     case DivertConditionNotReachable:
         if (serviceGroup & ServiceGroupVoice) {
-            item(ServiceGroupVoice, condition)->setContentWidgetData("number", number);
-            item(ServiceGroupVoice, condition)->setContentWidgetData("timeout", timeout);
-            item(ServiceGroupVoice, condition)->setContentWidgetData("state", itemState);
-            item(ServiceGroupVoice, condition)->setEnabled(true);
+            CpSettingFormItemData* itemData = item(ServiceGroupVoice, condition); 
+            itemData->setContentWidgetData("text", numberValue);
+            if (DivertConditionNoReply == condition) {
+                itemData->setDescription(
+                    hbTrId("txt_phone_setlabel_divert_delay_ln_seconds", timeout));
+            }
+            itemData->setContentWidgetData("checkState", itemState);
+            itemData->setEnabled(true);
         }
         
         if (serviceGroup & ServiceGroupData) {
-            item(ServiceGroupData, condition)->setContentWidgetData("number", number);
-            item(ServiceGroupData, condition)->setContentWidgetData("timeout", timeout);
-            item(ServiceGroupData, condition)->setContentWidgetData("state", itemState);
-            item(ServiceGroupData, condition)->setEnabled(true);
+            CpSettingFormItemData* itemData = item(ServiceGroupData, condition);
+            itemData->setContentWidgetData("text", numberValue);
+            if (DivertConditionNoReply == condition) {
+                itemData->setDescription(
+                    hbTrId("txt_phone_setlabel_divert_delay_ln_seconds", timeout));
+            }
+            itemData->setContentWidgetData("checkState", itemState);
+            itemData->setEnabled(true);
         }
+        
         break;
     case DivertConditionAllCalls:
     case DivertConditionUnknown:
     default:
         break;
     }
+    
+    DPRINT << ": OUT";
 }
 
 /*!
@@ -408,16 +426,23 @@
         PsServiceGroup serviceGroup, PsCallDivertingCondition condition)
 {
     DPRINT << ": IN";
+    
     if (serviceGroup & ServiceGroupVoice) {
-        item(ServiceGroupVoice, condition)->setContentWidgetData("state",
-            item(ServiceGroupVoice, condition)->contentWidgetData("state"));
+        CpSettingFormItemData* itemData = item(ServiceGroupVoice, condition);
+        int checkState = itemData->contentWidgetData("checkState").toInt();
+        int revertedCheckState = 
+            Qt::Checked == checkState ? Qt::Unchecked : Qt::Checked;
+        itemData->setContentWidgetData("checkState", revertedCheckState);
     }
     
     if (serviceGroup & ServiceGroupData) {
-        item(ServiceGroupData, condition)->setContentWidgetData("state",
-            item(ServiceGroupData, condition)->contentWidgetData("state"));
+        CpSettingFormItemData* itemData = item(ServiceGroupData, condition);
+        int checkState = itemData->contentWidgetData("checkState").toInt();
+        int revertedCheckState = 
+            Qt::Checked == checkState ? Qt::Unchecked : Qt::Checked;
+        itemData->setContentWidgetData("checkState", revertedCheckState);
     }
-
+    
     DPRINT << ": OUT";
 }
 
@@ -427,6 +452,8 @@
 CpSettingFormItemData* CpDivertPluginGroup::item(
         PsService service, PsCallDivertingCondition condition)
 {
+    DPRINT << ": IN";
+    
     CpSettingFormItemData *ret = 0;
     switch (condition) {
         case DivertConditionUnconditional:
@@ -470,6 +497,8 @@
             break;
     }
     Q_CHECK_PTR(ret);
+    
+    DPRINT << ": OUT";
     return ret;
 }
 
@@ -485,61 +514,40 @@
     }
     CpDivertRequestQueueItem request = m_divertRequestQueue.head();
     // Command param
-    PSCallDivertingCommand divertCommand;
-    divertCommand.iServiceGroup = qvariant_cast<PsServiceGroup>(
+    m_divertCommand.iServiceGroup = qvariant_cast<PsServiceGroup>(
             request.item->property("serviceGroup"));
-    divertCommand.iCondition = qvariant_cast<PsCallDivertingCondition>(
+    m_divertCommand.iCondition = qvariant_cast<PsCallDivertingCondition>(
             request.item->property("condition"));
-    divertCommand.iStatus = DivertingStatusUnknown;
-    divertCommand.iNumber = "";
-    divertCommand.iNoReplyTimer = 0;
+    m_divertCommand.iStatus = DivertingStatusUnknown;
+    m_divertCommand.iNumber = "";
+    m_divertCommand.iNoReplyTimer = 0;
 
     switch (request.request) {
         case ActivateDivert: {
             DPRINT << "activate";
-            divertCommand.iSetting = RegisterDiverting;
-            if (popUpVoiceNumberListQuery(
-                    request.item->property("queryLabel").toString(),
-                    divertCommand.iNumber,
-                    divertCommand.iServiceGroup)) {
-                if (request.item->property("needTimeoutInfo").toBool()) {
-                    if (popUpTimerQuery(divertCommand.iNoReplyTimer)) {
-                        setCallDiverting(divertCommand);
-                    } else {
-                        // Query was cancelled
-                        revertItemData(
-                                divertCommand.iServiceGroup, 
-                                divertCommand.iCondition);
-                        m_divertRequestQueue.clear();
-                    }
-                } else {
-                    setCallDiverting(divertCommand);
-                }
-            } else {
-                // Query was cancelled
-                revertItemData(
-                        divertCommand.iServiceGroup, 
-                        divertCommand.iCondition);
-                m_divertRequestQueue.clear();
-            }
+            m_divertCommand.iSetting = RegisterDiverting;
+            m_activateDivertPhase = PopUpVoiceNumberListQueryPhase;
+            popUpVoiceNumberListQuery(
+                request.item->property("queryLabel").toString(),
+                        m_divertCommand.iServiceGroup);
         }
             break;
         case DeactivateDivert: {
             DPRINT << "deactivate";
-            divertCommand.iSetting = EraseDiverting;
-            setCallDiverting(divertCommand);
+            m_divertCommand.iSetting = EraseDiverting;
+            setCallDiverting(m_divertCommand);
         }
             break;
         case CheckDivertStatus: {
             DPRINT << "check status";
             m_callDivertingWrapper->getCallDivertingStatus(
-                divertCommand.iServiceGroup,
-                divertCommand.iCondition,
-                bscParam(divertCommand.iServiceGroup) );
+                m_divertCommand.iServiceGroup,
+                m_divertCommand.iCondition,
+                bscParam(m_divertCommand.iServiceGroup) );
             
             if (!CpPhoneNotes::instance()->noteShowing()) {
                 CpPhoneNotes::instance()->showGlobalProgressNote(
-                        m_activeProgressNoteId, hbTrId("txt_phone_info_requesting"));
+                        m_activeProgressNoteId, hbTrId("txt_common_info_requesting"));
             }
         }
             break;
@@ -559,12 +567,11 @@
 {
     DPRINT << ": IN";
     
-    DivertRequest event=ActivateDivert;
-    if (CpDivertSelectionCustomitem::Enabled == 
-            item.contentWidgetData("state").toInt()) {
+    DivertRequest event = ActivateDivert;
+    if (Qt::Checked == item.contentWidgetData("checkState").toInt()) {
+        event = ActivateDivert;
+    } else {
         event = DeactivateDivert;
-    } else {
-        event = ActivateDivert;
     }
     
     addToDivertingRequestQueue(event, item);
@@ -601,44 +608,27 @@
     switch(aSetting.iStatus) {
         case DivertingStatusActive:
             if (aPlural) {
-                CpPhoneNotes::instance()->showGlobalNote(m_activeNoteId,
-                    hbTrId("txt_phone_info_diverts_activated"), 
-                    HbMessageBox::MessageTypeInformation);
+                CpPhoneNotes::instance()->showNotificationDialog(hbTrId("txt_phone_info_diverts_activated"));
             } else {
-                CpPhoneNotes::instance()->showGlobalNote(m_activeNoteId,
-                    hbTrId("txt_phone_info_divert_activated"), 
-                    HbMessageBox::MessageTypeInformation);
+                CpPhoneNotes::instance()->showNotificationDialog(hbTrId("txt_phone_info_divert_activated"));
             }
             if (!m_divertToVoiceMailBox) {
                 // Number, except vmbx number, will be added to defaultnumber list
                 m_callDivertingWrapper->setNewDefaultNumber(aSetting.iNumber);
             }
-            // Diverting calls does not affect Internet calls
-            if (Tools::voipSupported() &&
-                    (aSetting.iServiceGroup & ServiceGroupVoice)) {
-                CpPhoneNotes::instance()->showGlobalNote(m_activeNoteId,
-                    hbTrId("Diverting calls does not affect Internet calls"), 
-                    HbMessageBox::MessageTypeInformation);
-            }
             break;
         case DivertingStatusNotRegistered:  
         case DivertingStatusInactive:
             if (aPlural) {
-                CpPhoneNotes::instance()->showGlobalNote(m_activeNoteId,
-                    hbTrId("txt_phone_info_diverts_deactivated"), 
-                    HbMessageBox::MessageTypeInformation);
+                CpPhoneNotes::instance()->showNotificationDialog(hbTrId("txt_phone_info_diverts_deactivated"));
             } else {
-                CpPhoneNotes::instance()->showGlobalNote(m_activeNoteId,
-                    hbTrId("txt_phone_info_divert_deactivated"), 
-                    HbMessageBox::MessageTypeInformation);
+                CpPhoneNotes::instance()->showNotificationDialog(hbTrId("txt_phone_info_divert_deactivated"));
             }
             break;
         case DivertingStatusNotProvisioned:
         case DivertingStatusUnknown:
         default:
-            CpPhoneNotes::instance()->showGlobalNote(m_activeNoteId,
-                hbTrId("txt_phone_info_request_not_completed"), 
-                HbMessageBox::MessageTypeInformation);
+            CpPhoneNotes::instance()->showNotificationDialog(hbTrId("txt_phone_info_request_not_completed"));
     }
     
     DPRINT << ": OUT";
@@ -704,65 +694,76 @@
 /*!
   CpDivertPluginGroup::popUpVoiceNumberListQuery.
  */
-bool CpDivertPluginGroup::popUpVoiceNumberListQuery(
-        const QString& heading, QString& result, PsServiceGroup serviceGroup)
+void CpDivertPluginGroup::popUpVoiceNumberListQuery(
+        const QString& heading, PsServiceGroup serviceGroup)
 {
     DPRINT << ": IN";
     
-    bool requestOK(false);
-
-    if (!m_eventLoop->isRunning()){
-        m_divertNumber = ""; 
-        m_divertToVoiceMailBox = false;
-        QStringList defNumbers;
-        HbDialog *dialog = createDialog(heading);
-        m_voiceNumberList = new HbListWidget(dialog);
-        if (serviceGroup == ServiceGroupVoice) {
-            addItemToListWidget(
-                    m_voiceNumberList, hbTrId("txt_phone_setlabel_voice_mbx"), KVoiceMail );
-        } else if(serviceGroup == ServiceGroupData) {
-            // TODO: Implement video voicemail
-        }
+    m_divertCommand.iNumber = ""; 
+    m_divertToVoiceMailBox = false;
+    QStringList defNumbers;
+    QScopedPointer<HbDialog> dialog(createDialog(heading));
+    HbListWidget *list = new HbListWidget(dialog.data());
     
-        // Add "old" divert number to list
-        m_callDivertingWrapper->getDefaultNumbers(defNumbers);
-        int count(defNumbers.count());
-        for (int i = 0; i < count; i++) {
-            addItemToListWidget(m_voiceNumberList, defNumbers[i], defNumbers[i]);
-        }
-        addItemToListWidget(m_voiceNumberList, hbTrId("txt_phone_list_enter_number_manually"), KOtherNumber );
-        dialog->setContentWidget(m_voiceNumberList);
+    QString vmbxNumber;
+    int vmbxErr = 0;
+    if (serviceGroup == ServiceGroupVoice) {
+        vmbxErr = m_callDivertingWrapper->getVoiceMailBoxNumber(
+                vmbxNumber, ServiceGroupVoice);
         
-        // Connect list item activation signal to close the popup
-        QObject::connect(m_voiceNumberList, 
-                SIGNAL(activated(HbListWidgetItem*)), 
-                dialog, 
-                SLOT(close()), 
-                Qt::UniqueConnection);
+    } else if(serviceGroup == ServiceGroupData) {
+        vmbxErr = m_callDivertingWrapper->getVoiceMailBoxNumber(
+                vmbxNumber, ServiceGroupData);
         
-        // Sets the "Cancel"-action/button
-        HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
-        dialog->addAction(cancelAction);
-        QObject::connect(cancelAction, 
-                SIGNAL(triggered(bool)), 
-                dialog, 
-                SLOT(close()));
-        
-        dialog->open(this, SLOT(voiceNumberListQueryClosed(HbAction *))); 
-        
-        QPointer<QObject> guard = this;
-        m_eventLoop->exec(); 
-        if (guard.isNull()) {
-            requestOK = false;
-        } else if (!m_divertNumber.isEmpty()) {
-            result = m_divertNumber;
-            requestOK = true;
-        }    
+    } else {
+        vmbxErr = -1;
+        // Skip
     }
     
-    DPRINT << ": OUT : result:" << result;
-    DPRINT << ": OUT : requestOK :" << requestOK;
-    return requestOK;
+    if (!vmbxErr) {
+        addItemToListWidget(
+            list, 
+            hbTrId("txt_phone_setlabel_voice_mbx"), 
+            vmbxNumber );
+    }
+
+    // Add "old" divert number to list
+    m_callDivertingWrapper->getDefaultNumbers(defNumbers);
+    int count(defNumbers.count());
+    for (int i = 0; i < count; i++) {
+        addItemToListWidget(list, defNumbers[i], defNumbers[i]);
+    }
+    addItemToListWidget(
+            list, 
+            hbTrId("txt_phone_list_enter_number_manually"), 
+            KOtherNumber );
+    dialog->setContentWidget(list);
+    
+    // Connect list item activation signal to close the popup
+    QObject::connect(list, 
+            SIGNAL(activated(HbListWidgetItem*)), 
+            dialog.data(), 
+            SLOT(close()), 
+            Qt::UniqueConnection);
+    
+    // Sets the "Cancel"-action/button
+    HbAction *cancelAction = new HbAction(hbTrId(
+            "txt_common_button_cancel"), 
+            dialog.data());
+    dialog->addAction(cancelAction);
+    QObject::connect(cancelAction, 
+            SIGNAL(triggered(bool)), 
+            dialog.data(), 
+            SLOT(close()));
+    
+    dialog->open(this, SLOT(voiceNumberListQueryClosed(HbAction *)));
+    if (m_dialog) {
+        m_dialog->deleteLater();
+        m_dialog = NULL;
+    }
+    m_dialog = dialog.take();
+    
+    DPRINT << ": OUT";
 }
 
 /*!
@@ -771,40 +772,67 @@
 void CpDivertPluginGroup::voiceNumberListQueryClosed(HbAction* action)
 {
     DPRINT << ": IN";
+    HbListWidget *list = NULL;
     
-    bool exitLoop(true); 
+    if (m_dialog) {
+        bool err = QObject::disconnect(m_dialog->contentWidget(), 
+            SIGNAL(activated(HbListWidgetItem*)), 
+            m_dialog, 
+            SLOT(close()));
+        list = qobject_cast<HbListWidget*>(m_dialog->contentWidget());
+        m_dialog->deleteLater();
+        m_dialog = NULL;
+    }
     
     // Enter if cancel wasn't selected 
-    if (!action) {  
-        // Update the view with selected text
-        QString data = m_voiceNumberList->currentItem()->data().toString();
-        DPRINT << ": data: " << data; 
+    if (!action) {
+        QString data;
+        QString text;
         
-        if (data == KVoiceMail) {
-            m_callDivertingWrapper->getVoiceMailBoxNumber(m_divertNumber);
-            if (!m_divertNumber.isEmpty()) {
-                DPRINT << ": voicemailboxnumber found";
+        if (list) {
+            // Update the view with selected text
+            data = list->currentItem()->data().toString();
+            text = list->currentItem()->text();
+        }
+        DPRINT << ": data: " << data; 
+        DPRINT << ": text: " << text; 
+
+        if (text == hbTrId("txt_phone_setlabel_voice_mbx")) {
+            m_divertCommand.iNumber = data;
+
+            if (m_divertCommand.iNumber.isEmpty()) {
+                DPRINT << ": voicemailboxnumber query";
+                if (m_divertCommand.iServiceGroup == ServiceGroupVoice) {
+                    m_callDivertingWrapper->queryVoiceMailBoxNumber(
+                            m_divertCommand.iNumber, ServiceGroupVoice);
+                    
+                } else if(m_divertCommand.iServiceGroup == ServiceGroupData) {
+                    m_callDivertingWrapper->queryVoiceMailBoxNumber(
+                            m_divertCommand.iNumber, ServiceGroupData);
+                    
+                } else {
+                    // Skip
+                }
+
             }
             
-            m_eventLoop->quit();
-            
+            if (m_divertCommand.iNumber.isEmpty()) {
+                nextPhaseForActivateDivert(false);
+            } else {
+                nextPhaseForActivateDivert(true);
+            }
         } else if (data == KOtherNumber) {
-                // Event loop is terminated by popUpNumberEditorClosed
-                exitLoop = false;
-                
-                DPRINT << ": open popUpNumberEditor";                
-                popUpNumberEditor(hbTrId("txt_phone_info_number"), m_divertNumber);
+            DPRINT << ": open popUpNumberEditor";                
+            popUpNumberEditor(hbTrId("txt_phone_info_number"));
         } else {
             //TODO if matched contact name not work
             DPRINT << ": else";
-            m_divertNumber = data;
+            m_divertCommand.iNumber = data;
+            nextPhaseForActivateDivert(true);
         }        
         
-    }
-    
-    if (exitLoop) {
-        DPRINT << ": quit eventloop";
-        m_eventLoop->quit();
+    } else {
+        nextPhaseForActivateDivert(false);
     }
     
     DPRINT << ": OUT";
@@ -814,25 +842,33 @@
   CpDivertPluginGroup::popUpNumberEditor.
  */
 void CpDivertPluginGroup::popUpNumberEditor(
-        const QString& heading, QString& result)
+        const QString& heading)
 {
     DPRINT << ": IN";
-
-    Q_UNUSED(result); 
     
-    HbDialog *dialog = createDialog(heading);
+    QScopedPointer<HbDialog> dialog(createDialog(heading));
 
-    m_voiceNumberEditor = new HbLineEdit(dialog);
-    m_voiceNumberEditor->setInputMethodHints(Qt::ImhDialableCharactersOnly);    
-    dialog->setContentWidget(m_voiceNumberEditor);
+    HbLineEdit *editor = new HbLineEdit(dialog.data());
+    editor->setInputMethodHints(Qt::ImhDialableCharactersOnly);    
+    //Ownership is transferred
+    dialog->setContentWidget(editor);
     
-    HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
+    HbAction *okAction = new HbAction(
+            hbTrId("txt_common_button_ok"), 
+            dialog.data());
     dialog->addAction(okAction);
     
-    HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
+    HbAction *cancelAction = new HbAction(
+            hbTrId("txt_common_button_cancel"), 
+            dialog.data());
     dialog->addAction(cancelAction);
     
     dialog->open(this, SLOT(popUpNumberEditorClosed(HbAction*)));
+    if (m_dialog) {
+        m_dialog->deleteLater();
+        m_dialog = NULL;
+    }
+    m_dialog = dialog.take();
     
     DPRINT << ": OUT";
 }
@@ -843,32 +879,33 @@
 void CpDivertPluginGroup::popUpNumberEditorClosed(HbAction* action)
 {
     DPRINT << ": IN";
-    
     bool cancelled(true); 
     if (action) {
-        if (action->text() == hbTrId("txt_common_button_ok")) 
-            {
+        if (action->text() == hbTrId("txt_common_button_ok")) {
             cancelled = false;  
             DPRINT << ": ok selected";
-            }
+        }
     }
     
     if (!cancelled) {
-        m_divertNumber = m_voiceNumberEditor->text();
-            DPRINT << ": m_divertNumber "
-                << m_divertNumber;
-            if (m_divertNumber.isEmpty()) {
-                CpPhoneNotes::instance()->showGlobalNote(m_activeNoteId, 
-                    hbTrId("txt_phone_info_invalid_phone_number"), HbMessageBox::MessageTypeWarning);
-            }
+        HbLineEdit *editor = qobject_cast<HbLineEdit *>(m_dialog->contentWidget());
+        if (editor) {
+            m_divertCommand.iNumber = editor->text();
+        }
+        
+        DPRINT << ": m_divertCommand.iNumber "
+            << m_divertCommand.iNumber;
+        if (m_divertCommand.iNumber.isEmpty()) {
+            CpPhoneNotes::instance()->showNotificationDialog(hbTrId("txt_phone_info_invalid_phone_number"));
+        }
+    }
+    if (m_dialog) {
+        m_dialog->deleteLater();
+        m_dialog = NULL;
     }
     
-    if (m_voiceNumberEditor) {
-        delete m_voiceNumberEditor;
-        m_voiceNumberEditor = NULL; 
-    } 
+    nextPhaseForActivateDivert(!cancelled);
     
-    m_eventLoop->quit();
     DPRINT << ": OUT";
 }
 
@@ -890,7 +927,7 @@
     if (0 == result) {
         if (!CpPhoneNotes::instance()->noteShowing()) {
             CpPhoneNotes::instance()->showGlobalProgressNote(
-                    m_activeProgressNoteId, hbTrId("txt_phone_info_requesting"));
+                    m_activeProgressNoteId, hbTrId("txt_common_info_requesting"));
         }
     } else {
         handleDivertingError(result);
@@ -902,52 +939,41 @@
 /*!
   CpDivertPluginGroup::popUpTimerQuery.
  */
-bool CpDivertPluginGroup::popUpTimerQuery(int &timeout) 
+void CpDivertPluginGroup::popUpTimerQuery() 
 {
     DPRINT << ": IN";
-    Q_UNUSED(timeout); 
+    
+    m_divertCommand.iNoReplyTimer = 0; 
+    
+    QScopedPointer<HbDialog> dialog(createDialog(hbTrId("txt_phone_title_delay")));
+    HbListWidget *list = new HbListWidget(dialog.data());
     
-    bool requestOK(false);
-    m_divertTimeout = 0; 
+    addItemToListWidget(list, hbTrId("txt_phone_list_5_seconds"), 5 );
+    addItemToListWidget(list, hbTrId("txt_phone_list_10_seconds"), 10);
+    addItemToListWidget(list, hbTrId("txt_phone_list_15_seconds"), 15);
+    addItemToListWidget(list, hbTrId("txt_phone_list_20_seconds"), 20);
+    addItemToListWidget(list, hbTrId("txt_phone_list_25_seconds"), 25);
+    addItemToListWidget(list, hbTrId("txt_phone_list_30_seconds"), 30);
     
-    if (!m_eventLoop->isRunning()) {
-        HbDialog *dialog = createDialog(hbTrId("txt_phone_title_delay"));
-        
-        if (m_popupTimerList) {
-            m_popupTimerList = new HbListWidget(dialog);
-            
-            addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_5_seconds"), 5 );
-            addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_10_seconds"), 10);
-            addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_15_seconds"), 15);
-            addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_20_seconds"), 20);
-            addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_25_seconds"), 25);
-            addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_30_seconds"), 30);
-            
-            // Connect list item activation signal to close the popup
-            QObject::connect(
-                    m_popupTimerList, SIGNAL(activated(HbListWidgetItem*)), 
-                    dialog, SLOT(close()), 
-                    Qt::UniqueConnection);
-        }
-        
-        // Sets the "Cancel"-action/button
-        HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
-        dialog->addAction(cancelAction);
-        dialog->setContentWidget(m_popupTimerList);
+    // Connect list item activation signal to close the popup
+    QObject::connect(
+            list, SIGNAL(activated(HbListWidgetItem*)), 
+            dialog.data(), SLOT(close()), 
+            Qt::UniqueConnection);
     
-        dialog->open(this, SLOT(popUpTimerQueryClosed(HbAction *))); 
-        
-        QPointer<QObject> guard = this;
-        m_eventLoop->exec(); 
-        if (guard.isNull()) {
-            requestOK = false;
-        } else if (m_divertTimeout > 0) {
-            requestOK = true;
-        }
+    // Sets the "Cancel"-action/button
+    HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
+    dialog->addAction(cancelAction);
+    dialog->setContentWidget(list);
+
+    dialog->open(this, SLOT(popUpTimerQueryClosed(HbAction *)));
+    if (m_dialog) {
+        m_dialog->deleteLater();
+        m_dialog = NULL;
     }
+    m_dialog = dialog.take();
     
-    DPRINT << ": OUT : requestOK :" << requestOK;
-    return requestOK;
+    DPRINT << ": OUT";
 }
 
 /*!
@@ -955,22 +981,28 @@
  */
 void CpDivertPluginGroup::popUpTimerQueryClosed(HbAction* action)
 {
+    DPRINT << ": IN";
+    
     // If not cancel action selected 
+    bool cancelled(true);
     if (!action) {
+        cancelled = false;
         // Update the view with selected text
-        if (m_popupTimerList->currentItem()) {
-            m_divertTimeout = 
-                    m_popupTimerList->currentItem()->data().toInt();
+        HbListWidget *list = qobject_cast<HbListWidget*>(m_dialog->contentWidget());
+        if (list && list->currentItem()) {
+            m_divertCommand.iNoReplyTimer = 
+                    list->currentItem()->data().toInt();
         }
     }
-    else {
-        DPRINT << ": Cancel";
+    
+    if (m_dialog) {
+        m_dialog->deleteLater();
+        m_dialog = NULL;
     }
+    
+    nextPhaseForActivateDivert(!cancelled);
 
-    DPRINT << ": quit eventloop";
-    m_eventLoop->quit();
-
-    DPRINT << ": OUT: timeout: " << m_divertTimeout;
+    DPRINT << ": OUT: timeout: " << m_divertCommand.iNoReplyTimer;
 }
 
 
@@ -1004,8 +1036,6 @@
         bsc = AllBearer;
     }
 
-
-    
     DPRINT << ": OUT : bsc :" << bsc;
     return bsc;
 }
@@ -1074,9 +1104,9 @@
     DPRINT << ": IN";
     
     // all calls divert activation deactivates automatically other diverts
-    QVariant itemState = m_DataItemVoiceAllCalls->contentWidgetData("state");
+    QVariant itemState = m_DataItemVoiceAllCalls->contentWidgetData("checkState");
     if ((itemState.isValid()) && 
-        (itemState.toInt() == CpDivertSelectionCustomitem::Enabled)) {
+        (itemState.toInt() == Qt::Checked)) {
         deActivateDependentDivertOption(m_DataItemVoiceIfBusy);
         deActivateDependentDivertOption(m_DataItemVoiceIfNotAnswered);
         deActivateDependentDivertOption(m_DataItemVoiceIfOutOfReach);
@@ -1090,9 +1120,9 @@
     }
     
     // all calls divert activation deactivates automatically other diverts
-    itemState = m_DataItemVideoAllCalls->contentWidgetData("state");
+    itemState = m_DataItemVideoAllCalls->contentWidgetData("checkState");
     if ((itemState.isValid()) && 
-        (itemState.toInt() == CpDivertSelectionCustomitem::Enabled)) {
+        (itemState.toInt() == Qt::Checked)) {
         deActivateDependentDivertOption(m_DataItemVideoIfBusy);
         deActivateDependentDivertOption(m_DataItemVideoIfNotAnswered);
         deActivateDependentDivertOption(m_DataItemVideoIfOutOfReach);
@@ -1117,13 +1147,21 @@
 void CpDivertPluginGroup::deActivateDependentDivertOption(
         CpDivertItemData* item) const
 {
-    QVariant itemState = item->contentWidgetData("state");
-    if ((itemState.isValid()) && 
-        (itemState == CpDivertSelectionCustomitem::Enabled)) {
-        item->setContentWidgetData(
-            "state", CpDivertSelectionCustomitem::Deactivated);
+    DPRINT << ": IN";
+    
+    QVariant itemState = item->contentWidgetData("checkState");
+    if ((itemState.isValid()) && (itemState == Qt::Checked)) {
+        item->setContentWidgetData("checkState", Qt::Unchecked);
+        item->setContentWidgetData("text", QString(""));
+        
+        if (!item->description().isEmpty()) {
+            item->setDescription(
+                hbTrId("txt_phone_setlabel_divert_delay_ln_seconds", 0));
+        }
     }
     item->setEnabled(false);
+    
+    DPRINT << ": OUT";
 }
 
 /*!
@@ -1132,13 +1170,15 @@
 void CpDivertPluginGroup::activateDependentDivertOption(
         CpDivertItemData* item, bool fetchFromNetwork)
 {
-    if ((CpDivertSelectionCustomitem::Deactivated == 
-            item->contentWidgetData("state").toInt()) &&
+    DPRINT << ": IN";
+    
+    if ((Qt::Unchecked == item->contentWidgetData("checkState").toInt()) &&
             fetchFromNetwork) {
-        addToDivertingRequestQueue(
-            CheckDivertStatus, *item);
+        addToDivertingRequestQueue(CheckDivertStatus, *item);
     }
     item->setEnabled(true);
+    
+    DPRINT << ": OUT";
 }
 
 /*!
@@ -1152,31 +1192,28 @@
     // CFNrc before concluding that not available divert is enabled, because
     // some networks may not return divert number for inactive diverts.
     int cfbState = 
-        m_DataItemVoiceIfBusy->contentWidgetData("state").toInt();
+        m_DataItemVoiceIfBusy->contentWidgetData("checkState").toInt();
     int cfnryState = 
-        m_DataItemVoiceIfNotAnswered->contentWidgetData("state").toInt();
+        m_DataItemVoiceIfNotAnswered->contentWidgetData("checkState").toInt();
     int cfnrcState = 
-        m_DataItemVoiceIfOutOfReach->contentWidgetData("state").toInt();
+        m_DataItemVoiceIfOutOfReach->contentWidgetData("checkState").toInt();
     QVariant cfbNumber = 
-        m_DataItemVoiceIfBusy->contentWidgetData("number");
+        m_DataItemVoiceIfBusy->contentWidgetData("text");
     QVariant cfnryNumber = 
-        m_DataItemVoiceIfNotAnswered->contentWidgetData("number");
+        m_DataItemVoiceIfNotAnswered->contentWidgetData("text");
     QVariant cfnrcNumber = 
-        m_DataItemVoiceIfOutOfReach->contentWidgetData("number");
+        m_DataItemVoiceIfOutOfReach->contentWidgetData("text");
     
     if ((cfbNumber == cfnryNumber) && (cfbNumber == cfnrcNumber) &&
         (cfbState == cfnryState) && (cfbState == cfnrcState)) {
         m_DataItemVoiceIfNotAvailable->setContentWidgetData(
-            "number", m_DataItemVoiceIfBusy->contentWidgetData("number"));
-        m_DataItemVoiceIfNotAvailable->setContentWidgetData(
-            "timeout", m_DataItemVoiceIfNotAnswered->contentWidgetData("timeout"));
+            "text", m_DataItemVoiceIfBusy->contentWidgetData("text"));
         m_DataItemVoiceIfNotAvailable->setContentWidgetData(
-            "state", m_DataItemVoiceIfBusy->contentWidgetData("state"));
+            "checkState", m_DataItemVoiceIfBusy->contentWidgetData("checkState"));
     } else {
-        m_DataItemVoiceIfNotAvailable->setContentWidgetData("number", "");
-        m_DataItemVoiceIfNotAvailable->setContentWidgetData("timeout", 0);
+        m_DataItemVoiceIfNotAvailable->setContentWidgetData("text", "");
         m_DataItemVoiceIfNotAvailable->setContentWidgetData(
-            "state", CpDivertSelectionCustomitem::Disabled);
+            "checkState", Qt::Unchecked);
 
     }
     // Item dimming
@@ -1190,32 +1227,28 @@
     // CFNrc before concluding that not available divert is enabled, because
     // some networks may not return divert number for inactive diverts.
     cfbState = 
-        m_DataItemVideoIfBusy->contentWidgetData("state").toInt();
+        m_DataItemVideoIfBusy->contentWidgetData("checkState").toInt();
     cfnryState = 
-        m_DataItemVideoIfNotAnswered->contentWidgetData("state").toInt();
+        m_DataItemVideoIfNotAnswered->contentWidgetData("checkState").toInt();
     cfnrcState = 
-        m_DataItemVideoIfOutOfReach->contentWidgetData("state").toInt();
+        m_DataItemVideoIfOutOfReach->contentWidgetData("checkState").toInt();
     cfbNumber = 
-        m_DataItemVideoIfBusy->contentWidgetData("number");
+        m_DataItemVideoIfBusy->contentWidgetData("text");
     cfnryNumber = 
-        m_DataItemVideoIfNotAnswered->contentWidgetData("number");
+        m_DataItemVideoIfNotAnswered->contentWidgetData("text");
     cfnrcNumber = 
-        m_DataItemVideoIfOutOfReach->contentWidgetData("number");
+        m_DataItemVideoIfOutOfReach->contentWidgetData("text");
     
     if ((cfbNumber == cfnryNumber) && (cfbNumber == cfnrcNumber) &&
         (cfbState == cfnryState) && (cfbState == cfnrcState)) {
         m_DataItemVideoIfNotAvailable->setContentWidgetData(
-            "number", m_DataItemVideoIfBusy->contentWidgetData("number"));
+            "text", m_DataItemVideoIfBusy->contentWidgetData("text"));
         m_DataItemVideoIfNotAvailable->setContentWidgetData(
-            "timeout", m_DataItemVideoIfNotAnswered->contentWidgetData("timeout"));
-        m_DataItemVideoIfNotAvailable->setContentWidgetData(
-            "state", m_DataItemVideoIfBusy->contentWidgetData("state"));
+            "checkState", m_DataItemVideoIfBusy->contentWidgetData("checkState"));
     } else {
-        m_DataItemVideoIfNotAvailable->setContentWidgetData("number", "");
-        m_DataItemVideoIfNotAvailable->setContentWidgetData("timeout", 0);
+        m_DataItemVideoIfNotAvailable->setContentWidgetData("text", "");
         m_DataItemVideoIfNotAvailable->setContentWidgetData(
-            "state", CpDivertSelectionCustomitem::Disabled);
-
+            "checkState", Qt::Unchecked);
     }
     
     // Item dimming
@@ -1227,4 +1260,60 @@
     DPRINT << ": OUT";
 }
 
+void CpDivertPluginGroup::nextPhaseForActivateDivert(bool ok)
+{
+    DPRINT << ": IN";
+    
+    if (ok) {
+        switch (m_activateDivertPhase) {
+            case PopUpVoiceNumberListQueryPhase: {
+                CpDivertRequestQueueItem request = m_divertRequestQueue.head();
+                if (request.item->property("needTimeoutInfo").toBool()) {
+                    m_activateDivertPhase = PopUpTimerQueryPhase;
+                    popUpTimerQuery();
+                } else {
+                    m_activateDivertPhase = NonePhase;
+                    setCallDiverting(m_divertCommand);
+                    }
+            }
+                break;
+            case PopUpTimerQueryPhase: {
+                m_activateDivertPhase = NonePhase;
+                setCallDiverting(m_divertCommand);
+            }
+            default:
+                DPRINT << "Error: unknown enum value";
+                break;
+        }
+    } else {
+        // Query was cancelled
+        revertItemData(
+            m_divertCommand.iServiceGroup, 
+            m_divertCommand.iCondition);
+        m_divertRequestQueue.clear();
+        m_activateDivertPhase = NonePhase;
+    }
+    
+    DPRINT << ": OUT";
+}
+
+/*!
+  CpDivertPluginGroup::itemShown.
+ */
+bool CpDivertPluginGroup::isDivertSettingsItem(HbDataFormModelItem* modelItem) {
+    return (
+        modelItem == m_DataItemVoiceAllCalls ||
+        modelItem == m_DataItemVoiceIfBusy ||
+        modelItem == m_DataItemVoiceIfNotAnswered ||
+        modelItem == m_DataItemVoiceIfOutOfReach ||
+        modelItem == m_DataItemVoiceIfNotAvailable ||
+        
+        modelItem == m_DataItemVideoAllCalls ||
+        modelItem == m_DataItemVideoIfBusy ||
+        modelItem == m_DataItemVideoIfNotAnswered ||
+        modelItem == m_DataItemVideoIfOutOfReach ||
+        modelItem == m_DataItemVideoIfNotAvailable
+    );
+}
+
 // End of File.